Skip to content

Commit

Permalink
Refactor file structure, update how commands run
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stevehanson committed May 10, 2023
1 parent aa0e634 commit 5ed7cff
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 38 deletions.
2 changes: 1 addition & 1 deletion bin/belt
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

yarn ts-node ./react-native/react-native.ts "$@"
yarn ts-node ./src/cli.ts "$@"
16 changes: 0 additions & 16 deletions index.ts

This file was deleted.

1 change: 0 additions & 1 deletion react-native/eslint.ts

This file was deleted.

1 change: 0 additions & 1 deletion react-native/prettier.ts

This file was deleted.

19 changes: 0 additions & 19 deletions react-native/react-native.ts

This file was deleted.

25 changes: 25 additions & 0 deletions 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();
3 changes: 3 additions & 0 deletions src/commands/eslint.ts
@@ -0,0 +1,3 @@
export default function runEslint() {
console.log("ESLint!");
}
3 changes: 3 additions & 0 deletions src/commands/prettier.ts
@@ -0,0 +1,3 @@
export default function runPrettier() {
console.log("Prettier!");
}
17 changes: 17 additions & 0 deletions 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);
};
}

0 comments on commit 5ed7cff

Please sign in to comment.