@nodearch/cli
Version:
nodearch cli
95 lines (94 loc) • 3.63 kB
JavaScript
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 { Command, QuestionType } from '@nodearch/command';
import { CodeGenerator } from '@nodearch/blueprints';
import { Logger } from '@nodearch/core';
let CreateCommand = class CreateCommand {
constructor(logger) {
this.logger = logger;
this.command = 'create';
this.describe = 'Create a new NodeArch component';
this.availableTypes = ['Hook', 'Controller', 'Service', 'Repository', 'Component'];
this.builder = {
type: {
alias: 't',
describe: 'Component type',
choices: this.availableTypes
},
name: {
alias: 'n',
describe: 'Component name',
},
path: {
alias: 'p',
describe: 'Component directory path',
}
};
this.questions = [
{
type: QuestionType.LIST,
name: 'type',
message: 'Select a component type',
choices: this.availableTypes
},
{
type: QuestionType.INPUT,
name: 'name',
message: 'Enter the component name',
default: 'user',
validate: (input) => {
if (!input) {
return 'Component name is required';
}
return true;
}
},
{
type: QuestionType.INPUT,
name: 'path',
message: 'Enter the component directory path',
validate: (input) => {
if (!input) {
return 'Component directory path is required';
}
return true;
}
}
];
}
async handler(options) {
const codeGenerator = new CodeGenerator();
switch (options.type) {
case 'Hook':
await codeGenerator.hook(options.name, {}, options.path);
break;
case 'Controller':
await codeGenerator.controller(options.name, {}, options.path);
break;
case 'Service':
await codeGenerator.service(options.name, {}, options.path);
break;
case 'Repository':
await codeGenerator.repository(options.name, {}, options.path);
break;
case 'Component':
await codeGenerator.component(options.name, {}, options.path);
break;
default:
this.logger.error('Invalid component type');
break;
}
}
};
CreateCommand = __decorate([
Command(),
__metadata("design:paramtypes", [Logger])
], CreateCommand);
export { CreateCommand };