-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix typescript issues, refactor a bit (#4)
* Fix TypeScript issues Commander can automatically import files for us by specifying 'executableFile' for commands. This unfortunately doesn't work well with TypeScript, which was why we were using `node -r ts-node` to run the CLI instead of `ts-node`. This setup to get commander working was also causing other issues with file imports. This commit updates so we now manually import files for commands, which enables us to revert the less-conventional TypeScript config. * Refactor file structure, update how commands run Since the tool is only React Native for now, it didn't seem necessary to have the 'react-native' directory. Moved to 'src'. Also created utility for importing commands for commander * Run ts-node with esm loader This fixes the issue where we are unable to run packages that only export ES Modules. It's possible we will still run into some issues with this configuration since ESM support is still experimental on the TypeScript side. Relevant issue: TypeStrong/ts-node#1007 ESM loader docs: https://typestrong.org/ts-node/docs/imports/#native-ecmascript-modules
- Loading branch information
Stephen Hanson
authored
May 16, 2023
1 parent
f7d9cc7
commit 0c40068
Showing
11 changed files
with
57 additions
and
38 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
node -r ts-node/register ./react-native/react-native.ts "$@" | ||
yarn ts-node ./src/cli.ts "$@" |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,25 @@ | ||
import { program } from "commander"; | ||
import buildAction from "./util/buildAction"; | ||
|
||
console.log("React Native 🎉"); | ||
|
||
export default function runCli() { | ||
program | ||
.name("thoughtbelt") | ||
.description( | ||
"Perform React Native and Expo setup and redundant tasks without your pants falling down!" | ||
) | ||
|
||
.command("eslint") | ||
.description("Configure ESLint") | ||
.action(buildAction(import("./commands/eslint"))); | ||
|
||
program | ||
.command("prettier") | ||
.description("Configure Prettier") | ||
.action(buildAction(import("./commands/prettier"))); | ||
|
||
program.showHelpAfterError().parse(); | ||
} | ||
|
||
runCli(); |
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,3 @@ | ||
export default function runEslint() { | ||
console.log("ESLint!"); | ||
} |
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,3 @@ | ||
export default function runPrettier() { | ||
console.log("Prettier!"); | ||
} |
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,17 @@ | ||
type AsyncModule = Promise<{ | ||
default: (...args: unknown[]) => void; | ||
}>; | ||
|
||
/** | ||
* builds the action function that is passed to Commander's | ||
* program.action. | ||
* Eg: program.action( | ||
* buildAction(import('./commands/prettier)) | ||
* ) | ||
*/ | ||
export default function buildAction(asyncModule: AsyncModule) { | ||
return async (...args: unknown[]) => { | ||
const module = await asyncModule; | ||
module.default(args); | ||
}; | ||
} |
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 |
---|---|---|
@@ -1,17 +1,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowSyntheticDefaultImports": true, | ||
"lib": ["es2019"], | ||
"target": "es2019", | ||
"module": "commonjs", | ||
"strict": true, | ||
"module": "ES2020", | ||
"moduleResolution": "node", | ||
"noImplicitThis": true, | ||
"noUnusedLocals": true, | ||
"strict": true, | ||
"sourceMap": true, | ||
"outDir": "./build", | ||
"skipLibCheck": true, | ||
"types": ["node"] | ||
}, | ||
"include": ["./**/*"], | ||
"ts-node": { | ||
"esm": true, | ||
"experimentalSpecifierResolution": "node" | ||
}, | ||
"include": ["./**/*"] | ||
} |