@sanity/runtime-cli 4.5.0 → 5.0.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.
Files changed (55) hide show
  1. package/README.md +61 -84
  2. package/dist/actions/blueprints/blueprint.d.ts +6 -12
  3. package/dist/actions/blueprints/blueprint.js +55 -45
  4. package/dist/actions/blueprints/index.d.ts +33 -0
  5. package/dist/actions/blueprints/index.js +32 -0
  6. package/dist/actions/blueprints/projects.d.ts +9 -0
  7. package/dist/actions/blueprints/projects.js +12 -0
  8. package/dist/actions/blueprints/resources.d.ts +1 -0
  9. package/dist/actions/blueprints/resources.js +24 -11
  10. package/dist/actions/blueprints/stacks.d.ts +0 -12
  11. package/dist/actions/blueprints/stacks.js +1 -30
  12. package/dist/baseCommands.d.ts +24 -0
  13. package/dist/baseCommands.js +69 -0
  14. package/dist/commands/blueprints/add.d.ts +7 -3
  15. package/dist/commands/blueprints/add.js +51 -14
  16. package/dist/commands/blueprints/config.d.ts +9 -2
  17. package/dist/commands/blueprints/config.js +68 -18
  18. package/dist/commands/blueprints/deploy.d.ts +2 -2
  19. package/dist/commands/blueprints/deploy.js +18 -33
  20. package/dist/commands/blueprints/destroy.d.ts +4 -3
  21. package/dist/commands/blueprints/destroy.js +32 -35
  22. package/dist/commands/blueprints/info.d.ts +2 -2
  23. package/dist/commands/blueprints/info.js +16 -36
  24. package/dist/commands/blueprints/init.d.ts +15 -6
  25. package/dist/commands/blueprints/init.js +99 -47
  26. package/dist/commands/blueprints/logs.d.ts +2 -2
  27. package/dist/commands/blueprints/logs.js +18 -32
  28. package/dist/commands/blueprints/plan.d.ts +2 -2
  29. package/dist/commands/blueprints/plan.js +10 -16
  30. package/dist/commands/blueprints/stacks.d.ts +3 -2
  31. package/dist/commands/blueprints/stacks.js +10 -29
  32. package/dist/commands/functions/env/add.d.ts +2 -2
  33. package/dist/commands/functions/env/add.js +6 -17
  34. package/dist/commands/functions/env/list.d.ts +2 -2
  35. package/dist/commands/functions/env/list.js +10 -17
  36. package/dist/commands/functions/env/remove.d.ts +2 -2
  37. package/dist/commands/functions/env/remove.js +6 -17
  38. package/dist/commands/functions/invoke.d.ts +2 -2
  39. package/dist/commands/functions/invoke.js +7 -14
  40. package/dist/commands/functions/logs.d.ts +3 -7
  41. package/dist/commands/functions/logs.js +21 -37
  42. package/dist/commands/functions/test.d.ts +3 -3
  43. package/dist/commands/functions/test.js +10 -8
  44. package/dist/server/app.js +3 -3
  45. package/dist/server/static/vendor/vendor.bundle.d.ts +2 -2
  46. package/dist/utils/display/blueprints-formatting.js +2 -2
  47. package/dist/utils/display/colors.js +2 -0
  48. package/dist/utils/display/errors.d.ts +4 -0
  49. package/dist/utils/display/errors.js +27 -0
  50. package/dist/utils/display/index.d.ts +1 -0
  51. package/dist/utils/display/index.js +1 -0
  52. package/dist/utils/types.d.ts +15 -3
  53. package/dist/utils/types.js +9 -3
  54. package/oclif.manifest.json +93 -45
  55. package/package.json +2 -1
package/README.md CHANGED
@@ -20,7 +20,7 @@ $ npm install -g @sanity/runtime-cli
20
20
  $ sanity-run COMMAND
21
21
  running command...
22
22
  $ sanity-run (--version)
23
- @sanity/runtime-cli/4.5.0 linux-x64 node-v22.15.0
23
+ @sanity/runtime-cli/5.0.0 linux-x64 node-v22.15.0
24
24
  $ sanity-run --help [COMMAND]
25
25
  USAGE
26
26
  $ sanity-run COMMAND
@@ -34,10 +34,9 @@ USAGE
34
34
  * [`sanity-run blueprints deploy`](#sanity-run-blueprints-deploy)
35
35
  * [`sanity-run blueprints destroy`](#sanity-run-blueprints-destroy)
36
36
  * [`sanity-run blueprints info`](#sanity-run-blueprints-info)
37
- * [`sanity-run blueprints init`](#sanity-run-blueprints-init)
37
+ * [`sanity-run blueprints init [DIR]`](#sanity-run-blueprints-init-dir)
38
38
  * [`sanity-run blueprints logs`](#sanity-run-blueprints-logs)
39
39
  * [`sanity-run blueprints plan`](#sanity-run-blueprints-plan)
40
- * [`sanity-run blueprints stacks`](#sanity-run-blueprints-stacks)
41
40
  * [`sanity-run functions dev`](#sanity-run-functions-dev)
42
41
  * [`sanity-run functions env add NAME KEY VALUE`](#sanity-run-functions-env-add-name-key-value)
43
42
  * [`sanity-run functions env list NAME`](#sanity-run-functions-env-list-name)
@@ -49,32 +48,37 @@ USAGE
49
48
 
50
49
  ## `sanity-run blueprints add TYPE`
51
50
 
52
- Add a resource to a Blueprint
51
+ Add a (function) resource to a Blueprint
53
52
 
54
53
  ```
55
54
  USAGE
56
- $ sanity-run blueprints add TYPE [--function-type document-publish -n <value>]
55
+ $ sanity-run blueprints add TYPE [--fn-type document-publish -n <value>] [--language ts|js] [--javascript]
57
56
 
58
57
  ARGUMENTS
59
58
  TYPE (function) Type of resource to add (e.g. function)
60
59
 
61
60
  FLAGS
62
- -n, --name=<value> Name of the resource to add
63
- --function-type=<option> Type of function to add (e.g. document-publish)
64
- <options: document-publish>
61
+ -n, --name=<value> Name of the resource to add
62
+ --fn-type=<option> Type of new function
63
+ <options: document-publish>
64
+ --javascript Use JavaScript instead of TypeScript
65
+ --language=<option> [default: ts] Language of the new function
66
+ <options: ts|js>
65
67
 
66
68
  DESCRIPTION
67
- Add a resource to a Blueprint
69
+ Add a (function) resource to a Blueprint
68
70
 
69
71
  EXAMPLES
70
72
  $ sanity-run blueprints add function
71
73
 
72
74
  $ sanity-run blueprints add function --name my-function
73
75
 
74
- $ sanity-run blueprints add function --name my-function --function-type document-publish
76
+ $ sanity-run blueprints add function --name my-function --fn-type document-publish
77
+
78
+ $ sanity-run blueprints add function --name my-function --fn-type document-publish --lang js
75
79
  ```
76
80
 
77
- _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v4.5.0/src/commands/blueprints/add.ts)_
81
+ _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/blueprints/add.ts)_
78
82
 
79
83
  ## `sanity-run blueprints config`
80
84
 
@@ -82,13 +86,12 @@ View or edit Blueprint configuration
82
86
 
83
87
  ```
84
88
  USAGE
85
- $ sanity-run blueprints config [-t] [--project-id <value> -e] [--stack-id <value> ]
89
+ $ sanity-run blueprints config [-t] [--project-id <value> -e]
86
90
 
87
91
  FLAGS
88
92
  -e, --edit Edit the configuration
89
93
  -t, --test-config Validate the configuration
90
94
  --project-id=<value> Update the Project ID in the configuration. Requires --edit flag
91
- --stack-id=<value> Update the Stack ID in the configuration. Requires --edit flag
92
95
 
93
96
  DESCRIPTION
94
97
  View or edit Blueprint configuration
@@ -100,10 +103,10 @@ EXAMPLES
100
103
 
101
104
  $ sanity-run blueprints config --edit
102
105
 
103
- $ sanity-run blueprints config --edit --project-id <projectId> --stack-id <stackId>
106
+ $ sanity-run blueprints config --edit --project-id <projectId>
104
107
  ```
105
108
 
106
- _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v4.5.0/src/commands/blueprints/config.ts)_
109
+ _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/blueprints/config.ts)_
107
110
 
108
111
  ## `sanity-run blueprints deploy`
109
112
 
@@ -121,69 +124,65 @@ DESCRIPTION
121
124
 
122
125
  EXAMPLES
123
126
  $ sanity-run blueprints deploy
127
+
128
+ $ sanity-run blueprints deploy --no-wait
124
129
  ```
125
130
 
126
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v4.5.0/src/commands/blueprints/deploy.ts)_
131
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/blueprints/deploy.ts)_
127
132
 
128
133
  ## `sanity-run blueprints destroy`
129
134
 
130
- Destroy a deployed Blueprint Stack
135
+ Destroy a Blueprint deployment (will not delete local files)
131
136
 
132
137
  ```
133
138
  USAGE
134
- $ sanity-run blueprints destroy [--id <value>] [--force]
139
+ $ sanity-run blueprints destroy [--force]
135
140
 
136
141
  FLAGS
137
- --force Force destroy (skip confirmation)
138
- --id=<value> Stack ID to destroy (defaults to current Stack)
142
+ --force Force destroy (skip confirmation)
139
143
 
140
144
  DESCRIPTION
141
- Destroy a deployed Blueprint Stack
145
+ Destroy a Blueprint deployment (will not delete local files)
142
146
 
143
147
  EXAMPLES
144
148
  $ sanity-run blueprints destroy
145
-
146
- $ sanity-run blueprints destroy --id ST-a1b2c3
147
149
  ```
148
150
 
149
- _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v4.5.0/src/commands/blueprints/destroy.ts)_
151
+ _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/blueprints/destroy.ts)_
150
152
 
151
153
  ## `sanity-run blueprints info`
152
154
 
153
- Show information about a deployed Blueprint Stack
155
+ Show information about a Blueprint deployment
154
156
 
155
157
  ```
156
158
  USAGE
157
- $ sanity-run blueprints info [--id <value>]
158
-
159
- FLAGS
160
- --id=<value> Stack ID to show info for (defaults to current stack)
159
+ $ sanity-run blueprints info
161
160
 
162
161
  DESCRIPTION
163
- Show information about a deployed Blueprint Stack
162
+ Show information about a Blueprint deployment
164
163
 
165
164
  EXAMPLES
166
165
  $ sanity-run blueprints info
167
-
168
- $ sanity-run blueprints info --id ST-a1b2c3
169
166
  ```
170
167
 
171
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v4.5.0/src/commands/blueprints/info.ts)_
168
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/blueprints/info.ts)_
172
169
 
173
- ## `sanity-run blueprints init`
170
+ ## `sanity-run blueprints init [DIR]`
174
171
 
175
172
  Initialize a new Blueprint
176
173
 
177
174
  ```
178
175
  USAGE
179
- $ sanity-run blueprints init [--blueprint-type json|js|ts] [--stack-id <value> --project-id <value>] [-n <value> ]
176
+ $ sanity-run blueprints init [DIR] [--dir <value>] [--blueprint-type json|js|ts] [--project-id <value>]
177
+
178
+ ARGUMENTS
179
+ DIR Directory to create the Blueprint in
180
180
 
181
181
  FLAGS
182
- -n, --stack-name=<value> Name to use for a NEW Stack
183
- --blueprint-type=<option> Blueprint manifest type to use for the Blueprint
184
- <options: json|js|ts>
185
- --project-id=<value> Sanity Project ID to use for the Blueprint
186
- --stack-id=<value> Existing Stack ID to use for the Blueprint
182
+ --blueprint-type=<option> Blueprint manifest type to use for the Blueprint
183
+ <options: json|js|ts>
184
+ --dir=<value> Directory to create the Blueprint in
185
+ --project-id=<value> Sanity Project ID to use for the Blueprint
187
186
 
188
187
  DESCRIPTION
189
188
  Initialize a new Blueprint
@@ -191,18 +190,18 @@ DESCRIPTION
191
190
  EXAMPLES
192
191
  $ sanity-run blueprints init
193
192
 
194
- $ sanity-run blueprints init --blueprint-type <json|js|ts>
193
+ $ sanity-run blueprints init [directory]
195
194
 
196
- $ sanity-run blueprints init --blueprint-type <json|js|ts> --project-id <projectId> --stack-id <stackId>
195
+ $ sanity-run blueprints init --blueprint-type <json|js|ts>
197
196
 
198
- $ sanity-run blueprints init --blueprint-type <json|js|ts> --project-id <projectId> --stack-name <stackName>
197
+ $ sanity-run blueprints init --blueprint-type <json|js|ts> --project-id <projectId>
199
198
  ```
200
199
 
201
- _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v4.5.0/src/commands/blueprints/init.ts)_
200
+ _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/blueprints/init.ts)_
202
201
 
203
202
  ## `sanity-run blueprints logs`
204
203
 
205
- Display logs for a Blueprint stack
204
+ Display logs for a Blueprint deployment
206
205
 
207
206
  ```
208
207
  USAGE
@@ -212,7 +211,7 @@ FLAGS
212
211
  -w, --watch Watch for new logs (streaming mode)
213
212
 
214
213
  DESCRIPTION
215
- Display logs for a Blueprint stack
214
+ Display logs for a Blueprint deployment
216
215
 
217
216
  EXAMPLES
218
217
  $ sanity-run blueprints logs
@@ -220,7 +219,7 @@ EXAMPLES
220
219
  $ sanity-run blueprints logs --watch
221
220
  ```
222
221
 
223
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v4.5.0/src/commands/blueprints/logs.ts)_
222
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/blueprints/logs.ts)_
224
223
 
225
224
  ## `sanity-run blueprints plan`
226
225
 
@@ -237,29 +236,7 @@ EXAMPLES
237
236
  $ sanity-run blueprints plan
238
237
  ```
239
238
 
240
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v4.5.0/src/commands/blueprints/plan.ts)_
241
-
242
- ## `sanity-run blueprints stacks`
243
-
244
- List all Blueprint stacks
245
-
246
- ```
247
- USAGE
248
- $ sanity-run blueprints stacks [--projectId <value>]
249
-
250
- FLAGS
251
- --projectId=<value> Project ID to show stacks for
252
-
253
- DESCRIPTION
254
- List all Blueprint stacks
255
-
256
- EXAMPLES
257
- $ sanity-run blueprints stacks
258
-
259
- $ sanity-run blueprints stacks --projectId a1b2c3
260
- ```
261
-
262
- _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v4.5.0/src/commands/blueprints/stacks.ts)_
239
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/blueprints/plan.ts)_
263
240
 
264
241
  ## `sanity-run functions dev`
265
242
 
@@ -279,7 +256,7 @@ EXAMPLES
279
256
  $ sanity-run functions dev --port 8974
280
257
  ```
281
258
 
282
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v4.5.0/src/commands/functions/dev.ts)_
259
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/functions/dev.ts)_
283
260
 
284
261
  ## `sanity-run functions env add NAME KEY VALUE`
285
262
 
@@ -301,7 +278,7 @@ EXAMPLES
301
278
  $ sanity-run functions env add MyFunction API_URL https://api.example.com/
302
279
  ```
303
280
 
304
- _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v4.5.0/src/commands/functions/env/add.ts)_
281
+ _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/functions/env/add.ts)_
305
282
 
306
283
  ## `sanity-run functions env list NAME`
307
284
 
@@ -321,7 +298,7 @@ EXAMPLES
321
298
  $ sanity-run functions env list MyFunction
322
299
  ```
323
300
 
324
- _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v4.5.0/src/commands/functions/env/list.ts)_
301
+ _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/functions/env/list.ts)_
325
302
 
326
303
  ## `sanity-run functions env remove NAME KEY`
327
304
 
@@ -342,7 +319,7 @@ EXAMPLES
342
319
  $ sanity-run functions env remove MyFunction API_URL
343
320
  ```
344
321
 
345
- _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v4.5.0/src/commands/functions/env/remove.ts)_
322
+ _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/functions/env/remove.ts)_
346
323
 
347
324
  ## `sanity-run functions invoke NAME`
348
325
 
@@ -368,7 +345,7 @@ EXAMPLES
368
345
  $ sanity-run functions invoke <name> --file 'payload.json'
369
346
  ```
370
347
 
371
- _See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v4.5.0/src/commands/functions/invoke.ts)_
348
+ _See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/functions/invoke.ts)_
372
349
 
373
350
  ## `sanity-run functions logs NAME`
374
351
 
@@ -400,7 +377,7 @@ EXAMPLES
400
377
  $ sanity-run functions logs <name> --delete
401
378
  ```
402
379
 
403
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v4.5.0/src/commands/functions/logs.ts)_
380
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/functions/logs.ts)_
404
381
 
405
382
  ## `sanity-run functions test NAME`
406
383
 
@@ -409,18 +386,18 @@ Invoke a local Sanity Function
409
386
  ```
410
387
  USAGE
411
388
  $ sanity-run functions test NAME [-d <value>] [-f <value>] [-t <value>] [-a <value>] [--dataset <value>]
412
- [--project <value>]
389
+ [--project-id <value>]
413
390
 
414
391
  ARGUMENTS
415
392
  NAME The name of the Sanity Function
416
393
 
417
394
  FLAGS
418
- -a, --api=<value> Sanity API Version to use
419
- -d, --data=<value> Data to send to the function
420
- -f, --file=<value> Read data from file and send to the function
421
- -t, --timeout=<value> Execution timeout value in seconds
422
- --dataset=<value> The Sanity dataset to use
423
- --project=<value> The Sanity project to use
395
+ -a, --api=<value> Sanity API Version to use
396
+ -d, --data=<value> Data to send to the function
397
+ -f, --file=<value> Read data from file and send to the function
398
+ -t, --timeout=<value> Execution timeout value in seconds
399
+ --dataset=<value> The Sanity dataset to use
400
+ --project-id=<value> Sanity Project ID to use
424
401
 
425
402
  DESCRIPTION
426
403
  Invoke a local Sanity Function
@@ -433,7 +410,7 @@ EXAMPLES
433
410
  $ sanity-run functions test <name> --data '{ "id": 1 }' --timeout 60
434
411
  ```
435
412
 
436
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v4.5.0/src/commands/functions/test.ts)_
413
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.0/src/commands/functions/test.ts)_
437
414
 
438
415
  ## `sanity-run help [COMMAND]`
439
416
 
@@ -1,28 +1,23 @@
1
- import type { BlueprintParserError, LocalBlueprint, LocalResource, Stack } from '../../utils/types.js';
1
+ import type { BlueprintParserError, LocalBlueprint, LocalResource } from '../../utils/types.js';
2
2
  declare const SUPPORTED_FILE_EXTENSIONS: readonly [".json", ".js", ".mjs", ".cjs", ".ts"];
3
3
  type BlueprintFileExtension = (typeof SUPPORTED_FILE_EXTENSIONS)[number];
4
4
  export declare const DEFAULT_BLUEPRINT_CONTENT: LocalBlueprint;
5
5
  /**
6
6
  * Finds the blueprint file in the given path or current working directory
7
- * @param blueprintFilePath - The full path of the blueprint file
7
+ * @param blueprintPath - The path of the blueprint file or directory
8
8
  * @returns The path, file name, and extension of the blueprint file
9
9
  */
10
- export declare function findBlueprintFile(blueprintFilePath?: string): {
10
+ export declare function findBlueprintFile(blueprintPath?: string): {
11
11
  blueprintFilePath: string;
12
12
  fileName: string;
13
13
  extension: BlueprintFileExtension;
14
14
  } | null;
15
15
  /**
16
- * Reads the blueprint file from disk and parses it
17
- * @todo rename to loadBlueprint or similar
18
- * @todo extract "getStack" into a separate function
16
+ * Reads the blueprint file from disk and parses it. Greedily looks for project and stack config
17
+ * @param blueprintPath - The path of the blueprint file or directory- will search up the directory tree!
19
18
  * @returns Known information about the Blueprint, config, and Stack
20
19
  */
21
- export declare function readBlueprintOnDisk({ blueprintFilePath, getStack, token, }?: {
22
- blueprintFilePath?: string;
23
- getStack?: boolean;
24
- token?: string;
25
- }): Promise<{
20
+ export declare function readLocalBlueprint(blueprintPath?: string): Promise<{
26
21
  fileInfo: {
27
22
  blueprintFilePath: string;
28
23
  fileName: string;
@@ -34,7 +29,6 @@ export declare function readBlueprintOnDisk({ blueprintFilePath, getStack, token
34
29
  configPath?: string;
35
30
  projectId?: string;
36
31
  stackId?: string;
37
- deployedStack?: Stack;
38
32
  }>;
39
33
  export declare function writeBlueprintToDisk({ blueprintFilePath, content, }: {
40
34
  blueprintFilePath: string;
@@ -2,8 +2,9 @@ import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'no
2
2
  import { createRequire } from 'node:module';
3
3
  import { basename, dirname, extname, join } from 'node:path';
4
4
  import { cwd } from 'node:process';
5
+ import { findUpSync } from 'find-up';
6
+ import { BlueprintParserErrorType, isLocalFunctionResource } from '../../utils/types.js';
5
7
  import { blueprintParserValidator } from '../../utils/vendor/parser-validator.js';
6
- import { getStack as getStackById } from './stacks.js';
7
8
  const SUPPORTED_FILE_EXTENSIONS = ['.json', '.js', '.mjs', '.cjs', '.ts'];
8
9
  const SUPPORTED_FILE_NAMES_IN_PRIORITY_ORDER = SUPPORTED_FILE_EXTENSIONS.map((ext) => `blueprint${ext}`);
9
10
  export const DEFAULT_BLUEPRINT_CONTENT = {
@@ -12,49 +13,47 @@ export const DEFAULT_BLUEPRINT_CONTENT = {
12
13
  };
13
14
  /**
14
15
  * Finds the blueprint file in the given path or current working directory
15
- * @param blueprintFilePath - The full path of the blueprint file
16
+ * @param blueprintPath - The path of the blueprint file or directory
16
17
  * @returns The path, file name, and extension of the blueprint file
17
18
  */
18
- export function findBlueprintFile(blueprintFilePath) {
19
+ export function findBlueprintFile(blueprintPath) {
19
20
  let dirToSearch = cwd();
20
- if (blueprintFilePath) {
21
- try {
22
- const stat = statSync(blueprintFilePath);
23
- if (stat.isFile()) {
24
- return {
25
- blueprintFilePath: blueprintFilePath,
26
- fileName: basename(blueprintFilePath),
27
- extension: extname(blueprintFilePath),
28
- };
29
- }
30
- if (stat.isDirectory()) {
31
- dirToSearch = blueprintFilePath;
32
- }
33
- }
34
- catch {
35
- throw Error(`Blueprint file not found: ${blueprintFilePath}`);
36
- }
37
- }
38
- for (const fileName of SUPPORTED_FILE_NAMES_IN_PRIORITY_ORDER) {
39
- const filePath = join(dirToSearch, fileName);
40
- if (existsSync(filePath)) {
21
+ if (blueprintPath) {
22
+ const pathExists = existsSync(blueprintPath);
23
+ if (!pathExists)
24
+ return null;
25
+ const stat = statSync(blueprintPath);
26
+ if (stat.isFile()) {
41
27
  return {
42
- blueprintFilePath: filePath,
43
- fileName,
44
- extension: extname(filePath),
28
+ blueprintFilePath: blueprintPath,
29
+ fileName: basename(blueprintPath),
30
+ extension: extname(blueprintPath),
45
31
  };
46
32
  }
33
+ if (stat.isDirectory()) {
34
+ dirToSearch = blueprintPath;
35
+ }
47
36
  }
48
- return null;
37
+ const blueprintFile = findUpSync(SUPPORTED_FILE_NAMES_IN_PRIORITY_ORDER, {
38
+ cwd: dirToSearch,
39
+ type: 'file',
40
+ allowSymlinks: false,
41
+ });
42
+ if (!blueprintFile)
43
+ return null;
44
+ return {
45
+ blueprintFilePath: blueprintFile,
46
+ fileName: basename(blueprintFile),
47
+ extension: extname(blueprintFile),
48
+ };
49
49
  }
50
50
  /**
51
- * Reads the blueprint file from disk and parses it
52
- * @todo rename to loadBlueprint or similar
53
- * @todo extract "getStack" into a separate function
51
+ * Reads the blueprint file from disk and parses it. Greedily looks for project and stack config
52
+ * @param blueprintPath - The path of the blueprint file or directory- will search up the directory tree!
54
53
  * @returns Known information about the Blueprint, config, and Stack
55
54
  */
56
- export async function readBlueprintOnDisk({ blueprintFilePath, getStack, token, } = {}) {
57
- const blueprintFile = findBlueprintFile(blueprintFilePath);
55
+ export async function readLocalBlueprint(blueprintPath) {
56
+ const blueprintFile = findBlueprintFile(blueprintPath);
58
57
  if (!blueprintFile)
59
58
  throw Error('Could not find Blueprint file! Use the init command.');
60
59
  const { blueprintFilePath: foundPath, fileName, extension } = blueprintFile;
@@ -79,7 +78,6 @@ export async function readBlueprintOnDisk({ blueprintFilePath, getStack, token,
79
78
  break;
80
79
  }
81
80
  case '.ts': {
82
- console.warn('\x1b[2mSupport for Typescript blueprints is experimental.\x1b[0m');
83
81
  try {
84
82
  const { tsImport } = await import('tsx/esm/api');
85
83
  const module = await tsImport(foundPath, dirname(foundPath));
@@ -113,10 +111,26 @@ export async function readBlueprintOnDisk({ blueprintFilePath, getStack, token,
113
111
  const parserResult = blueprintParserValidator(rawBlueprint);
114
112
  const { blueprint: parsedBlueprint } = parserResult;
115
113
  const errors = parserResult.errors || [];
114
+ // further validation - remove once validator is updated
115
+ if (parsedBlueprint.resources) {
116
+ const functionResources = parsedBlueprint.resources.filter(isLocalFunctionResource);
117
+ for (const fnR of functionResources) {
118
+ if (!fnR.event?.on) {
119
+ errors.push({
120
+ message: 'Function resource must have an event "on" property',
121
+ type: BlueprintParserErrorType.InvalidProperty,
122
+ });
123
+ }
124
+ // if (!fnR.src) {
125
+ // // this could be a good spot to infer the src from the name
126
+ // // for now anyway
127
+ // }
128
+ }
129
+ }
116
130
  const configIds = readConfigFile(foundPath);
117
131
  const configPath = configIds?.configPath;
118
132
  const blueprintMetadata = parsedBlueprint.metadata;
119
- // find/create project resource
133
+ // find projectId
120
134
  let projectId;
121
135
  if (configIds?.projectId) {
122
136
  projectId = configIds.projectId;
@@ -129,7 +143,7 @@ export async function readBlueprintOnDisk({ blueprintFilePath, getStack, token,
129
143
  if (projectResource)
130
144
  projectId = projectResource.id;
131
145
  }
132
- // find/create stack resource
146
+ // find stackId
133
147
  let stackId;
134
148
  if (configIds?.stackId) {
135
149
  stackId = configIds.stackId;
@@ -142,14 +156,9 @@ export async function readBlueprintOnDisk({ blueprintFilePath, getStack, token,
142
156
  if (stackResource)
143
157
  stackId = stackResource.id;
144
158
  }
145
- let deployedStack;
146
- if (getStack && token && stackId && projectId) {
147
- const { stack, ok, error } = await getStackById({ stackId, auth: { token, projectId } });
148
- if (!ok) {
149
- throw Error(error || 'Unable to retrieve Stack');
150
- }
151
- deployedStack = stack;
152
- }
159
+ // LAUNCH LIMIT: 1 Stack per Project - infer stackId from projectId
160
+ if (!stackId && projectId)
161
+ stackId = `ST-${projectId}`;
153
162
  return {
154
163
  fileInfo: { blueprintFilePath: foundPath, fileName, extension },
155
164
  rawBlueprint: rawBlueprint,
@@ -157,11 +166,11 @@ export async function readBlueprintOnDisk({ blueprintFilePath, getStack, token,
157
166
  projectId,
158
167
  stackId,
159
168
  configPath,
160
- deployedStack,
161
169
  parsedBlueprint,
162
170
  };
163
171
  }
164
172
  export function writeBlueprintToDisk({ blueprintFilePath, content = DEFAULT_BLUEPRINT_CONTENT, }) {
173
+ const dir = dirname(blueprintFilePath);
165
174
  const extension = extname(blueprintFilePath);
166
175
  let blueprintContent;
167
176
  switch (extension) {
@@ -187,6 +196,7 @@ export function writeBlueprintToDisk({ blueprintFilePath, content = DEFAULT_BLUE
187
196
  throw Error(`Unsupported blueprint file extension: ${extension}`);
188
197
  }
189
198
  }
199
+ mkdirSync(dir, { recursive: true });
190
200
  writeFileSync(blueprintFilePath, blueprintContent);
191
201
  return blueprintContent;
192
202
  }
@@ -5,3 +5,36 @@ export * as operations from './operations.js';
5
5
  export * as projects from './projects.js';
6
6
  export * as resources from './resources.js';
7
7
  export * as stacks from './stacks.js';
8
+ import type { Stack } from '../../utils/types.js';
9
+ import type { BlueprintParserError } from '../../utils/types.js';
10
+ import { readLocalBlueprint } from './blueprint.js';
11
+ export type BlueprintIssue = {
12
+ code: 'NO_STACK_ID' | 'NO_PROJECT_ID' | 'NO_STACK' | 'PARSE_ERROR';
13
+ message: string;
14
+ errors?: BlueprintParserError[];
15
+ };
16
+ type LocalBlueprintWithIds = Awaited<ReturnType<typeof readLocalBlueprint>> & {
17
+ projectId: string;
18
+ stackId: string;
19
+ };
20
+ type BlueprintSuccess = {
21
+ localBlueprint: LocalBlueprintWithIds;
22
+ deployedStack: Stack;
23
+ issues?: never;
24
+ };
25
+ type BlueprintFailure = {
26
+ localBlueprint: Awaited<ReturnType<typeof readLocalBlueprint>>;
27
+ issues: BlueprintIssue[];
28
+ deployedStack?: never;
29
+ };
30
+ type BlueprintResult = BlueprintSuccess | BlueprintFailure;
31
+ /**
32
+ * Get the local Blueprint and deployed Stack
33
+ * @param blueprintPath - The path of the Blueprint file or directory- will search up the directory tree if not provided
34
+ * @param token - The Sanity API token
35
+ * @returns The local Blueprint and deployed Stack
36
+ */
37
+ export declare function getBlueprintAndStack({ token, blueprintPath, }: {
38
+ token: string;
39
+ blueprintPath?: string;
40
+ }): Promise<BlueprintResult>;
@@ -5,3 +5,35 @@ export * as operations from './operations.js';
5
5
  export * as projects from './projects.js';
6
6
  export * as resources from './resources.js';
7
7
  export * as stacks from './stacks.js';
8
+ import { readLocalBlueprint } from './blueprint.js';
9
+ import { getStack } from './stacks.js';
10
+ /**
11
+ * Get the local Blueprint and deployed Stack
12
+ * @param blueprintPath - The path of the Blueprint file or directory- will search up the directory tree if not provided
13
+ * @param token - The Sanity API token
14
+ * @returns The local Blueprint and deployed Stack
15
+ */
16
+ export async function getBlueprintAndStack({ token, blueprintPath, }) {
17
+ if (!token)
18
+ throw new Error('Auth is required');
19
+ const localBlueprint = await readLocalBlueprint(blueprintPath);
20
+ const { projectId, stackId, errors } = localBlueprint;
21
+ const issues = [];
22
+ if (errors.length > 0) {
23
+ issues.push({ code: 'PARSE_ERROR', message: 'Blueprint parse errors', errors });
24
+ }
25
+ if (!(stackId && projectId)) {
26
+ if (!projectId)
27
+ issues.push({ code: 'NO_PROJECT_ID', message: 'Project ID not found' });
28
+ if (!stackId)
29
+ issues.push({ code: 'NO_STACK_ID', message: 'Stack ID not found' });
30
+ return { localBlueprint, issues };
31
+ }
32
+ const auth = { token, projectId };
33
+ const { error, ok, stack: deployedStack } = await getStack({ stackId, auth });
34
+ if (!ok) {
35
+ issues.push({ code: 'NO_STACK', message: error || 'Unknown error' });
36
+ return { localBlueprint, issues };
37
+ }
38
+ return { localBlueprint: localBlueprint, deployedStack };
39
+ }
@@ -18,4 +18,13 @@ interface ListProjectsResponse {
18
18
  export declare function listProjects({ token }: {
19
19
  token: string;
20
20
  }): Promise<ListProjectsResponse>;
21
+ interface GetProjectResponse {
22
+ ok: boolean;
23
+ error: string | null;
24
+ project: Project;
25
+ }
26
+ export declare function getProject({ token, projectId, }: {
27
+ token: string;
28
+ projectId: string;
29
+ }): Promise<GetProjectResponse>;
21
30
  export {};
@@ -16,3 +16,15 @@ export async function listProjects({ token }) {
16
16
  projects,
17
17
  };
18
18
  }
19
+ export async function getProject({ token, projectId, }) {
20
+ const response = await fetch(`${projectsUrl}/${projectId}`, {
21
+ method: 'GET',
22
+ headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
23
+ });
24
+ const project = await response.json();
25
+ return {
26
+ ok: response.ok,
27
+ error: response.ok ? null : project.error?.message,
28
+ project,
29
+ };
30
+ }