@arkstack/console 0.1.26 → 0.1.28

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/dist/app.d.ts CHANGED
@@ -1,13 +1,20 @@
1
1
  import { CliApp } from "resora";
2
2
 
3
3
  //#region src/app.d.ts
4
+ interface Core {
5
+ [k: string]: any;
6
+ getDriver: () => {
7
+ [k: string]: any;
8
+ name: string;
9
+ };
10
+ }
4
11
  interface ConsoleAppOptions {
5
12
  stubsDir?: string;
6
13
  }
7
14
  declare const resolveStubsDir: (config: {
8
15
  localStubsDir?: string;
9
- } | undefined, options?: ConsoleAppOptions) => string;
10
- declare class ArkstackConsoleApp<TCore> extends CliApp {
16
+ } | undefined, options?: ConsoleAppOptions, core?: Core) => string;
17
+ declare class ArkstackConsoleApp<TCore extends Core> extends CliApp {
11
18
  core: TCore;
12
19
  private readonly options;
13
20
  constructor(core: TCore, options: ConsoleAppOptions);
package/dist/app.js CHANGED
@@ -1 +1,54 @@
1
- import e,{isAbsolute as t,join as n}from"node:path";import{CliApp as r}from"resora";import{existsSync as i}from"node:fs";const a=(e,r)=>{let i=e?.localStubsDir;return i?t(i)?i:n(process.cwd(),i):r?.stubsDir};var o=class extends r{core;options;constructor(e,t){super(),this.core=e,this.options=t}makeController=(t,r)=>{let o=t.endsWith(`Controller`)?t.replace(/controller/i,``):t,s=o.endsWith(`Controller`)?o:`${o}Controller`,c=n(e.resolve(process.cwd(),`src`,`app/http/controllers`),`${s}.${r?.ext??`ts`}`),l=a(this.config,this.options);l||(console.error(`Error: stubsDir is not configured. Set stubsDir in resora.config.js.`),process.exit(1));let u=n(l,r.model?this.config.stubs.model:r.api?this.config.stubs.api:this.config.stubs.controller);return i(u)||(console.error(`Error: Stub file ${u} not found.`),process.exit(1)),s=s.split(`/`).pop(),this.generateFile(u,c,{ControllerName:s,Model:r.model?.pascalCase(),ModelName:r.model?.camelCase(),Name:s.replace(/controller/i,``)},r),c};normalizePath=e=>e.replace(process.cwd(),``)};export{o as ArkstackConsoleApp,a as resolveStubsDir};
1
+ import path, { 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, core) => {
7
+ const configuredDir = config?.localStubsDir;
8
+ if (configuredDir) return isAbsolute(configuredDir) ? configuredDir : join(process.cwd(), configuredDir);
9
+ if (!options?.stubsDir) {
10
+ const driver = core?.getDriver().name ?? "h3";
11
+ let stubsDir = path.resolve(process.cwd(), `node_modules/@arkstack/driver-${driver}/stubs`);
12
+ if (!existsSync(stubsDir)) stubsDir = path.resolve(process.cwd(), "stubs");
13
+ return stubsDir;
14
+ }
15
+ return options?.stubsDir;
16
+ };
17
+ var ArkstackConsoleApp = class extends CliApp {
18
+ core;
19
+ options;
20
+ constructor(core, options) {
21
+ super();
22
+ this.core = core;
23
+ this.options = options;
24
+ }
25
+ makeController = (name, opts) => {
26
+ const normalized = name.endsWith("Controller") ? name.replace(/controller/i, "") : name;
27
+ let controllerName = normalized.endsWith("Controller") ? normalized : `${normalized}Controller`;
28
+ const outputPath = join(path.resolve(process.cwd(), "src", "app/http/controllers"), `${controllerName}.${opts?.ext ?? "ts"}`);
29
+ const stubsDir = resolveStubsDir(this.config, this.options, this.core);
30
+ if (!stubsDir) {
31
+ console.error("Error: stubsDir is not configured. Set stubsDir in resora.config.js.");
32
+ process.exit(1);
33
+ }
34
+ const stubPath = join(stubsDir, opts.model ? this.config.stubs.model : opts.api ? this.config.stubs.api : this.config.stubs.controller);
35
+ if (!existsSync(stubPath)) {
36
+ console.error(`Error: Stub file ${stubPath} not found.`);
37
+ process.exit(1);
38
+ }
39
+ controllerName = controllerName.split("/").pop();
40
+ this.generateFile(stubPath, outputPath, {
41
+ ControllerName: controllerName,
42
+ Model: opts.model?.pascalCase(),
43
+ ModelName: opts.model?.camelCase(),
44
+ Name: controllerName.replace(/controller/i, "")
45
+ }, opts);
46
+ return outputPath;
47
+ };
48
+ normalizePath = (p) => {
49
+ return p.replace(process.cwd(), "");
50
+ };
51
+ };
52
+
53
+ //#endregion
54
+ export { ArkstackConsoleApp, resolveStubsDir };
package/dist/index.js CHANGED
@@ -1,8 +1,112 @@
1
1
  #!/usr/bin/env node
2
- import{ArkstackConsoleApp as e}from"./app.js";import{fileURLToPath as t,pathToFileURL as n}from"node:url";import{join as r}from"node:path";import{MakeResource as i}from"resora";import{realpathSync as a}from"node:fs";import{Command as o,Kernel as s}from"@h3ravel/musket";import{spawn as c}from"node:child_process";import{resolve as l}from"path";import{writeFile as u}from"fs/promises";import{CliApp as d,MakeFactoryCommand as f,MakeMigrationCommand as p,MakeModelCommand as m,MakeSeederCommand as h,MigrateCommand as g,MigrateRollbackCommand as _,MigrationHistoryCommand as v,ModelsSyncCommand as y,SeedCommand as b}from"arkormx";import x from"chalk";import{loadPrototypes as S}from"@arkstack/common";var C=class extends o{signature=`build`;description=`Build the application for production`;async handle(){await new Promise((e,t)=>{let n=c(process.platform===`win32`?`pnpm.cmd`:`pnpm`,[`exec`,`tsdown`],{cwd:process.cwd(),stdio:`inherit`,env:Object.assign({},process.env,{NODE_ENV:`production`})});n.on(`error`,e=>{t(e)}),n.on(`exit`,n=>{if(n===0||n===null){e();return}t(Error(`tsdown exited with code ${n}`))})})}},w=class extends o{signature=`dev`;description=`Run the development server`;async handle(){await new Promise((e,t)=>{let n=c(process.platform===`win32`?`pnpm.cmd`:`pnpm`,[`exec`,`tsdown`,`--log-level`,`silent`],{cwd:process.cwd(),stdio:`inherit`});n.on(`error`,e=>{t(e)}),n.on(`exit`,n=>{if(n===0||n===null){e();return}t(Error(`tsdown exited with code ${n}`))})})}},T=class extends o{signature=`make:command
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 { resolve } from "path";
10
+ import { writeFile } from "fs/promises";
11
+ import { CliApp as CliApp$1, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateRollbackCommand, MigrationHistoryCommand, ModelsSyncCommand, SeedCommand } from "arkormx";
12
+ import chalk from "chalk";
13
+ import { loadPrototypes } from "@arkstack/common";
14
+
15
+ //#region dist/commands/BuildCommand.js
16
+ var BuildCommand = class extends Command {
17
+ signature = "build";
18
+ description = "Build the application for production";
19
+ async handle() {
20
+ await new Promise((resolve, reject) => {
21
+ const child = spawn(process.platform === "win32" ? "pnpm.cmd" : "pnpm", ["exec", "tsdown"], {
22
+ cwd: process.cwd(),
23
+ stdio: "inherit",
24
+ env: Object.assign({}, process.env, { NODE_ENV: "production" })
25
+ });
26
+ child.on("error", (error) => {
27
+ reject(error);
28
+ });
29
+ child.on("exit", (code) => {
30
+ if (code === 0 || code === null) {
31
+ resolve();
32
+ return;
33
+ }
34
+ reject(/* @__PURE__ */ new Error(`tsdown exited with code ${code}`));
35
+ });
36
+ });
37
+ }
38
+ };
39
+
40
+ //#endregion
41
+ //#region dist/commands/DevCommand.js
42
+ var DevCommand = class extends Command {
43
+ signature = "dev";
44
+ description = "Run the development server";
45
+ async handle() {
46
+ await new Promise((resolve, reject) => {
47
+ const child = spawn(process.platform === "win32" ? "pnpm.cmd" : "pnpm", [
48
+ "exec",
49
+ "tsdown",
50
+ "--log-level",
51
+ "silent"
52
+ ], {
53
+ cwd: process.cwd(),
54
+ stdio: "inherit"
55
+ });
56
+ child.on("error", (error) => {
57
+ reject(error);
58
+ });
59
+ child.on("exit", (code) => {
60
+ if (code === 0 || code === null) {
61
+ resolve();
62
+ return;
63
+ }
64
+ reject(/* @__PURE__ */ new Error(`tsdown exited with code ${code}`));
65
+ });
66
+ });
67
+ }
68
+ };
69
+
70
+ //#endregion
71
+ //#region dist/commands/MakeCommand.js
72
+ var MakeCommand = class extends Command {
73
+ signature = `make:command
3
74
  {name : name of the command to create}
4
- `;description=`Creates a new console command class.`;async handle(){let e=String(this.argument(`name`)).replace(/\s+/g,``).replace(/\.js$/,``).trim();if(!e)return void this.error(`Command name is required`);let t=this.stub(e),n=l(process.cwd(),`src`,`app/console/commands/${e}.js`);await u(n,t,{flag:`wx`}),this.success(`Command ${e} created successfully at ${n}`)}stub(e){e=e.endsWith(`Command`)?e:`${e}Command`,e=e.split(`/`).pop().split(`.`).shift();let t=`app:${e.toLowerCase()}`,n=`Description for ${t} command`;return[`import { Command } from '@h3ravel/musket'`,``,`export class ${e} extends Command {`,` signature = '${t}'`,``,` description = '${n}'`,``,` async handle () {`,` // Command logic goes here`,` }`,`}`].join(`
5
- `)}},E=class extends o{signature=`make:controller
75
+ `;
76
+ description = "Creates a new console command class.";
77
+ async handle() {
78
+ const name = String(this.argument("name")).replace(/\s+/g, "").replace(/\.js$/, "").trim();
79
+ if (!name) return void this.error("Command name is required");
80
+ const stubContent = this.stub(name);
81
+ const filePath = resolve(process.cwd(), "src", `app/console/commands/${name}.js`);
82
+ await writeFile(filePath, stubContent, { flag: "wx" });
83
+ this.success(`Command ${name} created successfully at ${filePath}`);
84
+ }
85
+ stub(name) {
86
+ name = name.endsWith("Command") ? name : `${name}Command`;
87
+ name = name.split("/").pop().split(".").shift();
88
+ const signature = `app:${name.toLowerCase()}`;
89
+ const description = `Description for ${signature} command`;
90
+ return [
91
+ "import { Command } from '@h3ravel/musket'",
92
+ "",
93
+ `export class ${name} extends Command {`,
94
+ ` signature = '${signature}'`,
95
+ "",
96
+ ` description = '${description}'`,
97
+ "",
98
+ " async handle () {",
99
+ " // Command logic goes here",
100
+ " }",
101
+ "}"
102
+ ].join("\n");
103
+ }
104
+ };
105
+
106
+ //#endregion
107
+ //#region dist/commands/MakeController.js
108
+ var MakeController = class extends Command {
109
+ signature = `make:controller
6
110
  {name : name of the controller to create}
7
111
  {--api : make an API controller}
8
112
  {--m|model? : name of model to attach to controller}
@@ -10,22 +114,301 @@ import{ArkstackConsoleApp as e}from"./app.js";import{fileURLToPath as t,pathToFi
10
114
  {--s|seeder : Create a seeder file for the model (only if --model is specified)}
11
115
  {--x|migration : Create a migration file for the model (only if --model is specified)}
12
116
  {--force : force overwrite if controller already exists}
13
- `;description=`Create a new controller file`;async handle(){if(this.app.command=this,!this.argument(`name`))return void this.error(`Error: Controller name is required.`);let e=this.app.makeController(this.argument(`name`),this.options()),t=new d,n=this.option(`model`)?t.makeModel(this.argument(`model`),{...this.options(),force:!1}):null;this.success(`Controller created successfully!`),[[`Controller`,e],n?[`Model`,n.model.path]:``,n?[`Prisma schema ${n.prisma.updated?`(updated)`:`(already up to date)`}`,n?.prisma.path]:``,n?.factory?[`Factory`,n.factory.path]:``,n?.seeder?[`Seeder`,n.seeder.path]:``,n?.migration?[`Migration`,n.migration.path]:``].filter(Boolean).map(([e,n])=>this.success(t.splitLogger(e,n)))}},D=class extends f{async handle(){return this.app.command=this,this.app=new d,super.handle()}},O=class extends o{signature=`make:full-resource
117
+ `;
118
+ description = "Create a new controller file";
119
+ async handle() {
120
+ this.app.command = this;
121
+ if (!this.argument("name")) return void this.error("Error: Controller name is required.");
122
+ const name = this.app.makeController(this.argument("name"), this.options());
123
+ const app = new CliApp$1();
124
+ const model = this.option("model") ? app.makeModel(this.argument("model"), {
125
+ ...this.options(),
126
+ force: false
127
+ }) : null;
128
+ this.success("Controller created successfully!");
129
+ [
130
+ ["Controller", name],
131
+ model ? ["Model", model.model.path] : "",
132
+ model ? [`Prisma schema ${model.prisma.updated ? "(updated)" : "(already up to date)"}`, model?.prisma.path] : "",
133
+ model?.factory ? ["Factory", model.factory.path] : "",
134
+ model?.seeder ? ["Seeder", model.seeder.path] : "",
135
+ model?.migration ? ["Migration", model.migration.path] : ""
136
+ ].filter(Boolean).map(([name, path]) => this.success(app.splitLogger(name, path)));
137
+ }
138
+ };
139
+
140
+ //#endregion
141
+ //#region dist/commands/MakeFactoryCommand.js
142
+ var MakeFactoryCommand$1 = class extends MakeFactoryCommand {
143
+ async handle() {
144
+ this.app.command = this;
145
+ this.app = new CliApp$1();
146
+ return super.handle();
147
+ }
148
+ };
149
+
150
+ //#endregion
151
+ //#region dist/commands/MakeFullResource.js
152
+ var MakeFullResource = class extends Command {
153
+ signature = `make:full-resource
14
154
  {prefix : prefix of the resources to create, "Admin" will create AdminResource, AdminCollection and AdminController}
15
155
  {--m|model? : name of model to attach to the generated controller (will be created if it doesn't exist)}
16
156
  {--f|factory : Create and link a factory}
17
157
  {--s|seeder : Create a seeder file for the model (only if --model is specified)}
18
158
  {--x|migration : Create a migration file for the model (only if --model is specified)}
19
159
  {--force : force overwrite if resources already exist}
20
- `;description=`Create a full new set of API resources (Controller, Resource, Collection)`;async handle(){this.app.command=this;let e=this.app.makeResource(this.argument(`prefix`),{force:this.option(`force`)}),t=this.app.makeResource(this.argument(`prefix`)+`Collection`,{collection:!0,force:this.option(`force`)}),n=this.app.makeController(this.argument(`prefix`),Object.assign({},this.options(),{api:!0,force:this.option(`force`)})),r=new d,i=this.option(`model`)?r.makeModel(this.argument(`prefix`),{...this.options(),force:!1}):null;this.success(`Created full resource set:`),[[`Resource`,e.path],[`Collection`,t.path],[`Controller`,n],i?[`Model`,i.model.path]:``,i?[`Prisma schema ${i.prisma.updated?`(updated)`:`(already up to date)`}`,i.prisma.path]:``,i?.factory?[`Factory`,i.factory.path]:``,i?.seeder?[`Seeder`,i.seeder.path]:``,i?.migration?[`Migration`,i.migration.path]:``].filter(Boolean).map(([e,t])=>this.success(r.splitLogger(e,t)))}},k=class extends p{async handle(){return this.app.command=this,this.app=new d,super.handle()}},A=class extends m{async handle(){return this.app.command=this,this.app=new d,super.handle()}},j=class extends i{},M=class extends h{async handle(){return this.app.command=this,this.app=new d,super.handle()}},N=class extends g{async handle(){return this.app.command=this,this.app=new d,super.handle()}},P=class extends _{async handle(){return this.app.command=this,this.app=new d,super.handle()}},F=class extends v{async handle(){return this.app.command=this,this.app=new d,super.handle()}},I=class extends y{async handle(){return this.app.command=this,this.app=new d,super.handle()}},L=class extends o{signature=`route:list
160
+ `;
161
+ description = "Create a full new set of API resources (Controller, Resource, Collection)";
162
+ async handle() {
163
+ this.app.command = this;
164
+ const res = this.app.makeResource(this.argument("prefix"), { force: this.option("force") });
165
+ const col = this.app.makeResource(this.argument("prefix") + "Collection", {
166
+ collection: true,
167
+ force: this.option("force")
168
+ });
169
+ const cont = this.app.makeController(this.argument("prefix"), Object.assign({}, this.options(), {
170
+ api: true,
171
+ force: this.option("force")
172
+ }));
173
+ const app = new CliApp$1();
174
+ const model = this.option("model") ? app.makeModel(this.argument("prefix"), {
175
+ ...this.options(),
176
+ force: false
177
+ }) : null;
178
+ this.success("Created full resource set:");
179
+ [
180
+ ["Resource", res.path],
181
+ ["Collection", col.path],
182
+ ["Controller", cont],
183
+ model ? ["Model", model.model.path] : "",
184
+ model ? [`Prisma schema ${model.prisma.updated ? "(updated)" : "(already up to date)"}`, model.prisma.path] : "",
185
+ model?.factory ? ["Factory", model.factory.path] : "",
186
+ model?.seeder ? ["Seeder", model.seeder.path] : "",
187
+ model?.migration ? ["Migration", model.migration.path] : ""
188
+ ].filter(Boolean).map(([name, path]) => this.success(app.splitLogger(name, path)));
189
+ }
190
+ };
191
+
192
+ //#endregion
193
+ //#region dist/commands/MakeMigrationCommand.js
194
+ var MakeMigrationCommand$1 = class extends MakeMigrationCommand {
195
+ async handle() {
196
+ this.app.command = this;
197
+ this.app = new CliApp$1();
198
+ return super.handle();
199
+ }
200
+ };
201
+
202
+ //#endregion
203
+ //#region dist/commands/MakeModelCommand.js
204
+ var MakeModelCommand$1 = class extends MakeModelCommand {
205
+ async handle() {
206
+ this.app.command = this;
207
+ this.app = new CliApp$1();
208
+ return super.handle();
209
+ }
210
+ };
211
+
212
+ //#endregion
213
+ //#region dist/commands/MakeResource.js
214
+ var MakeResource$1 = class extends MakeResource {};
215
+
216
+ //#endregion
217
+ //#region dist/commands/MakeSeederCommand.js
218
+ var MakeSeederCommand$1 = class extends MakeSeederCommand {
219
+ async handle() {
220
+ this.app.command = this;
221
+ this.app = new CliApp$1();
222
+ return super.handle();
223
+ }
224
+ };
225
+
226
+ //#endregion
227
+ //#region dist/commands/MigrateCommand.js
228
+ var MigrateCommand$1 = class extends MigrateCommand {
229
+ async handle() {
230
+ this.app.command = this;
231
+ this.app = new CliApp$1();
232
+ return super.handle();
233
+ }
234
+ };
235
+
236
+ //#endregion
237
+ //#region dist/commands/MigrateRollbackCommand.js
238
+ var MigrateRollbackCommand$1 = class extends MigrateRollbackCommand {
239
+ async handle() {
240
+ this.app.command = this;
241
+ this.app = new CliApp$1();
242
+ return super.handle();
243
+ }
244
+ };
245
+
246
+ //#endregion
247
+ //#region dist/commands/MigrationHistoryCommand.js
248
+ var MigrationHistoryCommand$1 = class extends MigrationHistoryCommand {
249
+ async handle() {
250
+ this.app.command = this;
251
+ this.app = new CliApp$1();
252
+ return super.handle();
253
+ }
254
+ };
255
+
256
+ //#endregion
257
+ //#region dist/commands/ModelsSyncCommand.js
258
+ var ModelsSyncCommand$1 = class extends ModelsSyncCommand {
259
+ async handle() {
260
+ this.app.command = this;
261
+ this.app = new CliApp$1();
262
+ return super.handle();
263
+ }
264
+ };
265
+
266
+ //#endregion
267
+ //#region dist/commands/RouteList.js
268
+ var RouteList = class extends Command {
269
+ signature = `route:list
21
270
  {--p|path? : Path to filter routes by}
22
271
  {--m|method? : Method to filter routes by}
23
- `;description=`List all registered routes`;async handle(){let e=await this.app.core.getRouter().list(this.options(),this.app.core.getAppInstance()),t=this.filterRoutes(e);console.log(this.formatRoutes(t.reverse())),this.newLine(),this.info(`Total routes: ${t.length}`)}filterRoutes(e){let t=this.option(`path`),n=this.option(`method`);return!t&&!n?e:e.filter(e=>{let r=t?e.path.includes(t):!0,i=n?e.methods.includes(n.toLowerCase()):!0;return r&&i})}formatRoutes(e){if(e.length===0)return`No routes registered.`;let t=e.map(e=>({method:e.methods.join(` | `).toUpperCase(),path:e.path,handler:e.controllerName?`${e.controllerName} → ${e.actionName}`:e.actionName??`N/A`})),n=Math.max(6,...t.map(e=>e.method.length)),r=Math.max(4,...t.map(e=>e.path.length)),i=Math.max(7,...t.map(e=>e.handler.length));return[`${`METHOD`.padEnd(n)} ${`PATH`.padEnd(r)} ${`HANDLER`.padEnd(i)}`,`${`-`.repeat(n)} ${`-`.repeat(r)} ${`-`.repeat(i)}`,...t.map(e=>`${this.formatMethod(e.method.padEnd(n))} ${x.blue(e.path.padEnd(r))} ${x.yellow(e.handler.padEnd(i))}`)].join(`
24
- `)}methodColor(e){switch(e){case`GET`:return x.green(e);case`POST`:return x.blue(e);case`PUT`:return x.yellow(e);case`DELETE`:return x.red(e);case`PATCH`:return x.magenta(e);case`OPTIONS`:return x.cyan(e);default:return x.gray(e)}}formatMethod(e){let t=e.split(` | `);return t.length>1?t.map(e=>this.methodColor(e)).join(x.gray(` | `)):this.methodColor(e.toUpperCase())}},R=class extends b{async handle(){return this.app.command=this,this.app=new d,super.handle()}},z=String.raw`
272
+ `;
273
+ description = "List all registered routes";
274
+ async handle() {
275
+ const routes = await this.app.core.getRouter().list(this.options(), this.app.core.getAppInstance());
276
+ const filteredRoutes = this.filterRoutes(routes);
277
+ console.log(this.formatRoutes(filteredRoutes.reverse()));
278
+ this.newLine();
279
+ this.info(`Total routes: ${filteredRoutes.length}`);
280
+ }
281
+ filterRoutes(routes) {
282
+ const path = this.option("path");
283
+ const method = this.option("method");
284
+ if (!path && !method) return routes;
285
+ return routes.filter((route) => {
286
+ const pathMatches = path ? route.path.includes(path) : true;
287
+ const methodMatches = method ? route.methods.includes(method.toLowerCase()) : true;
288
+ return pathMatches && methodMatches;
289
+ });
290
+ }
291
+ formatRoutes(routes) {
292
+ if (routes.length === 0) return "No routes registered.";
293
+ const rows = routes.map((route) => ({
294
+ method: route.methods.join(" | ").toUpperCase(),
295
+ path: route.path,
296
+ handler: route.controllerName ? `${route.controllerName} → ${route.actionName}` : route.actionName ?? "N/A"
297
+ }));
298
+ const methodWidth = Math.max(6, ...rows.map((row) => row.method.length));
299
+ const pathWidth = Math.max(4, ...rows.map((row) => row.path.length));
300
+ const handlerWidth = Math.max(7, ...rows.map((row) => row.handler.length));
301
+ return [
302
+ `${"METHOD".padEnd(methodWidth)} ${"PATH".padEnd(pathWidth)} ${"HANDLER".padEnd(handlerWidth)}`,
303
+ `${"-".repeat(methodWidth)} ${"-".repeat(pathWidth)} ${"-".repeat(handlerWidth)}`,
304
+ ...rows.map((row) => `${this.formatMethod(row.method.padEnd(methodWidth))} ${chalk.blue(row.path.padEnd(pathWidth))} ${chalk.yellow(row.handler.padEnd(handlerWidth))}`)
305
+ ].join("\n");
306
+ }
307
+ methodColor(method) {
308
+ switch (method) {
309
+ case "GET": return chalk.green(method);
310
+ case "POST": return chalk.blue(method);
311
+ case "PUT": return chalk.yellow(method);
312
+ case "DELETE": return chalk.red(method);
313
+ case "PATCH": return chalk.magenta(method);
314
+ case "OPTIONS": return chalk.cyan(method);
315
+ default: return chalk.gray(method);
316
+ }
317
+ }
318
+ formatMethod(method) {
319
+ const methods = method.split(" | ");
320
+ if (methods.length > 1) return methods.map((m) => this.methodColor(m)).join(chalk.gray(" | "));
321
+ return this.methodColor(method.toUpperCase());
322
+ }
323
+ };
324
+
325
+ //#endregion
326
+ //#region dist/commands/SeedCommand.js
327
+ var SeedCommand$1 = class extends SeedCommand {
328
+ async handle() {
329
+ this.app.command = this;
330
+ this.app = new CliApp$1();
331
+ return super.handle();
332
+ }
333
+ };
334
+
335
+ //#endregion
336
+ //#region dist/logo.js
337
+ var logo_default = String.raw`
25
338
  ___ _ _
26
339
  / _ \ | | | |
27
340
  / /_\ \_ __ ___ ___| |_ __ _ ___| | __
28
341
  | _ | '__/ __/ __| __/ _' |/ __| |/ /
29
342
  | | | | | | (__\__ \ || (_| | (__| <
30
343
  \_| |_/_| \___|___/\__\__,_|\___|_|\_\
31
- `;const B=async()=>(await import(n(r(process.cwd(),`dist/core/bootstrap.js`)).href)).app,V=async(t={})=>{S();let n=await B(),i=process.env.ARKSTACK_STUBS_DIR;await s.init(await new e(n,{stubsDir:i}).loadConfig(),{logo:t.logo??z,name:`Cmd`,baseCommands:[L,j,E,O,w,C,D,k,A,M,N,I,R,T,P,F],discoveryPaths:[r(process.cwd(),`src`,`app/console/commands/*.js`),r(process.cwd(),`src`,`app/console/commands/*.js`),r(process.cwd(),`src`,`app/console/commands/*.mjs`)],exceptionHandler(e){throw e}})};(()=>{let e=process.argv[1];if(!e)return!1;try{return a(t(import.meta.url))===a(e)}catch{return import.meta.url===n(e).href}})()&&await V();export{V as runConsoleKernel};
344
+ `;
345
+
346
+ //#endregion
347
+ //#region dist/index.js
348
+ /**
349
+ * Loads the core application instance by importing the bootstrap file.
350
+ *
351
+ * @returns
352
+ */
353
+ const loadCoreApp = async () => {
354
+ return (await import(pathToFileURL(join(process.cwd(), "dist/core/bootstrap.js")).href)).app;
355
+ };
356
+ /**
357
+ * Runs the console kernel, initializing the application and registering commands.
358
+ *
359
+ * @param options
360
+ */
361
+ const runConsoleKernel = async (options = {}) => {
362
+ loadPrototypes();
363
+ const app = await loadCoreApp();
364
+ const stubsDir = process.env.ARKSTACK_STUBS_DIR;
365
+ await Kernel.init(await new ArkstackConsoleApp(app, { stubsDir }).loadConfig(), {
366
+ logo: options.logo ?? logo_default,
367
+ name: "Cmd",
368
+ baseCommands: [
369
+ RouteList,
370
+ MakeResource$1,
371
+ MakeController,
372
+ MakeFullResource,
373
+ DevCommand,
374
+ BuildCommand,
375
+ MakeFactoryCommand$1,
376
+ MakeMigrationCommand$1,
377
+ MakeModelCommand$1,
378
+ MakeSeederCommand$1,
379
+ MigrateCommand$1,
380
+ ModelsSyncCommand$1,
381
+ SeedCommand$1,
382
+ MakeCommand,
383
+ MigrateRollbackCommand$1,
384
+ MigrationHistoryCommand$1
385
+ ],
386
+ discoveryPaths: [
387
+ join(process.cwd(), "src", "app/console/commands/*.js"),
388
+ join(process.cwd(), "src", "app/console/commands/*.js"),
389
+ join(process.cwd(), "src", "app/console/commands/*.mjs")
390
+ ],
391
+ exceptionHandler(exception) {
392
+ throw exception;
393
+ }
394
+ });
395
+ };
396
+ /**
397
+ * Determines if the current module is being executed as the entry
398
+ * point of the application.
399
+ *
400
+ * @returns
401
+ */
402
+ const isEntrypointExecution = () => {
403
+ const argvEntry = process.argv[1];
404
+ if (!argvEntry) return false;
405
+ try {
406
+ return realpathSync(fileURLToPath(import.meta.url)) === realpathSync(argvEntry);
407
+ } catch {
408
+ return import.meta.url === pathToFileURL(argvEntry).href;
409
+ }
410
+ };
411
+ if (isEntrypointExecution()) await runConsoleKernel();
412
+
413
+ //#endregion
414
+ export { runConsoleKernel };
package/dist/prepare.js CHANGED
@@ -1 +1,26 @@
1
- import{spawn as e}from"node:child_process";import t from"chalk";const n=e(process.platform===`win32`?`pnpm.cmd`:`pnpm`,[`exec`,`tsdown`,`--log-level=silent`],{cwd:process.cwd(),stdio:`inherit`,env:Object.assign({},process.env,{NODE_ENV:`production`})});n.on(`error`,e=>{throw e}),n.on(`exit`,e=>{if(e===0||e===null){console.log(t.green(`Arkstak is ready for development!`));return}throw Error(`tsdown exited with code ${e}`)});export{};
1
+ import { spawn } from "node:child_process";
2
+ import chalk from "chalk";
3
+
4
+ //#region dist/prepare.js
5
+ const child = spawn(process.platform === "win32" ? "pnpm.cmd" : "pnpm", [
6
+ "exec",
7
+ "tsdown",
8
+ "--log-level=silent"
9
+ ], {
10
+ cwd: process.cwd(),
11
+ stdio: "inherit",
12
+ env: Object.assign({}, process.env, { NODE_ENV: "production" })
13
+ });
14
+ child.on("error", (error) => {
15
+ throw error;
16
+ });
17
+ child.on("exit", (code) => {
18
+ if (code === 0 || code === null) {
19
+ console.log(chalk.green("Arkstak is ready for development!"));
20
+ return;
21
+ }
22
+ throw new Error(`tsdown exited with code ${code}`);
23
+ });
24
+
25
+ //#endregion
26
+ export { };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkstack/console",
3
- "version": "0.1.26",
3
+ "version": "0.1.28",
4
4
  "type": "module",
5
5
  "description": "Console package for Arkstack providing console-specific implementations of core Arkstack features such as routing, middleware, and database integration.",
6
6
  "homepage": "https://arkstack.toneflix.net",
@@ -49,8 +49,8 @@
49
49
  "@h3ravel/musket": "^0.10.1",
50
50
  "chalk": "^5.6.2",
51
51
  "resora": "^0.2.14",
52
- "@arkstack/common": "^0.1.26",
53
- "@arkstack/contract": "^0.1.26"
52
+ "@arkstack/common": "^0.1.28",
53
+ "@arkstack/contract": "^0.1.28"
54
54
  },
55
55
  "scripts": {
56
56
  "build": "tsdown",