UNPKG

@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
#!/usr/bin/env node 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);