Skip to content

Commit

Permalink
webview: Add a 'watch' option to the build process
Browse files Browse the repository at this point in the history
Use `yarn build-webview -w` or `yarn build-webview --watch`

The input files are watched for changes. If asset files change,
they are copied again to the asset folders. If the JavaScript file
changes, it is recompiled.
  • Loading branch information
borisyankov committed Jun 21, 2018
1 parent 7f355a4 commit 8a53bf9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,4 @@ rules:
const, wildcard, reactotron, camelcase, hydrator, perf, stacktrace, Dir, fs,
avoider, octicons, centerer, ldap, gravatar, identicon, blueimp, filename, wildcards,
jpeg, jpg, tif, mov, notif, diag, bmp, viewport, scalable, polyfill, rect, touchstart,
touchend, touchmove, remoteuser, sso, submessages, nbsp, args, readdir]
touchend, touchmove, remoteuser, sso, submessages, nbsp, args, readdir, argv, stdout]
34 changes: 32 additions & 2 deletions tools/build-webview.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,35 @@ const compileJS = () => {
fs.writeFileSync(`${outputIosFolder}zulip.js`, compiledCode);
};

copyResourceFiles();
compileJS();
const build = () => {
copyResourceFiles();
compileJS();
};

const watch = () => {
process.stdout.write('Watching...\n');

fs.watch(inputFolder, {}, (eventType, filename) => {
if (filename) {
process.stdout.write('Asset changed. Copying... ');
copyResourceFiles();
process.stdout.write('Done.\n');
}
});

fs.watch(sourceFilename, {}, (eventType, filename) => {
if (filename) {
process.stdout.write('Code changed. Compiling... ');
compileJS();
process.stdout.write('Done.\n');
}
});
};

const args = process.argv.slice(2);

if (args.length === 0) {
build();
} else if (args.indexOf('--watch') !== -1 || args.indexOf('-w') !== -1) {
watch();
}

0 comments on commit 8a53bf9

Please sign in to comment.