@sanity/cli 3.84.1-next.2 → 3.85.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 +156 -31
- package/lib/_chunks-cjs/cli.js.map +1 -1
- package/lib/index.d.mts +10 -0
- package/lib/index.d.ts +10 -0
- package/package.json +9 -9
- package/src/commands/functions/devFunctionsCommand.ts +2 -3
- package/src/commands/functions/envFunctionsCommand.ts +109 -0
- package/src/commands/functions/logsFunctionsCommand.ts +78 -10
- package/src/commands/functions/testFunctionsCommand.ts +33 -22
- package/src/commands/index.ts +2 -0
- package/src/types.ts +11 -0
package/lib/index.d.mts
CHANGED
@@ -128,6 +128,16 @@ export declare interface CliConfig {
|
|
128
128
|
* Signals to `sanity` commands that this is not a studio.
|
129
129
|
*/
|
130
130
|
app?: AppConfig
|
131
|
+
/**
|
132
|
+
* Configuration for Sanity media libraries.
|
133
|
+
*/
|
134
|
+
mediaLibrary?: {
|
135
|
+
/**
|
136
|
+
* The path to the Media Library aspects directory. When using the CLI to manage aspects, this
|
137
|
+
* is the directory they will be read from and written to.
|
138
|
+
*/
|
139
|
+
aspectsPath: string
|
140
|
+
}
|
131
141
|
}
|
132
142
|
|
133
143
|
declare type CliConfigResult =
|
package/lib/index.d.ts
CHANGED
@@ -128,6 +128,16 @@ export declare interface CliConfig {
|
|
128
128
|
* Signals to `sanity` commands that this is not a studio.
|
129
129
|
*/
|
130
130
|
app?: AppConfig
|
131
|
+
/**
|
132
|
+
* Configuration for Sanity media libraries.
|
133
|
+
*/
|
134
|
+
mediaLibrary?: {
|
135
|
+
/**
|
136
|
+
* The path to the Media Library aspects directory. When using the CLI to manage aspects, this
|
137
|
+
* is the directory they will be read from and written to.
|
138
|
+
*/
|
139
|
+
aspectsPath: string
|
140
|
+
}
|
131
141
|
}
|
132
142
|
|
133
143
|
declare type CliConfigResult =
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sanity/cli",
|
3
|
-
"version": "3.
|
3
|
+
"version": "3.85.0",
|
4
4
|
"description": "Sanity CLI tool for managing Sanity installations, managing plugins, schemas and datasets",
|
5
5
|
"keywords": [
|
6
6
|
"sanity",
|
@@ -58,12 +58,12 @@
|
|
58
58
|
},
|
59
59
|
"dependencies": {
|
60
60
|
"@babel/traverse": "^7.23.5",
|
61
|
-
"@sanity/client": "^6.
|
62
|
-
"@sanity/codegen": "3.
|
63
|
-
"@sanity/runtime-cli": "^
|
61
|
+
"@sanity/client": "^6.29.0",
|
62
|
+
"@sanity/codegen": "3.85.0",
|
63
|
+
"@sanity/runtime-cli": "^2.5.0",
|
64
64
|
"@sanity/telemetry": "^0.8.0",
|
65
65
|
"@sanity/template-validator": "^2.4.3",
|
66
|
-
"@sanity/util": "3.
|
66
|
+
"@sanity/util": "3.85.0",
|
67
67
|
"chalk": "^4.1.2",
|
68
68
|
"debug": "^4.3.4",
|
69
69
|
"decompress": "^4.2.0",
|
@@ -77,13 +77,13 @@
|
|
77
77
|
"validate-npm-package-name": "^3.0.0"
|
78
78
|
},
|
79
79
|
"devDependencies": {
|
80
|
-
"@repo/package.config": "3.
|
81
|
-
"@repo/test-config": "3.
|
80
|
+
"@repo/package.config": "3.85.0",
|
81
|
+
"@repo/test-config": "3.85.0",
|
82
82
|
"@rexxars/gitconfiglocal": "^3.0.1",
|
83
83
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
84
84
|
"@sanity/eslint-config-studio": "^4.0.0",
|
85
85
|
"@sanity/generate-help-url": "^3.0.0",
|
86
|
-
"@sanity/types": "3.
|
86
|
+
"@sanity/types": "3.85.0",
|
87
87
|
"@types/babel__traverse": "^7.20.5",
|
88
88
|
"@types/configstore": "^5.0.1",
|
89
89
|
"@types/cpx": "^1.5.2",
|
@@ -135,5 +135,5 @@
|
|
135
135
|
"engines": {
|
136
136
|
"node": ">=18"
|
137
137
|
},
|
138
|
-
"gitHead": "
|
138
|
+
"gitHead": "b29374fa3044d1707d15229dc300f4e0595cfa4b"
|
139
139
|
}
|
@@ -30,9 +30,8 @@ const devFunctionsCommand: CliCommandDefinition = {
|
|
30
30
|
const {print} = output
|
31
31
|
const flags = {...defaultFlags, ...args.extOptions}
|
32
32
|
|
33
|
-
const {
|
34
|
-
|
35
|
-
devAction(flags.port)
|
33
|
+
const {functionsActions} = await import('@sanity/runtime-cli')
|
34
|
+
functionsActions.dev.dev(flags.port)
|
36
35
|
|
37
36
|
print(`Server is running on port ${flags.port}\n`)
|
38
37
|
open(`http://localhost:${flags.port}`)
|
@@ -0,0 +1,109 @@
|
|
1
|
+
import {type StackFunctionResource} from '@sanity/runtime-cli/dist/utils/types'
|
2
|
+
|
3
|
+
import {type CliCommandDefinition} from '../../types'
|
4
|
+
|
5
|
+
const helpText = `
|
6
|
+
Options
|
7
|
+
--name <name> The name of the function
|
8
|
+
--add Add or update an environment variable
|
9
|
+
--remove Remove an environment variable
|
10
|
+
--key <key> The name of the environment variable
|
11
|
+
--value <value> The value of the environment variable
|
12
|
+
|
13
|
+
Examples
|
14
|
+
# Add or update an environment variable
|
15
|
+
sanity functions env --name echo --add --key API_URL --value https://api.example.com/
|
16
|
+
|
17
|
+
# Remove an environment variable
|
18
|
+
sanity functions env --name echo --remove --key API_URL
|
19
|
+
`
|
20
|
+
|
21
|
+
const defaultFlags = {
|
22
|
+
name: '',
|
23
|
+
add: false,
|
24
|
+
remove: false,
|
25
|
+
key: '',
|
26
|
+
value: '',
|
27
|
+
}
|
28
|
+
|
29
|
+
const envFunctionsCommand: CliCommandDefinition = {
|
30
|
+
name: 'env',
|
31
|
+
group: 'functions',
|
32
|
+
helpText,
|
33
|
+
signature: '',
|
34
|
+
description: 'Add or remove an environment variable for a Sanity function',
|
35
|
+
hideFromHelp: true,
|
36
|
+
async action(args, context) {
|
37
|
+
const {apiClient, output} = context
|
38
|
+
const {print} = output
|
39
|
+
const flags = {...defaultFlags, ...args.extOptions}
|
40
|
+
|
41
|
+
const client = apiClient({
|
42
|
+
requireUser: true,
|
43
|
+
requireProject: false,
|
44
|
+
})
|
45
|
+
|
46
|
+
if (flags.name === '') {
|
47
|
+
print('You must provide a function name')
|
48
|
+
return
|
49
|
+
}
|
50
|
+
|
51
|
+
const token = client.config().token
|
52
|
+
const {blueprintsActions, functionsActions, utils} = await import('@sanity/runtime-cli')
|
53
|
+
|
54
|
+
const {deployedStack} = await blueprintsActions.blueprint.readBlueprintOnDisk({
|
55
|
+
getStack: true,
|
56
|
+
token,
|
57
|
+
})
|
58
|
+
|
59
|
+
if (!deployedStack) {
|
60
|
+
print('Stack not found')
|
61
|
+
return
|
62
|
+
}
|
63
|
+
|
64
|
+
const blueprintConfig = blueprintsActions.blueprint.readConfigFile()
|
65
|
+
const projectId = blueprintConfig?.projectId
|
66
|
+
|
67
|
+
const {externalId} = utils.findFunctions.findFunctionByName(
|
68
|
+
deployedStack,
|
69
|
+
flags.name,
|
70
|
+
) as StackFunctionResource
|
71
|
+
|
72
|
+
if (token && projectId) {
|
73
|
+
if (flags.add) {
|
74
|
+
print(`Updating "${flags.key}" environment variable in "${flags.name}"`)
|
75
|
+
const result = await functionsActions.env.update.update(
|
76
|
+
externalId,
|
77
|
+
flags.key,
|
78
|
+
flags.value,
|
79
|
+
{
|
80
|
+
token,
|
81
|
+
projectId,
|
82
|
+
},
|
83
|
+
)
|
84
|
+
if (result.ok) {
|
85
|
+
print(`Update of ${flags.key} succeeded`)
|
86
|
+
} else {
|
87
|
+
print(`Failed to update ${flags.key}`)
|
88
|
+
print(`Error: ${result.error || 'Unknown error'}`)
|
89
|
+
}
|
90
|
+
} else if (flags.remove) {
|
91
|
+
print(`Removing "${flags.key}" environment variable in "${flags.name}"`)
|
92
|
+
const result = await functionsActions.env.remove.remove(externalId, flags.key, {
|
93
|
+
token,
|
94
|
+
projectId,
|
95
|
+
})
|
96
|
+
if (result.ok) {
|
97
|
+
print(`Remove of ${flags.key} succeeded`)
|
98
|
+
} else {
|
99
|
+
print(`Failed to remove ${flags.key}`)
|
100
|
+
print(`Error: ${result.error || 'Unknown error'}`)
|
101
|
+
}
|
102
|
+
}
|
103
|
+
} else {
|
104
|
+
print('You must run this command from a blueprints project')
|
105
|
+
}
|
106
|
+
},
|
107
|
+
}
|
108
|
+
|
109
|
+
export default envFunctionsCommand
|
@@ -1,16 +1,28 @@
|
|
1
|
+
import {type StackFunctionResource} from '@sanity/runtime-cli/dist/utils/types'
|
2
|
+
|
1
3
|
import {type CliCommandDefinition} from '../../types'
|
2
4
|
|
3
5
|
const helpText = `
|
4
6
|
Options
|
5
|
-
--
|
7
|
+
--name <name> The name of the function to retrieve logs for
|
8
|
+
--limit <limit> The number of log entries to retrieve
|
9
|
+
--json If set return json
|
6
10
|
|
7
11
|
Examples
|
8
12
|
# Retrieve logs for Sanity Function abcd1234
|
9
|
-
sanity functions logs --
|
13
|
+
sanity functions logs --name echo
|
14
|
+
|
15
|
+
# Retrieve the last two log entries for Sanity Function abcd1234
|
16
|
+
sanity functions logs --name echo --limit 2
|
17
|
+
|
18
|
+
# Retrieve logs for Sanity Function abcd1234 in json format
|
19
|
+
sanity functions logs --name echo --json
|
10
20
|
`
|
11
21
|
|
12
22
|
const defaultFlags = {
|
13
|
-
|
23
|
+
name: '',
|
24
|
+
limit: 50,
|
25
|
+
json: false,
|
14
26
|
}
|
15
27
|
|
16
28
|
const logsFunctionsCommand: CliCommandDefinition = {
|
@@ -30,15 +42,71 @@ const logsFunctionsCommand: CliCommandDefinition = {
|
|
30
42
|
requireProject: false,
|
31
43
|
})
|
32
44
|
|
33
|
-
if (flags.
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
45
|
+
if (flags.name === '') {
|
46
|
+
print('You must provide a function name')
|
47
|
+
return
|
48
|
+
}
|
49
|
+
|
50
|
+
const token = client.config().token
|
51
|
+
const {blueprintsActions, utils} = await import('@sanity/runtime-cli')
|
52
|
+
|
53
|
+
const {deployedStack} = await blueprintsActions.blueprint.readBlueprintOnDisk({
|
54
|
+
getStack: true,
|
55
|
+
token,
|
56
|
+
})
|
57
|
+
|
58
|
+
if (!deployedStack) {
|
59
|
+
print('Stack not found')
|
60
|
+
return
|
61
|
+
}
|
62
|
+
|
63
|
+
const blueprintConfig = blueprintsActions.blueprint.readConfigFile()
|
64
|
+
const projectId = blueprintConfig?.projectId
|
65
|
+
|
66
|
+
const {externalId} = utils.findFunctions.findFunctionByName(
|
67
|
+
deployedStack,
|
68
|
+
flags.name,
|
69
|
+
) as StackFunctionResource
|
70
|
+
|
71
|
+
if (token && projectId) {
|
72
|
+
const {functionsActions} = await import('@sanity/runtime-cli')
|
73
|
+
const {ok, error, logs, total} = await functionsActions.logs.logs(
|
74
|
+
externalId,
|
75
|
+
{limit: flags.limit},
|
76
|
+
{token, projectId},
|
77
|
+
)
|
78
|
+
|
79
|
+
if (!ok) {
|
80
|
+
print(`Error: ${error || 'Unknown error'}`)
|
81
|
+
return
|
82
|
+
}
|
83
|
+
|
84
|
+
const filteredLogs = logs.filter(
|
85
|
+
(entry: {level: string; message: string}) => entry.level && entry.message,
|
86
|
+
)
|
87
|
+
|
88
|
+
if (filteredLogs.length === 0) {
|
89
|
+
print(`No logs found for function ${flags.name}`)
|
90
|
+
return
|
91
|
+
}
|
92
|
+
|
93
|
+
if (flags.json) {
|
94
|
+
print(JSON.stringify(filteredLogs, null, 2))
|
95
|
+
} else {
|
96
|
+
print(`Found ${total} log entries for function ${flags.name}`)
|
97
|
+
if (logs.length < total) {
|
98
|
+
print(`Here are the last ${filteredLogs.length} entries`)
|
99
|
+
}
|
100
|
+
print('\n')
|
101
|
+
|
102
|
+
for (const log of filteredLogs) {
|
103
|
+
const {time, level, message} = log
|
104
|
+
const date = new Date(time)
|
105
|
+
print(`${date.toLocaleDateString()} ${date.toLocaleTimeString()} ${level} ${message}`)
|
106
|
+
}
|
39
107
|
}
|
40
108
|
} else {
|
41
|
-
print('You must
|
109
|
+
print('You must run this command from a blueprints project')
|
42
110
|
}
|
43
111
|
},
|
44
112
|
}
|
@@ -4,24 +4,24 @@ const helpText = `
|
|
4
4
|
Options
|
5
5
|
--data <data> Data to send to the function
|
6
6
|
--file <file> Read data from file and send to the function
|
7
|
-
--
|
7
|
+
--name <name> The name of your Sanity Function
|
8
8
|
--timeout <timeout> Execution timeout value in seconds
|
9
9
|
|
10
10
|
Examples
|
11
11
|
# Test function passing event data on command line
|
12
|
-
sanity functions test --
|
12
|
+
sanity functions test --name echo --data '{ "id": 1 }'
|
13
13
|
|
14
14
|
# Test function passing event data via a file
|
15
|
-
sanity functions test -
|
15
|
+
sanity functions test -name echo --file 'payload.json'
|
16
16
|
|
17
17
|
# Test function passing event data on command line and cap execution time to 60 seconds
|
18
|
-
sanity functions test -
|
18
|
+
sanity functions test -name echo --data '{ "id": 1 }' --timeout 60
|
19
19
|
`
|
20
20
|
|
21
21
|
const defaultFlags = {
|
22
22
|
data: undefined,
|
23
23
|
file: undefined,
|
24
|
-
|
24
|
+
name: '',
|
25
25
|
timeout: 5, // seconds
|
26
26
|
}
|
27
27
|
|
@@ -37,24 +37,35 @@ const testFunctionsCommand: CliCommandDefinition = {
|
|
37
37
|
const {print} = output
|
38
38
|
const flags = {...defaultFlags, ...args.extOptions}
|
39
39
|
|
40
|
-
if (flags.
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
40
|
+
if (flags.name === '') {
|
41
|
+
print('You must provide a function name')
|
42
|
+
return
|
43
|
+
}
|
44
|
+
|
45
|
+
const {blueprintsActions, functionsActions, utils} = await import('@sanity/runtime-cli')
|
46
|
+
|
47
|
+
const {parsedBlueprint} = await blueprintsActions.blueprint.readBlueprintOnDisk({
|
48
|
+
getStack: false,
|
49
|
+
})
|
50
|
+
|
51
|
+
const src = utils.findFunctions.getFunctionSource(parsedBlueprint, flags.name)
|
52
|
+
if (!src) {
|
53
|
+
print(`Error: Function ${flags.name} has no source code`)
|
54
|
+
}
|
55
|
+
|
56
|
+
const {json, logs, error} = await functionsActions.test.testAction(src, {
|
57
|
+
data: flags.data,
|
58
|
+
file: flags.file,
|
59
|
+
timeout: flags.timeout,
|
60
|
+
})
|
61
|
+
|
62
|
+
if (error) {
|
63
|
+
print(error.toString())
|
56
64
|
} else {
|
57
|
-
print('
|
65
|
+
print('Logs:')
|
66
|
+
print(logs)
|
67
|
+
print('Response:')
|
68
|
+
print(JSON.stringify(json, null, 2))
|
58
69
|
}
|
59
70
|
},
|
60
71
|
}
|
package/src/commands/index.ts
CHANGED
@@ -3,6 +3,7 @@ import codemodCommand from './codemod/codemodCommand'
|
|
3
3
|
import debugCommand from './debug/debugCommand'
|
4
4
|
import docsCommand from './docs/docsCommand'
|
5
5
|
import devfunctionsCommand from './functions/devFunctionsCommand'
|
6
|
+
import envFunctionsCommand from './functions/envFunctionsCommand'
|
6
7
|
import functionsGroup from './functions/functionsGroup'
|
7
8
|
import logsfunctionsCommand from './functions/logsFunctionsCommand'
|
8
9
|
import testfunctionsCommand from './functions/testFunctionsCommand'
|
@@ -47,4 +48,5 @@ export const baseCommands: (CliCommandDefinition | CliCommandGroupDefinition)[]
|
|
47
48
|
devfunctionsCommand,
|
48
49
|
logsfunctionsCommand,
|
49
50
|
testfunctionsCommand,
|
51
|
+
envFunctionsCommand,
|
50
52
|
]
|
package/src/types.ts
CHANGED
@@ -360,6 +360,17 @@ export interface CliConfig {
|
|
360
360
|
* Signals to `sanity` commands that this is not a studio.
|
361
361
|
*/
|
362
362
|
app?: AppConfig
|
363
|
+
|
364
|
+
/**
|
365
|
+
* Configuration for Sanity media libraries.
|
366
|
+
*/
|
367
|
+
mediaLibrary?: {
|
368
|
+
/**
|
369
|
+
* The path to the Media Library aspects directory. When using the CLI to manage aspects, this
|
370
|
+
* is the directory they will be read from and written to.
|
371
|
+
*/
|
372
|
+
aspectsPath: string
|
373
|
+
}
|
363
374
|
}
|
364
375
|
|
365
376
|
export type UserViteConfig =
|