-
-
Notifications
You must be signed in to change notification settings - Fork 416
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add feature about custom options to use own tsconfig
- Loading branch information
Showing
2 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
interface Options { | ||
Project: 'project', | ||
}; | ||
interface CustomOptions extends Record<Options[keyof Options], string> {}; | ||
|
||
const ARGS_ACCESS_NUM = 2; | ||
const OPTIONS = { | ||
Project: 'project', | ||
} as const satisfies Options; | ||
const OPTIONS_PREFIX = '--'; | ||
|
||
export function createCliOptions(): CustomOptions | undefined { | ||
const args = structuredClone(process.argv); | ||
let parsedOptions: CustomOptions | undefined | ||
args.slice(ARGS_ACCESS_NUM).forEach((arg, i) => { | ||
const options = Object.values(OPTIONS) | ||
const optionStrings = options.map(t => `${OPTIONS_PREFIX}${t}`); | ||
if (!optionStrings.includes(arg)) { | ||
return; | ||
} | ||
if (args[i + 1] == null) { | ||
return; | ||
} | ||
const findIndex = optionStrings.findIndex(s => s === arg); | ||
if (findIndex !== -1 && !!options[findIndex]) { | ||
parsedOptions = { | ||
...(parsedOptions ?? {}), | ||
[options[findIndex]]: arg[i + 1], | ||
}; | ||
// required to remove custom options and value for executing runTsc() | ||
process.argv = process.argv.filter((_, j) => j !== i + ARGS_ACCESS_NUM && j !== i + ARGS_ACCESS_NUM + 1); | ||
} | ||
args.slice(1); | ||
}); | ||
return parsedOptions; | ||
}; |