@h3ravel/console 11.7.1 → 11.8.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.
- package/bin/fire.cjs +14 -10
- package/bin/fire.js +16 -12
- package/dist/index.cjs +119 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +37 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +124 -48
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/bin/fire.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const e=require(`./zero-BT86xjc9.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(`node:path`);s=e.__toESM(s);let c=require(`commander`);c=e.__toESM(c);let l=require(`node:fs`);l=e.__toESM(l);let u=require(`child_process`);u=e.__toESM(u);let d=require(`path`);d=e.__toESM(d);let f=require(`tsdown`);f=e.__toESM(f);var p=class extends t.ConsoleCommand{signature=`build:
|
|
3
|
-
{--m|minify
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
const e=require(`./zero-BT86xjc9.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(`node:path`);s=e.__toESM(s);let c=require(`commander`);c=e.__toESM(c);let l=require(`node:fs`);l=e.__toESM(l);let u=require(`child_process`);u=e.__toESM(u);let d=require(`path`);d=e.__toESM(d);let f=require(`tsdown`);f=e.__toESM(f);var p=class e extends t.ConsoleCommand{signature=`build:
|
|
3
|
+
{--m|minify : Minify your bundle output}
|
|
4
|
+
{--d|dev : Build for dev but don't watch for changes}
|
|
5
|
+
`;description=`Build the app for production`;async handle(){try{await this.fire()}catch(e){n.Logger.error(e)}}async fire(){let t=this.option(`dev`)?`.h3ravel/serve`:env(`DIST_DIR`,`dist`),n=this.option(`minify`),r=this.getVerbosity(),i=r>0;this.newLine(),await e.build({outDir:t,minify:n,verbosity:r,debug:i,mute:!1}),this.newLine()}static async build({debug:e,minify:t,mute:a,verbosity:o,outDir:s}={mute:!1,debug:!1,minify:!1,verbosity:0,outDir:`dist`}){let c=(await(0,i.default)(base_path()))?.name??`pnpm`,l={EXTENDED_DEBUG:e?`true`:`false`,CLI_BUILD:`true`,NODE_ENV:`production`,DIST_DIR:s,DIST_MINIFY:t,LOG_LEVEL:[`silent`,`info`,`warn`,`error`][o]},u=l.LOG_LEVEL===`silent`?`--silent`:null;if(a)return await(0,r.execa)(c,[`tsdown`,u,`--config-loader`,`unconfig`,`-c`,`tsdown.default.config.ts`].filter(e=>e!==null),{stdout:`inherit`,stderr:`inherit`,cwd:base_path(),env:Object.assign({},process.env,l)});let d=s===`dist`?`Production`:`Development`;return await n.TaskManager.advancedTaskRunner([[`Creating ${d} Bundle`,`STARTED`],[`${d} Bundle Created`,`COMPLETED`]],async()=>{await(0,r.execa)(c,[`tsdown`,u,`--config-loader`,`unconfig`,`-c`,`tsdown.default.config.ts`].filter(e=>e!==null),{stdout:`inherit`,stderr:`inherit`,cwd:base_path(),env:Object.assign({},process.env,l)})})}},m=class extends t.ConsoleCommand{};const h=String.raw`
|
|
6
6
|
111
|
|
7
7
|
111111111
|
|
8
8
|
1111111111 111111
|
|
@@ -31,12 +31,13 @@ const e=require(`./zero-BT86xjc9.cjs`);require(`tsx/esm`);let t=require(`@h3rave
|
|
|
31
31
|
| _ |___) | | | (_| |\ V / __/ |
|
|
32
32
|
|_| |_|____/|_| \__,_| \_/ \___|_|
|
|
33
33
|
|
|
34
|
-
`;var _=class extends m{signature=`list`;description=`List all available commands`;async handle(){let
|
|
35
|
-
`)
|
|
36
|
-
`)});n.Logger.log([[`H3ravel Framework`,`white`],[this.kernel.modulePackage.version,`green`]],` `),console.log(``),console.log(g),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(`
|
|
34
|
+
`;var _=class e extends m{signature=`list`;description=`List all available commands`;async handle(){let t=[{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(``)),r=this.program.commands.map(e=>n.Logger.describe(n.Logger.log(` `+e.name(),`green`,!1),e.description(),25,!1).join(``)),i=e.groupItems(r);n.Logger.log([[`H3ravel Framework`,`white`],[this.kernel.modulePackage.version,`green`]],` `),console.log(``),console.log(g),console.log(``),n.Logger.log(`Usage:`,`yellow`),n.Logger.log(` command [options] [arguments]`,`white`),console.log(``),n.Logger.log(`Options:`,`yellow`),console.log(t.join(`
|
|
35
|
+
`).trim()),console.log(``),n.Logger.log(`Available Commands:`,`yellow`),console.log(i.join(`
|
|
38
36
|
|
|
39
|
-
`).trim())}
|
|
37
|
+
`).trim())}static groupItems(e,t=!1){let r=e.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},{});return Object.entries(r).map(([e,r])=>{let i=e===`__root__`?``:e,a=[n.Logger.log(i,`yellow`,!1),r.join(`
|
|
38
|
+
`)].join(`
|
|
39
|
+
`);return t&&(a+=`
|
|
40
|
+
`),a})}},v=class extends m{signature=`#make:
|
|
40
41
|
{controller : Create a new controller class.
|
|
41
42
|
| {--a|api : Exclude the create and edit methods from the controller}
|
|
42
43
|
| {--m|model= : Generate a resource controller for the given model}
|
|
@@ -56,4 +57,7 @@ const e=require(`./zero-BT86xjc9.cjs`);require(`tsx/esm`);let t=require(`@h3rave
|
|
|
56
57
|
}
|
|
57
58
|
{^name : The name of the [name] to generate}
|
|
58
59
|
`;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),await this[{controller:`makeController`,resource:`makeResource`,view:`makeView`,command:`makeCommand`}[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)??``,c=s.default.join(i,`dist/stubs/controller${e}.stub`),l=app_path(`Http/Controllers/${t}.ts`);t.includes(`/`)&&await(0,a.mkdir)(o.Str.beforeLast(l,`/`),{recursive:!0}),!r&&await n.FileSystem.fileExists(l)&&n.Logger.error(`ERORR: ${t} controller already exists`);let u=await(0,a.readFile)(c,`utf-8`);u=u.replace(/{{ name }}/g,t),await(0,a.writeFile)(l,u),n.Logger.split(`INFO: Controller Created`,n.Logger.log(s.default.basename(l),`gray`,!1))}makeResource(){n.Logger.success(`Resource support is not yet available`)}makeCommand(){n.Logger.success(`Musket command creation is not yet available`)}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)(o.Str.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))}},y=class extends m{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`),``))}},b=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,h;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),h=`[${f.split(`--`).at(1)?.split(`|`).at(1)??f}]`);let g=f.startsWith(`--`),_,v;if(g){let e=f.split(`|`).map(e=>e.trim());_=[];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){_.push(t.substring(0,e));let n=t.substring(e+1);v=n===`*`?[]:n===`true`||n===`false`||!n&&!p?n===`true`:isNaN(Number(n))?n:Number(n)}else _.push(t)}}n.push({name:g?_[_.length-1]:f,required:p,multiple:m,description:l,flags:_,shared:t,isFlag:g,isHidden:r,placeholder:h,defaultValue:v,nestedOptions:u})}return n}static parseSignature(t,n){let r=t.split(`
|
|
59
|
-
`).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 x(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,d.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,u.fork)((0,d.join)(e,t),r,o)},c=e.dir||(0,d.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 S=process.env.NODE_ENV||`development`;let C=S===`development`?`.h3ravel/serve`:`dist`;process.env.DIST_DIR&&(C=process.env.DIST_DIR);const w={outDir:C,entry:[`src/**/*.ts`],format:[`esm`],target:`node22`,sourcemap:S===`development`,minify:!!process.env.DIST_MINIFY,external:[/^@h3ravel\/.*/gi],clean:!0,shims:!0,copy:[{from:`public`,to:C},`src/resources`,`src/database`],env:S===`development`?{NODE_ENV:S,DIST_DIR:C}:{},watch:S===`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,l.existsSync)(s.default.join(C,n))&&await(0,a.rm)(s.default.join(C,n),{recursive:!0})}})},plugins:S===`development`&&process.env.CLI_BUILD!==`true`?[x({env:Object.assign({},process.env,{NODE_ENV:S,DIST_DIR:C}),execArgv:[`-r`,`source-map-support/register`],allowRestarts:!1,input:process.cwd()+`/src/server.ts`})]:[]};var T=w,E=class e{commands=[];constructor(e,t){this.app=e,this.kernel=t}async build(){return this.loadBaseCommands(),await this.loadDiscoveredCommands(),this.initialize()}loadBaseCommands(){[new v(this.app,this.kernel),new _(this.app,this.kernel),new y(this.app,this.kernel),new p(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=s.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(b.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`],
|
|
60
|
+
`).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 x(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,d.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,u.fork)((0,d.join)(e,t),r,o)},c=e.dir||(0,d.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 S=process.env.NODE_ENV||`development`;let C=S===`development`?`.h3ravel/serve`:`dist`;process.env.DIST_DIR&&(C=process.env.DIST_DIR);const w={outDir:C,entry:[`src/**/*.ts`],format:[`esm`],target:`node22`,sourcemap:S===`development`,minify:!!process.env.DIST_MINIFY,external:[/^@h3ravel\/.*/gi],clean:!0,shims:!0,copy:[{from:`public`,to:C},`src/resources`,`src/database`],env:S===`development`?{NODE_ENV:S,DIST_DIR:C}:{},watch:S===`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,l.existsSync)(s.default.join(C,n))&&await(0,a.rm)(s.default.join(C,n),{recursive:!0})}})},plugins:S===`development`&&process.env.CLI_BUILD!==`true`?[x({env:Object.assign({},process.env,{NODE_ENV:S,DIST_DIR:C}),execArgv:[`-r`,`source-map-support/register`],allowRestarts:!1,input:process.cwd()+`/src/server.ts`})]:[]};var T=w,E=class e{commands=[];constructor(e,t){this.app=e,this.kernel=t}async build(){return this.loadBaseCommands(),await this.loadDiscoveredCommands(),await this.initialize()}loadBaseCommands(){[new v(this.app,this.kernel),new _(this.app,this.kernel),new y(this.app,this.kernel),new p(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=s.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(b.parseSignature(e.getSignature(),e))}async initialize(){(process.argv.includes(`--help`)||process.argv.includes(`-h`))&&(await this.rebuild(`help`),Object.keys(require.cache).forEach(e=>delete require.cache[e]));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 except errors and warnings`],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`],noInteraction:[`-n, --no-interaction`,`Do not ask any interactive question`]};c.program.name(`musket`).version(`${e}\n${t}`).description(g).configureHelp({showGlobalOptions:!0}).addOption(new c.Option(r.quiet[0],r.quiet[1])).addOption(new c.Option(r.silent[0],r.silent[1]).implies({quiet:!0})).addOption(new c.Option(r.verbose[0],r.verbose[1]).choices([`1`,`2`,`3`])).addOption(new c.Option(r.noInteraction[0],r.noInteraction[1])).action(async()=>{let e=new _(this.app,this.kernel);e.setInput(c.program.opts(),c.program.args,c.program.registeredArguments,{},c.program),e.handle()}),c.program.configureHelp({styleTitle:e=>n.Logger.log(e,`yellow`,!1),styleOptionTerm:e=>n.Logger.log(e,`green`,!1),styleArgumentTerm:e=>n.Logger.log(e,`green`,!1),styleSubcommandTerm:e=>n.Logger.log(e,`green`,!1),formatItemList(e,t){if(t.length<1)return[];let r=e=>e.replace(/[^A-Za-z0-9-,]/g,``).replace(`32m`,``),i=t.filter(e=>r(e).startsWith(`--`)||r(e).includes(`,--`));i.length>0&&(i=[n.Logger.log(`
|
|
61
|
+
`+e+`
|
|
62
|
+
`,`yellow`,!1)].concat(i));let a=t.filter(e=>!r(e).startsWith(`--`)&&!r(e).includes(`,--`));return a.length<1?i:i.concat(n.Logger.log(`
|
|
63
|
+
Available Commands:`,`yellow`,!1),_.groupItems(a,!0))},showGlobalOptions:!0}),c.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?c.program:c.program.command(t.baseCommand).description(t.description??``).action(async()=>{n.setInput(e.opts(),e.args,e.registeredArguments,t,c.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 r=c.program.command(`${t.baseCommand}:${e.name}`).description(e.description||``).action(async()=>{n.setInput(r.opts(),r.args,r.registeredArguments,e,c.program),await n.handle()});t.subCommands?.filter(e=>e.shared).forEach(t=>{this.makeOption(t,r,!1,e)}),t.options?.filter(e=>e.shared).forEach(t=>{this.makeOption(t,r,!1,e)}),e.nestedOptions&&e.nestedOptions.filter((e,t,n)=>n.findIndex(t=>t.name===e.name)===t).forEach(e=>{this.makeOption(e,r)})})}else{let e=c.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,c.program),await n.handle()})}}return c.program.hook(`preAction`,async(e,t)=>{this.rebuild(t.name())}),c.program}async rebuild(e){e!==`fire`&&e!==`build`&&await(0,f.build)({...T,watch:!1,plugins:[]})}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.replace(/^-+/,``)}`).join(`, `)??void 0;e.required&&!e.placeholder?n+=` <${a}>`:e.placeholder&&(n+=` `+e.placeholder),t.option(n||``,i,e.defaultValue)}else{let n=e.flags?.join(`, `)??``;e.required&&!e.placeholder?n+=` <${a}>`:e.placeholder&&(n+=` `+e.placeholder),t.option(n,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()}},D=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 E.parse(this),process.exit(0)}async loadRequirements(){this.cwd=s.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(s.default.join(this.modulePath,`package.json`))}catch{this.modulePackage={version:`N/A`}}try{this.consolePackage=await import(s.default.join(this.consolePath,`package.json`))}catch{this.consolePackage={version:`N/A`}}return this}},O=class extends t.ServiceProvider{static priority=992;static runsInConsole=!0;runsInConsole=!0;register(){}boot(){D.init(this.app),process.on(`SIGINT`,()=>{process.exit(0)}),process.on(`SIGTERM`,()=>{process.exit(0)})}},k=class{async fire(){let e=process.env.DIST_DIR??`/.h3ravel/serve/`,n=[],r=new t.Application(process.cwd()),i=base_path(s.default.join(e,`bootstrap/providers.js`));n.push(...(await import(i)).default),n.push(O),await r.quickStartup(n,[`CoreServiceProvider`])}};new k().fire();
|
package/bin/fire.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import"./zero-Ddh7ucIS.js";import"tsx/esm";import{Application as
|
|
3
|
-
{--m|minify
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import"./zero-Ddh7ucIS.js";import{createRequire as e}from"node:module";import"tsx/esm";import{Application as t,ConsoleCommand as n,ConsoleKernel as r,ServiceProvider as i}from"@h3ravel/core";import{FileSystem as a,Logger as o,TaskManager as s}from"@h3ravel/shared";import{execa as c}from"execa";import l from"preferred-pm";import{glob as u,mkdir as d,readFile as f,rm as p,writeFile as m}from"node:fs/promises";import{Str as h}from"@h3ravel/support";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=e(import.meta.url),E=class e extends n{signature=`build:
|
|
3
|
+
{--m|minify : Minify your bundle output}
|
|
4
|
+
{--d|dev : Build for dev but don't watch for changes}
|
|
5
|
+
`;description=`Build the app for production`;async handle(){try{await this.fire()}catch(e){o.error(e)}}async fire(){let t=this.option(`dev`)?`.h3ravel/serve`:env(`DIST_DIR`,`dist`),n=this.option(`minify`),r=this.getVerbosity(),i=r>0;this.newLine(),await e.build({outDir:t,minify:n,verbosity:r,debug:i,mute:!1}),this.newLine()}static async build({debug:e,minify:t,mute:n,verbosity:r,outDir:i}={mute:!1,debug:!1,minify:!1,verbosity:0,outDir:`dist`}){let a=(await l(base_path()))?.name??`pnpm`,o={EXTENDED_DEBUG:e?`true`:`false`,CLI_BUILD:`true`,NODE_ENV:`production`,DIST_DIR:i,DIST_MINIFY:t,LOG_LEVEL:[`silent`,`info`,`warn`,`error`][r]},u=o.LOG_LEVEL===`silent`?`--silent`:null;if(n)return await c(a,[`tsdown`,u,`--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)});let d=i===`dist`?`Production`:`Development`;return await s.advancedTaskRunner([[`Creating ${d} Bundle`,`STARTED`],[`${d} Bundle Created`,`COMPLETED`]],async()=>{await c(a,[`tsdown`,u,`--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)})})}},D=class extends n{};String.raw`
|
|
6
6
|
111
|
|
7
7
|
111111111
|
|
8
8
|
1111111111 111111
|
|
@@ -24,19 +24,20 @@ import"./zero-Ddh7ucIS.js";import"tsx/esm";import{Application as e,ConsoleComman
|
|
|
24
24
|
111111 111 111111
|
|
25
25
|
111111111
|
|
26
26
|
110
|
|
27
|
-
`;const
|
|
27
|
+
`;const O=String.raw`
|
|
28
28
|
_ _ _____ _
|
|
29
29
|
| | | |___ / _ __ __ ___ _____| |
|
|
30
30
|
| |_| | |_ \| '__/ _ \ \ / / _ \ |
|
|
31
31
|
| _ |___) | | | (_| |\ V / __/ |
|
|
32
32
|
|_| |_|____/|_| \__,_| \_/ \___|_|
|
|
33
33
|
|
|
34
|
-
`;var
|
|
35
|
-
`)
|
|
36
|
-
`)});a.log([[`H3ravel Framework`,`white`],[this.kernel.modulePackage.version,`green`]],` `),console.log(``),console.log(E),console.log(``),a.log(`Usage:`,`yellow`),a.log(` command [options] [arguments]`,`white`),console.log(``),a.log(`Options:`,`yellow`),console.log(e.join(`
|
|
37
|
-
`).trim()),console.log(``),a.log(`Available Commands:`,`yellow`),console.log(n.join(`
|
|
34
|
+
`;var k=class e extends D{signature=`list`;description=`List all available commands`;async handle(){let t=[{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=>o.describe(o.log(` `+[e.short,e.long].filter(e=>!!e).join(`, `),`green`,!1),e.description,25,!1).join(``)),n=this.program.commands.map(e=>o.describe(o.log(` `+e.name(),`green`,!1),e.description(),25,!1).join(``)),r=e.groupItems(n);o.log([[`H3ravel Framework`,`white`],[this.kernel.modulePackage.version,`green`]],` `),console.log(``),console.log(O),console.log(``),o.log(`Usage:`,`yellow`),o.log(` command [options] [arguments]`,`white`),console.log(``),o.log(`Options:`,`yellow`),console.log(t.join(`
|
|
35
|
+
`).trim()),console.log(``),o.log(`Available Commands:`,`yellow`),console.log(r.join(`
|
|
38
36
|
|
|
39
|
-
`).trim())}
|
|
37
|
+
`).trim())}static groupItems(e,t=!1){let n=e.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},{});return Object.entries(n).map(([e,n])=>{let r=e===`__root__`?``:e,i=[o.log(r,`yellow`,!1),n.join(`
|
|
38
|
+
`)].join(`
|
|
39
|
+
`);return t&&(i+=`
|
|
40
|
+
`),i})}},A=class extends D{signature=`#make:
|
|
40
41
|
{controller : Create a new controller class.
|
|
41
42
|
| {--a|api : Exclude the create and edit methods from the controller}
|
|
42
43
|
| {--m|model= : Generate a resource controller for the given model}
|
|
@@ -55,5 +56,8 @@ import"./zero-Ddh7ucIS.js";import"tsx/esm";import{Application as e,ConsoleComman
|
|
|
55
56
|
| {--force : Create the view even if it already exists}
|
|
56
57
|
}
|
|
57
58
|
{^name : The name of the [name] to generate}
|
|
58
|
-
`;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),await this[{controller:`makeController`,resource:`makeResource`,view:`makeView`,command:`makeCommand`}[e]]()}async makeController(){let e=this.option(`api`)?`-resource`:``,t=this.argument(`name`),n=this.option(`force`),r=
|
|
59
|
-
`).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
|
|
59
|
+
`;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),await this[{controller:`makeController`,resource:`makeResource`,view:`makeView`,command:`makeCommand`}[e]]()}async makeController(){let e=this.option(`api`)?`-resource`:``,t=this.argument(`name`),n=this.option(`force`),r=a.findModulePkg(`@h3ravel/http`,this.kernel.cwd)??``,i=g.join(r,`dist/stubs/controller${e}.stub`),s=app_path(`Http/Controllers/${t}.ts`);t.includes(`/`)&&await d(h.beforeLast(s,`/`),{recursive:!0}),!n&&await a.fileExists(s)&&o.error(`ERORR: ${t} controller already exists`);let c=await f(i,`utf-8`);c=c.replace(/{{ name }}/g,t),await m(s,c),o.split(`INFO: Controller Created`,o.log(g.basename(s),`gray`,!1))}makeResource(){o.success(`Resource support is not yet available`)}makeCommand(){o.success(`Musket command creation is not yet available`)}async makeView(){let e=this.argument(`name`),t=this.option(`force`),n=base_path(`src/resources/views/${e}.edge`);e.includes(`/`)&&await d(h.beforeLast(n,`/`),{recursive:!0}),!t&&await a.fileExists(n)&&o.error(`ERORR: ${e} view already exists`),await m(n,`{{-- src/resources/views/${e}.edge --}}`),o.split(`INFO: View Created`,o.log(`src/resources/views/${e}.edge`,`gray`,!1))}},j=class extends D{signature=`postinstall`;description=`Default post installation command`;async handle(){this.createSqliteDB()}async createSqliteDB(){config(`database.default`)===`sqlite`&&(await a.fileExists(database_path())||await d(database_path(),{recursive:!0}),await a.fileExists(database_path(`db.sqlite`))||await m(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,h;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),h=`[${f.split(`--`).at(1)?.split(`|`).at(1)??f}]`);let g=f.startsWith(`--`),_,v;if(g){let e=f.split(`|`).map(e=>e.trim());_=[];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){_.push(t.substring(0,e));let n=t.substring(e+1);v=n===`*`?[]:n===`true`||n===`false`||!n&&!p?n===`true`:isNaN(Number(n))?n:Number(n)}else _.push(t)}}n.push({name:g?_[_.length-1]:f,required:p,multiple:m,description:l,flags:_,shared:t,isFlag:g,isHidden:r,placeholder:h,defaultValue:v,nestedOptions:u})}return n}static parseSignature(t,n){let r=t.split(`
|
|
60
|
+
`).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,external:[/^@h3ravel\/.*/gi],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 p(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(),await this.initialize()}loadBaseCommands(){[new A(this.app,this.kernel),new k(this.app,this.kernel),new j(this.app,this.kernel),new E(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 u(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))}async initialize(){(process.argv.includes(`--help`)||process.argv.includes(`-h`))&&(await this.rebuild(`help`),Object.keys(T.cache).forEach(e=>delete T.cache[e]));let e=o.parse([[`Musket CLI:`,`white`],[this.kernel.consolePackage.version,`green`]],` `,!1),t=o.parse([[`H3ravel Framework:`,`white`],[this.kernel.modulePackage.version,`green`]],` `,!1),n={quiet:[`-q, --quiet`,`Do not output any message except errors and warnings`],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`],noInteraction:[`-n, --no-interaction`,`Do not ask any interactive question`]};v.name(`musket`).version(`${e}\n${t}`).description(O).configureHelp({showGlobalOptions:!0}).addOption(new _(n.quiet[0],n.quiet[1])).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.noInteraction[0],n.noInteraction[1])).action(async()=>{let e=new k(this.app,this.kernel);e.setInput(v.opts(),v.args,v.registeredArguments,{},v),e.handle()}),v.configureHelp({styleTitle:e=>o.log(e,`yellow`,!1),styleOptionTerm:e=>o.log(e,`green`,!1),styleArgumentTerm:e=>o.log(e,`green`,!1),styleSubcommandTerm:e=>o.log(e,`green`,!1),formatItemList(e,t){if(t.length<1)return[];let n=e=>e.replace(/[^A-Za-z0-9-,]/g,``).replace(`32m`,``),r=t.filter(e=>n(e).startsWith(`--`)||n(e).includes(`,--`));r.length>0&&(r=[o.log(`
|
|
61
|
+
`+e+`
|
|
62
|
+
`,`yellow`,!1)].concat(r));let i=t.filter(e=>!n(e).startsWith(`--`)&&!n(e).includes(`,--`));return i.length<1?r:r.concat(o.log(`
|
|
63
|
+
Available Commands:`,`yellow`,!1),k.groupItems(i,!0))},showGlobalOptions:!0}),v.command(`init`).description(`Initialize H3ravel.`).action(async()=>{o.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?v:v.command(t.baseCommand).description(t.description??``).action(async()=>{n.setInput(e.opts(),e.args,e.registeredArguments,t,v),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 r=v.command(`${t.baseCommand}:${e.name}`).description(e.description||``).action(async()=>{n.setInput(r.opts(),r.args,r.registeredArguments,e,v),await n.handle()});t.subCommands?.filter(e=>e.shared).forEach(t=>{this.makeOption(t,r,!1,e)}),t.options?.filter(e=>e.shared).forEach(t=>{this.makeOption(t,r,!1,e)}),e.nestedOptions&&e.nestedOptions.filter((e,t,n)=>n.findIndex(t=>t.name===e.name)===t).forEach(e=>{this.makeOption(e,r)})})}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()=>{n.setInput(e.opts(),e.args,e.registeredArguments,t,v),await n.handle()})}}return v.hook(`preAction`,async(e,t)=>{this.rebuild(t.name())}),v}async rebuild(e){e!==`fire`&&e!==`build`&&await w({...I,watch:!1,plugins:[]})}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.replace(/^-+/,``)}`).join(`, `)??void 0;e.required&&!e.placeholder?n+=` <${a}>`:e.placeholder&&(n+=` `+e.placeholder),t.option(n||``,i,e.defaultValue)}else{let n=e.flags?.join(`, `)??``;e.required&&!e.placeholder?n+=` <${a}>`:e.placeholder&&(n+=` `+e.placeholder),t.option(n,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 r{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=a.findModulePkg(`@h3ravel/core`,this.cwd)??``,this.consolePath=a.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 i{static priority=992;static runsInConsole=!0;runsInConsole=!0;register(){}boot(){R.init(this.app),process.on(`SIGINT`,()=>{process.exit(0)}),process.on(`SIGTERM`,()=>{process.exit(0)})}};new class{async fire(){let e=process.env.DIST_DIR??`/.h3ravel/serve/`,n=[],r=new t(process.cwd()),i=base_path(g.join(e,`bootstrap/providers.js`));n.push(...(await import(i)).default),n.push(z),await r.quickStartup(n,[`CoreServiceProvider`])}}().fire();export{};
|
package/dist/index.cjs
CHANGED
|
@@ -47,14 +47,15 @@ let tsdown = require("tsdown");
|
|
|
47
47
|
tsdown = __toESM(tsdown);
|
|
48
48
|
|
|
49
49
|
//#region src/Commands/BuildCommand.ts
|
|
50
|
-
var BuildCommand = class extends __h3ravel_core.ConsoleCommand {
|
|
50
|
+
var BuildCommand = class BuildCommand extends __h3ravel_core.ConsoleCommand {
|
|
51
51
|
/**
|
|
52
52
|
* The name and signature of the console command.
|
|
53
53
|
*
|
|
54
54
|
* @var string
|
|
55
55
|
*/
|
|
56
56
|
signature = `build:
|
|
57
|
-
{--m|minify
|
|
57
|
+
{--m|minify : Minify your bundle output}
|
|
58
|
+
{--d|dev : Build for dev but don't watch for changes}
|
|
58
59
|
`;
|
|
59
60
|
/**
|
|
60
61
|
* The console command description.
|
|
@@ -70,11 +71,33 @@ var BuildCommand = class extends __h3ravel_core.ConsoleCommand {
|
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
async fire() {
|
|
73
|
-
const outDir$1 = env("DIST_DIR", "dist");
|
|
74
|
-
const pm = (await (0, preferred_pm.default)(base_path()))?.name ?? "pnpm";
|
|
74
|
+
const outDir$1 = this.option("dev") ? ".h3ravel/serve" : env("DIST_DIR", "dist");
|
|
75
75
|
const minify = this.option("minify");
|
|
76
|
+
const verbosity = this.getVerbosity();
|
|
77
|
+
const debug = verbosity > 0;
|
|
78
|
+
this.newLine();
|
|
79
|
+
await BuildCommand.build({
|
|
80
|
+
outDir: outDir$1,
|
|
81
|
+
minify,
|
|
82
|
+
verbosity,
|
|
83
|
+
debug,
|
|
84
|
+
mute: false
|
|
85
|
+
});
|
|
86
|
+
this.newLine();
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* build
|
|
90
|
+
*/
|
|
91
|
+
static async build({ debug, minify, mute, verbosity, outDir: outDir$1 } = {
|
|
92
|
+
mute: false,
|
|
93
|
+
debug: false,
|
|
94
|
+
minify: false,
|
|
95
|
+
verbosity: 0,
|
|
96
|
+
outDir: "dist"
|
|
97
|
+
}) {
|
|
98
|
+
const pm = (await (0, preferred_pm.default)(base_path()))?.name ?? "pnpm";
|
|
76
99
|
const ENV_VARS = {
|
|
77
|
-
EXTENDED_DEBUG:
|
|
100
|
+
EXTENDED_DEBUG: debug ? "true" : "false",
|
|
78
101
|
CLI_BUILD: "true",
|
|
79
102
|
NODE_ENV: "production",
|
|
80
103
|
DIST_DIR: outDir$1,
|
|
@@ -84,12 +107,24 @@ var BuildCommand = class extends __h3ravel_core.ConsoleCommand {
|
|
|
84
107
|
"info",
|
|
85
108
|
"warn",
|
|
86
109
|
"error"
|
|
87
|
-
][
|
|
110
|
+
][verbosity]
|
|
88
111
|
};
|
|
89
112
|
const silent = ENV_VARS.LOG_LEVEL === "silent" ? "--silent" : null;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
113
|
+
if (mute) return await (0, execa.execa)(pm, [
|
|
114
|
+
"tsdown",
|
|
115
|
+
silent,
|
|
116
|
+
"--config-loader",
|
|
117
|
+
"unconfig",
|
|
118
|
+
"-c",
|
|
119
|
+
"tsdown.default.config.ts"
|
|
120
|
+
].filter((e) => e !== null), {
|
|
121
|
+
stdout: "inherit",
|
|
122
|
+
stderr: "inherit",
|
|
123
|
+
cwd: base_path(),
|
|
124
|
+
env: Object.assign({}, process.env, ENV_VARS)
|
|
125
|
+
});
|
|
126
|
+
const type = outDir$1 === "dist" ? "Production" : "Development";
|
|
127
|
+
return await __h3ravel_shared.TaskManager.advancedTaskRunner([[`Creating ${type} Bundle`, "STARTED"], [`${type} Bundle Created`, "COMPLETED"]], async () => {
|
|
93
128
|
await (0, execa.execa)(pm, [
|
|
94
129
|
"tsdown",
|
|
95
130
|
silent,
|
|
@@ -103,7 +138,6 @@ var BuildCommand = class extends __h3ravel_core.ConsoleCommand {
|
|
|
103
138
|
cwd: base_path(),
|
|
104
139
|
env: Object.assign({}, process.env, ENV_VARS)
|
|
105
140
|
});
|
|
106
|
-
console.log("");
|
|
107
141
|
});
|
|
108
142
|
}
|
|
109
143
|
};
|
|
@@ -148,7 +182,7 @@ const altLogo = String.raw`
|
|
|
148
182
|
|
|
149
183
|
//#endregion
|
|
150
184
|
//#region src/Commands/ListCommand.ts
|
|
151
|
-
var ListCommand = class extends Command {
|
|
185
|
+
var ListCommand = class ListCommand extends Command {
|
|
152
186
|
/**
|
|
153
187
|
* The name and signature of the console command.
|
|
154
188
|
*
|
|
@@ -169,21 +203,11 @@ var ListCommand = class extends Command {
|
|
|
169
203
|
}].concat(this.program.options).map((e) => {
|
|
170
204
|
return __h3ravel_shared.Logger.describe(__h3ravel_shared.Logger.log(" " + [e.short, e.long].filter((e$1) => !!e$1).join(", "), "green", false), e.description, 25, false).join("");
|
|
171
205
|
});
|
|
172
|
-
|
|
206
|
+
/** Get the program commands */
|
|
207
|
+
const commands = this.program.commands.map((e) => {
|
|
173
208
|
return __h3ravel_shared.Logger.describe(__h3ravel_shared.Logger.log(" " + e.name(), "green", false), e.description(), 25, false).join("");
|
|
174
|
-
}).reduce((acc, cmd) => {
|
|
175
|
-
/** strip colors before checking prefix */
|
|
176
|
-
const clean = cmd.replace(/\x1b\[\d+m/g, "");
|
|
177
|
-
const prefix = clean.includes(":") ? clean.split(":")[0].trim() : "__root__";
|
|
178
|
-
acc[prefix] ??= [];
|
|
179
|
-
/** keep original with colors */
|
|
180
|
-
acc[prefix].push(cmd);
|
|
181
|
-
return acc;
|
|
182
|
-
}, {});
|
|
183
|
-
const list = Object.entries(grouped).map(([group, cmds]) => {
|
|
184
|
-
const label = group === "__root__" ? "" : group;
|
|
185
|
-
return [__h3ravel_shared.Logger.log(label, "yellow", false), cmds.join("\n")].join("\n");
|
|
186
209
|
});
|
|
210
|
+
const list = ListCommand.groupItems(commands);
|
|
187
211
|
/** Ootput the app version */
|
|
188
212
|
__h3ravel_shared.Logger.log([["H3ravel Framework", "white"], [this.kernel.modulePackage.version, "green"]], " ");
|
|
189
213
|
console.log("");
|
|
@@ -200,6 +224,29 @@ var ListCommand = class extends Command {
|
|
|
200
224
|
__h3ravel_shared.Logger.log("Available Commands:", "yellow");
|
|
201
225
|
console.log(list.join("\n\n").trim());
|
|
202
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Group Commands based on thier names
|
|
229
|
+
*
|
|
230
|
+
* @param commands
|
|
231
|
+
* @returns
|
|
232
|
+
*/
|
|
233
|
+
static groupItems(commands, fmtd = false) {
|
|
234
|
+
const grouped = commands.reduce((acc, cmd) => {
|
|
235
|
+
/** strip colors before checking prefix */
|
|
236
|
+
const clean = cmd.replace(/\x1b\[\d+m/g, "");
|
|
237
|
+
const prefix = clean.includes(":") ? clean.split(":")[0].trim() : "__root__";
|
|
238
|
+
acc[prefix] ??= [];
|
|
239
|
+
/** keep original with colors */
|
|
240
|
+
acc[prefix].push(cmd);
|
|
241
|
+
return acc;
|
|
242
|
+
}, {});
|
|
243
|
+
return Object.entries(grouped).map(([group, cmds]) => {
|
|
244
|
+
const label = group === "__root__" ? "" : group;
|
|
245
|
+
let out = [__h3ravel_shared.Logger.log(label, "yellow", false), cmds.join("\n")].join("\n");
|
|
246
|
+
if (fmtd) out += "\n";
|
|
247
|
+
return out;
|
|
248
|
+
});
|
|
249
|
+
}
|
|
203
250
|
};
|
|
204
251
|
|
|
205
252
|
//#endregion
|
|
@@ -609,7 +656,7 @@ var Musket = class Musket {
|
|
|
609
656
|
async build() {
|
|
610
657
|
this.loadBaseCommands();
|
|
611
658
|
await this.loadDiscoveredCommands();
|
|
612
|
-
return this.initialize();
|
|
659
|
+
return await this.initialize();
|
|
613
660
|
}
|
|
614
661
|
loadBaseCommands() {
|
|
615
662
|
[
|
|
@@ -639,32 +686,61 @@ var Musket = class Musket {
|
|
|
639
686
|
addCommand(command) {
|
|
640
687
|
this.commands.push(Signature.parseSignature(command.getSignature(), command));
|
|
641
688
|
}
|
|
642
|
-
initialize() {
|
|
689
|
+
async initialize() {
|
|
690
|
+
if (process.argv.includes("--help") || process.argv.includes("-h")) {
|
|
691
|
+
await this.rebuild("help");
|
|
692
|
+
Object.keys(require.cache).forEach((key) => delete require.cache[key]);
|
|
693
|
+
}
|
|
643
694
|
/** Init the Musket Version */
|
|
644
695
|
const cliVersion = __h3ravel_shared.Logger.parse([["Musket CLI:", "white"], [this.kernel.consolePackage.version, "green"]], " ", false);
|
|
645
696
|
/** Init the App Version */
|
|
646
697
|
const localVersion = __h3ravel_shared.Logger.parse([["H3ravel Framework:", "white"], [this.kernel.modulePackage.version, "green"]], " ", false);
|
|
647
698
|
const additional = {
|
|
648
|
-
quiet: ["-q, --quiet", "Do not output any message"],
|
|
699
|
+
quiet: ["-q, --quiet", "Do not output any message except errors and warnings"],
|
|
649
700
|
silent: ["--silent", "Do not output any message"],
|
|
650
701
|
verbose: ["-v, --verbose <number>", "Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug"],
|
|
651
|
-
|
|
702
|
+
noInteraction: ["-n, --no-interaction", "Do not ask any interactive question"]
|
|
652
703
|
};
|
|
653
|
-
/**
|
|
654
|
-
|
|
704
|
+
/**
|
|
705
|
+
* Init Commander
|
|
706
|
+
*/
|
|
707
|
+
commander.program.name("musket").version(`${cliVersion}\n${localVersion}`).description(altLogo).configureHelp({ showGlobalOptions: true }).addOption(new commander.Option(additional.quiet[0], additional.quiet[1])).addOption(new commander.Option(additional.silent[0], additional.silent[1]).implies({ quiet: true })).addOption(new commander.Option(additional.verbose[0], additional.verbose[1]).choices([
|
|
655
708
|
"1",
|
|
656
709
|
"2",
|
|
657
710
|
"3"
|
|
658
|
-
])).addOption(new commander.Option(additional.
|
|
711
|
+
])).addOption(new commander.Option(additional.noInteraction[0], additional.noInteraction[1])).action(async () => {
|
|
659
712
|
const instance = new ListCommand(this.app, this.kernel);
|
|
660
713
|
instance.setInput(commander.program.opts(), commander.program.args, commander.program.registeredArguments, {}, commander.program);
|
|
661
714
|
instance.handle();
|
|
662
715
|
});
|
|
663
|
-
/**
|
|
716
|
+
/**
|
|
717
|
+
* Format the help command display
|
|
718
|
+
*/
|
|
719
|
+
commander.program.configureHelp({
|
|
720
|
+
styleTitle: (str) => __h3ravel_shared.Logger.log(str, "yellow", false),
|
|
721
|
+
styleOptionTerm: (str) => __h3ravel_shared.Logger.log(str, "green", false),
|
|
722
|
+
styleArgumentTerm: (str) => __h3ravel_shared.Logger.log(str, "green", false),
|
|
723
|
+
styleSubcommandTerm: (str) => __h3ravel_shared.Logger.log(str, "green", false),
|
|
724
|
+
formatItemList(heading, items) {
|
|
725
|
+
if (items.length < 1) return [];
|
|
726
|
+
const c = (str) => str.replace(/[^A-Za-z0-9-,]/g, "").replace("32m", "");
|
|
727
|
+
let flags = items.filter((e) => c(e).startsWith("--") || c(e).includes(",--"));
|
|
728
|
+
if (flags.length > 0) flags = [__h3ravel_shared.Logger.log("\n" + heading + "\n", "yellow", false)].concat(flags);
|
|
729
|
+
const list = items.filter((e) => !c(e).startsWith("--") && !c(e).includes(",--"));
|
|
730
|
+
if (list.length < 1) return flags;
|
|
731
|
+
return flags.concat(__h3ravel_shared.Logger.log("\nAvailable Commands:", "yellow", false), ListCommand.groupItems(list, true));
|
|
732
|
+
},
|
|
733
|
+
showGlobalOptions: true
|
|
734
|
+
});
|
|
735
|
+
/**
|
|
736
|
+
* Create the init Command
|
|
737
|
+
*/
|
|
664
738
|
commander.program.command("init").description("Initialize H3ravel.").action(async () => {
|
|
665
739
|
__h3ravel_shared.Logger.success("Initialized: H3ravel has been initialized!");
|
|
666
740
|
});
|
|
667
|
-
/**
|
|
741
|
+
/**
|
|
742
|
+
* Loop through all the available commands
|
|
743
|
+
*/
|
|
668
744
|
for (let i = 0; i < this.commands.length; i++) {
|
|
669
745
|
const command = this.commands[i];
|
|
670
746
|
const instance = command.commandClass;
|
|
@@ -672,11 +748,7 @@ var Musket = class Musket {
|
|
|
672
748
|
/**
|
|
673
749
|
* Initialize the base command
|
|
674
750
|
*/
|
|
675
|
-
const cmd = command.isHidden ? commander.program : commander.program.command(command.baseCommand).description(command.description ?? "").
|
|
676
|
-
"1",
|
|
677
|
-
"2",
|
|
678
|
-
"3"
|
|
679
|
-
])).addOption(new commander.Option(additional.lock[0], additional.lock[1])).action(async () => {
|
|
751
|
+
const cmd = command.isHidden ? commander.program : commander.program.command(command.baseCommand).description(command.description ?? "").action(async () => {
|
|
680
752
|
instance.setInput(cmd.opts(), cmd.args, cmd.registeredArguments, command, commander.program);
|
|
681
753
|
await instance.handle();
|
|
682
754
|
});
|
|
@@ -690,11 +762,7 @@ var Musket = class Musket {
|
|
|
690
762
|
* Initialize the sub commands
|
|
691
763
|
*/
|
|
692
764
|
command.subCommands.filter((v, i$1, a) => !v.shared && a.findIndex((t) => t.name === v.name) === i$1).forEach((sub) => {
|
|
693
|
-
const cmd$1 = commander.program.command(`${command.baseCommand}:${sub.name}`).description(sub.description || "").
|
|
694
|
-
"1",
|
|
695
|
-
"2",
|
|
696
|
-
"3"
|
|
697
|
-
])).addOption(new commander.Option(additional.lock[0], additional.lock[1])).action(async () => {
|
|
765
|
+
const cmd$1 = commander.program.command(`${command.baseCommand}:${sub.name}`).description(sub.description || "").action(async () => {
|
|
698
766
|
instance.setInput(cmd$1.opts(), cmd$1.args, cmd$1.registeredArguments, sub, commander.program);
|
|
699
767
|
await instance.handle();
|
|
700
768
|
});
|
|
@@ -733,14 +801,17 @@ var Musket = class Musket {
|
|
|
733
801
|
}
|
|
734
802
|
/** Rebuild the app on every command except fire so we wont need TS */
|
|
735
803
|
commander.program.hook("preAction", async (_, cmd) => {
|
|
736
|
-
|
|
737
|
-
...TsdownConfig_default,
|
|
738
|
-
watch: false,
|
|
739
|
-
plugins: []
|
|
740
|
-
});
|
|
804
|
+
this.rebuild(cmd.name());
|
|
741
805
|
});
|
|
742
806
|
return commander.program;
|
|
743
807
|
}
|
|
808
|
+
async rebuild(name) {
|
|
809
|
+
if (name !== "fire" && name !== "build") await (0, tsdown.build)({
|
|
810
|
+
...TsdownConfig_default,
|
|
811
|
+
watch: false,
|
|
812
|
+
plugins: []
|
|
813
|
+
});
|
|
814
|
+
}
|
|
744
815
|
makeOption(opt, cmd, parse, parent) {
|
|
745
816
|
const description = opt.description?.replace(/\[(\w+)\]/g, (_, k) => parent?.[k] ?? `[${k}]`) ?? "";
|
|
746
817
|
const type = opt.name.replaceAll("-", "");
|