Skip to content

fix: don't suggest redundant --directory #1805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading