@sanity/cli 3.65.2-corel.472 → 3.66.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/lib/_chunks-cjs/cli.js +445 -1082
- package/lib/_chunks-cjs/cli.js.map +1 -1
- package/lib/index.d.mts +0 -1
- package/lib/index.d.ts +0 -1
- package/package.json +7 -7
- package/src/CommandRunner.ts +1 -2
- package/src/actions/init-project/bootstrapRemoteTemplate.ts +10 -7
- package/src/actions/init-project/initProject.ts +1 -17
- package/src/commands/index.ts +0 -2
- package/src/commands/init/initCommand.ts +0 -9
- package/src/types.ts +0 -1
- package/src/util/remoteTemplate.ts +16 -0
- package/src/actions/init-plugin/initPlugin.ts +0 -119
- package/src/actions/init-plugin/pluginTemplates.ts +0 -38
- package/src/actions/init-project/reconfigureV2Project.ts +0 -446
- package/src/commands/upgrade/upgradeCommand.ts +0 -38
- package/src/commands/upgrade/upgradeDependencies.ts +0 -289
package/lib/index.d.mts
CHANGED
package/lib/index.d.ts
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sanity/cli",
|
3
|
-
"version": "3.
|
3
|
+
"version": "3.66.0",
|
4
4
|
"description": "Sanity CLI tool for managing Sanity installations, managing plugins, schemas and datasets",
|
5
5
|
"keywords": [
|
6
6
|
"sanity",
|
@@ -58,9 +58,9 @@
|
|
58
58
|
"dependencies": {
|
59
59
|
"@babel/traverse": "^7.23.5",
|
60
60
|
"@sanity/client": "^6.24.1",
|
61
|
-
"@sanity/codegen": "3.
|
61
|
+
"@sanity/codegen": "3.66.0",
|
62
62
|
"@sanity/telemetry": "^0.7.7",
|
63
|
-
"@sanity/util": "3.
|
63
|
+
"@sanity/util": "3.66.0",
|
64
64
|
"chalk": "^4.1.2",
|
65
65
|
"debug": "^4.3.4",
|
66
66
|
"decompress": "^4.2.0",
|
@@ -76,13 +76,13 @@
|
|
76
76
|
"yaml": "^2.6.1"
|
77
77
|
},
|
78
78
|
"devDependencies": {
|
79
|
-
"@repo/package.config": "3.
|
80
|
-
"@repo/test-config": "3.
|
79
|
+
"@repo/package.config": "3.66.0",
|
80
|
+
"@repo/test-config": "3.66.0",
|
81
81
|
"@rexxars/gitconfiglocal": "^3.0.1",
|
82
82
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
83
83
|
"@sanity/eslint-config-studio": "^4.0.0",
|
84
84
|
"@sanity/generate-help-url": "^3.0.0",
|
85
|
-
"@sanity/types": "3.
|
85
|
+
"@sanity/types": "3.66.0",
|
86
86
|
"@types/babel__traverse": "^7.20.5",
|
87
87
|
"@types/configstore": "^5.0.1",
|
88
88
|
"@types/cpx": "^1.5.2",
|
@@ -136,5 +136,5 @@
|
|
136
136
|
"engines": {
|
137
137
|
"node": ">=18"
|
138
138
|
},
|
139
|
-
"gitHead": "
|
139
|
+
"gitHead": "aeff5521ef6c5e440baf8bfd31349d0a823c74cd"
|
140
140
|
}
|
package/src/CommandRunner.ts
CHANGED
@@ -4,7 +4,7 @@ import {cloneDeep, sortBy} from 'lodash'
|
|
4
4
|
import {baseCommands} from './commands'
|
5
5
|
import {debug} from './debug'
|
6
6
|
import cliOutputter from './outputters/cliOutputter'
|
7
|
-
import {cliPackageManager
|
7
|
+
import {cliPackageManager} from './packageManager'
|
8
8
|
import {prompt as cliPrompter} from './prompters/cliPrompter'
|
9
9
|
import {
|
10
10
|
type CliCommandArguments,
|
@@ -96,7 +96,6 @@ export class CommandRunner {
|
|
96
96
|
cliPackageManager,
|
97
97
|
...commandOptions,
|
98
98
|
commandRunner: this,
|
99
|
-
yarn: getYarnStub({output, workDir: commandOptions.workDir}),
|
100
99
|
...getVersionedContextParams(cliConfig),
|
101
100
|
}
|
102
101
|
|
@@ -5,6 +5,7 @@ import {debug} from '../../debug'
|
|
5
5
|
import {type CliCommandContext} from '../../types'
|
6
6
|
import {
|
7
7
|
applyEnvVariables,
|
8
|
+
checkNeedsReadToken,
|
8
9
|
downloadAndExtractRepo,
|
9
10
|
generateSanityApiReadToken,
|
10
11
|
getMonoRepo,
|
@@ -23,7 +24,6 @@ export interface BootstrapRemoteOptions {
|
|
23
24
|
bearerToken?: string
|
24
25
|
packageName: string
|
25
26
|
variables: GenerateConfigOptions['variables']
|
26
|
-
isCI?: boolean
|
27
27
|
}
|
28
28
|
|
29
29
|
const INITIAL_COMMIT_MESSAGE = 'Initial commit from Sanity CLI'
|
@@ -32,7 +32,7 @@ export async function bootstrapRemoteTemplate(
|
|
32
32
|
opts: BootstrapRemoteOptions,
|
33
33
|
context: CliCommandContext,
|
34
34
|
): Promise<void> {
|
35
|
-
const {outputPath, repoInfo, bearerToken, variables, packageName
|
35
|
+
const {outputPath, repoInfo, bearerToken, variables, packageName} = opts
|
36
36
|
const {output, apiClient} = context
|
37
37
|
const name = [repoInfo.username, repoInfo.name, repoInfo.filePath].filter(Boolean).join('/')
|
38
38
|
const spinner = output.spinner(`Bootstrapping files from template "${name}"`).start()
|
@@ -47,12 +47,15 @@ export async function bootstrapRemoteTemplate(
|
|
47
47
|
debug('Downloading and extracting repo to %s', outputPath)
|
48
48
|
await downloadAndExtractRepo(outputPath, repoInfo, bearerToken)
|
49
49
|
|
50
|
+
debug('Checking if template needs read token')
|
51
|
+
const needsReadToken = await Promise.all(
|
52
|
+
(packages ?? ['']).map((pkg) => checkNeedsReadToken(join(outputPath, pkg))),
|
53
|
+
).then((results) => results.some(Boolean))
|
54
|
+
|
50
55
|
debug('Applying environment variables')
|
51
|
-
const readToken =
|
52
|
-
|
53
|
-
|
54
|
-
apiClient,
|
55
|
-
)
|
56
|
+
const readToken = needsReadToken
|
57
|
+
? await generateSanityApiReadToken('API Read Token', variables.projectId, apiClient)
|
58
|
+
: undefined
|
56
59
|
const isNext = await isNextJsTemplate(outputPath)
|
57
60
|
const envName = isNext ? '.env.local' : '.env'
|
58
61
|
|
@@ -62,7 +62,6 @@ import {
|
|
62
62
|
promptForStudioPath,
|
63
63
|
} from './prompts/nextjs'
|
64
64
|
import {readPackageJson} from './readPackageJson'
|
65
|
-
import {reconfigureV2Project} from './reconfigureV2Project'
|
66
65
|
import templates from './templates'
|
67
66
|
import {
|
68
67
|
sanityCliTemplate,
|
@@ -115,16 +114,7 @@ export default async function initSanity(
|
|
115
114
|
detectedFramework: Awaited<ReturnType<typeof detectFrameworkRecord>>
|
116
115
|
},
|
117
116
|
): Promise<void> {
|
118
|
-
const {
|
119
|
-
output,
|
120
|
-
prompt,
|
121
|
-
workDir,
|
122
|
-
apiClient,
|
123
|
-
chalk,
|
124
|
-
sanityMajorVersion,
|
125
|
-
telemetry,
|
126
|
-
detectedFramework,
|
127
|
-
} = context
|
117
|
+
const {output, prompt, workDir, apiClient, chalk, telemetry, detectedFramework} = context
|
128
118
|
|
129
119
|
const trace = telemetry.trace(CLIInitStepCompleted)
|
130
120
|
|
@@ -165,11 +155,6 @@ export default async function initSanity(
|
|
165
155
|
},
|
166
156
|
})
|
167
157
|
|
168
|
-
if (sanityMajorVersion === 2) {
|
169
|
-
await reconfigureV2Project(args, context)
|
170
|
-
return
|
171
|
-
}
|
172
|
-
|
173
158
|
if (detectedFramework && detectedFramework.slug !== 'sanity' && remoteTemplateInfo) {
|
174
159
|
throw new Error(
|
175
160
|
`A remote template cannot be used with a detected framework. Detected: ${detectedFramework.name}`,
|
@@ -1127,7 +1112,6 @@ export default async function initSanity(
|
|
1127
1112
|
repoInfo: remoteTemplateInfo,
|
1128
1113
|
bearerToken: cliFlags['template-token'],
|
1129
1114
|
variables: bootstrapVariables,
|
1130
|
-
isCI,
|
1131
1115
|
},
|
1132
1116
|
context,
|
1133
1117
|
)
|
package/src/commands/index.ts
CHANGED
@@ -17,7 +17,6 @@ import telemetryGroup from './telemetry/telemetryGroup'
|
|
17
17
|
import telemetryStatusCommand from './telemetry/telemetryStatusCommand'
|
18
18
|
import generateTypegenCommand from './typegen/generateTypesCommand'
|
19
19
|
import typegenGroup from './typegen/typegenGroup'
|
20
|
-
import upgradeCommand from './upgrade/upgradeCommand'
|
21
20
|
import versionsCommand from './versions/versionsCommand'
|
22
21
|
|
23
22
|
export const baseCommands: (CliCommandDefinition | CliCommandGroupDefinition)[] = [
|
@@ -25,7 +24,6 @@ export const baseCommands: (CliCommandDefinition | CliCommandGroupDefinition)[]
|
|
25
24
|
loginCommand,
|
26
25
|
logoutCommand,
|
27
26
|
installCommand,
|
28
|
-
upgradeCommand,
|
29
27
|
versionsCommand,
|
30
28
|
docsCommand,
|
31
29
|
manageCommand,
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import {type Framework, frameworks} from '@vercel/frameworks'
|
2
2
|
import {detectFrameworkRecord, LocalFileSystemDetector} from '@vercel/fs-detectors'
|
3
3
|
|
4
|
-
import initPlugin from '../../actions/init-plugin/initPlugin'
|
5
4
|
import initProject from '../../actions/init-project/initProject'
|
6
5
|
import {
|
7
6
|
allowedPackageManagersString,
|
@@ -105,14 +104,6 @@ export const initCommand: CliCommandDefinition<InitFlags> = {
|
|
105
104
|
const {output, chalk} = context
|
106
105
|
const [type] = args.argsWithoutOptions
|
107
106
|
|
108
|
-
// `sanity init plugin`
|
109
|
-
if (type === 'plugin') {
|
110
|
-
return context.sanityMajorVersion === 2
|
111
|
-
? // don't bother with telemetry here, as it's not supported in v3
|
112
|
-
initPlugin(args, context)
|
113
|
-
: Promise.reject(new Error(`'sanity init plugin' is not available in modern studios`))
|
114
|
-
}
|
115
|
-
|
116
107
|
// `sanity init whatever`
|
117
108
|
if (type) {
|
118
109
|
return Promise.reject(new Error(`Unknown init type "${type}"`))
|
package/src/types.ts
CHANGED
@@ -420,6 +420,22 @@ export async function isNextJsTemplate(root: string): Promise<boolean> {
|
|
420
420
|
}
|
421
421
|
}
|
422
422
|
|
423
|
+
export async function checkNeedsReadToken(root: string): Promise<boolean> {
|
424
|
+
try {
|
425
|
+
const templatePath = await Promise.any(
|
426
|
+
ENV_TEMPLATE_FILES.map(async (file) => {
|
427
|
+
await access(join(root, file))
|
428
|
+
return file
|
429
|
+
}),
|
430
|
+
)
|
431
|
+
|
432
|
+
const templateContent = await readFile(join(root, templatePath), 'utf8')
|
433
|
+
return templateContent.includes(ENV_VAR.READ_TOKEN)
|
434
|
+
} catch {
|
435
|
+
return false
|
436
|
+
}
|
437
|
+
}
|
438
|
+
|
423
439
|
export async function applyEnvVariables(
|
424
440
|
root: string,
|
425
441
|
envData: EnvData,
|
@@ -1,119 +0,0 @@
|
|
1
|
-
import fs from 'node:fs/promises'
|
2
|
-
import path from 'node:path'
|
3
|
-
|
4
|
-
import {type InitFlags} from '../../commands/init/initCommand'
|
5
|
-
import {debug} from '../../debug'
|
6
|
-
import {type CliCommandArguments, type CliCommandContext, type SanityJson} from '../../types'
|
7
|
-
import {bootstrapFromTemplate} from './bootstrapFromTemplate'
|
8
|
-
import {pluginTemplates} from './pluginTemplates'
|
9
|
-
|
10
|
-
export default async function initPlugin(
|
11
|
-
args: CliCommandArguments<InitFlags>,
|
12
|
-
context: CliCommandContext,
|
13
|
-
): Promise<void> {
|
14
|
-
const {output, prompt} = context
|
15
|
-
const [, specifiedTemplateUrl] = args.argsWithoutOptions
|
16
|
-
|
17
|
-
output.print('This utility will walk you through creating a new Sanity plugin.')
|
18
|
-
output.print('Press ^C at any time to quit.\n')
|
19
|
-
|
20
|
-
const hasTemplateUrl = /^https?:\/\//.test(specifiedTemplateUrl || '')
|
21
|
-
|
22
|
-
if (hasTemplateUrl) {
|
23
|
-
debug('User provided template URL: %s', specifiedTemplateUrl)
|
24
|
-
return bootstrapFromUrl(context, specifiedTemplateUrl)
|
25
|
-
}
|
26
|
-
|
27
|
-
let specifiedTemplate = null
|
28
|
-
if (specifiedTemplateUrl) {
|
29
|
-
specifiedTemplate = pluginTemplates.find((tpl) => tpl.value === specifiedTemplateUrl)
|
30
|
-
}
|
31
|
-
|
32
|
-
if (specifiedTemplate) {
|
33
|
-
debug(
|
34
|
-
'User wanted template "%s", match found at %s',
|
35
|
-
specifiedTemplateUrl,
|
36
|
-
specifiedTemplate.url,
|
37
|
-
)
|
38
|
-
|
39
|
-
return bootstrapFromUrl(context, specifiedTemplate.url)
|
40
|
-
} else if (specifiedTemplateUrl) {
|
41
|
-
throw new Error(`Cannot find template with name "${specifiedTemplateUrl}"`)
|
42
|
-
}
|
43
|
-
|
44
|
-
const templateChoices = pluginTemplates.map(({value, name}) => ({value, name}))
|
45
|
-
const selected = await prompt.single({
|
46
|
-
message: 'Select template to use',
|
47
|
-
type: 'list',
|
48
|
-
choices: templateChoices,
|
49
|
-
})
|
50
|
-
|
51
|
-
specifiedTemplate = pluginTemplates.find((tpl) => tpl.value === selected)
|
52
|
-
if (!specifiedTemplate) {
|
53
|
-
throw new Error('No template selected')
|
54
|
-
}
|
55
|
-
|
56
|
-
debug('User selected template URL: %s', specifiedTemplate.url)
|
57
|
-
return bootstrapFromUrl(context, specifiedTemplate.url)
|
58
|
-
}
|
59
|
-
|
60
|
-
async function bootstrapFromUrl(context: CliCommandContext, url: string): Promise<void> {
|
61
|
-
const {output, prompt, yarn, workDir} = context
|
62
|
-
|
63
|
-
debug('Bootstrapping from URL: %s', url)
|
64
|
-
const {name, outputPath, inPluginsPath, dependencies} = await bootstrapFromTemplate(context, url)
|
65
|
-
|
66
|
-
if (inPluginsPath) {
|
67
|
-
const addIt = await prompt.single({
|
68
|
-
type: 'confirm',
|
69
|
-
message: 'Enable plugin in current Sanity installation?',
|
70
|
-
default: true,
|
71
|
-
})
|
72
|
-
|
73
|
-
if (addIt) {
|
74
|
-
await addPluginToManifest(workDir, name.replace(/^sanity-plugin-/, ''))
|
75
|
-
}
|
76
|
-
}
|
77
|
-
|
78
|
-
if (dependencies) {
|
79
|
-
const dependencyString = JSON.stringify(dependencies, null, 2)
|
80
|
-
.split('\n')
|
81
|
-
.slice(1, -1)
|
82
|
-
.join('\n')
|
83
|
-
.replace(/"/g, '')
|
84
|
-
|
85
|
-
output.print('\nThe following dependencies are required for this template:')
|
86
|
-
output.print(`${dependencyString}\n`)
|
87
|
-
}
|
88
|
-
|
89
|
-
if (dependencies && inPluginsPath) {
|
90
|
-
const addDeps = await prompt.single({
|
91
|
-
type: 'confirm',
|
92
|
-
message: 'Install dependencies in current project?',
|
93
|
-
default: true,
|
94
|
-
})
|
95
|
-
|
96
|
-
if (addDeps) {
|
97
|
-
const deps = Object.keys(dependencies).map((dep) => `${dep}@${dependencies[dep]}`)
|
98
|
-
await yarn(['add'].concat(deps), {...output, rootDir: workDir})
|
99
|
-
|
100
|
-
output.print('Dependencies installed.')
|
101
|
-
output.print('Remember to remove them from `package.json` if you no longer need them!')
|
102
|
-
}
|
103
|
-
}
|
104
|
-
|
105
|
-
output.print(`\nSuccess! Plugin initialized at ${outputPath}`)
|
106
|
-
}
|
107
|
-
|
108
|
-
async function addPluginToManifest(sanityDir: string, pluginName: string): Promise<SanityJson> {
|
109
|
-
const manifestPath = path.join(sanityDir, 'sanity.json')
|
110
|
-
const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8'))
|
111
|
-
|
112
|
-
manifest.plugins = manifest.plugins || []
|
113
|
-
if (manifest.plugins.indexOf(pluginName) === -1) {
|
114
|
-
manifest.plugins.push(pluginName)
|
115
|
-
}
|
116
|
-
|
117
|
-
await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 2))
|
118
|
-
return manifest
|
119
|
-
}
|
@@ -1,38 +0,0 @@
|
|
1
|
-
export interface PluginTemplate {
|
2
|
-
value: string
|
3
|
-
name: string
|
4
|
-
url: string
|
5
|
-
}
|
6
|
-
|
7
|
-
export const pluginTemplates: PluginTemplate[] = [
|
8
|
-
{
|
9
|
-
value: 'logo',
|
10
|
-
name: 'Studio logo',
|
11
|
-
url: 'https://github.com/sanity-io/plugin-template-logo/archive/master.zip',
|
12
|
-
},
|
13
|
-
{
|
14
|
-
value: 'tool',
|
15
|
-
name: 'Basic, empty tool',
|
16
|
-
url: 'https://github.com/sanity-io/plugin-template-tool/archive/master.zip',
|
17
|
-
},
|
18
|
-
{
|
19
|
-
value: 'toolWithRouting',
|
20
|
-
name: 'Tool with basic routing',
|
21
|
-
url: 'https://github.com/sanity-io/plugin-template-tool-with-routing/archive/master.zip',
|
22
|
-
},
|
23
|
-
{
|
24
|
-
value: 'chessInput',
|
25
|
-
name: 'Chess board input component w/ block preview',
|
26
|
-
url: 'https://github.com/sanity-io/plugin-template-chess-input/archive/master.zip',
|
27
|
-
},
|
28
|
-
{
|
29
|
-
value: 'dashboardWidget',
|
30
|
-
name: 'A Dashboard widget with cats',
|
31
|
-
url: 'https://github.com/sanity-io/plugin-template-dashboard-widget-cats/archive/master.zip',
|
32
|
-
},
|
33
|
-
{
|
34
|
-
value: 'assetSource',
|
35
|
-
name: 'Custom asset source plugin',
|
36
|
-
url: 'https://github.com/sanity-io/plugin-template-asset-source/archive/master.zip',
|
37
|
-
},
|
38
|
-
]
|