@sanity/plugin-kit 4.0.20 → 5.0.0
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/assets/inject/semver-workflow/.husky/commit-msg +0 -0
- package/assets/inject/semver-workflow/.husky/pre-commit +0 -0
- package/assets/inject/ui-workshop/src/__workshop__/props.tsx +2 -1
- package/bin/plugin-kit.js +3 -1
- package/dist/{_chunks-cjs/cli.js → _chunks-es/index.js} +53 -63
- package/dist/_chunks-es/index.js.map +1 -0
- package/dist/{_chunks-cjs/init2.js → _chunks-es/init.js} +25 -23
- package/dist/_chunks-es/init.js.map +1 -0
- package/dist/_chunks-es/init2.js +140 -0
- package/dist/_chunks-es/init2.js.map +1 -0
- package/{src/cmds/inject.ts → dist/_chunks-es/inject.js} +18 -32
- package/dist/{_chunks-cjs → _chunks-es}/inject.js.map +1 -1
- package/dist/_chunks-es/link-watch.js +91 -0
- package/dist/_chunks-es/link-watch.js.map +1 -0
- package/dist/_chunks-es/load-package-config.js +22 -0
- package/dist/_chunks-es/load-package-config.js.map +1 -0
- package/dist/_chunks-es/package.js +1759 -0
- package/dist/_chunks-es/package.js.map +1 -0
- package/dist/_chunks-es/package2.js +9 -0
- package/dist/{_chunks-cjs → _chunks-es}/package2.js.map +1 -1
- package/dist/_chunks-es/ts.js +171 -0
- package/dist/_chunks-es/ts.js.map +1 -0
- package/dist/_chunks-es/verify-package.js +92 -0
- package/dist/_chunks-es/verify-package.js.map +1 -0
- package/dist/_chunks-es/verify-studio.js +61 -0
- package/dist/_chunks-es/verify-studio.js.map +1 -0
- package/dist/_chunks-es/version.js +50 -0
- package/dist/_chunks-es/version.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/package.json +40 -98
- package/LICENSE +0 -21
- package/dist/_chunks-cjs/cli.js.map +0 -1
- package/dist/_chunks-cjs/init.js +0 -892
- package/dist/_chunks-cjs/init.js.map +0 -1
- package/dist/_chunks-cjs/init2.js.map +0 -1
- package/dist/_chunks-cjs/inject.js +0 -54
- package/dist/_chunks-cjs/link-watch.js +0 -84
- package/dist/_chunks-cjs/link-watch.js.map +0 -1
- package/dist/_chunks-cjs/package.js +0 -1809
- package/dist/_chunks-cjs/package.js.map +0 -1
- package/dist/_chunks-cjs/package2.js +0 -8
- package/dist/_chunks-cjs/ts.js +0 -160732
- package/dist/_chunks-cjs/ts.js.map +0 -1
- package/dist/_chunks-cjs/verify-package.js +0 -75
- package/dist/_chunks-cjs/verify-package.js.map +0 -1
- package/dist/_chunks-cjs/verify-studio.js +0 -57
- package/dist/_chunks-cjs/verify-studio.js.map +0 -1
- package/dist/_chunks-cjs/version.js +0 -51
- package/dist/_chunks-cjs/version.js.map +0 -1
- package/dist/cli.d.ts +0 -4
- package/dist/cli.js +0 -6
- package/dist/cli.js.map +0 -1
- package/src/actions/init.ts +0 -95
- package/src/actions/inject.ts +0 -399
- package/src/actions/link-watch.ts +0 -98
- package/src/actions/verify/types.ts +0 -56
- package/src/actions/verify/validations.ts +0 -505
- package/src/actions/verify/verify-common.ts +0 -93
- package/src/actions/verify-package.ts +0 -103
- package/src/actions/verify-studio.ts +0 -58
- package/src/cli.ts +0 -77
- package/src/cmds/index.ts +0 -20
- package/src/cmds/init.ts +0 -90
- package/src/cmds/link-watch.ts +0 -50
- package/src/cmds/verify-package.ts +0 -36
- package/src/cmds/verify-studio.ts +0 -36
- package/src/cmds/version.ts +0 -67
- package/src/configs/banned-packages.ts +0 -27
- package/src/configs/buildExtensions.ts +0 -1
- package/src/configs/default-source.ts +0 -64
- package/src/configs/eslint.ts +0 -51
- package/src/configs/forced-package-versions.ts +0 -12
- package/src/configs/git.ts +0 -68
- package/src/configs/pkg-config.ts +0 -30
- package/src/configs/prettier.ts +0 -11
- package/src/configs/tsconfig.ts +0 -78
- package/src/configs/uselessFiles.ts +0 -29
- package/src/constants.ts +0 -15
- package/src/dependencies/find.ts +0 -193
- package/src/dependencies/import-linter.ts +0 -95
- package/src/index.ts +0 -1
- package/src/npm/manager.ts +0 -44
- package/src/npm/package.ts +0 -427
- package/src/npm/publish.ts +0 -9
- package/src/npm/resolveLatestVersions.ts +0 -31
- package/src/presets/presets.ts +0 -54
- package/src/presets/renovatebot.ts +0 -21
- package/src/presets/semver-workflow.ts +0 -186
- package/src/presets/ui-workshop.ts +0 -97
- package/src/presets/ui.ts +0 -67
- package/src/sanity/manifest.ts +0 -340
- package/src/sharedFlags.ts +0 -14
- package/src/util/command-parser.ts +0 -36
- package/src/util/errorToUndefined.ts +0 -7
- package/src/util/files.ts +0 -260
- package/src/util/log.ts +0 -44
- package/src/util/prompt.ts +0 -70
- package/src/util/readme.ts +0 -88
- package/src/util/request.ts +0 -11
- package/src/util/ts.ts +0 -19
- package/src/util/user.ts +0 -129
package/src/actions/inject.ts
DELETED
|
@@ -1,399 +0,0 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
// @ts-expect-error missing types
|
|
3
|
-
import licenses from '@rexxars/choosealicense-list'
|
|
4
|
-
import gitRemoteOriginUrl from 'git-remote-origin-url'
|
|
5
|
-
import log from '../util/log'
|
|
6
|
-
import {getUserInfo} from '../util/user'
|
|
7
|
-
import {errorToUndefined} from '../util/errorToUndefined'
|
|
8
|
-
import {addBuildScripts, getPackage, writePackageJson} from '../npm/package'
|
|
9
|
-
import {prompt, promptForPackageName, promptForRepoOrigin} from '../util/prompt'
|
|
10
|
-
import {generateReadme, isDefaultGitHubReadme} from '../util/readme'
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
copyFileWithOverwritePrompt,
|
|
14
|
-
fileExists,
|
|
15
|
-
readFile,
|
|
16
|
-
writeFile,
|
|
17
|
-
writeFileWithOverwritePrompt,
|
|
18
|
-
} from '../util/files'
|
|
19
|
-
import {InitFlags} from './init'
|
|
20
|
-
import {PackageJson} from './verify/types'
|
|
21
|
-
import {injectPresets} from '../presets/presets'
|
|
22
|
-
import {tsconfigTemplateDist, tsconfigTemplate, tsconfigTemplateSettings} from '../configs/tsconfig'
|
|
23
|
-
import {pkgConfigTemplate} from '../configs/pkg-config'
|
|
24
|
-
import {gitignoreTemplate} from '../configs/git'
|
|
25
|
-
import {eslintignoreTemplate, eslintrcTemplate} from '../configs/eslint'
|
|
26
|
-
import {prettierignoreTemplate} from '../configs/prettier'
|
|
27
|
-
|
|
28
|
-
const bannedFields = ['login', 'description', 'projecturl', 'email']
|
|
29
|
-
const preferredLicenses = ['MIT', 'ISC', 'BSD-3-Clause']
|
|
30
|
-
const otherLicenses = Object.keys(licenses.list).filter((id) => {
|
|
31
|
-
const license = licenses.list[id]
|
|
32
|
-
return (
|
|
33
|
-
!preferredLicenses.includes(id) &&
|
|
34
|
-
!bannedFields.some((field) => license.body.includes(`[${field}]`))
|
|
35
|
-
)
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
export interface InjectCopyFromTo {
|
|
39
|
-
type: 'copy'
|
|
40
|
-
from: string | string[]
|
|
41
|
-
to: string | string[]
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface InjectTemplate {
|
|
45
|
-
type: 'template'
|
|
46
|
-
to: string | string[]
|
|
47
|
-
value: string
|
|
48
|
-
force?: boolean
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export type Injectable = InjectCopyFromTo | InjectTemplate
|
|
52
|
-
|
|
53
|
-
export interface InjectOptions {
|
|
54
|
-
basePath: string
|
|
55
|
-
requireUserConfirmation?: boolean
|
|
56
|
-
flags: InitFlags
|
|
57
|
-
dependencies?: Record<string, string>
|
|
58
|
-
devDependencies?: Record<string, string>
|
|
59
|
-
peerDependencies?: Record<string, string>
|
|
60
|
-
validate?: boolean
|
|
61
|
-
outDir: string
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export interface PackageData {
|
|
65
|
-
user?: {name?: string; email?: string}
|
|
66
|
-
pluginName?: string
|
|
67
|
-
license?: {id: string; text: string}
|
|
68
|
-
description?: string
|
|
69
|
-
pkg?: PackageJson
|
|
70
|
-
gitOrigin?: string
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export async function inject(options: InjectOptions) {
|
|
74
|
-
if (options.flags.presetOnly) {
|
|
75
|
-
log.info('Only apply presets, skipping default inject.')
|
|
76
|
-
} else {
|
|
77
|
-
await injectBase(options)
|
|
78
|
-
}
|
|
79
|
-
await injectPresets(options)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async function injectBase(options: InjectOptions) {
|
|
83
|
-
const {basePath, flags, requireUserConfirmation} = options
|
|
84
|
-
const info = (write: boolean, msg: string, ...args: string[]) => write && log.info(msg, ...args)
|
|
85
|
-
// Gather data
|
|
86
|
-
const pkg = await getPackage(options).catch(errorToUndefined)
|
|
87
|
-
log.debug('Plugin has package.json: %s', pkg ? 'yes' : 'no')
|
|
88
|
-
|
|
89
|
-
const user = await getUserInfo(options, pkg)
|
|
90
|
-
log.debug('User information: %o', user)
|
|
91
|
-
|
|
92
|
-
const pkgName = flags.name ?? pkg?.name
|
|
93
|
-
const pluginName =
|
|
94
|
-
requireUserConfirmation || !pkgName ? await promptForPackageName(options, pkgName) : pkgName
|
|
95
|
-
|
|
96
|
-
log.debug('Plugin name: %s', pluginName)
|
|
97
|
-
|
|
98
|
-
const license = await getLicense(flags, {user, pluginName, pkg, requireUserConfirmation})
|
|
99
|
-
const licenseChanged = (pkg && pkg.license) !== (license && license.id)
|
|
100
|
-
log.debug('License: %s', license ? license.id : '<none>')
|
|
101
|
-
|
|
102
|
-
const description = await getProjectDescription(basePath, pkg, requireUserConfirmation)
|
|
103
|
-
log.debug('Description: %s', description || '<none>')
|
|
104
|
-
|
|
105
|
-
const repoUrl =
|
|
106
|
-
flags.repo ??
|
|
107
|
-
((await gitRemoteOriginUrl(basePath).catch(errorToUndefined)) || pkg?.repository?.url)
|
|
108
|
-
|
|
109
|
-
const gitOrigin = requireUserConfirmation ? await promptForRepoOrigin(options, repoUrl) : repoUrl
|
|
110
|
-
|
|
111
|
-
log.debug('Remote origin: %s', gitOrigin || '<none>')
|
|
112
|
-
|
|
113
|
-
// Output
|
|
114
|
-
const data: PackageData = {user, pluginName, license, description, pkg, gitOrigin}
|
|
115
|
-
let didWrite
|
|
116
|
-
|
|
117
|
-
// Write package.json, if returns the original (data.pkg) if it was unchanged,
|
|
118
|
-
// otherwise it returns the new object
|
|
119
|
-
const newPkg = await writePackageJson(data, options)
|
|
120
|
-
info(newPkg !== pkg, 'Wrote package.json')
|
|
121
|
-
data.pkg = newPkg
|
|
122
|
-
|
|
123
|
-
didWrite = await writeLicense(data, options, licenseChanged)
|
|
124
|
-
info(didWrite, 'Wrote license file (LICENSE)')
|
|
125
|
-
|
|
126
|
-
didWrite = await writeReadme(data, options)
|
|
127
|
-
info(didWrite, 'Wrote readme file (README.md)')
|
|
128
|
-
|
|
129
|
-
didWrite = await writeStaticAssets(options)
|
|
130
|
-
info(didWrite.length > 0, 'Wrote static asset files: %s', didWrite.join(', '))
|
|
131
|
-
|
|
132
|
-
didWrite = await addBuildScripts(newPkg, options)
|
|
133
|
-
info(didWrite, 'Added build scripts to package.json')
|
|
134
|
-
|
|
135
|
-
didWrite = await addCompileDirToGitIgnore(data, options)
|
|
136
|
-
info(didWrite, 'Added compilation output directory to .gitignore')
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
async function writeReadme(data: PackageData, options: InjectOptions) {
|
|
140
|
-
const {basePath} = options
|
|
141
|
-
|
|
142
|
-
const readmePath = path.join(basePath, 'README.md')
|
|
143
|
-
const readme = await readFile(readmePath, 'utf8').catch(errorToUndefined)
|
|
144
|
-
|
|
145
|
-
if (readme && !isDefaultGitHubReadme(readme)) {
|
|
146
|
-
return false
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
await writeFileWithOverwritePrompt(readmePath, generateReadme(data), {
|
|
150
|
-
encoding: 'utf8',
|
|
151
|
-
force: options.flags.force,
|
|
152
|
-
})
|
|
153
|
-
return true
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
async function writeLicense(
|
|
157
|
-
{license}: PackageData,
|
|
158
|
-
options: InjectOptions,
|
|
159
|
-
licenseChanged: boolean,
|
|
160
|
-
) {
|
|
161
|
-
const {basePath, flags} = options
|
|
162
|
-
|
|
163
|
-
if ((flags.license as unknown as boolean) === false || !license) {
|
|
164
|
-
return false
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Prefer whatever path the user is currenly using (LICENSE.md or LICENSE)
|
|
168
|
-
const hasLicenseMdFile = await fileExists(path.join(basePath, 'LICENSE.md'))
|
|
169
|
-
const licensePath = path.join(basePath, hasLicenseMdFile ? 'LICENSE.md' : 'LICENSE')
|
|
170
|
-
|
|
171
|
-
await writeFileWithOverwritePrompt(licensePath, license.text, {
|
|
172
|
-
encoding: 'utf8',
|
|
173
|
-
default: licenseChanged,
|
|
174
|
-
force: flags.force,
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
return true
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
async function getLicense(
|
|
181
|
-
flags: InitFlags,
|
|
182
|
-
{
|
|
183
|
-
user,
|
|
184
|
-
pluginName,
|
|
185
|
-
pkg,
|
|
186
|
-
requireUserConfirmation,
|
|
187
|
-
}: PackageData & {requireUserConfirmation?: boolean},
|
|
188
|
-
) {
|
|
189
|
-
const license = await getLicenseIdentifier(flags, pkg, requireUserConfirmation)
|
|
190
|
-
if (!license) {
|
|
191
|
-
return undefined
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const text = license.body
|
|
195
|
-
.replace(/\[fullname\]/g, user?.name)
|
|
196
|
-
.replace(/\[project\]/g, pluginName)
|
|
197
|
-
.replace(/\[year\]/g, new Date().getFullYear())
|
|
198
|
-
|
|
199
|
-
return {id: license.id, text}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
async function getLicenseIdentifier(
|
|
203
|
-
flags: InitFlags,
|
|
204
|
-
pkg: PackageJson | undefined,
|
|
205
|
-
requireUserConfirmation = false,
|
|
206
|
-
) {
|
|
207
|
-
// --no-license
|
|
208
|
-
if ((flags.license as unknown) === false) {
|
|
209
|
-
return null
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// --license becomes "", --license mit beocomes "mit"
|
|
213
|
-
if (typeof flags.license === 'string') {
|
|
214
|
-
const license = licenses.find(`${flags.license}`)
|
|
215
|
-
if (!license) {
|
|
216
|
-
throw new Error(`License "${flags.license}" not found`)
|
|
217
|
-
}
|
|
218
|
-
return license
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// no --license flag provided, do we have one in package already?
|
|
222
|
-
if (pkg && pkg.license && !requireUserConfirmation) {
|
|
223
|
-
const license = licenses.find(`${pkg.license}`)
|
|
224
|
-
if (license) {
|
|
225
|
-
return license
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// Warn, then prompt the user
|
|
229
|
-
log.warn(`package.json contains license "${pkg.license}", which is not recognized`)
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const licenseId = await prompt('Which license do you want to use?', {
|
|
233
|
-
default: pkg && pkg.license && licenses.find(pkg.license) ? pkg.license : preferredLicenses[0],
|
|
234
|
-
choices: [
|
|
235
|
-
prompt.separator(),
|
|
236
|
-
...preferredLicenses.map((value) => ({value, name: licenses.list[value].title})),
|
|
237
|
-
prompt.separator(),
|
|
238
|
-
...otherLicenses.map((value) => ({value, name: licenses.list[value].title})),
|
|
239
|
-
],
|
|
240
|
-
})
|
|
241
|
-
|
|
242
|
-
return licenses.find(licenseId)
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
async function getProjectDescription(
|
|
246
|
-
basePath: string,
|
|
247
|
-
pkg: PackageJson | undefined,
|
|
248
|
-
requireUserConfirmation = false,
|
|
249
|
-
) {
|
|
250
|
-
let description = await resolveProjectDescription(basePath, pkg)
|
|
251
|
-
if (requireUserConfirmation) {
|
|
252
|
-
description = await prompt('Plugin description', {default: description || ''})
|
|
253
|
-
}
|
|
254
|
-
return description ?? ''
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
async function resolveProjectDescription(basePath: string, pkg: PackageJson | undefined) {
|
|
258
|
-
// Try to grab from package.json
|
|
259
|
-
if (pkg && typeof pkg.description === 'string' && pkg.description.length > 5) {
|
|
260
|
-
return pkg.description
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// Try to grab a project description from a standard GitHub-generated readme
|
|
264
|
-
try {
|
|
265
|
-
const readmePath = path.join(basePath, 'README.md')
|
|
266
|
-
const readme = await readFile(readmePath, 'utf8')
|
|
267
|
-
const [title, description] = readme.split('\n').filter(Boolean)
|
|
268
|
-
if (!title || !description || !title.match(/^#\s+\w+/)) {
|
|
269
|
-
return null
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// Naive, but this isn't too important
|
|
273
|
-
const unlinked = description.replace(/\[(.*?)\]\(.*?\)/g, '$1')
|
|
274
|
-
if (/^[^#]/.test(unlinked)) {
|
|
275
|
-
return unlinked
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
return null
|
|
279
|
-
} catch (err) {
|
|
280
|
-
return errorToUndefined(err)
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
export async function writeAssets(injectables: Injectable[], {basePath, flags}: InjectOptions) {
|
|
285
|
-
const assetsDir = await findAssetsDir()
|
|
286
|
-
|
|
287
|
-
const from = (...segments: string[]) => path.join(assetsDir, 'inject', ...segments)
|
|
288
|
-
const to = (...segments: string[]) => path.join(basePath, ...segments)
|
|
289
|
-
|
|
290
|
-
const writes: string[] = []
|
|
291
|
-
for (const injectable of injectables) {
|
|
292
|
-
if (injectable.type === 'copy') {
|
|
293
|
-
const fromPath = asArray(injectable.from)
|
|
294
|
-
const toPath = asArray(injectable.to)
|
|
295
|
-
if (await copyFileWithOverwritePrompt(from(...fromPath), to(...toPath), flags)) {
|
|
296
|
-
writes.push(path.join(...toPath))
|
|
297
|
-
}
|
|
298
|
-
continue
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
if (injectable.type === 'template') {
|
|
302
|
-
const toPath = asArray(injectable.to)
|
|
303
|
-
|
|
304
|
-
await writeFileWithOverwritePrompt(to(...toPath), `${injectable.value.trim()}\n`, {
|
|
305
|
-
default: 'n',
|
|
306
|
-
force: injectable.force || flags.force,
|
|
307
|
-
})
|
|
308
|
-
|
|
309
|
-
writes.push(path.join(...toPath))
|
|
310
|
-
continue
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
throw new Error(`Unknown operation type "${(injectable as any).type}"`)
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
return writes
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
async function writeStaticAssets(options: InjectOptions) {
|
|
320
|
-
const {outDir, flags} = options
|
|
321
|
-
|
|
322
|
-
const files: Injectable[] = [
|
|
323
|
-
flags.eslint && eslintrcTemplate({flags: options.flags}),
|
|
324
|
-
flags.eslint && eslintignoreTemplate({outDir, flags: options.flags}),
|
|
325
|
-
{type: 'copy', from: 'editorconfig', to: '.editorconfig'},
|
|
326
|
-
{type: 'copy', from: 'sanity.json', to: 'sanity.json'},
|
|
327
|
-
{type: 'copy', from: 'v2-incompatible.js.template', to: 'v2-incompatible.js'},
|
|
328
|
-
pkgConfigTemplate({outDir, flags: options.flags}),
|
|
329
|
-
flags.gitignore && gitignoreTemplate(),
|
|
330
|
-
flags.typescript && tsconfigTemplate({flags: options.flags}),
|
|
331
|
-
flags.typescript && tsconfigTemplateDist({outDir, flags: options.flags}),
|
|
332
|
-
flags.typescript && tsconfigTemplateSettings({outDir, flags: options.flags}),
|
|
333
|
-
flags.prettier && prettierignoreTemplate({outDir}),
|
|
334
|
-
flags.prettier && {type: 'copy', from: 'prettierrc.json', to: '.prettierrc'},
|
|
335
|
-
]
|
|
336
|
-
.map((f) => (f ? (f as Injectable) : undefined))
|
|
337
|
-
.filter((f): f is Injectable => !!f)
|
|
338
|
-
|
|
339
|
-
const result = writeAssets(files, options)
|
|
340
|
-
|
|
341
|
-
return result
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
function asArray(input: string | string[]): string[] {
|
|
345
|
-
return typeof input === 'string' ? [input] : input
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* assets dir might be in higher or lower in the dir hierarchy depending on
|
|
350
|
-
* if we run from `dist` or `src`
|
|
351
|
-
*/
|
|
352
|
-
async function findAssetsDir(): Promise<string> {
|
|
353
|
-
let maxBackpaddle = 3
|
|
354
|
-
let currDir = __dirname
|
|
355
|
-
let assetsDir: string = ''
|
|
356
|
-
while (!assetsDir && maxBackpaddle) {
|
|
357
|
-
currDir = path.join(currDir, '..')
|
|
358
|
-
const assets = path.join(currDir, 'assets')
|
|
359
|
-
if (await fileExists(assets)) {
|
|
360
|
-
assetsDir = assets
|
|
361
|
-
} else {
|
|
362
|
-
maxBackpaddle--
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
if (!assetsDir) {
|
|
367
|
-
throw new Error('Could not find assets directory!')
|
|
368
|
-
}
|
|
369
|
-
return assetsDir
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
async function addCompileDirToGitIgnore(data: PackageData, options: InjectOptions) {
|
|
373
|
-
const gitIgnorePath = path.join(options.basePath, '.gitignore')
|
|
374
|
-
const gitignore = await readFile(gitIgnorePath, 'utf8').catch(errorToUndefined)
|
|
375
|
-
if (!gitignore) {
|
|
376
|
-
return false
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
const output = data.pkg?.main ?? data.pkg?.module
|
|
380
|
-
if (!output) {
|
|
381
|
-
return false
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
const ignorePath = output.replace(/^[./]+/, '')
|
|
385
|
-
const ignore = ignorePath.split('/')[0]
|
|
386
|
-
if (!ignore) {
|
|
387
|
-
return false
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
const lines = gitignore.trim().split('\n')
|
|
391
|
-
if (lines.includes(ignore)) {
|
|
392
|
-
return false
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
lines.push('', '# Compiled plugin', ignore)
|
|
396
|
-
|
|
397
|
-
await writeFile(gitIgnorePath, lines.join('\n') + '\n', {encoding: 'utf8'})
|
|
398
|
-
return true
|
|
399
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
ISC License (ISC)
|
|
3
|
-
Copyright 2019 Johan Otterud
|
|
4
|
-
|
|
5
|
-
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted,
|
|
6
|
-
provided that the above copyright notice and this permission notice appear in all copies.
|
|
7
|
-
|
|
8
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
|
9
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
11
|
-
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
|
|
12
|
-
THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/*
|
|
16
|
-
This code is a modified version of https://github.com/johot/yalc-watch,
|
|
17
|
-
and the ISC License has been added for this file only, in accordance with the package.json license field in that package
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import nodemon from 'nodemon'
|
|
21
|
-
import concurrently from 'concurrently'
|
|
22
|
-
import chalk from 'chalk'
|
|
23
|
-
import fs from 'fs'
|
|
24
|
-
import path from 'path'
|
|
25
|
-
import log from '../util/log'
|
|
26
|
-
import {getPackage} from '../npm/package'
|
|
27
|
-
import outdent from 'outdent'
|
|
28
|
-
import {fileExists, mkdir} from '../util/files'
|
|
29
|
-
import {loadConfig as loadPackageConfig} from '@sanity/pkg-utils'
|
|
30
|
-
import {defaultOutDir} from '../constants'
|
|
31
|
-
|
|
32
|
-
interface YalcWatchConfig {
|
|
33
|
-
command?: string
|
|
34
|
-
extensions?: string
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
interface PackageJson {
|
|
38
|
-
sanityPlugin?: {linkWatch?: YalcWatchConfig}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export async function linkWatch({basePath}: {basePath: string}) {
|
|
42
|
-
const packageJson: PackageJson = JSON.parse(
|
|
43
|
-
fs.readFileSync(path.join(basePath, 'package.json'), 'utf8'),
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
const packageConfig = await loadPackageConfig({cwd: basePath})
|
|
47
|
-
const outDir = packageConfig?.dist ?? defaultOutDir
|
|
48
|
-
|
|
49
|
-
const watch: Required<YalcWatchConfig> = {
|
|
50
|
-
command: 'npm run watch',
|
|
51
|
-
extensions: 'ts,js,png,svg,gif,jpeg,css',
|
|
52
|
-
...packageJson.sanityPlugin?.linkWatch,
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
nodemon({
|
|
56
|
-
watch: [outDir],
|
|
57
|
-
ext: watch.extensions,
|
|
58
|
-
exec: 'yalc push --changed',
|
|
59
|
-
//delay: 1000
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
// ensure the folder exits so it can be watched
|
|
63
|
-
const folder = path.join(basePath, outDir)
|
|
64
|
-
if (!(await fileExists(folder))) {
|
|
65
|
-
await mkdir(folder)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const pkg = await getPackage({basePath, validate: false})
|
|
69
|
-
|
|
70
|
-
concurrently([watch.command])
|
|
71
|
-
|
|
72
|
-
nodemon
|
|
73
|
-
.on('start', function () {
|
|
74
|
-
log.info(
|
|
75
|
-
outdent`
|
|
76
|
-
Watching ${outDir} for changes to files with extensions: ${watch.extensions}
|
|
77
|
-
|
|
78
|
-
To test this package in Sanity Studio or another package, in a separate shell run:
|
|
79
|
-
cd /path/to/sanity/studio-or-package
|
|
80
|
-
|
|
81
|
-
Then, run one of the below commands, based on the package manager used in studio-or-package:
|
|
82
|
-
|
|
83
|
-
## yarn
|
|
84
|
-
${chalk.greenBright(`yalc add --link ${pkg.name} && yarn install`)}
|
|
85
|
-
|
|
86
|
-
## npm
|
|
87
|
-
${chalk.greenBright(`npx yalc add ${pkg.name} && npx yalc link ${pkg.name} && npm install`)}
|
|
88
|
-
`.trimStart(),
|
|
89
|
-
)
|
|
90
|
-
})
|
|
91
|
-
.on('quit', function () {
|
|
92
|
-
process.exit()
|
|
93
|
-
})
|
|
94
|
-
.on('restart', function (files: any) {
|
|
95
|
-
log.info('Found changes in files:', chalk.magentaBright(files))
|
|
96
|
-
log.info('Pushing new yalc package...')
|
|
97
|
-
})
|
|
98
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import {VerifyPackageConfig} from './verify-common'
|
|
2
|
-
|
|
3
|
-
export interface SanityPlugin {
|
|
4
|
-
verifyPackage?: VerifyPackageConfig
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface PackageJson {
|
|
8
|
-
name?: string
|
|
9
|
-
version?: string
|
|
10
|
-
description?: string
|
|
11
|
-
author?: string
|
|
12
|
-
license?: string
|
|
13
|
-
source?: string
|
|
14
|
-
exports?: {
|
|
15
|
-
[index: string]: Record<string, string> | string | undefined
|
|
16
|
-
}
|
|
17
|
-
main?: string
|
|
18
|
-
module?: string
|
|
19
|
-
types?: string
|
|
20
|
-
browser?: string
|
|
21
|
-
files?: string[]
|
|
22
|
-
scripts?: Record<string, string>
|
|
23
|
-
dependencies?: Record<string, string>
|
|
24
|
-
peerDependencies?: Record<string, string>
|
|
25
|
-
devDependencies?: Record<string, string>
|
|
26
|
-
sanityPlugin?: SanityPlugin
|
|
27
|
-
engines?: {
|
|
28
|
-
node?: string
|
|
29
|
-
}
|
|
30
|
-
keywords?: string[]
|
|
31
|
-
repository?: {url?: string}
|
|
32
|
-
|
|
33
|
-
[index: string]: unknown
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface SanityV2Json {
|
|
37
|
-
parts?: [
|
|
38
|
-
{
|
|
39
|
-
implements?: string
|
|
40
|
-
path?: 'string'
|
|
41
|
-
},
|
|
42
|
-
]
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface SanityStudioJson {
|
|
46
|
-
root?: boolean
|
|
47
|
-
project?: {
|
|
48
|
-
name?: string
|
|
49
|
-
}
|
|
50
|
-
api?: {
|
|
51
|
-
projectId?: string
|
|
52
|
-
dataset?: string
|
|
53
|
-
}
|
|
54
|
-
plugins?: string[]
|
|
55
|
-
parts?: Record<string, unknown>[]
|
|
56
|
-
}
|