mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 18:17:48 +00:00
Add copyFile, minFile, and writeFile to lib/common/util.js.
This commit is contained in:
@@ -4,23 +4,23 @@ var _ = require('lodash'),
|
|||||||
fs = require('fs-extra'),
|
fs = require('fs-extra'),
|
||||||
uglify = require('uglify-js');
|
uglify = require('uglify-js');
|
||||||
|
|
||||||
var uglifyOptions = require('./uglify.options.js');
|
var uglifyOptions = require('./uglify.options');
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
function minify(inpath, outpath, callback, options) {
|
function minify(srcPath, destPath, callback, options) {
|
||||||
if (_.isFunction(outpath)) {
|
if (_.isFunction(destPath)) {
|
||||||
if (_.isObject(callback)) {
|
if (_.isObject(callback)) {
|
||||||
options = callback;
|
options = callback;
|
||||||
}
|
}
|
||||||
callback = outpath;
|
callback = destPath;
|
||||||
outpath = undefined;
|
destPath = undefined;
|
||||||
}
|
}
|
||||||
if (!outpath) {
|
if (!destPath) {
|
||||||
outpath = inpath.replace(/(?=\.js$)/, '.min');
|
destPath = srcPath.replace(/(?=\.js$)/, '.min');
|
||||||
}
|
}
|
||||||
var output = uglify.minify(inpath, _.defaults(options || {}, uglifyOptions));
|
var output = uglify.minify(srcPath, _.defaults(options || {}, uglifyOptions));
|
||||||
fs.writeFile(outpath, output.code, 'utf-8', callback);
|
fs.writeFile(destPath, output.code, 'utf-8', callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = minify;
|
module.exports = minify;
|
||||||
|
|||||||
@@ -5,8 +5,14 @@ var _ = require('lodash'),
|
|||||||
glob = require('glob'),
|
glob = require('glob'),
|
||||||
path = require('path');
|
path = require('path');
|
||||||
|
|
||||||
|
var minify = require('../common/minify.js');
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
function copyFile(srcPath, destPath) {
|
||||||
|
return _.partial(fs.copy, srcPath, destPath);
|
||||||
|
}
|
||||||
|
|
||||||
function globTemplate(pattern) {
|
function globTemplate(pattern) {
|
||||||
return _.transform(glob.sync(pattern), function(result, filePath) {
|
return _.transform(glob.sync(pattern), function(result, filePath) {
|
||||||
var key = path.basename(filePath, path.extname(filePath));
|
var key = path.basename(filePath, path.extname(filePath));
|
||||||
@@ -14,6 +20,17 @@ function globTemplate(pattern) {
|
|||||||
}, {});
|
}, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function minFile(srcPath, destPath) {
|
||||||
|
return _.partial(minify, srcPath, destPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeFile(filePath, data) {
|
||||||
|
return _.partial(fs.writeFile, filePath, data);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
'globTemplate': globTemplate
|
'copyFile': copyFile,
|
||||||
|
'globTemplate': globTemplate,
|
||||||
|
'minFile': minFile,
|
||||||
|
'writeFile': writeFile
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ var _ = require('lodash'),
|
|||||||
path = require('path'),
|
path = require('path'),
|
||||||
webpack = require('webpack');
|
webpack = require('webpack');
|
||||||
|
|
||||||
var minify = require('../common/minify.js');
|
var util = require('../common/util');
|
||||||
|
|
||||||
var basePath = path.join(__dirname, '..', '..'),
|
var basePath = path.join(__dirname, '..', '..'),
|
||||||
distPath = path.join(basePath, 'dist'),
|
distPath = path.join(basePath, 'dist'),
|
||||||
@@ -48,7 +48,7 @@ function build() {
|
|||||||
async.series([
|
async.series([
|
||||||
_.partial(webpack, mappingConfig),
|
_.partial(webpack, mappingConfig),
|
||||||
_.partial(webpack, fpConfig),
|
_.partial(webpack, fpConfig),
|
||||||
_.partial(minify, path.join(distPath, filename))
|
util.minFile(path.join(distPath, filename))
|
||||||
], onComplete);
|
], onComplete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
var _ = require('lodash'),
|
var _ = require('lodash'),
|
||||||
async = require('async'),
|
async = require('async'),
|
||||||
fs = require('fs-extra'),
|
|
||||||
glob = require('glob'),
|
glob = require('glob'),
|
||||||
path = require('path'),
|
path = require('path');
|
||||||
util = require('../common/util');
|
|
||||||
|
var util = require('../common/util');
|
||||||
|
|
||||||
var mapping = require('../../fp/_mapping'),
|
var mapping = require('../../fp/_mapping'),
|
||||||
templatePath = path.join(__dirname, 'template/modules'),
|
templatePath = path.join(__dirname, 'template/modules'),
|
||||||
@@ -40,10 +40,6 @@ var ignored = [
|
|||||||
'lodash.js'
|
'lodash.js'
|
||||||
];
|
];
|
||||||
|
|
||||||
function copyFile(srcPath, destPath) {
|
|
||||||
return _.partial(fs.copy, srcPath, destPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isAlias(funcName) {
|
function isAlias(funcName) {
|
||||||
return _.has(mapping.aliasToReal, funcName);
|
return _.has(mapping.aliasToReal, funcName);
|
||||||
}
|
}
|
||||||
@@ -74,10 +70,6 @@ function getTemplate(moduleName) {
|
|||||||
return template.module(data);
|
return template.module(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeFile(filePath, data) {
|
|
||||||
return _.partial(fs.writeFile, filePath, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
function onComplete(error) {
|
function onComplete(error) {
|
||||||
@@ -112,13 +104,13 @@ function build(target) {
|
|||||||
|
|
||||||
var actions = modulePaths.map(function(modulePath) {
|
var actions = modulePaths.map(function(modulePath) {
|
||||||
var moduleName = path.basename(modulePath, '.js');
|
var moduleName = path.basename(modulePath, '.js');
|
||||||
return writeFile(path.join(fpPath, moduleName + '.js'), getTemplate(moduleName));
|
return util.writeFile(path.join(fpPath, moduleName + '.js'), getTemplate(moduleName));
|
||||||
});
|
});
|
||||||
|
|
||||||
actions.unshift(copyFile(path.join(__dirname, '../../fp'), fpPath));
|
actions.unshift(util.copyFile(path.join(__dirname, '../../fp'), fpPath));
|
||||||
actions.push(writeFile(path.join(target, 'fp.js'), template.fp()));
|
actions.push(util.writeFile(path.join(target, 'fp.js'), template.fp()));
|
||||||
actions.push(writeFile(path.join(fpPath, 'convert.js'), template.convert()));
|
actions.push(util.writeFile(path.join(fpPath, 'convert.js'), template.convert()));
|
||||||
actions.push(writeFile(path.join(fpPath, '_util.js'), template._util()));
|
actions.push(util.writeFile(path.join(fpPath, '_util.js'), template._util()));
|
||||||
|
|
||||||
async.series(actions, onComplete);
|
async.series(actions, onComplete);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,9 @@
|
|||||||
|
|
||||||
var _ = require('lodash'),
|
var _ = require('lodash'),
|
||||||
async = require('async'),
|
async = require('async'),
|
||||||
fs = require('fs-extra'),
|
|
||||||
path = require('path');
|
path = require('path');
|
||||||
|
|
||||||
var minify = require('../common/minify.js');
|
var util = require('../common/util');
|
||||||
|
|
||||||
var basePath = path.join(__dirname, '..', '..'),
|
var basePath = path.join(__dirname, '..', '..'),
|
||||||
distPath = path.join(basePath, 'dist'),
|
distPath = path.join(basePath, 'dist'),
|
||||||
@@ -24,8 +23,8 @@ function onComplete(error) {
|
|||||||
|
|
||||||
function build() {
|
function build() {
|
||||||
async.series([
|
async.series([
|
||||||
_.partial(fs.copy, baseLodash, distLodash),
|
util.copyFile(baseLodash, distLodash),
|
||||||
_.partial(minify, distLodash)
|
util.minFile(distLodash)
|
||||||
], onComplete);
|
], onComplete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user