Update of multiple frontend libs.

This commit is contained in:
baldo 2017-05-13 13:25:33 +02:00
commit a9c6ddc03b
276 changed files with 41257 additions and 19300 deletions

View file

@ -1,24 +1,25 @@
'use strict';
var _ = require('lodash'),
async = require('async'),
glob = require('glob'),
path = require('path');
const _ = require('lodash');
const async = require('async');
const glob = require('glob');
const path = require('path');
var file = require('../common/file'),
mapping = require('../common/mapping');
const file = require('../common/file');
const mapping = require('../common/mapping');
const util = require('../common/util');
var templatePath = path.join(__dirname, 'template/modules'),
template = file.globTemplate(path.join(templatePath, '*.jst'));
const templatePath = path.join(__dirname, 'template/modules');
const template = file.globTemplate(path.join(templatePath, '*.jst'));
var aryMethods = _.union(
const aryMethods = _.union(
mapping.aryMethod[1],
mapping.aryMethod[2],
mapping.aryMethod[3],
mapping.aryMethod[4]
);
var categories = [
const categories = [
'array',
'collection',
'date',
@ -32,7 +33,7 @@ var categories = [
'util'
];
var ignored = [
const ignored = [
'_*.js',
'core.js',
'core.min.js',
@ -42,21 +43,50 @@ var ignored = [
'lodash.min.js'
];
function isAlias(funcName) {
return _.has(mapping.aliasToReal, funcName);
/**
* Checks if `name` is a method alias.
*
* @private
* @param {string} name The name to check.
* @returns {boolean} Returns `true` if `name` is a method alias, else `false`.
*/
function isAlias(name) {
return _.has(mapping.aliasToReal, name);
}
function isCategory(funcName) {
return _.includes(categories, funcName);
/**
* Checks if `name` is a category name.
*
* @private
* @param {string} name The name to check.
* @returns {boolean} Returns `true` if `name` is a category name, else `false`.
*/
function isCategory(name) {
return _.includes(categories, name);
}
function isThru(funcName) {
return !_.includes(aryMethods, funcName);
/**
* Checks if `name` belongs to a method that's passed thru and not wrapped.
*
* @private
* @param {string} name The name to check.
* @returns {boolean} Returns `true` if `name` is of a pass thru method,
* else `false`.
*/
function isThru(name) {
return !_.includes(aryMethods, name);
}
/**
* Gets metadata for `func`.
*
* @private
* @param {Function} func The function to query.
* @returns {*} Returns the metadata for `func`.
*/
function getTemplate(moduleName) {
var data = {
'name': _.result(mapping.aliasToReal, moduleName, moduleName),
const data = {
'name': _.get(mapping.aliasToReal, moduleName, moduleName),
'mapping': mapping
};
@ -74,37 +104,37 @@ function getTemplate(moduleName) {
/*----------------------------------------------------------------------------*/
function onComplete(error) {
if (error) {
throw error;
}
}
/**
* Creates FP modules at the `target` path.
*
* @private
* @param {string} target The output directory path.
*/
function build(target) {
target = path.resolve(target);
var fpPath = path.join(target, 'fp');
const fpPath = path.join(target, 'fp');
// Glob existing lodash module paths.
var modulePaths = glob.sync(path.join(target, '*.js'), {
const modulePaths = glob.sync(path.join(target, '*.js'), {
'nodir': true,
'ignore': ignored.map(function(filename) {
'ignore': ignored.map(filename => {
return path.join(target, filename);
})
});
// Add FP alias and remapped module paths.
_.each([mapping.aliasToReal, mapping.remap], function(data) {
_.forOwn(data, function(realName, alias) {
var modulePath = path.join(target, alias + '.js');
_.each([mapping.aliasToReal, mapping.remap], data => {
_.forOwn(data, (realName, alias) => {
const modulePath = path.join(target, alias + '.js');
if (!_.includes(modulePaths, modulePath)) {
modulePaths.push(modulePath);
}
});
});
var actions = modulePaths.map(function(modulePath) {
var moduleName = path.basename(modulePath, '.js');
const actions = modulePaths.map(modulePath => {
const moduleName = path.basename(modulePath, '.js');
return file.write(path.join(fpPath, moduleName + '.js'), getTemplate(moduleName));
});
@ -114,7 +144,7 @@ function build(target) {
actions.push(file.write(path.join(target, 'fp.js'), template.fp()));
actions.push(file.write(path.join(fpPath, 'convert.js'), template.convert()));
async.series(actions, onComplete);
async.series(actions, util.pitch);
}
build(_.last(process.argv));