summaryrefslogtreecommitdiff
path: root/support
diff options
context:
space:
mode:
authorAlexander Early <alexander.early@gmail.com>2017-04-09 18:10:06 -0700
committerAlexander Early <alexander.early@gmail.com>2017-04-16 12:26:41 -0700
commit70aa51c12b8009b5c899d855aa6185fc7303a4ef (patch)
tree2d7b5ba5d8e85a5c63294f6a57be347182e9763c /support
parent38f1440101f5b17d06dd90be358957a5619a980c (diff)
downloadasync-70aa51c12b8009b5c899d855aa6185fc7303a4ef.tar.gz
decouple compling modules and bundling
Diffstat (limited to 'support')
-rw-r--r--support/build/aggregate-build.js31
-rw-r--r--support/build/aggregate-bundle.js22
-rw-r--r--support/build/aggregate-cjs.js22
-rw-r--r--support/build/compile-modules.js28
-rw-r--r--support/build/modules-cjs.js4
5 files changed, 62 insertions, 45 deletions
diff --git a/support/build/aggregate-build.js b/support/build/aggregate-build.js
index 54ccf96..b3f04c5 100644
--- a/support/build/aggregate-build.js
+++ b/support/build/aggregate-build.js
@@ -1,20 +1,17 @@
-const compileModules = require('./compile-modules');
const {rollup} = require('rollup');
-const rimraf = require('rimraf/rimraf');
-module.exports = function buildBundle(options) {
- function bundle() {
- rollup({
- entry: options.outpath + '/index.js'
- }).then(function ( bundle ) {
- bundle.write({
- format: options.format,
- moduleName: 'async',
- dest: options.outfile
- });
- rimraf.sync(options.outpath);
- }).catch(console.error);
- }
-
- compileModules(bundle, options);
+module.exports = function buildBundle(options, cb) {
+ const {format, entriesPath, outfile} = options;
+ return rollup({
+ entry: entriesPath + '/index.js'
+ })
+ .then(function ( bundle ) {
+ return bundle.write({
+ format,
+ moduleName: 'async',
+ dest: outfile
+ });
+ })
+ .then(() => cb())
+ .catch(cb);
}
diff --git a/support/build/aggregate-bundle.js b/support/build/aggregate-bundle.js
index a933033..78b1e7e 100644
--- a/support/build/aggregate-bundle.js
+++ b/support/build/aggregate-bundle.js
@@ -1,9 +1,17 @@
const aggregateBuild = require('./aggregate-build');
+const compileModules = require('./compile-modules');
+const {series} = require('async');
+const outpath = 'build/modules-for-umd';
-aggregateBuild({
- es6: true,
- outpath:'build/build-modules-es6',
- outfile: 'build/dist/async.js',
- format: 'umd',
- lodashRename: true
-});
+series([
+ compileModules.bind(null, {
+ es6: true,
+ outpath,
+ lodashRename: true
+ }),
+ aggregateBuild.bind(null, {
+ entriesPath: outpath,
+ outfile: 'build/dist/async.js',
+ format: 'umd',
+ })
+], err => { if (err) throw err; })
diff --git a/support/build/aggregate-cjs.js b/support/build/aggregate-cjs.js
index 4b6896f..a5c60b8 100644
--- a/support/build/aggregate-cjs.js
+++ b/support/build/aggregate-cjs.js
@@ -1,9 +1,17 @@
const aggregateBuild = require('./aggregate-build');
+const compileModules = require('./compile-modules');
+const {series} = require('async');
+const outpath = 'build/modules-for-cjs';
-aggregateBuild({
- es6: true,
- outpath:'build/build-modules-es6',
- outfile: 'build/index.js',
- format: 'cjs',
- lodashRename: false
-});
+series([
+ compileModules.bind(null, {
+ es6: true,
+ outpath,
+ lodashRename: false
+ }),
+ aggregateBuild.bind(null, {
+ entriesPath: outpath,
+ outfile: 'build/index.js',
+ format: 'cjs',
+ })
+], err => { if (err); throw err; });
diff --git a/support/build/compile-modules.js b/support/build/compile-modules.js
index 00e7381..583f83d 100644
--- a/support/build/compile-modules.js
+++ b/support/build/compile-modules.js
@@ -8,14 +8,15 @@ const pluginLodashImportRename = require('./plugin-lodash-import-rename');
const joinPath = require('path').join;
const fs = require('fs-extra');
-module.exports = function(cb, options) {
+module.exports = function(options, cb) {
options = _.defaults({}, options, {
- path:'lib/',
- outpath:'build',
+ path: 'lib/',
+ outpath: 'build',
es6: false,
lodashRename: false
});
- let plugins = [];
+ const plugins = [];
+ const { path, outpath } = options;
if (options.lodashRename) {
plugins.push(pluginLodashImportRename);
@@ -25,20 +26,21 @@ module.exports = function(cb, options) {
plugins.push(pluginCJS);
}
- readdirR(options.path, [], function(err, files) {
- fs.emptyDirSync(options.outpath);
- fs.emptyDirSync(joinPath(options.outpath, 'internal'));
+ readdirR(path, [], (err, files) => {
+ fs.emptyDirSync(outpath);
+ fs.emptyDirSync(joinPath(outpath, 'internal'));
async.each(files, (file, callback) => {
- let filename = file.startsWith(options.path) ?
- file.slice(options.path.length) :
- file;
transformFile(file, {
babelrc: false,
plugins: plugins
- }, function(err, content) {
- let outpath = joinPath(options.outpath, filename);
- fs.writeFile(outpath, content.code, callback);
+ }, (err, content) => {
+ if (err) { return callback(err); }
+ const outfile = file.startsWith(path) ?
+ file.slice(path.length) :
+ file;
+ const finalPath = joinPath(outpath, outfile);
+ fs.writeFile(finalPath, content.code, callback);
});
}, cb);
});
diff --git a/support/build/modules-cjs.js b/support/build/modules-cjs.js
index 3ae9a8b..e131a42 100644
--- a/support/build/modules-cjs.js
+++ b/support/build/modules-cjs.js
@@ -1,3 +1,5 @@
const compileModules = require('./compile-modules');
-compileModules(function() {}, {es6: false});
+compileModules({
+ es6: false
+}, err => { if (err) throw err; });