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: add optional --access option #871

Merged
merged 4 commits into from
Sep 22, 2023
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
2 changes: 1 addition & 1 deletion .release-it.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"release": true,
"releaseName": "v${version}"
},
"npm": { "publishArgs": ["--provenance"] },
"npm": { "publishArgs": ["--access public", "--provenance"] },
"plugins": {
"@release-it/conventional-changelog": {
"infile": "CHANGELOG.md",
Expand Down
1 change: 1 addition & 0 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ That script will run completely autonomously, no prompted inputs required. ✨

The setup scripts also allow for optional overrides of the following inputs whose defaults are based on other options:

- `--access` _(`"public" | "restricted`)_: Which [`npm publish --access`](https://docs.npmjs.com/cli/commands/npm-publish#access) to release npm packages with (by default, `"public"`)
- `--author` _(`string`)_: Username on npm to publish packages under (by default, an existing npm author, or the currently logged in npm user, or `owner.toLowerCase()`)
- `--email` _(`string`)_: Email address to be listed as the point of contact in docs and packages (e.g. `[email protected]`)
- Optionally, `--email-github` _(`string`)_ and/or `--email-npm` _(`string`)_ may be provided to use different emails in `.md` files and `package.json`, respectively
Expand Down
7 changes: 4 additions & 3 deletions src/create/createRerunSuggestion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Options } from "../shared/types.js";
import { createRerunSuggestion } from "./createRerunSuggestion.js";

const options = {
access: "public",
author: "TestAuthor",
base: "everything",
createRepository: true,
Expand Down Expand Up @@ -43,7 +44,7 @@ describe("createRerunSuggestion", () => {
const actual = createRerunSuggestion("initialize", options);

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

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

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

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

expect(actual).toMatchInlineSnapshot(
'"npx create-typescript-app --mode initialize --base everything --author TestAuthor --create-repository true --description \\"Test description.\\" --email-github [email protected] --email-npm [email protected] --exclude-compliance true --exclude-contributors 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 --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 --create-repository true --description \\"Test description.\\" --email-github [email protected] --email-npm [email protected] --exclude-compliance true --exclude-contributors 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 --owner TestOwner --repository test-repository --skip-github-api true --skip-install true --skip-removal true --title \\"Test Title\\""',
);
});
});
1 change: 1 addition & 0 deletions src/shared/options/args.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const allArgOptions = {
access: { type: "string" },
author: { type: "string" },
base: { type: "string" },
"create-repository": { type: "boolean" },
Expand Down
3 changes: 2 additions & 1 deletion src/shared/options/augmentOptionsWithExcludes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Options } from "../types.js";
import { augmentOptionsWithExcludes } from "./augmentOptionsWithExcludes.js";

const optionsBase = {
access: "public",
author: undefined,
base: undefined,
createRepository: undefined,
Expand Down Expand Up @@ -41,7 +42,7 @@ const optionsBase = {
skipRestore: undefined,
skipUninstall: undefined,
title: "",
};
} satisfies Options;

describe("augmentOptionsWithExcludes", () => {
it("returns options without exclusions and skips prompting when exclusions are provided manually", async () => {
Expand Down
6 changes: 3 additions & 3 deletions src/shared/options/augmentOptionsWithExcludes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as prompts from "@clack/prompts";
import chalk from "chalk";

import { filterPromptCancel } from "../prompts.js";
import { InputBase, Options } from "../types.js";
import { Options, OptionsBase } from "../types.js";

interface ExclusionDescription {
hint: string;
Expand Down Expand Up @@ -134,9 +134,9 @@ export async function augmentOptionsWithExcludes(

const base =
options.base ??
filterPromptCancel<InputBase | symbol>(
filterPromptCancel<OptionsBase | symbol>(
await prompts.select({
initialValue: "common" as InputBase,
initialValue: "common" as OptionsBase,
message: `How much tooling would you like the template to set up for you?`,
options: [
{
Expand Down
1 change: 1 addition & 0 deletions src/shared/options/optionsSchema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { z } from "zod";

export const optionsSchemaShape = {
access: z.union([z.literal("public"), z.literal("restricted")]).optional(),
author: z.string().optional(),
base: z
.union([
Expand Down
1 change: 1 addition & 0 deletions src/shared/options/readOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { optionsSchemaShape } from "./optionsSchema.js";
import { readOptions } from "./readOptions.js";

const emptyOptions = {
access: undefined,
author: undefined,
base: undefined,
createRepository: undefined,
Expand Down
2 changes: 2 additions & 0 deletions src/shared/options/readOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export async function readOptions(args: string[]): Promise<OptionsParseResult> {
});

const mappedOptions = {
access: values.access,
author: values.author,
base: values.base,
createRepository: values["create-repository"],
Expand Down Expand Up @@ -186,6 +187,7 @@ export async function readOptions(args: string[]): Promise<OptionsParseResult> {

const augmentedOptions = await augmentOptionsWithExcludes({
...options,
access: options.access ?? "public",
author: options.author ?? (await defaults.owner()),
description: options.description,
email: typeof email === "string" ? { github: email, npm: email } : email,
Expand Down
15 changes: 9 additions & 6 deletions src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,24 @@ export interface PartialPackageData {
repository?: { type: string; url: string } | string;
}

export type InputBase = "common" | "everything" | "minimum" | "prompt";
export type OptionsAccess = "public" | "restricted";

export interface OptionsLogo {
alt: string;
src: string;
}
export type OptionsBase = "common" | "everything" | "minimum" | "prompt";

export interface OptionsEmail {
github: string;
npm: string;
}

export interface OptionsLogo {
alt: string;
src: string;
}

export interface Options {
access: OptionsAccess;
author?: string;
base?: InputBase;
base?: OptionsBase;
createRepository?: boolean;
description: string;
email: OptionsEmail;
Expand Down
1 change: 1 addition & 0 deletions src/steps/finalizeDependencies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ vi.mock("../shared/packages.js", () => ({
}));

const options = {
access: "public",
author: undefined,
base: "everything",
createRepository: undefined,
Expand Down
1 change: 1 addition & 0 deletions src/steps/updateLocalFiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ vi.mock("../shared/readFileSafeAsJson.js", () => ({
}));

const options = {
access: "public",
author: undefined,
base: "everything",
createRepository: undefined,
Expand Down
4 changes: 3 additions & 1 deletion src/steps/writeReadme/generateTopContent.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { describe, expect, it } from "vitest";

import { Options } from "../../shared/types.js";
import { generateTopContent } from "./generateTopContent.js";

const optionsBase = {
access: "public",
author: undefined,
base: undefined,
createRepository: undefined,
Expand Down Expand Up @@ -34,7 +36,7 @@ const optionsBase = {
skipRestore: undefined,
skipUninstall: undefined,
title: "",
};
} satisfies Options;

describe("findExistingBadges", () => {
it("generates full contents when there are no existing badges", () => {
Expand Down
1 change: 1 addition & 0 deletions src/steps/writeReadme/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ vi.mock("../../shared/readFileSafe.js", () => ({
}));

const options = {
access: "public",
author: "Test Author",
base: "everything",
createRepository: false,
Expand Down
1 change: 1 addition & 0 deletions src/steps/writing/creation/createESLintRC.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createESLintRC } from "./createESLintRC.js";

function fakeOptions(getExcludeValue: (exclusionName: string) => boolean) {
return {
access: "public",
author: "TestAuthor",
base: "everything",
createRepository: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Options } from "../../../../shared/types.js";
import { createDevelopment } from "./createDevelopment.js";

const options = {
access: "public",
author: "Test Author",
base: "everything",
createRepository: false,
Expand Down
2 changes: 1 addition & 1 deletion src/steps/writing/creation/rootFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function createRootFiles(options: Options) {
releaseName: "v${version}",
},
npm: {
publishArgs: ["--provenance"],
publishArgs: [`--access ${options.access}`, "--provenance"],
},
plugins: {
"@release-it/conventional-changelog": {
Expand Down
1 change: 1 addition & 0 deletions src/steps/writing/creation/writePackageJson.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ vi.mock("../../../shared/readFileSafeAsJson.js", () => ({
}));

const options = {
access: "public",
author: "test-author",
base: "everything",
createRepository: undefined,
Expand Down