mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +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'),
|
||||
uglify = require('uglify-js');
|
||||
|
||||
var uglifyOptions = require('./uglify.options.js');
|
||||
var uglifyOptions = require('./uglify.options');
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
function minify(inpath, outpath, callback, options) {
|
||||
if (_.isFunction(outpath)) {
|
||||
function minify(srcPath, destPath, callback, options) {
|
||||
if (_.isFunction(destPath)) {
|
||||
if (_.isObject(callback)) {
|
||||
options = callback;
|
||||
}
|
||||
callback = outpath;
|
||||
outpath = undefined;
|
||||
callback = destPath;
|
||||
destPath = undefined;
|
||||
}
|
||||
if (!outpath) {
|
||||
outpath = inpath.replace(/(?=\.js$)/, '.min');
|
||||
if (!destPath) {
|
||||
destPath = srcPath.replace(/(?=\.js$)/, '.min');
|
||||
}
|
||||
var output = uglify.minify(inpath, _.defaults(options || {}, uglifyOptions));
|
||||
fs.writeFile(outpath, output.code, 'utf-8', callback);
|
||||
var output = uglify.minify(srcPath, _.defaults(options || {}, uglifyOptions));
|
||||
fs.writeFile(destPath, output.code, 'utf-8', callback);
|
||||
}
|
||||
|
||||
module.exports = minify;
|
||||
|
||||
@@ -5,8 +5,14 @@ var _ = require('lodash'),
|
||||
glob = require('glob'),
|
||||
path = require('path');
|
||||
|
||||
var minify = require('../common/minify.js');
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
function copyFile(srcPath, destPath) {
|
||||
return _.partial(fs.copy, srcPath, destPath);
|
||||
}
|
||||
|
||||
function globTemplate(pattern) {
|
||||
return _.transform(glob.sync(pattern), function(result, 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 = {
|
||||
'globTemplate': globTemplate
|
||||
'copyFile': copyFile,
|
||||
'globTemplate': globTemplate,
|
||||
'minFile': minFile,
|
||||
'writeFile': writeFile
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user