Skip to content

Commit 95cebe1

Browse files
fix: delete any existing Git tags in --mode create (#1614)
## PR Checklist - [x] Addresses an existing open issue: fixes #926 - [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 At the end of `createWithOptions`, prepends a nice little Git command before the other commands. Includes a small refactor of `createCleanupCommands` to not care about the mode. 💖
1 parent 4b975d2 commit 95cebe1

7 files changed

+38
-22
lines changed

src/create/createWithOptions.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ vi.mock("../steps/finalizeDependencies.js");
6363

6464
vi.mock("../steps/populateCSpellDictionary.js");
6565

66+
vi.mock("../steps/clearLocalGitTags.js");
67+
6668
vi.mock("../steps/runCleanup.js");
6769

6870
vi.mock("../shared/doesRepositoryExist.js", () => ({

src/create/createWithOptions.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { createCleanupCommands } from "../shared/createCleanupCommands.js";
55
import { doesRepositoryExist } from "../shared/doesRepositoryExist.js";
66
import { GitHubAndOptions } from "../shared/options/readOptions.js";
77
import { addToolAllContributors } from "../steps/addToolAllContributors.js";
8+
import { clearLocalGitTags } from "../steps/clearLocalGitTags.js";
89
import { finalizeDependencies } from "../steps/finalizeDependencies.js";
910
import { initializeGitHubRepository } from "../steps/initializeGitHubRepository/index.js";
1011
import { populateCSpellDictionary } from "../steps/populateCSpellDictionary.js";
@@ -46,9 +47,11 @@ export async function createWithOptions({ github, options }: GitHubAndOptions) {
4647
);
4748
}
4849

49-
await runCleanup(createCleanupCommands(options), options.mode);
50+
await runCleanup(createCleanupCommands(options.bin), options.mode);
5051
}
5152

53+
await withSpinner("Clearing any local Git tags", clearLocalGitTags);
54+
5255
const sendToGitHub =
5356
github && (await doesRepositoryExist(github.octokit, options));
5457

src/initialize/initializeWithOptions.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,8 @@ export async function initializeWithOptions({
6161
);
6262
}
6363

64-
await runCleanup(createCleanupCommands(options), options.mode);
64+
await runCleanup(
65+
createCleanupCommands(options.bin, "pnpm dedupe --offline"),
66+
options.mode,
67+
);
6568
}

src/migrate/migrateWithOptions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,5 @@ export async function migrateWithOptions({
6666
await withSpinner("Populating CSpell dictionary", populateCSpellDictionary);
6767
}
6868

69-
await runCleanup(createCleanupCommands(options), options.mode);
69+
await runCleanup(createCleanupCommands(options.bin), options.mode);
7070
}

src/shared/createCleanupCommands.test.ts

+15-11
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,27 @@ import { describe, expect, it } from "vitest";
33
import { createCleanupCommands } from "./createCleanupCommands.js";
44

55
describe("createCleanupCommands", () => {
6-
it("only lints and formats when bin is not enabled and mode is initialize", () => {
7-
const actual = createCleanupCommands({
8-
bin: undefined,
9-
mode: "initialize",
10-
});
6+
it("only lints and formats when bin is not enabled and there are no prepended commands", () => {
7+
const actual = createCleanupCommands(undefined);
118

129
expect(actual).toEqual(["pnpm lint --fix", "pnpm format --write"]);
1310
});
1411

15-
it("runs dedupe and build before it lints and formats when bin is enabled and mode is create", () => {
16-
const actual = createCleanupCommands({
17-
bin: "bin/index.js",
18-
mode: "create",
19-
});
12+
it("runs prepended commands before it lints and formats when bin is not enabled", () => {
13+
const actual = createCleanupCommands(undefined, "prepended");
2014

2115
expect(actual).toEqual([
22-
"pnpm dedupe --offline",
16+
"prepended",
17+
"pnpm lint --fix",
18+
"pnpm format --write",
19+
]);
20+
});
21+
22+
it("runs prepended commands before it builds, lints, and formats when bin is not enabled", () => {
23+
const actual = createCleanupCommands("bin/index.js", "prepended");
24+
25+
expect(actual).toEqual([
26+
"prepended",
2327
"pnpm build",
2428
"pnpm lint --fix",
2529
"pnpm format --write",

src/shared/createCleanupCommands.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import { Options } from "./types.js";
2-
3-
export function createCleanupCommands({
4-
bin,
5-
mode,
6-
}: Pick<Options, "bin" | "mode">) {
1+
export function createCleanupCommands(
2+
bin: string | undefined,
3+
...prependedCommands: string[]
4+
) {
75
return [
8-
// There's no need to dedupe when initializing from the fixed template
9-
...(mode === "initialize" ? [] : ["pnpm dedupe --offline"]),
6+
...prependedCommands,
107
// n/no-missing-import rightfully reports on a missing the bin .js file
118
...(bin ? ["pnpm build"] : []),
129
"pnpm lint --fix",

src/steps/clearLocalGitTags.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { execaCommand } from "execa";
2+
3+
export async function clearLocalGitTags() {
4+
const tags = await execaCommand("git tag -l");
5+
6+
await execaCommand(`git tag -d ${tags.stdout.replaceAll("\n", " ")}`);
7+
}

0 commit comments

Comments
 (0)