@h3ravel/console 11.3.9 → 11.4.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 -7
- package/bin/fire.js +14 -7
- package/dist/index.cjs +99 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -1
- package/dist/index.d.ts +24 -1
- package/dist/index.js +95 -21
- package/dist/index.js.map +1 -1
- package/package.json +4 -11
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(`
|
|
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(`execa`);u=s(u);let d=require(`preferred-pm`);d=s(d);let f=require(`node:fs/promises`);f=s(f);let p=require(`@h3ravel/support`);p=s(p);let m=require(`dayjs`);m=s(m);let h=require(`node:path`);h=s(h);let g=require(`commander`);g=s(g);let _=require(`node:fs`);_=s(_);let v=require(`child_process`);v=s(v);let y=require(`path`);y=s(y);let b=require(`tsdown`);b=s(b);var x=class extends c.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){l.Logger.error(e)}}async fire(){let e=env(`DIST_DIR`,`dist`),t=(await(0,d.default)(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;l.Logger.log([[`
|
|
5
|
+
INFO `,`bgBlue`],[` Creating Production Bundle`,`white`]],``),console.log(``),await l.TaskManager.taskRunner(l.Logger.log([[` SUCCESS `,`bgGreen`],[` Production Bundle Created`,`white`]],``,!1),async()=>{await(0,u.execa)(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(``)})}},S=class extends c.ConsoleCommand{};const C=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
|
-
`,
|
|
27
|
+
`,w=String.raw`
|
|
25
28
|
_ _ _____ _
|
|
26
29
|
| | | |___ / _ __ __ ___ _____| |
|
|
27
30
|
| |_| | |_ \| '__/ _ \ \ / / _ \ |
|
|
28
31
|
| _ |___) | | | (_| |\ V / __/ |
|
|
29
32
|
|_| |_|____/|_| \__,_| \_/ \___|_|
|
|
30
33
|
|
|
31
|
-
`;var
|
|
34
|
+
`;var T=class extends S{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(`
|
|
32
35
|
`)].join(`
|
|
33
|
-
`)});l.Logger.log([[`H3ravel Framework`,`white`],[this.kernel.modulePackage.version,`green`]],` `),console.log(``),console.log(
|
|
36
|
+
`)});l.Logger.log([[`H3ravel Framework`,`white`],[this.kernel.modulePackage.version,`green`]],` `),console.log(``),console.log(w),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
37
|
`).trim()),console.log(``),l.Logger.log(`Available Commands:`,`yellow`),console.log(n.join(`
|
|
35
38
|
|
|
36
|
-
`).trim())}},
|
|
39
|
+
`).trim())}},E=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[]}},D=class extends S{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=
|
|
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
|
|
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){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=h.default.join(r,`dist/stubs/controller${e}.stub`),a=app_path(`Http/Controllers/${t}.ts`);t.includes(`/`)&&await(0,f.mkdir)((0,p.beforeLast)(a,`/`),{recursive:!0}),!n&&await l.FileSystem.fileExists(a)&&l.Logger.error(`ERORR: ${t} controller already exists`);let o=await(0,f.readFile)(i,`utf-8`);o=o.replace(/{{ name }}/g,t),await(0,f.writeFile)(a,o),l.Logger.split(`INFO: Controller Created`,l.Logger.log(h.default.basename(a),`gray`,!1))}makeResource(){l.Logger.success(`Resource support is not yet available`)}async makeMigration(){let e=this.argument(`name`),t=(0,m.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=E.guess(e);a=t[0],i=!!t[1]}let o=h.default.join(r,this.getMigrationStubName(a,i)),s=await(0,f.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(h.default.dirname(n)),await(0,f.writeFile)(n,s),l.Logger.split(`INFO: Migration Created`,l.Logger.log(h.default.basename(n),`gray`,!1))}makeFactory(){l.Logger.success(`Factory support is not yet available`)}makeCommand(){l.Logger.success(`Musket command creation 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,f.mkdir)((0,p.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=h.default.join(i,`dist/stubs/model-${e}.stub`),o=await(0,f.readFile)(a,`utf-8`);o=o.replace(/{{ name }}/g,t),await(0,f.writeFile)(r,o),l.Logger.split(`INFO: ${t} Model Created`,l.Logger.log(h.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,f.mkdir)((0,p.beforeLast)(n,`/`),{recursive:!0}),!t&&await l.FileSystem.fileExists(n)&&l.Logger.error(`ERORR: ${e} view already exists`),await(0,f.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}},O=class extends S{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,f.mkdir)(database_path(),{recursive:!0}),await l.FileSystem.fileExists(database_path(`db.sqlite`))||await(0,f.writeFile)(database_path(`db.sqlite`),``))}},k=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 A(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,y.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,v.fork)((0,y.join)(e,t),r,o)},c=e.dir||(0,y.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 j=process.env.NODE_ENV||`development`;let M=j===`development`?`.h3ravel/serve`:`dist`;process.env.DIST_DIR&&(M=process.env.DIST_DIR);const N={outDir:M,entry:[`src/**/*.ts`],format:[`esm`],target:`node22`,sourcemap:j===`development`,minify:!!process.env.DIST_MINIFY,clean:!0,shims:!0,copy:[{from:`public`,to:M},`src/resources`,`src/database`],env:j===`development`?{NODE_ENV:j,DIST_DIR:M}:{},watch:j===`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,_.existsSync)(h.default.join(M,n))&&await(0,f.rm)(h.default.join(M,n),{recursive:!0})}})},plugins:j===`development`&&process.env.CLI_BUILD!==`true`?[A({env:Object.assign({},process.env,{NODE_ENV:j,DIST_DIR:M}),execArgv:[`-r`,`source-map-support/register`],allowRestarts:!1,input:process.cwd()+`/src/server.ts`})]:[]};var P=N,F=class e{commands=[];constructor(e,t){this.app=e,this.kernel=t}async build(){return this.loadBaseCommands(),await this.loadDiscoveredCommands(),this.initialize()}loadBaseCommands(){[new D(this.app,this.kernel),new T(this.app,this.kernel),new O(this.app,this.kernel),new x(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,f.glob)(n)){let n=h.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(k.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`]};g.program.name(`musket`).version(`${e}\n${t}`).description(w).addOption(new g.Option(n.quiet[0],n.quiet[1]).implies({silent:!0})).addOption(new g.Option(n.silent[0],n.silent[1]).implies({quiet:!0})).addOption(new g.Option(n.verbose[0],n.verbose[1]).choices([`1`,`2`,`3`])).addOption(new g.Option(n.lock[0],n.lock[1])).action(async()=>{let e=new T(this.app,this.kernel);e.setInput(g.program.opts(),g.program.args,g.program.registeredArguments,{},g.program),e.handle()}),g.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?g.program:g.program.command(t.baseCommand).description(t.description??``).addOption(new g.Option(n.quiet[0],n.quiet[1]).implies({silent:!0})).addOption(new g.Option(n.silent[0],n.silent[1]).implies({quiet:!0})).addOption(new g.Option(n.verbose[0],n.verbose[1]).choices([`1`,`2`,`3`])).addOption(new g.Option(n.lock[0],n.lock[1])).action(async()=>{r.setInput(e.opts(),e.args,e.registeredArguments,t,g.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=g.program.command(`${t.baseCommand}:${e.name}`).description(e.description||``).addOption(new g.Option(n.quiet[0],n.quiet[1]).implies({silent:!0})).addOption(new g.Option(n.silent[0],n.silent[1]).implies({quiet:!0})).addOption(new g.Option(n.verbose[0],n.verbose[1]).choices([`1`,`2`,`3`])).addOption(new g.Option(n.lock[0],n.lock[1])).action(async()=>{r.setInput(i.opts(),i.args,i.registeredArguments,e,g.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=g.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,g.program),await r.handle()})}}return g.program.hook(`preAction`,async(e,t)=>{t.name()!==`fire`&&await(0,b.build)({...P,watch:!1,plugins:[]})}),g.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()}},I=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 F.parse(this),process.exit(0)}async loadRequirements(){this.cwd=h.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(h.default.join(this.modulePath,`package.json`))}catch{this.modulePackage={version:`N/A`}}try{this.consolePackage=await import(h.default.join(this.consolePath,`package.json`))}catch{this.consolePackage={version:`N/A`}}return this}},L=class extends c.ServiceProvider{static priority=992;static console=!0;console=!0;register(){}boot(){I.init(this.app),process.on(`SIGINT`,()=>{process.exit(0)}),process.on(`SIGTERM`,()=>{process.exit(0)})}},R=class{async fire(){let e=process.env.DIST_DIR??`/.h3ravel/serve/`,t=[],n=new c.Application(process.cwd()),r=base_path(h.default.join(e,`bootstrap/providers.js`));t.push(...(await import(r)).default),t.push(L),await n.quickStartup(t,[`CoreServiceProvider`])}};new R().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
|
|
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
|
|
27
|
+
`;const D=String.raw`
|
|
25
28
|
_ _ _____ _
|
|
26
29
|
| | | |___ / _ __ __ ___ _____| |
|
|
27
30
|
| |_| | |_ \| '__/ _ \ \ / / _ \ |
|
|
28
31
|
| _ |___) | | | (_| |\ V / __/ |
|
|
29
32
|
|_| |_|____/|_| \__,_| \_/ \___|_|
|
|
30
33
|
|
|
31
|
-
`;var
|
|
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(
|
|
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())}},
|
|
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=
|
|
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
|
|
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/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
|
-
|
|
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/",
|
|
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;
|