Skip to content

Commit 3dac778

Browse files
committed
fixies
1 parent 4ce1236 commit 3dac778

File tree

5 files changed

+198
-12
lines changed

5 files changed

+198
-12
lines changed

create-octokit-project.js

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ async function main() {
8888

8989
await createRepository(octokit, {
9090
isUserRepo,
91+
owner,
9192
repo,
9293
description: answers.description
9394
});
@@ -122,9 +123,29 @@ async function main() {
122123

123124
await createPackageJson(answers);
124125
console.log("Install dependencies");
125-
await command(
126-
"npm install --save-dev @pika/pack @pika/plugin-build-node @pika/plugin-build-web @pika/plugin-ts-standard-pkg @types/jest @types/node jest prettier semantic-release semantic-release-plugin-update-version-in-files ts-jest typescript"
127-
);
126+
const dependencies = [
127+
"@pika/pack",
128+
"@pika/plugin-ts-standard-pkg",
129+
"@types/jest",
130+
"@types/node",
131+
"jest",
132+
"prettier",
133+
"semantic-release",
134+
"semantic-release-plugin-update-version-in-files",
135+
"ts-jest",
136+
"typescript"
137+
];
138+
139+
if (answers.supportsBrowsers) {
140+
dependencies.push("@pika/plugin-build-web");
141+
}
142+
if (answers.supportsNode) {
143+
dependencies.push("@pika/plugin-build-node");
144+
}
145+
if (answers.isPlugin) {
146+
dependencies.push("@octokit/core");
147+
}
148+
await command(`npm install --save-dev ${dependencies.join(" ")}`);
128149

129150
await command(`git add package.json`);
130151
await command(`git commit -m 'build(package): initial version'`);
@@ -133,7 +154,7 @@ async function main() {
133154

134155
if (!isUserRepo) {
135156
console.log("Inviting collaborators...");
136-
await inviteCollaborators(octokit, { isUserRepo });
157+
await inviteCollaborators(octokit, { owner, repo });
137158
}
138159

139160
console.log("Create branch protection for master");
@@ -170,6 +191,33 @@ async function main() {
170191

171192
console.log("create smoke test");
172193
await mkdir("test");
194+
195+
if (answers.isPlugin) {
196+
await writeFile(
197+
"test/smoke.test.ts",
198+
`import { Octokit } from "@octokit/core";
199+
200+
import { ${answers.exportName} } from "../src";
201+
202+
describe("Smoke test", () => {
203+
it("{ ${answers.exportName} } export is a function", () => {
204+
expect(${answers.exportName}).toBeInstanceOf(Function);
205+
});
206+
207+
it("${answers.exportName}.VERSION is set", () => {
208+
expect(${answers.exportName}.VERSION).toEqual("0.0.0-development");
209+
});
210+
211+
it("Loads plugin", () => {
212+
expect(() => {
213+
const TestOctokit = Octokit.plugin(${answers.exportName})
214+
new TestOctokit();
215+
}).not.toThrow();
216+
});
217+
});
218+
`
219+
);
220+
}
173221
await writeFile(
174222
"test/smoke.test.ts",
175223
`import { ${answers.exportName} } from "../src";
@@ -178,6 +226,10 @@ describe("Smoke test", () => {
178226
it("is a function", () => {
179227
expect(${answers.exportName}).toBeInstanceOf(Function);
180228
});
229+
230+
it("${answers.exportName}.VERSION is set", () => {
231+
expect(${answers.exportName}.VERSION).toEqual("0.0.0-development");
232+
});
181233
});
182234
`
183235
);
@@ -233,6 +285,9 @@ ${answers.exportName}.VERSION = VERSION`
233285
}
234286
}
235287

288+
await command(`git add src`);
289+
await command(`git commit -m 'feat: initial version'`);
290+
236291
await createReadme({
237292
addBadges: true,
238293
repo,
@@ -242,6 +297,21 @@ ${answers.exportName}.VERSION = VERSION`
242297
});
243298
await command(`git commit README.md -m 'docs(README): badges'`);
244299

300+
await createReadme({
301+
addBadges: true,
302+
addUsage: true,
303+
repo,
304+
description: answers.description,
305+
packageName: answers.packageName,
306+
repository: answers.repository,
307+
isPlugin: answers.isPlugin,
308+
exportName: answers.exportName,
309+
supportsBrowsers: answers.supportsBrowsers,
310+
supportsNode: answers.supportsNode,
311+
usageExample: answers.usageExample
312+
});
313+
await command(`git commit README.md -m 'docs(README): usage'`);
314+
245315
console.log("Create actions");
246316
await mkdir(".github/workflows", { recursive: true });
247317
await createReleaseAction();

lib/create-readme.js

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ async function createReadme({
88
description,
99
packageName,
1010
addWip,
11-
addBadges
11+
addBadges,
12+
addUsage,
13+
supportsBrowsers,
14+
supportsNode,
15+
isPlugin,
16+
exportName,
17+
usageExample
1218
}) {
1319
let content = "";
1420

@@ -31,6 +37,87 @@ async function createReadme({
3137
[![Build Status](https://github.com/${repository}/workflows/Test/badge.svg)](https://github.com/${repository}/actions?workflow=Test)
3238
[![Greenkeeper](https://badges.greenkeeper.io/${repository}.svg)](https://greenkeeper.io/)
3339
40+
`;
41+
}
42+
43+
if (addUsage) {
44+
content += `## Usage
45+
46+
<table>
47+
<tbody valign=top align=left>
48+
<tr><th>
49+
Browsers
50+
</th><td width=100%>
51+
52+
`;
53+
54+
if (supportsBrowsers) {
55+
if (isPlugin) {
56+
content += `Load \`${packageName}\` and [\`@octokit/core\`](https://github.com/octokit/core.js) (or core-compatible module) directly from [cdn.pika.dev](https://cdn.pika.dev)
57+
58+
\`\`\`html
59+
<script type="module">
60+
import { Octokit } from "https://cdn.pika.dev/@octokit/core";
61+
import { ${exportName} } from "https://cdn.pika.dev/${packageName}";
62+
</script>
63+
\`\`\`
64+
65+
`;
66+
} else {
67+
content += `Load \`${packageName}\` directly from [cdn.pika.dev](https://cdn.pika.dev)
68+
69+
\`\`\`html
70+
<script type="module">
71+
import { ${exportName} } from "https://cdn.pika.dev/${packageName}";
72+
</script>
73+
\`\`\`
74+
75+
`;
76+
}
77+
} else {
78+
content += `\`${packageName}\` is not meant for browser usage.
79+
80+
`;
81+
}
82+
83+
content += `</td></tr>
84+
<tr><th>
85+
Node
86+
</th><td>
87+
88+
`;
89+
if (supportsNode) {
90+
if (isPlugin) {
91+
content += `Install with \`npm install @octokit/core ${packageName}\`. Optionally replace \`@octokit/core\` with a core-compatible module
92+
93+
\`\`\`js
94+
const { Octokit } = require("@octokit/core");
95+
const { ${exportName} } = require("${packageName}");
96+
\`\`\`
97+
98+
`;
99+
} else {
100+
content += `Install with \`npm install @octokit/core ${packageName}\`
101+
102+
\`\`\`js
103+
const { ${exportName} } = require("${packageName}");
104+
\`\`\`
105+
106+
`;
107+
}
108+
} else {
109+
content += `\`${packageName}\` is not meant for Node usage.
110+
111+
`;
112+
}
113+
content += `</td></tr>
114+
</tbody>
115+
</table>
116+
117+
\`\`\`js
118+
${usageExample}
119+
\`\`\`
120+
34121
`;
35122
}
36123

lib/create-repository.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
module.exports = createRepository;
22

3-
async function createRepository(octokit, { isUserRepo, repo, description }) {
3+
async function createRepository(
4+
octokit,
5+
{ isUserRepo, owner, repo, description }
6+
) {
47
const createRepoOptions = {
58
name: repo,
69
description: description,

lib/invite-collaborators.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = inviteCollaborators;
22

3-
async function inviteCollaborators(octokit) {
3+
async function inviteCollaborators(octokit, { owner, repo }) {
44
await octokit.request("PUT /repos/:owner/:repo/collaborators/:username", {
55
owner,
66
repo,

lib/prompts.js

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ async function prompts({ username, name, email, website }) {
3232
return `What is the main export of the module? (Example: "Octokit" for "import { Octokit } of '${answers.packageName}'")`;
3333
}
3434
},
35+
{
36+
type: "editor",
37+
name: "usageExample",
38+
message: answers => {
39+
if (answers.isPlugin) {
40+
return `Provide the most simple usage example, without the ${answers.exportName} and Octokit import/require statements`;
41+
}
42+
43+
return `Provide the most simple usage example, without the ${answers.exportName} import/require statement`;
44+
}
45+
},
3546
{
3647
type: "confirm",
3748
name: "publicAccess",
@@ -56,8 +67,16 @@ async function prompts({ username, name, email, website }) {
5667
type: "input",
5768
name: "repository",
5869
message:
59-
"Full name of then repository (Example: octocat/octokit-plugin-hello-world)",
60-
default: answers => [username, answers.packageName].join("/"),
70+
"Full name of the repository (Example: octocat/octokit-plugin-hello-world)",
71+
default: answers => {
72+
if (answers.packageName.startsWith("@octokit")) {
73+
return answers.packageName.substr(1) + ".js";
74+
}
75+
76+
return answers.packageName.startsWith("@")
77+
? answers.packageName.substr(1)
78+
: [username, answers.packageName].join("/");
79+
},
6180
validate: input => input.includes("/")
6281
},
6382
{
@@ -83,18 +102,25 @@ async function prompts({ username, name, email, website }) {
83102
type: "input",
84103
name: "cocEmail",
85104
message: "Email for Code of Conduct",
86-
default: email
105+
default: answers =>
106+
answers.packageName.startsWith("@octokit")
107+
108+
: email
87109
},
88110
{
89111
type: "input",
90112
name: "licenseName",
91113
message: "Name for license",
92-
default: name
114+
default: answers =>
115+
answers.packageName.startsWith("@octokit")
116+
? "Octokit contributors"
117+
: name
93118
},
94119
{
95120
type: "input",
96121
name: "path",
97-
message: `Folder path to initialize the project in, relative to current path. If the path it does not yet exist it will be created. Current path is ${process.cwd()})`
122+
message: `Folder path to initialize the project in, relative to current path. If the path it does not yet exist it will be created. Current path is ${process.cwd()})`,
123+
default: answers => answers.repository.split("/")[1]
98124
}
99125
]);
100126
}

0 commit comments

Comments
 (0)