diff --git a/.eslintrc.yaml b/.eslintrc.yaml index c199f005b42..eaf5f2d8e5e 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -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] diff --git a/tools/build-webview.js b/tools/build-webview.js index 8d82b8be806..61c3e9b6d59 100644 --- a/tools/build-webview.js +++ b/tools/build-webview.js @@ -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(); +}