node-ff
Version:
A CLI for creating NodeJs projects
61 lines • 1.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Check = void 0;
const errors_1 = require("../../errors");
class Check {
checkCommands({ commands, err }) {
const typeCommand = this.typeOf(commands);
const message = this.instanceOfError({ err });
if (typeCommand !== 'string' && typeCommand !== 'object') {
throw new errors_1.AppError(`Tipo ${typeCommand} inválido`);
}
else if (message.includes('not found')) {
throw new errors_1.AppError('Este comando não existe');
}
else {
throw new errors_1.AppError('O (diretorio/arquivo) já existe');
}
}
checkRead({ filename, directory }) {
this.readWrite({
filename,
directory,
});
}
checkWrite({ filename, text }) {
this.readWrite({
filename,
text,
});
}
readWrite({ filename, text, directory }) {
if (text) {
if (this.typeOf(text) !== 'string') {
throw new errors_1.AppError('O texto deve ser do tipo string');
}
}
if (directory) {
if (this.typeOf(directory) !== 'string') {
throw new errors_1.AppError('O diretório deve ser do tipo string');
}
}
if (this.typeOf(filename) !== 'string') {
throw new errors_1.AppError('O arquivo deve ser do tipo string');
}
else {
throw new errors_1.AppError('Erro de leitura, arquivo não encontrado!');
}
}
typeOf(value) {
return typeof value;
}
instanceOfError({ err }) {
let errorMessage = '';
if (err instanceof Error) {
errorMessage = err.message;
}
return errorMessage;
}
}
exports.Check = Check;
//# sourceMappingURL=index.js.map