Skip to content

feat: add back Usage example to create and initialize #882

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 6 commits into from
Sep 23, 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
11 changes: 10 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = {
files: ["**/*.ts"],
parser: "@typescript-eslint/parser",
rules: {
// These off-by-default rules work well for this repo and we like them on.
// These off-/differently-configured-by-default rules work well for this repo and we like them on.
"jsdoc/informative-docs": "error",
"logical-assignment-operators": [
"error",
Expand All @@ -53,6 +53,15 @@ module.exports = {
"jsdoc/require-returns": "off",
},
},
{
files: "**/*.md/*.ts",
rules: {
"n/no-missing-import": [
"error",
{ allowModules: ["create-typescript-app"] },
],
},
},
{
excludedFiles: ["**/*.md/*.ts"],
extends: [
Expand Down
2 changes: 1 addition & 1 deletion script/create-test-e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { strict as assert } from "node:assert";
const author = "Test Author";
const description = "Test description.";
const email = "test@email.com";
const repository = "test-repository";
const repository = "create-typescript-app";
const owner = "TestOwner";
const title = "Test Title";

Expand Down
2 changes: 1 addition & 1 deletion src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export async function bin(args: string[]) {
prompts.log.info(
[
chalk.italic(`Tip: to run again with the same input values, use:`),
chalk.blue(createRerunSuggestion(mode, options)),
chalk.blue(createRerunSuggestion(options)),
].join(" "),
);

Expand Down
15 changes: 9 additions & 6 deletions src/create/createRerunSuggestion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const options = {
excludeTests: undefined,
funding: undefined,
logo: undefined,
mode: "create",
owner: "TestOwner",
repository: "test-repository",
skipGitHubApi: true,
Expand All @@ -41,37 +42,39 @@ const options = {

describe("createRerunSuggestion", () => {
it("includes key-value pairs with mixed truthy and falsy values", () => {
const actual = createRerunSuggestion("initialize", options);
const actual = createRerunSuggestion(options);

expect(actual).toMatchInlineSnapshot(
'"npx create-typescript-app --mode initialize --base everything --access public --author TestAuthor --create-repository true --description \\"Test description.\\" --email-github github@email.com --email-npm npm@email.com --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 create --base everything --access public --author TestAuthor --create-repository true --description \\"Test description.\\" --email-github github@email.com --email-npm npm@email.com --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 --mode create --owner TestOwner --repository test-repository --skip-github-api true --skip-install true --skip-removal true --title \\"Test Title\\""',
);
});

it("includes stringified logo when it exists", () => {
const actual = createRerunSuggestion("initialize", {
const actual = createRerunSuggestion({
...options,
logo: {
alt: "Test alt.",
src: "test/src.png",
},
mode: "initialize",
});

expect(actual).toMatchInlineSnapshot(
'"npx create-typescript-app --mode initialize --base everything --access public --author TestAuthor --create-repository true --description \\"Test description.\\" --email-github github@email.com --email-npm npm@email.com --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 github@email.com --email-npm npm@email.com --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.\\" --mode initialize --owner TestOwner --repository test-repository --skip-github-api true --skip-install true --skip-removal true --title \\"Test Title\\""',
);
});

it("includes exclusions when they exist", () => {
const actual = createRerunSuggestion("initialize", {
const actual = createRerunSuggestion({
...options,
excludeCompliance: true,
excludeLintMd: true,
excludeLintSpelling: true,
mode: "initialize",
});

expect(actual).toMatchInlineSnapshot(
'"npx create-typescript-app --mode initialize --base everything --access public --author TestAuthor --create-repository true --description \\"Test description.\\" --email-github github@email.com --email-npm npm@email.com --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 github@email.com --email-npm npm@email.com --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 --mode initialize --owner TestOwner --repository test-repository --skip-github-api true --skip-install true --skip-removal true --title \\"Test Title\\""',
);
});
});
8 changes: 2 additions & 6 deletions src/create/createRerunSuggestion.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Mode } from "../bin/mode.js";
import { allArgOptions } from "../shared/options/args.js";
import { Options } from "../shared/types.js";

Expand All @@ -8,10 +7,7 @@ function getFirstMatchingArg(key: string) {
);
}

export function createRerunSuggestion(
mode: Mode,
options: Partial<Options>,
): string {
export function createRerunSuggestion(options: Partial<Options>): string {
const optionsNormalized = {
...options,
...(options.email
Expand Down Expand Up @@ -42,5 +38,5 @@ export function createRerunSuggestion(
})
.join(" ");

return `npx create-typescript-app --mode ${mode} ${args}`;
return `npx create-typescript-app --mode ${options.mode} ${args}`;
}
2 changes: 1 addition & 1 deletion src/create/createWithOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function createWithOptions({ github, options }: GitHubAndOptions) {
[
"Writing structure",
async () => {
await writeStructure(options, "create");
await writeStructure(options);
},
],
[
Expand Down
5 changes: 3 additions & 2 deletions src/create/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { createRerunSuggestion } from "./createRerunSuggestion.js";
import { createWithOptions } from "./createWithOptions.js";

export async function create(args: string[]): Promise<ModeResult> {
const inputs = await readOptions(args);
const inputs = await readOptions(args, "create");
if (inputs.cancelled) {
return {
code: StatusCodes.Cancelled,
Expand Down Expand Up @@ -49,8 +49,9 @@ export async function create(args: string[]): Promise<ModeResult> {
"Consider creating a GitHub repository from the new directory:",
lines: [
`cd ${inputs.options.repository}`,
createRerunSuggestion("initialize", {
createRerunSuggestion({
...inputs.options,
mode: "initialize",
skipGitHubApi: false,
skipInstall: false,
}),
Expand Down
2 changes: 1 addition & 1 deletion src/initialize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { runOrRestore } from "../shared/runOrRestore.js";
import { initializeWithOptions } from "./initializeWithOptions.js";

export const initialize: ModeRunner = async (args) => {
const inputs = await readOptions(args);
const inputs = await readOptions(args, "initialize");
if (inputs.cancelled) {
return {
code: StatusCodes.Cancelled,
Expand Down
2 changes: 1 addition & 1 deletion src/initialize/initializeWithOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function initializeWithOptions({
[
"Updating local files",
async () => {
await updateLocalFiles(options, "initialize");
await updateLocalFiles(options);
},
],
["Updating README.md", updateReadme],
Expand Down
2 changes: 1 addition & 1 deletion src/migrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { runOrRestore } from "../shared/runOrRestore.js";
import { migrateWithOptions } from "./migrateWithOptions.js";

export const migrate: ModeRunner = async (args) => {
const inputs = await readOptions(args);
const inputs = await readOptions(args, "migrate");
if (inputs.cancelled) {
return {
code: StatusCodes.Cancelled,
Expand Down
4 changes: 2 additions & 2 deletions src/migrate/migrateWithOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function migrateWithOptions({
[
"Writing structure",
async () => {
await writeStructure(options, "migrate");
await writeStructure(options);
},
],
[
Expand All @@ -31,7 +31,7 @@ export async function migrateWithOptions({
[
"Updating local files",
async () => {
await updateLocalFiles(options, "migrate");
await updateLocalFiles(options);
},
],
[
Expand Down
1 change: 1 addition & 0 deletions src/shared/options/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const allArgOptions = {
funding: { type: "string" },
logo: { type: "string" },
"logo-alt": { type: "string" },
mode: { type: "string" },
owner: { type: "string" },
repository: { type: "string" },
"skip-github-api": { type: "boolean" },
Expand Down
1 change: 1 addition & 0 deletions src/shared/options/augmentOptionsWithExcludes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const optionsBase = {
excludeTests: undefined,
funding: undefined,
logo: undefined,
mode: "create",
owner: "",
repository: "",
skipGitHubApi: false,
Expand Down
3 changes: 3 additions & 0 deletions src/shared/options/optionsSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export const optionsSchemaShape = {
funding: z.string().optional(),
logo: z.string().optional(),
logoAlt: z.string().optional(),
mode: z
.union([z.literal("create"), z.literal("initialize"), z.literal("migrate")])
.optional(),
owner: z.string().optional(),
repository: z.string().optional(),
skipGitHubApi: z.boolean().optional(),
Expand Down
24 changes: 13 additions & 11 deletions src/shared/options/readOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe("readOptions", () => {
.object({ base: optionsSchemaShape.base })
.safeParse({ base: "b" });

const actual = await readOptions(["--base", "b"]);
const actual = await readOptions(["--base", "b"], "create");

expect(actual).toStrictEqual({
cancelled: true,
Expand All @@ -126,7 +126,7 @@ describe("readOptions", () => {
mockDetectEmailRedundancy.mockReturnValue(error);
mockGetPrefillOrPromptedOption.mockImplementation(() => undefined);

expect(await readOptions([])).toStrictEqual({
expect(await readOptions([], "create")).toStrictEqual({
cancelled: true,
error,
options: {
Expand All @@ -139,7 +139,7 @@ describe("readOptions", () => {
mockDetectEmailRedundancy.mockReturnValue(false);
mockGetPrefillOrPromptedOption.mockImplementation(() => undefined);

expect(await readOptions([])).toStrictEqual({
expect(await readOptions([], "create")).toStrictEqual({
cancelled: true,
options: {
...emptyOptions,
Expand All @@ -153,7 +153,7 @@ describe("readOptions", () => {
.mockImplementationOnce(() => "MockOwner")
.mockImplementation(() => undefined);

expect(await readOptions([])).toStrictEqual({
expect(await readOptions([], "create")).toStrictEqual({
cancelled: true,
options: {
...emptyOptions,
Expand All @@ -170,7 +170,7 @@ describe("readOptions", () => {
.mockImplementation(() => undefined);
mockEnsureRepositoryExists.mockResolvedValue({});

expect(await readOptions([])).toStrictEqual({
expect(await readOptions([], "create")).toStrictEqual({
cancelled: true,
options: {
...emptyOptions,
Expand All @@ -191,7 +191,7 @@ describe("readOptions", () => {
repository: mockOptions.repository,
});

expect(await readOptions([])).toStrictEqual({
expect(await readOptions([], "create")).toStrictEqual({
cancelled: true,
options: {
...emptyOptions,
Expand All @@ -213,7 +213,7 @@ describe("readOptions", () => {
repository: mockOptions.repository,
});

expect(await readOptions([])).toStrictEqual({
expect(await readOptions([], "create")).toStrictEqual({
cancelled: true,
options: {
...emptyOptions,
Expand All @@ -236,7 +236,7 @@ describe("readOptions", () => {
repository: mockOptions.repository,
});

expect(await readOptions(["--logo", "logo.svg"])).toStrictEqual({
expect(await readOptions(["--logo", "logo.svg"], "create")).toStrictEqual({
cancelled: true,
options: {
...emptyOptions,
Expand All @@ -260,7 +260,7 @@ describe("readOptions", () => {
repository: mockOptions.repository,
});

expect(await readOptions([])).toStrictEqual({
expect(await readOptions([], "create")).toStrictEqual({
cancelled: true,
options: {
...emptyOptions,
Expand All @@ -286,7 +286,7 @@ describe("readOptions", () => {
});
mockAugmentOptionsWithExcludes.mockResolvedValue(undefined);

expect(await readOptions([])).toStrictEqual({
expect(await readOptions([], "create")).toStrictEqual({
cancelled: true,
options: {
...emptyOptions,
Expand All @@ -305,7 +305,9 @@ describe("readOptions", () => {
});
mockGetPrefillOrPromptedOption.mockImplementation(() => "mock");

expect(await readOptions(["--base", mockOptions.base])).toStrictEqual({
expect(
await readOptions(["--base", mockOptions.base], "create"),
).toStrictEqual({
cancelled: false,
github: mockOptions.github,
options: {
Expand Down
7 changes: 6 additions & 1 deletion src/shared/options/readOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { parseArgs } from "node:util";
import { titleCase } from "title-case";
import { z } from "zod";

import { Mode } from "../../bin/mode.js";
import { withSpinner } from "../cli/spinners.js";
import { Options, OptionsLogo } from "../types.js";
import { allArgOptions } from "./args.js";
Expand Down Expand Up @@ -30,7 +31,10 @@ export interface OptionsParseSuccess extends GitHubAndOptions {

export type OptionsParseResult = OptionsParseCancelled | OptionsParseSuccess;

export async function readOptions(args: string[]): Promise<OptionsParseResult> {
export async function readOptions(
args: string[],
mode: Mode,
): Promise<OptionsParseResult> {
const defaults = readOptionDefaults();
const { values } = parseArgs({
args,
Expand Down Expand Up @@ -193,6 +197,7 @@ export async function readOptions(args: string[]): Promise<OptionsParseResult> {
email: typeof email === "string" ? { github: email, npm: email } : email,
funding: options.funding ?? (await defaults.funding()),
logo,
mode,
owner: options.owner,
repository,
title: options.title,
Expand Down
3 changes: 3 additions & 0 deletions src/shared/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Mode } from "../bin/mode.js";

export interface AllContributorContributor {
contributions: string[];
login: string;
Expand Down Expand Up @@ -59,6 +61,7 @@ export interface Options {
excludeTests?: boolean;
funding?: string;
logo: OptionsLogo | undefined;
mode: Mode;
owner: string;
repository: string;
skipGitHubApi?: boolean;
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 @@ -41,6 +41,7 @@ const options = {
excludeTests: undefined,
funding: undefined,
logo: undefined,
mode: "create",
owner: "StubOwner",
repository: "stub-repository",
skipGitHubApi: false,
Expand Down
Loading