import minimist from "minimist" ; import * as path from "path" ; import { CommandArgs } from "./command" ; import { CommandSearcher } from "./commandSearcher" ; import { ConsoleLogger } from "./loggers/consoleLogger" ; import { NameTransformer } from "./nameTransformer" ; import { Runner } from "./runner" ; const argv = minimist ( process . argv . slice ( 2 ) ) ; const commandName = argv . _ [ 0 ] || "help" ; remarks const parseArgsLocation = ( ) => { const cwd = process . cwd ( ) ; const match = /(^.*packages)(\/|\\)(.+)$/ . exec ( cwd ) ; if ( ! match ) { return { directory : cwd } ; } return { directory : match [ 1 ] , repository : match [ 3 ] , } ; } ; const main = async ( ) : Promise < void > => { const args = { commandName , ... parseArgsLocation ( ) , ... argv , } ; const runner = new Runner ( new CommandSearcher ( [ path . join ( __dirname , "commands" ) ] , new NameTransformer ( ) ) ) ; try { const result = await runner . run ( { args : args as CommandArgs , commandName , logger : new ConsoleLogger ( process . stderr , process . stdout ) , } ) ; if ( ! result ) { console . error ( `Could not find command '${ commandName }'...` ) ; return ; } } catch ( error ) { console . error ( error ) ; return ; } } ; main ( ) . catch ( ( error ) => { console . error ( error ) ; } ) ;