Skip to content

Commit 00ef611

Browse files
fix: suggest a re-run command instead of pnpm initialize after offline creation (#723)
## PR Checklist - [x] Addresses an existing open issue: fixes #722 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/template-typescript-node-package/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/template-typescript-node-package/blob/main/.github/CONTRIBUTING.md) were taken ## Overview Instead of `pnpm initialize`, adds a re-run suggestion that takes in the parsed options and re-prints them in the CLI. It hardcodes `skip-github-api` and `skip-install` to `false` because they're needed for the new repo.
1 parent 473ef5d commit 00ef611

10 files changed

+77
-8
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { describe, expect, it } from "vitest";
2+
3+
import { createRerunSuggestion } from "./createRerunSuggestion.js";
4+
5+
describe("createRerunSuggestion", () => {
6+
it("includes key-value pairs with mixed truthy and falsy values", () => {
7+
const actual = createRerunSuggestion("initialize", {
8+
author: "TestAuthor",
9+
base: "everything",
10+
createRepository: true,
11+
description: "Test description.",
12+
13+
excludeCompliance: true,
14+
excludeContributors: true,
15+
excludeLintJson: true,
16+
excludeLintKnip: true,
17+
excludeLintMd: false,
18+
excludeLintPackageJson: true,
19+
excludeLintPackages: false,
20+
excludeLintPerfectionist: true,
21+
excludeLintSpelling: false,
22+
excludeLintYml: false,
23+
excludeReleases: false,
24+
excludeRenovate: undefined,
25+
excludeTests: undefined,
26+
funding: undefined,
27+
owner: "TestOwner",
28+
repository: "test-repository",
29+
skipGitHubApi: true,
30+
skipInstall: true,
31+
skipRemoval: true,
32+
skipRestore: undefined,
33+
skipUninstall: undefined,
34+
title: "Test Title",
35+
});
36+
37+
expect(actual).toMatchInlineSnapshot(
38+
'"npx template-typescript-node-package --mode initialize --author TestAuthor --base everything --create-repository true --description \\"Test description.\\" --email [email protected] --exclude-compliance true --exclude-contributors true --exclude-lint-json true --exclude-lint-knip true --exclude-lint-package-json true --exclude-lint-perfectionist true --owner TestOwner --repository test-repository --skip-github-api true --skip-install true --skip-removal true --title \\"Test Title\\""',
39+
);
40+
});
41+
});

src/create/createRerunSuggestion.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Mode } from "../bin/mode.js";
2+
import { allArgOptions } from "../shared/options/args.js";
3+
import { Options } from "../shared/types.js";
4+
5+
function getFirstMatchingArg(key: string) {
6+
return Object.keys(allArgOptions).find(
7+
(arg) => arg.replaceAll("-", "") === key.toLowerCase(),
8+
);
9+
}
10+
11+
export function createRerunSuggestion(mode: Mode, options: Options): string {
12+
const args = Object.entries(options)
13+
.filter(([, value]) => !!value)
14+
.map(([key, value]) => {
15+
const valueStringified = `${value}`;
16+
return `--${getFirstMatchingArg(key)} ${
17+
valueStringified.includes(" ") ? `"${value}"` : value
18+
}`;
19+
})
20+
.join(" ");
21+
22+
return `npx template-typescript-node-package --mode ${mode} ${args}`;
23+
}

src/create/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import fs from "node:fs/promises";
66
import { outro } from "../shared/cli/outro.js";
77
import { readOptions } from "../shared/options/readOptions.js";
88
import { runOrRestore } from "../shared/runOrRestore.js";
9+
import { createRerunSuggestion } from "./createRerunSuggestion.js";
910
import { createWithOptions } from "./createWithOptions.js";
1011

1112
export async function create(args: string[]) {
@@ -38,7 +39,11 @@ export async function create(args: string[]) {
3839
"Consider creating a GitHub repository from the new directory:",
3940
lines: [
4041
`cd ${inputs.options.repository}`,
41-
`pnpm run initialize`,
42+
createRerunSuggestion("initialize", {
43+
...inputs.options,
44+
skipGitHubApi: false,
45+
skipInstall: false,
46+
}),
4247
`git add -A`,
4348
`git commit -m "feat: initial commit ✨"`,
4449
`git push -u origin main`,

src/shared/options/augmentOptionsWithExcludes.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const optionsBase = {
2525
funding: undefined,
2626
owner: "",
2727
repository: "",
28-
skipApi: false,
28+
skipGitHubApi: false,
2929
skipInstall: undefined,
3030
skipRemoval: undefined,
3131
skipRestore: undefined,

src/shared/options/readOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export async function readOptions(args: string[]): Promise<OctokitAndOptions> {
9191
),
9292
owner,
9393
repository: repository,
94-
skipApi: !!values["skip-github-api"],
94+
skipGitHubApi: !!values["skip-github-api"],
9595
skipInstall: !!values["skip-install"],
9696
skipRemoval: !!values["skip-removal"],
9797
skipRestore: values["skip-restore"] as boolean | undefined,

src/shared/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export interface Options {
4141
funding: string | undefined;
4242
owner: string;
4343
repository: string;
44-
skipApi: boolean;
44+
skipGitHubApi: boolean;
4545
skipInstall: boolean | undefined;
4646
skipRemoval: boolean | undefined;
4747
skipRestore: boolean | undefined;

src/steps/finalizeDependencies.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const options = {
4242
funding: undefined,
4343
owner: "StubOwner",
4444
repository: "stub-repository",
45-
skipApi: false,
45+
skipGitHubApi: false,
4646
skipInstall: undefined,
4747
skipRemoval: undefined,
4848
skipRestore: undefined,

src/steps/updateLocalFiles.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const options = {
4141
funding: undefined,
4242
owner: "StubOwner",
4343
repository: "stub-repository",
44-
skipApi: false,
44+
skipGitHubApi: false,
4545
skipInstall: undefined,
4646
skipRemoval: undefined,
4747
skipRestore: undefined,

src/steps/writeReadme.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const options = {
4545
funding: undefined,
4646
owner: "TestOwner",
4747
repository: "test-repository",
48-
skipApi: false,
48+
skipGitHubApi: false,
4949
skipInstall: true,
5050
skipRemoval: false,
5151
skipRestore: false,

src/steps/writing/creation/writePackageJson.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const options = {
3333
funding: undefined,
3434
owner: "test-owner",
3535
repository: "test-repository",
36-
skipApi: false,
36+
skipGitHubApi: false,
3737
skipInstall: undefined,
3838
skipRemoval: undefined,
3939
skipRestore: undefined,

0 commit comments

Comments
 (0)