@tsclean/scaffold
Version:
This CLI creates an initial structure of a project based on clean architecture.
62 lines • 2.68 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommandCreateAdapterSimple = void 0;
const ora_1 = __importDefault(require("ora"));
const paths_1 = require("../utils/paths");
const messages_1 = require("../utils/messages");
const CommandUtils_1 = require("./CommandUtils");
const constants_1 = require("../utils/constants");
const helpers_1 = require("../utils/helpers");
const emojis_1 = require("../utils/emojis");
class CommandCreateAdapterSimple {
constructor() {
this.command = "create:adapter";
this.describe = "Generate a new adapter";
}
builder(args) {
return args
.option("name", {
alias: "n",
describe: "Name the adapter",
demandOption: true
});
}
async handler(args) {
let spinner;
try {
setTimeout(async () => spinner = (0, ora_1.default)(constants_1.CONSTANTS.INSTALLING).start(), 1000);
const basePath = paths_1.PATHS.BASE_PATH_ADAPTER_SIMPLE();
const filename = paths_1.PATHS.FILE_NAME_ADAPTER_SIMPLE(args.name);
// The path for the validation of the file input is made up.
const path = `${basePath}${filename}`;
// We validate if the file exists, to throw the exception.
const fileExists = await CommandUtils_1.CommandUtils.fileExists(path);
// Throw message exception
if (fileExists)
throw messages_1.MESSAGES.FILE_EXISTS(path);
// Adapter
await CommandUtils_1.CommandUtils.createFile(paths_1.PATHS.PATH_ADAPTER_SIMPLE(args.name), CommandCreateAdapterSimple.getRepositoryAdapter(args.name));
setTimeout(() => {
spinner.succeed(constants_1.CONSTANTS.INSTALLATION_COMPLETED);
spinner.stopAndPersist({
symbol: emojis_1.EMOJIS.ROCKET,
text: `${messages_1.MESSAGES.FILE_SUCCESS(constants_1.CONSTANTS.ADAPTER, paths_1.PATHS.PATH_ADAPTER_SIMPLE(args.name))}`
});
}, 2000);
}
catch (error) {
(0, helpers_1.errorMessage)(error, constants_1.CONSTANTS.ADAPTER);
}
}
static getRepositoryAdapter(name) {
const _param = CommandUtils_1.CommandUtils.capitalizeString(name);
return `export class ${_param}Adapter {
// Implementation
}`;
}
}
exports.CommandCreateAdapterSimple = CommandCreateAdapterSimple;
//# sourceMappingURL=CommandCreateAdapterSimple.js.map