diff --git a/handlebars/helpers.js b/handlebars/helpers.js index 5016180..174e454 100644 --- a/handlebars/helpers.js +++ b/handlebars/helpers.js @@ -1,6 +1,12 @@ const path = require('path') const cp = require('child_process') -const _ = require('lodash') +const _ = { + escapeRegExp: require('lodash.escaperegexp'), + cloneDeep: require('lodash.clonedeep'), + isPlainObject: require('lodash.isplainobject'), + groupBy: require('lodash.groupby'), + map: require('lodash.map') +} const debug = require('debug')('thought:helpers') const Promise = require('bluebird') const glob = Promise.promisify(require('glob')) @@ -51,7 +57,7 @@ function json (obj) { function include (filename, language) { return qfs.read(filename).then(function (contents) { return '```' + - (_.isString(language) ? language : path.extname(filename).substr(1)) + + (typeof language === 'string' ? language : path.extname(filename).substr(1)) + '\n' + contents + '\n```\n' @@ -143,7 +149,7 @@ function exec (command, options) { start = end = '`' break default: - const fenceLanguage = _.isString(lang) ? lang : '' + const fenceLanguage = lang || '' start = '```' + fenceLanguage + '\n' end = '\n```' } @@ -165,7 +171,7 @@ function exec (command, options) { */ function dirTree (baseDir, globPattern, options) { // Is basedir is not a string, it is probably the handlebars "options" object - if (!_.isString(globPattern)) { + if (typeof globPattern !== 'string') { globPattern = '**' } @@ -413,20 +419,21 @@ function treeFromPathComponents (files, label) { if (files.length === 0) { return label } + + var byFirstPathComponent = _.groupBy(files, '0') + const result = { label: label, - nodes: _(files) - .groupBy('0') - .map(function (group, key) { - const values = group - .map(function (item) { - return item.slice(1) - }) - .filter(function (item) { - return item.length > 0 - }) - return treeFromPathComponents(values, key) - }).value() + nodes: _.map(byFirstPathComponent, function (group, key) { + const values = group + .map(function (item) { + return item.slice(1) + }) + .filter(function (item) { + return item.length > 0 + }) + return treeFromPathComponents(values, key) + }) } // Condense path if directory only has one entry diff --git a/lib/utils/exeq.js b/lib/utils/exeq.js index 6965953..be50b1a 100644 --- a/lib/utils/exeq.js +++ b/lib/utils/exeq.js @@ -5,10 +5,17 @@ * Released under the MIT license. */ var cp = require('child_process') -var Q = require('q') -var _ = require('lodash') /** * Call child_process.execFile with `{ encoding: utf-8 }` and return a promise of `[ stdout, stderr]` */ -module.exports = _.partial(Q.denodeify(cp.execFile), _, _, {encoding: 'utf-8'}) +module.exports = function (cmd, args) { + return new Promise(function (resolve, reject) { + return cp.execFile(cmd, args, function (err, stdout, stderr) { + if (err) { + return reject(err) + } + return resolve([stdout, stderr]) + }) + }) +} diff --git a/package.json b/package.json index e144e69..b022d47 100644 --- a/package.json +++ b/package.json @@ -35,13 +35,17 @@ "bluebird": "^3.5.0", "cheerio": "^0.22.0", "commander": "^2.8.1", - "customize": "^1.0.0", + "customize": "^2.0.0-alpha1", "customize-write-files": "^1.1.0", "debug": "^2.2.0", "find-package": "^1.0.0", "glob": "^7.0.5", "handlebars": "^4.0.5", - "lodash": "^4.13.1", + "lodash.clonedeep": "^4.5.0", + "lodash.escaperegexp": "^4.1.2", + "lodash.groupby": "^4.6.0", + "lodash.isplainobject": "^4.0.6", + "lodash.map": "^4.6.0", "m-io": "^0.5.0", "request": "^2.79.0", "request-promise": "^4.1.1",