@sanity/cli 3.72.2-canary.32 → 3.72.2-corel.24
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 +73 -127
- package/lib/_chunks-cjs/cli.js.map +1 -1
- package/lib/index.d.mts +0 -9
- package/lib/index.d.ts +0 -9
- package/package.json +9 -9
- package/src/actions/init-project/bootstrapLocalTemplate.ts +20 -32
- package/src/actions/init-project/createCliConfig.ts +47 -5
- package/src/actions/init-project/createPackageManifest.ts +1 -1
- package/src/actions/init-project/createStudioConfig.ts +27 -4
- package/src/actions/init-project/initProject.ts +2 -21
- package/src/actions/init-project/templates/index.ts +0 -2
- package/src/types.ts +0 -10
- package/src/actions/init-project/createCoreAppCliConfig.ts +0 -23
- package/src/actions/init-project/determineCoreAppTemplate.ts +0 -13
- package/src/actions/init-project/processTemplate.ts +0 -55
- package/src/actions/init-project/templates/coreApp.ts +0 -31
- package/templates/core-app/src/App.tsx +0 -26
package/lib/index.d.mts
CHANGED
@@ -114,14 +114,6 @@ export declare interface CliConfig {
|
|
114
114
|
vite?: UserViteConfig
|
115
115
|
autoUpdates?: boolean
|
116
116
|
studioHost?: string
|
117
|
-
/**
|
118
|
-
* Parameter used to configure other kinds of applications.
|
119
|
-
* Signals to `sanity` commands that this is not a studio.
|
120
|
-
* @internal
|
121
|
-
*/
|
122
|
-
__experimental_coreAppConfiguration?: {
|
123
|
-
appLocation?: string
|
124
|
-
}
|
125
117
|
}
|
126
118
|
|
127
119
|
declare type CliConfigResult =
|
@@ -365,7 +357,6 @@ export declare function loadEnv(
|
|
365
357
|
export declare interface PackageJson {
|
366
358
|
name: string
|
367
359
|
version: string
|
368
|
-
scripts?: Record<string, string>
|
369
360
|
description?: string
|
370
361
|
author?: string
|
371
362
|
license?: string
|
package/lib/index.d.ts
CHANGED
@@ -114,14 +114,6 @@ export declare interface CliConfig {
|
|
114
114
|
vite?: UserViteConfig
|
115
115
|
autoUpdates?: boolean
|
116
116
|
studioHost?: string
|
117
|
-
/**
|
118
|
-
* Parameter used to configure other kinds of applications.
|
119
|
-
* Signals to `sanity` commands that this is not a studio.
|
120
|
-
* @internal
|
121
|
-
*/
|
122
|
-
__experimental_coreAppConfiguration?: {
|
123
|
-
appLocation?: string
|
124
|
-
}
|
125
117
|
}
|
126
118
|
|
127
119
|
declare type CliConfigResult =
|
@@ -365,7 +357,6 @@ export declare function loadEnv(
|
|
365
357
|
export declare interface PackageJson {
|
366
358
|
name: string
|
367
359
|
version: string
|
368
|
-
scripts?: Record<string, string>
|
369
360
|
description?: string
|
370
361
|
author?: string
|
371
362
|
license?: string
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sanity/cli",
|
3
|
-
"version": "3.72.2-
|
3
|
+
"version": "3.72.2-corel.24+9afe9690e4",
|
4
4
|
"description": "Sanity CLI tool for managing Sanity installations, managing plugins, schemas and datasets",
|
5
5
|
"keywords": [
|
6
6
|
"sanity",
|
@@ -58,30 +58,30 @@
|
|
58
58
|
"dependencies": {
|
59
59
|
"@babel/traverse": "^7.23.5",
|
60
60
|
"@sanity/client": "^6.27.2",
|
61
|
-
"@sanity/codegen": "3.72.2-
|
61
|
+
"@sanity/codegen": "3.72.2-corel.24+9afe9690e4",
|
62
62
|
"@sanity/telemetry": "^0.7.7",
|
63
63
|
"@sanity/template-validator": "^2.4.0",
|
64
|
-
"@sanity/util": "3.72.2-
|
64
|
+
"@sanity/util": "3.72.2-corel.24+9afe9690e4",
|
65
65
|
"chalk": "^4.1.2",
|
66
66
|
"debug": "^4.3.4",
|
67
67
|
"decompress": "^4.2.0",
|
68
68
|
"esbuild": "0.21.5",
|
69
69
|
"esbuild-register": "^3.5.0",
|
70
70
|
"get-it": "^8.6.7",
|
71
|
-
"groq-js": "^1.
|
71
|
+
"groq-js": "^1.14.2",
|
72
72
|
"pkg-dir": "^5.0.0",
|
73
73
|
"prettier": "^3.3.0",
|
74
74
|
"semver": "^7.3.5",
|
75
75
|
"validate-npm-package-name": "^3.0.0"
|
76
76
|
},
|
77
77
|
"devDependencies": {
|
78
|
-
"@repo/package.config": "3.
|
79
|
-
"@repo/test-config": "3.
|
78
|
+
"@repo/package.config": "3.72.1",
|
79
|
+
"@repo/test-config": "3.72.1",
|
80
80
|
"@rexxars/gitconfiglocal": "^3.0.1",
|
81
81
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
82
82
|
"@sanity/eslint-config-studio": "^4.0.0",
|
83
83
|
"@sanity/generate-help-url": "^3.0.0",
|
84
|
-
"@sanity/types": "3.72.2-
|
84
|
+
"@sanity/types": "3.72.2-corel.24+9afe9690e4",
|
85
85
|
"@types/babel__traverse": "^7.20.5",
|
86
86
|
"@types/configstore": "^5.0.1",
|
87
87
|
"@types/cpx": "^1.5.2",
|
@@ -126,12 +126,12 @@
|
|
126
126
|
"semver-compare": "^1.0.0",
|
127
127
|
"tar": "^6.1.11",
|
128
128
|
"vite": "^6.0.11",
|
129
|
-
"vitest": "^2.1.
|
129
|
+
"vitest": "^2.1.8",
|
130
130
|
"which": "^2.0.2",
|
131
131
|
"xdg-basedir": "^4.0.0"
|
132
132
|
},
|
133
133
|
"engines": {
|
134
134
|
"node": ">=18"
|
135
135
|
},
|
136
|
-
"gitHead": "
|
136
|
+
"gitHead": "9afe9690e4bd322059a6953a37c7ad6f9fe23f7e"
|
137
137
|
}
|
@@ -10,10 +10,8 @@ import {copy} from '../../util/copy'
|
|
10
10
|
import {getAndWriteJourneySchemaWorker} from '../../util/journeyConfig'
|
11
11
|
import {resolveLatestVersions} from '../../util/resolveLatestVersions'
|
12
12
|
import {createCliConfig} from './createCliConfig'
|
13
|
-
import {createCoreAppCliConfig} from './createCoreAppCliConfig'
|
14
13
|
import {createPackageManifest} from './createPackageManifest'
|
15
14
|
import {createStudioConfig, type GenerateConfigOptions} from './createStudioConfig'
|
16
|
-
import {determineCoreAppTemplate} from './determineCoreAppTemplate'
|
17
15
|
import {type ProjectTemplate} from './initProject'
|
18
16
|
import templates from './templates'
|
19
17
|
import {updateInitialTemplateMetadata} from './updateInitialTemplateMetadata'
|
@@ -38,9 +36,9 @@ export async function bootstrapLocalTemplate(
|
|
38
36
|
const {apiClient, cliRoot, output} = context
|
39
37
|
const templatesDir = path.join(cliRoot, 'templates')
|
40
38
|
const {outputPath, templateName, useTypeScript, packageName, variables} = opts
|
39
|
+
const {projectId} = variables
|
41
40
|
const sourceDir = path.join(templatesDir, templateName)
|
42
41
|
const sharedDir = path.join(templatesDir, 'shared')
|
43
|
-
const isCoreAppTemplate = determineCoreAppTemplate(templateName)
|
44
42
|
|
45
43
|
// Check that we have a template info file (dependencies, plugins etc)
|
46
44
|
const template = templates[templateName]
|
@@ -83,16 +81,15 @@ export async function bootstrapLocalTemplate(
|
|
83
81
|
// Resolve latest versions of Sanity-dependencies
|
84
82
|
spinner = output.spinner('Resolving latest module versions').start()
|
85
83
|
const dependencyVersions = await resolveLatestVersions({
|
86
|
-
...
|
87
|
-
...
|
84
|
+
...studioDependencies.dependencies,
|
85
|
+
...studioDependencies.devDependencies,
|
88
86
|
...(template.dependencies || {}),
|
89
|
-
...(template.devDependencies || {}),
|
90
87
|
})
|
91
88
|
spinner.succeed()
|
92
89
|
|
93
90
|
// Use the resolved version for the given dependency
|
94
91
|
const dependencies = Object.keys({
|
95
|
-
...
|
92
|
+
...studioDependencies.dependencies,
|
96
93
|
...template.dependencies,
|
97
94
|
}).reduce(
|
98
95
|
(deps, dependency) => {
|
@@ -103,7 +100,7 @@ export async function bootstrapLocalTemplate(
|
|
103
100
|
)
|
104
101
|
|
105
102
|
const devDependencies = Object.keys({
|
106
|
-
...
|
103
|
+
...studioDependencies.devDependencies,
|
107
104
|
...template.devDependencies,
|
108
105
|
}).reduce(
|
109
106
|
(deps, dependency) => {
|
@@ -119,41 +116,32 @@ export async function bootstrapLocalTemplate(
|
|
119
116
|
name: packageName,
|
120
117
|
dependencies,
|
121
118
|
devDependencies,
|
122
|
-
scripts: template.scripts,
|
123
119
|
})
|
124
120
|
|
125
121
|
// ...and a studio config (`sanity.config.[ts|js]`)
|
126
|
-
const studioConfig = createStudioConfig({
|
122
|
+
const studioConfig = await createStudioConfig({
|
127
123
|
template: template.configTemplate,
|
128
124
|
variables,
|
129
125
|
})
|
130
126
|
|
131
127
|
// ...and a CLI config (`sanity.cli.[ts|js]`)
|
132
|
-
const cliConfig =
|
133
|
-
|
134
|
-
:
|
135
|
-
|
136
|
-
|
137
|
-
autoUpdates: variables.autoUpdates,
|
138
|
-
})
|
128
|
+
const cliConfig = await createCliConfig({
|
129
|
+
projectId: variables.projectId,
|
130
|
+
dataset: variables.dataset,
|
131
|
+
autoUpdates: variables.autoUpdates,
|
132
|
+
})
|
139
133
|
|
140
134
|
// Write non-template files to disc
|
141
135
|
const codeExt = useTypeScript ? 'ts' : 'js'
|
142
|
-
await Promise.all(
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
]
|
149
|
-
|
150
|
-
|
151
|
-
writeFileIfNotExists(
|
152
|
-
'eslint.config.mjs',
|
153
|
-
`import studio from '@sanity/eslint-config-studio'\n\nexport default [...studio]\n`,
|
154
|
-
),
|
155
|
-
].filter(Boolean),
|
156
|
-
)
|
136
|
+
await Promise.all([
|
137
|
+
writeFileIfNotExists(`sanity.config.${codeExt}`, studioConfig),
|
138
|
+
writeFileIfNotExists(`sanity.cli.${codeExt}`, cliConfig),
|
139
|
+
writeFileIfNotExists('package.json', packageManifest),
|
140
|
+
writeFileIfNotExists(
|
141
|
+
'eslint.config.mjs',
|
142
|
+
`import studio from '@sanity/eslint-config-studio'\n\nexport default [...studio]\n`,
|
143
|
+
),
|
144
|
+
])
|
157
145
|
|
158
146
|
debug('Updating initial template metadata')
|
159
147
|
await updateInitialTemplateMetadata(apiClient, variables.projectId, `cli-${templateName}`)
|
@@ -1,4 +1,6 @@
|
|
1
|
-
import
|
1
|
+
import traverse from '@babel/traverse'
|
2
|
+
import {parse, print} from 'recast'
|
3
|
+
import * as parser from 'recast/parsers/typescript'
|
2
4
|
|
3
5
|
const defaultTemplate = `
|
4
6
|
import {defineCliConfig} from 'sanity/cli'
|
@@ -23,9 +25,49 @@ export interface GenerateCliConfigOptions {
|
|
23
25
|
}
|
24
26
|
|
25
27
|
export function createCliConfig(options: GenerateCliConfigOptions): string {
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
const variables = options
|
29
|
+
const template = defaultTemplate.trimStart()
|
30
|
+
const ast = parse(template, {parser})
|
31
|
+
|
32
|
+
traverse(ast, {
|
33
|
+
StringLiteral: {
|
34
|
+
enter({node}) {
|
35
|
+
const value = node.value
|
36
|
+
if (!value.startsWith('%') || !value.endsWith('%')) {
|
37
|
+
return
|
38
|
+
}
|
39
|
+
const variableName = value.slice(1, -1) as keyof GenerateCliConfigOptions
|
40
|
+
if (!(variableName in variables)) {
|
41
|
+
throw new Error(`Template variable '${value}' not defined`)
|
42
|
+
}
|
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})
|
68
|
+
},
|
69
|
+
},
|
30
70
|
})
|
71
|
+
|
72
|
+
return print(ast, {quote: 'single'}).code
|
31
73
|
}
|
@@ -1,4 +1,6 @@
|
|
1
|
-
import
|
1
|
+
import traverse from '@babel/traverse'
|
2
|
+
import {parse, print} from 'recast'
|
3
|
+
import * as parser from 'recast/parsers/typescript'
|
2
4
|
|
3
5
|
const defaultTemplate = `
|
4
6
|
import {defineConfig} from 'sanity'
|
@@ -45,8 +47,29 @@ export function createStudioConfig(options: GenerateConfigOptions): string {
|
|
45
47
|
return options.template(variables).trimStart()
|
46
48
|
}
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
-
|
50
|
+
const template = (options.template || defaultTemplate).trimStart()
|
51
|
+
const ast = parse(template, {parser})
|
52
|
+
traverse(ast, {
|
53
|
+
StringLiteral: {
|
54
|
+
enter({node}) {
|
55
|
+
const value = node.value
|
56
|
+
if (!value.startsWith('%') || !value.endsWith('%')) {
|
57
|
+
return
|
58
|
+
}
|
59
|
+
|
60
|
+
const variableName = value.slice(1, -1) as keyof GenerateConfigOptions['variables']
|
61
|
+
if (!(variableName in variables)) {
|
62
|
+
throw new Error(`Template variable '${value}' not defined`)
|
63
|
+
}
|
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 : ''
|
70
|
+
},
|
71
|
+
},
|
51
72
|
})
|
73
|
+
|
74
|
+
return print(ast, {quote: 'single'}).code
|
52
75
|
}
|
@@ -49,7 +49,6 @@ import {createProject} from '../project/createProject'
|
|
49
49
|
import {bootstrapLocalTemplate} from './bootstrapLocalTemplate'
|
50
50
|
import {bootstrapRemoteTemplate} from './bootstrapRemoteTemplate'
|
51
51
|
import {type GenerateConfigOptions} from './createStudioConfig'
|
52
|
-
import {determineCoreAppTemplate} from './determineCoreAppTemplate'
|
53
52
|
import {absolutify, validateEmptyPath} from './fsUtils'
|
54
53
|
import {tryGitInit} from './git'
|
55
54
|
import {promptForDatasetName} from './promptForDatasetName'
|
@@ -98,8 +97,6 @@ export interface ProjectTemplate {
|
|
98
97
|
importPrompt?: string
|
99
98
|
configTemplate?: string | ((variables: GenerateConfigOptions['variables']) => string)
|
100
99
|
typescriptOnly?: boolean
|
101
|
-
appLocation?: string
|
102
|
-
scripts?: Record<string, string>
|
103
100
|
}
|
104
101
|
|
105
102
|
export interface ProjectOrganization {
|
@@ -274,9 +271,6 @@ export default async function initSanity(
|
|
274
271
|
print('')
|
275
272
|
|
276
273
|
const flags = await prepareFlags()
|
277
|
-
// skip project / dataset prompting
|
278
|
-
const isCoreAppTemplate = cliFlags.template ? determineCoreAppTemplate(cliFlags.template) : false // Default to false
|
279
|
-
|
280
274
|
// We're authenticated, now lets select or create a project
|
281
275
|
const {projectId, displayName, isFirstProject, datasetName, schemaUrl} = await getProjectDetails()
|
282
276
|
|
@@ -661,15 +655,11 @@ export default async function initSanity(
|
|
661
655
|
const isCurrentDir = outputPath === process.cwd()
|
662
656
|
if (isCurrentDir) {
|
663
657
|
print(`\n${chalk.green('Success!')} Now, use this command to continue:\n`)
|
664
|
-
print(
|
665
|
-
`${chalk.cyan(devCommand)} - to run ${isCoreAppTemplate ? 'your Sanity application' : 'Sanity Studio'}\n`,
|
666
|
-
)
|
658
|
+
print(`${chalk.cyan(devCommand)} - to run Sanity Studio\n`)
|
667
659
|
} else {
|
668
660
|
print(`\n${chalk.green('Success!')} Now, use these commands to continue:\n`)
|
669
661
|
print(`First: ${chalk.cyan(`cd ${outputPath}`)} - to enter project’s directory`)
|
670
|
-
print(
|
671
|
-
`Then: ${chalk.cyan(devCommand)} -to run ${isCoreAppTemplate ? 'your Sanity application' : 'Sanity Studio'}\n`,
|
672
|
-
)
|
662
|
+
print(`Then: ${chalk.cyan(devCommand)} - to run Sanity Studio\n`)
|
673
663
|
}
|
674
664
|
|
675
665
|
print(`Other helpful commands`)
|
@@ -730,15 +720,6 @@ export default async function initSanity(
|
|
730
720
|
return data
|
731
721
|
}
|
732
722
|
|
733
|
-
if (isCoreAppTemplate) {
|
734
|
-
return {
|
735
|
-
projectId: '',
|
736
|
-
displayName: '',
|
737
|
-
isFirstProject: false,
|
738
|
-
datasetName: '',
|
739
|
-
}
|
740
|
-
}
|
741
|
-
|
742
723
|
debug('Prompting user to select or create a project')
|
743
724
|
const project = await getOrCreateProject()
|
744
725
|
debug(`Project with name ${project.displayName} selected`)
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import {type ProjectTemplate} from '../initProject'
|
2
2
|
import blog from './blog'
|
3
3
|
import clean from './clean'
|
4
|
-
import coreAppTemplate from './coreApp'
|
5
4
|
import getStartedTemplate from './getStarted'
|
6
5
|
import moviedb from './moviedb'
|
7
6
|
import quickstart from './quickstart'
|
@@ -11,7 +10,6 @@ import shopifyOnline from './shopifyOnline'
|
|
11
10
|
const templates: Record<string, ProjectTemplate | undefined> = {
|
12
11
|
blog,
|
13
12
|
clean,
|
14
|
-
'core-app': coreAppTemplate,
|
15
13
|
'get-started': getStartedTemplate,
|
16
14
|
moviedb,
|
17
15
|
shopify,
|
package/src/types.ts
CHANGED
@@ -24,7 +24,6 @@ export interface SanityModuleInternal {
|
|
24
24
|
export interface PackageJson {
|
25
25
|
name: string
|
26
26
|
version: string
|
27
|
-
scripts?: Record<string, string>
|
28
27
|
|
29
28
|
description?: string
|
30
29
|
author?: string
|
@@ -345,15 +344,6 @@ export interface CliConfig {
|
|
345
344
|
autoUpdates?: boolean
|
346
345
|
|
347
346
|
studioHost?: string
|
348
|
-
|
349
|
-
/**
|
350
|
-
* Parameter used to configure other kinds of applications.
|
351
|
-
* Signals to `sanity` commands that this is not a studio.
|
352
|
-
* @internal
|
353
|
-
*/
|
354
|
-
__experimental_coreAppConfiguration?: {
|
355
|
-
appLocation?: string
|
356
|
-
}
|
357
347
|
}
|
358
348
|
|
359
349
|
export type UserViteConfig =
|
@@ -1,23 +0,0 @@
|
|
1
|
-
import {processTemplate} from './processTemplate'
|
2
|
-
|
3
|
-
const defaultCoreAppTemplate = `
|
4
|
-
import {defineCliConfig} from 'sanity/cli'
|
5
|
-
|
6
|
-
export default defineCliConfig({
|
7
|
-
__experimental_coreAppConfiguration: {
|
8
|
-
appLocation: '%appLocation%'
|
9
|
-
},
|
10
|
-
})
|
11
|
-
`
|
12
|
-
|
13
|
-
export interface GenerateCliConfigOptions {
|
14
|
-
organizationId?: string
|
15
|
-
appLocation: string
|
16
|
-
}
|
17
|
-
|
18
|
-
export function createCoreAppCliConfig(options: GenerateCliConfigOptions): string {
|
19
|
-
return processTemplate({
|
20
|
-
template: defaultCoreAppTemplate,
|
21
|
-
variables: options,
|
22
|
-
})
|
23
|
-
}
|
@@ -1,13 +0,0 @@
|
|
1
|
-
const coreAppTemplates = ['core-app']
|
2
|
-
|
3
|
-
/**
|
4
|
-
* Determine if a given template is a studio template.
|
5
|
-
* This function may need to be more robust once we
|
6
|
-
* introduce remote templates, for example.
|
7
|
-
*
|
8
|
-
* @param templateName - Name of the template
|
9
|
-
* @returns boolean indicating if the template is a studio template
|
10
|
-
*/
|
11
|
-
export function determineCoreAppTemplate(templateName: string): boolean {
|
12
|
-
return coreAppTemplates.includes(templateName)
|
13
|
-
}
|
@@ -1,55 +0,0 @@
|
|
1
|
-
import traverse from '@babel/traverse'
|
2
|
-
import {parse, print} from 'recast'
|
3
|
-
import * as parser from 'recast/parsers/typescript'
|
4
|
-
|
5
|
-
interface TemplateOptions<T> {
|
6
|
-
template: string
|
7
|
-
variables: T
|
8
|
-
includeBooleanTransform?: boolean
|
9
|
-
}
|
10
|
-
|
11
|
-
export function processTemplate<T extends object>(options: TemplateOptions<T>): string {
|
12
|
-
const {template, variables, includeBooleanTransform = false} = options
|
13
|
-
const ast = parse(template.trimStart(), {parser})
|
14
|
-
|
15
|
-
traverse(ast, {
|
16
|
-
StringLiteral: {
|
17
|
-
enter({node}) {
|
18
|
-
const value = node.value
|
19
|
-
if (!value.startsWith('%') || !value.endsWith('%')) {
|
20
|
-
return
|
21
|
-
}
|
22
|
-
const variableName = value.slice(1, -1) as keyof T
|
23
|
-
if (!(variableName in variables)) {
|
24
|
-
throw new Error(`Template variable '${value}' not defined`)
|
25
|
-
}
|
26
|
-
const newValue = variables[variableName]
|
27
|
-
/*
|
28
|
-
* although there are valid non-strings in our config,
|
29
|
-
* they're not in StringLiteral nodes, so assume undefined
|
30
|
-
*/
|
31
|
-
node.value = typeof newValue === 'string' ? newValue : ''
|
32
|
-
},
|
33
|
-
},
|
34
|
-
...(includeBooleanTransform && {
|
35
|
-
Identifier: {
|
36
|
-
enter(path) {
|
37
|
-
if (!path.node.name.startsWith('__BOOL__')) {
|
38
|
-
return
|
39
|
-
}
|
40
|
-
const variableName = path.node.name.replace(/^__BOOL__(.+?)__$/, '$1') as keyof T
|
41
|
-
if (!(variableName in variables)) {
|
42
|
-
throw new Error(`Template variable '${variableName.toString()}' not defined`)
|
43
|
-
}
|
44
|
-
const value = variables[variableName]
|
45
|
-
if (typeof value !== 'boolean') {
|
46
|
-
throw new Error(`Expected boolean value for '${variableName.toString()}'`)
|
47
|
-
}
|
48
|
-
path.replaceWith({type: 'BooleanLiteral', value})
|
49
|
-
},
|
50
|
-
},
|
51
|
-
}),
|
52
|
-
})
|
53
|
-
|
54
|
-
return print(ast, {quote: 'single'}).code
|
55
|
-
}
|
@@ -1,31 +0,0 @@
|
|
1
|
-
import {type ProjectTemplate} from '../initProject'
|
2
|
-
|
3
|
-
const coreAppTemplate: ProjectTemplate = {
|
4
|
-
dependencies: {
|
5
|
-
'@sanity/sdk': '^0.0.0-alpha',
|
6
|
-
'@sanity/sdk-react': '^0.0.0-alpha',
|
7
|
-
'react': '^19',
|
8
|
-
'react-dom': '^19',
|
9
|
-
},
|
10
|
-
devDependencies: {
|
11
|
-
/*
|
12
|
-
* this will be changed to eslint-config sanity,
|
13
|
-
* eslint.config generation will be a fast follow
|
14
|
-
*/
|
15
|
-
'@sanity/eslint-config-studio': '^5.0.1',
|
16
|
-
'@types/react': '^18.0.25',
|
17
|
-
'eslint': '^9.9.0',
|
18
|
-
'prettier': '^3.0.2',
|
19
|
-
'sanity': '^3',
|
20
|
-
'typescript': '^5.1.6',
|
21
|
-
},
|
22
|
-
appLocation: './src/App.tsx',
|
23
|
-
scripts: {
|
24
|
-
// this will eventually run a concurrently process with another in-flight utility
|
25
|
-
dev: 'sanity app dev',
|
26
|
-
build: 'sanity app build',
|
27
|
-
start: 'sanity app start',
|
28
|
-
},
|
29
|
-
}
|
30
|
-
|
31
|
-
export default coreAppTemplate
|
@@ -1,26 +0,0 @@
|
|
1
|
-
import {createSanityInstance} from '@sanity/sdk'
|
2
|
-
import {SanityProvider} from '@sanity/sdk-react/context'
|
3
|
-
|
4
|
-
export function App() {
|
5
|
-
|
6
|
-
const sanityConfig = {
|
7
|
-
auth: {
|
8
|
-
authScope: 'global'
|
9
|
-
}
|
10
|
-
/*
|
11
|
-
* Apps can access several different projects!
|
12
|
-
* Add the below configuration if you want to connect to a specific project.
|
13
|
-
*/
|
14
|
-
// projectId: 'my-project-id',
|
15
|
-
// dataset: 'my-dataset',
|
16
|
-
}
|
17
|
-
|
18
|
-
const sanityInstance = createSanityInstance(sanityConfig)
|
19
|
-
return (
|
20
|
-
<SanityProvider sanityInstance={sanityInstance}>
|
21
|
-
Hello world!
|
22
|
-
</SanityProvider>
|
23
|
-
)
|
24
|
-
}
|
25
|
-
|
26
|
-
export default App
|