import program from "commander" ; import { createTSCompiler } from "./tsCompilerHelpers" ; import stripComments from "./stripCommentsRunner" ; import ignoreErrors from "./ignoreErrorsRunner" ; import ignoreFileErrors from "./ignoreFileErrorsRunner" ; import convertCodebase from "./convertCodebase" ; import checkTypes from "./checkRunner" ; const rootDir = process . cwd ( ) ; const { configJSON } = createTSCompiler ( rootDir ) ; export interface FilePaths { rootDir : string ; include : string [ ] ; exclude : string [ ] ; extensions : string [ ] ; } const filePaths = { rootDir , include : configJSON . config . include , exclude : [ ] , extensions : [ ".ts" , ".tsx" ] } ; program . command ( "strip-comments" ) . option ( "-c, --commit" ) . option ( "--comments <list>" , "A comma-seperated list of comments to strip. Must start with `//`" , ( f ) => f . split ( "," ) ) . action ( ( cmd ) => { console . log ( "Stripping comments from files..." ) ; if ( cmd . comments ) console . log ( "Removing comments: " , cmd . comments ) ; stripComments ( filePaths , cmd . comments , ! ! cmd . commit ) ; } ) ; program . command ( "convert-codebase" ) . option ( "-c, --commit" ) . option ( "--files <list>" , "A comma-seperated list of files to convert" , ( f ) => f . split ( "," ) ) . option ( "--exclude <list>" , "A comma-seperated list of strings to exclude" , ( f ) => f . split ( "," ) ) . action ( ( cmd ) => { console . log ( "Converting the codebase from Flow to Typescript" ) ; const paths = { ... filePaths , exclude : [ ... filePaths . exclude , ... ( cmd . exclude || [ ] ) ] , extensions : [ ".js" , ".jsx" ] } ; console . log ( paths ) ; convertCodebase ( paths , ! ! cmd . commit , cmd . files ) ; } ) ; program . command ( "ignore-errors" ) . option ( "-c, --commit" ) . option ( "--includeJSX" , "Insert ignores into JSX -- may cause runtime changes!" , true ) . option ( "--exclude <list>" , "A comma-seperated list of strings to exclude" , ( f ) => f . split ( "," ) ) . action ( ( cmd ) => { console . log ( "Ignoring Typescript errors..." ) ; const paths = { ... filePaths , exclude : [ ... filePaths . exclude , ... ( cmd . exclude || [ ] ) ] } ; console . log ( paths ) ; ignoreErrors ( paths , ! ! cmd . commit , cmd . includeJSX ) ; } ) ; program . command ( "ignore-file-errors" ) . option ( "-c, --commit" ) . action ( ( cmd ) => { console . log ( "Inserting custom ts-ignore pragmas..." ) ; ignoreFileErrors ( filePaths , ! ! cmd . commit ) ; } ) ; program . command ( "check-types" ) . option ( "-c, --commit" ) . action ( ( ) => { console . log ( "Checking Typescript types and skipping ignored files..." ) ; checkTypes ( filePaths ) ; } ) ; program . parse ( process . argv ) ;