From 320c089dccdfb1b1b1dfbc6039f3a595d49b30b7 Mon Sep 17 00:00:00 2001 From: Yegor Jbanov Date: Mon, 9 Feb 2015 14:02:11 -0800 Subject: [PATCH] feat(packaging): automatically copy LICENSE to dist folders --- gulpfile.js | 30 ++++++++++++++++++++++++++++-- tools/build/multicopy.js | 26 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 tools/build/multicopy.js diff --git a/gulpfile.js b/gulpfile.js index b2fc8edd67..b2ae0a1bc9 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -14,6 +14,7 @@ var dartanalyzer = require('./tools/build/dartanalyzer'); var jsserve = require('./tools/build/jsserve'); var pubserve = require('./tools/build/pubserve'); var rundartpackage = require('./tools/build/rundartpackage'); +var multicopy = require('./tools/build/multicopy'); var karma = require('karma').server; var minimist = require('minimist'); @@ -177,6 +178,9 @@ var CONFIG = { pubspec: { src: 'modules/*/pubspec.yaml' }, + license: { + src: 'LICENSE' + }, formatDart: { packageName: 'dart_style', args: ['dart_style:format', '-w', 'dist/dart'] @@ -293,6 +297,25 @@ gulp.task('build/html.dart', html(gulp, gulpPlugins, { scriptsPerFolder: CONFIG.html.scriptsPerFolder.dart })); +// ------------ +// license + +gulp.task('build/license.js.dev', multicopy(gulp, gulpPlugins, { + src: CONFIG.license.src, + dest: CONFIG.dest.js.dev +})); + +gulp.task('build/license.js.prod', multicopy(gulp, gulpPlugins, { + src: CONFIG.license.src, + dest: CONFIG.dest.js.prod +})); + +gulp.task('build/license.dart', multicopy(gulp, gulpPlugins, { + src: CONFIG.license.src, + dest: CONFIG.dest.dart +})); + + // ------------ // pubspec @@ -454,6 +477,7 @@ gulp.task('build.dart', function() { return runSequence( ['build/deps.js.dart2js', 'build/transpile.dart', 'build/html.dart'], 'build/pubspec.dart', + 'build/license.dart', 'build/pubbuild.dart', 'build/analyze.dart', 'build/format.dart' @@ -462,13 +486,15 @@ gulp.task('build.dart', function() { gulp.task('build.js.dev', function() { return runSequence( - ['build/deps.js.dev', 'build/transpile.js.dev', 'build/html.js.dev'] + ['build/deps.js.dev', 'build/transpile.js.dev', 'build/html.js.dev'], + 'build/license.js.dev' ); }); gulp.task('build.js.prod', function() { return runSequence( - ['build/deps.js.prod', 'build/transpile.js.prod', 'build/html.js.prod'] + ['build/deps.js.prod', 'build/transpile.js.prod', 'build/html.js.prod'], + 'build/license.js.prod' ); }); diff --git a/tools/build/multicopy.js b/tools/build/multicopy.js new file mode 100644 index 0000000000..28ec0661a1 --- /dev/null +++ b/tools/build/multicopy.js @@ -0,0 +1,26 @@ +/** + * A utility that allows copying one file to multiple directories, such + * as the LICENSE file. + */ +var path = require('path'); +var fs = require('fs'); + +module.exports = function(gulp, plugins, config) { + return function() { + var content = fs.readFileSync(config.src); + getSubdirs(config.dest).forEach(function(subDir) { + var destFile = path.join(config.dest, subDir, path.basename(config.src)); + fs.writeFileSync(destFile, content); + }); + }; +}; + +function getSubdirs(rootDir) { + return fs.readdirSync(rootDir).filter(function(file) { + if (file[0] === '.') { + return false; + } + var dirPath = path.join(rootDir, file); + return fs.statSync(dirPath).isDirectory(); + }); +}