|
1 | 1 | import { BaseOptionsFor, createBase } from "bingo-stratum";
|
2 |
| -import { execaCommand } from "execa"; |
3 |
| -import gitRemoteOriginUrl from "git-remote-origin-url"; |
4 |
| -import gitUrlParse from "git-url-parse"; |
5 | 2 | import { inputFromFile } from "input-from-file";
|
6 | 3 | import { inputFromScript } from "input-from-script";
|
7 | 4 | import lazyValue from "lazy-value";
|
8 |
| -import npmUser from "npm-user"; |
9 | 5 | import { z } from "zod";
|
10 | 6 |
|
11 |
| -import { inputFromOctokit } from "./inputs/inputFromOctokit.js"; |
12 |
| -import { getExistingLabels } from "./options/getExistingLabels.js"; |
13 |
| -import { parseEmojiFromDescription } from "./options/parseEmojiFromDescription.js"; |
14 |
| -import { parsePackageAuthor } from "./options/parsePackageAuthor.js"; |
15 | 7 | import { readAllContributors } from "./options/readAllContributors.js";
|
16 |
| -import { readDefaultsFromReadme } from "./options/readDefaultsFromReadme.js"; |
| 8 | +import { readAuthor } from "./options/readAuthor.js"; |
17 | 9 | import { readDescription } from "./options/readDescription.js";
|
18 | 10 | import { readDocumentation } from "./options/readDocumentation.js";
|
| 11 | +import { readEmailFromCodeOfConduct } from "./options/readEmailFromCodeOfConduct.js"; |
| 12 | +import { readEmailFromGit } from "./options/readEmailFromGit.js"; |
| 13 | +import { readEmailFromNpm } from "./options/readEmailFromNpm.js"; |
19 | 14 | import { readEmails } from "./options/readEmails.js";
|
| 15 | +import { readEmoji } from "./options/readEmoji.js"; |
| 16 | +import { readExistingLabels } from "./options/readExistingLabels.js"; |
| 17 | +import { readExplainer } from "./options/readExplainer.js"; |
20 | 18 | import { readFileSafe } from "./options/readFileSafe.js";
|
21 | 19 | import { readFunding } from "./options/readFunding.js";
|
| 20 | +import { readGitDefaults } from "./options/readGitDefaults.js"; |
22 | 21 | import { readGuide } from "./options/readGuide.js";
|
| 22 | +import { readLogo } from "./options/readLogo.js"; |
| 23 | +import { readNode } from "./options/readNode.js"; |
| 24 | +import { readNpmDefaults } from "./options/readNpmDefaults.js"; |
| 25 | +import { readOwner } from "./options/readOwner.js"; |
| 26 | +import { readPackageAuthor } from "./options/readPackageAuthor.js"; |
23 | 27 | import { readPackageData } from "./options/readPackageData.js";
|
| 28 | +import { readPackageDataFull } from "./options/readPackageDataFull.js"; |
24 | 29 | import { readPnpm } from "./options/readPnpm.js";
|
25 |
| -import { swallowError } from "./utils/swallowError.js"; |
26 |
| -import { tryCatchLazyValueAsync } from "./utils/tryCatchLazyValueAsync.js"; |
| 30 | +import { readRepository } from "./options/readRepository.js"; |
| 31 | +import { readRulesetId } from "./options/readRulesetId.js"; |
| 32 | +import { readTitle } from "./options/readTitle.js"; |
| 33 | +import { readUsage } from "./options/readUsage.js"; |
27 | 34 |
|
28 | 35 | const zContributor = z.object({
|
29 | 36 | avatar_url: z.string(),
|
@@ -69,6 +76,7 @@ export const base = createBase({
|
69 | 76 | npm: z.string(),
|
70 | 77 | }),
|
71 | 78 | ])
|
| 79 | + // TODO: Test this? Is it still working? |
72 | 80 | .transform((email) =>
|
73 | 81 | typeof email === "string" ? { github: email, npm: email } : email,
|
74 | 82 | )
|
@@ -159,131 +167,146 @@ export const base = createBase({
|
159 | 167 | .describe("package version to publish as and store in `package.json`"),
|
160 | 168 | },
|
161 | 169 | prepare({ options, take }) {
|
162 |
| - const allContributors = lazyValue(async () => readAllContributors(take)); |
163 |
| - const documentation = lazyValue(async () => readDocumentation(take)); |
| 170 | + const getAllContributors = lazyValue( |
| 171 | + async () => await readAllContributors(take), |
| 172 | + ); |
164 | 173 |
|
165 |
| - const nvmrc = lazyValue( |
| 174 | + const getAuthor = lazyValue( |
166 | 175 | async () =>
|
167 |
| - await take(inputFromFile, { |
168 |
| - filePath: ".nvmrc", |
169 |
| - }), |
| 176 | + await readAuthor(getPackageAuthor, getNpmDefaults, options.owner), |
170 | 177 | );
|
171 | 178 |
|
172 |
| - const existingLabels = lazyValue(async () => |
173 |
| - getExistingLabels(take, await owner(), await repository()), |
| 179 | + const getBin = lazyValue(async () => (await getPackageDataFull()).bin); |
| 180 | + |
| 181 | + const getEmoji = lazyValue(async () => await readEmoji(getDescription)); |
| 182 | + |
| 183 | + const getDescription = lazyValue( |
| 184 | + async () => await readDescription(getPackageDataFull, getReadme), |
174 | 185 | );
|
175 | 186 |
|
176 |
| - const githubCliUser = lazyValue(async () => { |
177 |
| - return swallowError( |
178 |
| - await take(inputFromScript, { |
179 |
| - command: "gh config get user -h github.com", |
180 |
| - }), |
181 |
| - )?.stdout?.toString(); |
182 |
| - }); |
| 187 | + const getDocumentation = lazyValue( |
| 188 | + async () => await readDocumentation(take), |
| 189 | + ); |
| 190 | + |
| 191 | + const getEmail = lazyValue( |
| 192 | + async () => |
| 193 | + await readEmails( |
| 194 | + getEmailFromCodeOfConduct, |
| 195 | + getEmailFromGit, |
| 196 | + getEmailFromNpm, |
| 197 | + ), |
| 198 | + ); |
183 | 199 |
|
184 |
| - const readme = lazyValue(async () => await readFileSafe("README.md", "")); |
| 200 | + const getEmailFromCodeOfConduct = lazyValue( |
| 201 | + async () => await readEmailFromCodeOfConduct(take), |
| 202 | + ); |
185 | 203 |
|
186 |
| - const rulesetId = lazyValue(async () => { |
187 |
| - const rulesets = (await take(inputFromOctokit, { |
188 |
| - endpoint: "GET /repos/{owner}/{repo}/rulesets", |
189 |
| - options: { |
190 |
| - owner: await owner(), |
191 |
| - repo: await repository(), |
192 |
| - }, |
193 |
| - })) as undefined | { id: string; name: string }[]; |
| 204 | + const getEmailFromGit = lazyValue(async () => await readEmailFromGit(take)); |
194 | 205 |
|
195 |
| - return rulesets?.find( |
196 |
| - (ruleset) => ruleset.name === "Branch protection for main", |
197 |
| - )?.id; |
198 |
| - }); |
| 206 | + const getEmailFromNpm = lazyValue( |
| 207 | + async () => await readEmailFromNpm(getNpmDefaults, getPackageAuthor), |
| 208 | + ); |
199 | 209 |
|
200 |
| - // TODO: Make these all use take |
| 210 | + const getExistingLabels = lazyValue( |
| 211 | + async () => await readExistingLabels(take, getOwner, getRepository), |
| 212 | + ); |
201 | 213 |
|
202 |
| - const emoji = async () => parseEmojiFromDescription(description); |
| 214 | + const getExplainer = lazyValue(async () => await readExplainer(getReadme)); |
203 | 215 |
|
204 |
| - const description = async () => await readDescription(packageData, readme); |
| 216 | + const getFunding = lazyValue(async () => await readFunding(take)); |
205 | 217 |
|
206 |
| - const gitDefaults = tryCatchLazyValueAsync(async () => |
207 |
| - gitUrlParse(await gitRemoteOriginUrl()), |
| 218 | + const getGitDefaults = lazyValue(async () => await readGitDefaults()); |
| 219 | + |
| 220 | + const getGuide = lazyValue(async () => await readGuide(take)); |
| 221 | + |
| 222 | + const getLogo = lazyValue(async () => await readLogo(getReadme)); |
| 223 | + |
| 224 | + const getPackageData = lazyValue( |
| 225 | + async () => await readPackageData(getPackageDataFull), |
208 | 226 | );
|
209 | 227 |
|
210 |
| - const npmDefaults = tryCatchLazyValueAsync(async () => { |
211 |
| - const whoami = (await execaCommand(`npm whoami`)).stdout; |
212 |
| - return whoami ? await npmUser(whoami) : undefined; |
213 |
| - }); |
| 228 | + const getPackageDataFull = lazyValue( |
| 229 | + async () => await readPackageDataFull(take), |
| 230 | + ); |
214 | 231 |
|
215 |
| - const packageData = lazyValue(readPackageData); |
216 |
| - const packageAuthor = lazyValue(async () => |
217 |
| - parsePackageAuthor(await packageData()), |
| 232 | + const getNode = lazyValue( |
| 233 | + async () => await readNode(getNvmrc, getPackageDataFull), |
218 | 234 | );
|
219 | 235 |
|
220 |
| - const author = lazyValue( |
| 236 | + const getNpmDefaults = lazyValue( |
| 237 | + async () => await readNpmDefaults(getNpmWhoami), |
| 238 | + ); |
| 239 | + |
| 240 | + const getNpmWhoami = lazyValue( |
221 | 241 | async () =>
|
222 |
| - (await packageAuthor()).author ?? |
223 |
| - (await npmDefaults())?.name ?? |
224 |
| - options.owner, |
| 242 | + await take(inputFromScript, { command: "npm whoami --offline" }), |
225 | 243 | );
|
226 | 244 |
|
227 |
| - const node = lazyValue(async () => { |
228 |
| - const { engines } = await packageData(); |
| 245 | + const getNvmrc = lazyValue( |
| 246 | + async () => |
| 247 | + await take(inputFromFile, { |
| 248 | + filePath: ".nvmrc", |
| 249 | + }), |
| 250 | + ); |
229 | 251 |
|
230 |
| - return { |
231 |
| - minimum: |
232 |
| - (engines?.node && /[\d+.]+/.exec(engines.node))?.[0] ?? "18.3.0", |
233 |
| - pinned: swallowError(await nvmrc())?.trim() ?? "20.18.0", |
234 |
| - }; |
235 |
| - }); |
| 252 | + const getOwner = lazyValue( |
| 253 | + async () => await readOwner(take, getGitDefaults, getPackageAuthor), |
| 254 | + ); |
236 | 255 |
|
237 |
| - const pnpm = lazyValue(async () => readPnpm(packageData)); |
| 256 | + const getPackageAuthor = lazyValue( |
| 257 | + async () => await readPackageAuthor(getPackageDataFull), |
| 258 | + ); |
238 | 259 |
|
239 |
| - const version = lazyValue(async () => (await packageData()).version); |
| 260 | + const getPnpm = lazyValue(async () => await readPnpm(getPackageDataFull)); |
240 | 261 |
|
241 |
| - const owner = lazyValue( |
242 |
| - async () => |
243 |
| - (await gitDefaults())?.organization ?? |
244 |
| - (await packageAuthor()).author ?? |
245 |
| - (await githubCliUser()), |
| 262 | + const getReadme = lazyValue( |
| 263 | + async () => await readFileSafe("README.md", ""), |
246 | 264 | );
|
247 | 265 |
|
248 |
| - const repository = lazyValue( |
| 266 | + const getRepository = lazyValue( |
249 | 267 | async () =>
|
250 |
| - options.repository ?? |
251 |
| - (await gitDefaults())?.name ?? |
252 |
| - (await packageData()).name ?? |
253 |
| - options.directory, |
| 268 | + await readRepository(getGitDefaults, getPackageDataFull, options), |
| 269 | + ); |
| 270 | + |
| 271 | + const getRulesetId = lazyValue( |
| 272 | + async () => await readRulesetId(take, getOwner, getRepository), |
| 273 | + ); |
| 274 | + |
| 275 | + const getTitle = lazyValue( |
| 276 | + async () => await readTitle(getReadme, getRepository), |
| 277 | + ); |
| 278 | + |
| 279 | + const getUsage = lazyValue( |
| 280 | + async () => await readUsage(getEmoji, getReadme, getRepository), |
254 | 281 | );
|
255 | 282 |
|
256 |
| - const email = lazyValue(async () => readEmails(npmDefaults, packageAuthor)); |
| 283 | + const getVersion = lazyValue( |
| 284 | + async () => (await getPackageDataFull()).version, |
| 285 | + ); |
257 | 286 |
|
258 | 287 | return {
|
259 | 288 | access: "public" as const,
|
260 |
| - author, |
261 |
| - bin: async () => (await packageData()).bin, |
262 |
| - contributors: allContributors, |
263 |
| - description, |
264 |
| - documentation, |
265 |
| - email, |
266 |
| - emoji, |
267 |
| - existingLabels, |
268 |
| - funding: readFunding, |
269 |
| - guide: readGuide, |
270 |
| - login: author, |
271 |
| - node, |
272 |
| - owner, |
273 |
| - packageData: async () => { |
274 |
| - const original = await packageData(); |
275 |
| - |
276 |
| - return { |
277 |
| - dependencies: original.dependencies, |
278 |
| - devDependencies: original.devDependencies, |
279 |
| - scripts: original.scripts, |
280 |
| - }; |
281 |
| - }, |
282 |
| - pnpm, |
283 |
| - repository, |
284 |
| - rulesetId, |
285 |
| - ...readDefaultsFromReadme(emoji, readme, repository), |
286 |
| - version, |
| 289 | + author: getAuthor, |
| 290 | + bin: getBin, |
| 291 | + contributors: getAllContributors, |
| 292 | + description: getDescription, |
| 293 | + documentation: getDocumentation, |
| 294 | + email: getEmail, |
| 295 | + emoji: getEmoji, |
| 296 | + existingLabels: getExistingLabels, |
| 297 | + explainer: getExplainer, |
| 298 | + funding: getFunding, |
| 299 | + guide: getGuide, |
| 300 | + logo: getLogo, |
| 301 | + node: getNode, |
| 302 | + owner: getOwner, |
| 303 | + packageData: getPackageData, |
| 304 | + pnpm: getPnpm, |
| 305 | + repository: getRepository, |
| 306 | + rulesetId: getRulesetId, |
| 307 | + title: getTitle, |
| 308 | + usage: getUsage, |
| 309 | + version: getVersion, |
287 | 310 | };
|
288 | 311 | },
|
289 | 312 | });
|
|
0 commit comments