Skip to content

Commit 14b6e51

Browse files
chore: adopt create engine's 'new' mode (#1766)
## PR Checklist - [x] Addresses an existing open issue: fixes #1754; fixes #1763 - [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 Corresponding `create` PR: JoshuaKGoldberg/bingo#48 Adds `src/` directory creation as part of Block `initialize()`s. Hooks up `mode: "new"` for the new runtime mode setting. As a result, `createStructure` no longer needs a manual `src: createSrc()`. I've been testing this with: ```shell gh repo delete JoshuaKGoldberg/cta-create-testing-1 --yes; rm -rf ./cta-*; CTA_CREATE_ENGINE=true node ~/repos/create-typescript-app/bin/index.js --base common --owner JoshuaKGoldberg --repository cta-create-testing-1 --title "CTA Create Testing" --description "Testing, will delete."; code cta-create-testing-1 ``` 💖
1 parent fd67f75 commit 14b6e51

23 files changed

+292
-133
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Thanks! 💖
9595
<td align="center" valign="top" width="14.28%"><a href="https://blog.johnnyreilly.com/"><img src="https://avatars.githubusercontent.com/u/1010525?v=4?s=100" width="100px;" alt="John Reilly"/><br /><sub><b>John Reilly</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/create-typescript-app/commits?author=johnnyreilly" title="Code">💻</a> <a href="#ideas-johnnyreilly" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=author%3Ajohnnyreilly" title="Bug reports">🐛</a> <a href="#maintenance-johnnyreilly" title="Maintenance">🚧</a> <a href="https://github.com/JoshuaKGoldberg/create-typescript-app/commits?author=johnnyreilly" title="Documentation">📖</a> <a href="#tool-johnnyreilly" title="Tools">🔧</a></td>
9696
</tr>
9797
<tr>
98-
<td align="center" valign="top" width="14.28%"><a href="http://www.joshuakgoldberg.com"><img src="https://avatars.githubusercontent.com/u/3335181?v=4?s=100" width="100px;" alt="Josh Goldberg"/><br /><sub><b>Josh Goldberg</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=author%3AJoshuaKGoldberg" title="Bug reports">🐛</a> <a href="https://github.com/JoshuaKGoldberg/create-typescript-app/commits?author=JoshuaKGoldberg" title="Code">💻</a> <a href="#maintenance-JoshuaKGoldberg" title="Maintenance">🚧</a> <a href="https://github.com/JoshuaKGoldberg/create-typescript-app/pulls?q=is%3Apr+reviewed-by%3AJoshuaKGoldberg" title="Reviewed Pull Requests">👀</a> <a href="#tool-JoshuaKGoldberg" title="Tools">🔧</a> <a href="https://github.com/JoshuaKGoldberg/create-typescript-app/commits?author=JoshuaKGoldberg" title="Documentation">📖</a> <a href="#infra-JoshuaKGoldberg" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/JoshuaKGoldberg/create-typescript-app/commits?author=JoshuaKGoldberg" title="Tests">⚠️</a> <a href="#ideas-JoshuaKGoldberg" title="Ideas, Planning, & Feedback">🤔</a></td>
98+
<td align="center" valign="top" width="14.28%"><a href="http://www.joshuakgoldberg.com"><img src="https://avatars.githubusercontent.com/u/3335181?v=4?s=100" width="100px;" alt="Josh Goldberg"/><br /><sub><b>Josh Goldberg</b></sub></a><br /><a href="#tool-JoshuaKGoldberg" title="Tools">🔧</a></td>
9999
<td align="center" valign="top" width="14.28%"><a href="https://twitter.com/Jolg42"><img src="https://avatars.githubusercontent.com/u/1328733?v=4?s=100" width="100px;" alt="Joël Galeran"/><br /><sub><b>Joël Galeran</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/create-typescript-app/commits?author=jolg42" title="Code">💻</a></td>
100100
<td align="center" valign="top" width="14.28%"><a href="https://github.com/jaas666"><img src="https://avatars.githubusercontent.com/u/30204147?v=4?s=100" width="100px;" alt="Juan A."/><br /><sub><b>Juan A.</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/create-typescript-app/commits?author=jaas666" title="Code">💻</a> <a href="https://github.com/JoshuaKGoldberg/create-typescript-app/commits?author=jaas666" title="Documentation">📖</a></td>
101101
<td align="center" valign="top" width="14.28%"><a href="https://kristo-baricevic.github.io/"><img src="https://avatars.githubusercontent.com/u/108290619?v=4?s=100" width="100px;" alt="Kristo Baricevic"/><br /><sub><b>Kristo Baricevic</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/create-typescript-app/commits?author=kristo-baricevic" title="Code">💻</a></td>

package.json

+2-2
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.1",
48+
"create": "0.1.0-alpha.3",
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.1",
83+
"create-testers": "0.1.0-alpha.3",
8484
"cspell": "8.16.1",
8585
"eslint": "9.16.0",
8686
"eslint-plugin-jsdoc": "50.6.0",

pnpm-lock.yaml

+21-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bin/promptForMode.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import path from "node:path";
55
import * as process from "node:process";
66

77
import { logLine } from "../shared/cli/lines.js";
8+
import { isUsingCreateEngine } from "../shared/isUsingCreateEngine.js";
89
import { filterPromptCancel } from "../shared/prompts.js";
910
import { Mode, PromptedOptions } from "../shared/types.js";
1011

@@ -41,7 +42,7 @@ export async function promptForMode(
4142

4243
const dir = await fs.readdir(".");
4344

44-
if (dir.length === 0) {
45+
if (dir.length === 0 && !isUsingCreateEngine()) {
4546
const mode = filterPromptCancel(
4647
(await prompts.select({
4748
message: chalk.blue("How would you like to use the template?"),

src/create/createWithOptions.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { $ } from "execa";
22

3+
import { runCreateEnginePreset } from "../next/runCreateEnginePreset.js";
34
import {
45
LabeledSpinnerTask,
56
withSpinner,
@@ -18,23 +19,26 @@ import { writeReadme } from "../steps/writeReadme/index.js";
1819
import { writeStructure } from "../steps/writing/writeStructure.js";
1920

2021
export async function createWithOptions({ github, options }: GitHubAndOptions) {
22+
if (isUsingCreateEngine()) {
23+
await withSpinner("Creating repository", async () => {
24+
await runCreateEnginePreset(options);
25+
});
26+
return { sentToGitHub: false };
27+
}
28+
2129
await withSpinners("Creating repository structure", [
2230
[
2331
"Writing structure",
2432
async () => {
2533
await writeStructure(options);
2634
},
2735
],
28-
...(isUsingCreateEngine()
29-
? []
30-
: [
31-
[
32-
"Writing README.md",
33-
async () => {
34-
await writeReadme(options);
35-
},
36-
] satisfies LabeledSpinnerTask<void>,
37-
]),
36+
[
37+
"Writing README.md",
38+
async () => {
39+
await writeReadme(options);
40+
},
41+
] satisfies LabeledSpinnerTask<void>,
3842
]);
3943

4044
if (!options.excludeAllContributors && !options.skipAllContributorsApi) {

src/next/base.ts

+4
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ export const base = createBase({
172172
version,
173173
};
174174
},
175+
template: {
176+
owner: "JoshuaKGoldberg",
177+
repository: "create-typescript-app",
178+
},
175179
});
176180

177181
export type BaseOptions = BaseOptionsFor<typeof base>;

src/next/blocks/blockAllContributors.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createSoloWorkflowFile } from "../../steps/writing/creation/dotGitHub/createSoloWorkflowFile.js";
22
import { base } from "../base.js";
33
import { blockPrettier } from "./blockPrettier.js";
4+
import { CommandPhase } from "./phases.js";
45

56
export const blockAllContributors = base.createBlock({
67
about: {
@@ -13,10 +14,6 @@ export const blockAllContributors = base.createBlock({
1314
ignores: ["/.all-contributorsrc"],
1415
}),
1516
],
16-
commands:
17-
options.login === "JoshuaKGoldberg"
18-
? [`npx -y all-contributors-cli add JoshuaKGoldberg tool`]
19-
: undefined,
2017
files: {
2118
".all-contributorsrc": JSON.stringify({
2219
badgeTemplate:
@@ -55,6 +52,15 @@ export const blockAllContributors = base.createBlock({
5552
},
5653
},
5754
},
55+
scripts: [
56+
{
57+
commands: [
58+
`npx -y all-contributors-cli generate`,
59+
`npx -y all-contributors-cli add ${options.owner} code,content,docs,ideas,infra,maintenance,projectManagement,tool`,
60+
],
61+
phase: CommandPhase.Process,
62+
},
63+
],
5864
};
5965
},
6066
});

src/next/blocks/blockCSpell.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { blockPackageJson } from "./blockPackageJson.js";
77
import { blockVSCode } from "./blockVSCode.js";
88
import { getPackageDependencies } from "./packageData.js";
99

10+
const filesGlob = `"**" ".github/**/*"`;
11+
1012
export const blockCSpell = base.createBlock({
1113
about: {
1214
name: "CSpell",
@@ -46,7 +48,7 @@ export const blockCSpell = base.createBlock({
4648
properties: {
4749
devDependencies: getPackageDependencies("cspell"),
4850
scripts: {
49-
"lint:spelling": 'cspell "**" ".github/**/*"',
51+
"lint:spelling": `cspell ${filesGlob}`,
5052
},
5153
},
5254
}),
@@ -65,12 +67,6 @@ export const blockCSpell = base.createBlock({
6567
...(words.length && { words: words.sort() }),
6668
}),
6769
},
68-
package: {
69-
devDependencies: getPackageDependencies("cspell"),
70-
scripts: {
71-
"lint:spelling": 'cspell "**" ".github/**/*"',
72-
},
73-
},
7470
};
7571
},
7672
});

src/next/blocks/blockESLint.ts

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js";
99
import { blockPackageJson } from "./blockPackageJson.js";
1010
import { blockVSCode } from "./blockVSCode.js";
1111
import { getPackageDependencies } from "./packageData.js";
12+
import { CommandPhase } from "./phases.js";
1213

1314
const zRuleOptions = z.union([
1415
z.literal("error"),
@@ -197,6 +198,12 @@ export default tseslint.config(
197198
${extensionLines.join(",")}
198199
);`,
199200
},
201+
scripts: [
202+
{
203+
commands: ["pnpm lint --fix"],
204+
phase: CommandPhase.Process,
205+
},
206+
],
200207
};
201208
},
202209
});

src/next/blocks/blockExampleFiles.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { z } from "zod";
2+
3+
import { base } from "../base.js";
4+
5+
export const blockExampleFiles = base.createBlock({
6+
about: {
7+
name: "Example Files",
8+
},
9+
addons: {
10+
files: z.record(z.string()).default({}),
11+
},
12+
initialize({ addons }) {
13+
return {
14+
files: {
15+
src: addons.files,
16+
},
17+
};
18+
},
19+
// TODO: Make produce() optional (so base is generic on its definition)
20+
produce() {
21+
return {};
22+
},
23+
});

src/next/blocks/blockPackageJson.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import sortPackageJson from "sort-package-json";
22
import { z } from "zod";
33

44
import { base } from "../base.js";
5+
import { CommandPhase } from "./phases.js";
56

67
export const blockPackageJson = base.createBlock({
78
about: {
89
name: "Package JSON",
910
},
1011
addons: {
12+
cleanupCommands: z.array(z.string()).default([]),
1113
// TODO: Find a zod package for this?
1214
properties: z
1315
.intersection(
@@ -24,12 +26,6 @@ export const blockPackageJson = base.createBlock({
2426
},
2527
produce({ addons, options }) {
2628
return {
27-
commands: [
28-
{
29-
phase: 0, // TODO: ???
30-
script: "pnpm i",
31-
},
32-
],
3329
files: {
3430
"package.json": sortPackageJson(
3531
JSON.stringify({
@@ -77,6 +73,12 @@ export const blockPackageJson = base.createBlock({
7773
}),
7874
),
7975
},
76+
scripts: [
77+
{
78+
commands: ["pnpm install", ...addons.cleanupCommands],
79+
phase: CommandPhase.Install,
80+
},
81+
],
8082
};
8183
},
8284
});

src/next/blocks/blockPnpmDedupe.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,14 @@ export const blockPnpmDedupe = base.createBlock({
3030
],
3131
}),
3232
blockPackageJson({
33+
cleanupCommands: ["pnpm dedupe --offline"],
3334
properties: {
3435
scripts: {
3536
"lint:packages": "pnpm dedupe --check",
3637
},
3738
},
3839
}),
3940
],
40-
commands: [
41-
{
42-
phase: 1,
43-
script: "pnpm dedupe",
44-
},
45-
],
4641
};
4742
},
4843
});

0 commit comments

Comments
 (0)