summaryrefslogtreecommitdiffhomepage
path: root/gui/tasks/scripts.js
diff options
context:
space:
mode:
Diffstat (limited to 'gui/tasks/scripts.js')
-rw-r--r--gui/tasks/scripts.js67
1 files changed, 63 insertions, 4 deletions
diff --git a/gui/tasks/scripts.js b/gui/tasks/scripts.js
index 37dcfa9355..d32e704625 100644
--- a/gui/tasks/scripts.js
+++ b/gui/tasks/scripts.js
@@ -1,14 +1,30 @@
const { exec } = require('child_process');
-const { src, dest, series } = require('gulp');
+const { dest, series, parallel } = require('gulp');
const ts = require('gulp-typescript');
const inject = require('gulp-inject-string');
+const sourcemaps = require('gulp-sourcemaps');
const TscWatchClient = require('tsc-watch/client');
+const browserify = require('browserify');
+const buffer = require('vinyl-buffer');
+const source = require('vinyl-source-stream');
function makeWatchCompiler(onFirstSuccess) {
+ let firstBuild = true;
+
const compileScripts = function () {
const watch = new TscWatchClient();
- watch.on('first_success', onFirstSuccess);
- watch.start('--noClear', '--inlineSourceMap', '--incremental', '--project', '.');
+ watch.on('success', () =>
+ parallel(
+ makeBrowserifyRenderer(true),
+ makeBrowserifyPreload(true),
+ )(() => {
+ if (firstBuild) {
+ firstBuild = false;
+ onFirstSuccess();
+ }
+ }),
+ );
+ watch.start('--noClear', '--sourceMap', '--inlineSources', '--incremental', '--project', '.');
return watch.tsc;
};
compileScripts.displayName = 'compile-scripts-watch';
@@ -26,6 +42,46 @@ function compileScripts() {
.pipe(dest('build'));
}
+function makeBrowserifyRenderer(debug) {
+ const browserifyRenderer = () => {
+ let stream = browserify({ entries: './build/src/renderer/index.js', debug })
+ .bundle()
+ .pipe(source('bundle.js'))
+ .pipe(buffer());
+
+ if (debug) {
+ stream = stream.pipe(sourcemaps.init({ loadMaps: true })).pipe(sourcemaps.write());
+ }
+
+ return stream.pipe(dest('./build/src/renderer/'));
+ };
+
+ browserifyRenderer.displayName = 'browserify-renderer';
+ return browserifyRenderer;
+}
+
+function makeBrowserifyPreload(debug) {
+ const browserifyPreload = () => {
+ let stream = browserify({
+ entries: './build/src/renderer/preload.js',
+ debug,
+ })
+ .exclude('electron')
+ .bundle()
+ .pipe(source('preloadBundle.js'))
+ .pipe(buffer());
+
+ if (debug) {
+ stream = stream.pipe(sourcemaps.init({ loadMaps: true })).pipe(sourcemaps.write());
+ }
+
+ return stream.pipe(dest('./build/src/renderer/'));
+ };
+
+ browserifyPreload.displayName = 'browserify-preload';
+ return browserifyPreload;
+}
+
function buildProto(callback) {
exec('bash ./scripts/build-proto.sh', (err) => callback(err));
}
@@ -33,6 +89,9 @@ function buildProto(callback) {
compileScripts.displayName = 'compile-scripts';
buildProto.displayName = 'build-proto';
-exports.build = compileScripts;
+exports.build = series(
+ compileScripts,
+ parallel(makeBrowserifyPreload(false), makeBrowserifyRenderer(false)),
+);
exports.buildProto = buildProto;
exports.makeWatchCompiler = makeWatchCompiler;