Skip to content

Commit 42c6ebd

Browse files
fix: don't suggest redundant --directory (#1805)
## PR Checklist - [x] Addresses an existing open issue: fixes #1126 - [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 💖
1 parent 1d09b76 commit 42c6ebd

4 files changed

+84
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { describe, expect, it } from "vitest";
2+
3+
import { createRerunDirectorySuggestion } from "./createRerunDirectorySuggestion.js";
4+
5+
const directory = "test-directory";
6+
const repository = "test-repository";
7+
8+
describe("createRerunDirectorySuggestion", () => {
9+
it("returns undefined when mode is create and directory matches repository", () => {
10+
const suggestion = createRerunDirectorySuggestion({
11+
directory: repository,
12+
mode: "create",
13+
repository,
14+
});
15+
16+
expect(suggestion).toBe(undefined);
17+
});
18+
19+
it("returns directory when mode is create and directory doesn't match repository", () => {
20+
const suggestion = createRerunDirectorySuggestion({
21+
directory,
22+
mode: "create",
23+
repository,
24+
});
25+
26+
expect(suggestion).toBe(directory);
27+
});
28+
29+
it("returns undefined when mode is initialize and directory is .", () => {
30+
const suggestion = createRerunDirectorySuggestion({
31+
directory: ".",
32+
mode: "initialize",
33+
repository,
34+
});
35+
36+
expect(suggestion).toBe(undefined);
37+
});
38+
39+
it("returns directory when mode is initialize and directory is not .", () => {
40+
const suggestion = createRerunDirectorySuggestion({
41+
directory,
42+
mode: "initialize",
43+
repository,
44+
});
45+
46+
expect(suggestion).toBe(directory);
47+
});
48+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Options } from "../shared/types.js";
2+
3+
export function createRerunDirectorySuggestion(options: Partial<Options>) {
4+
const defaultValue = options.mode === "create" ? options.repository : ".";
5+
6+
return options.directory === defaultValue ? undefined : options.directory;
7+
}

src/create/createRerunSuggestion.test.ts

+27-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe("createRerunSuggestion", () => {
8989
});
9090

9191
expect(actual).toMatchInlineSnapshot(
92-
`"npx create-typescript-app --base everything --author TestAuthor --description "Test description." --directory . --email-github [email protected] --email-npm [email protected] --exclude-all-contributors --exclude-compliance --exclude-lint-jsdoc --exclude-lint-json --exclude-lint-knip --exclude-lint-package-json --exclude-lint-perfectionist --guide https://example.com --guide-title "Test Title" --keywords "abc def ghi jkl mno pqr" --mode initialize --owner TestOwner --repository test-repository --skip-github-api --skip-install --skip-removal --title "Test Title""`,
92+
`"npx create-typescript-app --base everything --author TestAuthor --description "Test description." --email-github [email protected] --email-npm [email protected] --exclude-all-contributors --exclude-compliance --exclude-lint-jsdoc --exclude-lint-json --exclude-lint-knip --exclude-lint-package-json --exclude-lint-perfectionist --guide https://example.com --guide-title "Test Title" --keywords "abc def ghi jkl mno pqr" --mode initialize --owner TestOwner --repository test-repository --skip-github-api --skip-install --skip-removal --title "Test Title""`,
9393
);
9494
});
9595

@@ -104,7 +104,31 @@ describe("createRerunSuggestion", () => {
104104
});
105105

106106
expect(actual).toMatchInlineSnapshot(
107-
`"npx create-typescript-app --base everything --author TestAuthor --description "Test description." --directory . --email-github [email protected] --email-npm [email protected] --exclude-all-contributors --exclude-compliance --exclude-lint-jsdoc --exclude-lint-json --exclude-lint-knip --exclude-lint-package-json --exclude-lint-perfectionist --keywords "abc def ghi jkl mno pqr" --logo test/src.png --logo-alt "Test alt." --mode initialize --owner TestOwner --repository test-repository --skip-github-api --skip-install --skip-removal --title "Test Title""`,
107+
`"npx create-typescript-app --base everything --author TestAuthor --description "Test description." --email-github [email protected] --email-npm [email protected] --exclude-all-contributors --exclude-compliance --exclude-lint-jsdoc --exclude-lint-json --exclude-lint-knip --exclude-lint-package-json --exclude-lint-perfectionist --keywords "abc def ghi jkl mno pqr" --logo test/src.png --logo-alt "Test alt." --mode initialize --owner TestOwner --repository test-repository --skip-github-api --skip-install --skip-removal --title "Test Title""`,
108+
);
109+
});
110+
111+
it("does not include directory when it is repository and the mode is create", () => {
112+
const actual = createRerunSuggestion({
113+
...options,
114+
directory: options.repository,
115+
mode: "create",
116+
});
117+
118+
expect(actual).toMatchInlineSnapshot(
119+
`"npx create-typescript-app --base everything --author TestAuthor --description "Test description." --email-github [email protected] --email-npm [email protected] --exclude-all-contributors --exclude-compliance --exclude-lint-jsdoc --exclude-lint-json --exclude-lint-knip --exclude-lint-package-json --exclude-lint-perfectionist --keywords "abc def ghi jkl mno pqr" --mode create --owner TestOwner --repository test-repository --skip-github-api --skip-install --skip-removal --title "Test Title""`,
120+
);
121+
});
122+
123+
it("includes directory when it is repository and the mode is migrate", () => {
124+
const actual = createRerunSuggestion({
125+
...options,
126+
directory: options.repository,
127+
mode: "migrate",
128+
});
129+
130+
expect(actual).toMatchInlineSnapshot(
131+
`"npx create-typescript-app --base everything --author TestAuthor --description "Test description." --directory test-repository --email-github [email protected] --email-npm [email protected] --exclude-all-contributors --exclude-compliance --exclude-lint-jsdoc --exclude-lint-json --exclude-lint-knip --exclude-lint-package-json --exclude-lint-perfectionist --keywords "abc def ghi jkl mno pqr" --mode migrate --owner TestOwner --repository test-repository --skip-github-api --skip-install --skip-removal --title "Test Title""`,
108132
);
109133
});
110134

@@ -118,7 +142,7 @@ describe("createRerunSuggestion", () => {
118142
});
119143

120144
expect(actual).toMatchInlineSnapshot(
121-
`"npx create-typescript-app --base everything --author TestAuthor --description "Test description." --directory . --email-github [email protected] --email-npm [email protected] --exclude-all-contributors --exclude-compliance --exclude-lint-jsdoc --exclude-lint-json --exclude-lint-knip --exclude-lint-md --exclude-lint-package-json --exclude-lint-perfectionist --exclude-lint-spelling --keywords "abc def ghi jkl mno pqr" --mode initialize --owner TestOwner --repository test-repository --skip-github-api --skip-install --skip-removal --title "Test Title""`,
145+
`"npx create-typescript-app --base everything --author TestAuthor --description "Test description." --email-github [email protected] --email-npm [email protected] --exclude-all-contributors --exclude-compliance --exclude-lint-jsdoc --exclude-lint-json --exclude-lint-knip --exclude-lint-md --exclude-lint-package-json --exclude-lint-perfectionist --exclude-lint-spelling --keywords "abc def ghi jkl mno pqr" --mode initialize --owner TestOwner --repository test-repository --skip-github-api --skip-install --skip-removal --title "Test Title""`,
122146
);
123147
});
124148

src/create/createRerunSuggestion.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
getExclusions,
55
} from "../shared/options/exclusionKeys.js";
66
import { Options } from "../shared/types.js";
7+
import { createRerunDirectorySuggestion } from "./createRerunDirectorySuggestion.js";
78

89
function getFirstMatchingArg(key: string) {
910
return Object.keys(allArgOptions).find(
@@ -37,6 +38,7 @@ export function createRerunSuggestion(options: Partial<Options>): string {
3738
skipAllContributorsApi: undefined,
3839
skipGitHubApi: undefined,
3940
}),
41+
directory: createRerunDirectorySuggestion(options),
4042
};
4143

4244
const args = Object.entries(optionsNormalized)

0 commit comments

Comments
 (0)