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 help cli #775

Merged
merged 64 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
00a74fa
feat: Add help CLI option in progress
dominicduffin1 Sep 2, 2023
7d2d598
Fix lint errors
dominicduffin1 Sep 3, 2023
42f002f
Merge branch 'main' of https://github.com/JoshuaKGoldberg/create-type…
dominicduffin1 Sep 3, 2023
cd19059
Fix merge conflict markers from weird VS Code issue
dominicduffin1 Sep 3, 2023
50d5bab
Merge branch 'main' of https://github.com/JoshuaKGoldberg/create-type…
dominicduffin1 Sep 9, 2023
21bf2b9
Get version from package.json and reduce duplication
dominicduffin1 Sep 9, 2023
44c929d
Help function refactor in progress
dominicduffin1 Sep 9, 2023
27cf5d2
Dedeuplication and automation of help printouts
dominicduffin1 Sep 10, 2023
890252c
Merge branch 'main' of https://github.com/JoshuaKGoldberg/create-type…
dominicduffin1 Sep 10, 2023
f966a41
Remove magenta highlighting
dominicduffin1 Sep 11, 2023
1bd67b8
Use URL for package.json import
dominicduffin1 Sep 16, 2023
8be564a
Remove pipes and formattng fixes for help section
dominicduffin1 Sep 16, 2023
d33e8f2
Fix lint errors
dominicduffin1 Sep 16, 2023
d930895
Merge branch 'main' of https://github.com/JoshuaKGoldberg/create-type…
dominicduffin1 Sep 16, 2023
58b2384
Merge branch 'add-help-cli' of https://github.com/dominicduffin1/crea…
dominicduffin1 Sep 16, 2023
32d6750
Merge branch 'main' of https://github.com/JoshuaKGoldberg/create-type…
dominicduffin1 Sep 17, 2023
bdf1704
Merge branch 'main' into add-help-cli
JoshuaKGoldberg Sep 18, 2023
e535b5a
Test descriptions consistent with repo conventions
dominicduffin1 Sep 20, 2023
0b68c65
Remove logPipelessLine function
dominicduffin1 Sep 20, 2023
bc66991
Merge branch 'add-help-cli' of https://github.com/dominicduffin1/crea…
dominicduffin1 Sep 20, 2023
5286d89
Cleanup unnecessary typeof
dominicduffin1 Sep 20, 2023
c2c9a82
Cleanup unnecessary typeof
dominicduffin1 Sep 20, 2023
a593594
Fix spacing in welcome text
dominicduffin1 Sep 20, 2023
f3aa25b
Cleanup help section looping
dominicduffin1 Sep 28, 2023
a9ed7c4
Cleanup help file
dominicduffin1 Sep 28, 2023
3b996a7
Fix lint errors
dominicduffin1 Sep 28, 2023
731d3f3
Throw error if package version not found
dominicduffin1 Oct 5, 2023
bd3a60f
Remove typeof check from package json test
dominicduffin1 Oct 5, 2023
7649696
Merge branch 'main' of https://github.com/JoshuaKGoldberg/create-type…
dominicduffin1 Oct 5, 2023
8668e25
Add help entries for new options
dominicduffin1 Oct 7, 2023
05ea1d0
Add missing argument from merge conflict resolution
dominicduffin1 Oct 7, 2023
ec14a93
Merge branch 'main' of https://github.com/JoshuaKGoldberg/create-type…
dominicduffin1 Oct 7, 2023
7de38f2
Remove type assertion
dominicduffin1 Oct 9, 2023
8abad7c
Cleanup package.json test
dominicduffin1 Oct 9, 2023
7fa04e5
Inline destructuring of subsection.flags
dominicduffin1 Oct 13, 2023
c8e273d
Rename Flag interface for clarity
dominicduffin1 Oct 13, 2023
7688582
Make possible undefined properties in HelpTextSection be optional
dominicduffin1 Oct 13, 2023
0621415
Remove undefined properties
dominicduffin1 Oct 13, 2023
74621d3
Revise help output to not have pipes at top (without indentation)
dominicduffin1 Oct 15, 2023
65e20d9
Help indentation
dominicduffin1 Oct 19, 2023
6a13230
Options code simplification
dominicduffin1 Oct 19, 2023
25689b2
Warning indentation
dominicduffin1 Oct 19, 2023
1b8e714
Attempt to mock an invalid package json file for testing
dominicduffin1 Oct 21, 2023
c037573
Add help cli test
dominicduffin1 Oct 21, 2023
809a3ec
Merge branch 'main' of https://github.com/JoshuaKGoldberg/create-type…
dominicduffin1 Oct 22, 2023
6c2589e
Merge branch 'main' of https://github.com/JoshuaKGoldberg/create-type…
dominicduffin1 Oct 26, 2023
d1b8730
Fix error from merge
dominicduffin1 Oct 26, 2023
5bfe967
Update help snapshot with new options
dominicduffin1 Oct 26, 2023
800ef74
Fix lint issues
dominicduffin1 Oct 26, 2023
3ac59db
Help CLI output tweaks
dominicduffin1 Oct 27, 2023
471ee66
Merge branch 'main' of https://github.com/JoshuaKGoldberg/create-type…
dominicduffin1 Oct 27, 2023
314233b
Exclude help snapshot from spelling linter
dominicduffin1 Oct 30, 2023
f3b22a6
Merge branch 'main' of https://github.com/JoshuaKGoldberg/create-type…
dominicduffin1 Oct 30, 2023
5fe93c3
Revise package.json test
dominicduffin1 Nov 1, 2023
fb97a83
Merge branch 'main' of https://github.com/JoshuaKGoldberg/create-type…
dominicduffin1 Nov 1, 2023
68ea2df
Comment failing test
dominicduffin1 Nov 2, 2023
d9da2ce
Update src/bin/packageJson.test.ts
dominicduffin1 Nov 3, 2023
07d413c
Apply package json test fixes
dominicduffin1 Nov 3, 2023
1716013
Mock chalk in help output test
dominicduffin1 Nov 3, 2023
9a1d298
Update help snapshot
dominicduffin1 Nov 3, 2023
9ccbbb3
Use inline snapshot
dominicduffin1 Nov 5, 2023
86753e8
Remove lint:spelling ignorePath
dominicduffin1 Nov 5, 2023
5f909d7
Merge branch 'main' of https://github.com/JoshuaKGoldberg/create-type…
dominicduffin1 Nov 5, 2023
8ad0980
Merge branch 'main' of https://github.com/JoshuaKGoldberg/create-type…
dominicduffin1 Nov 7, 2023
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
230 changes: 230 additions & 0 deletions src/bin/help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
import chalk from "chalk";

import { logLine } from "../shared/cli/lines.js";

export function logHelpText(version: string): void {
logLine();

logLine(chalk.cyan(`✨ template-typescript-node-package v${version} ✨`));

logLine(
chalk.cyan(
`
A quickstart-friendly TypeScript template with comprehensive formatting,
linting, releases, testing, and other great tooling built-in.
`,
),
);

logLine();

logLine(chalk.black.bgGreenBright("Core options:"));

logLine(
chalk.cyan(
`
--base: Whether to scaffold the repository with:
• everything: that comes with the template (${chalk.cyanBright.bold(
"recommended",
)})
• minimum: amounts of tooling, essentially opting out of everything
• prompt: for which portions to exclude
`,
`
--create-repository: 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
• migrate: an existing repository in the current directory
`,
`
--description (${chalk.cyanBright.bold(
"string",
)}): Sentence case description of the repository
(e.g. A quickstart-friendly TypeScript package with lots of great
repository tooling. ✨)
`,
`
--owner (${chalk.cyanBright.bold(
"string",
)}): GitHub organization or user the repository is
underneath (e.g. JoshuaKGoldberg)
`,
`
--repository (${chalk.cyanBright.bold(
"string",
)}): The kebab-case name of the repository
(e.g. create-typescript-app)
`,
`
--title (${chalk.cyanBright.bold(
"string",
)}): Title Case title for the repository to be used in
documentation (e.g. Create TypeScript App)
`,
),
);

logLine();

logLine(chalk.black.bgGreenBright("Optional options:"));

logLine(
chalk.cyan(
`
--author (${chalk.cyanBright.bold(
"string",
)}): Username on npm to publish packages under (by
default, an existing npm author, or the currently logged in npm user,
or ${chalk.cyanBright("owner.")}${chalk.magentaBright("toLowerCase()")})
`,
`
--email (${chalk.cyanBright.bold(
"string",
)}): Email address to be listed as the point of contact in
docs and packages (e.g. [email protected])
`,
`
--funding (${chalk.cyanBright.bold(
"string",
)}): GitHub organization or username to mention in
${chalk.cyanBright("funding.yml")} (by default, owner)
`,
),
);

logLine();

logLine(chalk.black.bgGreenBright("Opt-outs:"));

logLine();

logLine(
chalk.yellow(
`
⚠️ Warning: Specifying any --exclude-* flag on the command-line will
cause the setup script to skip prompting for more excludes. ⚠️
`,
),
);

logLine(
chalk.cyan(
`
--exclude-compliance: Don't add a GitHub Actions workflow to verify that
PRs match an expected format.
`,
`
--exclude-contributors: Don't add all-contributors to track contributions
and display them in a README.md table.
`,
`
--exclude-lint-json: Don't apply linting and sorting to ${chalk.cyanBright(
"*.json",
)} and
${chalk.cyanBright("*.jsonc")} files.
`,
`
--exclude-lint-knip: Don't add Knip to detect unused files, dependencies,
and code exports.
`,
`
--exclude-lint-md: Don't apply linting to ${chalk.cyanBright(
"*.md",
)} files.
`,
`
--exclude-lint-package-json: Don't add npm-package-json-lint to lint for
package.json correctness.
`,
`
--exclude-lint-packages: Don't add a pnpm dedupe workflow to ensure
packages aren't duplicated unnecessarily.
`,
`
--exclude-lint-perfectionist: Don't apply eslint-plugin-perfectionist to
ensure imports, keys, and so on are in sorted order.
`,
`
--exclude-lint-spelling: Don't add cspell to spell check against
dictionaries of known words.
`,
`
--exclude-lint-yml: Don't apply linting and sorting to ${chalk.cyanBright(
"*.yaml",
)} and ${chalk.cyanBright("*.yml")}
files.
`,
`
--exclude-releases: Don't add release-it to generate changelogs, package
bumps, and publishes based on conventional commits.
`,
`
--exclude-renovate: Don't add a Renovate config to dependencies
up-to-date with PRs.
`,
`
--exclude-tests: Don't add Vitest tooling for fast unit tests, configured
with coverage tracking.
`,
),
);

logLine();

logLine(
chalk.green(
`
You can prevent the migration script from making some network-based
changes using any or all of the following CLI flags:
`,
),
);

logLine(
chalk.cyan(
`
--exclude-contributors: Skips network calls that fetch
all-contributors data from GitHub
`,
`
--skip-github-api: Skips calling to GitHub APIs.
`,
`
--skip-install: Skips installing all the new template
packages with pnpm.
`,
),
);

logLine();

logLine(
chalk.green(
`
You can prevent the migration script from making some changes on disk
using any or all of the following CLI flags:
`,
),
);

logLine(
chalk.cyan(
`
--skip-removal: Skips removing setup docs and scripts,
including this ${chalk.cyanBright("docs/")} directory
`,
`
--skip-restore: Skips the prompt offering to restore the
repository if an error occurs during setup
`,
`
--skip-uninstall: Skips uninstalling packages only used for
setup scripts
`,
),
);
}
12 changes: 12 additions & 0 deletions src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { create } from "../create/index.js";
import { initialize } from "../initialize/index.js";
import { migrate } from "../migrate/index.js";
import { logLine } from "../shared/cli/lines.js";
import { logHelpText } from "./help.js";
import { StatusCodes } from "../shared/codes.js";
import { promptForMode } from "./mode.js";

Expand Down Expand Up @@ -39,11 +40,22 @@ export async function bin(args: string[]) {
const { values } = parseArgs({
args,
options: {
help: {
short: "h",
type: "boolean",
},
mode: { type: "string" },
},
strict: false,
});

const help = values.help;

if (help) {
logHelpText("");
return 0;
}

const mode = await promptForMode(values.mode);
if (typeof mode !== "string") {
prompts.outro(chalk.red(mode?.message ?? operationMessage("cancelled")));
Expand Down