Skip to content
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

fix: omit default --access value in rerun suggestions #1307

Merged
merged 1 commit into from
Feb 15, 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
23 changes: 17 additions & 6 deletions src/create/createRerunSuggestion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,18 @@ describe("createRerunSuggestion", () => {
const actual = createRerunSuggestion(options);

expect(actual).toMatchInlineSnapshot(
`"npx create-typescript-app --mode create --base everything --access public --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" --mode create --owner TestOwner --repository test-repository --skip-github-api --skip-install --skip-removal --title "Test Title""`,
`"npx create-typescript-app --mode create --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" --mode create --owner TestOwner --repository test-repository --skip-github-api --skip-install --skip-removal --title "Test Title""`,
);
});

it("includes a non-default value when specified", () => {
const actual = createRerunSuggestion({
...options,
access: "restricted",
});

expect(actual).toMatchInlineSnapshot(
`"npx create-typescript-app --mode create --base everything --access restricted --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" --mode create --owner TestOwner --repository test-repository --skip-github-api --skip-install --skip-removal --title "Test Title""`,
);
});

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

expect(actual).toMatchInlineSnapshot(
`"npx create-typescript-app --mode initialize --base everything --access public --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 --mode initialize --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""`,
);
});

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

expect(actual).toMatchInlineSnapshot(
`"npx create-typescript-app --mode initialize --base everything --access public --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 --mode initialize --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""`,
);
});

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

expect(actual).toMatchInlineSnapshot(
`"npx create-typescript-app --mode initialize --base everything --access public --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 --mode initialize --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""`,
);
});

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

expect(common).toMatchInlineSnapshot(
'"npx create-typescript-app --mode undefined --base common"',
`"npx create-typescript-app --mode undefined --base common"`,
);
});

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

expect(minimum).toMatchInlineSnapshot(
'"npx create-typescript-app --mode undefined --base minimum"',
`"npx create-typescript-app --mode undefined --base minimum"`,
);
});
});
8 changes: 6 additions & 2 deletions src/create/createRerunSuggestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ function getFirstMatchingArg(key: string) {
);
}

const defaultValues = new Map([["access", "public"]]);

export function createRerunSuggestion(options: Partial<Options>): string {
const optionsNormalized = {
...options,
Expand Down Expand Up @@ -38,11 +40,13 @@ export function createRerunSuggestion(options: Partial<Options>): string {
.sort(([a], [b]) =>
a === "base" ? -1 : b === "base" ? 1 : a.localeCompare(b),
)
// Filter out all entries that have a key in the excluded object or have a falsy value
// Filter out entries with an excluded key or a default or falsy value
.filter(
([key, value]) =>
getExclusions(options, optionsNormalized.base)[key as ExclusionKey] ==
undefined && !!value,
undefined &&
!!value &&
value !== defaultValues.get(key),
)
.map(([key, value]) => {
return `--${getFirstMatchingArg(key)}${stringifyValue(value)}`;
Expand Down
Loading