mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 03:47:50 +00:00
Add Hash util and split out file helper.
This commit is contained in:
36
lib/common/file.js
Normal file
36
lib/common/file.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var _ = require('lodash'),
|
||||||
|
fs = require('fs-extra'),
|
||||||
|
glob = require('glob'),
|
||||||
|
path = require('path');
|
||||||
|
|
||||||
|
var minify = require('../common/minify.js');
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
function copy(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));
|
||||||
|
result[key] = _.template(fs.readFileSync(filePath, 'utf8'));
|
||||||
|
}, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
function min(srcPath, destPath) {
|
||||||
|
return _.partial(minify, srcPath, destPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
function write(filePath, data) {
|
||||||
|
return _.partial(fs.writeFile, filePath, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
'copy': copy,
|
||||||
|
'globTemplate': globTemplate,
|
||||||
|
'min': min,
|
||||||
|
'write': write
|
||||||
|
};
|
||||||
9
lib/common/mapping.js
Normal file
9
lib/common/mapping.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var _mapping = require('../../fp/_mapping'),
|
||||||
|
util = require('./util'),
|
||||||
|
Hash = util.Hash;
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
module.exports = new Hash(_mapping);
|
||||||
@@ -1,4 +1,11 @@
|
|||||||
module.exports = {
|
'use strict';
|
||||||
|
|
||||||
|
var util = require('./util'),
|
||||||
|
Hash = util.Hash;
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
module.exports = new Hash({
|
||||||
'compress': {
|
'compress': {
|
||||||
'pure_getters': true,
|
'pure_getters': true,
|
||||||
'unsafe': true,
|
'unsafe': true,
|
||||||
@@ -13,4 +20,4 @@ module.exports = {
|
|||||||
'comments': /^!|@cc_on|@license|@preserve/i,
|
'comments': /^!|@cc_on|@license|@preserve/i,
|
||||||
'max_line_len': 500
|
'max_line_len': 500
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|||||||
@@ -1,36 +1,27 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _ = require('lodash'),
|
var _ = require('lodash');
|
||||||
fs = require('fs-extra'),
|
|
||||||
glob = require('glob'),
|
|
||||||
path = require('path');
|
|
||||||
|
|
||||||
var minify = require('../common/minify.js');
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
function copyFile(srcPath, destPath) {
|
/**
|
||||||
return _.partial(fs.copy, srcPath, destPath);
|
* Creates a hash object. If a `properties` object is provided, its own
|
||||||
|
* enumerable properties are assigned to the created object.
|
||||||
|
*
|
||||||
|
* @memberOf util
|
||||||
|
* @param {Object} [properties] The properties to assign to the object.
|
||||||
|
* @returns {Object} Returns the new hash object.
|
||||||
|
*/
|
||||||
|
function Hash(properties) {
|
||||||
|
return _.transform(properties, function(result, value, key) {
|
||||||
|
result[key] = (_.isPlainObject(value) && !(value instanceof Hash))
|
||||||
|
? new Hash(value)
|
||||||
|
: value;
|
||||||
|
}, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
function globTemplate(pattern) {
|
Hash.prototype = Object.create(null);
|
||||||
return _.transform(glob.sync(pattern), function(result, filePath) {
|
|
||||||
var key = path.basename(filePath, path.extname(filePath));
|
|
||||||
result[key] = _.template(fs.readFileSync(filePath, 'utf8'));
|
|
||||||
}, {});
|
|
||||||
}
|
|
||||||
|
|
||||||
function minFile(srcPath, destPath) {
|
|
||||||
return _.partial(minify, srcPath, destPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
function writeFile(filePath, data) {
|
|
||||||
return _.partial(fs.writeFile, filePath, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
'copyFile': copyFile,
|
'Hash': Hash
|
||||||
'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 util = require('../common/util');
|
var file = require('../common/file');
|
||||||
|
|
||||||
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),
|
||||||
util.minFile(path.join(distPath, filename))
|
file.min(path.join(distPath, filename))
|
||||||
], onComplete);
|
], onComplete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,13 @@
|
|||||||
|
|
||||||
var _ = require('lodash'),
|
var _ = require('lodash'),
|
||||||
fs = require('fs-extra'),
|
fs = require('fs-extra'),
|
||||||
path = require('path'),
|
path = require('path');
|
||||||
util = require('../common/util');
|
|
||||||
|
|
||||||
var mapping = require('../../fp/_mapping'),
|
var file = require('../common/file'),
|
||||||
templatePath = path.join(__dirname, 'template/doc'),
|
mapping = require('../common/mapping');
|
||||||
template = util.globTemplate(path.join(templatePath, '*.jst'));
|
|
||||||
|
var templatePath = path.join(__dirname, 'template/doc'),
|
||||||
|
template = file.globTemplate(path.join(templatePath, '*.jst'));
|
||||||
|
|
||||||
var argNames = ['a', 'b', 'c', 'd'];
|
var argNames = ['a', 'b', 'c', 'd'];
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ var _ = require('lodash'),
|
|||||||
glob = require('glob'),
|
glob = require('glob'),
|
||||||
path = require('path');
|
path = require('path');
|
||||||
|
|
||||||
var util = require('../common/util');
|
var file = require('../common/file'),
|
||||||
|
mapping = require('../common/mapping');
|
||||||
|
|
||||||
var mapping = require('../../fp/_mapping'),
|
var templatePath = path.join(__dirname, 'template/modules'),
|
||||||
templatePath = path.join(__dirname, 'template/modules'),
|
template = file.globTemplate(path.join(templatePath, '*.jst'));
|
||||||
template = util.globTemplate(path.join(templatePath, '*.jst'));
|
|
||||||
|
|
||||||
var aryMethods = _.union(
|
var aryMethods = _.union(
|
||||||
mapping.aryMethod[1],
|
mapping.aryMethod[1],
|
||||||
@@ -105,14 +105,14 @@ 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 util.writeFile(path.join(fpPath, moduleName + '.js'), getTemplate(moduleName));
|
return file.write(path.join(fpPath, moduleName + '.js'), getTemplate(moduleName));
|
||||||
});
|
});
|
||||||
|
|
||||||
actions.unshift(util.copyFile(path.join(__dirname, '../../fp'), fpPath));
|
actions.unshift(file.copy(path.join(__dirname, '../../fp'), fpPath));
|
||||||
actions.push(util.writeFile(path.join(fpPath, '_falseOptions.js'), template._falseOptions()));
|
actions.push(file.write(path.join(fpPath, '_falseOptions.js'), template._falseOptions()));
|
||||||
actions.push(util.writeFile(path.join(fpPath, '_util.js'), template._util()));
|
actions.push(file.write(path.join(fpPath, '_util.js'), template._util()));
|
||||||
actions.push(util.writeFile(path.join(target, 'fp.js'), template.fp()));
|
actions.push(file.write(path.join(target, 'fp.js'), template.fp()));
|
||||||
actions.push(util.writeFile(path.join(fpPath, 'convert.js'), template.convert()));
|
actions.push(file.write(path.join(fpPath, 'convert.js'), template.convert()));
|
||||||
|
|
||||||
async.series(actions, onComplete);
|
async.series(actions, onComplete);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ var _ = require('lodash'),
|
|||||||
async = require('async'),
|
async = require('async'),
|
||||||
path = require('path');
|
path = require('path');
|
||||||
|
|
||||||
var util = require('../common/util');
|
var file = require('../common/file');
|
||||||
|
|
||||||
var basePath = path.join(__dirname, '..', '..'),
|
var basePath = path.join(__dirname, '..', '..'),
|
||||||
distPath = path.join(basePath, 'dist'),
|
distPath = path.join(basePath, 'dist'),
|
||||||
@@ -23,8 +23,8 @@ function onComplete(error) {
|
|||||||
|
|
||||||
function build() {
|
function build() {
|
||||||
async.series([
|
async.series([
|
||||||
util.copyFile(baseLodash, distLodash),
|
file.copy(baseLodash, distLodash),
|
||||||
util.minFile(distLodash)
|
file.min(distLodash)
|
||||||
], onComplete);
|
], onComplete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ var _ = require('lodash'),
|
|||||||
async = require('async'),
|
async = require('async'),
|
||||||
path = require('path');
|
path = require('path');
|
||||||
|
|
||||||
var util = require('../common/util');
|
var file = require('../common/file');
|
||||||
|
|
||||||
var basePath = path.join(__dirname, '..', '..'),
|
var basePath = path.join(__dirname, '..', '..'),
|
||||||
distPath = path.join(basePath, 'dist');
|
distPath = path.join(basePath, 'dist');
|
||||||
@@ -25,7 +25,7 @@ function onComplete(error) {
|
|||||||
|
|
||||||
function build(target) {
|
function build(target) {
|
||||||
var actions = _.map(filePairs, function(pair) {
|
var actions = _.map(filePairs, function(pair) {
|
||||||
return util.copyFile(pair[0], path.join(target, pair[1]));
|
return file.copy(pair[0], path.join(target, pair[1]));
|
||||||
});
|
});
|
||||||
|
|
||||||
async.series(actions, onComplete);
|
async.series(actions, onComplete);
|
||||||
|
|||||||
Reference in New Issue
Block a user