diff options
Diffstat (limited to 'js/gulpfile.js')
-rw-r--r-- | js/gulpfile.js | 212 |
1 files changed, 124 insertions, 88 deletions
diff --git a/js/gulpfile.js b/js/gulpfile.js index 4df32f9fbe0..f87294069b1 100644 --- a/js/gulpfile.js +++ b/js/gulpfile.js @@ -7,7 +7,8 @@ // // ********************************************************************** -var bower = require("bower"), +var babel = require("gulp-babel"), + bower = require("bower"), bundle = require("./gulp/bundle"), concat = require('gulp-concat'), del = require("del"), @@ -17,7 +18,7 @@ var bower = require("bower"), gzip = require('gulp-gzip'), iceBuilder = require('gulp-ice-builder'), jshint = require('gulp-jshint'), - minifycss = require('gulp-minify-css'), + cleancss = require('gulp-clean-css'), newer = require('gulp-newer'), open = require("gulp-open"), path = require('path'), @@ -121,17 +122,16 @@ gulp.task("common:slice", [], .pipe(gulp.dest("test/Common")); }); -gulp.task("common:slice:clean", [], +gulp.task("common:slice-babel", ["common:slice"], function(){ - del(["test/Common/Controller.js", "test/Common/.depend"]); + return gulp.src(["test/Common/Controller.js"]) + .pipe(babel({compact: false})) + .pipe(gulp.dest("test/Common/es5")); }); -gulp.task("common:slice:watch", ["common:slice"], +gulp.task("common:slice:clean", [], function(){ - gulp.watch(["test/Common/Controller.ice"], - function(){ - gulp.start("common:slice"); - }); + del(["test/Common/Controller.js", "test/Common/.depend", "test/Common/es5/Controller.js"]); }); gulp.task("common:js", ["bower"], @@ -139,48 +139,33 @@ gulp.task("common:js", ["bower"], return gulp.src(common.scripts) .pipe(newer("assets/common.min.js")) .pipe(concat("common.min.js")) - .pipe(uglify()) + //.pipe(uglify()) // TODO: uglify doesn't support es6 .pipe(gulp.dest("assets")) .pipe(gzip()) .pipe(gulp.dest("assets")); }); -gulp.task("common:js:watch", ["common:js"], - function(){ - gulp.watch(common.scripts, - function(){ - gulp.start("common:js"); - }); - }); - gulp.task("common:css", ["bower"], function(){ return gulp.src(common.styles) .pipe(newer("assets/common.css")) .pipe(concat("common.css")) - .pipe(minifycss()) + .pipe(cleancss()) .pipe(gulp.dest("assets")) .pipe(gzip()) .pipe(gulp.dest("assets")); }); -gulp.task("common:css:watch", ["common:css"], - function(){ - gulp.watch(common.styles, - function(){ - gulp.start("common:css"); - }); - }); - gulp.task("common:clean", [], function(){ del(["assets/common.css", "assets/common.min.js"]); }); -function testTask(name) { return name.replace("/", "_"); } -function testWatchTask(name) { return testTask(name) + ":watch"; } +function testTask(name) { return name.replace(/\//g, "_"); } +function testBabelTask(name) { return testTask(name) + "-babel"; } function testCleanDependTask(name) { return testTask(name) + "-depend:clean"; } function testCleanTask(name) { return testTask(name) + ":clean"; } +function testBabelCleanTask(name) { return testCleanTask(name) + "-babel"; } tests.forEach( function(name){ @@ -194,13 +179,13 @@ tests.forEach( })) .pipe(gulp.dest(name)); }); - - gulp.task(testWatchTask(name), [testTask(name)], + + gulp.task(testBabelTask(name), [testTask(name)], function(){ - gulp.watch([path.join(name, "*.ice")], [testTask(name)]); - - gulp.watch( - [path.join(name, "*.js"), path.join(name, "browser", "*.js")]); + return gulp.src([path.join(name, "*.js"), "!" + path.join(name, "run.js")]) + .pipe(babel({compact: false})) + .pipe(gulp.dest(name.replace("test/Ice/", "test/Ice/es5/") + .replace("test/Glacier2/", "test/Glacier2/es5/"))); }); gulp.task(testCleanDependTask(name), [], @@ -215,14 +200,20 @@ tests.forEach( .pipe(extreplace(".js")) .pipe(paths(del)); }); + + gulp.task(testBabelCleanTask(name), [testCleanTask(name)], + function(){ + var s = name.replace("test/Ice/", "test/Ice/es5/") + .replace("test/Glacier2/", "test/Glacier2/es5/"); + + return gulp.src([path.join(s, "*.js"), "!" + path.join(s, "run.js")]) + .pipe(paths(del)); + }); }); -gulp.task("test", tests.map(testTask).concat(["common:slice", "common:js", "common:css"])); +gulp.task("test", tests.map(testBabelTask).concat(["common:slice-babel", "common:js", "common:css"])); -gulp.task("test:watch", tests.map(testWatchTask).concat( - ["common:slice:watch", "common:css:watch", "common:js:watch"])); - -gulp.task("test:clean", tests.map(testCleanTask).concat(["common:slice:clean"])); +gulp.task("test:clean", tests.map(testBabelCleanTask).concat(["common:slice:clean"])); // // Tasks to build IceJS Distribution @@ -232,19 +223,31 @@ var libs = ["Ice", "Glacier2", "IceStorm", "IceGrid"]; function generateTask(name){ return name.toLowerCase() + ":generate"; } function libTask(name){ return name.toLowerCase() + ":lib"; } -function minLibTask(name){ return name.toLowerCase() + ":lib-min"; } +function minLibTask(name){ return libTask(name) + "-min"; } +function babelTask(name){ return name.toLowerCase() + ":babel"; } +function babelLibTask(name){ return libTask(name) + "-babel";} +function babelMinLibTask(name){ return libTask(name) + "-babel-min"; } + function libFile(name) { return path.join(root, "lib", name + ".js"); } function libFileMin(name) { return path.join(root, "lib", name + ".min.js"); } + +function babelLibFile(name) { return path.join(root, "lib", "es5", name + ".js"); } +function babelLibFileMin(name) { return path.join(root, "lib", "es5", name + ".min.js"); } + function srcDir(name) { return "src/" + name; } function libCleanTask(lib) { return lib + ":clean"; } -function libWatchTask(lib) { return lib + ":watch"; } function libFiles(name){ return [ path.join(root, "lib", name + ".js"), path.join(root, "lib", name + ".js.gz"), path.join(root, "lib", name + ".min.js"), - path.join(root, "lib", name + ".min.js.gz")]; + path.join(root, "lib", name + ".min.js.gz"), + + path.join(root, "lib", "es5", name + ".js"), + path.join(root, "lib", "es5", name + ".js.gz"), + path.join(root, "lib", "es5", name + ".min.js"), + path.join(root, "lib", "es5", name + ".min.js.gz")]; } function mapFiles(name){ @@ -252,7 +255,12 @@ function mapFiles(name){ path.join(root, "lib", name + ".js.map"), path.join(root, "lib", name + ".js.map.gz"), path.join(root, "lib", name + ".min.js.map"), - path.join(root, "lib", name + ".min.js.map.gz")]; + path.join(root, "lib", name + ".min.js.map.gz"), + + path.join(root, "lib", "es5", name + ".js.map"), + path.join(root, "lib", "es5", name + ".js.map.gz"), + path.join(root, "lib", "es5", name + ".min.js.map"), + path.join(root, "lib", "es5", name + ".min.js.map.gz")]; } function libSources(lib, sources){ @@ -278,21 +286,12 @@ function libGeneratedFiles(lib, sources){ { return path.join(srcDir(lib), path.basename(f, ".ice") + ".js"); }) + .concat(path.join("src", "es5", lib, "*.js")) .concat(libFiles(lib)) .concat(mapFiles(lib)) .concat([path.join(srcDir(lib), ".depend", "*")]); } -function watchSources(lib, sources){ - var srcs = sources.common || []; - if(sources.browser){ - srcs = sources.common.concat(sources.browser); } - srcs = srcs.map( - function(f){ - return path.join(srcDir(lib), f); }); - return srcs; -} - function sliceFile(f){ return path.join(sliceDir, f); } libs.forEach( @@ -328,19 +327,47 @@ libs.forEach( return gulp.src(libFile(lib)) .pipe(newer(libFileMin(lib))) .pipe(sourcemaps.init({loadMaps:true, sourceRoot:"./"})) - .pipe(uglify({compress:false})) + //.pipe(uglify({compress:false})) // TODO: uglify doesn't support ES6 .pipe(extreplace(".min.js")) .pipe(sourcemaps.write("../lib", {includeContent: false, addComment: false})) .pipe(gulp.dest("lib")) .pipe(gzip()) .pipe(gulp.dest("lib")); }); + + gulp.task(babelTask(lib), [generateTask(lib)], + function(){ + return gulp.src(path.join("src", lib, "*.js")) + .pipe(babel({compact:false})) + .pipe(gulp.dest(path.join("src", "es5", lib))); + }); - gulp.task(libCleanTask(lib), [], function(){ del(libGeneratedFiles(lib, sources)); }); - gulp.task(libWatchTask(lib), [minLibTask(lib)], + gulp.task(babelLibTask(lib), [libTask(lib)], function(){ - gulp.watch(sources.slice.map(sliceFile).concat(watchSources(lib, sources))); + return gulp.src(libFile(lib)) + .pipe(newer(babelLibFile(lib))) + .pipe(sourcemaps.init()) + .pipe(babel({compact:false})) + .pipe(sourcemaps.write(".")) + .pipe(gulp.dest("lib/es5")) + .pipe(gzip()) + .pipe(gulp.dest("lib/es5")); }); + + gulp.task(babelMinLibTask(lib), [babelLibTask(lib)], + function(){ + return gulp.src(babelLibFile(lib)) + .pipe(newer(babelLibFileMin(lib))) + .pipe(sourcemaps.init({loadMaps:true, sourceRoot:"./"})) + .pipe(uglify({compress:false})) + .pipe(extreplace(".min.js")) + .pipe(sourcemaps.write(".", {includeContent: false, addComment: false})) + .pipe(gulp.dest("lib/es5")) + .pipe(gzip()) + .pipe(gulp.dest("lib/es5")); + }); + + gulp.task(libCleanTask(lib), [], function(){ del(libGeneratedFiles(lib, sources)); }); }); gulp.task("bower", [], @@ -354,40 +381,47 @@ gulp.task("dist:libs", ["bower"], .pipe(gulp.dest("lib")); }); -gulp.task("dist", useBinDist ? ["dist:libs"] : libs.map(minLibTask)); -gulp.task("dist:watch", libs.map(libWatchTask)); +gulp.task("dist", useBinDist ? ["dist:libs"] : libs.map(minLibTask).concat(libs.map(babelMinLibTask)).concat(libs.map(babelTask))); gulp.task("dist:clean", libs.map(libCleanTask)); -gulp.task("watch", ["test:watch"].concat(useBinDist ? [] : ["dist:watch"])); -gulp.task("test:run-with-browser", ["watch"].concat(useBinDist ? ["test"] : ["build"]), - function(){ - require("./bin/HttpServer")(); - var cmd = ["../scripts/TestController.py"]; - cmd = cmd.concat(process.argv.slice(3)); - var p = require("child_process").spawn("python", cmd, {stdio: "inherit"}); - p.on("error", function(err) - { - if(err.message == "spawn python ENOENT") - { - console.log("Error: python is required in PATH to run tests"); - process.exit(1); - } - else - { - throw err; - } - }); - process.on(process.platform == "win32" ? "SIGBREAK" : "SIGINT", - function() +function runTestsWithBrowser(url) +{ + require("./bin/HttpServer")(); + var cmd = ["../scripts/TestController.py"]; + cmd = cmd.concat(process.argv.slice(3)); + var p = require("child_process").spawn("python", cmd, {stdio: "inherit"}); + p.on("error", function(err) + { + if(err.message == "spawn python ENOENT") { - process.exit(); - }); - process.on("exit", function() + console.log("Error: python is required in PATH to run tests"); + process.exit(1); + } + else { - p.kill(); - }); - return gulp.src("") - .pipe(open({uri: "http://127.0.0.1:8080/test/Ice/acm/index.html"})); + throw err; + } + }); + process.on(process.platform == "win32" ? "SIGBREAK" : "SIGINT", + function() + { + process.exit(); + }); + process.on("exit", function() + { + p.kill(); + }); + return gulp.src("").pipe(open({uri: url})); +} + +gulp.task("test:run-with-browser", useBinDist ? ["test"] : ["build"], + function(url){ + return runTestsWithBrowser("http://127.0.0.1:8080/test/Ice/acm/index.html"); + }); + +gulp.task("test:run-with-browser-es5", useBinDist ? ["test"] : ["build"], + function(url){ + return runTestsWithBrowser("http://127.0.0.1:8080/test/Ice/es5/acm/index.html"); }); gulp.task("test:run-with-node", (useBinDist ? ["test"] : ["build"]), @@ -434,6 +468,8 @@ gulp.task("lint:js", ["build"], "src/**/*.js", "src/**/browser/*.js", "test/**/*.js", + "!src/es5/**/*.js", + "!test/**/es5/**/*.js", "!**/Client.min.js"]) .pipe(jshint()) .pipe(jshint.reporter("default")); |