@sanity/cli 3.85.1 → 3.86.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.
@@ -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 {functionsActions} = await import('@sanity/runtime-cli')
34
- functionsActions.dev.dev(flags.port)
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,7 +1,9 @@
1
- import {type StackFunctionResource} from '@sanity/runtime-cli/dist/utils/types'
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
@@ -49,9 +51,11 @@ const envFunctionsCommand: CliCommandDefinition = {
49
51
  }
50
52
 
51
53
  const token = client.config().token
52
- const {blueprintsActions, functionsActions, utils} = await import('@sanity/runtime-cli')
54
+ const {env} = await import('@sanity/runtime-cli/actions/functions')
55
+ const {blueprint} = await import('@sanity/runtime-cli/actions/blueprints')
56
+ const {findFunction} = await import('@sanity/runtime-cli/utils')
53
57
 
54
- const {deployedStack} = await blueprintsActions.blueprint.readBlueprintOnDisk({
58
+ const {deployedStack} = await blueprint.readBlueprintOnDisk({
55
59
  getStack: true,
56
60
  token,
57
61
  })
@@ -61,10 +65,10 @@ const envFunctionsCommand: CliCommandDefinition = {
61
65
  return
62
66
  }
63
67
 
64
- const blueprintConfig = blueprintsActions.blueprint.readConfigFile()
68
+ const blueprintConfig = blueprint.readConfigFile()
65
69
  const projectId = blueprintConfig?.projectId
66
70
 
67
- const {externalId} = utils.findFunctions.findFunctionByName(
71
+ const {externalId} = findFunction.findFunctionByName(
68
72
  deployedStack,
69
73
  flags.name,
70
74
  ) as StackFunctionResource
@@ -72,15 +76,10 @@ const envFunctionsCommand: CliCommandDefinition = {
72
76
  if (token && projectId) {
73
77
  if (flags.add) {
74
78
  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
- )
79
+ const result = await env.update.update(externalId, flags.key, flags.value, {
80
+ token,
81
+ projectId,
82
+ })
84
83
  if (result.ok) {
85
84
  print(`Update of ${flags.key} succeeded`)
86
85
  } else {
@@ -89,7 +88,7 @@ const envFunctionsCommand: CliCommandDefinition = {
89
88
  }
90
89
  } else if (flags.remove) {
91
90
  print(`Removing "${flags.key}" environment variable in "${flags.name}"`)
92
- const result = await functionsActions.env.remove.remove(externalId, flags.key, {
91
+ const result = await env.remove.remove(externalId, flags.key, {
93
92
  token,
94
93
  projectId,
95
94
  })
@@ -1,7 +1,9 @@
1
- import {type StackFunctionResource} from '@sanity/runtime-cli/dist/utils/types'
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
@@ -48,9 +50,10 @@ const logsFunctionsCommand: CliCommandDefinition = {
48
50
  }
49
51
 
50
52
  const token = client.config().token
51
- const {blueprintsActions, utils} = await import('@sanity/runtime-cli')
53
+ const {blueprint} = await import('@sanity/runtime-cli/actions/blueprints')
54
+ const {findFunction} = await import('@sanity/runtime-cli/utils')
52
55
 
53
- const {deployedStack} = await blueprintsActions.blueprint.readBlueprintOnDisk({
56
+ const {deployedStack} = await blueprint.readBlueprintOnDisk({
54
57
  getStack: true,
55
58
  token,
56
59
  })
@@ -60,17 +63,17 @@ const logsFunctionsCommand: CliCommandDefinition = {
60
63
  return
61
64
  }
62
65
 
63
- const blueprintConfig = blueprintsActions.blueprint.readConfigFile()
66
+ const blueprintConfig = blueprint.readConfigFile()
64
67
  const projectId = blueprintConfig?.projectId
65
68
 
66
- const {externalId} = utils.findFunctions.findFunctionByName(
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 {functionsActions} = await import('@sanity/runtime-cli')
73
- const {ok, error, logs, total} = await functionsActions.logs.logs(
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},
@@ -42,22 +42,28 @@ const testFunctionsCommand: CliCommandDefinition = {
42
42
  return
43
43
  }
44
44
 
45
- const {blueprintsActions, functionsActions, utils} = await import('@sanity/runtime-cli')
45
+ const {test} = await import('@sanity/runtime-cli/actions/functions')
46
+ const {blueprint} = await import('@sanity/runtime-cli/actions/blueprints')
47
+ const {findFunction} = await import('@sanity/runtime-cli/utils')
46
48
 
47
- const {parsedBlueprint} = await blueprintsActions.blueprint.readBlueprintOnDisk({
49
+ const {parsedBlueprint} = await blueprint.readBlueprintOnDisk({
48
50
  getStack: false,
49
51
  })
50
52
 
51
- const src = utils.findFunctions.getFunctionSource(parsedBlueprint, flags.name)
53
+ const src = findFunction.getFunctionSource(parsedBlueprint, flags.name)
52
54
  if (!src) {
53
55
  print(`Error: Function ${flags.name} has no source code`)
54
56
  }
55
57
 
56
- const {json, logs, error} = await functionsActions.test.testAction(src, {
57
- data: flags.data,
58
- file: flags.file,
59
- timeout: flags.timeout,
60
- })
58
+ const {json, logs, error} = await test.testAction(
59
+ src,
60
+ {
61
+ data: flags.data,
62
+ file: flags.file,
63
+ timeout: flags.timeout,
64
+ },
65
+ {}, // @TODO: Add context
66
+ )
61
67
 
62
68
  if (error) {
63
69
  print(error.toString())
@@ -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
  ]