config: remove gulp and realize build process with concurrently

This commit is contained in:
Xymorot 2019-12-04 03:51:28 +01:00
parent 95de66a3c9
commit 482e5bd343
5 changed files with 952 additions and 1805 deletions

View File

@ -11,7 +11,7 @@
},
"rules": {
"no-shadow": "error",
"no-magic-numbers": ["error", { "ignore": [0, 1, -1] }],
"no-magic-numbers": ["error", { "ignore": [0, 1, -1, 10, 100] }],
"no-param-reassign": "error",
"prefer-template": "error",
"prefer-arrow-callback": "error",

30
buildfile.js Normal file
View File

@ -0,0 +1,30 @@
const fs = require('fs');
const path = require('path');
const minimist = require('minimist');
const webpackConfig = require('./webpack.config');
const templating = require('./templates');
const { watch } = require('chokidar');
const { debounce } = require('lodash');
/** @type {Object} */
const argv = minimist(process.argv);
function buildIndexHtml() {
const html = templating.compile(!!argv.dev);
fs.writeFileSync(path.resolve(webpackConfig.output.path, 'index.html'), html);
console.log('compiled index.html');
}
const debouncedBuildIndexHtml = debounce(buildIndexHtml, 100, { leading: true, trailing: false });
function build() {
if (argv.watch) {
const templatesWatcher = watch('./templates/**/*');
templatesWatcher.on('all', debouncedBuildIndexHtml);
} else {
buildIndexHtml();
}
}
build();

View File

@ -1,66 +0,0 @@
const { src, dest, watch, parallel } = require('gulp');
const fs = require('fs');
const path = require('path');
const { exec } = require('child_process');
const minimist = require('minimist');
const tsConfig = require('./tsconfig.json');
const webpack = require('webpack-stream');
const webpackConfig = require('./webpack.config');
const templating = require('./templates');
const argv = minimist(process.argv);
function buildFrontend() {
let config = webpackConfig;
if (argv.dev) {
config = { ...config, ...{ mode: 'development' } };
}
if (argv.watch) {
config = { ...config, ...{ watch: true } };
}
return src(config.entry)
.pipe(webpack(config))
.pipe(dest(config.output.path));
}
function buildIndexHtml(cb) {
let isDev = false;
if (argv.dev) {
isDev = true;
}
const html = templating.compile(isDev);
fs.writeFileSync(path.resolve(webpackConfig.output.path, 'index.html'), html);
cb();
}
function transpileTypescript(cb) {
const command = path.resolve(process.cwd(), 'node_modules', '.bin', 'tsc');
exec(command, (err, stdout, stderr) => {
if (stdout) {
console.log(stdout);
}
if (stderr) {
console.log(stderr);
}
cb(err);
});
}
function build(cb) {
if (argv.watch) {
watch(tsConfig.include, { ignoreInitial: false }, transpileTypescript);
watch('./templates/**/*', { ignoreInitial: false }, buildIndexHtml);
buildFrontend();
} else {
parallel(transpileTypescript, buildIndexHtml, buildFrontend)(cb);
}
}
build.flags = {
'--dev': 'builds in development mode',
'--watch': 'watches the files',
};
exports.build = build;

2641
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -15,8 +15,14 @@
"rebuild": "electron-rebuild -f -b -t prod,dev,optional",
"typeorm:migrate": "npm run typeorm:migrate:library",
"typeorm:migrate:library": "typeorm migration:run -c library",
"watch": "gulp build --watch --dev",
"build": "gulp build",
"build:webpack": "webpack --config webpack.config.js",
"watch:webpack": "webpack --config webpack.config.js --mode development -w",
"build:index": "node buildfile.js",
"watch:index": "node buildfile.js --watch --dev",
"build:ts": "tsc",
"watch:ts": "tsc -w",
"build": "concurrently -c green,yellow,cyan -n webpack,index,typescript \"npm run build:webpack\" \"npm run build:index\" \"npm run build:ts\"",
"watch": "concurrently -c green,yellow,cyan -n webpack,index,typescript \"npm run watch:webpack\" \"npm run watch:index\" \"npm run watch:ts\"",
"test:before": "node tests/setup/before.js",
"test:after": "node tests/setup/after.js",
"test:fast": "npm run test:before && mocha --grep @slow --invert && npm run test:after",
@ -26,7 +32,7 @@
"lint:check": "npm run eslint:check && npm run tslint:check",
"lint": "npm run eslint && npm run tslint",
"lint:fix": "npm run eslint:fix && npm run tslint:fix",
"eslint:check": "eslint --print-config gulpfile.js | eslint-config-prettier-check",
"eslint:check": "eslint --print-config forge.config.js | eslint-config-prettier-check",
"eslint": "eslint .",
"eslint:fix": "eslint . --fix",
"tslint:check": "tslint-config-prettier-check ./tslint.json",
@ -54,7 +60,6 @@
"@electron-forge/maker-squirrel": "^6.0.0-beta.45",
"@types/chai": "^4.2.5",
"@types/fs-extra": "^8.0.1",
"@types/gulp": "^4.0.6",
"@types/jsdom": "latest",
"@types/minimist": "latest",
"@types/mocha": "latest",
@ -64,15 +69,16 @@
"@types/webdriverio": "^4.13.3",
"@types/webpack": "^4.41.0",
"chai": "^4.2.0",
"chokidar": "^3.3.0",
"concurrently": "^5.0.0",
"electron": "^6.1.4",
"electron-rebuild": "^1.8.8",
"eslint": "^6.6.0",
"eslint-config-prettier": "^6.7.0",
"fast-check": "^1.19.0",
"gulp": "^4.0.2",
"gulp-cli": "^2.2.0",
"handlebars": "^4.5.3",
"husky": "^3.1.0",
"lodash": "^4.17.15",
"minimist": "^1.2.0",
"mocha": "^6.2.2",
"nock": "^11.7.0",