diff options
author | Joe George <joe@zeroc.com> | 2015-02-18 15:43:52 -0500 |
---|---|---|
committer | Joe George <joe@zeroc.com> | 2015-02-18 15:43:52 -0500 |
commit | e1f8da73ec82a44bd23f6dfe430a3ed23b8c3e7c (patch) | |
tree | 75be9d70a067f0898abea22684e9eb41b2f6a297 /js/gulp | |
parent | Undo bogus change where EventLoggerMsg.h/.rc was added to the git repo. (diff) | |
download | ice-e1f8da73ec82a44bd23f6dfe430a3ed23b8c3e7c.tar.bz2 ice-e1f8da73ec82a44bd23f6dfe430a3ed23b8c3e7c.tar.xz ice-e1f8da73ec82a44bd23f6dfe430a3ed23b8c3e7c.zip |
ICE-6301 - Align nodejs source and npm distributions
Diffstat (limited to 'js/gulp')
-rw-r--r-- | js/gulp/bundle.js (renamed from js/gulp/gulp-bundle/index.js) | 28 | ||||
-rw-r--r-- | js/gulp/commonTasks.js | 117 | ||||
-rw-r--r-- | js/gulp/gulp-slice2js/index.js | 15 | ||||
-rw-r--r-- | js/gulp/libTasks.js | 207 | ||||
-rw-r--r-- | js/gulp/testAndDemoTasks.js | 180 | ||||
-rw-r--r-- | js/gulp/util.js | 44 |
6 files changed, 575 insertions, 16 deletions
diff --git a/js/gulp/gulp-bundle/index.js b/js/gulp/bundle.js index 34820c11295..cf78a02b7b0 100644 --- a/js/gulp/gulp-bundle/index.js +++ b/js/gulp/bundle.js @@ -7,13 +7,13 @@ // // ********************************************************************** -var gutil = require("gulp-util"); +var gutil = require("gulp-util"); var PluginError = gutil.PluginError; var PLUGIN_NAME = "gulp-slice2js-bundle"; -var through = require("through2"); -var fs = require("fs"); -var path = require("path"); -var sourcemap = require('source-map'); +var through = require("through2"); +var fs = require("fs"); +var path = require("path"); +var sourcemap = require('source-map'); function rmfile(path) { @@ -269,7 +269,7 @@ function bundle(args) cb(); }, function(cb) - { + { if(!isfile(args.target) || files.some(function(f){ return isnewer(f.path, args.target); })) { @@ -283,7 +283,7 @@ function bundle(args) }); d.depends = d.expand().sort(); - + var sourceMap = new sourcemap.SourceMapGenerator( { file: path.basename(args.target) @@ -316,12 +316,12 @@ function bundle(args) sb.write(preamble); lineOffset += 2; - + args.modules.forEach( function(m){ sb.write(" window." + m + " = window." + m + " || {};\n"); lineOffset++; - + if(m == "Ice") { sb.write(" Ice.Slice = Ice.Slice || {};\n"); @@ -330,12 +330,12 @@ function bundle(args) }); sb.write(" var Slice = Ice.Slice;\n"); lineOffset++; - + for(var i = 0; i < d.depends.length; ++i) { sb.write(modulePreamble); lineOffset += 3; - + var data = d.depends[i].file.contents.toString(); var file = d.depends[i].file; var lines = data.toString().split("\n"); @@ -423,9 +423,9 @@ function bundle(args) { continue; } - + sb.write(" " + out + "\n"); - + sourceMap.addMapping( { generated: @@ -447,7 +447,7 @@ function bundle(args) } sb.write("\n"); lineOffset++; - + // // Now exports the modules to the global Window object. // diff --git a/js/gulp/commonTasks.js b/js/gulp/commonTasks.js new file mode 100644 index 00000000000..a0219c1390e --- /dev/null +++ b/js/gulp/commonTasks.js @@ -0,0 +1,117 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +var browserSync = require("browser-sync"); +var concat = require('gulp-concat'); +var del = require("del"); +var gzip = require('gulp-gzip'); +var minifycss = require('gulp-minify-css'); +var newer = require('gulp-newer'); +var path = require('path'); +var uglify = require("gulp-uglify"); + +var util = require('./util'); + +module.exports = function(gulp) { + var common = + { + "scripts": [ + "bower_components/foundation/js/vendor/modernizr.js", + "bower_components/foundation/js/vendor/jquery.js", + "bower_components/foundation/js/foundation.min.js", + "bower_components/nouislider/distribute/jquery.nouislider.all.js", + "bower_components/animo.js/animo.js", + "bower_components/spin.js/spin.js", + "bower_components/spin.js/jquery.spin.js", + "bower_components/highlightjs/highlight.pack.js", + "assets/icejs.js"], + "styles": + ["bower_components/foundation/css/foundation.css", + "bower_components/animo.js/animate+animo.css", + "bower_components/highlightjs/styles/vs.css", + "bower_components/nouislider/distribute/jquery.nouislider.min.css", + "assets/icejs.css"] + }; + + gulp.task("common:slice", [], + function() + { + return gulp.src(["test/Common/Controller.ice"]) + .pipe(util.slice2js({dest: "test/Common"})) + .pipe(gulp.dest("test/Common")); + }); + + gulp.task("common:slice:clean", [], + function() + { + del(["test/Common/Controller.js"]); + }); + + gulp.task("common:slice:watch", ["common:slice"], + function() + { + gulp.watch(["test/Common/Controller.ice"], function(){ + gulp.start("common:slice", function(){ + browserSync.reload("test/Common/Controller.js"); + }); + }); + }); + + gulp.task("common:js", ["bower"], + function() + { + return gulp.src(common.scripts) + .pipe(newer("assets/common.min.js")) + .pipe(concat("common.min.js")) + .pipe(uglify()) + .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", function(){ + browserSync.reload("assets/common.min.js"); + }); + }); + }); + + gulp.task("common:css", ["bower"], + function() + { + return gulp.src(common.styles) + .pipe(newer("assets/common.css")) + .pipe(concat("common.css")) + .pipe(minifycss()) + .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", function(){ + browserSync.reload("assets/common.css"); + }); + }); + }); + + gulp.task("common:clean", [], + function() + { + del(["assets/common.css", "assets/common.min.js"]); + }); +}; diff --git a/js/gulp/gulp-slice2js/index.js b/js/gulp/gulp-slice2js/index.js index 22b8833a901..0135f48fb95 100644 --- a/js/gulp/gulp-slice2js/index.js +++ b/js/gulp/gulp-slice2js/index.js @@ -120,7 +120,7 @@ function compile(slice2js, file, args, cb) }); } -module.exports = function(options) +module.exports.compile = function(options) { var opts = options || {}; var slice2js; @@ -130,7 +130,7 @@ module.exports = function(options) { try { - slice2js = require("zeroc-slice2js"); + slice2js = require("zeroc-slice2js").compile; } catch(e) { @@ -200,3 +200,14 @@ module.exports = function(options) } }); }; + +module.exports.sliceDir = (function() { + try + { + return require('zeroc-slice2js').sliceDir; + } + catch(e) + { + return null; + } +})(); diff --git a/js/gulp/libTasks.js b/js/gulp/libTasks.js new file mode 100644 index 00000000000..9715bd25d1a --- /dev/null +++ b/js/gulp/libTasks.js @@ -0,0 +1,207 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +var browserSync = require("browser-sync"); +var del = require("del"); +var extreplace = require("gulp-ext-replace"); +var fs = require("fs"); +var gulp = require('gulp'); +var gzip = require('gulp-gzip'); +var newer = require('gulp-newer'); +var path = require('path'); +var sourcemaps = require('gulp-sourcemaps'); +var uglify = require("gulp-uglify"); + +var bundle = require("./bundle"); +var util = require('./util'); + +var root = path.resolve(path.join('__dirname', '..')); +var sliceDir = null; +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 libFile(name) +{ + return path.join(root, "lib", name + ".js"); +} +function libFileMin(name) +{ + return path.join(root, "lib", 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")]; +} + +function mapFiles(name) +{ + return [ + 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")]; +} + +function libSources(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); + }); + + if(sources.slice) + { + srcs = srcs.concat(sources.slice.map(function(f) + { + return path.join(srcDir(lib), path.basename(f, ".ice") + ".js"); + })); + } + + return srcs; +} + +function libGeneratedFiles(lib, sources) +{ + return sources.slice.map(function(f) + { + return path.join(srcDir(lib), path.basename(f, ".ice") + ".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 generateGulpTasks(gulp) { + function sliceFile(f) + { + return path.join(util.sliceDir, f); + } + + libs.forEach( + function(lib) + { + var sources = JSON.parse(fs.readFileSync(path.join(srcDir(lib), "sources.json"), {encoding: "utf8"})); + + gulp.task(generateTask(lib), + function() + { + return gulp.src(sources.slice.map(sliceFile)) + .pipe(util.slice2js({args: ["--ice","--icejs"], dest: srcDir(lib)})) + .pipe(gulp.dest(srcDir(lib))); + }); + + gulp.task(libTask(lib), [generateTask(lib)], + function() + { + return gulp.src(libSources(lib, sources)) + .pipe(sourcemaps.init()) + .pipe(bundle( + { + srcDir: srcDir(lib), + modules: sources.modules, + target: libFile(lib) + })) + .pipe(sourcemaps.write("../lib", {sourceRoot:"/src"})) + .pipe(gulp.dest("lib")) + .pipe(gzip()) + .pipe(gulp.dest("lib")); + }); + + gulp.task(minLibTask(lib), [libTask(lib)], + function() + { + return gulp.src(libFile(lib)) + .pipe(newer(libFileMin(lib))) + .pipe(sourcemaps.init({loadMaps:true, sourceRoot:"./"})) + .pipe(uglify({compress:false})) + .pipe(extreplace(".min.js")) + .pipe(sourcemaps.write("../lib", {includeContent: false})) + .pipe(gulp.dest("lib")) + .pipe(gzip()) + .pipe(gulp.dest("lib")); + }); + + gulp.task(libCleanTask(lib), [], + function() + { + del(libGeneratedFiles(lib, sources)); + }); + + gulp.task(libWatchTask(lib), [minLibTask(lib)], + function() + { + gulp.watch(sources.slice.map(sliceFile).concat(watchSources(lib, sources)), + function(){ + gulp.start(minLibTask(lib), function(){ + browserSync.reload(libFileMin(lib)); + }); + }); + }); + }); +} + +module.exports = function(gulp) { + generateGulpTasks(gulp); + return { + buildTasks : libs.map(minLibTask), + cleanTasks: libs.map(libCleanTask), + watchTasks: libs.map(libCleanTask) + }; +}; + + diff --git a/js/gulp/testAndDemoTasks.js b/js/gulp/testAndDemoTasks.js new file mode 100644 index 00000000000..73bc01594e9 --- /dev/null +++ b/js/gulp/testAndDemoTasks.js @@ -0,0 +1,180 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +var browserSync = require("browser-sync"); +var concat = require('gulp-concat'); +var del = require("del"); +var extreplace = require("gulp-ext-replace"); +var gzip = require('gulp-gzip'); +var newer = require('gulp-newer'); +var path = require('path'); +var paths = require('vinyl-paths'); +var uglify = require("gulp-uglify"); + +var util = require('./util'); + +module.exports = function(gulp) { + + var subprojects = + { + test: [ + "Ice/acm", "Ice/ami", "Ice/binding", "Ice/defaultValue", "Ice/enums", "Ice/exceptions", + "Ice/exceptionsBidir", "Ice/facets", "Ice/facetsBidir", "Ice/hold", "Ice/inheritance", + "Ice/inheritanceBidir", "Ice/location", "Ice/objects", "Ice/operations", "Ice/operationsBidir", + "Ice/optional", "Ice/optionalBidir", "Ice/promise", "Ice/properties", "Ice/proxy", "Ice/retry", + "Ice/slicing/exceptions", "Ice/slicing/objects", "Ice/timeout", "Glacier2/router"], + demo: ["Ice/hello", "Ice/throughput", "Ice/minimal", "Ice/latency", "Ice/bidir", "Glacier2/chat", + "ChatDemo"] + }; + + var minDemos = + { + "Ice/minimal": + { + srcs: [ + "lib/Ice.min.js", + "demo/Ice/minimal/Hello.js", + "demo/Ice/minimal/browser/Client.js"], + dest: "demo/Ice/minimal/browser/" + }, + "ChatDemo": + { + srcs: [ + "lib/Ice.min.js", + "lib/Glacier2.min.js", + "demo/ChatDemo/Chat.js", + "demo/ChatDemo/ChatSession.js", + "demo/ChatDemo/Client.js"], + dest: "demo/ChatDemo" + } + }; + + function testHtmlTask(name) { return "test_" + name.replace("/", "_") + ":html"; } + function testHtmlCleanTask(name) { return "test_" + name.replace("/", "_") + ":html:clean"; } + + subprojects.test.forEach( + function(name) + { + gulp.task(testHtmlTask(name), [], + function() + { + return gulp.src("test/Common/index.html") + .pipe(newer(path.join("test", name, "index.html"))) + .pipe(gulp.dest(path.join("test", name))); + }); + + gulp.task(testHtmlCleanTask(name), [], + function() + { + del(path.join("test", name, "index.html")); + }); + }); + + gulp.task("html", subprojects.test.map(testHtmlTask)); + gulp.task("html:watch", ["html"], + function() + { + gulp.watch(["test/Common/index.html"], ["html"]); + }); + gulp.task("html:clean", subprojects.test.map(testHtmlCleanTask)); + + Object.keys(subprojects).forEach( + function(group) + { + function groupTask(name) { return group + "_" + name.replace("/", "_"); } + function groupGenerateTask(name) { return groupTask(name); } + function groupWatchTask(name) { return groupTask(name) + ":watch"; } + function groupCleanTask(name) { return groupTask(name) + ":clean"; } + + subprojects[group].forEach( + function(name) + { + gulp.task(groupGenerateTask(name), (util.useBinDist ? [] : ["dist"]), + function() + { + return gulp.src(path.join(group, name, "*.ice")) + .pipe(util.slice2js( + { + args: ["-I" + path.join(group, name)], + dest: path.join(group, name) + })) + .pipe(gulp.dest(path.join(group, name))); + }); + + gulp.task(groupWatchTask(name), + (group == "test" ? [groupGenerateTask(name), "html"] : [groupGenerateTask(name)]), + function() + { + gulp.watch([path.join(group, name, "*.ice")], [groupGenerateTask(name)]); + + gulp.watch([path.join(group, name, "*.js"), + path.join(group, name, "browser", "*.js"), + path.join(group, name, "*.html")], function(e){ + browserSync.reload(e.path); + }); + }); + + gulp.task(groupCleanTask(name), [], + function() + { + return gulp.src(path.join(group, name, "*.ice")) + .pipe(extreplace(".js")) + .pipe(paths(del)); + }); + }); + + gulp.task(group, subprojects[group].map(groupGenerateTask).concat( + group == "test" ? ["common:slice", "common:js", "common:css"].concat(subprojects.test.map(testHtmlTask)) : + ["common:slice", "common:js", "common:css", "demo_Ice_minimal:min", "demo_ChatDemo:min"])); + + gulp.task(group + ":watch", subprojects[group].map(groupWatchTask).concat( + group == "test" ? ["common:slice:watch", "common:css:watch", "common:js:watch", "html:watch"] : + ["common:css:watch", "common:js:watch"].concat(Object.keys(minDemos).map(minDemoWatchTaskName)))); + + gulp.task(group + ":clean", subprojects[group].map(groupCleanTask).concat( + group == "test" ? subprojects.test.map(testHtmlCleanTask).concat(["common:slice:clean"]) : + ["demo_Ice_minimal:min:clean", "demo_ChatDemo:min:clean"])); + }); + + function demoTaskName(name) { return "demo_" + name.replace("/", "_"); } + function minDemoTaskName(name) { return demoTaskName(name) + ":min"; } + function minDemoWatchTaskName(name) { return minDemoTaskName(name) + ":watch"; } + function minDemoCleanTaskName(name) { return minDemoTaskName(name) + ":clean"; } + + Object.keys(minDemos).forEach( + function(name) + { + var demo = minDemos[name]; + + gulp.task(minDemoTaskName(name), [demoTaskName(name)], + function() + { + return gulp.src(demo.srcs) + .pipe(newer(path.join(demo.dest, "Client.min.js"))) + .pipe(concat("Client.min.js")) + .pipe(uglify()) + .pipe(gulp.dest(demo.dest)) + .pipe(gzip()) + .pipe(gulp.dest(demo.dest)); + }); + + gulp.task(minDemoWatchTaskName(name), [minDemoTaskName(name)], + function() + { + gulp.watch(demo.srcs, [minDemoTaskName(name)]); + }); + + gulp.task(minDemoCleanTaskName(name), [], + function() + { + del([path.join(demo.dest, "Client.min.js"), + path.join(demo.dest, "Client.min.js.gz")]); + }); + }); +}; diff --git a/js/gulp/util.js b/js/gulp/util.js new file mode 100644 index 00000000000..ac17a3ad5f7 --- /dev/null +++ b/js/gulp/util.js @@ -0,0 +1,44 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +var path = require('path'); + +var gulpSlice2js = require("./gulp-slice2js"); +var sliceDir = path.resolve(__dirname, '..', '..', 'slice'); + +var useBinDist = process.env.USE_BIN_DIST == "yes"; + +function getSliceArgs(options) +{ + var defaults = {}; + var opts = options || {}; + + defaults.args = opts.args || []; + defaults.dest = opts.dest; + + if(useBinDist) + { + defaults.exe = undefined; + } + else + { + defaults.args = defaults.args.concat(["-I" + sliceDir]); + defaults.exe = opts.exe || path.resolve( + path.join("../cpp/bin", process.platform == "win32" ? "slice2js.exe" : "slice2js")); + } + return defaults; +} + +function slice2js(options) { + return gulpSlice2js.compile(getSliceArgs(options)); +} + +module.exports.useBinDist = useBinDist; +module.exports.slice2js = slice2js; +module.exports.sliceDir = sliceDir; |