Skip to content

Commit

Permalink
fix: don't suggest redundant --directory (#1805)
Browse files Browse the repository at this point in the history
## 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

💖
  • Loading branch information
JoshuaKGoldberg authored Dec 24, 2024
1 parent 1d09b76 commit 42c6ebd
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
48 changes: 48 additions & 0 deletions src/create/createRerunDirectorySuggestion.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { describe, expect, it } from "vitest";

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

const directory = "test-directory";
const repository = "test-repository";

describe("createRerunDirectorySuggestion", () => {
it("returns undefined when mode is create and directory matches repository", () => {
const suggestion = createRerunDirectorySuggestion({
directory: repository,
mode: "create",
repository,
});

expect(suggestion).toBe(undefined);
});

it("returns directory when mode is create and directory doesn't match repository", () => {
const suggestion = createRerunDirectorySuggestion({
directory,
mode: "create",
repository,
});

expect(suggestion).toBe(directory);
});

it("returns undefined when mode is initialize and directory is .", () => {
const suggestion = createRerunDirectorySuggestion({
directory: ".",
mode: "initialize",
repository,
});

expect(suggestion).toBe(undefined);
});

it("returns directory when mode is initialize and directory is not .", () => {
const suggestion = createRerunDirectorySuggestion({
directory,
mode: "initialize",
repository,
});

expect(suggestion).toBe(directory);
});
});
7 changes: 7 additions & 0 deletions src/create/createRerunDirectorySuggestion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Options } from "../shared/types.js";

export function createRerunDirectorySuggestion(options: Partial<Options>) {
const defaultValue = options.mode === "create" ? options.repository : ".";

return options.directory === defaultValue ? undefined : options.directory;
}
30 changes: 27 additions & 3 deletions src/create/createRerunSuggestion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe("createRerunSuggestion", () => {
});

expect(actual).toMatchInlineSnapshot(
`"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""`,
`"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""`,
);
});

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

expect(actual).toMatchInlineSnapshot(
`"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""`,
`"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""`,
);
});

it("does not include directory when it is repository and the mode is create", () => {
const actual = createRerunSuggestion({
...options,
directory: options.repository,
mode: "create",
});

expect(actual).toMatchInlineSnapshot(
`"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""`,
);
});

it("includes directory when it is repository and the mode is migrate", () => {
const actual = createRerunSuggestion({
...options,
directory: options.repository,
mode: "migrate",
});

expect(actual).toMatchInlineSnapshot(
`"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""`,
);
});

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

expect(actual).toMatchInlineSnapshot(
`"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""`,
`"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""`,
);
});

Expand Down
2 changes: 2 additions & 0 deletions src/create/createRerunSuggestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getExclusions,
} from "../shared/options/exclusionKeys.js";
import { Options } from "../shared/types.js";
import { createRerunDirectorySuggestion } from "./createRerunDirectorySuggestion.js";

function getFirstMatchingArg(key: string) {
return Object.keys(allArgOptions).find(
Expand Down Expand Up @@ -37,6 +38,7 @@ export function createRerunSuggestion(options: Partial<Options>): string {
skipAllContributorsApi: undefined,
skipGitHubApi: undefined,
}),
directory: createRerunDirectorySuggestion(options),
};

const args = Object.entries(optionsNormalized)
Expand Down

0 comments on commit 42c6ebd

Please sign in to comment.