Skip to content

Commit

Permalink
chore: adopt create engine's 'new' mode (#1766)
Browse files Browse the repository at this point in the history
## 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/create#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
```

💖
  • Loading branch information
JoshuaKGoldberg authored Dec 13, 2024
1 parent fd67f75 commit 14b6e51
Show file tree
Hide file tree
Showing 23 changed files with 292 additions and 133 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Thanks! 💖
<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>
</tr>
<tr>
<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>
<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>
<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>
<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>
<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>
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@prettier/sync": "^0.5.2",
"all-contributors-for-repository": "^0.3.0",
"chalk": "^5.3.0",
"create": "0.1.0-alpha.1",
"create": "0.1.0-alpha.3",
"execa": "^9.5.1",
"get-github-auth-token": "^0.1.0",
"git-remote-origin-url": "^4.0.0",
Expand Down Expand Up @@ -80,7 +80,7 @@
"@vitest/eslint-plugin": "1.1.14",
"c8": "10.1.2",
"console-fail-test": "0.5.0",
"create-testers": "0.1.0-alpha.1",
"create-testers": "0.1.0-alpha.3",
"cspell": "8.16.1",
"eslint": "9.16.0",
"eslint-plugin-jsdoc": "50.6.0",
Expand Down
40 changes: 21 additions & 19 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/bin/promptForMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import path from "node:path";
import * as process from "node:process";

import { logLine } from "../shared/cli/lines.js";
import { isUsingCreateEngine } from "../shared/isUsingCreateEngine.js";
import { filterPromptCancel } from "../shared/prompts.js";
import { Mode, PromptedOptions } from "../shared/types.js";

Expand Down Expand Up @@ -41,7 +42,7 @@ export async function promptForMode(

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

if (dir.length === 0) {
if (dir.length === 0 && !isUsingCreateEngine()) {
const mode = filterPromptCancel(
(await prompts.select({
message: chalk.blue("How would you like to use the template?"),
Expand Down
24 changes: 14 additions & 10 deletions src/create/createWithOptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { $ } from "execa";

import { runCreateEnginePreset } from "../next/runCreateEnginePreset.js";
import {
LabeledSpinnerTask,
withSpinner,
Expand All @@ -18,23 +19,26 @@ import { writeReadme } from "../steps/writeReadme/index.js";
import { writeStructure } from "../steps/writing/writeStructure.js";

export async function createWithOptions({ github, options }: GitHubAndOptions) {
if (isUsingCreateEngine()) {
await withSpinner("Creating repository", async () => {
await runCreateEnginePreset(options);
});
return { sentToGitHub: false };
}

await withSpinners("Creating repository structure", [
[
"Writing structure",
async () => {
await writeStructure(options);
},
],
...(isUsingCreateEngine()
? []
: [
[
"Writing README.md",
async () => {
await writeReadme(options);
},
] satisfies LabeledSpinnerTask<void>,
]),
[
"Writing README.md",
async () => {
await writeReadme(options);
},
] satisfies LabeledSpinnerTask<void>,
]);

if (!options.excludeAllContributors && !options.skipAllContributorsApi) {
Expand Down
4 changes: 4 additions & 0 deletions src/next/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ export const base = createBase({
version,
};
},
template: {
owner: "JoshuaKGoldberg",
repository: "create-typescript-app",
},
});

export type BaseOptions = BaseOptionsFor<typeof base>;
14 changes: 10 additions & 4 deletions src/next/blocks/blockAllContributors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createSoloWorkflowFile } from "../../steps/writing/creation/dotGitHub/createSoloWorkflowFile.js";
import { base } from "../base.js";
import { blockPrettier } from "./blockPrettier.js";
import { CommandPhase } from "./phases.js";

export const blockAllContributors = base.createBlock({
about: {
Expand All @@ -13,10 +14,6 @@ export const blockAllContributors = base.createBlock({
ignores: ["/.all-contributorsrc"],
}),
],
commands:
options.login === "JoshuaKGoldberg"
? [`npx -y all-contributors-cli add JoshuaKGoldberg tool`]
: undefined,
files: {
".all-contributorsrc": JSON.stringify({
badgeTemplate:
Expand Down Expand Up @@ -55,6 +52,15 @@ export const blockAllContributors = base.createBlock({
},
},
},
scripts: [
{
commands: [
`npx -y all-contributors-cli generate`,
`npx -y all-contributors-cli add ${options.owner} code,content,docs,ideas,infra,maintenance,projectManagement,tool`,
],
phase: CommandPhase.Process,
},
],
};
},
});
10 changes: 3 additions & 7 deletions src/next/blocks/blockCSpell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { blockPackageJson } from "./blockPackageJson.js";
import { blockVSCode } from "./blockVSCode.js";
import { getPackageDependencies } from "./packageData.js";

const filesGlob = `"**" ".github/**/*"`;

export const blockCSpell = base.createBlock({
about: {
name: "CSpell",
Expand Down Expand Up @@ -46,7 +48,7 @@ export const blockCSpell = base.createBlock({
properties: {
devDependencies: getPackageDependencies("cspell"),
scripts: {
"lint:spelling": 'cspell "**" ".github/**/*"',
"lint:spelling": `cspell ${filesGlob}`,
},
},
}),
Expand All @@ -65,12 +67,6 @@ export const blockCSpell = base.createBlock({
...(words.length && { words: words.sort() }),
}),
},
package: {
devDependencies: getPackageDependencies("cspell"),
scripts: {
"lint:spelling": 'cspell "**" ".github/**/*"',
},
},
};
},
});
7 changes: 7 additions & 0 deletions src/next/blocks/blockESLint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { blockGitHubActionsCI } from "./blockGitHubActionsCI.js";
import { blockPackageJson } from "./blockPackageJson.js";
import { blockVSCode } from "./blockVSCode.js";
import { getPackageDependencies } from "./packageData.js";
import { CommandPhase } from "./phases.js";

const zRuleOptions = z.union([
z.literal("error"),
Expand Down Expand Up @@ -197,6 +198,12 @@ export default tseslint.config(
${extensionLines.join(",")}
);`,
},
scripts: [
{
commands: ["pnpm lint --fix"],
phase: CommandPhase.Process,
},
],
};
},
});
Expand Down
23 changes: 23 additions & 0 deletions src/next/blocks/blockExampleFiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { z } from "zod";

import { base } from "../base.js";

export const blockExampleFiles = base.createBlock({
about: {
name: "Example Files",
},
addons: {
files: z.record(z.string()).default({}),
},
initialize({ addons }) {
return {
files: {
src: addons.files,
},
};
},
// TODO: Make produce() optional (so base is generic on its definition)
produce() {
return {};
},
});
14 changes: 8 additions & 6 deletions src/next/blocks/blockPackageJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import sortPackageJson from "sort-package-json";
import { z } from "zod";

import { base } from "../base.js";
import { CommandPhase } from "./phases.js";

export const blockPackageJson = base.createBlock({
about: {
name: "Package JSON",
},
addons: {
cleanupCommands: z.array(z.string()).default([]),
// TODO: Find a zod package for this?
properties: z
.intersection(
Expand All @@ -24,12 +26,6 @@ export const blockPackageJson = base.createBlock({
},
produce({ addons, options }) {
return {
commands: [
{
phase: 0, // TODO: ???
script: "pnpm i",
},
],
files: {
"package.json": sortPackageJson(
JSON.stringify({
Expand Down Expand Up @@ -77,6 +73,12 @@ export const blockPackageJson = base.createBlock({
}),
),
},
scripts: [
{
commands: ["pnpm install", ...addons.cleanupCommands],
phase: CommandPhase.Install,
},
],
};
},
});
7 changes: 1 addition & 6 deletions src/next/blocks/blockPnpmDedupe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,14 @@ export const blockPnpmDedupe = base.createBlock({
],
}),
blockPackageJson({
cleanupCommands: ["pnpm dedupe --offline"],
properties: {
scripts: {
"lint:packages": "pnpm dedupe --check",
},
},
}),
],
commands: [
{
phase: 1,
script: "pnpm dedupe",
},
],
};
},
});
Loading

0 comments on commit 14b6e51

Please sign in to comment.