Skip to content
This repository was archived by the owner on Mar 10, 2023. It is now read-only.

Commit 7de52e9

Browse files
authored
fix: add option to keep default dev tools (#25)
1 parent 20e19b4 commit 7de52e9

File tree

5 files changed

+60
-32
lines changed

5 files changed

+60
-32
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ yarn create notion-app --ts
2626

2727
`create-notion-app` comes with the following options:
2828

29-
| Option | Description |
30-
| -------------------------- | ---------------------------------- |
31-
| **-t, --ts, --typescript** | Initialize as a TypeScript project |
29+
| Option | Description |
30+
| -------------------------- | ------------------------------------------------------------------------- |
31+
| **-t, --ts, --typescript** | Initialize as a TypeScript project |
32+
| **-d, --devtool** | Use default devtools (prettier, husky, lint-staged, commitlint, & cspell) |
3233

3334
## Contributing
3435

cspell.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
"hgcheck",
66
"hgignore",
77
"intellij",
8+
"minh",
89
"mkdocs",
910
"nbundle",
1011
"nolookalikes",
1112
"npmignore",
13+
"phuc",
1214
"pnpm"
1315
]
1416
}

src/create.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import {
77
formatProject,
88
installDependencies,
99
tryGitInit,
10+
toJson,
1011
} from "./utils";
1112
import path from "path";
1213

1314
export interface CreateOptions {
1415
typescript?: boolean;
16+
devtool?: boolean;
1517
}
1618

1719
export default async function create(
@@ -34,18 +36,23 @@ export default async function create(
3436
branch: "main",
3537
});
3638

37-
await formatProject(projectDirectory);
39+
await formatProject(projectDirectory, options);
40+
41+
if ((await tryGitInit(projectDirectory)) && options.devtool) {
42+
const pkgJsonPath = path.join(projectDirectory, "package.json");
43+
const pkg = JSON.parse(await fs.readFile(pkgJsonPath, "utf8"));
44+
if (pkg.devDependencies.husky) {
45+
pkg.scripts.prepare = "husky install";
46+
await fs.writeFile(pkgJsonPath, toJson(pkg), "utf8");
47+
}
48+
}
3849

3950
console.log("Installing packages. This might take up to a few minutes.");
4051

4152
await installDependencies(projectDirectory);
4253

4354
console.log();
4455

45-
if (await tryGitInit(projectDirectory)) {
46-
console.log("Initialized a git repository.\n");
47-
}
48-
4956
const packageManager = "yarn";
5057
const useYarn = packageManager === "yarn";
5158

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ async function run() {
5252
"initialize as a TypeScript project"
5353
).hideHelp()
5454
)
55+
.option(
56+
"-d, --devtool",
57+
"use default devtools (prettier, husky, lint-staged, commitlint, & cspell)"
58+
)
5559
.action(async (optionalProjectDirectory, opts) => {
5660
let projectDirectory = optionalProjectDirectory;
5761
if (!projectDirectory) {
@@ -68,6 +72,7 @@ async function run() {
6872
}
6973
await create(path.resolve(projectDirectory), {
7074
typescript: opts.ts || opts.typescript,
75+
devtool: opts.devtool,
7176
});
7277
});
7378
await program.parseAsync();

src/utils/format-project.ts

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,55 @@ async function createAppName(): Promise<string> {
1717
throw new Error("Couldn't generate app name.");
1818
}
1919

20-
export async function formatProject(projectDirectory: string): Promise<void> {
20+
export interface FormatProjectOptions {
21+
devtool?: boolean;
22+
}
23+
24+
export async function formatProject(
25+
projectDirectory: string,
26+
options?: FormatProjectOptions
27+
): Promise<void> {
2128
await Promise.all(
2229
[
23-
".github",
24-
".vscode",
25-
".husky",
26-
"commitlint.config.js",
27-
"cspell.json",
2830
"LICENSE",
29-
"lint-staged.config.js",
30-
".prettierignore",
3131
"yarn.lock",
32+
...(options?.devtool
33+
? []
34+
: [
35+
".github",
36+
".vscode",
37+
".husky",
38+
"commitlint.config.js",
39+
"cspell.json",
40+
"lint-staged.config.js",
41+
".prettierignore",
42+
]),
3243
].map((file) =>
3344
fs.rm(path.join(projectDirectory, file), { recursive: true })
3445
)
3546
);
47+
48+
if (options?.devtool) {
49+
const cspellJsonPath = path.join(projectDirectory, "cspell.json");
50+
const cspell = JSON.parse(await fs.readFile(cspellJsonPath, "utf8"));
51+
cspell.words = cspell.words.filter(
52+
(w: string) => !["minh", "phuc"].includes(w)
53+
);
54+
await fs.writeFile(cspellJsonPath, toJson(cspell), "utf8");
55+
}
56+
3657
const name = path.basename(projectDirectory);
3758
const pkgJsonPath = path.join(projectDirectory, "package.json");
3859
const pkg = JSON.parse(await fs.readFile(pkgJsonPath, "utf8"));
3960
pkg.name = await createAppName();
4061
pkg.productName = capitalCase(name);
41-
pkg.devDependencies = Object.fromEntries(
42-
Object.entries(pkg.devDependencies).filter(([key]) =>
43-
key.startsWith("@nbundle/")
44-
)
45-
);
4662
if (pkg.scripts.prepare) delete pkg.scripts.prepare;
47-
await fs.writeFile(
48-
pkgJsonPath,
49-
toJson({
50-
name: pkg.name,
51-
version: pkg.version,
52-
productName: pkg.productName,
53-
description: pkg.description,
54-
...pkg,
55-
}),
56-
"utf8"
57-
);
63+
if (!options?.devtool) {
64+
pkg.devDependencies = Object.fromEntries(
65+
Object.entries(pkg.devDependencies).filter(([key]) =>
66+
key.startsWith("@nbundle/")
67+
)
68+
);
69+
}
70+
await fs.writeFile(pkgJsonPath, toJson(pkg), "utf8");
5871
}

0 commit comments

Comments
 (0)