Skip to content

Commit d5b612d

Browse files
authored
fix: adapt for @octoherd/cli v3 (#31)
1 parent 8259809 commit d5b612d

File tree

1 file changed

+49
-38
lines changed

1 file changed

+49
-38
lines changed

lib/create-readme.js

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ export default async function createReadme({
1717

1818
if (addWip) {
1919
// WIP banner
20-
content += `# 🚧 WORK IN PROGRESS. See [#1](https://github.com/${repository}/pull/1)
20+
content += `# 🚧 WORK IN PROGRESS. See [#1](https://github.com/${repository}/pull/1) | [Preview](https://github.com/${repository}/tree/initial-version)
2121
2222
`;
2323
}
2424

2525
// header
26-
content += `# ${repo}
26+
content += `# ${repo}\n\n`;
2727

28-
> ${description}
29-
30-
`;
28+
if (description) {
29+
content += `> ${description}\n\n`;
30+
}
3131

3232
if (addBadges) {
3333
content += `[![@latest](https://img.shields.io/npm/v/${packageName}.svg)](https://www.npmjs.com/package/${packageName})
@@ -37,58 +37,69 @@ export default async function createReadme({
3737
}
3838

3939
if (addUsage) {
40-
let usage = `npx ${packageName} \\
41-
--octoherd-token 0123456789012345678901234567890123456789 \\
42-
"${owner}/*"`;
40+
let minimalUsage = `npx ${packageName}`;
41+
let fullUsage = `npx ${packageName} \\
42+
-T ghp_0123456789abcdefghjklmnopqrstuvwxyzA \\
43+
-R "${owner}/*"`;
4344

4445
Object.entries(scriptOptions).forEach(([name, { required, example }]) => {
4546
if (!required) return;
46-
usage += ` \\
47+
minimalUsage += ` \\
48+
--${name} ${example}`;
49+
});
50+
Object.entries(scriptOptions).forEach(([name, { required, example }]) => {
51+
fullUsage += ` \\
4752
--${name} ${example}`;
4853
});
4954

5055
content += `## Usage
5156
57+
Minimal usage
58+
5259
\`\`\`js
53-
${usage}
60+
${minimalUsage}
61+
\`\`\`
62+
63+
Pass all options as CLI flags to avoid user prompts
64+
65+
\`\`\`js
66+
${fullUsage}
5467
\`\`\`
5568
56-
`;
5769
58-
if (Object.keys(scriptOptions).length === 0) {
59-
content += `The script has no options
60-
6170
`;
62-
} else {
63-
content += `## Options
71+
72+
content += `## Options
6473
6574
| option | type | description |
6675
| --- | --- | --- |
6776
`;
6877

69-
Object.entries(scriptOptions).forEach(
70-
([name, { type, required, description, default: defaultValue }]) => {
71-
const CliOption = decamelize(name, {
72-
separator: "-",
73-
});
74-
let optionNames = `\`--${CliOption}\``;
75-
if (type === "boolean") {
76-
optionNames += ` or \`--no-${CliOption}\``;
77-
}
78-
79-
content += `| ${optionNames} | ${type} | ${
80-
required ? `**(required)**` : ""
81-
} ${description} ${
82-
defaultValue
83-
? `. Defaults to ${
84-
type === "string" ? `"${defaultValue}"` : defaultValue
85-
}`
86-
: ""
87-
} |
88-
`;
78+
Object.entries(scriptOptions).forEach(
79+
([name, { type, required, description, default: defaultValue }]) => {
80+
const CliOption = decamelize(name, {
81+
separator: "-",
82+
});
83+
let optionNames = `\`--${CliOption}\``;
84+
if (type === "boolean") {
85+
optionNames += ` or \`--no-${CliOption}\``;
8986
}
90-
);
91-
}
87+
88+
content += `| ${optionNames} | ${type} | ${
89+
required ? `**Required.**` : ""
90+
} ${description}${
91+
defaultValue
92+
? `. Defaults to ${
93+
type === "string" ? `"${defaultValue}"` : defaultValue
94+
}`
95+
: ""
96+
} |
97+
`;
98+
}
99+
);
100+
101+
content += `| \`--octoherd-token\`, \`-T\` | string | A personal access token ([create](https://github.com/settings/tokens/new?scopes=repo)). Script will create one if option is not set |\n`;
102+
content += `| \`--octoherd-repos\`, \`-R\` | array of strings | One or multiple space-separated repositories in the form of \`repo-owner/repo-name\`. \`repo-owner/*\` will find all repositories for one owner. \`*\` will find all repositories the user has access to. Will prompt for repositories if not set |\n\n`;
92103
}
93104

94105
// footer

0 commit comments

Comments
 (0)