diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2021-01-26 09:19:06 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2021-01-26 09:19:06 +0100 |
| commit | 2c5163b9fa05e8b21ed92f6992e3a216e96817fe (patch) | |
| tree | 32f4f2e706e152626b31ca472e1e564f71340319 /gui/tasks/scripts.js | |
| parent | 2b055cc39c4eee4b8af8bb193143ddd4055b39ac (diff) | |
| parent | 5e9d51d61ecf3a7f8df10fcfc767213a108274c1 (diff) | |
| download | mullvadvpn-2c5163b9fa05e8b21ed92f6992e3a216e96817fe.tar.xz mullvadvpn-2c5163b9fa05e8b21ed92f6992e3a216e96817fe.zip | |
Merge branch 'sandbox-electron-renderer'
Diffstat (limited to 'gui/tasks/scripts.js')
| -rw-r--r-- | gui/tasks/scripts.js | 67 |
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; |
