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
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
@@ -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",
@@ -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: [
2 changes: 1 addition & 1 deletion script/create-test-e2e.js
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import { strict as assert } from "node:assert";
const author = "Test Author";
const description = "Test description.";
const email = "[email protected]";
const repository = "test-repository";
const repository = "create-typescript-app";
const owner = "TestOwner";
const title = "Test Title";

2 changes: 1 addition & 1 deletion src/bin/index.ts
Original file line number Diff line number Diff line change
@@ -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(" "),
);

15 changes: 9 additions & 6 deletions src/create/createRerunSuggestion.test.ts
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ const options = {
excludeTests: undefined,
funding: undefined,
logo: undefined,
mode: "create",
owner: "TestOwner",
repository: "test-repository",
skipGitHubApi: true,
@@ -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 [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 create --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 --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 [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.\\" --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 [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 --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";

@@ -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
@@ -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
@@ -16,7 +16,7 @@ export async function createWithOptions({ github, options }: GitHubAndOptions) {
[
"Writing structure",
async () => {
await writeStructure(options, "create");
await writeStructure(options);
},
],
[
5 changes: 3 additions & 2 deletions src/create/index.ts
Original file line number Diff line number Diff line change
@@ -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,
@@ -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,
}),
2 changes: 1 addition & 1 deletion src/initialize/index.ts
Original file line number Diff line number Diff line change
@@ -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,
2 changes: 1 addition & 1 deletion src/initialize/initializeWithOptions.ts
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ export async function initializeWithOptions({
[
"Updating local files",
async () => {
await updateLocalFiles(options, "initialize");
await updateLocalFiles(options);
},
],
["Updating README.md", updateReadme],
2 changes: 1 addition & 1 deletion src/migrate/index.ts
Original file line number Diff line number Diff line change
@@ -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,
4 changes: 2 additions & 2 deletions src/migrate/migrateWithOptions.ts
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ export async function migrateWithOptions({
[
"Writing structure",
async () => {
await writeStructure(options, "migrate");
await writeStructure(options);
},
],
[
@@ -31,7 +31,7 @@ export async function migrateWithOptions({
[
"Updating local files",
async () => {
await updateLocalFiles(options, "migrate");
await updateLocalFiles(options);
},
],
[
1 change: 1 addition & 0 deletions src/shared/options/args.ts
Original file line number Diff line number Diff line change
@@ -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" },
1 change: 1 addition & 0 deletions src/shared/options/augmentOptionsWithExcludes.test.ts
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@ const optionsBase = {
excludeTests: undefined,
funding: undefined,
logo: undefined,
mode: "create",
owner: "",
repository: "",
skipGitHubApi: false,
3 changes: 3 additions & 0 deletions src/shared/options/optionsSchema.ts
Original file line number Diff line number Diff line change
@@ -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(),
24 changes: 13 additions & 11 deletions src/shared/options/readOptions.test.ts
Original file line number Diff line number Diff line change
@@ -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,
@@ -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: {
@@ -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,
@@ -153,7 +153,7 @@ describe("readOptions", () => {
.mockImplementationOnce(() => "MockOwner")
.mockImplementation(() => undefined);

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

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

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

expect(await readOptions([])).toStrictEqual({
expect(await readOptions([], "create")).toStrictEqual({
cancelled: true,
options: {
...emptyOptions,
@@ -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,
@@ -260,7 +260,7 @@ describe("readOptions", () => {
repository: mockOptions.repository,
});

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

expect(await readOptions([])).toStrictEqual({
expect(await readOptions([], "create")).toStrictEqual({
cancelled: true,
options: {
...emptyOptions,
@@ -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: {
7 changes: 6 additions & 1 deletion src/shared/options/readOptions.ts
Original file line number Diff line number Diff line change
@@ -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";
@@ -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,
@@ -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,
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;
@@ -59,6 +61,7 @@ export interface Options {
excludeTests?: boolean;
funding?: string;
logo: OptionsLogo | undefined;
mode: Mode;
owner: string;
repository: string;
skipGitHubApi?: boolean;
1 change: 1 addition & 0 deletions src/steps/finalizeDependencies.test.ts
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@ const options = {
excludeTests: undefined,
funding: undefined,
logo: undefined,
mode: "create",
owner: "StubOwner",
repository: "stub-repository",
skipGitHubApi: false,
Loading