(argv: ArgumentsResolver<CommandParameters>)
| 209 | } |
| 210 | |
| 211 | async function valdiNewModule(argv: ArgumentsResolver<CommandParameters>) { |
| 212 | console.log(referenceString); |
| 213 | const skipChecks = argv.getArgument('skipChecks'); |
| 214 | |
| 215 | const checks: Checks = skipChecks ? {} : await promptChecks(); |
| 216 | const valdiModulePath = checks.valdiModulePath ?? path.join(await getBazelWorkspaceRoot(), 'modules'); |
| 217 | |
| 218 | let moduleName = await getModuleName(argv); |
| 219 | |
| 220 | // Validate module name if provided via command line argument |
| 221 | if (argv.getArgument('moduleName')) { |
| 222 | const validationError = validateProjectName(moduleName); |
| 223 | if (validationError) { |
| 224 | throw new CliError(validationError); |
| 225 | } |
| 226 | moduleName = sanitizeProjectName(moduleName); |
| 227 | } |
| 228 | |
| 229 | const destPath = path.join(valdiModulePath, moduleName); |
| 230 | const didConfirm = skipChecks || (await finalConfirmation(destPath, argv)); |
| 231 | if (!didConfirm) { |
| 232 | throw new CliError('Cancelled new module creation.'); |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Do not overwrite existing files |
| 237 | */ |
| 238 | if (fs.existsSync(destPath)) { |
| 239 | throw new CliError(`Path already exists ${destPath}`); |
| 240 | } |
| 241 | |
| 242 | const choices: CliChoice<ModuleTemplate>[] = ALL_MODULE_TEMPLATES.map(target => ({ |
| 243 | name: `${wrapInColor(target.name, ANSI_COLORS.GREEN_COLOR)} . ${target.description}`, |
| 244 | value: target, |
| 245 | })); |
| 246 | |
| 247 | const templateOption = argv.getArgument('template'); |
| 248 | const template = templateOption ? ALL_MODULE_TEMPLATES.find(template => template.path === templateOption) : undefined; |
| 249 | const moduleTemplate = template ?? await getUserChoice(choices, `Please choose the module type:`); |
| 250 | |
| 251 | /** |
| 252 | * Copy bootstrap files |
| 253 | */ |
| 254 | const sourcePath = path.join(BOOTSTRAP_DIR_PATH, 'modules', moduleTemplate.path); |
| 255 | const replacements: Replacements = { |
| 256 | MODULE_NAME: moduleName, |
| 257 | MODULE_NAME_PASCAL_CASED: toPascalCase(moduleName), |
| 258 | }; |
| 259 | |
| 260 | copyBootstrapFiles(sourcePath, destPath, replacements); |
| 261 | |
| 262 | // Finalize message |
| 263 | console.log(`Success! New module directory: ${wrapInColor(destPath, ANSI_COLORS.GREEN_COLOR)}`); |
| 264 | } |
| 265 | |
| 266 | export const command = `new_module [module-name]`; |
| 267 | export const describe = referenceString; |
nothing calls this directly
no test coverage detected