From 1eab4f5f0720363fc746fa509e4dd45962dc7b3d Mon Sep 17 00:00:00 2001 From: Mark Ethan Trostler Date: Fri, 10 Jul 2015 17:43:30 -0700 Subject: [PATCH] feat(license): include license files in dev and dev.sfx bundles --- gulpfile.js | 20 +++++++++++++++++++- tools/build/licensewrap.js | 12 ++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tools/build/licensewrap.js diff --git a/gulpfile.js b/gulpfile.js index 2fe69353b2..3ac02c625b 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -16,6 +16,7 @@ var madge = require('madge'); var merge = require('merge'); var merge2 = require('merge2'); var path = require('path'); +var licenseWrap = require('./tools/build/licensewrap'); var watch = require('./tools/build/watch'); @@ -951,13 +952,29 @@ gulp.task('bundle.js.min.deps', ['bundle.js.min'], function() { }); var JS_DEV_DEPS = [ + licenseWrap('node_modules/zone.js/LICENSE', true), 'node_modules/zone.js/dist/zone-microtask.js', 'node_modules/zone.js/dist/long-stack-trace-zone.js', - 'node_modules/reflect-metadata/Reflect.js' + licenseWrap('node_modules/reflect-metadata/LICENSE', true), + 'node_modules/reflect-metadata/Reflect.js', + // traceur-runtime is always first in the bundle + licenseWrap('node_modules/traceur/LICENSE', true) ]; +// Splice in RX license if rx is in the bundle. +function insertRXLicense(source) { + var n = source.indexOf('System.register("rx"'); + if (n >= 0) { + var rxLicense = licenseWrap('node_modules/rx/license.txt'); + return source.slice(0, n) + rxLicense + source.slice(n); + } else { + return source; + } +} + gulp.task('bundle.js.dev.deps', ['bundle.js.dev'], function() { return bundler.modify(JS_DEV_DEPS.concat(['dist/build/angular2.dev.js']), 'angular2.dev.js') + .pipe(insert.transform(insertRXLicense)) .pipe(insert.append('\nSystem.config({"paths":{"*":"*.js","angular2/*":"angular2/*"}});\n')) .pipe(gulp.dest('dist/bundle')); }); @@ -965,6 +982,7 @@ gulp.task('bundle.js.dev.deps', ['bundle.js.dev'], function() { gulp.task('bundle.js.sfx.dev.deps', ['bundle.js.sfx.dev'], function() { return bundler.modify(JS_DEV_DEPS.concat(['dist/build/angular2.sfx.dev.js']), 'angular2.sfx.dev.js') + .pipe(insert.transform(insertRXLicense)) .pipe(gulp.dest('dist/bundle')); }); diff --git a/tools/build/licensewrap.js b/tools/build/licensewrap.js new file mode 100644 index 0000000000..3d87830070 --- /dev/null +++ b/tools/build/licensewrap.js @@ -0,0 +1,12 @@ +var fs = require('fs'); +module.exports = function(licenseFile, outputFile) { + var licenseText = fs.readFileSync(licenseFile); + var license = "/**\n @license\n" + licenseText + "\n */\n"; + if (outputFile) { + outputFile = licenseFile + '.wrapped'; + fs.writeFileSync(outputFile, license, 'utf8'); + return outputFile; + } else { + return license; + } +};