File tree Expand file tree Collapse file tree 2 files changed +53
-1
lines changed
Expand file tree Collapse file tree 2 files changed +53
-1
lines changed Original file line number Diff line number Diff line change 1+ import { Command } from '@h3ravel/musket'
2+ import { resolve } from 'path'
3+ import { writeFile } from 'fs/promises'
4+
5+ export class MakeCommand extends Command {
6+ protected signature = `make:command
7+ {name : name of the command to create}
8+ `
9+
10+ protected description = 'Creates a new console command class.'
11+
12+ async handle ( ) {
13+ const name = String ( this . argument ( 'name' ) )
14+ . replace ( / \s + / g, '' )
15+ . replace ( / \. t s $ / , '' ) . trim ( )
16+
17+ if ( ! name ) return void this . error ( 'Command name is required' )
18+
19+ const stubContent = this . stub ( name )
20+ const filePath = resolve ( process . cwd ( ) , 'src' , `app/console/commands/${ name } .ts` )
21+
22+ await writeFile ( filePath , stubContent , { flag : 'wx' } )
23+ this . success ( `Command ${ name } created successfully at ${ filePath } ` )
24+ }
25+
26+ stub ( name : string ) {
27+ const signature = `app:${ name . toLowerCase ( ) } `
28+ const description = `Description for ${ signature } command`
29+
30+ const stub = [
31+ 'import { Command } from \'@h3ravel/musket\'' ,
32+ '' ,
33+ `export class ${ name } extends Command {` ,
34+ ` signature = '${ signature } '` ,
35+ '' ,
36+ ` description = '${ description } '` ,
37+ '' ,
38+ ' async handle () {' ,
39+ ' // Command logic goes here' ,
40+ ' }' ,
41+ '}' ,
42+ ]
43+
44+ return stub . join ( '\n' )
45+ }
46+ }
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { ArkstackConsoleApp } from './app'
66import { BuildCommand } from './commands/BuildCommand'
77import { DevCommand } from './commands/DevCommand'
88import { Kernel } from '@h3ravel/musket'
9+ import { MakeCommand } from './commands/MakeCommand'
910import { MakeController } from './commands/MakeController'
1011import { MakeFactoryCommand } from './commands/MakeFactoryCommand'
1112import { MakeFullResource } from './commands/MakeFullResource'
@@ -66,8 +67,13 @@ export const runConsoleKernel = async (options: RunConsoleOptions = {}) => {
6667 MigrateCommand ,
6768 ModelsSyncCommand ,
6869 SeedCommand ,
70+ MakeCommand
71+ ] ,
72+ discoveryPaths : [
73+ join ( process . cwd ( ) , 'src' , 'app/console/commands/*.ts' ) ,
74+ join ( process . cwd ( ) , 'src' , 'app/console/commands/*.js' ) ,
75+ join ( process . cwd ( ) , 'src' , 'app/console/commands/*.mjs' ) ,
6976 ] ,
70- discoveryPaths : [ join ( process . cwd ( ) , 'src/app/console/commands/*.ts' ) ] ,
7177 exceptionHandler ( exception ) {
7278 throw exception
7379 } ,
You can’t perform that action at this time.
0 commit comments