UNPKG

@clea/cli

Version:

CLI tool for AngularJS & Typescript projects

73 lines (57 loc) 2.21 kB
const program = require('commander'), chalk = require('chalk'), debug = require('debug')('clea-generate'), packageFile = require('../package.json'), logger = require('../vendors/logger'), Project = require('../lib/project'), project = Project.getInstance(), Blueprints = require('../lib/blueprints/blueprints'), Generate = require('../lib/commands/generate'), { options } = require('../lib/commands-options/clea-generate'), Command = require('../lib/utilities/command'); program .version(packageFile.version) .arguments('[blueprint] [name]'); Command.addOptions(program, options); program .action((blueprint, name, options) => { project.init().then(() => { if (project.clea && project.clea.type === Project.TYPE.LIBRARY) { logger.error('ERROR: Generation is disabled in library mode.'); process.exit(1); } if (!Blueprints.types.includes(blueprint) && !Blueprints.types.includes(name)) { logger.error(`"${blueprint}" blueprint is not allowed. ${chalk.blue.bold('clea help generate')} to see allowed blueprints.`); process.exit(1); } // HACK blueprint & name aren't always well ordered. Don't know why ... let tmp = name; name = (Blueprints.types.includes(name)) ? blueprint : name; blueprint = (Blueprints.types.includes(tmp)) ? tmp : blueprint; if (name === undefined) { logger.error(`The ${chalk.blue('clea generate ' + blueprint)} command requires a name to be specified.`); process.exit(1); } try { Generate.create(blueprint, name, { component: options.withComponent, lazyLoad : options.lazyLoad }).catch((err) => { debug(err); logger.error(err.message); process.exit(1); }); } catch (err) { debug(err); logger.error(err.message); process.exit(1); } }, (err) => logger.error(err)); }); program.on('--help', () => { logger.help(' Arguments:'); logger.help(''); logger.help(` [blueprint] ${Blueprints.types.join(', ')}`); logger.help(' [name] name of the new component'); }); program.parse(process.argv);