-
Notifications
You must be signed in to change notification settings - Fork 1
/
armory
65 lines (55 loc) · 1.98 KB
/
armory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env node
require("module-alias/register");
const { Command } = require("commander");
const chalk = require("chalk");
const path = require("path");
const fs = require("fs");
class Armory {
static program = new Command();
static version = "1.0.0";
static getTimestamp() {
const now = new Date();
return `${now.toISOString().replace("T", " ").split(".")[0]}`;
}
static logWithTimestamp(message, color = "white") {
const timestamp = Armory.getTimestamp();
console.log(chalk[color](`[${timestamp}] ${message}`));
}
static showLoading = async (message, action) => {
const ora = (await import("ora")).default;
const spinner = ora(message).start();
try {
await action();
spinner.succeed("Completed!");
} catch (error) {
spinner.fail("Failed!");
this.logWithTimestamp(error, "red");
}
};
static configFilePath = path.resolve(process.cwd(), "zentinel.config.js");
static modelsDir = path.resolve(process.cwd(), "app/models");
static controllersDir = path.resolve(process.cwd(), "app/controllers");
static routesDir = path.resolve(process.cwd(), "app/routes");
static validationsDir = path.resolve(process.cwd(), "app/validations");
static middlewaresDir = path.resolve(process.cwd(), "app/middlewares");
static servicesDir = path.resolve(process.cwd(), "app/services");
static utilitiesDir = path.resolve(process.cwd(), "app/utilities");
static exceptionsDir = path.resolve(process.cwd(), "app/exceptions");
}
Armory.program
.version(Armory.version)
.description("Armory CLI - A Node.js tool similar to Laravel's Artisan");
const consoleDir = path.join(__dirname, "console");
fs.readdirSync(consoleDir).forEach((file) => {
if (path.extname(file) === ".js") {
const filePath = path.join(consoleDir, file);
require(filePath)(Armory);
}
});
Armory.program.arguments("").action((unknownCommand) => {
Armory.logWithTimestamp(`Invalid command: ${unknownCommand}`, "red");
});
Armory.program.parse(process.argv);
if (process.argv.length <= 2) {
Armory.program.help();
}