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

feat: remove --create-repository option #921

Merged
merged 1 commit into from
Oct 1, 2023
Merged
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
5 changes: 2 additions & 3 deletions docs/Options.md
Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@ These required options determine how the creation script will set up and scaffol
- `common`: Important additions to the minimum starters such as releases and tests.
- `everything`: The most thorough tooling imaginable: sorting, spellchecking, and more!
- `prompt`: Fine-grained control over which tooling pieces to use
- `--create-repository` _(boolean)_: Whether to create a corresponding repository on github.com (if it doesn't yet exist)
- `--mode`: Whether to:
- `create` a new repository in a child directory
- `initialize` a freshly repository in the current directory
@@ -26,7 +25,7 @@ These required options determine how the creation script will set up and scaffol
For example, scaffolding a full new repository under the current directory and also linking it to a new repository on github.com:

```shell
npx create-typescript-app --base everything --create-repository --mode create
npx create-typescript-app --base everything --mode create
```

See [Tooling.md](./Tooling.md) for details on the tooling pieces and which bases they're included in.
@@ -43,7 +42,7 @@ These required options determine the options that will be substituted into the t
For example, pre-populating all core required options and also creating a new repository:

```shell
npx create-typescript-app --create-repository --base everything --mode create --repository testing-repository --title "Testing Title" --owner TestingOwner --description "Test Description"
npx create-typescript-app --base everything --mode create --repository testing-repository --title "Testing Title" --owner TestingOwner --description "Test Description"
```

That script will run completely autonomously, no prompted inputs required. ✨
7 changes: 3 additions & 4 deletions src/create/createRerunSuggestion.test.ts
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ const options = {
access: "public",
author: "TestAuthor",
base: "everything",
createRepository: true,
description: "Test description.",
directory: ".",
email: {
@@ -47,7 +46,7 @@ describe("createRerunSuggestion", () => {
const actual = createRerunSuggestion(options);

expect(actual).toMatchInlineSnapshot(
'"npx create-typescript-app --mode create --base everything --access public --author TestAuthor --create-repository true --description \\"Test description.\\" --directory . --email-github [email protected] --email-npm [email protected] --exclude-all-contributors true --exclude-compliance true --exclude-lint-jsdoc true --exclude-lint-json true --exclude-lint-knip true --exclude-lint-package-json true --exclude-lint-perfectionist true --keywords \\"abc def ghi jkl mno pqr\\" --mode create --owner TestOwner --repository test-repository --skip-github-api true --skip-install true --skip-removal true --title \\"Test Title\\""',
'"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 true --exclude-compliance true --exclude-lint-jsdoc true --exclude-lint-json true --exclude-lint-knip true --exclude-lint-package-json true --exclude-lint-perfectionist true --keywords \\"abc def ghi jkl mno pqr\\" --mode create --owner TestOwner --repository test-repository --skip-github-api true --skip-install true --skip-removal true --title \\"Test Title\\""',
);
});

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

expect(actual).toMatchInlineSnapshot(
'"npx create-typescript-app --mode initialize --base everything --access public --author TestAuthor --create-repository true --description \\"Test description.\\" --directory . --email-github [email protected] --email-npm [email protected] --exclude-all-contributors true --exclude-compliance true --exclude-lint-jsdoc true --exclude-lint-json true --exclude-lint-knip true --exclude-lint-package-json true --exclude-lint-perfectionist true --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 true --skip-install true --skip-removal true --title \\"Test Title\\""',
'"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 true --exclude-compliance true --exclude-lint-jsdoc true --exclude-lint-json true --exclude-lint-knip true --exclude-lint-package-json true --exclude-lint-perfectionist true --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 true --skip-install true --skip-removal true --title \\"Test Title\\""',
);
});

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

expect(actual).toMatchInlineSnapshot(
'"npx create-typescript-app --mode initialize --base everything --access public --author TestAuthor --create-repository true --description \\"Test description.\\" --directory . --email-github [email protected] --email-npm [email protected] --exclude-all-contributors true --exclude-compliance true --exclude-lint-jsdoc true --exclude-lint-json true --exclude-lint-knip true --exclude-lint-md true --exclude-lint-package-json true --exclude-lint-perfectionist true --exclude-lint-spelling true --keywords \\"abc def ghi jkl mno pqr\\" --mode initialize --owner TestOwner --repository test-repository --skip-github-api true --skip-install true --skip-removal true --title \\"Test Title\\""',
'"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 true --exclude-compliance true --exclude-lint-jsdoc true --exclude-lint-json true --exclude-lint-knip true --exclude-lint-md true --exclude-lint-package-json true --exclude-lint-perfectionist true --exclude-lint-spelling true --keywords \\"abc def ghi jkl mno pqr\\" --mode initialize --owner TestOwner --repository test-repository --skip-github-api true --skip-install true --skip-removal true --title \\"Test Title\\""',
);
});
});
9 changes: 1 addition & 8 deletions src/create/createWithOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as prompts from "@clack/prompts";
import { $ } from "execa";

import { withSpinner, withSpinners } from "../shared/cli/spinners.js";
@@ -46,13 +45,7 @@ export async function createWithOptions({ github, options }: GitHubAndOptions) {
]);

const sendToGitHub =
github &&
(await doesRepositoryExist(github.octokit, options)) &&
(options.createRepository ??
(await prompts.confirm({
message:
"Would you like to push the template's tooling up to the repository on GitHub?",
})) === true);
github && (await doesRepositoryExist(github.octokit, options));

if (sendToGitHub) {
await withSpinner("Initializing GitHub repository", async () => {
1 change: 0 additions & 1 deletion src/shared/options/args.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ export const allArgOptions = {
access: { type: "string" },
author: { type: "string" },
base: { type: "string" },
"create-repository": { type: "boolean" },
description: { type: "string" },
directory: { type: "string" },
email: { type: "string" },
1 change: 0 additions & 1 deletion src/shared/options/augmentOptionsWithExcludes.test.ts
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ const optionsBase = {
access: "public",
author: undefined,
base: "everything",
createRepository: undefined,
description: "",
directory: ".",
email: {
29 changes: 0 additions & 29 deletions src/shared/options/ensureRepositoryExists.test.ts
Original file line number Diff line number Diff line change
@@ -38,7 +38,6 @@ const createMockOctokit = () =>
describe("ensureRepositoryExists", () => {
it("returns the repository when octokit is undefined", async () => {
const actual = await ensureRepositoryExists(undefined, {
createRepository: false,
owner,
repository,
});
@@ -52,7 +51,6 @@ describe("ensureRepositoryExists", () => {
const actual = await ensureRepositoryExists(
{ auth, octokit },
{
createRepository: false,
owner,
repository,
},
@@ -61,29 +59,6 @@ describe("ensureRepositoryExists", () => {
expect(actual).toEqual({ github: { auth, octokit }, repository });
});

it("creates a new repository when createRepository is true and the repository does not exist", async () => {
const octokit = createMockOctokit();

mockDoesRepositoryExist.mockResolvedValue(false);

const actual = await ensureRepositoryExists(
{ auth, octokit },
{
createRepository: true,
owner,
repository,
},
);

expect(actual).toEqual({ github: { auth, octokit }, repository });
expect(octokit.rest.repos.createUsingTemplate).toHaveBeenCalledWith({
name: repository,
owner,
template_owner: "JoshuaKGoldberg",
template_repo: "create-typescript-app",
});
});

it("creates a new repository when the prompt is 'create' and the repository does not exist", async () => {
const octokit = createMockOctokit();

@@ -93,7 +68,6 @@ describe("ensureRepositoryExists", () => {
const actual = await ensureRepositoryExists(
{ auth, octokit },
{
createRepository: false,
owner,
repository,
},
@@ -121,7 +95,6 @@ describe("ensureRepositoryExists", () => {
const actual = await ensureRepositoryExists(
{ auth, octokit },
{
createRepository: false,
owner,
repository,
},
@@ -147,7 +120,6 @@ describe("ensureRepositoryExists", () => {
const actual = await ensureRepositoryExists(
{ auth, octokit },
{
createRepository: false,
owner,
repository,
},
@@ -174,7 +146,6 @@ describe("ensureRepositoryExists", () => {
const actual = await ensureRepositoryExists(
{ auth, octokit },
{
createRepository: false,
owner,
repository,
},
43 changes: 19 additions & 24 deletions src/shared/options/ensureRepositoryExists.ts
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ import { GitHub } from "./getGitHub.js";

export type EnsureRepositoryExistsOptions = Pick<
Options,
"createRepository" | "owner" | "repository"
"owner" | "repository"
>;

export interface RepositoryExistsResult {
@@ -19,8 +19,7 @@ export async function ensureRepositoryExists(
github: GitHub | undefined,
options: EnsureRepositoryExistsOptions,
): Promise<Partial<RepositoryExistsResult>> {
// We'll only respect input options once before prompting for them
let { createRepository, repository } = options;
let { repository } = options;

// We'll continuously pester the user for a repository
// until they bail, create a new one, or it exists.
@@ -29,27 +28,23 @@ export async function ensureRepositoryExists(
return { github, repository };
}

const selection = createRepository
? "create"
: filterPromptCancel(
(await prompts.select({
message: `Repository ${options.repository} doesn't seem to exist under ${options.owner}. What would you like to do?`,
options: [
{ label: "Create a new repository", value: "create" },
{
label: "Switch to a different repository name",
value: "different",
},
{
label: "Keep changes local",
value: "local",
},
{ label: "Bail out and maybe try again later", value: "bail" },
],
})) as "bail" | "create" | "different" | "local",
);

createRepository = false;
const selection = filterPromptCancel(
(await prompts.select({
message: `Repository ${options.repository} doesn't seem to exist under ${options.owner}. What would you like to do?`,
options: [
{ label: "Create a new repository", value: "create" },
{
label: "Switch to a different repository name",
value: "different",
},
{
label: "Keep changes local",
value: "local",
},
{ label: "Bail out and maybe try again later", value: "bail" },
],
})) as "bail" | "create" | "different" | "local",
);

switch (selection) {
case undefined:
1 change: 0 additions & 1 deletion src/shared/options/optionsSchema.ts
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@ export const optionsSchemaShape = {
z.literal("prompt"),
])
.optional(),
createRepository: z.boolean().optional(),
description: z.string().optional(),
directory: z.string().optional(),
email: z
1 change: 0 additions & 1 deletion src/shared/options/readOptions.test.ts
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@ const emptyOptions = {
access: undefined,
author: undefined,
base: undefined,
createRepository: undefined,
description: undefined,
directory: undefined,
email: undefined,
2 changes: 0 additions & 2 deletions src/shared/options/readOptions.ts
Original file line number Diff line number Diff line change
@@ -48,7 +48,6 @@ export async function readOptions(
access: values.access,
author: values.author,
base: values.base,
createRepository: values["create-repository"],
description: values.description,
directory: values.directory,
email:
@@ -138,7 +137,6 @@ export async function readOptions(
? undefined
: await withSpinner("Checking GitHub authentication", getGitHub),
{
createRepository: options.createRepository,
owner: options.owner,
repository: options.repository,
},
1 change: 0 additions & 1 deletion src/shared/types.ts
Original file line number Diff line number Diff line change
@@ -42,7 +42,6 @@ export interface Options {
access: OptionsAccess;
author?: string;
base?: OptionsBase;
createRepository?: boolean;
description: string;
directory: string;
email: OptionsEmail;
1 change: 0 additions & 1 deletion src/steps/finalizeDependencies.test.ts
Original file line number Diff line number Diff line change
@@ -20,7 +20,6 @@ const options = {
access: "public",
author: undefined,
base: "everything",
createRepository: undefined,
description: "Stub description.",
directory: ".",
email: {
1 change: 0 additions & 1 deletion src/steps/updateLocalFiles.test.ts
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ const options = {
access: "public",
author: undefined,
base: "everything",
createRepository: undefined,
description: "Stub description.",
directory: ".",
email: {
1 change: 0 additions & 1 deletion src/steps/writeReadme/generateTopContent.test.ts
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ const optionsBase = {
access: "public",
author: undefined,
base: undefined,
createRepository: undefined,
description: "",
directory: ".",
email: {
1 change: 0 additions & 1 deletion src/steps/writeReadme/index.test.ts
Original file line number Diff line number Diff line change
@@ -27,7 +27,6 @@ const options = {
access: "public",
author: "Test Author",
base: "everything",
createRepository: false,
description: "Test description.",
directory: ".",
email: {
1 change: 0 additions & 1 deletion src/steps/writing/creation/createESLintRC.test.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@ function fakeOptions(getExcludeValue: (exclusionName: string) => boolean) {
access: "public",
author: "TestAuthor",
base: "everything",
createRepository: true,
description: "Test description.",
directory: ".",
email: {
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ const options = {
access: "public",
author: "Test Author",
base: "everything",
createRepository: false,
description: "Test description.",
directory: ".",
email: {
1 change: 0 additions & 1 deletion src/steps/writing/creation/writePackageJson.test.ts
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@ const options = {
access: "public",
author: "test-author",
base: "everything",
createRepository: undefined,
description: "Test description.",
directory: ".",
email: {