@sanity/runtime-cli 5.0.4 → 5.2.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/README.md +23 -49
- package/dist/actions/blueprints/blueprint.d.ts +9 -5
- package/dist/actions/blueprints/index.d.ts +1 -1
- package/dist/actions/blueprints/index.js +1 -1
- package/dist/actions/functions/index.d.ts +0 -1
- package/dist/actions/functions/index.js +0 -1
- package/dist/baseCommands.d.ts +10 -0
- package/dist/baseCommands.js +23 -11
- package/dist/commands/blueprints/add.d.ts +0 -8
- package/dist/commands/blueprints/add.js +12 -93
- package/dist/commands/blueprints/config.d.ts +2 -24
- package/dist/commands/blueprints/config.js +12 -179
- package/dist/commands/blueprints/deploy.js +12 -69
- package/dist/commands/blueprints/destroy.d.ts +5 -4
- package/dist/commands/blueprints/destroy.js +21 -61
- package/dist/commands/blueprints/info.js +11 -19
- package/dist/commands/blueprints/init.d.ts +0 -16
- package/dist/commands/blueprints/init.js +10 -167
- package/dist/commands/blueprints/logs.js +14 -67
- package/dist/commands/blueprints/plan.js +8 -13
- package/dist/commands/blueprints/stacks.js +10 -19
- package/dist/cores/blueprints/add.d.ts +13 -0
- package/dist/cores/blueprints/add.js +107 -0
- package/dist/cores/blueprints/config.d.ts +13 -0
- package/dist/cores/blueprints/config.js +222 -0
- package/dist/cores/blueprints/deploy.d.ts +14 -0
- package/dist/cores/blueprints/deploy.js +81 -0
- package/dist/cores/blueprints/destroy.d.ts +13 -0
- package/dist/cores/blueprints/destroy.js +106 -0
- package/dist/cores/blueprints/index.d.ts +18 -0
- package/dist/cores/blueprints/index.js +9 -0
- package/dist/cores/blueprints/info.d.ts +11 -0
- package/dist/cores/blueprints/info.js +33 -0
- package/dist/cores/blueprints/init.d.ts +15 -0
- package/dist/cores/blueprints/init.js +190 -0
- package/dist/cores/blueprints/logs.d.ts +11 -0
- package/dist/cores/blueprints/logs.js +74 -0
- package/dist/cores/blueprints/plan.d.ts +6 -0
- package/dist/cores/blueprints/plan.js +11 -0
- package/dist/cores/blueprints/stacks.d.ts +10 -0
- package/dist/cores/blueprints/stacks.js +30 -0
- package/dist/cores/index.d.ts +20 -0
- package/dist/cores/index.js +1 -0
- package/dist/utils/display/blueprints-formatting.js +12 -11
- package/dist/utils/display/colors.d.ts +3 -1
- package/dist/utils/display/colors.js +8 -2
- package/oclif.manifest.json +29 -64
- package/package.json +5 -1
- package/dist/actions/functions/invoke.d.ts +0 -6
- package/dist/actions/functions/invoke.js +0 -18
- package/dist/commands/functions/invoke.d.ts +0 -13
- package/dist/commands/functions/invoke.js +0 -42
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/5.0
|
|
23
|
+
@sanity/runtime-cli/5.2.0 linux-x64 node-v22.15.0
|
|
24
24
|
$ sanity-run --help [COMMAND]
|
|
25
25
|
USAGE
|
|
26
26
|
$ sanity-run COMMAND
|
|
@@ -41,14 +41,13 @@ USAGE
|
|
|
41
41
|
* [`sanity-run functions env add NAME KEY VALUE`](#sanity-run-functions-env-add-name-key-value)
|
|
42
42
|
* [`sanity-run functions env list NAME`](#sanity-run-functions-env-list-name)
|
|
43
43
|
* [`sanity-run functions env remove NAME KEY`](#sanity-run-functions-env-remove-name-key)
|
|
44
|
-
* [`sanity-run functions invoke NAME`](#sanity-run-functions-invoke-name)
|
|
45
44
|
* [`sanity-run functions logs NAME`](#sanity-run-functions-logs-name)
|
|
46
45
|
* [`sanity-run functions test NAME`](#sanity-run-functions-test-name)
|
|
47
46
|
* [`sanity-run help [COMMAND]`](#sanity-run-help-command)
|
|
48
47
|
|
|
49
48
|
## `sanity-run blueprints add TYPE`
|
|
50
49
|
|
|
51
|
-
Add a
|
|
50
|
+
Add a Resource to a Blueprint
|
|
52
51
|
|
|
53
52
|
```
|
|
54
53
|
USAGE
|
|
@@ -58,15 +57,15 @@ ARGUMENTS
|
|
|
58
57
|
TYPE (function) Type of resource to add (e.g. function)
|
|
59
58
|
|
|
60
59
|
FLAGS
|
|
61
|
-
-n, --name=<value> Name of the
|
|
62
|
-
--fn-type=<option> Type of new
|
|
60
|
+
-n, --name=<value> Name of the Resource to add
|
|
61
|
+
--fn-type=<option> Type of new Function
|
|
63
62
|
<options: document-publish>
|
|
64
63
|
--javascript Use JavaScript instead of TypeScript
|
|
65
|
-
--language=<option> [default: ts] Language of the new
|
|
64
|
+
--language=<option> [default: ts] Language of the new Function
|
|
66
65
|
<options: ts|js>
|
|
67
66
|
|
|
68
67
|
DESCRIPTION
|
|
69
|
-
Add a
|
|
68
|
+
Add a Resource to a Blueprint
|
|
70
69
|
|
|
71
70
|
EXAMPLES
|
|
72
71
|
$ sanity-run blueprints add function
|
|
@@ -78,7 +77,7 @@ EXAMPLES
|
|
|
78
77
|
$ sanity-run blueprints add function --name my-function --fn-type document-publish --lang js
|
|
79
78
|
```
|
|
80
79
|
|
|
81
|
-
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0
|
|
80
|
+
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/blueprints/add.ts)_
|
|
82
81
|
|
|
83
82
|
## `sanity-run blueprints config`
|
|
84
83
|
|
|
@@ -106,7 +105,7 @@ EXAMPLES
|
|
|
106
105
|
$ sanity-run blueprints config --edit --project-id <projectId>
|
|
107
106
|
```
|
|
108
107
|
|
|
109
|
-
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0
|
|
108
|
+
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/blueprints/config.ts)_
|
|
110
109
|
|
|
111
110
|
## `sanity-run blueprints deploy`
|
|
112
111
|
|
|
@@ -128,7 +127,7 @@ EXAMPLES
|
|
|
128
127
|
$ sanity-run blueprints deploy --no-wait
|
|
129
128
|
```
|
|
130
129
|
|
|
131
|
-
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0
|
|
130
|
+
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/blueprints/deploy.ts)_
|
|
132
131
|
|
|
133
132
|
## `sanity-run blueprints destroy`
|
|
134
133
|
|
|
@@ -136,10 +135,11 @@ Destroy a Blueprint deployment (will not delete local files)
|
|
|
136
135
|
|
|
137
136
|
```
|
|
138
137
|
USAGE
|
|
139
|
-
$ sanity-run blueprints destroy [--force]
|
|
138
|
+
$ sanity-run blueprints destroy [--force] [--no-wait]
|
|
140
139
|
|
|
141
140
|
FLAGS
|
|
142
|
-
--force
|
|
141
|
+
--force Force destroy (skip confirmation)
|
|
142
|
+
--no-wait Do not wait for destruction to complete
|
|
143
143
|
|
|
144
144
|
DESCRIPTION
|
|
145
145
|
Destroy a Blueprint deployment (will not delete local files)
|
|
@@ -148,7 +148,7 @@ EXAMPLES
|
|
|
148
148
|
$ sanity-run blueprints destroy
|
|
149
149
|
```
|
|
150
150
|
|
|
151
|
-
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0
|
|
151
|
+
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/blueprints/destroy.ts)_
|
|
152
152
|
|
|
153
153
|
## `sanity-run blueprints info`
|
|
154
154
|
|
|
@@ -165,7 +165,7 @@ EXAMPLES
|
|
|
165
165
|
$ sanity-run blueprints info
|
|
166
166
|
```
|
|
167
167
|
|
|
168
|
-
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0
|
|
168
|
+
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/blueprints/info.ts)_
|
|
169
169
|
|
|
170
170
|
## `sanity-run blueprints init [DIR]`
|
|
171
171
|
|
|
@@ -197,7 +197,7 @@ EXAMPLES
|
|
|
197
197
|
$ sanity-run blueprints init --blueprint-type <json|js|ts> --project-id <projectId>
|
|
198
198
|
```
|
|
199
199
|
|
|
200
|
-
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0
|
|
200
|
+
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/blueprints/init.ts)_
|
|
201
201
|
|
|
202
202
|
## `sanity-run blueprints logs`
|
|
203
203
|
|
|
@@ -219,7 +219,7 @@ EXAMPLES
|
|
|
219
219
|
$ sanity-run blueprints logs --watch
|
|
220
220
|
```
|
|
221
221
|
|
|
222
|
-
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0
|
|
222
|
+
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/blueprints/logs.ts)_
|
|
223
223
|
|
|
224
224
|
## `sanity-run blueprints plan`
|
|
225
225
|
|
|
@@ -236,7 +236,7 @@ EXAMPLES
|
|
|
236
236
|
$ sanity-run blueprints plan
|
|
237
237
|
```
|
|
238
238
|
|
|
239
|
-
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0
|
|
239
|
+
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/blueprints/plan.ts)_
|
|
240
240
|
|
|
241
241
|
## `sanity-run functions dev`
|
|
242
242
|
|
|
@@ -256,7 +256,7 @@ EXAMPLES
|
|
|
256
256
|
$ sanity-run functions dev --port 8974
|
|
257
257
|
```
|
|
258
258
|
|
|
259
|
-
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0
|
|
259
|
+
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/functions/dev.ts)_
|
|
260
260
|
|
|
261
261
|
## `sanity-run functions env add NAME KEY VALUE`
|
|
262
262
|
|
|
@@ -278,7 +278,7 @@ EXAMPLES
|
|
|
278
278
|
$ sanity-run functions env add MyFunction API_URL https://api.example.com/
|
|
279
279
|
```
|
|
280
280
|
|
|
281
|
-
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0
|
|
281
|
+
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/functions/env/add.ts)_
|
|
282
282
|
|
|
283
283
|
## `sanity-run functions env list NAME`
|
|
284
284
|
|
|
@@ -298,7 +298,7 @@ EXAMPLES
|
|
|
298
298
|
$ sanity-run functions env list MyFunction
|
|
299
299
|
```
|
|
300
300
|
|
|
301
|
-
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0
|
|
301
|
+
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/functions/env/list.ts)_
|
|
302
302
|
|
|
303
303
|
## `sanity-run functions env remove NAME KEY`
|
|
304
304
|
|
|
@@ -319,33 +319,7 @@ EXAMPLES
|
|
|
319
319
|
$ sanity-run functions env remove MyFunction API_URL
|
|
320
320
|
```
|
|
321
321
|
|
|
322
|
-
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0
|
|
323
|
-
|
|
324
|
-
## `sanity-run functions invoke NAME`
|
|
325
|
-
|
|
326
|
-
Invoke a remote Sanity Function
|
|
327
|
-
|
|
328
|
-
```
|
|
329
|
-
USAGE
|
|
330
|
-
$ sanity-run functions invoke NAME [-d <value>] [-f <value>]
|
|
331
|
-
|
|
332
|
-
ARGUMENTS
|
|
333
|
-
NAME The name of the Sanity Function
|
|
334
|
-
|
|
335
|
-
FLAGS
|
|
336
|
-
-d, --data=<value> Data to send to the function
|
|
337
|
-
-f, --file=<value> Read data from file and send to the function
|
|
338
|
-
|
|
339
|
-
DESCRIPTION
|
|
340
|
-
Invoke a remote Sanity Function
|
|
341
|
-
|
|
342
|
-
EXAMPLES
|
|
343
|
-
$ sanity-run functions invoke <name> --data '{ "id": 1 }'
|
|
344
|
-
|
|
345
|
-
$ sanity-run functions invoke <name> --file 'payload.json'
|
|
346
|
-
```
|
|
347
|
-
|
|
348
|
-
_See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0.4/src/commands/functions/invoke.ts)_
|
|
322
|
+
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/functions/env/remove.ts)_
|
|
349
323
|
|
|
350
324
|
## `sanity-run functions logs NAME`
|
|
351
325
|
|
|
@@ -377,7 +351,7 @@ EXAMPLES
|
|
|
377
351
|
$ sanity-run functions logs <name> --delete
|
|
378
352
|
```
|
|
379
353
|
|
|
380
|
-
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0
|
|
354
|
+
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/functions/logs.ts)_
|
|
381
355
|
|
|
382
356
|
## `sanity-run functions test NAME`
|
|
383
357
|
|
|
@@ -410,7 +384,7 @@ EXAMPLES
|
|
|
410
384
|
$ sanity-run functions test <name> --data '{ "id": 1 }' --timeout 60
|
|
411
385
|
```
|
|
412
386
|
|
|
413
|
-
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v5.0
|
|
387
|
+
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v5.2.0/src/commands/functions/test.ts)_
|
|
414
388
|
|
|
415
389
|
## `sanity-run help [COMMAND]`
|
|
416
390
|
|
|
@@ -13,11 +13,9 @@ export declare function findBlueprintFile(blueprintPath?: string): {
|
|
|
13
13
|
extension: BlueprintFileExtension;
|
|
14
14
|
} | null;
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
* @param blueprintPath - The path of the blueprint file or directory- will search up the directory tree!
|
|
18
|
-
* @returns Known information about the Blueprint, config, and Stack
|
|
16
|
+
* Result of the blueprint read operation
|
|
19
17
|
*/
|
|
20
|
-
export
|
|
18
|
+
export interface ReadBlueprintResult {
|
|
21
19
|
fileInfo: {
|
|
22
20
|
blueprintFilePath: string;
|
|
23
21
|
fileName: string;
|
|
@@ -29,7 +27,13 @@ export declare function readLocalBlueprint(blueprintPath?: string): Promise<{
|
|
|
29
27
|
configPath?: string;
|
|
30
28
|
projectId?: string;
|
|
31
29
|
stackId?: string;
|
|
32
|
-
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Reads the blueprint file from disk and parses it. Greedily looks for project and stack config
|
|
33
|
+
* @param blueprintPath - The path of the blueprint file or directory- will search up the directory tree!
|
|
34
|
+
* @returns Known information about the Blueprint, config, and Stack
|
|
35
|
+
*/
|
|
36
|
+
export declare function readLocalBlueprint(blueprintPath?: string): Promise<ReadBlueprintResult>;
|
|
33
37
|
export declare function writeBlueprintToDisk({ blueprintFilePath, content, }: {
|
|
34
38
|
blueprintFilePath: string;
|
|
35
39
|
content?: LocalBlueprint;
|
|
@@ -32,7 +32,7 @@ type BlueprintResult = BlueprintSuccess | BlueprintFailure;
|
|
|
32
32
|
* Get the local Blueprint and deployed Stack
|
|
33
33
|
* @param blueprintPath - The path of the Blueprint file or directory- will search up the directory tree if not provided
|
|
34
34
|
* @param token - The Sanity API token
|
|
35
|
-
* @returns The local Blueprint and deployed Stack
|
|
35
|
+
* @returns The local Blueprint, issues, and maybe a deployed Stack
|
|
36
36
|
*/
|
|
37
37
|
export declare function getBlueprintAndStack({ token, blueprintPath, }: {
|
|
38
38
|
token: string;
|
|
@@ -11,7 +11,7 @@ import { getStack } from './stacks.js';
|
|
|
11
11
|
* Get the local Blueprint and deployed Stack
|
|
12
12
|
* @param blueprintPath - The path of the Blueprint file or directory- will search up the directory tree if not provided
|
|
13
13
|
* @param token - The Sanity API token
|
|
14
|
-
* @returns The local Blueprint and deployed Stack
|
|
14
|
+
* @returns The local Blueprint, issues, and maybe a deployed Stack
|
|
15
15
|
*/
|
|
16
16
|
export async function getBlueprintAndStack({ token, blueprintPath, }) {
|
|
17
17
|
if (!token)
|
package/dist/baseCommands.d.ts
CHANGED
|
@@ -4,6 +4,11 @@ import { readLocalBlueprint } from './actions/blueprints/blueprint.js';
|
|
|
4
4
|
import type { AuthParams, Stack } from './utils/types.js';
|
|
5
5
|
export type Flags<T extends typeof Command> = Interfaces.InferredFlags<(typeof BlueprintCommand)['baseFlags'] & T['flags']>;
|
|
6
6
|
export type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>;
|
|
7
|
+
/**
|
|
8
|
+
* @description Guarantees flags, args, sanityToken, and blueprint.
|
|
9
|
+
* Blueprint parser errors are logged and the command exits with an error
|
|
10
|
+
* @extends Command
|
|
11
|
+
*/
|
|
7
12
|
export declare abstract class BlueprintCommand<T extends typeof Command> extends Command {
|
|
8
13
|
protected sanityToken: string;
|
|
9
14
|
protected blueprint: Awaited<ReturnType<typeof readLocalBlueprint>>;
|
|
@@ -15,6 +20,11 @@ export declare abstract class BlueprintCommand<T extends typeof Command> extends
|
|
|
15
20
|
}): Promise<unknown>;
|
|
16
21
|
protected finally(_: Error | undefined): Promise<unknown>;
|
|
17
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* @description Guarantees flags, args, sanityToken, blueprint, projectId, stackId, auth, and deployedStack.
|
|
25
|
+
* If a project or stack is missing, the command exits with an error
|
|
26
|
+
* @extends BlueprintCommand
|
|
27
|
+
*/
|
|
18
28
|
export declare abstract class DeployedBlueprintCommand<T extends typeof Command> extends BlueprintCommand<T> {
|
|
19
29
|
protected auth: AuthParams;
|
|
20
30
|
protected deployedStack: Stack;
|
package/dist/baseCommands.js
CHANGED
|
@@ -2,8 +2,14 @@
|
|
|
2
2
|
import { Command } from '@oclif/core';
|
|
3
3
|
import { readLocalBlueprint } from './actions/blueprints/blueprint.js';
|
|
4
4
|
import { getStack } from './actions/blueprints/stacks.js';
|
|
5
|
+
import { niceId } from './utils/display/colors.js';
|
|
5
6
|
import { presentBlueprintParserErrors } from './utils/display/errors.js';
|
|
6
7
|
import { validTokenOrErrorMessage } from './utils/validated-token.js';
|
|
8
|
+
/**
|
|
9
|
+
* @description Guarantees flags, args, sanityToken, and blueprint.
|
|
10
|
+
* Blueprint parser errors are logged and the command exits with an error
|
|
11
|
+
* @extends Command
|
|
12
|
+
*/
|
|
7
13
|
export class BlueprintCommand extends Command {
|
|
8
14
|
sanityToken;
|
|
9
15
|
blueprint;
|
|
@@ -27,7 +33,7 @@ export class BlueprintCommand extends Command {
|
|
|
27
33
|
const blueprint = await readLocalBlueprint();
|
|
28
34
|
if (blueprint.errors.length > 0) {
|
|
29
35
|
this.log(presentBlueprintParserErrors(blueprint.errors));
|
|
30
|
-
this.error('
|
|
36
|
+
this.error('Unable to parse Blueprint file.');
|
|
31
37
|
}
|
|
32
38
|
this.blueprint = blueprint;
|
|
33
39
|
}
|
|
@@ -41,6 +47,11 @@ export class BlueprintCommand extends Command {
|
|
|
41
47
|
return super.finally(_);
|
|
42
48
|
}
|
|
43
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* @description Guarantees flags, args, sanityToken, blueprint, projectId, stackId, auth, and deployedStack.
|
|
52
|
+
* If a project or stack is missing, the command exits with an error
|
|
53
|
+
* @extends BlueprintCommand
|
|
54
|
+
*/
|
|
44
55
|
export class DeployedBlueprintCommand extends BlueprintCommand {
|
|
45
56
|
auth;
|
|
46
57
|
deployedStack;
|
|
@@ -49,21 +60,22 @@ export class DeployedBlueprintCommand extends BlueprintCommand {
|
|
|
49
60
|
async init() {
|
|
50
61
|
await super.init();
|
|
51
62
|
const { projectId, stackId } = this.blueprint;
|
|
52
|
-
if (!projectId)
|
|
53
|
-
this.
|
|
54
|
-
|
|
55
|
-
|
|
63
|
+
if (!(projectId && stackId)) {
|
|
64
|
+
this.log(`Run \`${this.config.bin} blueprints config --edit --test\` to update your config`);
|
|
65
|
+
if (!projectId)
|
|
66
|
+
this.error('Missing Project configuration for Blueprint');
|
|
67
|
+
if (!stackId)
|
|
68
|
+
this.error('Missing deployment configuration for Blueprint');
|
|
69
|
+
}
|
|
56
70
|
this.projectId = projectId;
|
|
57
71
|
this.stackId = stackId;
|
|
58
72
|
this.auth = { token: this.sanityToken, projectId };
|
|
59
73
|
const stackResponse = await getStack({ stackId, auth: this.auth });
|
|
60
74
|
if (!stackResponse.ok) {
|
|
61
|
-
this.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (!deployedStack) {
|
|
65
|
-
this.error('Unable to find deployed Stack. Run `sanity-run blueprints init`');
|
|
75
|
+
this.log(`Could not retrieve deployment info for ${niceId(stackId)}. Was it destroyed?`);
|
|
76
|
+
this.log(`Run \`${this.config.bin} blueprints config --edit --test\` to update your config`);
|
|
77
|
+
this.error('Missing deployment');
|
|
66
78
|
}
|
|
67
|
-
this.deployedStack =
|
|
79
|
+
this.deployedStack = stackResponse.stack;
|
|
68
80
|
}
|
|
69
81
|
}
|
|
@@ -12,12 +12,4 @@ export default class AddCommand extends Command {
|
|
|
12
12
|
javascript: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
13
13
|
};
|
|
14
14
|
run(): Promise<void>;
|
|
15
|
-
promptForFunctionName(): Promise<string>;
|
|
16
|
-
promptForFunctionType(): Promise<string>;
|
|
17
|
-
promptForFunctionLang(): Promise<string>;
|
|
18
|
-
addFunction({ name, type, lang, }: {
|
|
19
|
-
name?: string;
|
|
20
|
-
type?: string;
|
|
21
|
-
lang?: string;
|
|
22
|
-
}): Promise<void>;
|
|
23
15
|
}
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import { cwd } from 'node:process';
|
|
2
1
|
import { Args, Command, Flags } from '@oclif/core';
|
|
3
|
-
import
|
|
4
|
-
import highlight from 'color-json';
|
|
5
|
-
import inquirer from 'inquirer';
|
|
6
|
-
import { findBlueprintFile } from '../../actions/blueprints/blueprint.js';
|
|
7
|
-
import { createFunctionResource } from '../../actions/blueprints/resources.js';
|
|
8
|
-
import { validateFunctionName } from '../../utils/validate/resource.js';
|
|
2
|
+
import { blueprintAddCore } from '../../cores/blueprints/index.js';
|
|
9
3
|
export default class AddCommand extends Command {
|
|
10
|
-
static description = 'Add a
|
|
4
|
+
static description = 'Add a Resource to a Blueprint';
|
|
11
5
|
static examples = [
|
|
12
6
|
'<%= config.bin %> <%= command.id %> function',
|
|
13
7
|
'<%= config.bin %> <%= command.id %> function --name my-function',
|
|
@@ -23,18 +17,18 @@ export default class AddCommand extends Command {
|
|
|
23
17
|
};
|
|
24
18
|
static flags = {
|
|
25
19
|
name: Flags.string({
|
|
26
|
-
description: 'Name of the
|
|
20
|
+
description: 'Name of the Resource to add',
|
|
27
21
|
char: 'n',
|
|
28
22
|
}),
|
|
29
23
|
'fn-type': Flags.string({
|
|
30
|
-
description: 'Type of new
|
|
24
|
+
description: 'Type of new Function',
|
|
31
25
|
options: ['document-publish' /*, 'document-create', 'document-delete'*/],
|
|
32
26
|
aliases: ['function-type'],
|
|
33
27
|
// default: 'document-publish', // prompting informs user of default
|
|
34
28
|
dependsOn: ['name'],
|
|
35
29
|
}),
|
|
36
30
|
language: Flags.string({
|
|
37
|
-
description: 'Language of the new
|
|
31
|
+
description: 'Language of the new Function',
|
|
38
32
|
aliases: ['function-language', 'lang'],
|
|
39
33
|
options: ['ts', 'js'],
|
|
40
34
|
default: 'ts',
|
|
@@ -46,88 +40,13 @@ export default class AddCommand extends Command {
|
|
|
46
40
|
};
|
|
47
41
|
async run() {
|
|
48
42
|
const { args, flags } = await this.parse(AddCommand);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
const { name: resourceName, 'fn-type': functionType, javascript } = flags;
|
|
56
|
-
let { language: functionLang } = flags;
|
|
57
|
-
if (javascript)
|
|
58
|
-
functionLang = 'js';
|
|
59
|
-
await this.addFunction({ name: resourceName, type: functionType, lang: functionLang });
|
|
60
|
-
}
|
|
61
|
-
async promptForFunctionName() {
|
|
62
|
-
const { functionName } = await inquirer.prompt([
|
|
63
|
-
{
|
|
64
|
-
type: 'input',
|
|
65
|
-
name: 'functionName',
|
|
66
|
-
message: 'Enter function name:',
|
|
67
|
-
validate: (input) => input.length > 0 || 'Function name is required',
|
|
68
|
-
},
|
|
69
|
-
]);
|
|
70
|
-
return functionName;
|
|
71
|
-
}
|
|
72
|
-
async promptForFunctionType() {
|
|
73
|
-
const { functionType } = await inquirer.prompt([
|
|
74
|
-
{
|
|
75
|
-
type: 'list',
|
|
76
|
-
name: 'functionType',
|
|
77
|
-
message: 'Choose function type:',
|
|
78
|
-
choices: [
|
|
79
|
-
{ name: 'Document Publish', value: 'document-publish' },
|
|
80
|
-
{ name: 'Document Create', value: 'document-create', disabled: true },
|
|
81
|
-
{ name: 'Document Delete', value: 'document-delete', disabled: true },
|
|
82
|
-
],
|
|
83
|
-
default: 'document-publish',
|
|
84
|
-
},
|
|
85
|
-
]);
|
|
86
|
-
return functionType;
|
|
87
|
-
}
|
|
88
|
-
async promptForFunctionLang() {
|
|
89
|
-
const { functionLang } = await inquirer.prompt([
|
|
90
|
-
{
|
|
91
|
-
type: 'list',
|
|
92
|
-
name: 'functionLang',
|
|
93
|
-
message: 'Choose function language:',
|
|
94
|
-
choices: [
|
|
95
|
-
{ name: 'TypeScript', value: 'ts' },
|
|
96
|
-
{ name: 'JavaScript', value: 'js' },
|
|
97
|
-
],
|
|
98
|
-
default: 'ts',
|
|
99
|
-
},
|
|
100
|
-
]);
|
|
101
|
-
return functionLang;
|
|
102
|
-
}
|
|
103
|
-
async addFunction({ name, type, lang, }) {
|
|
104
|
-
const functionName = name || (await this.promptForFunctionName());
|
|
105
|
-
if (!validateFunctionName(functionName)) {
|
|
106
|
-
this.error('Invalid function name. Must be 6+ characters, no special characters, no spaces');
|
|
107
|
-
}
|
|
108
|
-
const functionType = type || (await this.promptForFunctionType());
|
|
109
|
-
const functionLang = lang || (await this.promptForFunctionLang());
|
|
110
|
-
if (!['document-publish', 'document-create', 'document-delete'].includes(functionType)) {
|
|
111
|
-
this.error('Invalid function type. Must be one of: document-publish, document-create, document-delete');
|
|
112
|
-
}
|
|
113
|
-
const { filePath, resourceAdded, resource } = createFunctionResource({
|
|
114
|
-
name: functionName,
|
|
115
|
-
type: functionType,
|
|
116
|
-
lang: functionLang,
|
|
117
|
-
displayName: functionName,
|
|
43
|
+
const { success, error } = await blueprintAddCore({
|
|
44
|
+
bin: this.config.bin,
|
|
45
|
+
log: (msg) => this.log(msg),
|
|
46
|
+
args,
|
|
47
|
+
flags,
|
|
118
48
|
});
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
this.log(chalk.dim('To avoid committing build artifacts, it is helpful to .gitignore "functions/**/.build/**"'));
|
|
122
|
-
}
|
|
123
|
-
if (!resourceAdded) {
|
|
124
|
-
// print the resource JSON for manual addition
|
|
125
|
-
this.log('\nAdd this Function resource to your blueprint:');
|
|
126
|
-
this.log(highlight(JSON.stringify(resource, null, 2)));
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
// added to blueprint.json
|
|
130
|
-
this.log('Function resource added to blueprint');
|
|
131
|
-
}
|
|
49
|
+
if (!success)
|
|
50
|
+
this.error(error);
|
|
132
51
|
}
|
|
133
52
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class ConfigCommand extends
|
|
1
|
+
import { BlueprintCommand } from '../../baseCommands.js';
|
|
2
|
+
export default class ConfigCommand extends BlueprintCommand<typeof ConfigCommand> {
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
@@ -8,27 +8,5 @@ export default class ConfigCommand extends Command {
|
|
|
8
8
|
'project-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
9
|
'stack-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
10
|
};
|
|
11
|
-
sanityToken: string | undefined;
|
|
12
|
-
projectId: string | undefined;
|
|
13
|
-
stackId: string | undefined;
|
|
14
11
|
run(): Promise<void>;
|
|
15
|
-
promptForProjectId({ knownProjectId }: {
|
|
16
|
-
knownProjectId?: string;
|
|
17
|
-
}): Promise<string>;
|
|
18
|
-
promptForStackId({ projectId, knownStackId, }: {
|
|
19
|
-
projectId: string;
|
|
20
|
-
knownStackId?: string;
|
|
21
|
-
}): Promise<string | undefined>;
|
|
22
|
-
testConfigAndReport({ stackId, projectId, reinit, }: {
|
|
23
|
-
stackId: string;
|
|
24
|
-
projectId: string;
|
|
25
|
-
reinit?: boolean;
|
|
26
|
-
}): Promise<{
|
|
27
|
-
ok: boolean;
|
|
28
|
-
error: string | null;
|
|
29
|
-
}>;
|
|
30
|
-
startReinitializeStack({ projectId, stackId }: {
|
|
31
|
-
projectId: string;
|
|
32
|
-
stackId: string;
|
|
33
|
-
}): Promise<void>;
|
|
34
12
|
}
|