diff --git a/bin/belt b/bin/belt index 2770033..f96a09a 100755 --- a/bin/belt +++ b/bin/belt @@ -1,3 +1,3 @@ #!/usr/bin/env bash -node -r ts-node/register ./react-native/react-native.ts "$@" +yarn ts-node ./src/cli.ts "$@" diff --git a/index.ts b/index.ts deleted file mode 100755 index e67520d..0000000 --- a/index.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { program } from "commander"; - -program - .name("thoughtbelt") - .description( - "Perform project setup and redundant tasks without your pants falling down!" - ) - .command( - "react-native [options]", - "Perform a React Native task", - { executableFile: "react-native/react-native.ts" } - ) - .alias("rn") - .alias("expo") - .showHelpAfterError() - .parse(); diff --git a/package.json b/package.json index f499106..c1a1a44 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "1.0.0", "description": "Monorepo for project bootstrapping CLIs", "main": "index.js", + "type": "module", "scripts": { "belt": "bin/belt", "test": "echo \"Error: no test specified\" && exit 1" diff --git a/react-native/eslint.ts b/react-native/eslint.ts deleted file mode 100755 index 22cd7ba..0000000 --- a/react-native/eslint.ts +++ /dev/null @@ -1 +0,0 @@ -console.log('ESLint!') diff --git a/react-native/prettier.ts b/react-native/prettier.ts deleted file mode 100755 index 828c5cf..0000000 --- a/react-native/prettier.ts +++ /dev/null @@ -1 +0,0 @@ -console.log("Prettier!"); diff --git a/react-native/react-native.ts b/react-native/react-native.ts deleted file mode 100644 index 24cbed0..0000000 --- a/react-native/react-native.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { program } from "commander"; - -console.log("React Native 🎉"); - -program - .name("thoughtbelt") - .description( - "Perform React Native and Expo setup and redundant tasks without your pants falling down!" - ) - .command("eslint", "Configure ESLint", { executableFile: "eslint.ts" }) - .command("prettier", "Configure Prettier", { executableFile: "prettier.ts" }) - .showHelpAfterError() - .parse(); diff --git a/src/cli.ts b/src/cli.ts new file mode 100644 index 0000000..ce238e1 --- /dev/null +++ b/src/cli.ts @@ -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(); diff --git a/src/commands/eslint.ts b/src/commands/eslint.ts new file mode 100755 index 0000000..5f8c481 --- /dev/null +++ b/src/commands/eslint.ts @@ -0,0 +1,3 @@ +export default function runEslint() { + console.log("ESLint!"); +} diff --git a/src/commands/prettier.ts b/src/commands/prettier.ts new file mode 100755 index 0000000..5d3bb16 --- /dev/null +++ b/src/commands/prettier.ts @@ -0,0 +1,3 @@ +export default function runPrettier() { + console.log("Prettier!"); +} diff --git a/src/util/buildAction.ts b/src/util/buildAction.ts new file mode 100644 index 0000000..4013fef --- /dev/null +++ b/src/util/buildAction.ts @@ -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); + }; +} diff --git a/tsconfig.json b/tsconfig.json index d2ba263..d945246 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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": ["./**/*"] }