3 var _ = require('lodash'),
4 async = require('async'),
5 glob = require('glob'),
6 path = require('path');
8 var file = require('../common/file'),
9 mapping = require('../common/mapping');
11 var templatePath = path.join(__dirname, 'template/modules'),
12 template = file.globTemplate(path.join(templatePath, '*.jst'));
14 var aryMethods = _.union(
45 function isAlias(funcName) {
46 return _.has(mapping.aliasToReal, funcName);
49 function isCategory(funcName) {
50 return _.includes(categories, funcName);
53 function isThru(funcName) {
54 return !_.includes(aryMethods, funcName);
57 function getTemplate(moduleName) {
59 'name': _.result(mapping.aliasToReal, moduleName, moduleName),
63 if (isAlias(moduleName)) {
64 return template.alias(data);
66 if (isCategory(moduleName)) {
67 return template.category(data);
69 if (isThru(moduleName)) {
70 return template.thru(data);
72 return template.module(data);
75 /*----------------------------------------------------------------------------*/
77 function onComplete(error) {
83 function build(target) {
84 target = path.resolve(target);
86 var fpPath = path.join(target, 'fp');
88 // Glob existing lodash module paths.
89 var modulePaths = glob.sync(path.join(target, '*.js'), {
91 'ignore': ignored.map(function(filename) {
92 return path.join(target, filename);
96 // Add FP alias and remapped module paths.
97 _.each([mapping.aliasToReal, mapping.remap], function(data) {
98 _.forOwn(data, function(realName, alias) {
99 var modulePath = path.join(target, alias + '.js');
100 if (!_.includes(modulePaths, modulePath)) {
101 modulePaths.push(modulePath);
106 var actions = modulePaths.map(function(modulePath) {
107 var moduleName = path.basename(modulePath, '.js');
108 return file.write(path.join(fpPath, moduleName + '.js'), getTemplate(moduleName));
111 actions.unshift(file.copy(path.join(__dirname, '../../fp'), fpPath));
112 actions.push(file.write(path.join(fpPath, '_falseOptions.js'), template._falseOptions()));
113 actions.push(file.write(path.join(fpPath, '_util.js'), template._util()));
114 actions.push(file.write(path.join(target, 'fp.js'), template.fp()));
115 actions.push(file.write(path.join(fpPath, 'convert.js'), template.convert()));
117 async.series(actions, onComplete);
120 build(_.last(process.argv));