mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
Add lib/common/util.
This commit is contained in:
18
lib/common/util.js
Normal file
18
lib/common/util.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var _ = require('lodash'),
|
||||||
|
fs = require('fs-extra'),
|
||||||
|
glob = require('glob'),
|
||||||
|
path = require('path');
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
function globTemplate(pattern) {
|
||||||
|
return _.transform(glob.sync(pattern), function(result, filePath) {
|
||||||
|
result[path.basename(filePath, path.extname(filePath))] = _.template(fs.readFileSync(filePath));
|
||||||
|
}, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
'globTemplate': globTemplate
|
||||||
|
};
|
||||||
@@ -4,15 +4,12 @@ var _ = require('lodash'),
|
|||||||
async = require('async'),
|
async = require('async'),
|
||||||
fs = require('fs-extra'),
|
fs = require('fs-extra'),
|
||||||
glob = require('glob'),
|
glob = require('glob'),
|
||||||
path = require('path');
|
path = require('path'),
|
||||||
|
util = require('../common/util');
|
||||||
|
|
||||||
var mapping = require('../../fp/_mapping');
|
var mapping = require('../../fp/_mapping'),
|
||||||
|
templatePath = path.join(__dirname, 'template/modules'),
|
||||||
var templatePath = path.join(__dirname, 'template/modules');
|
template = util.globTemplate(path.join(templatePath, '*.jst'));
|
||||||
|
|
||||||
var template = _.transform(glob.sync(path.join(templatePath, '*.jst')), function(result, filePath) {
|
|
||||||
result[path.basename(filePath, '.jst')] = _.template(fs.readFileSync(filePath));
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
var aryMethods = _.union(
|
var aryMethods = _.union(
|
||||||
mapping.aryMethod[1],
|
mapping.aryMethod[1],
|
||||||
@@ -35,6 +32,18 @@ var categories = [
|
|||||||
'util'
|
'util'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
var ignored = [
|
||||||
|
'_*.js',
|
||||||
|
'core.js',
|
||||||
|
'fp.js',
|
||||||
|
'index.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);
|
||||||
}
|
}
|
||||||
@@ -65,6 +74,10 @@ 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) {
|
||||||
@@ -79,13 +92,7 @@ function build(target) {
|
|||||||
// Glob existing lodash module paths.
|
// Glob existing lodash module paths.
|
||||||
var modulePaths = glob.sync(path.join(target, '*.js'), {
|
var modulePaths = glob.sync(path.join(target, '*.js'), {
|
||||||
'nodir': true,
|
'nodir': true,
|
||||||
'ignore': [
|
'ignore': ignored.map(function(filename) {
|
||||||
'_*.js',
|
|
||||||
'core.js',
|
|
||||||
'fp.js',
|
|
||||||
'index.js',
|
|
||||||
'lodash.js'
|
|
||||||
].map(function(filename) {
|
|
||||||
return path.join(target, filename);
|
return path.join(target, filename);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@@ -103,13 +110,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 _.partial(fs.writeFile, path.join(fpPath, moduleName + '.js'), getTemplate(moduleName));
|
return writeFile(path.join(fpPath, moduleName + '.js'), getTemplate(moduleName));
|
||||||
});
|
});
|
||||||
|
|
||||||
actions.unshift(_.partial(fs.copy, path.join(__dirname, '../../fp'), fpPath));
|
actions.unshift(copyFile(path.join(__dirname, '../../fp'), fpPath));
|
||||||
actions.push(_.partial(fs.writeFile, path.join(target, 'fp.js'), template.fp()));
|
actions.push(writeFile(path.join(target, 'fp.js'), template.fp()));
|
||||||
actions.push(_.partial(fs.writeFile, path.join(fpPath, 'convert.js'), template.convert()));
|
actions.push(writeFile(path.join(fpPath, 'convert.js'), template.convert()));
|
||||||
actions.push(_.partial(fs.writeFile, path.join(fpPath, '_util.js'), template._util()));
|
actions.push(writeFile(path.join(fpPath, '_util.js'), template._util()));
|
||||||
|
|
||||||
async.series(actions, onComplete);
|
async.series(actions, onComplete);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user