Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
jondot committed Mar 24, 2018
1 parent 1594480 commit de21ec5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
5 changes: 0 additions & 5 deletions lib/bin.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
#!/usr/bin/env node
const path = require('path');

const _require = require('./index'),
runner = _require.runner;

const defaultTemplates = path.join(__dirname, '../src/templates');

const Logger = require('./logger');

runner(process.argv.slice(2), {
templates: defaultTemplates,
cwd: process.cwd(),
logger: new Logger(console.log.bind(console)),
debug: !!process.env.DEBUG,
Expand Down
18 changes: 11 additions & 7 deletions lib/config-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ const L = require('lodash');

const fs = require('fs-extra');

const path = require('path');

const resolver = new _config.ConfigResolver('.hygen.js', {
const configResolver = new _config.ConfigResolver('.hygen.js', {
exists: fs.exists,
// $FlowFixMe
load: f => Promise.resolve(require(f)),
none: f => ({})
});
const templateResolver = new _config.ConfigResolver('_templates', {
exists: fs.exists,
// $FlowFixMe
load: f => Promise.resolve(require(f))
load: f => f,
none: f => null
});

module.exports =
Expand All @@ -24,11 +29,10 @@ function () {
var _ref = _asyncToGenerator(function* (config) {
const cwd = config.cwd,
templates = config.templates;
const fileConfig = yield resolver.resolve(cwd);
const resolvedTemplates = L.find([process.env.HYGEN_TMPLS, path.join(cwd, '_templates')], _ => fs.existsSync(_)) || templates;
const resolvedTemplates = L.find([process.env.HYGEN_TMPLS, yield templateResolver.resolve(cwd)], _ => _ && fs.existsSync(_)) || templates;
return _extends({}, config, {
templates: resolvedTemplates
}, fileConfig);
}, (yield configResolver.resolve(cwd)));
});

return function (_x) {
Expand Down
5 changes: 3 additions & 2 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class ConfigResolver {
const configCandidates = configLookup(_this.configFile, from);
const _this$io = _this.io,
exists = _this$io.exists,
load = _this$io.load;
load = _this$io.load,
none = _this$io.none;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
Expand Down Expand Up @@ -75,7 +76,7 @@ class ConfigResolver {
}
}

return {};
return yield none(from);
})();
}

Expand Down
22 changes: 22 additions & 0 deletions lib/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,28 @@ const help = templates => {

const printHelp = (templates, logger) => {
logger.log('\nAvailable actions:');

if (!templates) {
logger.log(`No generators or actions found.
This means I didn't find a _templates folder right here,
or anywhere up the folder tree starting here.
Here's how to start using Hygen:
$ hygen init self
$ hygen with-prompt new --name my-generator
(edit your generator in _templates/my-generator)
$ hygen my-generator
See http://hygen.io for more.
`);
return;
}

L.each(help(templates), (v, k) => {
logger.log(chalk.bold(k) + ': ' + v.join(', '));
});
Expand Down

0 comments on commit de21ec5

Please sign in to comment.