UNPKG

@quadnix/octo-build

Version:

Octo-Build is a CLI tool to build Octo projects.

62 lines 2.4 kB
import { dirname, resolve } from 'path'; import { fileURLToPath } from 'url'; import chalk from 'chalk'; import { createEnv } from 'yeoman-environment'; import { StringUtility } from '../../utilities/string/string.utility.js'; const __dirname = dirname(fileURLToPath(import.meta.url)); export const createModuleCommand = { builder: (yargs) => { return yargs .option('name', { alias: 'n', demandOption: true, description: 'Name of the module to create. Should be in kebab-case (e.g., my-awesome-region).', type: 'string', }) .option('type', { alias: 't', choices: StringUtility.AVAILABLE_MODEL_TYPES, demandOption: true, description: 'Type of model this module is for.', type: 'string', }) .option('package', { demandOption: true, description: 'Package name for the module.', type: 'string', }) .option('path', { alias: 'p', default: '.', description: 'Root directory path of the CDK.', type: 'string', }); }, command: 'create-module', describe: 'Create a new Octo module.', handler: async (argv) => { const { name, package: packageName, path, type } = argv; // Validate module name format (should be kebab-case) if (!StringUtility.isKebabCase(name)) { console.error(chalk.red('Module name must be in kebab-case format (e.g., my-awesome-region)')); process.exit(1); } console.log(chalk.blue(`Creating module "${name}" of type "${type}"...`)); const env = createEnv(); env.register(resolve(__dirname, 'generator-octo-module-template/generators/app/index.js'), { namespace: 'generator-octo-module-template:app', }); try { await env.run(['generator-octo-module-template:app', name, type, packageName, path], { skipCache: true, skipInstall: true, }); console.log(chalk.green(`Successfully created module!`)); } catch (error) { console.error(chalk.red(`Failed to create module! ${error.message}`)); process.exit(1); } }, }; //# sourceMappingURL=create-module.command.js.map