@sanity/plugin-kit 6.0.3 → 6.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.js +12 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.js +72 -4
- package/dist/index.js.map +1 -1
- package/dist/init.js +866 -0
- package/dist/init.js.map +1 -0
- package/dist/init2.js +99 -0
- package/dist/init2.js.map +1 -0
- package/dist/{_chunks-es/inject.js → inject.js} +22 -16
- package/dist/inject.js.map +1 -0
- package/dist/link-watch.js +93 -0
- package/dist/link-watch.js.map +1 -0
- package/dist/load-package-config.js +31 -0
- package/dist/load-package-config.js.map +1 -0
- package/dist/log.js +31 -0
- package/dist/log.js.map +1 -0
- package/dist/package.js +908 -0
- package/dist/package.js.map +1 -0
- package/dist/package2.js +4 -0
- package/dist/package2.js.map +1 -0
- package/dist/verify-common.js +145 -0
- package/dist/verify-common.js.map +1 -0
- package/dist/verify-package.js +89 -0
- package/dist/verify-package.js.map +1 -0
- package/dist/verify-studio.js +65 -0
- package/dist/verify-studio.js.map +1 -0
- package/dist/version.js +54 -0
- package/dist/version.js.map +1 -0
- package/package.json +8 -7
- package/dist/_chunks-es/index.js +0 -125
- package/dist/_chunks-es/index.js.map +0 -1
- package/dist/_chunks-es/init.js +0 -85
- package/dist/_chunks-es/init.js.map +0 -1
- package/dist/_chunks-es/init2.js +0 -839
- package/dist/_chunks-es/init2.js.map +0 -1
- package/dist/_chunks-es/inject.js.map +0 -1
- package/dist/_chunks-es/link-watch.js +0 -91
- package/dist/_chunks-es/link-watch.js.map +0 -1
- package/dist/_chunks-es/load-package-config.js +0 -22
- package/dist/_chunks-es/load-package-config.js.map +0 -1
- package/dist/_chunks-es/package.js +0 -1066
- package/dist/_chunks-es/package.js.map +0 -1
- package/dist/_chunks-es/package2.js +0 -9
- package/dist/_chunks-es/package2.js.map +0 -1
- package/dist/_chunks-es/verify-common.js +0 -169
- package/dist/_chunks-es/verify-common.js.map +0 -1
- package/dist/_chunks-es/verify-package.js +0 -95
- package/dist/_chunks-es/verify-package.js.map +0 -1
- package/dist/_chunks-es/verify-studio.js +0 -61
- package/dist/_chunks-es/verify-studio.js.map +0 -1
- package/dist/_chunks-es/version.js +0 -50
- package/dist/_chunks-es/version.js.map +0 -1
package/dist/init.js
ADDED
|
@@ -0,0 +1,866 @@
|
|
|
1
|
+
import { n as defaultOutDir } from "./constants.js";
|
|
2
|
+
import { n as sharedFlags_default, t as log_default } from "./log.js";
|
|
3
|
+
import { B as writeFileWithOverwritePrompt, H as promptForPackageName, L as readFile, M as copyFileWithOverwritePrompt, N as ensureDir, P as fileExists, R as readJsonFile, U as promptForRepoOrigin, V as prompt, a as getPackage, c as writePackageJsonDirect, f as errorToUndefined, i as forceDependencyVersions, l as resolveLatestVersions, m as forcedPackageVersions, n as addPackageJsonScripts, o as sortKeys, p as forcedDevPackageVersions, r as addScript, s as writePackageJson, t as addBuildScripts, z as writeFile } from "./package.js";
|
|
4
|
+
import { n as name, r as version } from "./package2.js";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import outdent, { outdent as outdent$1 } from "outdent";
|
|
8
|
+
import { fileURLToPath } from "url";
|
|
9
|
+
import licenses from "@rexxars/choosealicense-list";
|
|
10
|
+
import gitRemoteOriginUrl from "git-remote-origin-url";
|
|
11
|
+
import { execSync } from "child_process";
|
|
12
|
+
import { validate } from "email-validator";
|
|
13
|
+
import xdgBasedir from "xdg-basedir";
|
|
14
|
+
import { createRequester } from "get-it";
|
|
15
|
+
function defaultSourceJs(pkg) {
|
|
16
|
+
return outdent`
|
|
17
|
+
import {definePlugin} from 'sanity'
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Usage in sanity.config.js (or .ts)
|
|
21
|
+
*
|
|
22
|
+
* \`\`\`js
|
|
23
|
+
* import {defineConfig} from 'sanity'
|
|
24
|
+
* import {myPlugin} from '${pkg.name}'
|
|
25
|
+
*
|
|
26
|
+
* export default defineConfig({
|
|
27
|
+
* // ...
|
|
28
|
+
* plugins: [myPlugin({})],
|
|
29
|
+
* })
|
|
30
|
+
* \`\`\`
|
|
31
|
+
*
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
export const myPlugin = definePlugin((config = {}) => {
|
|
35
|
+
// eslint-disable-next-line no-console
|
|
36
|
+
console.log(\`hello from ${pkg.name}\`)
|
|
37
|
+
return {
|
|
38
|
+
name: '${pkg.name}',
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
`.trimStart() + "\n";
|
|
42
|
+
}
|
|
43
|
+
function defaultSourceTs(pkg) {
|
|
44
|
+
return outdent`
|
|
45
|
+
import {definePlugin} from 'sanity'
|
|
46
|
+
|
|
47
|
+
interface MyPluginConfig {
|
|
48
|
+
/* nothing here yet */
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Usage in \`sanity.config.ts\` (or .js)
|
|
53
|
+
*
|
|
54
|
+
* \`\`\`ts
|
|
55
|
+
* import {defineConfig} from 'sanity'
|
|
56
|
+
* import {myPlugin} from '${pkg.name}'
|
|
57
|
+
*
|
|
58
|
+
* export default defineConfig({
|
|
59
|
+
* // ...
|
|
60
|
+
* plugins: [myPlugin()],
|
|
61
|
+
* })
|
|
62
|
+
* \`\`\`
|
|
63
|
+
*
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
export const myPlugin = definePlugin<MyPluginConfig | void>((config = {}) => {
|
|
67
|
+
// eslint-disable-next-line no-console
|
|
68
|
+
console.log('hello from ${pkg.name}')
|
|
69
|
+
return {
|
|
70
|
+
name: '${pkg.name}',
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
`.trimStart() + "\n";
|
|
74
|
+
}
|
|
75
|
+
function eslintrcTemplate(options) {
|
|
76
|
+
let { flags } = options, eslintConfig = {
|
|
77
|
+
root: !0,
|
|
78
|
+
env: {
|
|
79
|
+
node: !0,
|
|
80
|
+
browser: !0
|
|
81
|
+
},
|
|
82
|
+
extends: [
|
|
83
|
+
"sanity",
|
|
84
|
+
flags.typescript && "sanity/typescript",
|
|
85
|
+
"sanity/react",
|
|
86
|
+
"plugin:react-hooks/recommended",
|
|
87
|
+
flags.prettier && "plugin:prettier/recommended",
|
|
88
|
+
"plugin:react/jsx-runtime"
|
|
89
|
+
].filter(Boolean)
|
|
90
|
+
};
|
|
91
|
+
return {
|
|
92
|
+
type: "template",
|
|
93
|
+
force: flags.force,
|
|
94
|
+
to: ".eslintrc",
|
|
95
|
+
value: JSON.stringify(eslintConfig, null, 2)
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function eslintignoreTemplate(options) {
|
|
99
|
+
let { flags, outDir } = options, patterns = [
|
|
100
|
+
".eslintrc.js",
|
|
101
|
+
"commitlint.config.js",
|
|
102
|
+
outDir,
|
|
103
|
+
"lint-staged.config.js",
|
|
104
|
+
"package.config.ts",
|
|
105
|
+
flags.typescript ? "*.js" : ""
|
|
106
|
+
].filter(Boolean);
|
|
107
|
+
return patterns.sort(), {
|
|
108
|
+
type: "template",
|
|
109
|
+
force: flags.force,
|
|
110
|
+
to: ".eslintignore",
|
|
111
|
+
value: patterns.join("\n")
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function gitignoreTemplate() {
|
|
115
|
+
return {
|
|
116
|
+
type: "template",
|
|
117
|
+
to: ".gitignore",
|
|
118
|
+
value: outdent$1`
|
|
119
|
+
# Logs
|
|
120
|
+
logs
|
|
121
|
+
*.log
|
|
122
|
+
npm-debug.log*
|
|
123
|
+
|
|
124
|
+
# Runtime data
|
|
125
|
+
pids
|
|
126
|
+
*.pid
|
|
127
|
+
*.seed
|
|
128
|
+
|
|
129
|
+
# Directory for instrumented libs generated by jscoverage/JSCover
|
|
130
|
+
lib-cov
|
|
131
|
+
|
|
132
|
+
# Coverage directory used by tools like istanbul
|
|
133
|
+
coverage
|
|
134
|
+
|
|
135
|
+
# nyc test coverage
|
|
136
|
+
.nyc_output
|
|
137
|
+
|
|
138
|
+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
|
139
|
+
.grunt
|
|
140
|
+
|
|
141
|
+
# node-waf configuration
|
|
142
|
+
.lock-wscript
|
|
143
|
+
|
|
144
|
+
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
|
145
|
+
build/Release
|
|
146
|
+
|
|
147
|
+
# Dependency directories
|
|
148
|
+
node_modules
|
|
149
|
+
jspm_packages
|
|
150
|
+
|
|
151
|
+
# Optional npm cache directory
|
|
152
|
+
.npm
|
|
153
|
+
|
|
154
|
+
# Optional REPL history
|
|
155
|
+
.node_repl_history
|
|
156
|
+
|
|
157
|
+
# macOS finder cache file
|
|
158
|
+
.DS_Store
|
|
159
|
+
|
|
160
|
+
# VS Code settings
|
|
161
|
+
.vscode
|
|
162
|
+
|
|
163
|
+
# IntelliJ
|
|
164
|
+
.idea
|
|
165
|
+
*.iml
|
|
166
|
+
|
|
167
|
+
# Cache
|
|
168
|
+
.cache
|
|
169
|
+
|
|
170
|
+
# Yalc
|
|
171
|
+
.yalc
|
|
172
|
+
yalc.lock
|
|
173
|
+
|
|
174
|
+
# npm package zips
|
|
175
|
+
*.tgz
|
|
176
|
+
`
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function pkgConfigTemplate(options) {
|
|
180
|
+
let { flags, outDir } = options;
|
|
181
|
+
return {
|
|
182
|
+
type: "template",
|
|
183
|
+
force: flags.force,
|
|
184
|
+
to: "package.config.ts",
|
|
185
|
+
value: outdent$1`
|
|
186
|
+
import {defineConfig} from '@sanity/pkg-utils'
|
|
187
|
+
|
|
188
|
+
export default defineConfig({
|
|
189
|
+
dist: '${outDir}',
|
|
190
|
+
tsconfig: 'tsconfig.${outDir}.json',
|
|
191
|
+
|
|
192
|
+
// Remove this block to enable strict export validation
|
|
193
|
+
extract: {
|
|
194
|
+
rules: {
|
|
195
|
+
'ae-incompatible-release-tags': 'off',
|
|
196
|
+
'ae-internal-missing-underscore': 'off',
|
|
197
|
+
'ae-missing-release-tag': 'off',
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
})
|
|
201
|
+
`
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function prettierignoreTemplate(options) {
|
|
205
|
+
let { outDir } = options;
|
|
206
|
+
return {
|
|
207
|
+
type: "template",
|
|
208
|
+
to: ".prettierignore",
|
|
209
|
+
value: [
|
|
210
|
+
outDir,
|
|
211
|
+
"pnpm-lock.yaml",
|
|
212
|
+
"yarn.lock",
|
|
213
|
+
"package-lock.json"
|
|
214
|
+
].join("\n")
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
function tsconfigTemplate(options) {
|
|
218
|
+
let { flags } = options;
|
|
219
|
+
return {
|
|
220
|
+
type: "template",
|
|
221
|
+
force: flags.force,
|
|
222
|
+
to: "tsconfig.json",
|
|
223
|
+
value: outdent$1`
|
|
224
|
+
{
|
|
225
|
+
"extends": "./tsconfig.settings",
|
|
226
|
+
"include": ["./src", "./package.config.ts"]
|
|
227
|
+
}
|
|
228
|
+
`
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function tsconfigTemplateDist(options) {
|
|
232
|
+
let { flags, outDir } = options;
|
|
233
|
+
return {
|
|
234
|
+
type: "template",
|
|
235
|
+
force: flags.force,
|
|
236
|
+
to: `tsconfig.${outDir}.json`,
|
|
237
|
+
value: outdent$1`
|
|
238
|
+
{
|
|
239
|
+
"extends": "./tsconfig.settings",
|
|
240
|
+
"include": ["./src"],
|
|
241
|
+
"exclude": [
|
|
242
|
+
"./src/**/__fixtures__",
|
|
243
|
+
"./src/**/__mocks__",
|
|
244
|
+
"./src/**/*.test.ts",
|
|
245
|
+
"./src/**/*.test.tsx"
|
|
246
|
+
]
|
|
247
|
+
}
|
|
248
|
+
`
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
function tsconfigTemplateSettings(options) {
|
|
252
|
+
let { flags, outDir } = options;
|
|
253
|
+
return {
|
|
254
|
+
type: "template",
|
|
255
|
+
force: flags.force,
|
|
256
|
+
to: "tsconfig.settings.json",
|
|
257
|
+
value: outdent$1`
|
|
258
|
+
{
|
|
259
|
+
"compilerOptions": {
|
|
260
|
+
"rootDir": ".",
|
|
261
|
+
"outDir": "./${outDir}",
|
|
262
|
+
|
|
263
|
+
"target": "esnext",
|
|
264
|
+
"jsx": "preserve",
|
|
265
|
+
"module": "preserve",
|
|
266
|
+
"moduleResolution": "bundler",
|
|
267
|
+
"esModuleInterop": true,
|
|
268
|
+
"resolveJsonModule": true,
|
|
269
|
+
"moduleDetection": "force",
|
|
270
|
+
"strict": true,
|
|
271
|
+
"allowSyntheticDefaultImports": true,
|
|
272
|
+
"skipLibCheck": true,
|
|
273
|
+
"forceConsistentCasingInFileNames": true,
|
|
274
|
+
"isolatedModules": true,
|
|
275
|
+
|
|
276
|
+
// Don't emit by default, pkg-utils will ignore this when generating .d.ts files
|
|
277
|
+
"noEmit": true
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
`
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
const renovatePreset = {
|
|
284
|
+
name: "renovatebot",
|
|
285
|
+
description: "Files to enable renovatebot.",
|
|
286
|
+
apply: applyPreset$2
|
|
287
|
+
};
|
|
288
|
+
async function applyPreset$2(options) {
|
|
289
|
+
await writeAssets([{
|
|
290
|
+
type: "copy",
|
|
291
|
+
from: ["renovatebot", "renovate.json"],
|
|
292
|
+
to: "renovate.json"
|
|
293
|
+
}], options);
|
|
294
|
+
}
|
|
295
|
+
function generateReadme(data) {
|
|
296
|
+
let { user, pluginName, license } = data;
|
|
297
|
+
return outdent`
|
|
298
|
+
# ${pluginName}
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
${installationSnippet(pluginName ?? "unknown")}
|
|
302
|
+
|
|
303
|
+
## Usage
|
|
304
|
+
|
|
305
|
+
Add it as a plugin in \`sanity.config.ts\` (or .js):
|
|
306
|
+
|
|
307
|
+
\`\`\`ts
|
|
308
|
+
import {defineConfig} from 'sanity'
|
|
309
|
+
import {myPlugin} from '${pluginName}'
|
|
310
|
+
|
|
311
|
+
export default defineConfig({
|
|
312
|
+
//...
|
|
313
|
+
plugins: [myPlugin({})],
|
|
314
|
+
})
|
|
315
|
+
\`\`\`
|
|
316
|
+
|
|
317
|
+
${getLicenseText(license?.id, user?.name ? user : void 0)}
|
|
318
|
+
${developTestSnippet()}
|
|
319
|
+
` + "\n";
|
|
320
|
+
}
|
|
321
|
+
function installationSnippet(packageName) {
|
|
322
|
+
return outdent`
|
|
323
|
+
## Installation
|
|
324
|
+
|
|
325
|
+
\`\`\`sh
|
|
326
|
+
npm install ${packageName}
|
|
327
|
+
\`\`\`
|
|
328
|
+
`;
|
|
329
|
+
}
|
|
330
|
+
function developTestSnippet() {
|
|
331
|
+
return outdent`
|
|
332
|
+
## Develop & test
|
|
333
|
+
|
|
334
|
+
This plugin uses [@sanity/plugin-kit](https://github.com/sanity-io/plugin-kit)
|
|
335
|
+
with default configuration for build & watch scripts.
|
|
336
|
+
|
|
337
|
+
See [Testing a plugin in Sanity Studio](https://github.com/sanity-io/plugin-kit#testing-a-plugin-in-sanity-studio)
|
|
338
|
+
on how to run this plugin with hotreload in the studio.
|
|
339
|
+
`;
|
|
340
|
+
}
|
|
341
|
+
function getLicenseText(licenseId, user) {
|
|
342
|
+
if (!licenseId) return "";
|
|
343
|
+
let license = licenses.find(licenseId), licenseName = license ? license.title : void 0;
|
|
344
|
+
licenseName = licenseName?.replace(/\s+license$/i, "");
|
|
345
|
+
let licenseText = "## License\n";
|
|
346
|
+
return licenseText = licenseName && user?.name ? `${licenseText}\n[${licenseName}](LICENSE) © ${user?.name}\n` : licenseName ? `${licenseText}\n[${licenseName}](LICENSE)\n` : `${licenseText}\nSee [LICENSE](LICENSE)`, licenseText;
|
|
347
|
+
}
|
|
348
|
+
function isDefaultGitHubReadme(readme) {
|
|
349
|
+
if (!readme) return !1;
|
|
350
|
+
let lines = readme.split("\n", 20).filter(Boolean);
|
|
351
|
+
return lines.length <= 2 && lines[0].startsWith("#");
|
|
352
|
+
}
|
|
353
|
+
const requester = createRequester({
|
|
354
|
+
headers: { "User-Agent": `${name}@${version}` },
|
|
355
|
+
as: "json"
|
|
356
|
+
});
|
|
357
|
+
async function getUserInfo({ requireUserConfirmation, flags }, pkg) {
|
|
358
|
+
let userInfo = getPackageUserInfo({ author: flags.author ?? pkg?.author }) || await getSanityUserInfo() || await getGitUserInfo();
|
|
359
|
+
return requireUserConfirmation ? promptForInfo(userInfo) : userInfo;
|
|
360
|
+
}
|
|
361
|
+
function getPackageUserInfo(pkg) {
|
|
362
|
+
let author = pkg?.author;
|
|
363
|
+
if (!author) return;
|
|
364
|
+
if (author && typeof author != "string") return author;
|
|
365
|
+
if (!author.includes("@")) return { name: author };
|
|
366
|
+
let [pre, ...post] = author.replace(/[<>[\]]/g, "").split(/@/), nameParts = pre.split(/\s+/), email = [nameParts[nameParts.length - 1], ...post].join("@");
|
|
367
|
+
return {
|
|
368
|
+
name: nameParts.slice(0, -1).join(" "),
|
|
369
|
+
email
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
async function promptForInfo(defValue) {
|
|
373
|
+
return {
|
|
374
|
+
name: await prompt("Author name", {
|
|
375
|
+
filter: filterString,
|
|
376
|
+
default: defValue && defValue.name,
|
|
377
|
+
validate: requiredString
|
|
378
|
+
}),
|
|
379
|
+
email: await prompt("Author email", {
|
|
380
|
+
filter: filterString,
|
|
381
|
+
default: defValue && defValue.email,
|
|
382
|
+
validate: validOrEmptyEmail
|
|
383
|
+
})
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
async function getSanityUserInfo() {
|
|
387
|
+
try {
|
|
388
|
+
let token = (await readJsonFile(path.join(xdgBasedir.config ?? "", "sanity", "config.json")))?.authToken;
|
|
389
|
+
if (!token) return;
|
|
390
|
+
let { body: user } = await requester({
|
|
391
|
+
url: "https://api.sanity.io/v1/users/me",
|
|
392
|
+
as: "json",
|
|
393
|
+
headers: { Authorization: `Bearer ${token}` }
|
|
394
|
+
});
|
|
395
|
+
if (!user) return;
|
|
396
|
+
let { name, email } = user;
|
|
397
|
+
return {
|
|
398
|
+
name,
|
|
399
|
+
email
|
|
400
|
+
};
|
|
401
|
+
} catch {
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
async function getGitUserInfo() {
|
|
406
|
+
try {
|
|
407
|
+
let name = execSync("git config user.name", { encoding: "utf8" }).trim(), email = execSync("git config user.email", { encoding: "utf8" }).trim();
|
|
408
|
+
return name ? {
|
|
409
|
+
name,
|
|
410
|
+
email: email || void 0
|
|
411
|
+
} : void 0;
|
|
412
|
+
} catch {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
function filterString(val) {
|
|
417
|
+
return (val || "").trim();
|
|
418
|
+
}
|
|
419
|
+
function requiredString(value) {
|
|
420
|
+
return value.length > 1 ? !0 : "Required";
|
|
421
|
+
}
|
|
422
|
+
function validOrEmptyEmail(value) {
|
|
423
|
+
return value ? validate(value) ? !0 : "Must either be a valid email or empty" : !0;
|
|
424
|
+
}
|
|
425
|
+
const semverWorkflowPreset = {
|
|
426
|
+
name: "semver-workflow",
|
|
427
|
+
description: "Files and dependencies for conventional-commits, github workflow and semantic-release.",
|
|
428
|
+
apply: applyPreset$1
|
|
429
|
+
}, info = (write, msg, ...args) => write && log_default.info(msg, ...args);
|
|
430
|
+
async function applyPreset$1(options) {
|
|
431
|
+
await writeAssets(semverWorkflowFiles(), options), await addPrepareScript(options), await addDevDependencies$1(options), await updateReadme(options);
|
|
432
|
+
}
|
|
433
|
+
async function addPrepareScript(options) {
|
|
434
|
+
info(await addPackageJsonScripts(await getPackage(options), options, (scripts) => (scripts.prepare = addScript("husky", scripts.prepare), scripts)), "Added prepare script to package.json");
|
|
435
|
+
}
|
|
436
|
+
async function addDevDependencies$1(options) {
|
|
437
|
+
let pkg = await getPackage(options), devDeps = sortKeys({
|
|
438
|
+
...pkg.devDependencies,
|
|
439
|
+
...await semverWorkflowDependencies()
|
|
440
|
+
}), newPkg = { ...pkg };
|
|
441
|
+
newPkg.devDependencies = devDeps, await writePackageJsonDirect(newPkg, options), log_default.info("Updated devDependencies."), log_default.info(chalk.green(outdent`
|
|
442
|
+
semantic-release preset injected.
|
|
443
|
+
|
|
444
|
+
Please confer
|
|
445
|
+
https://github.com/sanity-io/plugin-kit/blob/main/docs/semver-workflow.md#manual-steps-after-inject
|
|
446
|
+
to finalize configuration for this preset.
|
|
447
|
+
`.trim()));
|
|
448
|
+
}
|
|
449
|
+
async function updateReadme(options) {
|
|
450
|
+
let { basePath } = options, readmePath = path.join(basePath, "README.md"), readme = await readFile(readmePath, "utf8").catch(errorToUndefined) ?? "", { install, usage, developTest, license, releaseSnippet } = await readmeSnippets(options), prependSections = missingSections(readme, [install, usage]), appendSections = missingSections(readme, [
|
|
451
|
+
license,
|
|
452
|
+
developTest,
|
|
453
|
+
releaseSnippet
|
|
454
|
+
]);
|
|
455
|
+
(prependSections.length || appendSections.length) && (await writeFile(readmePath, [
|
|
456
|
+
...prependSections,
|
|
457
|
+
readme,
|
|
458
|
+
...appendSections
|
|
459
|
+
].filter(Boolean).join("\n\n"), { encoding: "utf8" }), log_default.info("Updated README. Please review the changes."));
|
|
460
|
+
}
|
|
461
|
+
async function readmeSnippets(options) {
|
|
462
|
+
let pkg = await getPackage(options), user = await getUserInfo(options, pkg), bestEffortUrl = readmeBaseurl(pkg), install = installationSnippet(pkg.name ?? "unknown"), usage = outdent`
|
|
463
|
+
## Usage
|
|
464
|
+
`, license = getLicenseText(typeof pkg.license == "string" ? pkg.license : void 0, user), releaseSnippet = outdent`
|
|
465
|
+
### Release new version
|
|
466
|
+
|
|
467
|
+
Run ["CI & Release" workflow](${bestEffortUrl}/actions/workflows/main.yml).
|
|
468
|
+
Make sure to select the main branch and check "Release new version".
|
|
469
|
+
|
|
470
|
+
Semantic release will only release on configured branches, so it is safe to run release on any branch.
|
|
471
|
+
`;
|
|
472
|
+
return {
|
|
473
|
+
install,
|
|
474
|
+
usage,
|
|
475
|
+
license,
|
|
476
|
+
developTest: developTestSnippet(),
|
|
477
|
+
releaseSnippet
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Returns sections that do not exist "close enough" in readme
|
|
482
|
+
*/
|
|
483
|
+
function missingSections(readme, sections) {
|
|
484
|
+
return sections.filter((section) => !closeEnough(section, readme));
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* a and b are considered "close enough" if > 50% of a lines exist in b lines
|
|
488
|
+
* @param a
|
|
489
|
+
* @param b
|
|
490
|
+
*/
|
|
491
|
+
function closeEnough(a, b) {
|
|
492
|
+
let aLines = a.split("\n"), bLines = b.split("\n");
|
|
493
|
+
return aLines.filter((line) => bLines.find((bLine) => bLine === line)).length >= aLines.length * .5;
|
|
494
|
+
}
|
|
495
|
+
function semverWorkflowFiles() {
|
|
496
|
+
return [
|
|
497
|
+
{
|
|
498
|
+
type: "copy",
|
|
499
|
+
from: [
|
|
500
|
+
".github",
|
|
501
|
+
"workflows",
|
|
502
|
+
"main.yml"
|
|
503
|
+
],
|
|
504
|
+
to: [
|
|
505
|
+
".github",
|
|
506
|
+
"workflows",
|
|
507
|
+
"main.yml"
|
|
508
|
+
]
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
type: "copy",
|
|
512
|
+
from: [".husky", "commit-msg"],
|
|
513
|
+
to: [".husky", "commit-msg"]
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
type: "copy",
|
|
517
|
+
from: [".husky", "pre-commit"],
|
|
518
|
+
to: [".husky", "pre-commit"]
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
type: "copy",
|
|
522
|
+
from: [".releaserc.json"],
|
|
523
|
+
to: ".releaserc.json"
|
|
524
|
+
},
|
|
525
|
+
{
|
|
526
|
+
type: "copy",
|
|
527
|
+
from: ["commitlint.template.js"],
|
|
528
|
+
to: "commitlint.config.js"
|
|
529
|
+
},
|
|
530
|
+
{
|
|
531
|
+
type: "copy",
|
|
532
|
+
from: ["lint-staged.template.js"],
|
|
533
|
+
to: "lint-staged.config.js"
|
|
534
|
+
}
|
|
535
|
+
].map((fromTo) => fromTo.type === "copy" ? {
|
|
536
|
+
...fromTo,
|
|
537
|
+
from: ["semver-workflow", ...fromTo.from]
|
|
538
|
+
} : fromTo);
|
|
539
|
+
}
|
|
540
|
+
async function semverWorkflowDependencies() {
|
|
541
|
+
return resolveLatestVersions([
|
|
542
|
+
"@commitlint/cli",
|
|
543
|
+
"@commitlint/config-conventional",
|
|
544
|
+
"@sanity/semantic-release-preset",
|
|
545
|
+
"husky",
|
|
546
|
+
"lint-staged"
|
|
547
|
+
]);
|
|
548
|
+
}
|
|
549
|
+
function readmeBaseurl(pkg) {
|
|
550
|
+
return (pkg.repository?.url ?? pkg.homepage ?? "TODO").replace(/.+:\/\//g, "https://").replace(/\.git/g, "").replace(/git@github.com\//g, "github.com/").replace(/git@github.com:/g, "https://github.com/").replace(/#.+/g, "");
|
|
551
|
+
}
|
|
552
|
+
const ui = {
|
|
553
|
+
name: "ui",
|
|
554
|
+
description: "`@sanity/ui` and dependencies",
|
|
555
|
+
apply: applyPreset
|
|
556
|
+
};
|
|
557
|
+
async function applyPreset(options) {
|
|
558
|
+
await addDependencies(options), await addDevDependencies(options), log_default.info(chalk.green("ui preset injected"));
|
|
559
|
+
}
|
|
560
|
+
async function addDependencies(options) {
|
|
561
|
+
let pkg = await getPackage(options), newDeps = sortKeys(forceDependencyVersions({
|
|
562
|
+
...pkg.dependencies,
|
|
563
|
+
...await resolveDependencyList()
|
|
564
|
+
}, forcedPackageVersions)), newPkg = { ...pkg };
|
|
565
|
+
newPkg.dependencies = newDeps, await writePackageJsonDirect(newPkg, options), log_default.info("Updated dependencies.");
|
|
566
|
+
}
|
|
567
|
+
async function addDevDependencies(options) {
|
|
568
|
+
let pkg = await getPackage(options), newDeps = sortKeys(forceDependencyVersions({
|
|
569
|
+
...pkg.devDependencies,
|
|
570
|
+
...await resolveDevDependencyList()
|
|
571
|
+
}, forcedDevPackageVersions)), newPkg = { ...pkg };
|
|
572
|
+
newPkg.devDependencies = newDeps, await writePackageJsonDirect(newPkg, options), log_default.info("Updated devDependencies.");
|
|
573
|
+
}
|
|
574
|
+
async function resolveDependencyList() {
|
|
575
|
+
return resolveLatestVersions(["@sanity/icons", "@sanity/ui"]);
|
|
576
|
+
}
|
|
577
|
+
async function resolveDevDependencyList() {
|
|
578
|
+
return resolveLatestVersions([
|
|
579
|
+
"react",
|
|
580
|
+
"react-dom",
|
|
581
|
+
"styled-components"
|
|
582
|
+
]);
|
|
583
|
+
}
|
|
584
|
+
const presets = [
|
|
585
|
+
semverWorkflowPreset,
|
|
586
|
+
renovatePreset,
|
|
587
|
+
ui
|
|
588
|
+
], presetNames = presets.map((p) => p?.name);
|
|
589
|
+
function presetHelpList(padStart) {
|
|
590
|
+
return presets.map((p) => `${"".padStart(padStart)}${p.name.padEnd(20)}${p.description}`).join("\n");
|
|
591
|
+
}
|
|
592
|
+
async function injectPresets(options) {
|
|
593
|
+
if (options.flags.presetOnly && !options.flags.preset?.length) throw Error("--preset-only, but no --preset [preset-name] was provided.");
|
|
594
|
+
let applyPresets = presetsFromInput(options.flags.preset);
|
|
595
|
+
for (let preset of applyPresets) await preset.apply(options);
|
|
596
|
+
}
|
|
597
|
+
function presetsFromInput(inputPresets) {
|
|
598
|
+
if (!inputPresets) return [];
|
|
599
|
+
let unknownPresets = inputPresets.filter((p) => !presetNames.includes(p));
|
|
600
|
+
if (unknownPresets.length) throw Error(`Unknown --preset(s): [${unknownPresets.join(", ")}]. Must be one of: [${presetNames.join(", ")}]`);
|
|
601
|
+
return inputPresets.filter(onlyUnique).map((presetName) => presets.find((p) => p.name === presetName)).filter((p) => !!p);
|
|
602
|
+
}
|
|
603
|
+
function onlyUnique(value, index, arr) {
|
|
604
|
+
return arr.indexOf(value) === index;
|
|
605
|
+
}
|
|
606
|
+
const bannedFields = [
|
|
607
|
+
"login",
|
|
608
|
+
"description",
|
|
609
|
+
"projecturl",
|
|
610
|
+
"email"
|
|
611
|
+
], preferredLicenses = [
|
|
612
|
+
"MIT",
|
|
613
|
+
"ISC",
|
|
614
|
+
"BSD-3-Clause"
|
|
615
|
+
], otherLicenses = Object.keys(licenses.list).filter((id) => {
|
|
616
|
+
let license = licenses.list[id];
|
|
617
|
+
return !preferredLicenses.includes(id) && !bannedFields.some((field) => license.body.includes(`[${field}]`));
|
|
618
|
+
});
|
|
619
|
+
async function inject(options) {
|
|
620
|
+
options.flags.presetOnly ? log_default.info("Only apply presets, skipping default inject.") : await injectBase(options), await injectPresets(options);
|
|
621
|
+
}
|
|
622
|
+
async function injectBase(options) {
|
|
623
|
+
let { basePath, flags, requireUserConfirmation } = options, info = (write, msg, ...args) => write && log_default.info(msg, ...args), pkg = await getPackage(options).catch(errorToUndefined);
|
|
624
|
+
log_default.debug("Plugin has package.json: %s", pkg ? "yes" : "no");
|
|
625
|
+
let user = await getUserInfo(options, pkg);
|
|
626
|
+
log_default.debug("User information: %o", user);
|
|
627
|
+
let pkgName = flags.name ?? pkg?.name, pluginName = requireUserConfirmation || !pkgName ? await promptForPackageName(options, pkgName) : pkgName;
|
|
628
|
+
log_default.debug("Plugin name: %s", pluginName);
|
|
629
|
+
let license = await getLicense(flags, {
|
|
630
|
+
user,
|
|
631
|
+
pluginName,
|
|
632
|
+
pkg,
|
|
633
|
+
requireUserConfirmation
|
|
634
|
+
}), licenseChanged = (pkg && pkg.license) !== (license && license.id);
|
|
635
|
+
log_default.debug("License: %s", license ? license.id : "<none>");
|
|
636
|
+
let description = await getProjectDescription(basePath, pkg, requireUserConfirmation);
|
|
637
|
+
log_default.debug("Description: %s", description || "<none>");
|
|
638
|
+
let repoUrl = flags.repo ?? (await gitRemoteOriginUrl(basePath).catch(errorToUndefined) || pkg?.repository?.url), gitOrigin = requireUserConfirmation ? await promptForRepoOrigin(options, repoUrl) : repoUrl;
|
|
639
|
+
log_default.debug("Remote origin: %s", gitOrigin || "<none>");
|
|
640
|
+
let data = {
|
|
641
|
+
user,
|
|
642
|
+
pluginName,
|
|
643
|
+
license,
|
|
644
|
+
description,
|
|
645
|
+
pkg,
|
|
646
|
+
gitOrigin
|
|
647
|
+
}, didWrite, newPkg = await writePackageJson(data, options);
|
|
648
|
+
info(newPkg !== pkg, "Wrote package.json"), data.pkg = newPkg, didWrite = await writeLicense(data, options, licenseChanged), info(didWrite, "Wrote license file (LICENSE)"), didWrite = await writeReadme(data, options), info(didWrite, "Wrote readme file (README.md)"), didWrite = await writeStaticAssets(options), info(didWrite.length > 0, "Wrote static asset files: %s", didWrite.join(", ")), didWrite = await addBuildScripts(newPkg, options), info(didWrite, "Added build scripts to package.json"), didWrite = await addCompileDirToGitIgnore(options), info(didWrite, "Added compilation output directory to .gitignore");
|
|
649
|
+
}
|
|
650
|
+
async function writeReadme(data, options) {
|
|
651
|
+
let { basePath } = options, readmePath = path.join(basePath, "README.md"), readme = await readFile(readmePath, "utf8").catch(errorToUndefined);
|
|
652
|
+
return readme && !isDefaultGitHubReadme(readme) ? !1 : (await writeFileWithOverwritePrompt(readmePath, generateReadme(data), {
|
|
653
|
+
encoding: "utf8",
|
|
654
|
+
force: options.flags.force
|
|
655
|
+
}), !0);
|
|
656
|
+
}
|
|
657
|
+
async function writeLicense({ license }, options, licenseChanged) {
|
|
658
|
+
let { basePath, flags } = options;
|
|
659
|
+
if (flags.license === !1 || !license) return !1;
|
|
660
|
+
let hasLicenseMdFile = await fileExists(path.join(basePath, "LICENSE.md"));
|
|
661
|
+
return await writeFileWithOverwritePrompt(path.join(basePath, hasLicenseMdFile ? "LICENSE.md" : "LICENSE"), license.text, {
|
|
662
|
+
encoding: "utf8",
|
|
663
|
+
default: licenseChanged,
|
|
664
|
+
force: flags.force
|
|
665
|
+
}), !0;
|
|
666
|
+
}
|
|
667
|
+
async function getLicense(flags, { user, pluginName, pkg, requireUserConfirmation }) {
|
|
668
|
+
let license = await getLicenseIdentifier(flags, pkg, requireUserConfirmation);
|
|
669
|
+
if (!license) return;
|
|
670
|
+
let text = license.body.replace(/\[fullname\]/g, user?.name ?? "").replace(/\[project\]/g, pluginName ?? "").replace(/\[year\]/g, String((/* @__PURE__ */ new Date()).getFullYear()));
|
|
671
|
+
return {
|
|
672
|
+
id: license.id,
|
|
673
|
+
text
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
async function getLicenseIdentifier(flags, pkg, requireUserConfirmation = !1) {
|
|
677
|
+
if (flags.license === !1) return null;
|
|
678
|
+
if (typeof flags.license == "string") {
|
|
679
|
+
let license = licenses.find(`${flags.license}`);
|
|
680
|
+
if (!license) throw Error(`License "${flags.license}" not found`);
|
|
681
|
+
return license;
|
|
682
|
+
}
|
|
683
|
+
if (pkg && pkg.license && !requireUserConfirmation) {
|
|
684
|
+
let license = licenses.find(`${pkg.license}`);
|
|
685
|
+
if (license) return license;
|
|
686
|
+
log_default.warn(`package.json contains license "${pkg.license}", which is not recognized`);
|
|
687
|
+
}
|
|
688
|
+
let licenseId = await prompt("Which license do you want to use?", {
|
|
689
|
+
default: pkg && pkg.license && licenses.find(pkg.license) ? pkg.license : preferredLicenses[0],
|
|
690
|
+
choices: [
|
|
691
|
+
prompt.separator(),
|
|
692
|
+
...preferredLicenses.map((value) => ({
|
|
693
|
+
value,
|
|
694
|
+
name: licenses.list[value].title
|
|
695
|
+
})),
|
|
696
|
+
prompt.separator(),
|
|
697
|
+
...otherLicenses.map((value) => ({
|
|
698
|
+
value,
|
|
699
|
+
name: licenses.list[value].title
|
|
700
|
+
}))
|
|
701
|
+
]
|
|
702
|
+
});
|
|
703
|
+
return licenses.find(licenseId);
|
|
704
|
+
}
|
|
705
|
+
async function getProjectDescription(basePath, pkg, requireUserConfirmation = !1) {
|
|
706
|
+
let description = await resolveProjectDescription(basePath, pkg);
|
|
707
|
+
return requireUserConfirmation && (description = await prompt("Plugin description", { default: description || "" })), description ?? "";
|
|
708
|
+
}
|
|
709
|
+
async function resolveProjectDescription(basePath, pkg) {
|
|
710
|
+
if (pkg && typeof pkg.description == "string" && pkg.description.length > 5) return pkg.description;
|
|
711
|
+
try {
|
|
712
|
+
let [title, description] = (await readFile(path.join(basePath, "README.md"), "utf8")).split("\n").filter(Boolean);
|
|
713
|
+
if (!title || !description || !title.match(/^#\s+\w+/)) return null;
|
|
714
|
+
let unlinked = description.replace(/\[(.*?)\]\(.*?\)/g, "$1");
|
|
715
|
+
return /^[^#]/.test(unlinked) ? unlinked : null;
|
|
716
|
+
} catch (err) {
|
|
717
|
+
return errorToUndefined(err);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
async function writeAssets(injectables, { basePath, flags }) {
|
|
721
|
+
let assetsDir = await findAssetsDir(), from = (...segments) => path.join(assetsDir, "inject", ...segments), to = (...segments) => path.join(basePath, ...segments), writes = [];
|
|
722
|
+
for (let injectable of injectables) {
|
|
723
|
+
if (injectable.type === "copy") {
|
|
724
|
+
let fromPath = asArray(injectable.from), toPath = asArray(injectable.to);
|
|
725
|
+
await copyFileWithOverwritePrompt(from(...fromPath), to(...toPath), flags) && writes.push(path.join(...toPath));
|
|
726
|
+
continue;
|
|
727
|
+
}
|
|
728
|
+
if (injectable.type === "template") {
|
|
729
|
+
let toPath = asArray(injectable.to);
|
|
730
|
+
await writeFileWithOverwritePrompt(to(...toPath), `${injectable.value.trim()}\n`, {
|
|
731
|
+
default: "n",
|
|
732
|
+
force: injectable.force || flags.force
|
|
733
|
+
}), writes.push(path.join(...toPath));
|
|
734
|
+
continue;
|
|
735
|
+
}
|
|
736
|
+
throw Error(`Unknown operation type "${injectable.type}"`);
|
|
737
|
+
}
|
|
738
|
+
return writes;
|
|
739
|
+
}
|
|
740
|
+
async function writeStaticAssets(options) {
|
|
741
|
+
let { outDir, flags } = options;
|
|
742
|
+
return writeAssets([
|
|
743
|
+
flags.eslint && eslintrcTemplate({ flags: options.flags }),
|
|
744
|
+
flags.eslint && eslintignoreTemplate({
|
|
745
|
+
outDir,
|
|
746
|
+
flags: options.flags
|
|
747
|
+
}),
|
|
748
|
+
{
|
|
749
|
+
type: "copy",
|
|
750
|
+
from: "editorconfig",
|
|
751
|
+
to: ".editorconfig"
|
|
752
|
+
},
|
|
753
|
+
pkgConfigTemplate({
|
|
754
|
+
outDir,
|
|
755
|
+
flags: options.flags
|
|
756
|
+
}),
|
|
757
|
+
flags.gitignore && gitignoreTemplate(),
|
|
758
|
+
flags.typescript && tsconfigTemplate({ flags: options.flags }),
|
|
759
|
+
flags.typescript && tsconfigTemplateDist({
|
|
760
|
+
outDir,
|
|
761
|
+
flags: options.flags
|
|
762
|
+
}),
|
|
763
|
+
flags.typescript && tsconfigTemplateSettings({
|
|
764
|
+
outDir,
|
|
765
|
+
flags: options.flags
|
|
766
|
+
}),
|
|
767
|
+
flags.prettier && prettierignoreTemplate({ outDir }),
|
|
768
|
+
flags.prettier && {
|
|
769
|
+
type: "copy",
|
|
770
|
+
from: "prettierrc.json",
|
|
771
|
+
to: ".prettierrc"
|
|
772
|
+
}
|
|
773
|
+
].map((f) => f || void 0).filter((f) => !!f), options);
|
|
774
|
+
}
|
|
775
|
+
function asArray(input) {
|
|
776
|
+
return typeof input == "string" ? [input] : input;
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* assets dir might be in higher or lower in the dir hierarchy depending on
|
|
780
|
+
* if we run from `dist` or `src`
|
|
781
|
+
*/
|
|
782
|
+
async function findAssetsDir() {
|
|
783
|
+
let maxBackpaddle = 3, currDir = path.dirname(fileURLToPath(import.meta.url)), assetsDir = "";
|
|
784
|
+
for (; !assetsDir && maxBackpaddle;) {
|
|
785
|
+
currDir = path.join(currDir, "..");
|
|
786
|
+
let assets = path.join(currDir, "assets");
|
|
787
|
+
await fileExists(assets) ? assetsDir = assets : maxBackpaddle--;
|
|
788
|
+
}
|
|
789
|
+
if (!assetsDir) throw Error("Could not find assets directory!");
|
|
790
|
+
return assetsDir;
|
|
791
|
+
}
|
|
792
|
+
async function addCompileDirToGitIgnore(options) {
|
|
793
|
+
let gitIgnorePath = path.join(options.basePath, ".gitignore"), gitignore = await readFile(gitIgnorePath, "utf8").catch(errorToUndefined);
|
|
794
|
+
if (!gitignore) return !1;
|
|
795
|
+
let ignore = options.outDir.replace(/^[./]+/, "").split("/")[0];
|
|
796
|
+
if (!ignore) return !1;
|
|
797
|
+
let lines = gitignore.trim().split("\n");
|
|
798
|
+
return lines.includes(ignore) ? !1 : (lines.push("", "# Compiled plugin", ignore), await writeFile(gitIgnorePath, lines.join("\n") + "\n", { encoding: "utf8" }), !0);
|
|
799
|
+
}
|
|
800
|
+
const initFlags = {
|
|
801
|
+
...sharedFlags_default,
|
|
802
|
+
scripts: {
|
|
803
|
+
type: "boolean",
|
|
804
|
+
default: !0
|
|
805
|
+
},
|
|
806
|
+
eslint: {
|
|
807
|
+
type: "boolean",
|
|
808
|
+
default: !0
|
|
809
|
+
},
|
|
810
|
+
typescript: {
|
|
811
|
+
type: "boolean",
|
|
812
|
+
default: !0
|
|
813
|
+
},
|
|
814
|
+
prettier: {
|
|
815
|
+
type: "boolean",
|
|
816
|
+
default: !0
|
|
817
|
+
},
|
|
818
|
+
license: { type: "string" },
|
|
819
|
+
editorconfig: {
|
|
820
|
+
type: "boolean",
|
|
821
|
+
default: !0
|
|
822
|
+
},
|
|
823
|
+
gitignore: {
|
|
824
|
+
type: "boolean",
|
|
825
|
+
default: !0
|
|
826
|
+
},
|
|
827
|
+
force: {
|
|
828
|
+
type: "boolean",
|
|
829
|
+
default: !1
|
|
830
|
+
},
|
|
831
|
+
install: {
|
|
832
|
+
type: "boolean",
|
|
833
|
+
default: !0
|
|
834
|
+
},
|
|
835
|
+
name: { type: "string" },
|
|
836
|
+
author: { type: "string" },
|
|
837
|
+
repo: { type: "string" },
|
|
838
|
+
presetOnly: {
|
|
839
|
+
type: "boolean",
|
|
840
|
+
default: !1
|
|
841
|
+
},
|
|
842
|
+
preset: {
|
|
843
|
+
type: "string",
|
|
844
|
+
isMultiple: !0
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
async function init(options) {
|
|
848
|
+
let dependencies = {}, devDependencies = {}, peerDependencies = {};
|
|
849
|
+
await inject({
|
|
850
|
+
...options,
|
|
851
|
+
outDir: defaultOutDir,
|
|
852
|
+
requireUserConfirmation: !options.flags.force,
|
|
853
|
+
dependencies,
|
|
854
|
+
devDependencies,
|
|
855
|
+
peerDependencies,
|
|
856
|
+
validate: !1
|
|
857
|
+
});
|
|
858
|
+
let packageJson = await getPackage({
|
|
859
|
+
basePath: options.basePath,
|
|
860
|
+
validate: !1
|
|
861
|
+
}), typescript = options.flags.typescript, source = typescript ? defaultSourceTs(packageJson) : defaultSourceJs(packageJson), filename = typescript ? "index.ts" : "index.js", srcDir = path.resolve(options.basePath, "src");
|
|
862
|
+
await ensureDir(srcDir), await writeFile(path.join(srcDir, filename), source, { encoding: "utf8" });
|
|
863
|
+
}
|
|
864
|
+
export { presetHelpList as i, initFlags as n, inject as r, init as t };
|
|
865
|
+
|
|
866
|
+
//# sourceMappingURL=init.js.map
|