@arkstack/console 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/app.d.ts +18 -0
- package/dist/app.js +45 -0
- package/dist/app.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +221 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
package/README.md
ADDED
package/dist/app.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CliApp } from "resora";
|
|
2
|
+
|
|
3
|
+
//#region src/app.d.ts
|
|
4
|
+
interface ConsoleAppOptions {
|
|
5
|
+
stubsDir?: string;
|
|
6
|
+
}
|
|
7
|
+
declare const resolveStubsDir: (config: {
|
|
8
|
+
localStubsDir?: string;
|
|
9
|
+
} | undefined, options?: ConsoleAppOptions) => string;
|
|
10
|
+
declare class ArkstackConsoleApp<TCore> extends CliApp {
|
|
11
|
+
core: TCore;
|
|
12
|
+
private readonly options;
|
|
13
|
+
constructor(core: TCore, options: ConsoleAppOptions);
|
|
14
|
+
makeController: (name: string, opts: any) => string;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { ArkstackConsoleApp, ConsoleAppOptions, resolveStubsDir };
|
|
18
|
+
//# sourceMappingURL=app.d.ts.map
|
package/dist/app.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { isAbsolute, join } from "node:path";
|
|
2
|
+
import { CliApp } from "resora";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
|
|
5
|
+
//#region dist/app.js
|
|
6
|
+
const resolveStubsDir = (config, options) => {
|
|
7
|
+
const configuredDir = config?.localStubsDir;
|
|
8
|
+
if (configuredDir) return isAbsolute(configuredDir) ? configuredDir : join(process.cwd(), configuredDir);
|
|
9
|
+
return options?.stubsDir;
|
|
10
|
+
};
|
|
11
|
+
var ArkstackConsoleApp = class extends CliApp {
|
|
12
|
+
core;
|
|
13
|
+
options;
|
|
14
|
+
constructor(core, options) {
|
|
15
|
+
super();
|
|
16
|
+
this.core = core;
|
|
17
|
+
this.options = options;
|
|
18
|
+
}
|
|
19
|
+
makeController = (name, opts) => {
|
|
20
|
+
const normalized = name.endsWith("Controller") ? name.replace(/controller/i, "") : name;
|
|
21
|
+
const controllersDir = join(process.cwd(), "dist/app/http/controllers");
|
|
22
|
+
const controllerName = normalized.endsWith("Controller") ? normalized : `${normalized}Controller`;
|
|
23
|
+
const outputPath = join(controllersDir, `${controllerName}.js`);
|
|
24
|
+
const stubsDir = resolveStubsDir(this.config, this.options);
|
|
25
|
+
if (!stubsDir) {
|
|
26
|
+
console.error("Error: stubsDir is not configured. Set stubsDir in resora.config.js.");
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
const stubPath = join(stubsDir, opts.model ? this.config.stubs.model : opts.api ? this.config.stubs.api : this.config.stubs.controller);
|
|
30
|
+
if (!existsSync(stubPath)) {
|
|
31
|
+
console.error(`Error: Stub file ${stubPath} not found.`);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
this.generateFile(stubPath, outputPath, {
|
|
35
|
+
ControllerName: controllerName,
|
|
36
|
+
ModelName: opts.model?.camelCase(),
|
|
37
|
+
Name: controllerName.replace(/controller/i, "")
|
|
38
|
+
}, opts);
|
|
39
|
+
return outputPath;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { ArkstackConsoleApp, resolveStubsDir };
|
|
45
|
+
//# sourceMappingURL=app.js.map
|
package/dist/app.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.js","names":[],"sources":["../src/app.ts"],"sourcesContent":["// oxlint-disable typescript/no-explicit-any\nimport { isAbsolute, join } from \"node:path\";\n\nimport { CliApp } from \"resora\";\nimport { existsSync } from \"node:fs\";\n\nexport interface ConsoleAppOptions {\n stubsDir?: string;\n}\n\nexport const resolveStubsDir = (\n config: { localStubsDir?: string } | undefined,\n options?: ConsoleAppOptions,\n) => {\n const configuredDir = config?.localStubsDir;\n\n if (configuredDir) {\n return isAbsolute(configuredDir)\n ? configuredDir\n : join(process.cwd(), configuredDir);\n }\n\n return options?.stubsDir;\n};\n\nexport class ArkstackConsoleApp<TCore> extends CliApp {\n core: TCore;\n private readonly options: ConsoleAppOptions;\n\n constructor(\n core: TCore,\n options: ConsoleAppOptions,\n ) {\n super();\n this.core = core;\n this.options = options;\n }\n\n makeController = (name: string, opts: any) => {\n const normalized = name.endsWith(\"Controller\") ? name.replace(/controller/i, \"\") : name;\n\n const controllersDir = join(process.cwd(), \"src/app/http/controllers\");\n const controllerName = normalized.endsWith(\"Controller\") ? normalized : `${normalized}Controller`;\n const fileName = `${controllerName}.ts`;\n const outputPath = join(controllersDir, fileName);\n const stubsDir = resolveStubsDir(this.config as any, this.options);\n\n if (!stubsDir) {\n console.error(\"Error: stubsDir is not configured. Set stubsDir in resora.config.js.\");\n process.exit(1);\n }\n\n const stubPath = join(\n stubsDir,\n opts.model\n ? (this.config.stubs as any).model\n : opts.api\n ? (this.config.stubs as any).api\n : (this.config.stubs as any).controller,\n );\n\n if (!existsSync(stubPath)) {\n console.error(`Error: Stub file ${stubPath} not found.`);\n process.exit(1);\n }\n\n this.generateFile(\n stubPath,\n outputPath,\n {\n ControllerName: controllerName,\n ModelName: opts.model?.camelCase(),\n Name: controllerName.replace(/controller/i, \"\"),\n },\n opts,\n );\n\n return outputPath;\n };\n}\n"],"mappings":";;;;;AAUA,MAAa,mBACT,QACA,YACC;CACD,MAAM,gBAAgB,QAAQ;AAE9B,KAAI,cACA,QAAO,WAAW,cAAc,GAC1B,gBACA,KAAK,QAAQ,KAAK,EAAE,cAAc;AAG5C,QAAO,SAAS;;AAGpB,IAAa,qBAAb,cAA+C,OAAO;CAClD;CACA,AAAiB;CAEjB,YACI,MACA,SACF;AACE,SAAO;AACP,OAAK,OAAO;AACZ,OAAK,UAAU;;CAGnB,kBAAkB,MAAc,SAAc;EAC1C,MAAM,aAAa,KAAK,SAAS,aAAa,GAAG,KAAK,QAAQ,eAAe,GAAG,GAAG;EAEnF,MAAM,iBAAiB,KAAK,QAAQ,KAAK,EAAE,2BAA2B;EACtE,MAAM,iBAAiB,WAAW,SAAS,aAAa,GAAG,aAAa,GAAG,WAAW;EAEtF,MAAM,aAAa,KAAK,gBADP,GAAG,eAAe,KACc;EACjD,MAAM,WAAW,gBAAgB,KAAK,QAAe,KAAK,QAAQ;AAElE,MAAI,CAAC,UAAU;AACX,WAAQ,MAAM,uEAAuE;AACrF,WAAQ,KAAK,EAAE;;EAGnB,MAAM,WAAW,KACb,UACA,KAAK,QACE,KAAK,OAAO,MAAc,QAC3B,KAAK,MACA,KAAK,OAAO,MAAc,MAC1B,KAAK,OAAO,MAAc,WACxC;AAED,MAAI,CAAC,WAAW,SAAS,EAAE;AACvB,WAAQ,MAAM,oBAAoB,SAAS,aAAa;AACxD,WAAQ,KAAK,EAAE;;AAGnB,OAAK,aACD,UACA,YACA;GACI,gBAAgB;GAChB,WAAW,KAAK,OAAO,WAAW;GAClC,MAAM,eAAe,QAAQ,eAAe,GAAG;GAClD,EACD,KACH;AAED,SAAO"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
interface RunConsoleOptions {
|
|
3
|
+
logo?: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Runs the console kernel, initializing the application and registering commands.
|
|
7
|
+
*
|
|
8
|
+
* @param options
|
|
9
|
+
*/
|
|
10
|
+
declare const runConsoleKernel: (options?: RunConsoleOptions) => Promise<void>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { RunConsoleOptions, runConsoleKernel };
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { ArkstackConsoleApp } from "./app.js";
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { MakeResource } from "resora";
|
|
6
|
+
import { realpathSync } from "node:fs";
|
|
7
|
+
import { Command, Kernel } from "@h3ravel/musket";
|
|
8
|
+
import { spawn } from "node:child_process";
|
|
9
|
+
import chalk from "chalk";
|
|
10
|
+
import { loadPrototypes } from "@arkstack/common";
|
|
11
|
+
|
|
12
|
+
//#region dist/commands/BuildCommand.js
|
|
13
|
+
var BuildCommand = class extends Command {
|
|
14
|
+
signature = "build";
|
|
15
|
+
description = "Build the application for production";
|
|
16
|
+
async handle() {
|
|
17
|
+
await new Promise((resolve, reject) => {
|
|
18
|
+
const child = spawn(process.platform === "win32" ? "pnpm.cmd" : "pnpm", ["exec", "tsdown"], {
|
|
19
|
+
cwd: process.cwd(),
|
|
20
|
+
stdio: "inherit",
|
|
21
|
+
env: Object.assign({}, process.env, { NODE_ENV: "production" })
|
|
22
|
+
});
|
|
23
|
+
child.on("error", (error) => {
|
|
24
|
+
reject(error);
|
|
25
|
+
});
|
|
26
|
+
child.on("exit", (code) => {
|
|
27
|
+
if (code === 0 || code === null) {
|
|
28
|
+
resolve();
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
reject(/* @__PURE__ */ new Error(`tsdown exited with code ${code}`));
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region dist/commands/DevCommand.js
|
|
39
|
+
var DevCommand = class extends Command {
|
|
40
|
+
signature = "dev";
|
|
41
|
+
description = "Run the development server";
|
|
42
|
+
async handle() {
|
|
43
|
+
await new Promise((resolve, reject) => {
|
|
44
|
+
const child = spawn(process.platform === "win32" ? "pnpm.cmd" : "pnpm", [
|
|
45
|
+
"exec",
|
|
46
|
+
"tsdown",
|
|
47
|
+
"--log-level",
|
|
48
|
+
"silent"
|
|
49
|
+
], {
|
|
50
|
+
cwd: process.cwd(),
|
|
51
|
+
stdio: "inherit"
|
|
52
|
+
});
|
|
53
|
+
child.on("error", (error) => {
|
|
54
|
+
reject(error);
|
|
55
|
+
});
|
|
56
|
+
child.on("exit", (code) => {
|
|
57
|
+
if (code === 0 || code === null) {
|
|
58
|
+
resolve();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
reject(/* @__PURE__ */ new Error(`tsdown exited with code ${code}`));
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region dist/commands/MakeController.js
|
|
69
|
+
var MakeController = class extends Command {
|
|
70
|
+
signature = `make:controller
|
|
71
|
+
{name : name of the controller to create}
|
|
72
|
+
{--api : make an API controller}
|
|
73
|
+
{--m|model? : name of model to attach to controller}
|
|
74
|
+
{--force : force overwrite if controller already exists}
|
|
75
|
+
`;
|
|
76
|
+
description = "Create a new controller file";
|
|
77
|
+
async handle() {
|
|
78
|
+
this.app.command = this;
|
|
79
|
+
if (!this.argument("name")) return void this.error("Error: Controller name is required.");
|
|
80
|
+
const name = this.app.makeController(this.argument("name"), this.options());
|
|
81
|
+
this.success(`Controller ${name} created successfully!`);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region dist/commands/MakeFullResource.js
|
|
87
|
+
var MakeFullResource = class extends Command {
|
|
88
|
+
signature = `make:full-resource
|
|
89
|
+
{prefix : prefix of the resources to create, "Admin" will create AdminResource, AdminCollection and AdminController}
|
|
90
|
+
{--m|model? : name of model to attach to the generated controller}
|
|
91
|
+
{--force : force overwrite if resources already exist}
|
|
92
|
+
`;
|
|
93
|
+
description = "Create a full new set of API resources (Controller, Resource, Collection)";
|
|
94
|
+
async handle() {
|
|
95
|
+
this.app.command = this;
|
|
96
|
+
const res1 = this.app.makeResource(this.argument("prefix"), {});
|
|
97
|
+
const res2 = this.app.makeResource(this.argument("prefix") + "Collection", { collection: true });
|
|
98
|
+
const name3 = this.app.makeController(this.argument("prefix"), Object.assign({}, this.options(), { api: true }));
|
|
99
|
+
this.success(`Created full resource set: ${res1.name}, ${res2.name}, ${name3}`);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region dist/commands/MakeResource.js
|
|
105
|
+
var MakeResource$1 = class extends MakeResource {
|
|
106
|
+
signature = `#make:
|
|
107
|
+
{resource : Generates a new resource file.
|
|
108
|
+
| {name : Name of the resource to create}
|
|
109
|
+
| {--c|collection : Make a resource collection}
|
|
110
|
+
| {--force : Create the resource or collection file even if it already exists.}
|
|
111
|
+
}
|
|
112
|
+
{collection : Create a new resource collection file.
|
|
113
|
+
| {name : Name of the resource collection to create}
|
|
114
|
+
| {--force : Create the resource or collection file even if it already exists.}
|
|
115
|
+
}
|
|
116
|
+
{all : Create both resource and collection files.
|
|
117
|
+
| {prefix : prefix of the resources to create, "Admin" will create AdminResource, AdminCollection}
|
|
118
|
+
| {--force : Create the resource or collection file even if it already exists.}
|
|
119
|
+
}
|
|
120
|
+
`;
|
|
121
|
+
description = "Create a new resource or resource collection file";
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region dist/commands/RouteList.js
|
|
126
|
+
var RouteList = class extends Command {
|
|
127
|
+
signature = `route:list
|
|
128
|
+
{--p|path? : Path to filter routes by}
|
|
129
|
+
`;
|
|
130
|
+
description = "List all registered routes";
|
|
131
|
+
async handle() {
|
|
132
|
+
const routes = await this.app.core.getRouter().list(this.options(), this.app.core.getAppInstance());
|
|
133
|
+
console.log(this.formatRoutes(routes.reverse()));
|
|
134
|
+
this.newLine();
|
|
135
|
+
this.info(`Total routes: ${routes.length}`);
|
|
136
|
+
}
|
|
137
|
+
formatRoutes(routes) {
|
|
138
|
+
if (routes.length === 0) return "No routes registered.";
|
|
139
|
+
const rows = routes.map((route) => ({
|
|
140
|
+
method: route.methods.join("|").toUpperCase(),
|
|
141
|
+
path: route.path,
|
|
142
|
+
handler: route.controllerName ? `${route.controllerName} → ${route.actionName}` : route.actionName ?? "N/A"
|
|
143
|
+
}));
|
|
144
|
+
const methodWidth = Math.max(6, ...rows.map((row) => row.method.length));
|
|
145
|
+
const pathWidth = Math.max(4, ...rows.map((row) => row.path.length));
|
|
146
|
+
const handlerWidth = Math.max(7, ...rows.map((row) => row.handler.length));
|
|
147
|
+
return [
|
|
148
|
+
`${"METHOD".padEnd(methodWidth)} ${"PATH".padEnd(pathWidth)} ${"HANDLER".padEnd(handlerWidth)}`,
|
|
149
|
+
`${"-".repeat(methodWidth)} ${"-".repeat(pathWidth)} ${"-".repeat(handlerWidth)}`,
|
|
150
|
+
...rows.map((row) => `${chalk.green(row.method.padEnd(methodWidth))} ${chalk.blue(row.path.padEnd(pathWidth))} ${chalk.yellow(row.handler.padEnd(handlerWidth))}`)
|
|
151
|
+
].join("\n");
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region dist/logo.js
|
|
157
|
+
var logo_default = String.raw`
|
|
158
|
+
___ _ _
|
|
159
|
+
/ _ \ | | | |
|
|
160
|
+
/ /_\ \_ __ ___ ___| |_ __ _ ___| | __
|
|
161
|
+
| _ | '__/ __/ __| __/ _' |/ __| |/ /
|
|
162
|
+
| | | | | | (__\__ \ || (_| | (__| <
|
|
163
|
+
\_| |_/_| \___|___/\__\__,_|\___|_|\_\
|
|
164
|
+
`;
|
|
165
|
+
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region dist/index.js
|
|
168
|
+
/**
|
|
169
|
+
* Loads the core application instance by importing the bootstrap file.
|
|
170
|
+
*
|
|
171
|
+
* @returns
|
|
172
|
+
*/
|
|
173
|
+
const loadCoreApp = async () => {
|
|
174
|
+
return (await import(pathToFileURL(join(process.cwd(), "dist/core/bootstrap.js")).href)).app;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Runs the console kernel, initializing the application and registering commands.
|
|
178
|
+
*
|
|
179
|
+
* @param options
|
|
180
|
+
*/
|
|
181
|
+
const runConsoleKernel = async (options = {}) => {
|
|
182
|
+
loadPrototypes();
|
|
183
|
+
const app = await loadCoreApp();
|
|
184
|
+
const stubsDir = process.env.ARKSTACK_STUBS_DIR;
|
|
185
|
+
await Kernel.init(await new ArkstackConsoleApp(app, { stubsDir }).loadConfig(), {
|
|
186
|
+
logo: options.logo ?? logo_default,
|
|
187
|
+
name: "Cmd",
|
|
188
|
+
baseCommands: [
|
|
189
|
+
RouteList,
|
|
190
|
+
MakeResource$1,
|
|
191
|
+
MakeController,
|
|
192
|
+
MakeFullResource,
|
|
193
|
+
DevCommand,
|
|
194
|
+
BuildCommand
|
|
195
|
+
],
|
|
196
|
+
discoveryPaths: [join(process.cwd(), "dist/core/console/commands/*.js")],
|
|
197
|
+
exceptionHandler(exception) {
|
|
198
|
+
throw exception;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Determines if the current module is being executed as the entry
|
|
204
|
+
* point of the application.
|
|
205
|
+
*
|
|
206
|
+
* @returns
|
|
207
|
+
*/
|
|
208
|
+
const isEntrypointExecution = () => {
|
|
209
|
+
const argvEntry = process.argv[1];
|
|
210
|
+
if (!argvEntry) return false;
|
|
211
|
+
try {
|
|
212
|
+
return realpathSync(fileURLToPath(import.meta.url)) === realpathSync(argvEntry);
|
|
213
|
+
} catch {
|
|
214
|
+
return import.meta.url === pathToFileURL(argvEntry).href;
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
if (isEntrypointExecution()) await runConsoleKernel();
|
|
218
|
+
|
|
219
|
+
//#endregion
|
|
220
|
+
export { runConsoleKernel };
|
|
221
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["MakeResource","MakeResourceBase","logo","MakeResource"],"sources":["../src/commands/BuildCommand.ts","../src/commands/DevCommand.ts","../src/commands/MakeController.ts","../src/commands/MakeFullResource.ts","../src/commands/MakeResource.ts","../src/commands/RouteList.ts","../src/logo.ts","../src/index.ts"],"sourcesContent":["import { Command } from \"@h3ravel/musket\";\nimport { spawn } from \"node:child_process\";\n\nexport class BuildCommand extends Command {\n protected signature = \"build\";\n\n protected description = \"Build the application for production\";\n\n async handle () {\n await new Promise<void>((resolve, reject) => {\n const command = process.platform === \"win32\" ? \"pnpm.cmd\" : \"pnpm\";\n const child = spawn(command, [\"exec\", \"tsdown\"], {\n cwd: process.cwd(),\n stdio: \"inherit\",\n env: Object.assign({}, process.env, {\n NODE_ENV: \"production\",\n }),\n });\n\n child.on(\"error\", (error) => {\n reject(error);\n });\n\n child.on(\"exit\", (code) => {\n if (code === 0 || code === null) {\n resolve();\n return;\n }\n\n reject(new Error(`tsdown exited with code ${code}`));\n });\n });\n }\n}\n","import { Command } from \"@h3ravel/musket\";\nimport { spawn } from \"node:child_process\";\n\nexport class DevCommand extends Command {\n protected signature = \"dev\";\n\n protected description = \"Run the development server\";\n\n async handle () {\n await new Promise<void>((resolve, reject) => {\n const command = process.platform === \"win32\" ? \"pnpm.cmd\" : \"pnpm\";\n const child = spawn(command, [\"exec\", \"tsdown\", \"--log-level\", \"silent\"], {\n cwd: process.cwd(),\n stdio: \"inherit\",\n });\n\n child.on(\"error\", (error) => {\n reject(error);\n });\n\n child.on(\"exit\", (code) => {\n if (code === 0 || code === null) {\n resolve();\n return;\n }\n\n reject(new Error(`tsdown exited with code ${code}`));\n });\n });\n }\n}\n","import { ArkstackConsoleApp } from \"@arkstack/console/app\";\nimport { Command } from \"@h3ravel/musket\";\n\n// oxlint-disable-next-line typescript/no-explicit-any\nexport class MakeController extends Command<ArkstackConsoleApp<any>> {\n protected signature = `make:controller\n {name : name of the controller to create}\n {--api : make an API controller}\n {--m|model? : name of model to attach to controller}\n {--force : force overwrite if controller already exists}\n `;\n\n protected description = \"Create a new controller file\";\n\n async handle () {\n this.app.command = this;\n\n if (!this.argument(\"name\")) return void this.error(\"Error: Controller name is required.\");\n\n const name = this.app.makeController(this.argument(\"name\"), this.options());\n\n this.success(`Controller ${name} created successfully!`);\n }\n}\n","import { ArkstackConsoleApp } from \"@arkstack/console/app\";\nimport { Command } from \"@h3ravel/musket\";\n\n// oxlint-disable-next-line typescript/no-explicit-any\nexport class MakeFullResource extends Command<ArkstackConsoleApp<any>> {\n protected signature = `make:full-resource\n {prefix : prefix of the resources to create, \"Admin\" will create AdminResource, AdminCollection and AdminController}\n {--m|model? : name of model to attach to the generated controller}\n {--force : force overwrite if resources already exist}\n `;\n\n protected description =\n \"Create a full new set of API resources (Controller, Resource, Collection)\";\n\n async handle () {\n this.app.command = this;\n\n const res1 = this.app.makeResource(this.argument(\"prefix\"), {});\n const res2 = this.app.makeResource(this.argument(\"prefix\") + \"Collection\", {\n collection: true,\n });\n const name3 = this.app.makeController(\n this.argument(\"prefix\"),\n Object.assign({}, this.options(), { api: true }),\n );\n this.success(`Created full resource set: ${res1.name}, ${res2.name}, ${name3}`);\n }\n}\n","import { MakeResource as MakeResourceBase } from \"resora\";\n\nexport class MakeResource extends MakeResourceBase {\n signature = `#make:\n {resource : Generates a new resource file.\n | {name : Name of the resource to create}\n | {--c|collection : Make a resource collection}\n | {--force : Create the resource or collection file even if it already exists.}\n }\n {collection : Create a new resource collection file.\n | {name : Name of the resource collection to create}\n | {--force : Create the resource or collection file even if it already exists.}\n }\n {all : Create both resource and collection files.\n | {prefix : prefix of the resources to create, \"Admin\" will create AdminResource, AdminCollection}\n | {--force : Create the resource or collection file even if it already exists.}\n }\n `;\n\n description = \"Create a new resource or resource collection file\";\n}\n","import { ArkstackConsoleApp } from \"../app\";\nimport type { ArkstackRouterAwareCore } from \"@arkstack/contract\";\nimport { Command } from \"@h3ravel/musket\";\nimport type { Route } from \"clear-router\";\nimport chalk from \"chalk\";\n\ntype App = ArkstackConsoleApp<ArkstackRouterAwareCore<unknown, Route[]>>;\n\nexport class RouteList extends Command<App> {\n protected signature = `route:list\n {--p|path? : Path to filter routes by}\n `;\n\n protected description = \"List all registered routes\";\n\n async handle () {\n const routes = await this.app.core.getRouter().list(this.options(), this.app.core.getAppInstance());\n\n console.log(this.formatRoutes(routes.reverse()));\n this.newLine();\n this.info(`Total routes: ${routes.length}`);\n }\n\n private formatRoutes (routes: Route[]) {\n if (routes.length === 0) {\n return \"No routes registered.\";\n }\n\n const rows = routes.map((route) => ({\n method: route.methods.join(\"|\").toUpperCase(),\n path: route.path,\n handler: route.controllerName ? `${route.controllerName} → ${route.actionName}` : route.actionName ?? \"N/A\",\n }));\n\n const methodWidth = Math.max(\"METHOD\".length, ...rows.map((row) => row.method.length));\n const pathWidth = Math.max(\"PATH\".length, ...rows.map((row) => row.path.length));\n const handlerWidth = Math.max(\"HANDLER\".length, ...rows.map((row) => row.handler.length));\n\n const header = `${\"METHOD\".padEnd(methodWidth)} ${\"PATH\".padEnd(pathWidth)} ${\"HANDLER\".padEnd(handlerWidth)}`;\n const divider = `${\"-\".repeat(methodWidth)} ${\"-\".repeat(pathWidth)} ${\"-\".repeat(handlerWidth)}`;\n const body = rows.map(\n (row) => `${chalk.green(row.method.padEnd(methodWidth))} ${chalk.blue(row.path.padEnd(pathWidth))} ${chalk.yellow(row.handler.padEnd(handlerWidth))}`\n );\n\n return [header, divider, ...body].join(\"\\n\");\n }\n}\n","export default String.raw`\n ___ _ _ \n / _ \\ | | | | \n/ /_\\ \\_ __ ___ ___| |_ __ _ ___| | __\n| _ | '__/ __/ __| __/ _' |/ __| |/ /\n| | | | | | (__\\__ \\ || (_| | (__| < \n\\_| |_/_| \\___|___/\\__\\__,_|\\___|_|\\_\\ \n`","#!/usr/bin/env node\n\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\n\nimport { ArkstackConsoleApp } from \"./app\";\nimport { BuildCommand } from \"./commands/BuildCommand\";\nimport { DevCommand } from \"./commands/DevCommand\";\nimport { Kernel } from \"@h3ravel/musket\";\nimport { MakeController } from \"./commands/MakeController\";\nimport { MakeFullResource } from \"./commands/MakeFullResource\";\nimport { MakeResource } from \"./commands/MakeResource\";\nimport { RouteList } from \"./commands/RouteList\";\nimport { join } from \"node:path\";\nimport { loadPrototypes } from \"@arkstack/common\";\nimport logo from \"./logo\";\nimport { realpathSync } from \"node:fs\";\n\nexport interface RunConsoleOptions {\n logo?: string;\n}\n\n/**\n * Loads the core application instance by importing the bootstrap file.\n * \n * @returns \n */\nconst loadCoreApp = async () => {\n const bootstrapPath = pathToFileURL(join(process.cwd(), \"src/core/bootstrap.ts\")).href;\n const module = await import(bootstrapPath);\n return module.app;\n};\n\n/**\n * Runs the console kernel, initializing the application and registering commands.\n * \n * @param options \n */\nexport const runConsoleKernel = async (options: RunConsoleOptions = {}) => {\n loadPrototypes();\n\n const app = await loadCoreApp();\n const stubsDir = process.env.ARKSTACK_STUBS_DIR;\n\n await Kernel.init(await new ArkstackConsoleApp(app, { stubsDir }).loadConfig(), {\n logo: options.logo ?? logo,\n name: \"Cmd\",\n baseCommands: [\n RouteList,\n MakeResource,\n MakeController,\n MakeFullResource,\n DevCommand,\n BuildCommand\n ],\n discoveryPaths: [join(process.cwd(), \"src/core/console/commands/*.ts\")],\n exceptionHandler (exception) {\n throw exception;\n },\n });\n};\n\n/**\n * Determines if the current module is being executed as the entry \n * point of the application.\n * \n * @returns \n */\nconst isEntrypointExecution = () => {\n const argvEntry = process.argv[1];\n\n if (!argvEntry) {\n return false;\n }\n\n try {\n const currentModulePath = realpathSync(fileURLToPath(import.meta.url));\n const entryPath = realpathSync(argvEntry);\n\n return currentModulePath === entryPath;\n } catch {\n return import.meta.url === pathToFileURL(argvEntry).href;\n }\n};\n\nif (isEntrypointExecution()) {\n await runConsoleKernel();\n}\n"],"mappings":";;;;;;;;;;;;AAGA,IAAa,eAAb,cAAkC,QAAQ;CACtC,AAAU,YAAY;CAEtB,AAAU,cAAc;CAExB,MAAM,SAAU;AACZ,QAAM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AAC,UACD,QAAO;AAGX,KAAI;AAIA,SAH0B,aAAa,cAAc,OAAO,KAAK,IAAI,CAAC,KACpD,aAAa,UAAU;SAGrC;AACJ,SAAO,OAAO,KAAK,QAAQ,cAAc,UAAU,CAAC;;;AAI5D,IAAI,uBAAuB,CACvB,OAAM,kBAAkB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arkstack/console",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Console package for Arkstack providing console-specific implementations of core Arkstack features such as routing, middleware, and database integration.",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/arkstack-hq/arkstack.git",
|
|
9
|
+
"directory": "packages/console"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"console",
|
|
13
|
+
"cli",
|
|
14
|
+
"command-line",
|
|
15
|
+
"interface",
|
|
16
|
+
"runtime",
|
|
17
|
+
"application",
|
|
18
|
+
"framework",
|
|
19
|
+
"stubs",
|
|
20
|
+
"musket",
|
|
21
|
+
"h3ravel"
|
|
22
|
+
],
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"bin": {
|
|
30
|
+
"arch": "./dist/index.js"
|
|
31
|
+
},
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"import": "./dist/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./app": {
|
|
38
|
+
"types": "./dist/app.d.ts",
|
|
39
|
+
"import": "./dist/app.js"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"clear-router": "^2.1.6"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@h3ravel/musket": "^0.10.1",
|
|
47
|
+
"chalk": "^5.6.2",
|
|
48
|
+
"resora": "^0.2.3",
|
|
49
|
+
"@arkstack/common": "^0.1.1",
|
|
50
|
+
"@arkstack/contract": "^0.1.1"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "tsdown",
|
|
54
|
+
"test": "vitest",
|
|
55
|
+
"version:patch": "pnpm version patch --no-git-tag-version"
|
|
56
|
+
}
|
|
57
|
+
}
|