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: base suggested next steps on options #906

Merged
merged 3 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ module.exports = {
allowConstantLoopConditions: true,
},
],
"@typescript-eslint/prefer-nullish-coalescing": [
"error",
{ ignorePrimitives: true },
],
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that I can use booleanValue || somethingMoreComplex in the new function.

},
},
{
Expand Down
3 changes: 2 additions & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"tada",
"tsup",
"Unstaged",
"wontfix"
"wontfix",
"vitest"
]
}
15 changes: 5 additions & 10 deletions src/create/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import chalk from "chalk";
import { ModeResult } from "../bin/mode.js";
import { outro } from "../shared/cli/outro.js";
import { StatusCodes } from "../shared/codes.js";
import { generateNextSteps } from "../shared/generateNextSteps.js";
import { readOptions } from "../shared/options/readOptions.js";
import { runOrRestore } from "../shared/runOrRestore.js";
import { createAndEnterRepository } from "./createAndEnterRepository.js";
Expand Down Expand Up @@ -34,15 +35,11 @@ export async function create(args: string[]): Promise<ModeResult> {
code: await runOrRestore({
run: async () => {
const { sentToGitHub } = await createWithOptions(inputs);
const nextSteps = generateNextSteps(inputs.options);

outro(
sentToGitHub
? [
{
label:
"Now all you have to do is populate the repository's ACCESS_TOKEN and NPM_TOKEN secrets, and enable the Codecov and Renovate GitHub apps.",
},
]
? nextSteps
: [
{
label:
Expand All @@ -59,11 +56,9 @@ export async function create(args: string[]): Promise<ModeResult> {
`git commit -m "feat: initial commit ✨"`,
`git push -u origin main`,
],
variant: "code",
},
{
label:
"If you do, be sure to populate its ACCESS_TOKEN and NPM_TOKEN secrets, and enable the Codecov and Renovate GitHub apps.",
},
...nextSteps,
],
);
},
Expand Down
7 changes: 3 additions & 4 deletions src/initialize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ModeRunner } from "../bin/mode.js";
import { outro } from "../shared/cli/outro.js";
import { StatusCodes } from "../shared/codes.js";
import { ensureGitRepository } from "../shared/ensureGitRepository.js";
import { generateNextSteps } from "../shared/generateNextSteps.js";
import { readOptions } from "../shared/options/readOptions.js";
import { runOrRestore } from "../shared/runOrRestore.js";
import { initializeWithOptions } from "./initializeWithOptions.js";
Expand Down Expand Up @@ -31,11 +32,9 @@ export const initialize: ModeRunner = async (args) => {
`git commit -m "feat: initialized repo ✨`,
`git push`,
],
variant: "code",
},
{
label:
"Otherwise, all you have to do is populate the repository's ACCESS_TOKEN and NPM_TOKEN secrets, and enable the Codecov and Renovate GitHub apps.",
},
...generateNextSteps(inputs.options),
]);
},
skipRestore: inputs.options.skipRestore,
Expand Down
3 changes: 3 additions & 0 deletions src/migrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ModeRunner } from "../bin/mode.js";
import { outro } from "../shared/cli/outro.js";
import { StatusCodes } from "../shared/codes.js";
import { ensureGitRepository } from "../shared/ensureGitRepository.js";
import { generateNextSteps } from "../shared/generateNextSteps.js";
import { readOptions } from "../shared/options/readOptions.js";
import { runOrRestore } from "../shared/runOrRestore.js";
import { migrateWithOptions } from "./migrateWithOptions.js";
Expand Down Expand Up @@ -31,7 +32,9 @@ export const migrate: ModeRunner = async (args) => {
`git commit -m "migrated repo to create-typescript-app ✨`,
`git push`,
],
variant: "code",
},
...generateNextSteps(inputs.options),
]);
},
skipRestore: inputs.options.skipRestore,
Expand Down
183 changes: 183 additions & 0 deletions src/shared/__snapshots__/generateNextSteps.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`generateNextSteps > {"excludeAllContributors":false,"excludeReleases":false,"excludeRenovate":false,"excludeTests":false} 1`] = `
[
{
"label": "Be sure to:",
"lines": [
"- enable the GitHub apps:
- Codecov (https://github.com/apps/codecov)
- Renovate (https://github.com/apps/renovate)",
"- populate the secrets:
- ACCESS_TOKEN (a GitHub PAT with repo and workflow permissions)
- NPM_TOKEN (an npm access token with automation permissions)",
],
},
]
`;

exports[`generateNextSteps > {"excludeAllContributors":false,"excludeReleases":false,"excludeRenovate":false,"excludeTests":true} 1`] = `
[
{
"label": "Be sure to:",
"lines": [
"- enable the Renovate GitHub app (https://github.com/apps/renovate).",
"- populate the secrets:
- ACCESS_TOKEN (a GitHub PAT with repo and workflow permissions)
- NPM_TOKEN (an npm access token with automation permissions)",
],
},
]
`;

exports[`generateNextSteps > {"excludeAllContributors":false,"excludeReleases":false,"excludeRenovate":true,"excludeTests":false} 1`] = `
[
{
"label": "Be sure to:",
"lines": [
"- enable the Codecov GitHub app (https://github.com/apps/codecov).",
"- populate the secrets:
- ACCESS_TOKEN (a GitHub PAT with repo and workflow permissions)
- NPM_TOKEN (an npm access token with automation permissions)",
],
},
]
`;

exports[`generateNextSteps > {"excludeAllContributors":false,"excludeReleases":false,"excludeRenovate":true,"excludeTests":true} 1`] = `
[
{
"label": "Be sure to populate the secrets:
- ACCESS_TOKEN (a GitHub PAT with repo and workflow permissions)
- NPM_TOKEN (an npm access token with automation permissions)",
},
]
`;

exports[`generateNextSteps > {"excludeAllContributors":false,"excludeReleases":true,"excludeRenovate":false,"excludeTests":false} 1`] = `
[
{
"label": "Be sure to:",
"lines": [
"- enable the GitHub apps:
- Codecov (https://github.com/apps/codecov)
- Renovate (https://github.com/apps/renovate)",
"- populate the ACCESS_TOKEN secret (a GitHub PAT with repo and workflow permissions).",
],
},
]
`;

exports[`generateNextSteps > {"excludeAllContributors":false,"excludeReleases":true,"excludeRenovate":false,"excludeTests":true} 1`] = `
[
{
"label": "Be sure to:",
"lines": [
"- enable the Renovate GitHub app (https://github.com/apps/renovate).",
"- populate the ACCESS_TOKEN secret (a GitHub PAT with repo and workflow permissions).",
],
},
]
`;

exports[`generateNextSteps > {"excludeAllContributors":false,"excludeReleases":true,"excludeRenovate":true,"excludeTests":false} 1`] = `
[
{
"label": "Be sure to:",
"lines": [
"- enable the Codecov GitHub app (https://github.com/apps/codecov).",
"- populate the ACCESS_TOKEN secret (a GitHub PAT with repo and workflow permissions).",
],
},
]
`;

exports[`generateNextSteps > {"excludeAllContributors":false,"excludeReleases":true,"excludeRenovate":true,"excludeTests":true} 1`] = `
[
{
"label": "Be sure to populate the ACCESS_TOKEN secret (a GitHub PAT with repo and workflow permissions).",
},
]
`;

exports[`generateNextSteps > {"excludeAllContributors":true,"excludeReleases":false,"excludeRenovate":false,"excludeTests":false} 1`] = `
[
{
"label": "Be sure to:",
"lines": [
"- enable the GitHub apps:
- Codecov (https://github.com/apps/codecov)
- Renovate (https://github.com/apps/renovate)",
"- populate the secrets:
- ACCESS_TOKEN (a GitHub PAT with repo and workflow permissions)
- NPM_TOKEN (an npm access token with automation permissions)",
],
},
]
`;

exports[`generateNextSteps > {"excludeAllContributors":true,"excludeReleases":false,"excludeRenovate":false,"excludeTests":true} 1`] = `
[
{
"label": "Be sure to:",
"lines": [
"- enable the Renovate GitHub app (https://github.com/apps/renovate).",
"- populate the secrets:
- ACCESS_TOKEN (a GitHub PAT with repo and workflow permissions)
- NPM_TOKEN (an npm access token with automation permissions)",
],
},
]
`;

exports[`generateNextSteps > {"excludeAllContributors":true,"excludeReleases":false,"excludeRenovate":true,"excludeTests":false} 1`] = `
[
{
"label": "Be sure to:",
"lines": [
"- enable the Codecov GitHub app (https://github.com/apps/codecov).",
"- populate the secrets:
- ACCESS_TOKEN (a GitHub PAT with repo and workflow permissions)
- NPM_TOKEN (an npm access token with automation permissions)",
],
},
]
`;

exports[`generateNextSteps > {"excludeAllContributors":true,"excludeReleases":false,"excludeRenovate":true,"excludeTests":true} 1`] = `
[
{
"label": "Be sure to populate the secrets:
- ACCESS_TOKEN (a GitHub PAT with repo and workflow permissions)
- NPM_TOKEN (an npm access token with automation permissions)",
},
]
`;

exports[`generateNextSteps > {"excludeAllContributors":true,"excludeReleases":true,"excludeRenovate":false,"excludeTests":false} 1`] = `
[
{
"label": "Be sure to enable the GitHub apps:
- Codecov (https://github.com/apps/codecov)
- Renovate (https://github.com/apps/renovate)",
},
]
`;

exports[`generateNextSteps > {"excludeAllContributors":true,"excludeReleases":true,"excludeRenovate":false,"excludeTests":true} 1`] = `
[
{
"label": "Be sure to enable the Renovate GitHub app (https://github.com/apps/renovate).",
},
]
`;

exports[`generateNextSteps > {"excludeAllContributors":true,"excludeReleases":true,"excludeRenovate":true,"excludeTests":false} 1`] = `
[
{
"label": "Be sure to enable the Codecov GitHub app (https://github.com/apps/codecov).",
},
]
`;

exports[`generateNextSteps > {"excludeAllContributors":true,"excludeReleases":true,"excludeRenovate":true,"excludeTests":true} 1`] = `[]`;
14 changes: 14 additions & 0 deletions src/shared/cli/outro.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ describe("outro", () => {
it("also logs lines when provided", () => {
outro([{ label: "Abc 123", lines: ["one", "two"] }]);

expect(mockConsoleLog.mock.calls).toEqual([
[chalk.blue("Abc 123")],
[],
["one"],
["two"],
[],
[chalk.greenBright(`See ya! 👋`)],
[],
]);
});

it("logs lines as code when variant is specified", () => {
outro([{ label: "Abc 123", lines: ["one", "two"], variant: "code" }]);

expect(mockConsoleLog.mock.calls).toEqual([
[chalk.blue("Abc 123")],
[],
Expand Down
9 changes: 5 additions & 4 deletions src/shared/cli/outro.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import * as prompts from "@clack/prompts";
import chalk from "chalk";

export interface outroGroup {
export interface OutroGroup {
label: string;
lines?: string[];
variant?: "code";
}

export function outro(groups: outroGroup[]) {
export function outro(groups: OutroGroup[]) {
prompts.outro(chalk.blue(`Great, looks like the script finished! 🎉`));

for (const { label, lines } of groups) {
for (const { label, lines, variant } of groups) {
console.log(chalk.blue(label));
console.log();

if (lines) {
for (const line of lines) {
console.log(chalk.gray(line));
console.log(variant === "code" ? chalk.gray(line) : line);
}

console.log();
Expand Down
50 changes: 50 additions & 0 deletions src/shared/generateNextSteps.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { describe, expect, test } from "vitest";

import { generateNextSteps } from "./generateNextSteps.js";
import { Options } from "./types.js";

const options = {
access: "public",
base: "everything",
description: "Test description.",
email: {
github: "[email protected]",
npm: "[email protected]",
},
logo: undefined,
mode: "create",
owner: "TestOwner",
repository: "test-repository",
title: "Test Title",
} satisfies Options;

describe("generateNextSteps", () => {
for (const excludeAllContributors of [false, true]) {
for (const excludeReleases of [false, true]) {
for (const excludeRenovate of [false, true]) {
for (const excludeTests of [false, true]) {
test(
// eslint-disable-next-line vitest/valid-title
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON.stringify({
excludeAllContributors,
excludeReleases,
excludeRenovate,
excludeTests,
}),
() => {
expect(
generateNextSteps({
...options,
excludeAllContributors,
excludeReleases,
excludeRenovate,
excludeTests,
}),
).toMatchSnapshot();
},
);
}
}
}
}
});
Loading