@sanity/cli 3.57.1 → 3.57.2-manifests.67
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/bin/xdg-open +1066 -0
- package/lib/_chunks-cjs/cli.js +417 -395
- package/lib/_chunks-cjs/cli.js.map +1 -1
- package/package.json +7 -7
- package/src/actions/init-project/bootstrapTemplate.ts +1 -0
- package/src/actions/init-project/createCliConfig.ts +33 -4
- package/src/actions/init-project/createStudioConfig.ts +7 -2
- package/src/actions/init-project/initProject.ts +43 -3
- package/src/commands/init/initCommand.ts +2 -0
- package/src/util/noSuchCommandText.ts +1 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sanity/cli",
|
3
|
-
"version": "3.57.
|
3
|
+
"version": "3.57.2-manifests.67+0246fa6e86",
|
4
4
|
"description": "Sanity CLI tool for managing Sanity installations, managing plugins, schemas and datasets",
|
5
5
|
"keywords": [
|
6
6
|
"sanity",
|
@@ -57,10 +57,10 @@
|
|
57
57
|
},
|
58
58
|
"dependencies": {
|
59
59
|
"@babel/traverse": "^7.23.5",
|
60
|
-
"@sanity/client": "^6.21.
|
61
|
-
"@sanity/codegen": "3.57.
|
60
|
+
"@sanity/client": "^6.21.3",
|
61
|
+
"@sanity/codegen": "3.57.2-manifests.67+0246fa6e86",
|
62
62
|
"@sanity/telemetry": "^0.7.7",
|
63
|
-
"@sanity/util": "3.57.
|
63
|
+
"@sanity/util": "3.57.2-manifests.67+0246fa6e86",
|
64
64
|
"chalk": "^4.1.2",
|
65
65
|
"debug": "^4.3.4",
|
66
66
|
"decompress": "^4.2.0",
|
@@ -77,12 +77,12 @@
|
|
77
77
|
},
|
78
78
|
"devDependencies": {
|
79
79
|
"@jest/globals": "^29.7.0",
|
80
|
-
"@repo/package.config": "3.57.
|
80
|
+
"@repo/package.config": "3.57.4",
|
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.57.
|
85
|
+
"@sanity/types": "3.57.2-manifests.67+0246fa6e86",
|
86
86
|
"@types/babel__traverse": "^7.20.5",
|
87
87
|
"@types/configstore": "^5.0.1",
|
88
88
|
"@types/cpx": "^1.5.2",
|
@@ -135,5 +135,5 @@
|
|
135
135
|
"engines": {
|
136
136
|
"node": ">=18"
|
137
137
|
},
|
138
|
-
"gitHead": "
|
138
|
+
"gitHead": "0246fa6e86d13669d16c487d1667baf36981ed98"
|
139
139
|
}
|
@@ -9,19 +9,26 @@ export default defineCliConfig({
|
|
9
9
|
api: {
|
10
10
|
projectId: '%projectId%',
|
11
11
|
dataset: '%dataset%'
|
12
|
-
}
|
12
|
+
},
|
13
|
+
/**
|
14
|
+
* Enable auto-updates for studios.
|
15
|
+
* Learn more at https://www.sanity.io/docs/cli#auto-updates
|
16
|
+
*/
|
17
|
+
autoUpdates: __BOOL__autoUpdates__,
|
13
18
|
})
|
14
19
|
`
|
15
20
|
|
16
21
|
export interface GenerateCliConfigOptions {
|
17
22
|
projectId: string
|
18
23
|
dataset: string
|
24
|
+
autoUpdates: boolean
|
19
25
|
}
|
20
26
|
|
21
27
|
export function createCliConfig(options: GenerateCliConfigOptions): string {
|
22
28
|
const variables = options
|
23
29
|
const template = defaultTemplate.trimStart()
|
24
30
|
const ast = parse(template, {parser})
|
31
|
+
|
25
32
|
traverse(ast, {
|
26
33
|
StringLiteral: {
|
27
34
|
enter({node}) {
|
@@ -29,13 +36,35 @@ export function createCliConfig(options: GenerateCliConfigOptions): string {
|
|
29
36
|
if (!value.startsWith('%') || !value.endsWith('%')) {
|
30
37
|
return
|
31
38
|
}
|
32
|
-
|
33
39
|
const variableName = value.slice(1, -1) as keyof GenerateCliConfigOptions
|
34
40
|
if (!(variableName in variables)) {
|
35
41
|
throw new Error(`Template variable '${value}' not defined`)
|
36
42
|
}
|
37
|
-
|
38
|
-
|
43
|
+
const newValue = variables[variableName]
|
44
|
+
/*
|
45
|
+
* although there are valid non-strings in our config,
|
46
|
+
* they're not in StringLiteral nodes, so assume undefined
|
47
|
+
*/
|
48
|
+
node.value = typeof newValue === 'string' ? newValue : ''
|
49
|
+
},
|
50
|
+
},
|
51
|
+
Identifier: {
|
52
|
+
enter(path) {
|
53
|
+
if (!path.node.name.startsWith('__BOOL__')) {
|
54
|
+
return
|
55
|
+
}
|
56
|
+
const variableName = path.node.name.replace(
|
57
|
+
/^__BOOL__(.+?)__$/,
|
58
|
+
'$1',
|
59
|
+
) as keyof GenerateCliConfigOptions
|
60
|
+
if (!(variableName in variables)) {
|
61
|
+
throw new Error(`Template variable '${variableName}' not defined`)
|
62
|
+
}
|
63
|
+
const value = variables[variableName]
|
64
|
+
if (typeof value !== 'boolean') {
|
65
|
+
throw new Error(`Expected boolean value for '${variableName}'`)
|
66
|
+
}
|
67
|
+
path.replaceWith({type: 'BooleanLiteral', value})
|
39
68
|
},
|
40
69
|
},
|
41
70
|
})
|
@@ -34,6 +34,7 @@ export interface GenerateConfigOptions {
|
|
34
34
|
variables: {
|
35
35
|
projectId: string
|
36
36
|
dataset: string
|
37
|
+
autoUpdates: boolean
|
37
38
|
projectName?: string
|
38
39
|
sourceName?: string
|
39
40
|
sourceTitle?: string
|
@@ -60,8 +61,12 @@ export function createStudioConfig(options: GenerateConfigOptions): string {
|
|
60
61
|
if (!(variableName in variables)) {
|
61
62
|
throw new Error(`Template variable '${value}' not defined`)
|
62
63
|
}
|
63
|
-
|
64
|
-
|
64
|
+
const newValue = variables[variableName]
|
65
|
+
/*
|
66
|
+
* although there are valid non-strings in our config,
|
67
|
+
* they're not in this template, so assume undefined
|
68
|
+
*/
|
69
|
+
node.value = typeof newValue === 'string' ? newValue : ''
|
65
70
|
},
|
66
71
|
},
|
67
72
|
})
|
@@ -240,7 +240,11 @@ export default async function initSanity(
|
|
240
240
|
throw new Error('`--reconfigure` is deprecated - manual configuration is now required')
|
241
241
|
}
|
242
242
|
|
243
|
-
|
243
|
+
let envFilenameDefault = '.env'
|
244
|
+
if (detectedFramework && detectedFramework.slug === 'nextjs') {
|
245
|
+
envFilenameDefault = '.env.local'
|
246
|
+
}
|
247
|
+
const envFilename = typeof env === 'string' ? env : envFilenameDefault
|
244
248
|
if (!envFilename.startsWith('.env')) {
|
245
249
|
throw new Error(`Env filename must start with .env`)
|
246
250
|
}
|
@@ -433,10 +437,39 @@ export default async function initSanity(
|
|
433
437
|
const appendEnv = unattended ? true : await promptForAppendEnv(prompt, envFilename)
|
434
438
|
|
435
439
|
if (appendEnv) {
|
436
|
-
await createOrAppendEnvVars(envFilename, detectedFramework, {
|
437
|
-
|
440
|
+
await createOrAppendEnvVars(envFilename, detectedFramework, {log: true})
|
441
|
+
}
|
442
|
+
|
443
|
+
if (embeddedStudio) {
|
444
|
+
const nextjsLocalDevOrigin = 'http://localhost:3000'
|
445
|
+
const existingCorsOrigins = await apiClient({api: {projectId}}).request({
|
446
|
+
method: 'GET',
|
447
|
+
uri: '/cors',
|
438
448
|
})
|
449
|
+
const hasExistingCorsOrigin = existingCorsOrigins.some(
|
450
|
+
(item: {origin: string}) => item.origin === nextjsLocalDevOrigin,
|
451
|
+
)
|
452
|
+
if (!hasExistingCorsOrigin) {
|
453
|
+
await apiClient({api: {projectId}})
|
454
|
+
.request({
|
455
|
+
method: 'POST',
|
456
|
+
url: '/cors',
|
457
|
+
body: {origin: nextjsLocalDevOrigin, allowCredentials: true},
|
458
|
+
maxRedirects: 0,
|
459
|
+
})
|
460
|
+
.then((res) => {
|
461
|
+
print(
|
462
|
+
res.id
|
463
|
+
? `Added ${nextjsLocalDevOrigin} to CORS origins`
|
464
|
+
: `Failed to add ${nextjsLocalDevOrigin} to CORS origins`,
|
465
|
+
)
|
466
|
+
})
|
467
|
+
.catch((error) => {
|
468
|
+
print(`Failed to add ${nextjsLocalDevOrigin} to CORS origins`, error)
|
469
|
+
})
|
470
|
+
}
|
439
471
|
}
|
472
|
+
|
440
473
|
const {chosen} = await getPackageManagerChoice(workDir, {interactive: false})
|
441
474
|
trace.log({step: 'selectPackageManager', selectedOption: chosen})
|
442
475
|
const packages = ['@sanity/vision@3', 'sanity@3', '@sanity/image-url@1', 'styled-components@6']
|
@@ -534,6 +567,12 @@ export default async function initSanity(
|
|
534
567
|
trace.log({step: 'useTypeScript', selectedOption: useTypeScript ? 'yes' : 'no'})
|
535
568
|
}
|
536
569
|
|
570
|
+
// we enable auto-updates by default, but allow users to specify otherwise
|
571
|
+
let autoUpdates = true
|
572
|
+
if (typeof cliFlags['auto-updates'] === 'boolean') {
|
573
|
+
autoUpdates = cliFlags['auto-updates']
|
574
|
+
}
|
575
|
+
|
537
576
|
// Build a full set of resolved options
|
538
577
|
const templateOptions: BootstrapOptions = {
|
539
578
|
outputPath,
|
@@ -542,6 +581,7 @@ export default async function initSanity(
|
|
542
581
|
schemaUrl,
|
543
582
|
useTypeScript,
|
544
583
|
variables: {
|
584
|
+
autoUpdates,
|
545
585
|
dataset: datasetName,
|
546
586
|
projectId,
|
547
587
|
projectName: displayName || answers.projectName,
|
@@ -27,6 +27,7 @@ Options
|
|
27
27
|
--coupon <name> Optionally select a coupon for a new project (cannot be used with --project-plan)
|
28
28
|
--no-typescript Do not use TypeScript for template files
|
29
29
|
--package-manager <name> Specify which package manager to use [allowed: ${allowedPackageManagersString}]
|
30
|
+
--no-auto-updates Disable auto updates of studio versions
|
30
31
|
|
31
32
|
Examples
|
32
33
|
# Initialize a new project, prompt for required information along the way
|
@@ -60,6 +61,7 @@ export interface InitFlags {
|
|
60
61
|
|
61
62
|
'visibility'?: string
|
62
63
|
'typescript'?: boolean
|
64
|
+
'auto-updates'?: boolean
|
63
65
|
/**
|
64
66
|
* Used for initializing a project from a server schema that is saved in the Journey API
|
65
67
|
* Overrides `project` option.
|