@h3ravel/console 11.3.9 → 11.5.0

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.
@@ -0,0 +1 @@
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));Object.defineProperty(exports,`__toESM`,{enumerable:!0,get:function(){return s}});
package/bin/fire.cjs CHANGED
@@ -1,5 +1,8 @@
1
1
  #!/usr/bin/env node
2
- var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));require(`tsx/esm`);let c=require(`@h3ravel/core`);c=s(c);let l=require(`@h3ravel/shared`);l=s(l);let u=require(`node:fs/promises`);u=s(u);let d=require(`@h3ravel/support`);d=s(d);let f=require(`dayjs`);f=s(f);let p=require(`node:path`);p=s(p);let m=require(`@h3ravel/http`);m=s(m);let h=require(`@h3ravel/router`);h=s(h);let g=require(`@h3ravel/database`);g=s(g);let _=require(`@h3ravel/cache`);_=s(_);let v=require(`@h3ravel/queue`);v=s(v);let y=require(`@h3ravel/mail`);y=s(y);let b=require(`@h3ravel/config`);b=s(b);let x=require(`commander`);x=s(x);let S=require(`node:fs`);S=s(S);let C=require(`path`);C=s(C);let w=require(`child_process`);w=s(w);let T=require(`tsdown`);T=s(T);var E=class extends c.ConsoleCommand{};const D=String.raw`
2
+ const e=require(`./chunk-CUT6urMc.cjs`);require(`tsx/esm`);let t=require(`@h3ravel/core`);t=e.__toESM(t);let n=require(`@h3ravel/shared`);n=e.__toESM(n);let r=require(`execa`);r=e.__toESM(r);let i=require(`preferred-pm`);i=e.__toESM(i);let a=require(`node:fs/promises`);a=e.__toESM(a);let o=require(`@h3ravel/support`);o=e.__toESM(o);let s=require(`dayjs`);s=e.__toESM(s);let c=require(`node:path`);c=e.__toESM(c);let l=require(`commander`);l=e.__toESM(l);let u=require(`node:fs`);u=e.__toESM(u);let d=require(`child_process`);d=e.__toESM(d);let f=require(`path`);f=e.__toESM(f);let p=require(`tsdown`);p=e.__toESM(p);var m=class extends t.ConsoleCommand{signature=`build:
3
+ {--m|minify=false : Minify your bundle output}
4
+ `;description=`Build the app for production`;async handle(){try{await this.fire()}catch(e){n.Logger.error(e)}}async fire(){let e=env(`DIST_DIR`,`dist`),t=(await(0,i.default)(base_path()))?.name??`pnpm`,a=this.option(`minify`),o={EXTENDED_DEBUG:Number(this.option(`verbose`,0))>0?`true`:`false`,CLI_BUILD:`true`,NODE_ENV:`production`,DIST_DIR:e,DIST_MINIFY:a,LOG_LEVEL:[`silent`,`info`,`warn`,`error`][Number(this.option(`verbose`,0))]},s=o.LOG_LEVEL===`silent`?`--silent`:null;n.Logger.log([[`
5
+ INFO `,`bgBlue`],[` Creating Production Bundle`,`white`]],``),console.log(``),await n.TaskManager.taskRunner(n.Logger.log([[` SUCCESS `,`bgGreen`],[` Production Bundle Created`,`white`]],``,!1),async()=>{await(0,r.execa)(t,[`tsdown`,s,`--config-loader`,`unconfig`,`-c`,`tsdown.default.config.ts`].filter(e=>e!==null),{stdout:`inherit`,stderr:`inherit`,cwd:base_path(),env:Object.assign({},process.env,o)}),console.log(``)})}},h=class extends t.ConsoleCommand{};const g=String.raw`
3
6
  111
4
7
  111111111
5
8
  1111111111 111111
@@ -21,19 +24,19 @@ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=
21
24
  111111 111 111111
22
25
  111111111
23
26
  110
24
- `,O=String.raw`
27
+ `,_=String.raw`
25
28
  _ _ _____ _
26
29
  | | | |___ / _ __ __ ___ _____| |
27
30
  | |_| | |_ \| '__/ _ \ \ / / _ \ |
28
31
  | _ |___) | | | (_| |\ V / __/ |
29
32
  |_| |_|____/|_| \__,_| \_/ \___|_|
30
33
 
31
- `;var k=class extends E{signature=`list`;description=`List all available commands`;async handle(){let e=[{short:`-h`,long:`--help`,description:`Display help for the given command. When no command is given display help for the list command`}].concat(this.program.options).map(e=>l.Logger.describe(l.Logger.log(` `+[e.short,e.long].filter(e=>!!e).join(`, `),`green`,!1),e.description,25,!1).join(``)),t=this.program.commands.map(e=>l.Logger.describe(l.Logger.log(` `+e.name(),`green`,!1),e.description(),25,!1).join(``)).reduce((e,t)=>{let n=t.replace(/\x1b\[\d+m/g,``),r=n.includes(`:`)?n.split(`:`)[0].trim():`__root__`;return e[r]??=[],e[r].push(t),e},{}),n=Object.entries(t).map(([e,t])=>{let n=e===`__root__`?``:e;return[l.Logger.log(n,`yellow`,!1),t.join(`
34
+ `;var v=class extends h{signature=`list`;description=`List all available commands`;async handle(){let e=[{short:`-h`,long:`--help`,description:`Display help for the given command. When no command is given display help for the list command`}].concat(this.program.options).map(e=>n.Logger.describe(n.Logger.log(` `+[e.short,e.long].filter(e=>!!e).join(`, `),`green`,!1),e.description,25,!1).join(``)),t=this.program.commands.map(e=>n.Logger.describe(n.Logger.log(` `+e.name(),`green`,!1),e.description(),25,!1).join(``)).reduce((e,t)=>{let n=t.replace(/\x1b\[\d+m/g,``),r=n.includes(`:`)?n.split(`:`)[0].trim():`__root__`;return e[r]??=[],e[r].push(t),e},{}),r=Object.entries(t).map(([e,t])=>{let r=e===`__root__`?``:e;return[n.Logger.log(r,`yellow`,!1),t.join(`
32
35
  `)].join(`
33
- `)});l.Logger.log([[`H3ravel Framework`,`white`],[this.kernel.modulePackage.version,`green`]],` `),console.log(``),console.log(O),console.log(``),l.Logger.log(`Usage:`,`yellow`),l.Logger.log(` command [options] [arguments]`,`white`),console.log(``),l.Logger.log(`Options:`,`yellow`),console.log(e.join(`
34
- `).trim()),console.log(``),l.Logger.log(`Available Commands:`,`yellow`),console.log(n.join(`
36
+ `)});n.Logger.log([[`H3ravel Framework`,`white`],[this.kernel.modulePackage.version,`green`]],` `),console.log(``),console.log(_),console.log(``),n.Logger.log(`Usage:`,`yellow`),n.Logger.log(` command [options] [arguments]`,`white`),console.log(``),n.Logger.log(`Options:`,`yellow`),console.log(e.join(`
37
+ `).trim()),console.log(``),n.Logger.log(`Available Commands:`,`yellow`),console.log(r.join(`
35
38
 
36
- `).trim())}},A=class e{static CREATE_PATTERNS=[/^create_(\w+)_table$/,/^create_(\w+)$/];static CHANGE_PATTERNS=[/.+_(to|from|in)_(\w+)_table$/,/.+_(to|from|in)_(\w+)$/];static guess(t){for(let n of e.CREATE_PATTERNS){let e=t.match(n);if(e)return[e[1],!0]}for(let n of e.CHANGE_PATTERNS){let e=t.match(n);if(e)return[e[2],!1]}return[]}},j=class extends E{signature=`#make:
39
+ `).trim())}},y=class e{static CREATE_PATTERNS=[/^create_(\w+)_table$/,/^create_(\w+)$/];static CHANGE_PATTERNS=[/.+_(to|from|in)_(\w+)_table$/,/.+_(to|from|in)_(\w+)$/];static guess(t){for(let n of e.CREATE_PATTERNS){let e=t.match(n);if(e)return[e[1],!0]}for(let n of e.CHANGE_PATTERNS){let e=t.match(n);if(e)return[e[2],!1]}return[]}},b=class extends h{signature=`#make:
37
40
  {controller : Create a new controller class.
38
41
  | {--a|api : Exclude the create and edit methods from the controller}
39
42
  | {--m|model= : Generate a resource controller for the given model}
@@ -49,6 +52,10 @@ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=
49
52
  | {--t|table : The table to migrate}
50
53
  | {--c|create : The table to be created}
51
54
  }
55
+ {command : Create a new Musket command.
56
+ | {--command : The terminal command that will be used to invoke the class}
57
+ | {--force : Create the class even if the console command already exists}
58
+ }
52
59
  {factory : Create a new model factory.}
53
60
  {seeder : Create a new seeder class.}
54
61
  {view : Create a new view.
@@ -66,5 +73,5 @@ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=
66
73
  | {--force : Create the model even if it already exists}
67
74
  }
68
75
  {^name : The name of the [name] to generate}
69
- `;description=`Generate component classes`;async handle(){let e=this.dictionary.baseCommand??this.dictionary.name;this.argument(`name`)||this.program.error(`Please provide a valid name for the `+e);let t={controller:`makeController`,resource:`makeResource`,migration:`makeMigration`,factory:`makeFactory`,seeder:`makeSeeder`,model:`makeModel`,view:`makeView`};try{await this?.[t[e]]()}catch(e){l.Logger.error(e)}}async makeController(){let e=this.option(`api`)?`-resource`:``,t=this.argument(`name`),n=this.option(`force`),r=l.FileSystem.findModulePkg(`@h3ravel/http`,this.kernel.cwd)??``,i=p.default.join(r,`dist/stubs/controller${e}.stub`),a=app_path(`Http/Controllers/${t}.ts`);t.includes(`/`)&&await(0,u.mkdir)((0,d.beforeLast)(a,`/`),{recursive:!0}),!n&&await l.FileSystem.fileExists(a)&&l.Logger.error(`ERORR: ${t} controller already exists`);let o=await(0,u.readFile)(i,`utf-8`);o=o.replace(/{{ name }}/g,t),await(0,u.writeFile)(a,o),l.Logger.split(`INFO: Controller Created`,l.Logger.log(p.default.basename(a),`gray`,!1))}makeResource(){l.Logger.success(`Resource support is not yet available`)}async makeMigration(){let e=this.argument(`name`),t=(0,f.default)().format(`YYYY_MM_DD_HHmmss`),n=database_path(`migrations/${t}_${e}.ts`),r=l.FileSystem.findModulePkg(`@h3ravel/database`,this.kernel.cwd)??``,i=this.option(`create`,!1),a=this.option(`table`);if(!a&&typeof i==`string`&&(a=i,i=!0),!a){let t=A.guess(e);a=t[0],i=!!t[1]}let o=p.default.join(r,this.getMigrationStubName(a,i)),s=await(0,u.readFile)(o,`utf-8`);a!==null&&(s=s.replace(/DummyTable|{{\s*table\s*}}/g,a)),l.Logger.info(`INFO: Creating Migration`),await this.kernel.ensureDirectoryExists(p.default.dirname(n)),await(0,u.writeFile)(n,s),l.Logger.split(`INFO: Migration Created`,l.Logger.log(p.default.basename(n),`gray`,!1))}makeFactory(){l.Logger.success(`Factory support is not yet available`)}makeSeeder(){l.Logger.success(`Seeder support is not yet available`)}async makeModel(){let e=this.option(`type`,`ts`),t=this.argument(`name`),n=this.option(`force`),r=app_path(`Models/${t.toLowerCase()}.${e}`);t.includes(`/`)&&await(0,u.mkdir)((0,d.beforeLast)(r,`/`),{recursive:!0}),!n&&await l.FileSystem.fileExists(r)&&l.Logger.error(`ERORR: ${t} model already exists`);let i=l.FileSystem.findModulePkg(`@h3ravel/database`,this.kernel.cwd)??``,a=p.default.join(i,`dist/stubs/model-${e}.stub`),o=await(0,u.readFile)(a,`utf-8`);o=o.replace(/{{ name }}/g,t),await(0,u.writeFile)(r,o),l.Logger.split(`INFO: ${t} Model Created`,l.Logger.log(p.default.basename(r),`gray`,!1))}async makeView(){let e=this.argument(`name`),t=this.option(`force`),n=base_path(`src/resources/views/${e}.edge`);e.includes(`/`)&&await(0,u.mkdir)((0,d.beforeLast)(n,`/`),{recursive:!0}),!t&&await l.FileSystem.fileExists(n)&&l.Logger.error(`ERORR: ${e} view already exists`),await(0,u.writeFile)(n,`{{-- src/resources/views/${e}.edge --}}`),l.Logger.split(`INFO: View Created`,l.Logger.log(`src/resources/views/${e}.edge`,`gray`,!1))}getMigrationStubName(e,t=!1,n=`ts`){let r;return r=e?t?`migration.create-${n}.stub`:`migration.update-${n}.stub`:`migration-${n}.stub`,`dist/stubs/`+r}},M=class extends E{signature=`postinstall`;description=`Default post installation command`;async handle(){this.createSqliteDB()}async createSqliteDB(){config(`database.default`)===`sqlite`&&(await l.FileSystem.fileExists(database_path())||await(0,u.mkdir)(database_path(),{recursive:!0}),await l.FileSystem.fileExists(database_path(`db.sqlite`))||await(0,u.writeFile)(database_path(`db.sqlite`),``))}},N=[m.HttpServiceProvider,b.ConfigServiceProvider,h.RouteServiceProvider,h.AssetsServiceProvider,g.DatabaseServiceProvider,_.CacheServiceProvider,v.QueueServiceProvider,y.MailServiceProvider],P=class e{static parseOptions(t){let n=[],r=/\{([^{}]+(?:\{[^{}]*\}[^{}]*)*)\}/g,i;for(;(i=r.exec(t))!==null;){let t=i[1][0]===`^`||/:[#^]/.test(i[1]),r=([`#`,`^`].includes(i[1][0])||/:[#^]/.test(i[1]))&&!t,a=i[1].trim().replace(/[#^]/,``),o=a.indexOf(`:`);if(o===-1){n.push({name:a});continue}let s=a.substring(0,o).trim(),c=a.substring(o+1).trim(),l=c,u,d=c.indexOf(`|`);if(d!==-1){l=c.substring(0,d).trim();let t=c.substring(d+1).trim().replace(/^\{/,``).trim();u=e.parseOptions(`{`+t+`}`)}else l=l.trim();let f=s,p=/[^a-zA-Z0-9_|-]/.test(f),m=!1;f.endsWith(`?*`)?(p=!1,m=!0,f=f.slice(0,-2)):f.endsWith(`*`)?(m=!0,f=f.slice(0,-1)):f.endsWith(`?`)&&(p=!1,f=f.slice(0,-1));let h=f.startsWith(`--`),g,_;if(h){let e=f.split(`|`).map(e=>e.trim());g=[];for(let t of e){t.startsWith(`--`)&&t.slice(2).length===1?t=`-`+t.slice(2):t.startsWith(`-`)&&!t.startsWith(`--`)&&t.slice(1).length>1?t=`--`+t.slice(1):!t.startsWith(`-`)&&t.slice(1).length>1&&(t=`--`+t);let e=t.indexOf(`=`);if(e!==-1){g.push(t.substring(0,e));let n=t.substring(e+1);_=n===`*`?[]:n===`true`||n===`false`||!n&&!p?n===`true`:isNaN(Number(n))?n:Number(n)}else g.push(t)}}n.push({name:h?g[g.length-1]:f,required:p,multiple:m,description:l,flags:g,shared:t,isFlag:h,isHidden:r,defaultValue:_,nestedOptions:u})}return n}static parseSignature(t,n){let r=t.split(`
70
- `).map(e=>e.trim()).filter(e=>e.length>0),i=[`#`,`^`].includes(r[0][0])||/:[#^]/.test(r[0]),a=r[0].replace(/[^\w=:-]/g,``),o=n.getDescription(),s=a.endsWith(`:`),c=r.slice(1).join(` `),l=e.parseOptions(c);return s?{baseCommand:a.slice(0,-1),isNamespaceCommand:s,subCommands:l.filter(e=>!e.flags&&!e.isHidden),description:o,commandClass:n,options:l.filter(e=>!!e.flags),isHidden:i}:{baseCommand:a,isNamespaceCommand:s,options:l,description:o,commandClass:n,isHidden:i}}};function F(e={}){let t,n,r=e.args||[],i=e.allowRestarts||!1,a=e.input,o=e.options||e;return delete o.args,delete o.allowRestarts,{name:`run`,buildStart(e){let n=a??e.input;if(typeof n==`string`&&(n=[n]),typeof n==`object`&&(n=Object.values(n)),n.length>1)throw Error("@rollup/plugin-run must have a single entry point; consider setting the `input` option");t=(0,C.resolve)(n[0])},generateBundle(e,t,n){n||this.error(`@rollup/plugin-run currently only works with bundles that are written to disk`)},writeBundle(e,a){let s=(e,t)=>{n&&n.kill(),n=(0,w.fork)((0,C.join)(e,t),r,o)},c=e.dir||(0,C.dirname)(e.file),l=Object.keys(a).find(e=>{let n=a[e];return n.isEntry&&n.facadeModuleId===t});l?(s(c,l),i&&(process.stdin.resume(),process.stdin.setEncoding(`utf8`),process.stdin.on(`data`,e=>{let t=e.toString().trim().toLowerCase();t===`rs`||t===`restart`||e.toString().charCodeAt(0)===11?s(c,l):(t===`cls`||t===`clear`||e.toString().charCodeAt(0)===12)&&console.clear()}))):this.error(`@rollup/plugin-run could not find output chunk`)}}}const I=process.env.NODE_ENV||`development`,L=I===`development`?`.h3ravel/serve`:`dist`,R={outDir:L,entry:[`src/**/*.ts`],format:[`esm`],target:`node22`,sourcemap:I===`development`,clean:!0,shims:!0,copy:[{from:`public`,to:L},`src/resources`,`src/database`],env:I===`development`?{NODE_ENV:I,DIST_DIR:L}:{},watch:I===`development`&&process.env.CLI_BUILD!==`true`?[`.env`,`.env.*`,`src`,`../../packages`]:!1,dts:!1,logLevel:`silent`,nodeProtocol:!0,skipNodeModulesBundle:!0,hooks(e){e.hook(`build:done`,async()=>{let e=[`database/migrations`,`database/factories`,`database/seeders`];for(let t=0;t<e.length;t++){let n=e[t];(0,S.existsSync)(p.default.join(L,n))&&await(0,u.rm)(p.default.join(L,n),{recursive:!0})}})},plugins:I===`development`&&process.env.CLI_BUILD!==`true`?[F({env:Object.assign({},process.env,{NODE_ENV:I,DIST_DIR:L}),execArgv:[`-r`,`source-map-support/register`],allowRestarts:!1,input:process.cwd()+`/src/server.ts`})]:[]};var z=R,B=class e{commands=[];constructor(e,t){this.app=e,this.kernel=t}async build(){return this.loadBaseCommands(),await this.loadDiscoveredCommands(),this.initialize()}loadBaseCommands(){[new j(this.app,this.kernel),new k(this.app,this.kernel),new M(this.app,this.kernel)].forEach(e=>this.addCommand(e))}async loadDiscoveredCommands(){let e=[...this.app.registeredCommands.map(e=>new e(this.app,this.kernel))],t=app_path(`Console/Commands/*.js`).replace(`/src/`,`/.h3ravel/serve/`);for await(let n of(0,u.glob)(t)){let t=p.default.basename(n).replace(`.js`,``);try{let r=(await import(n))[t];e.push(new r(this.app,this.kernel))}catch{}}e.forEach(e=>this.addCommand(e))}addCommand(e){this.commands.push(P.parseSignature(e.getSignature(),e))}initialize(){let e=l.Logger.parse([[`Musket CLI:`,`white`],[this.kernel.consolePackage.version,`green`]],` `,!1),t=l.Logger.parse([[`H3ravel Framework:`,`white`],[this.kernel.modulePackage.version,`green`]],` `,!1),n={quiet:[`-q, --quiet`,`Do not output any message`],silent:[`--silent`,`Do not output any message`],verbose:[`-v, --verbose <number>`,`Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug`],lock:[`--lock`,`Locked and loaded, do not ask any interactive question`]};x.program.name(`musket`).version(`${e}\n${t}`).description(O).addOption(new x.Option(n.quiet[0],n.quiet[1]).implies({silent:!0})).addOption(new x.Option(n.silent[0],n.silent[1]).implies({quiet:!0})).addOption(new x.Option(n.verbose[0],n.verbose[1]).choices([`1`,`2`,`3`])).addOption(new x.Option(n.lock[0],n.lock[1])).action(async()=>{let e=new k(this.app,this.kernel);e.setInput(x.program.opts(),x.program.args,x.program.registeredArguments,{},x.program),e.handle()}),x.program.command(`init`).description(`Initialize H3ravel.`).action(async()=>{l.Logger.success(`Initialized: H3ravel has been initialized!`)});for(let e=0;e<this.commands.length;e++){let t=this.commands[e],r=t.commandClass;if(t.isNamespaceCommand&&t.subCommands){let e=t.isHidden?x.program:x.program.command(t.baseCommand).description(t.description??``).addOption(new x.Option(n.quiet[0],n.quiet[1]).implies({silent:!0})).addOption(new x.Option(n.silent[0],n.silent[1]).implies({quiet:!0})).addOption(new x.Option(n.verbose[0],n.verbose[1]).choices([`1`,`2`,`3`])).addOption(new x.Option(n.lock[0],n.lock[1])).action(async()=>{r.setInput(e.opts(),e.args,e.registeredArguments,t,x.program),await r.handle()});(t.options?.length??0)>0&&t.options?.filter((e,t,n)=>n.findIndex(t=>t.name===e.name)===t).forEach(t=>{this.makeOption(t,e)}),t.subCommands.filter((e,t,n)=>!e.shared&&n.findIndex(t=>t.name===e.name)===t).forEach(e=>{let i=x.program.command(`${t.baseCommand}:${e.name}`).description(e.description||``).addOption(new x.Option(n.quiet[0],n.quiet[1]).implies({silent:!0})).addOption(new x.Option(n.silent[0],n.silent[1]).implies({quiet:!0})).addOption(new x.Option(n.verbose[0],n.verbose[1]).choices([`1`,`2`,`3`])).addOption(new x.Option(n.lock[0],n.lock[1])).action(async()=>{r.setInput(i.opts(),i.args,i.registeredArguments,e,x.program),await r.handle()});t.subCommands?.filter(e=>e.shared).forEach(t=>{this.makeOption(t,i,!1,e)}),t.options?.filter(e=>e.shared).forEach(t=>{this.makeOption(t,i,!1,e)}),e.nestedOptions&&e.nestedOptions.filter((e,t,n)=>n.findIndex(t=>t.name===e.name)===t).forEach(e=>{this.makeOption(e,i)})})}else{let e=x.program.command(t.baseCommand).description(t.description??``);t?.options?.filter((e,t,n)=>n.findIndex(t=>t.name===e.name)===t).forEach(t=>{this.makeOption(t,e,!0)}),e.action(async()=>{r.setInput(e.opts(),e.args,e.registeredArguments,t,x.program),await r.handle()})}}return x.program.hook(`preAction`,async(e,t)=>{t.name()!==`fire`&&await(0,T.build)({...z,watch:!1,plugins:[]})}),x.program}makeOption(e,t,n,r){let i=e.description?.replace(/\[(\w+)\]/g,(e,t)=>r?.[t]??`[${t}]`)??``,a=e.name.replaceAll(`-`,``);if(e.isFlag)if(n){let n=e.flags?.map(e=>e.length===1?`-${e}`:`--${e}`).join(`, `).replaceAll(`----`,`--`).replaceAll(`---`,`-`);t.option(n||``,i,String(e.defaultValue)||void 0)}else t.option(e.flags?.join(`, `)+(e.required?` <${a}>`:``),i,e.defaultValue);else t.argument(e.required?`<${e.name}>`:`[${e.name}]`,i,e.defaultValue)}static async parse(t){return(await new e(t.app,t).build()).parseAsync()}},V=class e extends c.ConsoleKernel{constructor(e){super(e),this.app=e}static init(t){let n=new e(t);Promise.all([n.loadRequirements()]).then(([e])=>e.run())}async run(){await B.parse(this),process.exit(0)}async loadRequirements(){this.cwd=p.default.join(process.cwd(),this.basePath),this.modulePath=l.FileSystem.findModulePkg(`@h3ravel/core`,this.cwd)??``,this.consolePath=l.FileSystem.findModulePkg(`@h3ravel/console`,this.cwd)??``;try{this.modulePackage=await import(p.default.join(this.modulePath,`package.json`))}catch{this.modulePackage={version:`N/A`}}try{this.consolePackage=await import(p.default.join(this.consolePath,`package.json`))}catch{this.consolePackage={version:`N/A`}}return this}},H=class extends c.ServiceProvider{static priority=992;static console=!0;register(){}boot(){V.init(this.app),process.on(`SIGINT`,()=>{process.exit(0)}),process.on(`SIGTERM`,()=>{process.exit(0)})}},U=class{async fire(){let e=new c.Application(process.cwd()),t=app_path(`Providers/*.js`).replace(`/src/`,`/.h3ravel/serve/`);for await(let e of(0,u.glob)(t)){let t=p.default.basename(e).replace(`.js`,``);try{N.push((await import(e))[t])}catch{}}N.push(H),e.registerProviders(N),await e.registerConfiguredProviders(),await e.boot()}};new U().fire();
76
+ `;description=`Generate component classes`;async handle(){let e=this.dictionary.baseCommand??this.dictionary.name;this.argument(`name`)||this.program.error(`Please provide a valid name for the `+e);let t={controller:`makeController`,resource:`makeResource`,migration:`makeMigration`,factory:`makeFactory`,seeder:`makeSeeder`,model:`makeModel`,view:`makeView`,command:`makeCommand`};try{await this?.[t[e]]()}catch(e){n.Logger.error(e)}}async makeController(){let e=this.option(`api`)?`-resource`:``,t=this.argument(`name`),r=this.option(`force`),i=n.FileSystem.findModulePkg(`@h3ravel/http`,this.kernel.cwd)??``,s=c.default.join(i,`dist/stubs/controller${e}.stub`),l=app_path(`Http/Controllers/${t}.ts`);t.includes(`/`)&&await(0,a.mkdir)((0,o.beforeLast)(l,`/`),{recursive:!0}),!r&&await n.FileSystem.fileExists(l)&&n.Logger.error(`ERORR: ${t} controller already exists`);let u=await(0,a.readFile)(s,`utf-8`);u=u.replace(/{{ name }}/g,t),await(0,a.writeFile)(l,u),n.Logger.split(`INFO: Controller Created`,n.Logger.log(c.default.basename(l),`gray`,!1))}makeResource(){n.Logger.success(`Resource support is not yet available`)}async makeMigration(){let e=this.argument(`name`),t=(0,s.default)().format(`YYYY_MM_DD_HHmmss`),r=database_path(`migrations/${t}_${e}.ts`),i=n.FileSystem.findModulePkg(`@h3ravel/database`,this.kernel.cwd)??``,o=this.option(`create`,!1),l=this.option(`table`);if(!l&&typeof o==`string`&&(l=o,o=!0),!l){let t=y.guess(e);l=t[0],o=!!t[1]}let u=c.default.join(i,this.getMigrationStubName(l,o)),d=await(0,a.readFile)(u,`utf-8`);l!==null&&(d=d.replace(/DummyTable|{{\s*table\s*}}/g,l)),n.Logger.info(`INFO: Creating Migration`),await this.kernel.ensureDirectoryExists(c.default.dirname(r)),await(0,a.writeFile)(r,d),n.Logger.split(`INFO: Migration Created`,n.Logger.log(c.default.basename(r),`gray`,!1))}makeFactory(){n.Logger.success(`Factory support is not yet available`)}makeCommand(){n.Logger.success(`Musket command creation is not yet available`)}makeSeeder(){n.Logger.success(`Seeder support is not yet available`)}async makeModel(){let e=this.option(`type`,`ts`),t=this.argument(`name`),r=this.option(`force`),i=app_path(`Models/${t.toLowerCase()}.${e}`);t.includes(`/`)&&await(0,a.mkdir)((0,o.beforeLast)(i,`/`),{recursive:!0}),!r&&await n.FileSystem.fileExists(i)&&n.Logger.error(`ERORR: ${t} model already exists`);let s=n.FileSystem.findModulePkg(`@h3ravel/database`,this.kernel.cwd)??``,l=c.default.join(s,`dist/stubs/model-${e}.stub`),u=await(0,a.readFile)(l,`utf-8`);u=u.replace(/{{ name }}/g,t),await(0,a.writeFile)(i,u),n.Logger.split(`INFO: ${t} Model Created`,n.Logger.log(c.default.basename(i),`gray`,!1))}async makeView(){let e=this.argument(`name`),t=this.option(`force`),r=base_path(`src/resources/views/${e}.edge`);e.includes(`/`)&&await(0,a.mkdir)((0,o.beforeLast)(r,`/`),{recursive:!0}),!t&&await n.FileSystem.fileExists(r)&&n.Logger.error(`ERORR: ${e} view already exists`),await(0,a.writeFile)(r,`{{-- src/resources/views/${e}.edge --}}`),n.Logger.split(`INFO: View Created`,n.Logger.log(`src/resources/views/${e}.edge`,`gray`,!1))}getMigrationStubName(e,t=!1,n=`ts`){let r;return r=e?t?`migration.create-${n}.stub`:`migration.update-${n}.stub`:`migration-${n}.stub`,`dist/stubs/`+r}},x=class extends h{signature=`postinstall`;description=`Default post installation command`;async handle(){this.createSqliteDB()}async createSqliteDB(){config(`database.default`)===`sqlite`&&(await n.FileSystem.fileExists(database_path())||await(0,a.mkdir)(database_path(),{recursive:!0}),await n.FileSystem.fileExists(database_path(`db.sqlite`))||await(0,a.writeFile)(database_path(`db.sqlite`),``))}},S=class e{static parseOptions(t){let n=[],r=/\{([^{}]+(?:\{[^{}]*\}[^{}]*)*)\}/g,i;for(;(i=r.exec(t))!==null;){let t=i[1][0]===`^`||/:[#^]/.test(i[1]),r=([`#`,`^`].includes(i[1][0])||/:[#^]/.test(i[1]))&&!t,a=i[1].trim().replace(/[#^]/,``),o=a.indexOf(`:`);if(o===-1){n.push({name:a});continue}let s=a.substring(0,o).trim(),c=a.substring(o+1).trim(),l=c,u,d=c.indexOf(`|`);if(d!==-1){l=c.substring(0,d).trim();let t=c.substring(d+1).trim().replace(/^\{/,``).trim();u=e.parseOptions(`{`+t+`}`)}else l=l.trim();let f=s,p=/[^a-zA-Z0-9_|-]/.test(f),m=!1;f.endsWith(`?*`)?(p=!1,m=!0,f=f.slice(0,-2)):f.endsWith(`*`)?(m=!0,f=f.slice(0,-1)):f.endsWith(`?`)&&(p=!1,f=f.slice(0,-1));let h=f.startsWith(`--`),g,_;if(h){let e=f.split(`|`).map(e=>e.trim());g=[];for(let t of e){t.startsWith(`--`)&&t.slice(2).length===1?t=`-`+t.slice(2):t.startsWith(`-`)&&!t.startsWith(`--`)&&t.slice(1).length>1?t=`--`+t.slice(1):!t.startsWith(`-`)&&t.slice(1).length>1&&(t=`--`+t);let e=t.indexOf(`=`);if(e!==-1){g.push(t.substring(0,e));let n=t.substring(e+1);_=n===`*`?[]:n===`true`||n===`false`||!n&&!p?n===`true`:isNaN(Number(n))?n:Number(n)}else g.push(t)}}n.push({name:h?g[g.length-1]:f,required:p,multiple:m,description:l,flags:g,shared:t,isFlag:h,isHidden:r,defaultValue:_,nestedOptions:u})}return n}static parseSignature(t,n){let r=t.split(`
77
+ `).map(e=>e.trim()).filter(e=>e.length>0),i=[`#`,`^`].includes(r[0][0])||/:[#^]/.test(r[0]),a=r[0].replace(/[^\w=:-]/g,``),o=n.getDescription(),s=a.endsWith(`:`),c=r.slice(1).join(` `),l=e.parseOptions(c);return s?{baseCommand:a.slice(0,-1),isNamespaceCommand:s,subCommands:l.filter(e=>!e.flags&&!e.isHidden),description:o,commandClass:n,options:l.filter(e=>!!e.flags),isHidden:i}:{baseCommand:a,isNamespaceCommand:s,options:l,description:o,commandClass:n,isHidden:i}}};function C(e={}){let t,n,r=e.args||[],i=e.allowRestarts||!1,a=e.input,o=e.options||e;return delete o.args,delete o.allowRestarts,{name:`run`,buildStart(e){let n=a??e.input;if(typeof n==`string`&&(n=[n]),typeof n==`object`&&(n=Object.values(n)),n.length>1)throw Error("@rollup/plugin-run must have a single entry point; consider setting the `input` option");t=(0,f.resolve)(n[0])},generateBundle(e,t,n){n||this.error(`@rollup/plugin-run currently only works with bundles that are written to disk`)},writeBundle(e,a){let s=(e,t)=>{n&&n.kill(),n=(0,d.fork)((0,f.join)(e,t),r,o)},c=e.dir||(0,f.dirname)(e.file),l=Object.keys(a).find(e=>{let n=a[e];return n.isEntry&&n.facadeModuleId===t});l?(s(c,l),i&&(process.stdin.resume(),process.stdin.setEncoding(`utf8`),process.stdin.on(`data`,e=>{let t=e.toString().trim().toLowerCase();t===`rs`||t===`restart`||e.toString().charCodeAt(0)===11?s(c,l):(t===`cls`||t===`clear`||e.toString().charCodeAt(0)===12)&&console.clear()}))):this.error(`@rollup/plugin-run could not find output chunk`)}}}const w=process.env.NODE_ENV||`development`;let T=w===`development`?`.h3ravel/serve`:`dist`;process.env.DIST_DIR&&(T=process.env.DIST_DIR);const E={outDir:T,entry:[`src/**/*.ts`],format:[`esm`],target:`node22`,sourcemap:w===`development`,minify:!!process.env.DIST_MINIFY,clean:!0,shims:!0,copy:[{from:`public`,to:T},`src/resources`,`src/database`],env:w===`development`?{NODE_ENV:w,DIST_DIR:T}:{},watch:w===`development`&&process.env.CLI_BUILD!==`true`?[`.env`,`.env.*`,`src`,`../../packages`]:!1,dts:!1,logLevel:`silent`,nodeProtocol:!0,skipNodeModulesBundle:!0,hooks(e){e.hook(`build:done`,async()=>{let e=[`database/migrations`,`database/factories`,`database/seeders`];for(let t=0;t<e.length;t++){let n=e[t];(0,u.existsSync)(c.default.join(T,n))&&await(0,a.rm)(c.default.join(T,n),{recursive:!0})}})},plugins:w===`development`&&process.env.CLI_BUILD!==`true`?[C({env:Object.assign({},process.env,{NODE_ENV:w,DIST_DIR:T}),execArgv:[`-r`,`source-map-support/register`],allowRestarts:!1,input:process.cwd()+`/src/server.ts`})]:[]};var D=E,O=class e{commands=[];constructor(e,t){this.app=e,this.kernel=t}async build(){return this.loadBaseCommands(),await this.loadDiscoveredCommands(),this.initialize()}loadBaseCommands(){[new b(this.app,this.kernel),new v(this.app,this.kernel),new x(this.app,this.kernel),new m(this.app,this.kernel)].forEach(e=>this.addCommand(e))}async loadDiscoveredCommands(){let e=`/${env(`DIST_DIR`,`.h3ravel/serve`)}/`.replaceAll(`//`,``),t=[...this.app.registeredCommands.map(e=>new e(this.app,this.kernel))],n=app_path(`Console/Commands/*.js`).replace(`/src/`,e);for await(let e of(0,a.glob)(n)){let n=c.default.basename(e).replace(`.js`,``);try{let r=(await import(e))[n];t.push(new r(this.app,this.kernel))}catch{}}t.forEach(e=>this.addCommand(e))}addCommand(e){this.commands.push(S.parseSignature(e.getSignature(),e))}initialize(){let e=n.Logger.parse([[`Musket CLI:`,`white`],[this.kernel.consolePackage.version,`green`]],` `,!1),t=n.Logger.parse([[`H3ravel Framework:`,`white`],[this.kernel.modulePackage.version,`green`]],` `,!1),r={quiet:[`-q, --quiet`,`Do not output any message`],silent:[`--silent`,`Do not output any message`],verbose:[`-v, --verbose <number>`,`Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug`],lock:[`--lock`,`Locked and loaded, do not ask any interactive question`]};l.program.name(`musket`).version(`${e}\n${t}`).description(_).addOption(new l.Option(r.quiet[0],r.quiet[1]).implies({silent:!0})).addOption(new l.Option(r.silent[0],r.silent[1]).implies({quiet:!0})).addOption(new l.Option(r.verbose[0],r.verbose[1]).choices([`1`,`2`,`3`])).addOption(new l.Option(r.lock[0],r.lock[1])).action(async()=>{let e=new v(this.app,this.kernel);e.setInput(l.program.opts(),l.program.args,l.program.registeredArguments,{},l.program),e.handle()}),l.program.command(`init`).description(`Initialize H3ravel.`).action(async()=>{n.Logger.success(`Initialized: H3ravel has been initialized!`)});for(let e=0;e<this.commands.length;e++){let t=this.commands[e],n=t.commandClass;if(t.isNamespaceCommand&&t.subCommands){let e=t.isHidden?l.program:l.program.command(t.baseCommand).description(t.description??``).addOption(new l.Option(r.quiet[0],r.quiet[1]).implies({silent:!0})).addOption(new l.Option(r.silent[0],r.silent[1]).implies({quiet:!0})).addOption(new l.Option(r.verbose[0],r.verbose[1]).choices([`1`,`2`,`3`])).addOption(new l.Option(r.lock[0],r.lock[1])).action(async()=>{n.setInput(e.opts(),e.args,e.registeredArguments,t,l.program),await n.handle()});(t.options?.length??0)>0&&t.options?.filter((e,t,n)=>n.findIndex(t=>t.name===e.name)===t).forEach(t=>{this.makeOption(t,e)}),t.subCommands.filter((e,t,n)=>!e.shared&&n.findIndex(t=>t.name===e.name)===t).forEach(e=>{let i=l.program.command(`${t.baseCommand}:${e.name}`).description(e.description||``).addOption(new l.Option(r.quiet[0],r.quiet[1]).implies({silent:!0})).addOption(new l.Option(r.silent[0],r.silent[1]).implies({quiet:!0})).addOption(new l.Option(r.verbose[0],r.verbose[1]).choices([`1`,`2`,`3`])).addOption(new l.Option(r.lock[0],r.lock[1])).action(async()=>{n.setInput(i.opts(),i.args,i.registeredArguments,e,l.program),await n.handle()});t.subCommands?.filter(e=>e.shared).forEach(t=>{this.makeOption(t,i,!1,e)}),t.options?.filter(e=>e.shared).forEach(t=>{this.makeOption(t,i,!1,e)}),e.nestedOptions&&e.nestedOptions.filter((e,t,n)=>n.findIndex(t=>t.name===e.name)===t).forEach(e=>{this.makeOption(e,i)})})}else{let e=l.program.command(t.baseCommand).description(t.description??``);t?.options?.filter((e,t,n)=>n.findIndex(t=>t.name===e.name)===t).forEach(t=>{this.makeOption(t,e,!0)}),e.action(async()=>{n.setInput(e.opts(),e.args,e.registeredArguments,t,l.program),await n.handle()})}}return l.program.hook(`preAction`,async(e,t)=>{t.name()!==`fire`&&await(0,p.build)({...D,watch:!1,plugins:[]})}),l.program}makeOption(e,t,n,r){let i=e.description?.replace(/\[(\w+)\]/g,(e,t)=>r?.[t]??`[${t}]`)??``,a=e.name.replaceAll(`-`,``);if(e.isFlag)if(n){let n=e.flags?.map(e=>e.length===1?`-${e}`:`--${e}`).join(`, `).replaceAll(`----`,`--`).replaceAll(`---`,`-`);t.option(n||``,i,String(e.defaultValue)||void 0)}else t.option(e.flags?.join(`, `)+(e.required?` <${a}>`:``),i,e.defaultValue);else t.argument(e.required?`<${e.name}>`:`[${e.name}]`,i,e.defaultValue)}static async parse(t){return(await new e(t.app,t).build()).parseAsync()}},k=class e extends t.ConsoleKernel{constructor(e){super(e),this.app=e}static init(t){let n=new e(t);Promise.all([n.loadRequirements()]).then(([e])=>e.run())}async run(){await O.parse(this),process.exit(0)}async loadRequirements(){this.cwd=c.default.join(process.cwd(),this.basePath),this.modulePath=n.FileSystem.findModulePkg(`@h3ravel/core`,this.cwd)??``,this.consolePath=n.FileSystem.findModulePkg(`@h3ravel/console`,this.cwd)??``;try{this.modulePackage=await import(c.default.join(this.modulePath,`package.json`))}catch{this.modulePackage={version:`N/A`}}try{this.consolePackage=await import(c.default.join(this.consolePath,`package.json`))}catch{this.consolePackage={version:`N/A`}}return this}},A=class extends t.ServiceProvider{static priority=992;static console=!0;console=!0;register(){}boot(){k.init(this.app),process.on(`SIGINT`,()=>{process.exit(0)}),process.on(`SIGTERM`,()=>{process.exit(0)})}},j=class{async fire(){let e=process.env.DIST_DIR??`/.h3ravel/serve/`,n=[],r=new t.Application(process.cwd()),i=base_path(c.default.join(e,`bootstrap/providers.js`));n.push(...(await import(i)).default),n.push(A),await r.quickStartup(n,[`CoreServiceProvider`])}};new j().fire();
package/bin/fire.js CHANGED
@@ -1,5 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import"tsx/esm";import{Application as e,ConsoleCommand as t,ConsoleKernel as n,ServiceProvider as r}from"@h3ravel/core";import{FileSystem as i,Logger as a}from"@h3ravel/shared";import{glob as o,mkdir as s,readFile as c,rm as l,writeFile as u}from"node:fs/promises";import{beforeLast as d}from"@h3ravel/support";import f from"dayjs";import p from"node:path";import{HttpServiceProvider as m}from"@h3ravel/http";import{AssetsServiceProvider as h,RouteServiceProvider as g}from"@h3ravel/router";import{DatabaseServiceProvider as _}from"@h3ravel/database";import{CacheServiceProvider as v}from"@h3ravel/cache";import{QueueServiceProvider as y}from"@h3ravel/queue";import{MailServiceProvider as b}from"@h3ravel/mail";import{ConfigServiceProvider as x}from"@h3ravel/config";import{Option as S,program as C}from"commander";import{existsSync as w}from"node:fs";import{dirname as T,join as E,resolve as D}from"path";import{fork as O}from"child_process";import{build as k}from"tsdown";var A=class extends t{};String.raw`
2
+ import"tsx/esm";import{Application as e,ConsoleCommand as t,ConsoleKernel as n,ServiceProvider as r}from"@h3ravel/core";import{FileSystem as i,Logger as a,TaskManager as o}from"@h3ravel/shared";import{execa as s}from"execa";import c from"preferred-pm";import{glob as l,mkdir as u,readFile as d,rm as f,writeFile as p}from"node:fs/promises";import{beforeLast as m}from"@h3ravel/support";import h from"dayjs";import g from"node:path";import{Option as _,program as v}from"commander";import{existsSync as y}from"node:fs";import{fork as b}from"child_process";import{dirname as x,join as S,resolve as C}from"path";import{build as w}from"tsdown";var T=class extends t{signature=`build:
3
+ {--m|minify=false : Minify your bundle output}
4
+ `;description=`Build the app for production`;async handle(){try{await this.fire()}catch(e){a.error(e)}}async fire(){let e=env(`DIST_DIR`,`dist`),t=(await c(base_path()))?.name??`pnpm`,n=this.option(`minify`),r={EXTENDED_DEBUG:Number(this.option(`verbose`,0))>0?`true`:`false`,CLI_BUILD:`true`,NODE_ENV:`production`,DIST_DIR:e,DIST_MINIFY:n,LOG_LEVEL:[`silent`,`info`,`warn`,`error`][Number(this.option(`verbose`,0))]},i=r.LOG_LEVEL===`silent`?`--silent`:null;a.log([[`
5
+ INFO `,`bgBlue`],[` Creating Production Bundle`,`white`]],``),console.log(``),await o.taskRunner(a.log([[` SUCCESS `,`bgGreen`],[` Production Bundle Created`,`white`]],``,!1),async()=>{await s(t,[`tsdown`,i,`--config-loader`,`unconfig`,`-c`,`tsdown.default.config.ts`].filter(e=>e!==null),{stdout:`inherit`,stderr:`inherit`,cwd:base_path(),env:Object.assign({},process.env,r)}),console.log(``)})}},E=class extends t{};String.raw`
3
6
  111
4
7
  111111111
5
8
  1111111111 111111
@@ -21,19 +24,19 @@ import"tsx/esm";import{Application as e,ConsoleCommand as t,ConsoleKernel as n,S
21
24
  111111 111 111111
22
25
  111111111
23
26
  110
24
- `;const j=String.raw`
27
+ `;const D=String.raw`
25
28
  _ _ _____ _
26
29
  | | | |___ / _ __ __ ___ _____| |
27
30
  | |_| | |_ \| '__/ _ \ \ / / _ \ |
28
31
  | _ |___) | | | (_| |\ V / __/ |
29
32
  |_| |_|____/|_| \__,_| \_/ \___|_|
30
33
 
31
- `;var M=class extends A{signature=`list`;description=`List all available commands`;async handle(){let e=[{short:`-h`,long:`--help`,description:`Display help for the given command. When no command is given display help for the list command`}].concat(this.program.options).map(e=>a.describe(a.log(` `+[e.short,e.long].filter(e=>!!e).join(`, `),`green`,!1),e.description,25,!1).join(``)),t=this.program.commands.map(e=>a.describe(a.log(` `+e.name(),`green`,!1),e.description(),25,!1).join(``)).reduce((e,t)=>{let n=t.replace(/\x1b\[\d+m/g,``),r=n.includes(`:`)?n.split(`:`)[0].trim():`__root__`;return e[r]??=[],e[r].push(t),e},{}),n=Object.entries(t).map(([e,t])=>{let n=e===`__root__`?``:e;return[a.log(n,`yellow`,!1),t.join(`
34
+ `;var O=class extends E{signature=`list`;description=`List all available commands`;async handle(){let e=[{short:`-h`,long:`--help`,description:`Display help for the given command. When no command is given display help for the list command`}].concat(this.program.options).map(e=>a.describe(a.log(` `+[e.short,e.long].filter(e=>!!e).join(`, `),`green`,!1),e.description,25,!1).join(``)),t=this.program.commands.map(e=>a.describe(a.log(` `+e.name(),`green`,!1),e.description(),25,!1).join(``)).reduce((e,t)=>{let n=t.replace(/\x1b\[\d+m/g,``),r=n.includes(`:`)?n.split(`:`)[0].trim():`__root__`;return e[r]??=[],e[r].push(t),e},{}),n=Object.entries(t).map(([e,t])=>{let n=e===`__root__`?``:e;return[a.log(n,`yellow`,!1),t.join(`
32
35
  `)].join(`
33
- `)});a.log([[`H3ravel Framework`,`white`],[this.kernel.modulePackage.version,`green`]],` `),console.log(``),console.log(j),console.log(``),a.log(`Usage:`,`yellow`),a.log(` command [options] [arguments]`,`white`),console.log(``),a.log(`Options:`,`yellow`),console.log(e.join(`
36
+ `)});a.log([[`H3ravel Framework`,`white`],[this.kernel.modulePackage.version,`green`]],` `),console.log(``),console.log(D),console.log(``),a.log(`Usage:`,`yellow`),a.log(` command [options] [arguments]`,`white`),console.log(``),a.log(`Options:`,`yellow`),console.log(e.join(`
34
37
  `).trim()),console.log(``),a.log(`Available Commands:`,`yellow`),console.log(n.join(`
35
38
 
36
- `).trim())}},N=class e{static CREATE_PATTERNS=[/^create_(\w+)_table$/,/^create_(\w+)$/];static CHANGE_PATTERNS=[/.+_(to|from|in)_(\w+)_table$/,/.+_(to|from|in)_(\w+)$/];static guess(t){for(let n of e.CREATE_PATTERNS){let e=t.match(n);if(e)return[e[1],!0]}for(let n of e.CHANGE_PATTERNS){let e=t.match(n);if(e)return[e[2],!1]}return[]}},P=class extends A{signature=`#make:
39
+ `).trim())}},k=class e{static CREATE_PATTERNS=[/^create_(\w+)_table$/,/^create_(\w+)$/];static CHANGE_PATTERNS=[/.+_(to|from|in)_(\w+)_table$/,/.+_(to|from|in)_(\w+)$/];static guess(t){for(let n of e.CREATE_PATTERNS){let e=t.match(n);if(e)return[e[1],!0]}for(let n of e.CHANGE_PATTERNS){let e=t.match(n);if(e)return[e[2],!1]}return[]}},A=class extends E{signature=`#make:
37
40
  {controller : Create a new controller class.
38
41
  | {--a|api : Exclude the create and edit methods from the controller}
39
42
  | {--m|model= : Generate a resource controller for the given model}
@@ -49,6 +52,10 @@ import"tsx/esm";import{Application as e,ConsoleCommand as t,ConsoleKernel as n,S
49
52
  | {--t|table : The table to migrate}
50
53
  | {--c|create : The table to be created}
51
54
  }
55
+ {command : Create a new Musket command.
56
+ | {--command : The terminal command that will be used to invoke the class}
57
+ | {--force : Create the class even if the console command already exists}
58
+ }
52
59
  {factory : Create a new model factory.}
53
60
  {seeder : Create a new seeder class.}
54
61
  {view : Create a new view.
@@ -66,5 +73,5 @@ import"tsx/esm";import{Application as e,ConsoleCommand as t,ConsoleKernel as n,S
66
73
  | {--force : Create the model even if it already exists}
67
74
  }
68
75
  {^name : The name of the [name] to generate}
69
- `;description=`Generate component classes`;async handle(){let e=this.dictionary.baseCommand??this.dictionary.name;this.argument(`name`)||this.program.error(`Please provide a valid name for the `+e);let t={controller:`makeController`,resource:`makeResource`,migration:`makeMigration`,factory:`makeFactory`,seeder:`makeSeeder`,model:`makeModel`,view:`makeView`};try{await this?.[t[e]]()}catch(e){a.error(e)}}async makeController(){let e=this.option(`api`)?`-resource`:``,t=this.argument(`name`),n=this.option(`force`),r=i.findModulePkg(`@h3ravel/http`,this.kernel.cwd)??``,o=p.join(r,`dist/stubs/controller${e}.stub`),l=app_path(`Http/Controllers/${t}.ts`);t.includes(`/`)&&await s(d(l,`/`),{recursive:!0}),!n&&await i.fileExists(l)&&a.error(`ERORR: ${t} controller already exists`);let f=await c(o,`utf-8`);f=f.replace(/{{ name }}/g,t),await u(l,f),a.split(`INFO: Controller Created`,a.log(p.basename(l),`gray`,!1))}makeResource(){a.success(`Resource support is not yet available`)}async makeMigration(){let e=this.argument(`name`),t=f().format(`YYYY_MM_DD_HHmmss`),n=database_path(`migrations/${t}_${e}.ts`),r=i.findModulePkg(`@h3ravel/database`,this.kernel.cwd)??``,o=this.option(`create`,!1),s=this.option(`table`);if(!s&&typeof o==`string`&&(s=o,o=!0),!s){let t=N.guess(e);s=t[0],o=!!t[1]}let l=p.join(r,this.getMigrationStubName(s,o)),d=await c(l,`utf-8`);s!==null&&(d=d.replace(/DummyTable|{{\s*table\s*}}/g,s)),a.info(`INFO: Creating Migration`),await this.kernel.ensureDirectoryExists(p.dirname(n)),await u(n,d),a.split(`INFO: Migration Created`,a.log(p.basename(n),`gray`,!1))}makeFactory(){a.success(`Factory support is not yet available`)}makeSeeder(){a.success(`Seeder support is not yet available`)}async makeModel(){let e=this.option(`type`,`ts`),t=this.argument(`name`),n=this.option(`force`),r=app_path(`Models/${t.toLowerCase()}.${e}`);t.includes(`/`)&&await s(d(r,`/`),{recursive:!0}),!n&&await i.fileExists(r)&&a.error(`ERORR: ${t} model already exists`);let o=i.findModulePkg(`@h3ravel/database`,this.kernel.cwd)??``,l=p.join(o,`dist/stubs/model-${e}.stub`),f=await c(l,`utf-8`);f=f.replace(/{{ name }}/g,t),await u(r,f),a.split(`INFO: ${t} Model Created`,a.log(p.basename(r),`gray`,!1))}async makeView(){let e=this.argument(`name`),t=this.option(`force`),n=base_path(`src/resources/views/${e}.edge`);e.includes(`/`)&&await s(d(n,`/`),{recursive:!0}),!t&&await i.fileExists(n)&&a.error(`ERORR: ${e} view already exists`),await u(n,`{{-- src/resources/views/${e}.edge --}}`),a.split(`INFO: View Created`,a.log(`src/resources/views/${e}.edge`,`gray`,!1))}getMigrationStubName(e,t=!1,n=`ts`){let r;return r=e?t?`migration.create-${n}.stub`:`migration.update-${n}.stub`:`migration-${n}.stub`,`dist/stubs/`+r}},F=class extends A{signature=`postinstall`;description=`Default post installation command`;async handle(){this.createSqliteDB()}async createSqliteDB(){config(`database.default`)===`sqlite`&&(await i.fileExists(database_path())||await s(database_path(),{recursive:!0}),await i.fileExists(database_path(`db.sqlite`))||await u(database_path(`db.sqlite`),``))}},I=[m,x,g,h,_,v,y,b],L=class e{static parseOptions(t){let n=[],r=/\{([^{}]+(?:\{[^{}]*\}[^{}]*)*)\}/g,i;for(;(i=r.exec(t))!==null;){let t=i[1][0]===`^`||/:[#^]/.test(i[1]),r=([`#`,`^`].includes(i[1][0])||/:[#^]/.test(i[1]))&&!t,a=i[1].trim().replace(/[#^]/,``),o=a.indexOf(`:`);if(o===-1){n.push({name:a});continue}let s=a.substring(0,o).trim(),c=a.substring(o+1).trim(),l=c,u,d=c.indexOf(`|`);if(d!==-1){l=c.substring(0,d).trim();let t=c.substring(d+1).trim().replace(/^\{/,``).trim();u=e.parseOptions(`{`+t+`}`)}else l=l.trim();let f=s,p=/[^a-zA-Z0-9_|-]/.test(f),m=!1;f.endsWith(`?*`)?(p=!1,m=!0,f=f.slice(0,-2)):f.endsWith(`*`)?(m=!0,f=f.slice(0,-1)):f.endsWith(`?`)&&(p=!1,f=f.slice(0,-1));let h=f.startsWith(`--`),g,_;if(h){let e=f.split(`|`).map(e=>e.trim());g=[];for(let t of e){t.startsWith(`--`)&&t.slice(2).length===1?t=`-`+t.slice(2):t.startsWith(`-`)&&!t.startsWith(`--`)&&t.slice(1).length>1?t=`--`+t.slice(1):!t.startsWith(`-`)&&t.slice(1).length>1&&(t=`--`+t);let e=t.indexOf(`=`);if(e!==-1){g.push(t.substring(0,e));let n=t.substring(e+1);_=n===`*`?[]:n===`true`||n===`false`||!n&&!p?n===`true`:isNaN(Number(n))?n:Number(n)}else g.push(t)}}n.push({name:h?g[g.length-1]:f,required:p,multiple:m,description:l,flags:g,shared:t,isFlag:h,isHidden:r,defaultValue:_,nestedOptions:u})}return n}static parseSignature(t,n){let r=t.split(`
70
- `).map(e=>e.trim()).filter(e=>e.length>0),i=[`#`,`^`].includes(r[0][0])||/:[#^]/.test(r[0]),a=r[0].replace(/[^\w=:-]/g,``),o=n.getDescription(),s=a.endsWith(`:`),c=r.slice(1).join(` `),l=e.parseOptions(c);return s?{baseCommand:a.slice(0,-1),isNamespaceCommand:s,subCommands:l.filter(e=>!e.flags&&!e.isHidden),description:o,commandClass:n,options:l.filter(e=>!!e.flags),isHidden:i}:{baseCommand:a,isNamespaceCommand:s,options:l,description:o,commandClass:n,isHidden:i}}};function R(e={}){let t,n,r=e.args||[],i=e.allowRestarts||!1,a=e.input,o=e.options||e;return delete o.args,delete o.allowRestarts,{name:`run`,buildStart(e){let n=a??e.input;if(typeof n==`string`&&(n=[n]),typeof n==`object`&&(n=Object.values(n)),n.length>1)throw Error("@rollup/plugin-run must have a single entry point; consider setting the `input` option");t=D(n[0])},generateBundle(e,t,n){n||this.error(`@rollup/plugin-run currently only works with bundles that are written to disk`)},writeBundle(e,a){let s=(e,t)=>{n&&n.kill(),n=O(E(e,t),r,o)},c=e.dir||T(e.file),l=Object.keys(a).find(e=>{let n=a[e];return n.isEntry&&n.facadeModuleId===t});l?(s(c,l),i&&(process.stdin.resume(),process.stdin.setEncoding(`utf8`),process.stdin.on(`data`,e=>{let t=e.toString().trim().toLowerCase();t===`rs`||t===`restart`||e.toString().charCodeAt(0)===11?s(c,l):(t===`cls`||t===`clear`||e.toString().charCodeAt(0)===12)&&console.clear()}))):this.error(`@rollup/plugin-run could not find output chunk`)}}}const z=process.env.NODE_ENV||`development`,B=z===`development`?`.h3ravel/serve`:`dist`;var V={outDir:B,entry:[`src/**/*.ts`],format:[`esm`],target:`node22`,sourcemap:z===`development`,clean:!0,shims:!0,copy:[{from:`public`,to:B},`src/resources`,`src/database`],env:z===`development`?{NODE_ENV:z,DIST_DIR:B}:{},watch:z===`development`&&process.env.CLI_BUILD!==`true`?[`.env`,`.env.*`,`src`,`../../packages`]:!1,dts:!1,logLevel:`silent`,nodeProtocol:!0,skipNodeModulesBundle:!0,hooks(e){e.hook(`build:done`,async()=>{let e=[`database/migrations`,`database/factories`,`database/seeders`];for(let t=0;t<e.length;t++){let n=e[t];w(p.join(B,n))&&await l(p.join(B,n),{recursive:!0})}})},plugins:z===`development`&&process.env.CLI_BUILD!==`true`?[R({env:Object.assign({},process.env,{NODE_ENV:z,DIST_DIR:B}),execArgv:[`-r`,`source-map-support/register`],allowRestarts:!1,input:process.cwd()+`/src/server.ts`})]:[]},H=class e{commands=[];constructor(e,t){this.app=e,this.kernel=t}async build(){return this.loadBaseCommands(),await this.loadDiscoveredCommands(),this.initialize()}loadBaseCommands(){[new P(this.app,this.kernel),new M(this.app,this.kernel),new F(this.app,this.kernel)].forEach(e=>this.addCommand(e))}async loadDiscoveredCommands(){let e=[...this.app.registeredCommands.map(e=>new e(this.app,this.kernel))],t=app_path(`Console/Commands/*.js`).replace(`/src/`,`/.h3ravel/serve/`);for await(let n of o(t)){let t=p.basename(n).replace(`.js`,``);try{let r=(await import(n))[t];e.push(new r(this.app,this.kernel))}catch{}}e.forEach(e=>this.addCommand(e))}addCommand(e){this.commands.push(L.parseSignature(e.getSignature(),e))}initialize(){let e=a.parse([[`Musket CLI:`,`white`],[this.kernel.consolePackage.version,`green`]],` `,!1),t=a.parse([[`H3ravel Framework:`,`white`],[this.kernel.modulePackage.version,`green`]],` `,!1),n={quiet:[`-q, --quiet`,`Do not output any message`],silent:[`--silent`,`Do not output any message`],verbose:[`-v, --verbose <number>`,`Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug`],lock:[`--lock`,`Locked and loaded, do not ask any interactive question`]};C.name(`musket`).version(`${e}\n${t}`).description(j).addOption(new S(n.quiet[0],n.quiet[1]).implies({silent:!0})).addOption(new S(n.silent[0],n.silent[1]).implies({quiet:!0})).addOption(new S(n.verbose[0],n.verbose[1]).choices([`1`,`2`,`3`])).addOption(new S(n.lock[0],n.lock[1])).action(async()=>{let e=new M(this.app,this.kernel);e.setInput(C.opts(),C.args,C.registeredArguments,{},C),e.handle()}),C.command(`init`).description(`Initialize H3ravel.`).action(async()=>{a.success(`Initialized: H3ravel has been initialized!`)});for(let e=0;e<this.commands.length;e++){let t=this.commands[e],r=t.commandClass;if(t.isNamespaceCommand&&t.subCommands){let e=t.isHidden?C:C.command(t.baseCommand).description(t.description??``).addOption(new S(n.quiet[0],n.quiet[1]).implies({silent:!0})).addOption(new S(n.silent[0],n.silent[1]).implies({quiet:!0})).addOption(new S(n.verbose[0],n.verbose[1]).choices([`1`,`2`,`3`])).addOption(new S(n.lock[0],n.lock[1])).action(async()=>{r.setInput(e.opts(),e.args,e.registeredArguments,t,C),await r.handle()});(t.options?.length??0)>0&&t.options?.filter((e,t,n)=>n.findIndex(t=>t.name===e.name)===t).forEach(t=>{this.makeOption(t,e)}),t.subCommands.filter((e,t,n)=>!e.shared&&n.findIndex(t=>t.name===e.name)===t).forEach(e=>{let i=C.command(`${t.baseCommand}:${e.name}`).description(e.description||``).addOption(new S(n.quiet[0],n.quiet[1]).implies({silent:!0})).addOption(new S(n.silent[0],n.silent[1]).implies({quiet:!0})).addOption(new S(n.verbose[0],n.verbose[1]).choices([`1`,`2`,`3`])).addOption(new S(n.lock[0],n.lock[1])).action(async()=>{r.setInput(i.opts(),i.args,i.registeredArguments,e,C),await r.handle()});t.subCommands?.filter(e=>e.shared).forEach(t=>{this.makeOption(t,i,!1,e)}),t.options?.filter(e=>e.shared).forEach(t=>{this.makeOption(t,i,!1,e)}),e.nestedOptions&&e.nestedOptions.filter((e,t,n)=>n.findIndex(t=>t.name===e.name)===t).forEach(e=>{this.makeOption(e,i)})})}else{let e=C.command(t.baseCommand).description(t.description??``);t?.options?.filter((e,t,n)=>n.findIndex(t=>t.name===e.name)===t).forEach(t=>{this.makeOption(t,e,!0)}),e.action(async()=>{r.setInput(e.opts(),e.args,e.registeredArguments,t,C),await r.handle()})}}return C.hook(`preAction`,async(e,t)=>{t.name()!==`fire`&&await k({...V,watch:!1,plugins:[]})}),C}makeOption(e,t,n,r){let i=e.description?.replace(/\[(\w+)\]/g,(e,t)=>r?.[t]??`[${t}]`)??``,a=e.name.replaceAll(`-`,``);if(e.isFlag)if(n){let n=e.flags?.map(e=>e.length===1?`-${e}`:`--${e}`).join(`, `).replaceAll(`----`,`--`).replaceAll(`---`,`-`);t.option(n||``,i,String(e.defaultValue)||void 0)}else t.option(e.flags?.join(`, `)+(e.required?` <${a}>`:``),i,e.defaultValue);else t.argument(e.required?`<${e.name}>`:`[${e.name}]`,i,e.defaultValue)}static async parse(t){return(await new e(t.app,t).build()).parseAsync()}},U=class e extends n{constructor(e){super(e),this.app=e}static init(t){let n=new e(t);Promise.all([n.loadRequirements()]).then(([e])=>e.run())}async run(){await H.parse(this),process.exit(0)}async loadRequirements(){this.cwd=p.join(process.cwd(),this.basePath),this.modulePath=i.findModulePkg(`@h3ravel/core`,this.cwd)??``,this.consolePath=i.findModulePkg(`@h3ravel/console`,this.cwd)??``;try{this.modulePackage=await import(p.join(this.modulePath,`package.json`))}catch{this.modulePackage={version:`N/A`}}try{this.consolePackage=await import(p.join(this.consolePath,`package.json`))}catch{this.consolePackage={version:`N/A`}}return this}},W=class extends r{static priority=992;static console=!0;register(){}boot(){U.init(this.app),process.on(`SIGINT`,()=>{process.exit(0)}),process.on(`SIGTERM`,()=>{process.exit(0)})}};new class{async fire(){let t=new e(process.cwd()),n=(app_path(`Providers/*.js`).replace(`/src/`,`/.h3ravel/serve/`));for await(let e of o(n)){let t=(p.basename(e).replace(`.js`,``));try{I.push((await import(e))[t])}catch{}}I.push(W),t.registerProviders(I),await t.registerConfiguredProviders(),await t.boot()}}().fire();export{};
76
+ `;description=`Generate component classes`;async handle(){let e=this.dictionary.baseCommand??this.dictionary.name;this.argument(`name`)||this.program.error(`Please provide a valid name for the `+e);let t={controller:`makeController`,resource:`makeResource`,migration:`makeMigration`,factory:`makeFactory`,seeder:`makeSeeder`,model:`makeModel`,view:`makeView`,command:`makeCommand`};try{await this?.[t[e]]()}catch(e){a.error(e)}}async makeController(){let e=this.option(`api`)?`-resource`:``,t=this.argument(`name`),n=this.option(`force`),r=i.findModulePkg(`@h3ravel/http`,this.kernel.cwd)??``,o=g.join(r,`dist/stubs/controller${e}.stub`),s=app_path(`Http/Controllers/${t}.ts`);t.includes(`/`)&&await u(m(s,`/`),{recursive:!0}),!n&&await i.fileExists(s)&&a.error(`ERORR: ${t} controller already exists`);let c=await d(o,`utf-8`);c=c.replace(/{{ name }}/g,t),await p(s,c),a.split(`INFO: Controller Created`,a.log(g.basename(s),`gray`,!1))}makeResource(){a.success(`Resource support is not yet available`)}async makeMigration(){let e=this.argument(`name`),t=h().format(`YYYY_MM_DD_HHmmss`),n=database_path(`migrations/${t}_${e}.ts`),r=i.findModulePkg(`@h3ravel/database`,this.kernel.cwd)??``,o=this.option(`create`,!1),s=this.option(`table`);if(!s&&typeof o==`string`&&(s=o,o=!0),!s){let t=k.guess(e);s=t[0],o=!!t[1]}let c=g.join(r,this.getMigrationStubName(s,o)),l=await d(c,`utf-8`);s!==null&&(l=l.replace(/DummyTable|{{\s*table\s*}}/g,s)),a.info(`INFO: Creating Migration`),await this.kernel.ensureDirectoryExists(g.dirname(n)),await p(n,l),a.split(`INFO: Migration Created`,a.log(g.basename(n),`gray`,!1))}makeFactory(){a.success(`Factory support is not yet available`)}makeCommand(){a.success(`Musket command creation is not yet available`)}makeSeeder(){a.success(`Seeder support is not yet available`)}async makeModel(){let e=this.option(`type`,`ts`),t=this.argument(`name`),n=this.option(`force`),r=app_path(`Models/${t.toLowerCase()}.${e}`);t.includes(`/`)&&await u(m(r,`/`),{recursive:!0}),!n&&await i.fileExists(r)&&a.error(`ERORR: ${t} model already exists`);let o=i.findModulePkg(`@h3ravel/database`,this.kernel.cwd)??``,s=g.join(o,`dist/stubs/model-${e}.stub`),c=await d(s,`utf-8`);c=c.replace(/{{ name }}/g,t),await p(r,c),a.split(`INFO: ${t} Model Created`,a.log(g.basename(r),`gray`,!1))}async makeView(){let e=this.argument(`name`),t=this.option(`force`),n=base_path(`src/resources/views/${e}.edge`);e.includes(`/`)&&await u(m(n,`/`),{recursive:!0}),!t&&await i.fileExists(n)&&a.error(`ERORR: ${e} view already exists`),await p(n,`{{-- src/resources/views/${e}.edge --}}`),a.split(`INFO: View Created`,a.log(`src/resources/views/${e}.edge`,`gray`,!1))}getMigrationStubName(e,t=!1,n=`ts`){let r;return r=e?t?`migration.create-${n}.stub`:`migration.update-${n}.stub`:`migration-${n}.stub`,`dist/stubs/`+r}},j=class extends E{signature=`postinstall`;description=`Default post installation command`;async handle(){this.createSqliteDB()}async createSqliteDB(){config(`database.default`)===`sqlite`&&(await i.fileExists(database_path())||await u(database_path(),{recursive:!0}),await i.fileExists(database_path(`db.sqlite`))||await p(database_path(`db.sqlite`),``))}},M=class e{static parseOptions(t){let n=[],r=/\{([^{}]+(?:\{[^{}]*\}[^{}]*)*)\}/g,i;for(;(i=r.exec(t))!==null;){let t=i[1][0]===`^`||/:[#^]/.test(i[1]),r=([`#`,`^`].includes(i[1][0])||/:[#^]/.test(i[1]))&&!t,a=i[1].trim().replace(/[#^]/,``),o=a.indexOf(`:`);if(o===-1){n.push({name:a});continue}let s=a.substring(0,o).trim(),c=a.substring(o+1).trim(),l=c,u,d=c.indexOf(`|`);if(d!==-1){l=c.substring(0,d).trim();let t=c.substring(d+1).trim().replace(/^\{/,``).trim();u=e.parseOptions(`{`+t+`}`)}else l=l.trim();let f=s,p=/[^a-zA-Z0-9_|-]/.test(f),m=!1;f.endsWith(`?*`)?(p=!1,m=!0,f=f.slice(0,-2)):f.endsWith(`*`)?(m=!0,f=f.slice(0,-1)):f.endsWith(`?`)&&(p=!1,f=f.slice(0,-1));let h=f.startsWith(`--`),g,_;if(h){let e=f.split(`|`).map(e=>e.trim());g=[];for(let t of e){t.startsWith(`--`)&&t.slice(2).length===1?t=`-`+t.slice(2):t.startsWith(`-`)&&!t.startsWith(`--`)&&t.slice(1).length>1?t=`--`+t.slice(1):!t.startsWith(`-`)&&t.slice(1).length>1&&(t=`--`+t);let e=t.indexOf(`=`);if(e!==-1){g.push(t.substring(0,e));let n=t.substring(e+1);_=n===`*`?[]:n===`true`||n===`false`||!n&&!p?n===`true`:isNaN(Number(n))?n:Number(n)}else g.push(t)}}n.push({name:h?g[g.length-1]:f,required:p,multiple:m,description:l,flags:g,shared:t,isFlag:h,isHidden:r,defaultValue:_,nestedOptions:u})}return n}static parseSignature(t,n){let r=t.split(`
77
+ `).map(e=>e.trim()).filter(e=>e.length>0),i=[`#`,`^`].includes(r[0][0])||/:[#^]/.test(r[0]),a=r[0].replace(/[^\w=:-]/g,``),o=n.getDescription(),s=a.endsWith(`:`),c=r.slice(1).join(` `),l=e.parseOptions(c);return s?{baseCommand:a.slice(0,-1),isNamespaceCommand:s,subCommands:l.filter(e=>!e.flags&&!e.isHidden),description:o,commandClass:n,options:l.filter(e=>!!e.flags),isHidden:i}:{baseCommand:a,isNamespaceCommand:s,options:l,description:o,commandClass:n,isHidden:i}}};function N(e={}){let t,n,r=e.args||[],i=e.allowRestarts||!1,a=e.input,o=e.options||e;return delete o.args,delete o.allowRestarts,{name:`run`,buildStart(e){let n=a??e.input;if(typeof n==`string`&&(n=[n]),typeof n==`object`&&(n=Object.values(n)),n.length>1)throw Error("@rollup/plugin-run must have a single entry point; consider setting the `input` option");t=C(n[0])},generateBundle(e,t,n){n||this.error(`@rollup/plugin-run currently only works with bundles that are written to disk`)},writeBundle(e,a){let s=(e,t)=>{n&&n.kill(),n=b(S(e,t),r,o)},c=e.dir||x(e.file),l=Object.keys(a).find(e=>{let n=a[e];return n.isEntry&&n.facadeModuleId===t});l?(s(c,l),i&&(process.stdin.resume(),process.stdin.setEncoding(`utf8`),process.stdin.on(`data`,e=>{let t=e.toString().trim().toLowerCase();t===`rs`||t===`restart`||e.toString().charCodeAt(0)===11?s(c,l):(t===`cls`||t===`clear`||e.toString().charCodeAt(0)===12)&&console.clear()}))):this.error(`@rollup/plugin-run could not find output chunk`)}}}const P=process.env.NODE_ENV||`development`;let F=P===`development`?`.h3ravel/serve`:`dist`;process.env.DIST_DIR&&(F=process.env.DIST_DIR);var I={outDir:F,entry:[`src/**/*.ts`],format:[`esm`],target:`node22`,sourcemap:P===`development`,minify:!!process.env.DIST_MINIFY,clean:!0,shims:!0,copy:[{from:`public`,to:F},`src/resources`,`src/database`],env:P===`development`?{NODE_ENV:P,DIST_DIR:F}:{},watch:P===`development`&&process.env.CLI_BUILD!==`true`?[`.env`,`.env.*`,`src`,`../../packages`]:!1,dts:!1,logLevel:`silent`,nodeProtocol:!0,skipNodeModulesBundle:!0,hooks(e){e.hook(`build:done`,async()=>{let e=[`database/migrations`,`database/factories`,`database/seeders`];for(let t=0;t<e.length;t++){let n=e[t];y(g.join(F,n))&&await f(g.join(F,n),{recursive:!0})}})},plugins:P===`development`&&process.env.CLI_BUILD!==`true`?[N({env:Object.assign({},process.env,{NODE_ENV:P,DIST_DIR:F}),execArgv:[`-r`,`source-map-support/register`],allowRestarts:!1,input:process.cwd()+`/src/server.ts`})]:[]},L=class e{commands=[];constructor(e,t){this.app=e,this.kernel=t}async build(){return this.loadBaseCommands(),await this.loadDiscoveredCommands(),this.initialize()}loadBaseCommands(){[new A(this.app,this.kernel),new O(this.app,this.kernel),new j(this.app,this.kernel),new T(this.app,this.kernel)].forEach(e=>this.addCommand(e))}async loadDiscoveredCommands(){let e=`/${env(`DIST_DIR`,`.h3ravel/serve`)}/`.replaceAll(`//`,``),t=[...this.app.registeredCommands.map(e=>new e(this.app,this.kernel))],n=app_path(`Console/Commands/*.js`).replace(`/src/`,e);for await(let e of l(n)){let n=g.basename(e).replace(`.js`,``);try{let r=(await import(e))[n];t.push(new r(this.app,this.kernel))}catch{}}t.forEach(e=>this.addCommand(e))}addCommand(e){this.commands.push(M.parseSignature(e.getSignature(),e))}initialize(){let e=a.parse([[`Musket CLI:`,`white`],[this.kernel.consolePackage.version,`green`]],` `,!1),t=a.parse([[`H3ravel Framework:`,`white`],[this.kernel.modulePackage.version,`green`]],` `,!1),n={quiet:[`-q, --quiet`,`Do not output any message`],silent:[`--silent`,`Do not output any message`],verbose:[`-v, --verbose <number>`,`Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug`],lock:[`--lock`,`Locked and loaded, do not ask any interactive question`]};v.name(`musket`).version(`${e}\n${t}`).description(D).addOption(new _(n.quiet[0],n.quiet[1]).implies({silent:!0})).addOption(new _(n.silent[0],n.silent[1]).implies({quiet:!0})).addOption(new _(n.verbose[0],n.verbose[1]).choices([`1`,`2`,`3`])).addOption(new _(n.lock[0],n.lock[1])).action(async()=>{let e=new O(this.app,this.kernel);e.setInput(v.opts(),v.args,v.registeredArguments,{},v),e.handle()}),v.command(`init`).description(`Initialize H3ravel.`).action(async()=>{a.success(`Initialized: H3ravel has been initialized!`)});for(let e=0;e<this.commands.length;e++){let t=this.commands[e],r=t.commandClass;if(t.isNamespaceCommand&&t.subCommands){let e=t.isHidden?v:v.command(t.baseCommand).description(t.description??``).addOption(new _(n.quiet[0],n.quiet[1]).implies({silent:!0})).addOption(new _(n.silent[0],n.silent[1]).implies({quiet:!0})).addOption(new _(n.verbose[0],n.verbose[1]).choices([`1`,`2`,`3`])).addOption(new _(n.lock[0],n.lock[1])).action(async()=>{r.setInput(e.opts(),e.args,e.registeredArguments,t,v),await r.handle()});(t.options?.length??0)>0&&t.options?.filter((e,t,n)=>n.findIndex(t=>t.name===e.name)===t).forEach(t=>{this.makeOption(t,e)}),t.subCommands.filter((e,t,n)=>!e.shared&&n.findIndex(t=>t.name===e.name)===t).forEach(e=>{let i=v.command(`${t.baseCommand}:${e.name}`).description(e.description||``).addOption(new _(n.quiet[0],n.quiet[1]).implies({silent:!0})).addOption(new _(n.silent[0],n.silent[1]).implies({quiet:!0})).addOption(new _(n.verbose[0],n.verbose[1]).choices([`1`,`2`,`3`])).addOption(new _(n.lock[0],n.lock[1])).action(async()=>{r.setInput(i.opts(),i.args,i.registeredArguments,e,v),await r.handle()});t.subCommands?.filter(e=>e.shared).forEach(t=>{this.makeOption(t,i,!1,e)}),t.options?.filter(e=>e.shared).forEach(t=>{this.makeOption(t,i,!1,e)}),e.nestedOptions&&e.nestedOptions.filter((e,t,n)=>n.findIndex(t=>t.name===e.name)===t).forEach(e=>{this.makeOption(e,i)})})}else{let e=v.command(t.baseCommand).description(t.description??``);t?.options?.filter((e,t,n)=>n.findIndex(t=>t.name===e.name)===t).forEach(t=>{this.makeOption(t,e,!0)}),e.action(async()=>{r.setInput(e.opts(),e.args,e.registeredArguments,t,v),await r.handle()})}}return v.hook(`preAction`,async(e,t)=>{t.name()!==`fire`&&await w({...I,watch:!1,plugins:[]})}),v}makeOption(e,t,n,r){let i=e.description?.replace(/\[(\w+)\]/g,(e,t)=>r?.[t]??`[${t}]`)??``,a=e.name.replaceAll(`-`,``);if(e.isFlag)if(n){let n=e.flags?.map(e=>e.length===1?`-${e}`:`--${e}`).join(`, `).replaceAll(`----`,`--`).replaceAll(`---`,`-`);t.option(n||``,i,String(e.defaultValue)||void 0)}else t.option(e.flags?.join(`, `)+(e.required?` <${a}>`:``),i,e.defaultValue);else t.argument(e.required?`<${e.name}>`:`[${e.name}]`,i,e.defaultValue)}static async parse(t){return(await new e(t.app,t).build()).parseAsync()}},R=class e extends n{constructor(e){super(e),this.app=e}static init(t){let n=new e(t);Promise.all([n.loadRequirements()]).then(([e])=>e.run())}async run(){await L.parse(this),process.exit(0)}async loadRequirements(){this.cwd=g.join(process.cwd(),this.basePath),this.modulePath=i.findModulePkg(`@h3ravel/core`,this.cwd)??``,this.consolePath=i.findModulePkg(`@h3ravel/console`,this.cwd)??``;try{this.modulePackage=await import(g.join(this.modulePath,`package.json`))}catch{this.modulePackage={version:`N/A`}}try{this.consolePackage=await import(g.join(this.consolePath,`package.json`))}catch{this.consolePackage={version:`N/A`}}return this}},z=class extends r{static priority=992;static console=!0;console=!0;register(){}boot(){R.init(this.app),process.on(`SIGINT`,()=>{process.exit(0)}),process.on(`SIGTERM`,()=>{process.exit(0)})}};new class{async fire(){let t=process.env.DIST_DIR??`/.h3ravel/serve/`,n=[],r=new e(process.cwd()),i=(base_path(g.join(t,`bootstrap/providers.js`)));n.push(...(await import(i)).default),n.push(z),await r.quickStartup(n,[`CoreServiceProvider`])}}().fire();export{};
package/bin/spawn.cjs ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ const e=require(`./chunk-CUT6urMc.cjs`);let t=require(`execa`);t=e.__toESM(t);let n=require(`preferred-pm`);n=e.__toESM(n);let r=require(`node:path`);r=e.__toESM(r);const i=async()=>{let e=(await(0,n.default)(process.cwd()))?.name??`npm`,i=(0,r.join)(process.env.DIST_DIR??`.h3ravel/serve`),a={EXTENDED_DEBUG:`false`,CLI_BUILD:`true`,NODE_ENV:`production`,DIST_DIR:i,LOG_LEVEL:`silent`};console.log(i,a),await(0,t.execa)(e,[`tsdown`,`--silent`,`--config-loader`,`unconfig`,`-c`,`tsdown.default.config.ts`].filter(e=>e!==null),{stdout:`inherit`,stderr:`inherit`,cwd:(0,r.join)(process.cwd()),env:Object.assign({},process.env,a)})};i();
package/bin/spawn.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import{execa as e}from"execa";import t from"preferred-pm";import{join as n}from"node:path";(async()=>{let r=(await t(process.cwd()))?.name??`npm`,i=n(process.env.DIST_DIR??`.h3ravel/serve`),a={EXTENDED_DEBUG:`false`,CLI_BUILD:`true`,NODE_ENV:`production`,DIST_DIR:i,LOG_LEVEL:`silent`};console.log(i,a),await e(r,[`tsdown`,`--silent`,`--config-loader`,`unconfig`,`-c`,`tsdown.default.config.ts`].filter(e=>e!==null),{stdout:`inherit`,stderr:`inherit`,cwd:n(process.cwd()),env:Object.assign({},process.env,a)})})();export{};
package/dist/index.cjs CHANGED
@@ -22,10 +22,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
22
 
23
23
  //#endregion
24
24
  const require_Utils = require('./Utils-D6ZDNdVG.cjs');
25
- let __h3ravel_core = require("@h3ravel/core");
26
- __h3ravel_core = __toESM(__h3ravel_core);
27
25
  let __h3ravel_shared = require("@h3ravel/shared");
28
26
  __h3ravel_shared = __toESM(__h3ravel_shared);
27
+ let __h3ravel_core = require("@h3ravel/core");
28
+ __h3ravel_core = __toESM(__h3ravel_core);
29
+ let execa = require("execa");
30
+ execa = __toESM(execa);
31
+ let preferred_pm = require("preferred-pm");
32
+ preferred_pm = __toESM(preferred_pm);
29
33
  let node_fs_promises = require("node:fs/promises");
30
34
  node_fs_promises = __toESM(node_fs_promises);
31
35
  let __h3ravel_support = require("@h3ravel/support");
@@ -34,24 +38,80 @@ let dayjs = require("dayjs");
34
38
  dayjs = __toESM(dayjs);
35
39
  let node_path = require("node:path");
36
40
  node_path = __toESM(node_path);
37
- require("@h3ravel/http");
38
- require("@h3ravel/router");
39
- require("@h3ravel/database");
40
- require("@h3ravel/cache");
41
- require("@h3ravel/queue");
42
- require("@h3ravel/mail");
43
- require("@h3ravel/config");
44
41
  let commander = require("commander");
45
42
  commander = __toESM(commander);
46
43
  let node_fs = require("node:fs");
47
44
  node_fs = __toESM(node_fs);
48
- let path = require("path");
49
- path = __toESM(path);
50
45
  let child_process = require("child_process");
51
46
  child_process = __toESM(child_process);
47
+ let path = require("path");
48
+ path = __toESM(path);
52
49
  let tsdown = require("tsdown");
53
50
  tsdown = __toESM(tsdown);
54
51
 
52
+ //#region src/Commands/BuildCommand.ts
53
+ var BuildCommand = class extends __h3ravel_core.ConsoleCommand {
54
+ /**
55
+ * The name and signature of the console command.
56
+ *
57
+ * @var string
58
+ */
59
+ signature = `build:
60
+ {--m|minify=false : Minify your bundle output}
61
+ `;
62
+ /**
63
+ * The console command description.
64
+ *
65
+ * @var string
66
+ */
67
+ description = "Build the app for production";
68
+ async handle() {
69
+ try {
70
+ await this.fire();
71
+ } catch (e) {
72
+ __h3ravel_shared.Logger.error(e);
73
+ }
74
+ }
75
+ async fire() {
76
+ const outDir$1 = env("DIST_DIR", "dist");
77
+ const pm = (await (0, preferred_pm.default)(base_path()))?.name ?? "pnpm";
78
+ const minify = this.option("minify");
79
+ const ENV_VARS = {
80
+ EXTENDED_DEBUG: Number(this.option("verbose", 0)) > 0 ? "true" : "false",
81
+ CLI_BUILD: "true",
82
+ NODE_ENV: "production",
83
+ DIST_DIR: outDir$1,
84
+ DIST_MINIFY: minify,
85
+ LOG_LEVEL: [
86
+ "silent",
87
+ "info",
88
+ "warn",
89
+ "error"
90
+ ][Number(this.option("verbose", 0))]
91
+ };
92
+ const silent = ENV_VARS.LOG_LEVEL === "silent" ? "--silent" : null;
93
+ __h3ravel_shared.Logger.log([["\n INFO ", "bgBlue"], [" Creating Production Bundle", "white"]], "");
94
+ console.log("");
95
+ await __h3ravel_shared.TaskManager.taskRunner(__h3ravel_shared.Logger.log([[" SUCCESS ", "bgGreen"], [" Production Bundle Created", "white"]], "", false), async () => {
96
+ await (0, execa.execa)(pm, [
97
+ "tsdown",
98
+ silent,
99
+ "--config-loader",
100
+ "unconfig",
101
+ "-c",
102
+ "tsdown.default.config.ts"
103
+ ].filter((e) => e !== null), {
104
+ stdout: "inherit",
105
+ stderr: "inherit",
106
+ cwd: base_path(),
107
+ env: Object.assign({}, process.env, ENV_VARS)
108
+ });
109
+ console.log("");
110
+ });
111
+ }
112
+ };
113
+
114
+ //#endregion
55
115
  //#region src/Commands/Command.ts
56
116
  var Command = class extends __h3ravel_core.ConsoleCommand {};
57
117
 
@@ -169,6 +229,10 @@ var MakeCommand = class extends Command {
169
229
  | {--t|table : The table to migrate}
170
230
  | {--c|create : The table to be created}
171
231
  }
232
+ {command : Create a new Musket command.
233
+ | {--command : The terminal command that will be used to invoke the class}
234
+ | {--force : Create the class even if the console command already exists}
235
+ }
172
236
  {factory : Create a new model factory.}
173
237
  {seeder : Create a new seeder class.}
174
238
  {view : Create a new view.
@@ -203,7 +267,8 @@ var MakeCommand = class extends Command {
203
267
  factory: "makeFactory",
204
268
  seeder: "makeSeeder",
205
269
  model: "makeModel",
206
- view: "makeView"
270
+ view: "makeView",
271
+ command: "makeCommand"
207
272
  };
208
273
  try {
209
274
  await this?.[methods[command]]();
@@ -267,6 +332,12 @@ var MakeCommand = class extends Command {
267
332
  __h3ravel_shared.Logger.success("Factory support is not yet available");
268
333
  }
269
334
  /**
335
+ * Create a new Musket command
336
+ */
337
+ makeCommand() {
338
+ __h3ravel_shared.Logger.success("Musket command creation is not yet available");
339
+ }
340
+ /**
270
341
  * Create a new seeder class
271
342
  */
272
343
  makeSeeder() {
@@ -567,14 +638,16 @@ function run(opts = {}) {
567
638
 
568
639
  //#endregion
569
640
  //#region src/TsdownConfig.ts
570
- const env = process.env.NODE_ENV || "development";
571
- const outDir = env === "development" ? ".h3ravel/serve" : "dist";
641
+ const env$1 = process.env.NODE_ENV || "development";
642
+ let outDir = env$1 === "development" ? ".h3ravel/serve" : "dist";
643
+ if (process.env.DIST_DIR) outDir = process.env.DIST_DIR;
572
644
  const TsDownConfig = {
573
645
  outDir,
574
646
  entry: ["src/**/*.ts"],
575
647
  format: ["esm"],
576
648
  target: "node22",
577
- sourcemap: env === "development",
649
+ sourcemap: env$1 === "development",
650
+ minify: !!process.env.DIST_MINIFY,
578
651
  clean: true,
579
652
  shims: true,
580
653
  copy: [
@@ -585,11 +658,11 @@ const TsDownConfig = {
585
658
  "src/resources",
586
659
  "src/database"
587
660
  ],
588
- env: env === "development" ? {
589
- NODE_ENV: env,
661
+ env: env$1 === "development" ? {
662
+ NODE_ENV: env$1,
590
663
  DIST_DIR: outDir
591
664
  } : {},
592
- watch: env === "development" && process.env.CLI_BUILD !== "true" ? [
665
+ watch: env$1 === "development" && process.env.CLI_BUILD !== "true" ? [
593
666
  ".env",
594
667
  ".env.*",
595
668
  "src",
@@ -612,9 +685,9 @@ const TsDownConfig = {
612
685
  }
613
686
  });
614
687
  },
615
- plugins: env === "development" && process.env.CLI_BUILD !== "true" ? [run({
688
+ plugins: env$1 === "development" && process.env.CLI_BUILD !== "true" ? [run({
616
689
  env: Object.assign({}, process.env, {
617
- NODE_ENV: env,
690
+ NODE_ENV: env$1,
618
691
  DIST_DIR: outDir
619
692
  }),
620
693
  execArgv: ["-r", "source-map-support/register"],
@@ -644,15 +717,17 @@ var Musket = class Musket {
644
717
  [
645
718
  new MakeCommand(this.app, this.kernel),
646
719
  new ListCommand(this.app, this.kernel),
647
- new PostinstallCommand(this.app, this.kernel)
720
+ new PostinstallCommand(this.app, this.kernel),
721
+ new BuildCommand(this.app, this.kernel)
648
722
  ].forEach((e) => this.addCommand(e));
649
723
  }
650
724
  async loadDiscoveredCommands() {
725
+ const DIST_DIR = `/${env("DIST_DIR", ".h3ravel/serve")}/`.replaceAll("//", "");
651
726
  const commands = [...this.app.registeredCommands.map((cmd) => new cmd(this.app, this.kernel))];
652
727
  /**
653
728
  * Musket Commands auto registration
654
729
  */
655
- const providers_path = app_path("Console/Commands/*.js").replace("/src/", "/.h3ravel/serve/");
730
+ const providers_path = app_path("Console/Commands/*.js").replace("/src/", DIST_DIR);
656
731
  /** Add the App Commands */
657
732
  for await (const cmd of (0, node_fs_promises.glob)(providers_path)) {
658
733
  const name = node_path.default.basename(cmd).replace(".js", "");
@@ -832,6 +907,7 @@ var ConsoleServiceProvider = class extends __h3ravel_core.ServiceProvider {
832
907
  * Indicate that this service provider only runs in console
833
908
  */
834
909
  static console = true;
910
+ console = true;
835
911
  register() {}
836
912
  boot() {
837
913
  Kernel.init(this.app);
@@ -845,6 +921,7 @@ var ConsoleServiceProvider = class extends __h3ravel_core.ServiceProvider {
845
921
  };
846
922
 
847
923
  //#endregion
924
+ exports.BuildCommand = BuildCommand;
848
925
  exports.Command = Command;
849
926
  exports.ConsoleServiceProvider = ConsoleServiceProvider;
850
927
  exports.Kernel = Kernel;