Skip to content

Commit cb5cfa0

Browse files
chore: use create's applyFilesToSystem with create engine (#1762)
## PR Checklist - [x] Addresses an existing open issue: fixes #1761 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md) were taken ## Overview Uses the (temporarily exported) `applyFilesToSystem` and `createWritingFileSystem` APIs from `create`. 💖
1 parent 4849839 commit cb5cfa0

File tree

5 files changed

+38
-33
lines changed

5 files changed

+38
-33
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"@prettier/sync": "^0.5.2",
4646
"all-contributors-for-repository": "^0.3.0",
4747
"chalk": "^5.3.0",
48-
"create": "0.1.0-alpha.0",
48+
"create": "0.1.0-alpha.1",
4949
"execa": "^9.5.1",
5050
"get-github-auth-token": "^0.1.0",
5151
"git-remote-origin-url": "^4.0.0",
@@ -80,7 +80,7 @@
8080
"@vitest/eslint-plugin": "1.1.14",
8181
"c8": "10.1.2",
8282
"console-fail-test": "0.5.0",
83-
"create-testers": "0.1.0-alpha.0",
83+
"create-testers": "0.1.0-alpha.1",
8484
"cspell": "8.16.1",
8585
"eslint": "9.16.0",
8686
"eslint-plugin-jsdoc": "50.6.0",

pnpm-lock.yaml

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/next/blocks/blockPrettier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pnpm format --write
8989
files: {
9090
".husky": {
9191
".gitignore": "_",
92-
"pre-commit": "npx lint-staged",
92+
"pre-commit": ["npx lint-staged", { mode: 0x777 }],
9393
},
9494
".prettierignore": ["/.husky", "/lib", "/pnpm-lock.yaml", ...ignores]
9595
.sort()

src/steps/writing/creation/index.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,12 @@ async function recursivelyFormat(files: CreatedFiles): Promise<Structure> {
5151
const result: Structure = {};
5252

5353
for (const [key, value] of Object.entries(files)) {
54-
switch (typeof value) {
55-
case "object":
56-
result[key] = await recursivelyFormat(value);
57-
break;
58-
case "string":
59-
result[key] = await formatCreatedFile(key, value);
60-
break;
54+
if (Array.isArray(value)) {
55+
result[key] = await formatCreatedFile(key, value[0]);
56+
} else if (typeof value === "string") {
57+
result[key] = await formatCreatedFile(key, value);
58+
} else if (typeof value === "object") {
59+
result[key] = await recursivelyFormat(value);
6160
}
6261
}
6362

src/steps/writing/writeStructure.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { applyFilesToSystem, createWritingFileSystem } from "create";
12
import { $ } from "execa";
23

34
import { isUsingCreateEngine } from "../../shared/isUsingCreateEngine.js";
@@ -6,10 +7,15 @@ import { createStructure } from "./creation/index.js";
67
import { writeStructureWorker } from "./writeStructureWorker.js";
78

89
export async function writeStructure(options: Options) {
9-
await writeStructureWorker(
10-
await createStructure(options, isUsingCreateEngine()),
11-
".",
12-
);
10+
const usingCreateEngine = isUsingCreateEngine();
11+
const structure = await createStructure(options, usingCreateEngine);
12+
13+
if (usingCreateEngine) {
14+
await applyFilesToSystem(structure, createWritingFileSystem(), ".");
15+
return;
16+
}
17+
18+
await writeStructureWorker(structure, ".");
1319

1420
try {
1521
// https://github.com/JoshuaKGoldberg/create-typescript-app/issues/718

0 commit comments

Comments
 (0)