@sanity/cli 3.85.2-media-library.14 → 3.86.1
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 +560 -62
- package/lib/_chunks-cjs/cli.js.map +1 -1
- package/package.json +8 -8
- package/src/commands/blueprints/addBlueprintsCommand.ts +81 -0
- package/src/commands/blueprints/blueprintsGroup.ts +11 -0
- package/src/commands/blueprints/configBlueprintsCommand.ts +112 -0
- package/src/commands/blueprints/deployBlueprintsCommand.ts +164 -0
- package/src/commands/blueprints/infoBlueprintsCommand.ts +84 -0
- package/src/commands/blueprints/initBlueprintsCommand.ts +96 -0
- package/src/commands/blueprints/logsBlueprintsCommand.ts +111 -0
- package/src/commands/blueprints/planBlueprintsCommand.ts +63 -0
- package/src/commands/blueprints/stacksBlueprintsCommand.ts +76 -0
- package/src/commands/functions/devFunctionsCommand.ts +2 -2
- package/src/commands/functions/envFunctionsCommand.ts +29 -27
- package/src/commands/functions/logsFunctionsCommand.ts +19 -13
- package/src/commands/functions/testFunctionsCommand.ts +16 -11
- package/src/commands/index.ts +18 -0
- package/bin/xdg-open +0 -1066
@@ -0,0 +1,63 @@
|
|
1
|
+
import {type CliCommandDefinition} from '../../types'
|
2
|
+
|
3
|
+
const helpText = `
|
4
|
+
Safe to run at any time. Will not modify any Resources.
|
5
|
+
|
6
|
+
Examples
|
7
|
+
# Show deployment plan
|
8
|
+
sanity blueprints plan
|
9
|
+
`
|
10
|
+
|
11
|
+
const planBlueprintsCommand: CliCommandDefinition = {
|
12
|
+
name: 'plan',
|
13
|
+
group: 'blueprints',
|
14
|
+
helpText,
|
15
|
+
signature: '',
|
16
|
+
description: 'Enumerate Resources to be deployed',
|
17
|
+
hideFromHelp: true,
|
18
|
+
async action(args, context) {
|
19
|
+
const {apiClient, output} = context
|
20
|
+
const {print} = output
|
21
|
+
|
22
|
+
const client = apiClient({requireUser: true, requireProject: false})
|
23
|
+
const {token} = client.config()
|
24
|
+
const {blueprint: blueprintAction} = await import('@sanity/runtime-cli/actions/blueprints')
|
25
|
+
const {display} = await import('@sanity/runtime-cli/utils')
|
26
|
+
|
27
|
+
let blueprint = null
|
28
|
+
try {
|
29
|
+
blueprint = await blueprintAction.readBlueprintOnDisk({token})
|
30
|
+
} catch (error) {
|
31
|
+
print('Unable to read Blueprint manifest file. Run `sanity blueprints init`')
|
32
|
+
return
|
33
|
+
}
|
34
|
+
|
35
|
+
if (!blueprint) {
|
36
|
+
print('Unable to read Blueprint manifest file. Run `sanity blueprints init`')
|
37
|
+
return
|
38
|
+
}
|
39
|
+
|
40
|
+
const {errors, projectId, stackId, parsedBlueprint, fileInfo} = blueprint
|
41
|
+
|
42
|
+
if (errors && errors.length > 0) {
|
43
|
+
print(errors)
|
44
|
+
}
|
45
|
+
|
46
|
+
const resources = parsedBlueprint.resources || []
|
47
|
+
|
48
|
+
if (!projectId) {
|
49
|
+
print('Unable to determine Project ID.')
|
50
|
+
print('To configure this Blueprint, run `sanity blueprints config`')
|
51
|
+
// continue to show the plan
|
52
|
+
}
|
53
|
+
|
54
|
+
const name = stackId || 'Unknown'
|
55
|
+
print(`${display.blueprintsFormatting.formatTitle('Blueprint', name)} Plan\n`)
|
56
|
+
print(`Blueprint document: (${fileInfo.fileName})`)
|
57
|
+
print('')
|
58
|
+
print(display.blueprintsFormatting.formatResourceTree(resources))
|
59
|
+
print('\nRun `sanity blueprints deploy` to deploy these changes')
|
60
|
+
},
|
61
|
+
}
|
62
|
+
|
63
|
+
export default planBlueprintsCommand
|
@@ -0,0 +1,76 @@
|
|
1
|
+
import {type CliCommandDefinition} from '../../types'
|
2
|
+
|
3
|
+
const helpText = `
|
4
|
+
Examples
|
5
|
+
# List all Stacks for the current Project
|
6
|
+
sanity blueprints stacks
|
7
|
+
`
|
8
|
+
|
9
|
+
const stacksBlueprintsCommand: CliCommandDefinition = {
|
10
|
+
name: 'stacks',
|
11
|
+
group: 'blueprints',
|
12
|
+
helpText,
|
13
|
+
signature: '',
|
14
|
+
description: 'List all Blueprint Stacks for the current Project',
|
15
|
+
hideFromHelp: true,
|
16
|
+
async action(args, context) {
|
17
|
+
const {apiClient, output} = context
|
18
|
+
const {print} = output
|
19
|
+
const client = apiClient({requireUser: true, requireProject: false})
|
20
|
+
const {token} = client.config()
|
21
|
+
|
22
|
+
if (!token) {
|
23
|
+
print('No API token found. Please run `sanity login` first.')
|
24
|
+
return
|
25
|
+
}
|
26
|
+
|
27
|
+
const {blueprint: blueprintAction, stacks: stacksAction} = await import(
|
28
|
+
'@sanity/runtime-cli/actions/blueprints'
|
29
|
+
)
|
30
|
+
const {display} = await import('@sanity/runtime-cli/utils')
|
31
|
+
|
32
|
+
let blueprint = null
|
33
|
+
try {
|
34
|
+
blueprint = await blueprintAction.readBlueprintOnDisk({token})
|
35
|
+
} catch (error) {
|
36
|
+
print('Unable to read Blueprint manifest file. Run `sanity blueprints init`')
|
37
|
+
return
|
38
|
+
}
|
39
|
+
|
40
|
+
if (!blueprint) {
|
41
|
+
print('Unable to read Blueprint manifest file. Run `sanity blueprints init`')
|
42
|
+
return
|
43
|
+
}
|
44
|
+
|
45
|
+
const {errors, projectId, stackId} = blueprint
|
46
|
+
|
47
|
+
if (errors && errors.length > 0) {
|
48
|
+
print(errors)
|
49
|
+
return
|
50
|
+
}
|
51
|
+
|
52
|
+
if (!projectId) {
|
53
|
+
print('Blueprint is not configured for a Project. Run `sanity blueprints config`')
|
54
|
+
return
|
55
|
+
}
|
56
|
+
|
57
|
+
const auth = {token, projectId}
|
58
|
+
const {ok, stacks, error} = await stacksAction.listStacks(auth)
|
59
|
+
|
60
|
+
if (!ok) {
|
61
|
+
print(error || 'Failed to list Stacks')
|
62
|
+
return
|
63
|
+
}
|
64
|
+
|
65
|
+
if (!stacks || stacks.length === 0) {
|
66
|
+
print('No Stacks found')
|
67
|
+
return
|
68
|
+
}
|
69
|
+
|
70
|
+
const {bold, yellow} = display.colors
|
71
|
+
print(`${bold('Project')} <${yellow(projectId)}> ${bold('Stacks')}:\n`)
|
72
|
+
print(display.blueprintsFormatting.formatStacksListing(stacks, stackId))
|
73
|
+
},
|
74
|
+
}
|
75
|
+
|
76
|
+
export default stacksBlueprintsCommand
|
@@ -30,8 +30,8 @@ const devFunctionsCommand: CliCommandDefinition = {
|
|
30
30
|
const {print} = output
|
31
31
|
const flags = {...defaultFlags, ...args.extOptions}
|
32
32
|
|
33
|
-
const {
|
34
|
-
|
33
|
+
const {dev: devAction} = await import('@sanity/runtime-cli/actions/functions')
|
34
|
+
devAction.dev(flags.port)
|
35
35
|
|
36
36
|
print(`Server is running on port ${flags.port}\n`)
|
37
37
|
open(`http://localhost:${flags.port}`)
|
@@ -1,27 +1,29 @@
|
|
1
|
-
import {type
|
1
|
+
import {type types} from '@sanity/runtime-cli/utils'
|
2
2
|
|
3
3
|
import {type CliCommandDefinition} from '../../types'
|
4
4
|
|
5
|
+
type StackFunctionResource = types.StackFunctionResource
|
6
|
+
|
5
7
|
const helpText = `
|
8
|
+
Arguments
|
9
|
+
[add] Add or update an environment variable
|
10
|
+
[remove] Remove an environment variable
|
11
|
+
|
6
12
|
Options
|
7
13
|
--name <name> The name of the function
|
8
|
-
--add Add or update an environment variable
|
9
|
-
--remove Remove an environment variable
|
10
14
|
--key <key> The name of the environment variable
|
11
15
|
--value <value> The value of the environment variable
|
12
16
|
|
13
17
|
Examples
|
14
18
|
# Add or update an environment variable
|
15
|
-
sanity functions env --name echo --
|
19
|
+
sanity functions env add --name echo --key API_URL --value https://api.example.com/
|
16
20
|
|
17
21
|
# Remove an environment variable
|
18
|
-
sanity functions env --name echo --
|
22
|
+
sanity functions env remove --name echo --key API_URL
|
19
23
|
`
|
20
24
|
|
21
25
|
const defaultFlags = {
|
22
26
|
name: '',
|
23
|
-
add: false,
|
24
|
-
remove: false,
|
25
27
|
key: '',
|
26
28
|
value: '',
|
27
29
|
}
|
@@ -36,60 +38,60 @@ const envFunctionsCommand: CliCommandDefinition = {
|
|
36
38
|
async action(args, context) {
|
37
39
|
const {apiClient, output} = context
|
38
40
|
const {print} = output
|
41
|
+
const [subCommand] = args.argsWithoutOptions
|
39
42
|
const flags = {...defaultFlags, ...args.extOptions}
|
40
43
|
|
44
|
+
if (!subCommand || !['add', 'remove'].includes(subCommand)) {
|
45
|
+
throw new Error('You must specify if you wish to add or remove an environment variable')
|
46
|
+
}
|
47
|
+
|
41
48
|
const client = apiClient({
|
42
49
|
requireUser: true,
|
43
50
|
requireProject: false,
|
44
51
|
})
|
45
52
|
|
46
53
|
if (flags.name === '') {
|
47
|
-
|
48
|
-
return
|
54
|
+
throw new Error('You must provide a function name via the --name flag')
|
49
55
|
}
|
50
56
|
|
51
57
|
const token = client.config().token
|
52
|
-
const {
|
58
|
+
const {env} = await import('@sanity/runtime-cli/actions/functions')
|
59
|
+
const {blueprint} = await import('@sanity/runtime-cli/actions/blueprints')
|
60
|
+
const {findFunction} = await import('@sanity/runtime-cli/utils')
|
53
61
|
|
54
|
-
const {deployedStack} = await
|
62
|
+
const {deployedStack} = await blueprint.readBlueprintOnDisk({
|
55
63
|
getStack: true,
|
56
64
|
token,
|
57
65
|
})
|
58
66
|
|
59
67
|
if (!deployedStack) {
|
60
|
-
|
61
|
-
return
|
68
|
+
throw new Error('Stack not found')
|
62
69
|
}
|
63
70
|
|
64
|
-
const blueprintConfig =
|
71
|
+
const blueprintConfig = blueprint.readConfigFile()
|
65
72
|
const projectId = blueprintConfig?.projectId
|
66
73
|
|
67
|
-
const {externalId} =
|
74
|
+
const {externalId} = findFunction.findFunctionByName(
|
68
75
|
deployedStack,
|
69
76
|
flags.name,
|
70
77
|
) as StackFunctionResource
|
71
78
|
|
72
79
|
if (token && projectId) {
|
73
|
-
if (
|
80
|
+
if (subCommand === 'add') {
|
74
81
|
print(`Updating "${flags.key}" environment variable in "${flags.name}"`)
|
75
|
-
const result = await
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
{
|
80
|
-
token,
|
81
|
-
projectId,
|
82
|
-
},
|
83
|
-
)
|
82
|
+
const result = await env.update.update(externalId, flags.key, flags.value, {
|
83
|
+
token,
|
84
|
+
projectId,
|
85
|
+
})
|
84
86
|
if (result.ok) {
|
85
87
|
print(`Update of ${flags.key} succeeded`)
|
86
88
|
} else {
|
87
89
|
print(`Failed to update ${flags.key}`)
|
88
90
|
print(`Error: ${result.error || 'Unknown error'}`)
|
89
91
|
}
|
90
|
-
} else if (
|
92
|
+
} else if (subCommand === 'remove') {
|
91
93
|
print(`Removing "${flags.key}" environment variable in "${flags.name}"`)
|
92
|
-
const result = await
|
94
|
+
const result = await env.remove.remove(externalId, flags.key, {
|
93
95
|
token,
|
94
96
|
projectId,
|
95
97
|
})
|
@@ -1,12 +1,15 @@
|
|
1
|
-
import {type
|
1
|
+
import {type types} from '@sanity/runtime-cli/utils'
|
2
2
|
|
3
3
|
import {type CliCommandDefinition} from '../../types'
|
4
4
|
|
5
|
+
type StackFunctionResource = types.StackFunctionResource
|
6
|
+
|
5
7
|
const helpText = `
|
6
8
|
Options
|
7
9
|
--name <name> The name of the function to retrieve logs for
|
8
|
-
--limit <limit> The number of log entries to retrieve
|
10
|
+
--limit <limit> The number of log entries to retrieve [default 50]
|
9
11
|
--json If set return json
|
12
|
+
--utc Use UTC dates in logs
|
10
13
|
|
11
14
|
Examples
|
12
15
|
# Retrieve logs for Sanity Function abcd1234
|
@@ -23,6 +26,7 @@ const defaultFlags = {
|
|
23
26
|
name: '',
|
24
27
|
limit: 50,
|
25
28
|
json: false,
|
29
|
+
utc: false,
|
26
30
|
}
|
27
31
|
|
28
32
|
const logsFunctionsCommand: CliCommandDefinition = {
|
@@ -43,34 +47,33 @@ const logsFunctionsCommand: CliCommandDefinition = {
|
|
43
47
|
})
|
44
48
|
|
45
49
|
if (flags.name === '') {
|
46
|
-
|
47
|
-
return
|
50
|
+
throw new Error('You must provide a function name via the --name flag')
|
48
51
|
}
|
49
52
|
|
50
53
|
const token = client.config().token
|
51
|
-
const {
|
54
|
+
const {blueprint} = await import('@sanity/runtime-cli/actions/blueprints')
|
55
|
+
const {findFunction} = await import('@sanity/runtime-cli/utils')
|
52
56
|
|
53
|
-
const {deployedStack} = await
|
57
|
+
const {deployedStack} = await blueprint.readBlueprintOnDisk({
|
54
58
|
getStack: true,
|
55
59
|
token,
|
56
60
|
})
|
57
61
|
|
58
62
|
if (!deployedStack) {
|
59
|
-
|
60
|
-
return
|
63
|
+
throw new Error('Stack not found')
|
61
64
|
}
|
62
65
|
|
63
|
-
const blueprintConfig =
|
66
|
+
const blueprintConfig = blueprint.readConfigFile()
|
64
67
|
const projectId = blueprintConfig?.projectId
|
65
68
|
|
66
|
-
const {externalId} =
|
69
|
+
const {externalId} = findFunction.findFunctionByName(
|
67
70
|
deployedStack,
|
68
71
|
flags.name,
|
69
72
|
) as StackFunctionResource
|
70
73
|
|
71
74
|
if (token && projectId) {
|
72
|
-
const {
|
73
|
-
const {ok, error, logs, total} = await
|
75
|
+
const {logs: logsAction} = await import('@sanity/runtime-cli/actions/functions')
|
76
|
+
const {ok, error, logs, total} = await logsAction.logs(
|
74
77
|
externalId,
|
75
78
|
{limit: flags.limit},
|
76
79
|
{token, projectId},
|
@@ -102,7 +105,10 @@ const logsFunctionsCommand: CliCommandDefinition = {
|
|
102
105
|
for (const log of filteredLogs) {
|
103
106
|
const {time, level, message} = log
|
104
107
|
const date = new Date(time)
|
105
|
-
|
108
|
+
const dateString = flags.utc
|
109
|
+
? date.toISOString().slice(0, 19).split('T').join(' ')
|
110
|
+
: `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`
|
111
|
+
print(`${dateString} ${level} ${message}`)
|
106
112
|
}
|
107
113
|
}
|
108
114
|
} else {
|
@@ -38,26 +38,31 @@ const testFunctionsCommand: CliCommandDefinition = {
|
|
38
38
|
const flags = {...defaultFlags, ...args.extOptions}
|
39
39
|
|
40
40
|
if (flags.name === '') {
|
41
|
-
|
42
|
-
return
|
41
|
+
throw new Error('You must provide a function name via the --name flag')
|
43
42
|
}
|
44
43
|
|
45
|
-
const {
|
44
|
+
const {test} = await import('@sanity/runtime-cli/actions/functions')
|
45
|
+
const {blueprint} = await import('@sanity/runtime-cli/actions/blueprints')
|
46
|
+
const {findFunction} = await import('@sanity/runtime-cli/utils')
|
46
47
|
|
47
|
-
const {parsedBlueprint} = await
|
48
|
+
const {parsedBlueprint} = await blueprint.readBlueprintOnDisk({
|
48
49
|
getStack: false,
|
49
50
|
})
|
50
51
|
|
51
|
-
const src =
|
52
|
+
const src = findFunction.getFunctionSource(parsedBlueprint, flags.name)
|
52
53
|
if (!src) {
|
53
|
-
|
54
|
+
throw new Error(`Error: Function ${flags.name} has no source code`)
|
54
55
|
}
|
55
56
|
|
56
|
-
const {json, logs, error} = await
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
const {json, logs, error} = await test.testAction(
|
58
|
+
src,
|
59
|
+
{
|
60
|
+
data: flags.data,
|
61
|
+
file: flags.file,
|
62
|
+
timeout: flags.timeout,
|
63
|
+
},
|
64
|
+
{}, // @TODO: Add context
|
65
|
+
)
|
61
66
|
|
62
67
|
if (error) {
|
63
68
|
print(error.toString())
|
package/src/commands/index.ts
CHANGED
@@ -1,4 +1,13 @@
|
|
1
1
|
import {type CliCommandDefinition, type CliCommandGroupDefinition} from '../types'
|
2
|
+
import addBlueprintsCommand from './blueprints/addBlueprintsCommand'
|
3
|
+
import blueprintsGroup from './blueprints/blueprintsGroup'
|
4
|
+
import configBlueprintsCommand from './blueprints/configBlueprintsCommand'
|
5
|
+
import deployBlueprintsCommand from './blueprints/deployBlueprintsCommand'
|
6
|
+
import infoBlueprintsCommand from './blueprints/infoBlueprintsCommand'
|
7
|
+
import initBlueprintsCommand from './blueprints/initBlueprintsCommand'
|
8
|
+
import logsBlueprintsCommand from './blueprints/logsBlueprintsCommand'
|
9
|
+
import planBlueprintsCommand from './blueprints/planBlueprintsCommand'
|
10
|
+
import listBlueprintsCommand from './blueprints/stacksBlueprintsCommand'
|
2
11
|
import codemodCommand from './codemod/codemodCommand'
|
3
12
|
import debugCommand from './debug/debugCommand'
|
4
13
|
import docsCommand from './docs/docsCommand'
|
@@ -49,4 +58,13 @@ export const baseCommands: (CliCommandDefinition | CliCommandGroupDefinition)[]
|
|
49
58
|
logsfunctionsCommand,
|
50
59
|
testfunctionsCommand,
|
51
60
|
envFunctionsCommand,
|
61
|
+
blueprintsGroup,
|
62
|
+
infoBlueprintsCommand,
|
63
|
+
listBlueprintsCommand,
|
64
|
+
initBlueprintsCommand,
|
65
|
+
deployBlueprintsCommand,
|
66
|
+
logsBlueprintsCommand,
|
67
|
+
addBlueprintsCommand,
|
68
|
+
configBlueprintsCommand,
|
69
|
+
planBlueprintsCommand,
|
52
70
|
]
|