From 82c3f8c36fb0684a82b393deacb4da72e1179da9 Mon Sep 17 00:00:00 2001 From: Stefan Thomas Date: Thu, 8 Nov 2012 14:02:39 -0800 Subject: [PATCH] Added ability to watch files and rebuild automatically. --- webpack.js | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/webpack.js b/webpack.js index d4cd81441..fe21a57d8 100644 --- a/webpack.js +++ b/webpack.js @@ -5,7 +5,13 @@ var extend = require("extend"); var programPath = __dirname + "/src/js/remote.js"; -console.log('Compiling Ripple JavaScript...'); +var watch = false; +process.argv.forEach(function (arg) { + if (arg === '-w' || arg === '--watch') { + watch = true; + } +}); + var builds = [{ filename: 'ripple-'+pkg.version+'.js', },{ @@ -20,8 +26,10 @@ var defaultOpts = { // [sic] Yes, this is the spelling upstream. libary: 'ripple', // However, it's fixed in webpack 0.8, so we include the correct spelling too: - library: 'ripple' + library: 'ripple', + watch: watch }; + function build(opts) { var opts = extend({}, defaultOpts, opts); opts.output = __dirname + "/build/"+opts.filename; @@ -29,13 +37,23 @@ function build(opts) { var filename = opts.filename; webpack(programPath, opts, function (err, result) { console.log(' '+filename, result.hash, '['+result.modulesCount+']'); - callback(err); + if ("function" === typeof callback) { + callback(err); + } }); } } -async.series(builds.map(build), function (err) { - if (err) { - console.error(err); - } -}); +if (!watch) { + console.log('Compiling Ripple JavaScript...'); + async.series(builds.map(build), function (err) { + if (err) { + console.error(err); + } + }); +} else { + console.log('Watching files for changes...'); + builds.map(build).forEach(function (build) { + build(); + }); +}