Skip to content

Commit

Permalink
Create command to setup prettier.
Browse files Browse the repository at this point in the history
- Setup inquirer to ask questions about prettier config
- If prettierrc/prettier.js or .prettierignore exists, it will not create any new files.
- Add ts-node key to tsconfig.json to help with node typescript errors.
- Add .prettierignore.template to use to write to .prettierignore.
- Add formatFile to format any files we add to the project.
- Add getProjectDir to get main directory of project.
  • Loading branch information
geekiam23 committed Aug 8, 2023
1 parent 10a496c commit 21771f1
Show file tree
Hide file tree
Showing 4 changed files with 353 additions and 225 deletions.
2 changes: 1 addition & 1 deletion src/util/formatFile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { exec } from "child_process";
import { exec } from 'child_process';

export default async function formatFile(filePath: string) {
exec(`npx prettier --write '${filePath}'`);
Expand Down
12 changes: 7 additions & 5 deletions src/util/getProjectDir.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import fs from "fs-extra";
import path from "path";
import fs from 'fs-extra';
import path from 'path';

export default async function getProjectDir(base: string = process.cwd()): Promise<string> {
export default async function getProjectDir(
base: string = process.cwd(),
): Promise<string> {
let previous = null;
let dir = base;

do {
try {
// This will throw if there is no package.json in the directory
// eslint-disable-next-line no-await-in-loop
await fs.readFile(path.join(dir, "package.json"));
await fs.readFile(path.join(dir, 'package.json'));

// if didn't throw, package.json exists, return dir
return dir;
Expand All @@ -22,6 +24,6 @@ export default async function getProjectDir(base: string = process.cwd()): Promi
} while (dir !== previous);

throw new Error(
"No project found. Ensure you are inside of a project directory with a package.json file."
'No project found. Ensure you are inside of a project directory with a package.json file.',
);
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"module": "ES2020",
"moduleResolution": "node",
"strict": true,
"moduleResolution": "Node",
"sourceMap": true,
"outDir": "./build",
"skipLibCheck": true,
Expand Down
Loading

0 comments on commit 21771f1

Please sign in to comment.