From e00931bc110107690f58adabd0fa3c220ec35731 Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 29 Apr 2015 14:04:59 -0700 Subject: [PATCH] compile main.min.js for each application - build-main.js is a separate file, spawned with process.fork to allow parallel builds - gulp js builds main.min.js for each js application --- .gitignore | 1 + build-main.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ gulpfile.js | 46 +++++++++++++++++++++++++++++++++++++++-- package.json | 1 + 4 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 build-main.js diff --git a/.gitignore b/.gitignore index d10a9932c..d142057e4 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ docs/source/api/generated docs/gh-pages notebook/static/components notebook/static/style/*.min.css* +notebook/static/*/js/main.min.js* node_modules *.py[co] __pycache__ diff --git a/build-main.js b/build-main.js new file mode 100644 index 000000000..5936b791d --- /dev/null +++ b/build-main.js @@ -0,0 +1,57 @@ +// build main.min.js +// spawned by gulp to allow parallelism + +var rjs = require('requirejs').optimize; + +var name = process.argv[2]; + +var rjs_config = { + name: name + '/js/main', + out: './notebook/static/' + name + '/js/main.min.js', + baseUrl: 'notebook/static', + preserveLicenseComments: false, // license comments conflict with sourcemap generation + generateSourceMaps: true, + optimize: "uglify2", + paths: { + underscore : 'components/underscore/underscore-min', + backbone : 'components/backbone/backbone-min', + jquery: 'components/jquery/jquery.min', + bootstrap: 'components/bootstrap/js/bootstrap.min', + bootstraptour: 'components/bootstrap-tour/build/js/bootstrap-tour.min', + jqueryui: 'components/jquery-ui/ui/minified/jquery-ui.min', + moment: 'components/moment/moment', + codemirror: 'components/codemirror', + termjs: 'components/term.js/src/term', + contents: 'empty:' + }, + shim: { + underscore: { + exports: '_' + }, + backbone: { + deps: ["underscore", "jquery"], + exports: "Backbone" + }, + bootstrap: { + deps: ["jquery"], + exports: "bootstrap" + }, + bootstraptour: { + deps: ["bootstrap"], + exports: "Tour" + }, + jqueryui: { + deps: ["jquery"], + exports: "$" + } + }, + + exclude: [ + "custom/custom", + ] +}; + +rjs(rjs_config, console.log, function (err) { + console.log("Failed to build", name, err); + process.exit(1); +}); diff --git a/gulpfile.js b/gulpfile.js index 3bb0297be..2e9b4992c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,13 +1,15 @@ +var fork = require('child_process').fork; +var path = require('path'); + var gulp = require('gulp'); var less = require('gulp-less'); -var path = require('path'); var minifyCSS = require('gulp-minify-css'); var rename = require('gulp-rename'); var sourcemaps = require('gulp-sourcemaps'); // now some dev nice utilities. var livereload = require('gulp-livereload'); - + gulp.task('css', function () { return gulp.src('./notebook/static/style/*.less') .pipe(sourcemaps.init()) @@ -23,9 +25,49 @@ gulp.task('css', function () { .pipe(livereload()); }); +function build_main(name, callback) { + // build main.min.js for a given application name + // run in a subprocess to allow parallel builds + // clone requirejs config + var p = fork('./build-main.js', [name]); + p.on('exit', function (code, status) { + if (code) { + callback(new Error("Build failed")); + } else { + callback(); + } + }); + return; +} + +// build notebook-js, edit-js, etc. tasks +// which enables parallelism +var apps = ['edit', 'notebook', 'terminal', 'tree']; + +apps.map(function (name) { + gulp.task(name + '-js', function (finish) { + build_main(name, finish); + }); +}); +gulp.task('js', apps.map(function (name) { return name + '-js'; })); gulp.task('watch', function() { livereload.listen(); gulp.watch('notebook/static/**/*.less', ['css']); + + var s = path.join('notebook', 'static'); + + function alljs(name) { + return path.join(s, name, '**', '*.js'); + } + var common_js = ['components', 'base', 'auth', 'services'].map(alljs); + + gulp.watch(common_js, ['js']); + apps.map(function (name) { + gulp.watch([ + alljs(name), + '!' + path.join(s, name, 'js', 'main.min.js'), + ], [name + '-js']); + }); }); diff --git a/package.json b/package.json index 93f03877d..381a854cc 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "gulp-rename": "^1.2.2", "gulp-sourcemaps": "^1.5.1", "less": "~2", + "requirejs": "^2.1.17", "source-map": "^0.4.2" } }