@arkstack/console 0.1.15 → 0.1.17
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/index.js +7 -7
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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,
|
|
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,MigrationHistoryCommand as _,ModelsSyncCommand as v,SeedCommand as y}from"arkormx";import b from"chalk";import{loadPrototypes as x}from"@arkstack/common";var S=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}`))})})}},C=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}`))})})}},w=class extends o{signature=`make:command
|
|
3
3
|
{name : name of the command to create}
|
|
4
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
|
-
`)}},
|
|
5
|
+
`)}},T=class extends o{signature=`make:controller
|
|
6
6
|
{name : name of the controller to create}
|
|
7
7
|
{--api : make an API controller}
|
|
8
8
|
{--m|model? : name of model to attach to controller}
|
|
@@ -10,22 +10,22 @@ import{ArkstackConsoleApp as e}from"./app.js";import{fileURLToPath as t,pathToFi
|
|
|
10
10
|
{--s|seeder : Create a seeder file for the model (only if --model is specified)}
|
|
11
11
|
{--x|migration : Create a migration file for the model (only if --model is specified)}
|
|
12
12
|
{--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)))}},
|
|
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)))}},E=class extends f{async handle(){return this.app.command=this,this.app=new d,super.handle()}},D=class extends o{signature=`make:full-resource
|
|
14
14
|
{prefix : prefix of the resources to create, "Admin" will create AdminResource, AdminCollection and AdminController}
|
|
15
15
|
{--m|model? : name of model to attach to the generated controller (will be created if it doesn't exist)}
|
|
16
16
|
{--f|factory : Create and link a factory}
|
|
17
17
|
{--s|seeder : Create a seeder file for the model (only if --model is specified)}
|
|
18
18
|
{--x|migration : Create a migration file for the model (only if --model is specified)}
|
|
19
19
|
{--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)))}},
|
|
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)))}},O=class extends p{async handle(){return this.app.command=this,this.app=new d,super.handle()}},k=class extends m{async handle(){return this.app.command=this,this.app=new d,super.handle()}},A=class extends i{},j=class extends h{async handle(){return this.app.command=this,this.app=new d,super.handle()}},M=class extends g{async handle(){return this.app.command=this,this.app=new d,super.handle()}},N=class extends _{async handle(){return this.app.command=this,this.app=new d,super.handle()}},P=class extends v{async handle(){return this.app.command=this,this.app=new d,super.handle()}},F=class extends o{signature=`route:list
|
|
21
21
|
{--p|path? : Path to filter routes by}
|
|
22
22
|
{--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))} ${
|
|
24
|
-
`)}methodColor(e){switch(e){case`GET`:return
|
|
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))} ${b.blue(e.path.padEnd(r))} ${b.yellow(e.handler.padEnd(i))}`)].join(`
|
|
24
|
+
`)}methodColor(e){switch(e){case`GET`:return b.green(e);case`POST`:return b.blue(e);case`PUT`:return b.yellow(e);case`DELETE`:return b.red(e);case`PATCH`:return b.magenta(e);case`OPTIONS`:return b.cyan(e);default:return b.gray(e)}}formatMethod(e){let t=e.split(` | `);return t.length>1?t.map(e=>this.methodColor(e)).join(b.gray(` | `)):this.methodColor(e.toUpperCase())}},I=class extends y{async handle(){return this.app.command=this,this.app=new d,super.handle()}},L=String.raw`
|
|
25
25
|
___ _ _
|
|
26
26
|
/ _ \ | | | |
|
|
27
27
|
/ /_\ \_ __ ___ ___| |_ __ _ ___| | __
|
|
28
28
|
| _ | '__/ __/ __| __/ _' |/ __| |/ /
|
|
29
29
|
| | | | | | (__\__ \ || (_| | (__| <
|
|
30
30
|
\_| |_/_| \___|___/\__\__,_|\___|_|\_\
|
|
31
|
-
`;const
|
|
31
|
+
`;const R=async()=>(await import(n(r(process.cwd(),`dist/core/bootstrap.js`)).href)).app,z=async(t={})=>{x();let n=await R(),i=process.env.ARKSTACK_STUBS_DIR;await s.init(await new e(n,{stubsDir:i}).loadConfig(),{logo:t.logo??L,name:`Cmd`,baseCommands:[F,A,T,D,C,S,E,O,k,j,M,P,I,w,N],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 z();export{z as runConsoleKernel};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkstack/console",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
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",
|
|
@@ -43,14 +43,14 @@
|
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"clear-router": "^2.1.7",
|
|
46
|
-
"arkormx": "^0.2.
|
|
46
|
+
"arkormx": "^0.2.5"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@h3ravel/musket": "^0.10.1",
|
|
50
50
|
"chalk": "^5.6.2",
|
|
51
51
|
"resora": "^0.2.6",
|
|
52
|
-
"@arkstack/common": "^0.1.
|
|
53
|
-
"@arkstack/contract": "^0.1.
|
|
52
|
+
"@arkstack/common": "^0.1.17",
|
|
53
|
+
"@arkstack/contract": "^0.1.17"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"build": "tsdown",
|