@avleon/cli
Version:
> **🚧 This project is in active development.** > > It is **not stable** and **not ready** for live environments. > Use **only for testing, experimentation, or internal evaluation**. > > ####❗ Risks of using this in production: > > - 🔄 Breaking changes
61 lines (60 loc) • 2.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PathExtractor = PathExtractor;
function formatFileName(name) {
return name
.replace(/[_\s]+/g, "-")
.replace(/([a-z])([A-Z])/g, "$1-$2")
.replace(/((-|_|\.)+(Controller|Service|Model))|(Controller|Service|Model)/gi, "")
.toLowerCase();
}
function formatClassName(name) {
return name
.replace(/[_\s-]+/g, " ")
.replace(/([a-z])([A-Z])/g, "$1 $2")
.toLowerCase()
.replace(/\b\w/g, (char) => char.toUpperCase())
.replace(/\s+/g, "");
}
function PathExtractor(givenPath, options) {
let pathSplits = givenPath.split("/");
let splitSize = pathSplits.length;
let hasSubDirectory = splitSize > 0;
let name = hasSubDirectory ? pathSplits[splitSize - 1] : pathSplits[0];
let className = formatClassName(name);
let fileType = "any";
let isRest = false;
let isForced = false;
if (options.includes("make:controller") || options.includes("m:c")) {
fileType = "controller";
className = name.toLowerCase().replace(/controller|Controller/g, "");
}
if (options.includes("make:model") || options.includes("m:m")) {
fileType = "model";
className = name.toLowerCase().replace(/controller|Controller/g, "");
}
if (options.includes("make:service") || options.includes("m:s")) {
fileType = "service";
className = name.toLowerCase().replace(/controller|Controller/g, "");
}
if (options.includes("make:util") || options.includes("m:u")) {
fileType = "util";
className = name.toLowerCase().replace(/controller|Controller/g, "");
}
if (options.includes("make:config")) {
fileType = "config";
className = name.toLowerCase().replace(/controller|Controller/g, "");
}
if (options.includes("--rest") || options.includes("-r")) {
isRest = true;
className = name.toLowerCase().replace(/controller|Controller/g, "");
}
if (options.includes("--force") || options.includes("-f")) {
isForced = true;
className = name.toLowerCase().replace(/controller|Controller/g, "");
}
let outputFileName = formatFileName(name);
let outputPath = givenPath + "." + fileType + ".ts";
return {};
}