UNPKG

@nodearch/cli

Version:
112 lines (111 loc) 4.34 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; import path from 'node:path'; import { Command, QuestionType } from '@nodearch/command'; import { Logger } from '@nodearch/core'; import { NpmService } from './npm.service.js'; import { CodeGenerator } from '@nodearch/blueprints'; let NewCommand = class NewCommand { constructor(npmService, logger) { this.npmService = npmService; this.logger = logger; this.command = 'new'; this.describe = 'Generate new NodeArch app'; this.aliases = 'n'; this.builder = { name: { alias: 'n', describe: 'Your project name' }, template: { alias: 't', describe: 'Template to download' }, description: { alias: 'd', describe: 'Project description' } }; this.questions = [ { type: QuestionType.INPUT, name: 'name', message: 'Your project name?', validate: (input) => { if (!input) { return 'Project name is required'; } return true; } }, { type: QuestionType.INPUT, name: 'description', message: 'Project description', validate: (input) => { if (!input) { return 'Project description is required'; } return true; } }, { type: QuestionType.LIST, name: 'template', message: 'Select an app template', choices: ['Standard', 'Express'] } ]; } async handler(options) { try { const appName = options.name.toLowerCase().replace(/\s+/g, '-'); const distPath = path.join(process.cwd(), appName); this.logger.info(`Generating a new app [${appName}] from the template [${options.template}]`); const codeGenerator = new CodeGenerator(); switch (options.template) { case 'Standard': await codeGenerator.app({ appName: appName, appDescription: options.description, extensions: { mocha: true } }, distPath); break; case 'Express': await codeGenerator.app({ appName: appName, appDescription: options.description, extensions: { express: true, mocha: true } }, distPath); break; default: this.logger.error('Invalid template selected'); return; } this.logger.info('Installing template dependencies [Running npm i]'); await this.npmService.install(distPath); this.logger.info('Initialization is complete. Your app is now ready to go, have fun!'); } catch (e) { this.logger.error('Couldn\'t create your app', e.message); } } }; NewCommand = __decorate([ Command(), __metadata("design:paramtypes", [NpmService, Logger]) ], NewCommand); export { NewCommand };