UNPKG

@toptal/davinci-code

Version:

Code generation package for frontend applications

22 lines (21 loc) 1.05 kB
import kebabCase from 'lodash.kebabcase' import camelCase from 'lodash.camelcase' import { print, createArgument } from '@toptal/davinci-cli-shared' import templates from '../templates.mjs' import { CORE_MODULE } from '../constants.mjs' export const createNewCommand = (program) => { return program .createCommand("new", { isDefault: true }) .description('Generate a component') .action((templateName, name, moduleName) => { const componentName = camelCase(name) const componentModuleName = kebabCase(moduleName) const template = camelCase(templateName) print.header('Creating new', componentName, 'in the module', componentModuleName, 'with template', template) templates.generate(template, componentName, componentModuleName) print.success('Done!') }) .addArgument(createArgument('<templateName>', 'Name of template: component, page etc.')) .addArgument(createArgument('<name>', 'Name of a folder')) .addArgument(createArgument('[moduleName]', 'Module where a new folder will be created').default(CORE_MODULE)) }