Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure; build tasks #653

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,10 @@ dist


# Project specific
**/server/config/devices.json
**/server/data/output/*
**/server/data/temp/*
**/server/data/thumbnail/*
**/server/data/preview/*.tif
**/scan*.jpg
app-server/config/devices.json
app-server/data/output/*
app-server/data/temp/*
app-server/data/thumbnail/*
app-server/data/preview/*.tif
**/config.local.js
var
13 changes: 6 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ FROM node:18-alpine AS scanservjs-build
ENV APP_DIR=/app
WORKDIR "$APP_DIR"

COPY package*.json "$APP_DIR/"
COPY packages/server/package*.json "$APP_DIR/packages/server/"
COPY packages/client/package*.json "$APP_DIR/packages/client/"
COPY package*.json gulpfile.js "$APP_DIR/"
COPY app-server/package*.json "$APP_DIR/app-server/"
COPY app-ui/package*.json "$APP_DIR/app-ui/"

RUN npm install .

COPY packages/client/ "$APP_DIR/packages/client/"
COPY packages/server/ "$APP_DIR/packages/server/"
COPY app-server/ "$APP_DIR/app-server/"
COPY app-ui/ "$APP_DIR/app-ui/"

RUN npm run build

Expand Down Expand Up @@ -49,7 +49,6 @@ RUN apt-get update \
&& sed -i \
's/policy domain="resource" name="disk" value="1GiB"/policy domain="resource" name="disk" value="8GiB"'/ \
/etc/ImageMagick-6/policy.xml \
&& npm install -g npm@8.3.0 \
&& npm cache clean --force;

# Core image
Expand Down Expand Up @@ -84,7 +83,7 @@ ENTRYPOINT [ "/run.sh" ]

# Copy the code and install
COPY --from=scanservjs-build "$APP_DIR/dist" "$APP_DIR/"
RUN npm install --production \
RUN npm install --omit=dev \
&& npm cache clean --force;

EXPOSE 8080
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
38 changes: 38 additions & 0 deletions app-server/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const chmod = require('gulp-chmod');
const eslint = require('gulp-eslint');
const { dest, src } = require('gulp');
const filter = require('gulp-filter');
const merge = require('merge-stream');

const DIST = './dist/';

// Useful resources
// * https://www.smashingmagazine.com/2014/06/building-with-gulp/
// * https://github.com/gulpjs/gulp/tree/master/docs/recipes

exports.lint = () => {
return src(['./src/**/*.js', './config/config.default.js', './test/**/*.js', 'gulpfile.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
};

exports.build = () => {
const shellFilter = filter('**/*.sh', { restore: true });

const common = src([
'./package.json',
'./*config/**/config.default.js',
'./*data/**/default.jpg'])
.pipe(shellFilter)
.pipe(chmod(0o755))
.pipe(shellFilter.restore)
.pipe(dest(DIST));

const source = src(['./src/**/*'])
.pipe(dest(`${DIST}/server/`));

return merge(common, source);
};

exports.default = exports.build;
49 changes: 49 additions & 0 deletions app-server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "scanservjs-server",
"version": "3.0.0-SNAPSHOT",
"description": "scanservjs-api is a REST based API to control your scanner.",
"scripts": {
"build": "gulp build",
"clean": "npm run clean:dist && npm run clean:modules",
"clean:dist": "rm -rf ./dist",
"clean:modules": "rm -rf ./node_modules",
"dev": "nodemon -e js,json,yml src/server.js",
"lint": "gulp lint",
"serve": "node ./src/server.js",
"test": "mocha"
},
"main": "server/server.js",
"repository": {
"type": "git",
"url": "https://github.com/sbs20/scanservjs"
},
"devDependencies": {
"eslint": "8.51.0",
"gulp": "4.0.2",
"gulp-chmod": "3.1.0",
"gulp-eslint": "6.0.0",
"gulp-filter": "7.0.0",
"merge-stream": "2.0.0",
"mocha": "10.2.0",
"nodemon": "3.0.1"
},
"author": "Sam Strachan",
"license": "GPL-2.0",
"dependencies": {
"adm-zip": "0.5.10",
"dayjs": "1.11.10",
"express": "4.18.2",
"express-basic-auth": "1.2.1",
"loglevel": "1.8.1",
"loglevel-plugin-prefix": "0.8.4",
"mv": "2.1.1",
"semver": "7.5.4",
"swagger-jsdoc": "6.2.8",
"swagger-ui-express": "4.6.3"
},
"nodemonConfig": {
"watch": [
"server"
]
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('FileInfo', () => {

it('List file', async () => {
await assert.rejects(
async () => FileInfo.create('../package.json').list(),
async () => FileInfo.create('./missing-file.txt').list(),
/Error: .* does not exist/);
await assert.rejects(
async () => FileInfo.create('./package.json').list(),
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 7 additions & 6 deletions packages/client/package.json → app-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
"description": "scanservjs is a simple web-based UI for SANE which allows you to share a scanner on a network without the need for drivers or complicated installation.",
"author": "Sam Strachan",
"scripts": {
"clean": "rm -rf ./dist",
"dev": "concurrently 'vite' 'export SCANSERV_BASE_PATH=../server/ && nodemon ../server/src/server.js'",
"build": "vite build",
"clean": "npm run clean:dist && npm run clean:modules",
"clean:dist": "rm -rf ./dist",
"clean:modules": "rm -rf ./node_modules",
"dev": "vite",
"lint": "eslint --ext .js,.vue src",
"missing-translations": "node missing-translations.js",
"preview": "vite preview",
"build": "npm run clean && vite build",
"lint": "eslint --ext .js,.vue src"
"preview": "vite preview"
},
"main": "server/server.js",
"dependencies": {
Expand All @@ -24,7 +26,6 @@
"vuetify": "3.3.17"
},
"devDependencies": {
"concurrently": "8.2.1",
"eslint": "8.50.0",
"eslint-plugin-vue": "9.17.0",
"nodemon": "3.0.1",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 7 additions & 13 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,13 @@ echo fs.inotify.max_user_watches=131072 | sudo tee -a /etc/sysctl.d/50-default.c
Before committing please verify and build

```
npm run verify && npm run build
```

Alternatively, create a local release package

```
npm run release
npm run lint && npm run test && npm run build
```

## Find missing translations

```
npm run missing-translations
npm run util:missing-translations
```

## Updating node dependencies
Expand Down Expand Up @@ -154,14 +148,14 @@ various ways to achieve this but Docker works well.
FROM node:18-alpine AS release-node18
WORKDIR /app

COPY package*.json /app/
COPY packages/server/package*.json /app/packages/server/
COPY packages/client/package*.json /app/packages/client/
COPY package*.json gulpfile.js "$APP_DIR/"
COPY app-server/package*.json "$APP_DIR/app-server/"
COPY app-ui/package*.json "$APP_DIR/app-ui/"

RUN npm install .

COPY packages/client/ /app/packages/client/
COPY packages/server/ /app/packages/server/
COPY app-server/ "$APP_DIR/app-server/"
COPY app-ui/ "$APP_DIR/app-ui/"

RUN npm run build && npm run package

Expand Down
44 changes: 44 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const version = require('./package.json').version;
const dayjs = require('dayjs');
const chmod = require('gulp-chmod');
const { dest, series, src } = require('gulp');
const gzip = require('gulp-gzip');
const filter = require('gulp-filter');
const tar = require('gulp-tar');
const merge = require('merge-stream');

const DIST = './dist';
const RELEASE = './release';

// Useful resources
// * https://www.smashingmagazine.com/2014/06/building-with-gulp/
// * https://github.com/gulpjs/gulp/tree/master/docs/recipes

exports.assemble = () => {
const ui = src(['./app-ui/dist/**'])
.pipe(dest(`${DIST}/client`));

const api = src(['./app-server/dist/**'])
.pipe(dest(DIST));

const shellFilter = filter('**/*.sh', {restore: true});
const assets = src(['./app-assets/**', 'package-lock.json'])
.pipe(shellFilter)
.pipe(chmod(0o755))
.pipe(shellFilter.restore)
.pipe(dest(DIST));

return merge(ui, api, assets);
};

exports.package = () => {
const filename = `scanservjs_v${version}_${dayjs().format('YYYYMMDD.HHmmss')}.tar`;
return src(`${DIST}/**/*`)
// chmod all dirs +x
.pipe(chmod(undefined, 0o755))
.pipe(tar(filename))
.pipe(gzip())
.pipe(dest(RELEASE));
};

exports.default = series(exports.assemble);
Loading
Loading