From ac16bc0e15bc7e3524ebac82f3c94dd8539dd0b4 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 22 Oct 2015 21:06:08 -0700 Subject: [PATCH] Update build scripts. --- lib/common/minify.js | 23 +++++++++++++++++++++ lib/common/uglify.options.js | 16 +++++++++++++++ lib/fp/build.js | 40 ++++++++---------------------------- lib/main/build.js | 27 ++++++++++++++++++++++++ package.json | 2 ++ 5 files changed, 77 insertions(+), 31 deletions(-) create mode 100644 lib/common/minify.js create mode 100644 lib/common/uglify.options.js diff --git a/lib/common/minify.js b/lib/common/minify.js new file mode 100644 index 000000000..cf30679be --- /dev/null +++ b/lib/common/minify.js @@ -0,0 +1,23 @@ +'use strict'; + +var _ = require('lodash'), + fs = require('fs-extra'), + uglify = require('uglify-js'); + +var uglifyOptions = require('./uglify.options.js'); + +/*----------------------------------------------------------------------------*/ + +function minify(inpath, outpath, callback, options) { + if (typeof outpath == 'function') { + outpath = undefined; + callback = options; + } + if (!outpath) { + outpath = inpath.replace(/(?=\.js$)/, '.min'); + } + var output = uglify.minify(inpath, _.defaults(options, uglifyOptions)); + fs.writeFile(outpath, output.code, 'utf-8', callback); +} + +module.exports = minify; diff --git a/lib/common/uglify.options.js b/lib/common/uglify.options.js new file mode 100644 index 000000000..9c8c339e1 --- /dev/null +++ b/lib/common/uglify.options.js @@ -0,0 +1,16 @@ +module.exports = { + 'mangle': true, + 'compress': { + 'comparisons': false, + 'keep_fargs': true, + 'pure_getters': true, + 'unsafe': true, + 'unsafe_comps': true, + 'warnings': false + }, + 'output': { + 'ascii_only': true, + 'beautify': false, + 'max_line_len': 500 + } +}; diff --git a/lib/fp/build.js b/lib/fp/build.js index 4cc217a61..daf160a34 100644 --- a/lib/fp/build.js +++ b/lib/fp/build.js @@ -2,19 +2,21 @@ var _ = require('lodash'), async = require('async'), - fs = require('fs'), + fs = require('fs-extra'), path = require('path'), - uglify = require('uglify-js'), webpack = require('webpack'); -var entryPath = path.join(__dirname, 'bower.js'), - outputPath = path.join(__dirname, '..', '..', 'dist'), +var minify = require('../common/minify.js'); + +var basePath = path.join(__dirname, '..', '..'), + distPath = path.join(basePath, 'dist'), + entryPath = path.join(__dirname, 'bower.js'), filename = 'lodash.fp.js'; var webpackConfig = { 'entry': entryPath, 'output': { - 'path': outputPath, + 'path': distPath, 'filename': filename, 'library': 'fp', 'libraryTarget': 'umd' @@ -23,34 +25,10 @@ var webpackConfig = { new webpack.optimize.OccurenceOrderPlugin, new webpack.optimize.DedupePlugin ] -} - -var uglifyConfig = { - 'mangle': true, - 'compress': { - 'comparisons': false, - 'keep_fargs': true, - 'pure_getters': true, - 'unsafe': true, - 'unsafe_comps': true, - 'warnings': false - }, - 'output': { - 'ascii_only': true, - 'beautify': false, - 'max_line_len': 500 - } -} +}; /*----------------------------------------------------------------------------*/ -function minify(inputPath, callback) { - var output = uglify.minify(inputPath, uglifyConfig), - outputPath = inputPath.replace(/(?=\.js$)/, '.min'); - - fs.writeFile(outputPath, output.code, 'utf-8', callback); -} - function onComplete(error) { if (error) { throw error; @@ -59,5 +37,5 @@ function onComplete(error) { async.series([ _.partial(webpack, webpackConfig), - _.partial(minify, path.join(outputPath, filename)) + _.partial(minify, path.join(distPath, filename)) ], onComplete); diff --git a/lib/main/build.js b/lib/main/build.js index ad9a93a7c..1f5a88359 100644 --- a/lib/main/build.js +++ b/lib/main/build.js @@ -1 +1,28 @@ 'use strict'; + +var _ = require('lodash'), + async = require('async'), + fs = require('fs-extra'), + path = require('path'); + +var minify = require('../common/minify.js'); + +var basePath = path.join(__dirname, '..', '..'), + distPath = path.join(basePath, 'dist'), + filename = 'lodash.js'; + +var baseLodash = path.join(basePath, filename), + distLodash = path.join(distPath, filename); + +/*----------------------------------------------------------------------------*/ + +function onComplete(error) { + if (error) { + throw error; + } +} + +async.series([ + _.partial(fs.copy, baseLodash, distLodash), + _.partial(minify, distLodash) +], onComplete); diff --git a/package.json b/package.json index 82e4a11c8..4c9abeaca 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "docdown": "0.3.0", "dojo": "~1.10.0", "ecstatic": "^1.1.3", + "fs-extra": "~0.24.0", "istanbul": "0.4.0", "jquery": "~1.11.0", "jscs": "^2.3.5", @@ -25,6 +26,7 @@ "webpack": "^1.12.2" }, "scripts": { + "build": "node lib/main/build.js && node lib/fp/build.js", "style": "jscs lodash.js", "test": "node test/test" },