Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
jondot committed Mar 14, 2018
1 parent 0156a99 commit fc27d32
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
12 changes: 6 additions & 6 deletions lib/ops/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
const add = require('./add');

const inject = require('./inject');

const shell = require('./shell');

const resolve = attributes => {
const ops = [];

if (attributes.to && !attributes.inject) {
const add = require('./add');

ops.push(add);
}

if (attributes.to && attributes.inject) {
const inject = require('./inject');

ops.push(inject);
}

if (attributes.sh) {
const shell = require('./shell');

ops.push(shell);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function () {
subaction = _L$split2[1];

const actionfolder = path.join(templates, generator, mainAction);
const promptArgs = yield prompt(actionfolder);
const promptArgs = yield prompt(actionfolder, L.omit(argv, ['_']));
const args = Object.assign({
templates,
actionfolder,
Expand Down
35 changes: 24 additions & 11 deletions lib/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,39 @@ const path = require('path');

const fs = require('fs');

const prompt = actionfolder => {
const promptfile = path.join(actionfolder, 'prompt.js');
const L = require('lodash');

if (!fs.existsSync(promptfile)) {
const hooksfiles = ['prompt.js', 'index.js'];

const prompt = (actionfolder, args) => {
const hooksfile = L.first(L.filter(L.map(hooksfiles, f => path.join(actionfolder, f)), f => fs.existsSync(f)));
console.log(hooksfile);

if (!hooksfile) {
return Promise.resolve({});
} // shortcircuit without inquirer


const hooksModule = require(hooksfile);

if (hooksModule.params) {
return hooksModule.params({
args
});
} // lazy loads inquirer (80ms load time)
// $FlowFixMe
// everything below requires it


const inquirer = require('inquirer');

const promptModule = require(promptfile);

if (promptModule.prompt) {
return promptModule.prompt({
inquirer
if (hooksModule.prompt) {
return hooksModule.prompt({
inquirer,
args
});
} else {
return inquirer.prompt(promptModule);
}

return inquirer.prompt(hooksModule);
};

module.exports = prompt;
2 changes: 1 addition & 1 deletion lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const map = f => arr => L.map(arr, f);

const filter = f => arr => L.filter(arr, f);

const ignores = ['prompt.js'];
const ignores = ['prompt.js', 'index.js'];

const renderTemplate = (tmpl, locals) => L.isString(tmpl) ? ejs.render(tmpl, context(locals)) : tmpl;

Expand Down

0 comments on commit fc27d32

Please sign in to comment.