@sanity/runtime-cli 3.1.0 → 3.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 +39 -15
- package/dist/actions/blueprints/stacks.d.ts +9 -0
- package/dist/actions/blueprints/stacks.js +12 -0
- package/dist/commands/blueprints/destroy.d.ts +10 -0
- package/dist/commands/blueprints/destroy.js +85 -0
- package/dist/utils/display/colors.d.ts +1 -0
- package/dist/utils/display/colors.js +5 -0
- package/oclif.manifest.json +41 -1
- package/package.json +3 -3
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/3.
|
|
23
|
+
@sanity/runtime-cli/3.2.0 linux-x64 node-v22.14.0
|
|
24
24
|
$ sanity-run --help [COMMAND]
|
|
25
25
|
USAGE
|
|
26
26
|
$ sanity-run COMMAND
|
|
@@ -32,6 +32,7 @@ USAGE
|
|
|
32
32
|
* [`sanity-run blueprints add TYPE`](#sanity-run-blueprints-add-type)
|
|
33
33
|
* [`sanity-run blueprints config`](#sanity-run-blueprints-config)
|
|
34
34
|
* [`sanity-run blueprints deploy`](#sanity-run-blueprints-deploy)
|
|
35
|
+
* [`sanity-run blueprints destroy`](#sanity-run-blueprints-destroy)
|
|
35
36
|
* [`sanity-run blueprints info`](#sanity-run-blueprints-info)
|
|
36
37
|
* [`sanity-run blueprints init`](#sanity-run-blueprints-init)
|
|
37
38
|
* [`sanity-run blueprints logs`](#sanity-run-blueprints-logs)
|
|
@@ -63,7 +64,7 @@ EXAMPLES
|
|
|
63
64
|
$ sanity-run blueprints add function
|
|
64
65
|
```
|
|
65
66
|
|
|
66
|
-
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v3.
|
|
67
|
+
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v3.2.0/src/commands/blueprints/add.ts)_
|
|
67
68
|
|
|
68
69
|
## `sanity-run blueprints config`
|
|
69
70
|
|
|
@@ -85,7 +86,7 @@ EXAMPLES
|
|
|
85
86
|
$ sanity-run blueprints config --edit
|
|
86
87
|
```
|
|
87
88
|
|
|
88
|
-
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v3.
|
|
89
|
+
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v3.2.0/src/commands/blueprints/config.ts)_
|
|
89
90
|
|
|
90
91
|
## `sanity-run blueprints deploy`
|
|
91
92
|
|
|
@@ -102,7 +103,30 @@ EXAMPLES
|
|
|
102
103
|
$ sanity-run blueprints deploy
|
|
103
104
|
```
|
|
104
105
|
|
|
105
|
-
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v3.
|
|
106
|
+
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v3.2.0/src/commands/blueprints/deploy.ts)_
|
|
107
|
+
|
|
108
|
+
## `sanity-run blueprints destroy`
|
|
109
|
+
|
|
110
|
+
Destroy a deployed Blueprint Stack
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
USAGE
|
|
114
|
+
$ sanity-run blueprints destroy [--id <value>] [--force]
|
|
115
|
+
|
|
116
|
+
FLAGS
|
|
117
|
+
--force Force destroy (skip confirmation)
|
|
118
|
+
--id=<value> Stack ID to destroy (defaults to current Stack)
|
|
119
|
+
|
|
120
|
+
DESCRIPTION
|
|
121
|
+
Destroy a deployed Blueprint Stack
|
|
122
|
+
|
|
123
|
+
EXAMPLES
|
|
124
|
+
$ sanity-run blueprints destroy
|
|
125
|
+
|
|
126
|
+
$ sanity-run blueprints destroy --id ST-a1b2c3
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v3.2.0/src/commands/blueprints/destroy.ts)_
|
|
106
130
|
|
|
107
131
|
## `sanity-run blueprints info`
|
|
108
132
|
|
|
@@ -124,7 +148,7 @@ EXAMPLES
|
|
|
124
148
|
$ sanity-run blueprints info --id abc123
|
|
125
149
|
```
|
|
126
150
|
|
|
127
|
-
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v3.
|
|
151
|
+
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v3.2.0/src/commands/blueprints/info.ts)_
|
|
128
152
|
|
|
129
153
|
## `sanity-run blueprints init`
|
|
130
154
|
|
|
@@ -141,7 +165,7 @@ EXAMPLES
|
|
|
141
165
|
$ sanity-run blueprints init
|
|
142
166
|
```
|
|
143
167
|
|
|
144
|
-
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v3.
|
|
168
|
+
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v3.2.0/src/commands/blueprints/init.ts)_
|
|
145
169
|
|
|
146
170
|
## `sanity-run blueprints logs`
|
|
147
171
|
|
|
@@ -163,7 +187,7 @@ EXAMPLES
|
|
|
163
187
|
$ sanity-run blueprints logs --watch
|
|
164
188
|
```
|
|
165
189
|
|
|
166
|
-
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v3.
|
|
190
|
+
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v3.2.0/src/commands/blueprints/logs.ts)_
|
|
167
191
|
|
|
168
192
|
## `sanity-run blueprints plan`
|
|
169
193
|
|
|
@@ -180,7 +204,7 @@ EXAMPLES
|
|
|
180
204
|
$ sanity-run blueprints plan
|
|
181
205
|
```
|
|
182
206
|
|
|
183
|
-
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v3.
|
|
207
|
+
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v3.2.0/src/commands/blueprints/plan.ts)_
|
|
184
208
|
|
|
185
209
|
## `sanity-run blueprints stacks`
|
|
186
210
|
|
|
@@ -197,7 +221,7 @@ EXAMPLES
|
|
|
197
221
|
$ sanity-run blueprints stacks
|
|
198
222
|
```
|
|
199
223
|
|
|
200
|
-
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v3.
|
|
224
|
+
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v3.2.0/src/commands/blueprints/stacks.ts)_
|
|
201
225
|
|
|
202
226
|
## `sanity-run functions dev`
|
|
203
227
|
|
|
@@ -217,7 +241,7 @@ EXAMPLES
|
|
|
217
241
|
$ sanity-run functions dev --port 8974
|
|
218
242
|
```
|
|
219
243
|
|
|
220
|
-
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v3.
|
|
244
|
+
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v3.2.0/src/commands/functions/dev.ts)_
|
|
221
245
|
|
|
222
246
|
## `sanity-run functions env add NAME KEY VALUE`
|
|
223
247
|
|
|
@@ -239,7 +263,7 @@ EXAMPLES
|
|
|
239
263
|
$ sanity-run functions env add MyFunction API_URL https://api.example.com/
|
|
240
264
|
```
|
|
241
265
|
|
|
242
|
-
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v3.
|
|
266
|
+
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v3.2.0/src/commands/functions/env/add.ts)_
|
|
243
267
|
|
|
244
268
|
## `sanity-run functions env remove NAME KEY`
|
|
245
269
|
|
|
@@ -260,7 +284,7 @@ EXAMPLES
|
|
|
260
284
|
$ sanity-run functions env remove MyFunction API_URL
|
|
261
285
|
```
|
|
262
286
|
|
|
263
|
-
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v3.
|
|
287
|
+
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v3.2.0/src/commands/functions/env/remove.ts)_
|
|
264
288
|
|
|
265
289
|
## `sanity-run functions invoke NAME`
|
|
266
290
|
|
|
@@ -286,7 +310,7 @@ EXAMPLES
|
|
|
286
310
|
$ sanity-run functions invoke <name> --file 'payload.json'
|
|
287
311
|
```
|
|
288
312
|
|
|
289
|
-
_See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v3.
|
|
313
|
+
_See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v3.2.0/src/commands/functions/invoke.ts)_
|
|
290
314
|
|
|
291
315
|
## `sanity-run functions logs NAME`
|
|
292
316
|
|
|
@@ -318,7 +342,7 @@ EXAMPLES
|
|
|
318
342
|
$ sanity-run functions logs <name> --delete
|
|
319
343
|
```
|
|
320
344
|
|
|
321
|
-
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v3.
|
|
345
|
+
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v3.2.0/src/commands/functions/logs.ts)_
|
|
322
346
|
|
|
323
347
|
## `sanity-run functions test NAME`
|
|
324
348
|
|
|
@@ -351,7 +375,7 @@ EXAMPLES
|
|
|
351
375
|
$ sanity-run functions test <name> --data '{ "id": 1 }' --timeout 60
|
|
352
376
|
```
|
|
353
377
|
|
|
354
|
-
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v3.
|
|
378
|
+
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v3.2.0/src/commands/functions/test.ts)_
|
|
355
379
|
|
|
356
380
|
## `sanity-run help [COMMAND]`
|
|
357
381
|
|
|
@@ -46,4 +46,13 @@ export declare function updateStack({ stackId, stackPayload, auth, }: {
|
|
|
46
46
|
stackPayload: StackPayload;
|
|
47
47
|
auth: AuthParams;
|
|
48
48
|
}): Promise<UpdateStackResponse>;
|
|
49
|
+
interface DestroyStackResponse {
|
|
50
|
+
ok: boolean;
|
|
51
|
+
error: string | null;
|
|
52
|
+
stack: Stack;
|
|
53
|
+
}
|
|
54
|
+
export declare function destroyStack({ stackId, auth, }: {
|
|
55
|
+
stackId: string;
|
|
56
|
+
auth: AuthParams;
|
|
57
|
+
}): Promise<DestroyStackResponse>;
|
|
49
58
|
export {};
|
|
@@ -81,3 +81,15 @@ export async function updateStack({ stackId, stackPayload, auth, }) {
|
|
|
81
81
|
stack,
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
|
+
export async function destroyStack({ stackId, auth, }) {
|
|
85
|
+
const response = await fetch(`${stacksUrl}/${stackId}`, {
|
|
86
|
+
method: 'DELETE',
|
|
87
|
+
headers: getHeaders(auth),
|
|
88
|
+
});
|
|
89
|
+
const stack = await response.json();
|
|
90
|
+
return {
|
|
91
|
+
ok: response.ok,
|
|
92
|
+
error: response.ok ? null : stack.message,
|
|
93
|
+
stack,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class Destroy extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
id: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
8
|
+
};
|
|
9
|
+
run(): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { setTimeout } from 'node:timers/promises';
|
|
2
|
+
import { Command, Flags } from '@oclif/core';
|
|
3
|
+
import inquirer from 'inquirer';
|
|
4
|
+
import Spinner from 'yocto-spinner';
|
|
5
|
+
import { readBlueprintOnDisk } from '../../actions/blueprints/blueprint.js';
|
|
6
|
+
import { destroyStack, getStack } from '../../actions/blueprints/stacks.js';
|
|
7
|
+
import config from '../../config.js';
|
|
8
|
+
import { bold, niceId } from '../../utils/display/colors.js';
|
|
9
|
+
const { token } = config;
|
|
10
|
+
export default class Destroy extends Command {
|
|
11
|
+
static description = 'Destroy a deployed Blueprint Stack';
|
|
12
|
+
static examples = [
|
|
13
|
+
'<%= config.bin %> <%= command.id %>',
|
|
14
|
+
'<%= config.bin %> <%= command.id %> --id ST-a1b2c3',
|
|
15
|
+
];
|
|
16
|
+
static flags = {
|
|
17
|
+
id: Flags.string({
|
|
18
|
+
description: 'Stack ID to destroy (defaults to current Stack)',
|
|
19
|
+
required: false,
|
|
20
|
+
}),
|
|
21
|
+
force: Flags.boolean({
|
|
22
|
+
description: 'Force destroy (skip confirmation)',
|
|
23
|
+
default: false,
|
|
24
|
+
}),
|
|
25
|
+
};
|
|
26
|
+
async run() {
|
|
27
|
+
const { flags } = await this.parse(Destroy);
|
|
28
|
+
const { errors, deployedStack, projectId } = await readBlueprintOnDisk({ getStack: true, token });
|
|
29
|
+
if (errors.length > 0) {
|
|
30
|
+
// printErrors(errors)
|
|
31
|
+
this.warn('Blueprint parse errors:');
|
|
32
|
+
console.dir(errors, { depth: null });
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (!projectId)
|
|
36
|
+
this.error('Project resource not found in blueprint');
|
|
37
|
+
const auth = { token, projectId };
|
|
38
|
+
let stack = deployedStack;
|
|
39
|
+
if (flags.id) {
|
|
40
|
+
const { ok, stack: foundStack, error } = await getStack({ stackId: flags.id, auth });
|
|
41
|
+
if (!ok)
|
|
42
|
+
this.error(error || 'Failed to get stack');
|
|
43
|
+
stack = foundStack;
|
|
44
|
+
}
|
|
45
|
+
else if (!stack) {
|
|
46
|
+
this.error('No stack found');
|
|
47
|
+
}
|
|
48
|
+
if (!stack)
|
|
49
|
+
this.error('Stack not found. Is it deployed?');
|
|
50
|
+
const destroySpinner = Spinner({
|
|
51
|
+
text: `Destroying ${bold(stack.name)} ${niceId(stack.id)}...`,
|
|
52
|
+
color: 'red',
|
|
53
|
+
});
|
|
54
|
+
if (!flags.force) {
|
|
55
|
+
const { confirm } = await inquirer.prompt([
|
|
56
|
+
{
|
|
57
|
+
type: 'confirm',
|
|
58
|
+
name: 'confirm',
|
|
59
|
+
message: `Are you sure you want to destroy stack "${stack.name}" ${niceId(stack.id)}?`,
|
|
60
|
+
default: false,
|
|
61
|
+
},
|
|
62
|
+
]);
|
|
63
|
+
if (!confirm) {
|
|
64
|
+
this.log('Stack destruction cancelled');
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
destroySpinner.start();
|
|
68
|
+
let i = 5;
|
|
69
|
+
while (i >= 0) {
|
|
70
|
+
destroySpinner.text = `Destroying stack in ${bold((i--).toString())} seconds...`;
|
|
71
|
+
await setTimeout(1000);
|
|
72
|
+
}
|
|
73
|
+
destroySpinner.text = 'Destroying stack 💥';
|
|
74
|
+
await setTimeout(500);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
destroySpinner.start();
|
|
78
|
+
}
|
|
79
|
+
const { ok, error } = await destroyStack({ stackId: stack.id, auth });
|
|
80
|
+
if (!ok)
|
|
81
|
+
this.error(error || 'Failed to destroy stack');
|
|
82
|
+
// TODO: update local config
|
|
83
|
+
destroySpinner.success(`Stack "${stack.name}" ${niceId(stack.id)} destroyed`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -5,3 +5,4 @@ export declare function green(str: string): string;
|
|
|
5
5
|
export declare function red(str: string): string;
|
|
6
6
|
export declare function yellow(str: string): string;
|
|
7
7
|
export declare function boldnblue(str: string): string;
|
|
8
|
+
export declare function niceId(id: string | undefined): string;
|
package/oclif.manifest.json
CHANGED
|
@@ -89,6 +89,46 @@
|
|
|
89
89
|
"deploy.js"
|
|
90
90
|
]
|
|
91
91
|
},
|
|
92
|
+
"blueprints:destroy": {
|
|
93
|
+
"aliases": [],
|
|
94
|
+
"args": {},
|
|
95
|
+
"description": "Destroy a deployed Blueprint Stack",
|
|
96
|
+
"examples": [
|
|
97
|
+
"<%= config.bin %> <%= command.id %>",
|
|
98
|
+
"<%= config.bin %> <%= command.id %> --id ST-a1b2c3"
|
|
99
|
+
],
|
|
100
|
+
"flags": {
|
|
101
|
+
"id": {
|
|
102
|
+
"description": "Stack ID to destroy (defaults to current Stack)",
|
|
103
|
+
"name": "id",
|
|
104
|
+
"required": false,
|
|
105
|
+
"hasDynamicHelp": false,
|
|
106
|
+
"multiple": false,
|
|
107
|
+
"type": "option"
|
|
108
|
+
},
|
|
109
|
+
"force": {
|
|
110
|
+
"description": "Force destroy (skip confirmation)",
|
|
111
|
+
"name": "force",
|
|
112
|
+
"allowNo": false,
|
|
113
|
+
"type": "boolean"
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
"hasDynamicHelp": false,
|
|
117
|
+
"hiddenAliases": [],
|
|
118
|
+
"id": "blueprints:destroy",
|
|
119
|
+
"pluginAlias": "@sanity/runtime-cli",
|
|
120
|
+
"pluginName": "@sanity/runtime-cli",
|
|
121
|
+
"pluginType": "core",
|
|
122
|
+
"strict": true,
|
|
123
|
+
"enableJsonFlag": false,
|
|
124
|
+
"isESM": true,
|
|
125
|
+
"relativePath": [
|
|
126
|
+
"dist",
|
|
127
|
+
"commands",
|
|
128
|
+
"blueprints",
|
|
129
|
+
"destroy.js"
|
|
130
|
+
]
|
|
131
|
+
},
|
|
92
132
|
"blueprints:info": {
|
|
93
133
|
"aliases": [],
|
|
94
134
|
"args": {},
|
|
@@ -551,5 +591,5 @@
|
|
|
551
591
|
]
|
|
552
592
|
}
|
|
553
593
|
},
|
|
554
|
-
"version": "3.
|
|
594
|
+
"version": "3.2.0"
|
|
555
595
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/runtime-cli",
|
|
3
3
|
"description": "Sanity's Runtime CLI for Blueprints and Functions",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.2.0",
|
|
5
5
|
"author": "Sanity Runtime Team",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
@@ -84,10 +84,10 @@
|
|
|
84
84
|
"@types/node": "18",
|
|
85
85
|
"codemirror": "^6.0.1",
|
|
86
86
|
"mentoss": "^0.9.2",
|
|
87
|
-
"oclif": "^4.17.
|
|
87
|
+
"oclif": "^4.17.44",
|
|
88
88
|
"pretty-bytes": "^6.1.1",
|
|
89
89
|
"pretty-ms": "^9.2.0",
|
|
90
|
-
"rollup": "^4.
|
|
90
|
+
"rollup": "^4.40.0",
|
|
91
91
|
"shx": "^0.4.0",
|
|
92
92
|
"ts-node": "^10.9.2",
|
|
93
93
|
"tsx": "^4.19.3",
|