@@ -3,9 +3,29 @@ import fs from 'fs'
33import path from 'path'
44import { ModuleArgv } from '../modules'
55const moduleArgv = new ModuleArgv ( )
6- const args = moduleArgv . getNotFormatted ( )
6+ const arg = moduleArgv . getNotFormatted ( ) [ 0 ]
77const paths = fs . readdirSync ( path . join ( __dirname , '..' , 'scripts' ) )
8- const scripts = [ ...paths . map ( ( script ) => `--${ script . split ( '.script' ) [ 0 ] } ` ) ]
9- const arg = args . filter ( ( arg ) => scripts . includes ( arg ) ) [ 0 ]
10- if ( typeof arg !== 'string' ) throw new Error ( 'No script' )
11- require ( `../scripts/${ arg . replace ( '--' , '' ) } .script` )
8+
9+ function createTeamNamesFromFile ( str : string ) {
10+ const [ filename ] = str . split ( '.' )
11+ const firstLetters = filename
12+ . split ( '-' )
13+ . map ( ( word ) => word [ 0 ] )
14+ . join ( '' )
15+ const hyphenated = `--${ filename } `
16+ const short = `-${ firstLetters } `
17+ return { [ hyphenated ] : str , [ short ] : str }
18+ }
19+
20+ const arrayCommands = paths . map ( ( path ) => ( {
21+ ...createTeamNamesFromFile ( path ) ,
22+ } ) )
23+
24+ const commands = arrayCommands . reduce ( ( flat , command ) => {
25+ return { ...flat , ...command }
26+ } , { } )
27+
28+ const command = commands [ arg ]
29+
30+ if ( typeof command === 'undefined' ) throw new Error ( 'No script' )
31+ require ( `../scripts/${ commands [ arg ] } ` )
0 commit comments