@ibernoh/arkanjs
Version:
Backend API generator with RBAC, CLI scaffolding, and built-in structure. Just install and run.
137 lines (120 loc) โข 3.69 kB
JavaScript
import { program } from "commander";
import { initProject } from "../scripts/initProject.js";
import { generateAuth } from "../scripts/generateAuth.js";
import { generateResource } from "../scripts/generateResource.js";
import { generateResourceAuth } from "../scripts/generateResourceAuth.js";
import { cleanAuth } from "../scripts/cleanAuth.js";
import { cleanResourceAuth } from "../scripts/cleanResourceAuth.js";
import { execSync } from "child_process";
import { reverseModels } from "../scripts/reverseModels.js";
import fs from "fs";
import path from "path";
program
.name("arkanjs")
.description("๐ฅ ArkanJS CLI โ vertical framework with JWT and RBAC")
.version("1.0.0");
//
// ๐ฏ Initialization
//
program
.command("new <name>")
.description("๐ฆ Create a new ArkanJS project")
.option("--no-docs", "Skip Doc.md and /doc route")
.action((name, options) => {
initProject({ noDocs: options.noDocs, nomeProjeto: name });
});
//
// ๐ Resource Generation
//
program
.command("make:resource <name>")
.description("๐ Generate public resource (model, controller and route)")
.option("--fields <fields>", "Format: name:string,isActive:boolean")
.action((name, options) => {
generateResource(name, options.fields);
});
program
.command("make:resource-auth <name>")
.description("๐ Generate protected resource with JWT + role")
.option("--fields <fields>", "Format: title:string,done:boolean")
.action((name, options) => {
generateResourceAuth(name, options.fields);
});
//
// ๐ Auth System
//
program
.command("make:auth")
.description("๐ก๏ธ Generate full JWT authentication system with RBAC")
.action(() => {
generateAuth();
});
//
// ๐งน Clean Commands
//
program
.command("clean:auth")
.description("๐งจ Remove all authentication files and folders")
.action(() => {
cleanAuth();
});
program
.command("clean:resource-auth <name>")
.description("๐งผ Remove protected resource files and folders")
.action((name) => {
cleanResourceAuth(name);
});
//
// ๐งฑ Database Commands
//
program
.command("make:migration <name>")
.description("๐ฆ Create a new migration file")
.action((name) => {
execSync(`npx sequelize-cli migration:generate --name ${name}`, { stdio: "inherit" });
});
program
.command("make:seed <name>")
.description("๐ฑ Create a new seed file")
.action((name) => {
execSync(`npx sequelize-cli seed:generate --name ${name}`, { stdio: "inherit" });
});
program
.command("migrate")
.description("๐งฑ Run all pending database migrations")
.action(() => {
execSync(`npx sequelize-cli db:migrate`, { stdio: "inherit" });
});
program
.command("seed")
.description("๐ฟ Run all seed files")
.action(() => {
execSync(`npx sequelize-cli db:seed:all`, { stdio: "inherit" });
});
program
.command("reverse")
.description("๐ฅ Reverse-engineer models from existing database")
.action(() => {
reverseModels();
});
//
// ๐ Dynamic List
//
program
.command("list")
.description("๐ List all generated resources")
.action(() => {
const modelsPath = path.resolve("src/models");
if (!fs.existsSync(modelsPath)) return console.log("โ ๏ธ No resources found.");
const folders = fs.readdirSync(modelsPath).filter(folder => {
return folder !== "auth" && fs.statSync(path.join(modelsPath, folder)).isDirectory();
});
if (!folders.length) {
console.log("๐ No resources created yet.");
} else {
console.log("๐ Existing resources:");
folders.forEach(name => console.log(" โข " + name));
}
});
program.parse(process.argv);