@@ -10,6 +10,9 @@ const COMMANDS_DIR = join(BASE_PATH, 'src/app/commands');
1010const EVENTS_DIR = join ( BASE_PATH , 'src/app/events' ) ;
1111const LOCALES_DIR = join ( BASE_PATH , 'src/app/locales' ) ;
1212
13+ const formatPath = ( path : string ) =>
14+ path . replace ( process . cwd ( ) , '.' ) . replace ( / \\ / g, '/' ) ;
15+
1316export async function generateCommand ( name : string , customPath ?: string ) {
1417 const cmdPath = join ( customPath || COMMANDS_DIR , name ) ;
1518 if ( ! existsSync ( cmdPath ) ) await mkdir ( cmdPath , { recursive : true } ) ;
@@ -39,19 +42,19 @@ export const message: MessageCommand = async (ctx) => {
3942
4043 console . log (
4144 colors . green (
42- `Command ${ colors . magenta ( name ) } created at ${ colors . blue ( cmdPath ) } /command.ts` ,
45+ `Command ${ colors . magenta ( name ) } created at ${ colors . blue ( formatPath ( cmdPath ) ) } /command.ts` ,
4346 ) ,
4447 ) ;
4548}
4649
4750export async function generateEvent ( name : string , customPath ?: string ) {
4851 const eventPath = join ( customPath || EVENTS_DIR , name ) ;
49- if ( ! existsSync ) await mkdir ( eventPath , { recursive : true } ) ;
52+ if ( ! existsSync ( eventPath ) ) await mkdir ( eventPath , { recursive : true } ) ;
5053
5154 let filename = 'event.ts' ;
5255 if ( existsSync ( join ( eventPath , filename ) ) ) {
5356 const count = ( await readdir ( eventPath ) ) . length ;
54- filename = `${ String ( count ) . padStart ( 2 , '0' ) } _${ filename } .ts ` ;
57+ filename = `${ String ( count ) . padStart ( 2 , '0' ) } _${ filename } ` ;
5558 }
5659
5760 const eventFile = `
@@ -64,7 +67,7 @@ export default async function on${name[0].toUpperCase() + name.slice(1)}() {
6467
6568 console . log (
6669 colors . green (
67- `Event ${ colors . magenta ( name ) } created at ${ colors . blue ( eventPath ) } /${ colors . magenta ( filename ) } ` ,
70+ `Event ${ colors . magenta ( name ) } created at ${ colors . blue ( formatPath ( eventPath ) ) } /${ colors . magenta ( filename ) } ` ,
6871 ) ,
6972 ) ;
7073}
@@ -74,7 +77,11 @@ export async function generateLocale(
7477 commandName : string ,
7578 customPath ?: string ,
7679) {
77- if ( ! Locale [ locale ] || / ^ \d + $ / . test ( locale ) ) {
80+ const localeNames = Object . fromEntries (
81+ Object . entries ( Locale ) . map ( ( [ k , v ] ) => [ v , k ] ) ,
82+ ) ;
83+
84+ if ( ! localeNames [ locale ] ) {
7885 panic ( `Invalid locale: ${ locale } ` ) ;
7986 }
8087
@@ -106,7 +113,7 @@ export async function generateLocale(
106113 console . log (
107114 colors . green (
108115 `Locale file for ${ colors . magenta ( commandName ) } created at ${ colors . blue (
109- localePath ,
116+ formatPath ( localePath ) ,
110117 ) } /${ colors . magenta ( `${ commandName } .json` ) } `,
111118 ) ,
112119 ) ;
0 commit comments