-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathbase.ts
320 lines (283 loc) · 9.29 KB
/
base.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
import { BaseOptionsFor, createBase } from "bingo-stratum";
import { inputFromFile } from "input-from-file";
import { inputFromScript } from "input-from-script";
import lazyValue from "lazy-value";
import { z } from "zod";
import { readAccess } from "./options/readAccess.js";
import { readAllContributors } from "./options/readAllContributors.js";
import { readAuthor } from "./options/readAuthor.js";
import { readDescription } from "./options/readDescription.js";
import { readDocumentation } from "./options/readDocumentation.js";
import { readEmailFromCodeOfConduct } from "./options/readEmailFromCodeOfConduct.js";
import { readEmailFromGit } from "./options/readEmailFromGit.js";
import { readEmailFromNpm } from "./options/readEmailFromNpm.js";
import { readEmails } from "./options/readEmails.js";
import { readEmoji } from "./options/readEmoji.js";
import { readExistingLabels } from "./options/readExistingLabels.js";
import { readExplainer } from "./options/readExplainer.js";
import { readFileSafe } from "./options/readFileSafe.js";
import { readFunding } from "./options/readFunding.js";
import { readGitDefaults } from "./options/readGitDefaults.js";
import { readGuide } from "./options/readGuide.js";
import { readLogo } from "./options/readLogo.js";
import { readNode } from "./options/readNode.js";
import { readNpmDefaults } from "./options/readNpmDefaults.js";
import { readOwner } from "./options/readOwner.js";
import { readPackageAuthor } from "./options/readPackageAuthor.js";
import { readPackageData } from "./options/readPackageData.js";
import { readPackageDataFull } from "./options/readPackageDataFull.js";
import { readPnpm } from "./options/readPnpm.js";
import { readRepository } from "./options/readRepository.js";
import { readRulesetId } from "./options/readRulesetId.js";
import { readTitle } from "./options/readTitle.js";
import { readUsage } from "./options/readUsage.js";
const zContributor = z.object({
avatar_url: z.string(),
contributions: z.array(z.string()),
login: z.string(),
name: z.string(),
profile: z.string(),
});
export type Contributor = z.infer<typeof zContributor>;
export const base = createBase({
options: {
access: z
.union([z.literal("public"), z.literal("restricted")])
.describe("which `npm publish --access` to release npm packages with"),
author: z
.string()
.optional()
.describe("username on npm to publish packages under"),
bin: z
.string()
.optional()
.describe('value to set in `package.json`\'s `"bin"` property'),
contributors: z
.array(zContributor)
.optional()
.describe("AllContributors contributors to store in .all-contributorsrc"),
description: z
.string()
.default("A very lovely package. Hooray!")
.describe("'Sentence case.' description of the repository"),
directory: z.string().describe("Directory to create the repository in"),
documentation: z
.string()
.optional()
.describe("any additional docs to add to .github/DEVELOPMENT.md"),
email: z
.union([
z.string(),
z.object({
github: z.string(),
npm: z.string(),
}),
])
// TODO: Test this? Is it still working?
// https://github.com/JoshuaKGoldberg/create-typescript-app/issues/1991
.transform((email) =>
typeof email === "string" ? { github: email, npm: email } : email,
)
.describe(
"email address to be listed as the point of contact in docs and packages",
),
emoji: z
.string()
.optional()
.describe("decorative emoji to use in descriptions and docs"),
existingLabels: z
.array(
z.object({
color: z.string(),
description: z.string(),
name: z.string(),
}),
)
.optional()
.describe("existing labels from the GitHub repository"),
explainer: z
.array(z.string())
.optional()
.describe("additional README.md sentence(s) describing the package"),
funding: z
.string()
.optional()
.describe("GitHub organization or username to mention in `funding.yml`"),
guide: z
.object({
href: z.string(),
title: z.string(),
})
.optional()
.describe(
"link to a contribution guide to place at the top of development docs",
),
keywords: z
.array(z.string())
.optional()
.describe("any number of keywords to include in `package.json`"),
logo: z
.object({
alt: z.string(),
height: z.number().optional(),
src: z.string(),
width: z.number().optional(),
})
.optional()
.describe(
"local image file and alt text to display near the top of the README.md",
),
node: z
.object({
minimum: z.string(),
pinned: z.string().optional(),
})
.optional()
.describe("Node.js engine version(s) to pin and require a minimum of"),
owner: z.string().describe("organization or user owning the repository"),
packageData: z
.object({
dependencies: z.record(z.string(), z.string()).optional(),
devDependencies: z.record(z.string(), z.string()).optional(),
scripts: z.record(z.string(), z.string()).optional(),
})
.optional()
.describe("additional properties to include in `package.json`"),
pnpm: z
.string()
.optional()
.describe("pnpm version for package.json's packageManager field"),
repository: z
.string()
.describe("'kebab-case' or 'PascalCase' title of the repository"),
rulesetId: z
.string()
.optional()
.describe("GitHub branch ruleset ID for main branch protections"),
title: z.string().describe("'Title Case' title for the repository"),
usage: z
.string()
.optional()
.describe("Markdown docs to put in README.md under the ## Usage heading"),
version: z
.string()
.optional()
.describe("package version to publish as and store in `package.json`"),
},
prepare({ options, take }) {
const getAccess = lazyValue(
async () => await readAccess(getPackageDataFull),
);
const getAllContributors = lazyValue(
async () => await readAllContributors(take),
);
const getAuthor = lazyValue(
async () =>
await readAuthor(getPackageAuthor, getNpmDefaults, options.owner),
);
const getBin = lazyValue(async () => (await getPackageDataFull()).bin);
const getEmoji = lazyValue(async () => await readEmoji(getDescription));
const getDescription = lazyValue(
async () => await readDescription(getPackageDataFull, getReadme),
);
const getDocumentation = lazyValue(
async () => await readDocumentation(take),
);
const getEmail = lazyValue(
async () =>
await readEmails(
getEmailFromCodeOfConduct,
getEmailFromGit,
getEmailFromNpm,
),
);
const getEmailFromCodeOfConduct = lazyValue(
async () => await readEmailFromCodeOfConduct(take),
);
const getEmailFromGit = lazyValue(async () => await readEmailFromGit(take));
const getEmailFromNpm = lazyValue(
async () => await readEmailFromNpm(getNpmDefaults, getPackageAuthor),
);
const getExistingLabels = lazyValue(
async () => await readExistingLabels(take, getOwner, getRepository),
);
const getExplainer = lazyValue(async () => await readExplainer(getReadme));
const getFunding = lazyValue(async () => await readFunding(take));
const getGitDefaults = lazyValue(async () => await readGitDefaults(take));
const getGuide = lazyValue(async () => await readGuide(take));
const getLogo = lazyValue(async () => await readLogo(getReadme));
const getPackageData = lazyValue(
async () => await readPackageData(getPackageDataFull),
);
const getPackageDataFull = lazyValue(
async () => await readPackageDataFull(take),
);
const getNode = lazyValue(
async () => await readNode(getNvmrc, getPackageDataFull),
);
const getNpmDefaults = lazyValue(
async () => await readNpmDefaults(getNpmWhoami),
);
const getNpmWhoami = lazyValue(
async () =>
await take(inputFromScript, { command: "npm whoami --offline" }),
);
const getNvmrc = lazyValue(
async () =>
await take(inputFromFile, {
filePath: ".nvmrc",
}),
);
const getOwner = lazyValue(
async () => await readOwner(take, getGitDefaults, getPackageAuthor),
);
const getPackageAuthor = lazyValue(
async () => await readPackageAuthor(getPackageDataFull),
);
const getPnpm = lazyValue(async () => await readPnpm(getPackageDataFull));
const getReadme = lazyValue(
async () => await readFileSafe("README.md", ""),
);
const getRepository = lazyValue(
async () =>
await readRepository(getGitDefaults, getPackageDataFull, options),
);
const getRulesetId = lazyValue(
async () => await readRulesetId(take, getOwner, getRepository),
);
const getTitle = lazyValue(
async () => await readTitle(getReadme, getRepository),
);
const getUsage = lazyValue(
async () => await readUsage(getEmoji, getReadme, getRepository),
);
const getVersion = lazyValue(
async () => (await getPackageDataFull()).version,
);
return {
access: getAccess,
author: getAuthor,
bin: getBin,
contributors: getAllContributors,
description: getDescription,
documentation: getDocumentation,
email: getEmail,
emoji: getEmoji,
existingLabels: getExistingLabels,
explainer: getExplainer,
funding: getFunding,
guide: getGuide,
logo: getLogo,
node: getNode,
owner: getOwner,
packageData: getPackageData,
pnpm: getPnpm,
repository: getRepository,
rulesetId: getRulesetId,
title: getTitle,
usage: getUsage,
version: getVersion,
};
},
});
export type BaseOptions = BaseOptionsFor<typeof base>;