@sanity/runtime-cli 11.2.0 → 12.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.
- package/README.md +36 -38
- package/dist/actions/blueprints/blueprint.d.ts +3 -0
- package/dist/actions/blueprints/blueprint.js +26 -14
- package/dist/actions/blueprints/config.d.ts +34 -3
- package/dist/actions/blueprints/config.js +67 -14
- package/dist/actions/blueprints/stacks.d.ts +1 -2
- package/dist/actions/blueprints/stacks.js +2 -3
- package/dist/commands/blueprints/config.d.ts +0 -1
- package/dist/commands/blueprints/config.js +4 -12
- package/dist/commands/blueprints/deploy.js +1 -1
- package/dist/commands/blueprints/destroy.js +3 -3
- package/dist/commands/blueprints/info.js +2 -2
- package/dist/commands/blueprints/init.d.ts +1 -0
- package/dist/commands/blueprints/init.js +4 -0
- package/dist/commands/blueprints/logs.js +2 -2
- package/dist/commands/blueprints/plan.js +1 -0
- package/dist/config.d.ts +2 -1
- package/dist/config.js +8 -1
- package/dist/cores/blueprints/config.d.ts +1 -1
- package/dist/cores/blueprints/config.js +92 -78
- package/dist/cores/blueprints/deploy.js +8 -8
- package/dist/cores/blueprints/destroy.d.ts +1 -0
- package/dist/cores/blueprints/destroy.js +22 -26
- package/dist/cores/blueprints/doctor.js +24 -72
- package/dist/cores/blueprints/info.d.ts +1 -0
- package/dist/cores/blueprints/info.js +5 -4
- package/dist/cores/blueprints/init.d.ts +1 -1
- package/dist/cores/blueprints/init.js +50 -78
- package/dist/cores/blueprints/logs.d.ts +1 -0
- package/dist/cores/blueprints/logs.js +7 -7
- package/dist/cores/blueprints/plan.d.ts +3 -0
- package/dist/cores/blueprints/plan.js +5 -4
- package/dist/cores/blueprints/stacks.d.ts +1 -0
- package/dist/cores/blueprints/stacks.js +1 -2
- package/dist/cores/functions/add.js +58 -70
- package/dist/cores/functions/logs.js +2 -4
- package/dist/cores/index.js +3 -3
- package/dist/server/static/vendor/vendor.bundle.js +515 -234
- package/dist/utils/display/blueprints-formatting.js +8 -3
- package/dist/utils/display/errors.js +2 -2
- package/dist/utils/display/presenters.d.ts +2 -0
- package/dist/utils/display/presenters.js +7 -0
- package/dist/utils/display/prompt.d.ts +14 -2
- package/dist/utils/display/prompt.js +60 -41
- package/dist/utils/types.d.ts +0 -1
- package/oclif.manifest.json +19 -26
- package/package.json +6 -5
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
2
|
import { dirname, join } from 'node:path';
|
|
3
3
|
import { cwd } from 'node:process';
|
|
4
|
+
import { checkbox, confirm, input, select } from '@inquirer/prompts';
|
|
4
5
|
import { highlight } from 'cardinal';
|
|
5
6
|
import chalk from 'chalk';
|
|
6
|
-
import inquirer from 'inquirer';
|
|
7
7
|
import { createFunctionResource } from '../../actions/blueprints/resources.js';
|
|
8
8
|
import { verifyExampleExists, writeExample } from '../../actions/sanity/examples.js';
|
|
9
9
|
import { check, indent, warn } from '../../utils/display/presenters.js';
|
|
@@ -198,86 +198,74 @@ export async function functionAddCore(options) {
|
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
async function promptForFunctionName() {
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
name
|
|
205
|
-
|
|
206
|
-
validate: (input) => validateFunctionName(input) ||
|
|
207
|
-
'Invalid function name. Must be 6+ characters, no special characters, no spaces',
|
|
208
|
-
},
|
|
209
|
-
]);
|
|
201
|
+
const functionName = await input({
|
|
202
|
+
message: 'Enter function name:',
|
|
203
|
+
validate: (input) => validateFunctionName(input) ||
|
|
204
|
+
'Invalid function name. Must be 6+ characters, no special characters, no spaces',
|
|
205
|
+
});
|
|
210
206
|
return functionName;
|
|
211
207
|
}
|
|
212
208
|
async function promptForFunctionType() {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
},
|
|
209
|
+
function hasAtLeastOne(arr) {
|
|
210
|
+
// TypeScript believes me when I make a funciton to "guard" the type
|
|
211
|
+
return arr.length > 0;
|
|
212
|
+
}
|
|
213
|
+
const functionTypes = await checkbox({
|
|
214
|
+
message: 'Choose events to trigger your function:',
|
|
215
|
+
choices: [
|
|
216
|
+
{ name: 'Document Create', value: 'document-create', checked: true },
|
|
217
|
+
{ name: 'Document Update', value: 'document-update', checked: true },
|
|
218
|
+
{ name: 'Document Delete', value: 'document-delete' },
|
|
219
|
+
{ name: 'Media Library Asset Create', value: 'media-library-asset-create' },
|
|
220
|
+
{ name: 'Media Library Asset Update', value: 'media-library-asset-update' },
|
|
221
|
+
{ name: 'Media Library Asset Delete', value: 'media-library-asset-delete' },
|
|
222
|
+
],
|
|
223
|
+
validate(choices) {
|
|
224
|
+
if (choices.length === 0) {
|
|
225
|
+
return 'You must choose at least one function type / document change event';
|
|
226
|
+
}
|
|
227
|
+
if (choices.some((c) => String(c.value).startsWith('media-library')) &&
|
|
228
|
+
choices.some((c) => String(c.value).startsWith('document'))) {
|
|
229
|
+
return 'You cannot mix both Document and Media Library Asset events together in one Function';
|
|
230
|
+
}
|
|
231
|
+
return true;
|
|
237
232
|
},
|
|
238
|
-
|
|
239
|
-
|
|
233
|
+
});
|
|
234
|
+
// checking functionTypes.length > 0 doesn't narrow the type
|
|
235
|
+
// validate should prevent this from happening, but just in case
|
|
236
|
+
if (!hasAtLeastOne(functionTypes)) {
|
|
237
|
+
throw new Error('You must choose at least one function type / document change event');
|
|
238
|
+
}
|
|
239
|
+
return functionTypes;
|
|
240
240
|
}
|
|
241
241
|
async function promptForFunctionLang() {
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
name: '
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
],
|
|
251
|
-
default: 'ts',
|
|
252
|
-
},
|
|
253
|
-
]);
|
|
242
|
+
const functionLang = await select({
|
|
243
|
+
message: 'Choose function language:',
|
|
244
|
+
choices: [
|
|
245
|
+
{ name: 'TypeScript', value: 'ts' },
|
|
246
|
+
{ name: 'JavaScript', value: 'js' },
|
|
247
|
+
],
|
|
248
|
+
default: 'ts',
|
|
249
|
+
});
|
|
254
250
|
return functionLang;
|
|
255
251
|
}
|
|
256
252
|
async function promptForAddHelpers() {
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
message: 'Add @sanity/functions helpers to the new Function?',
|
|
262
|
-
default: true,
|
|
263
|
-
},
|
|
264
|
-
]);
|
|
253
|
+
const addHelpers = await confirm({
|
|
254
|
+
message: 'Add @sanity/functions helpers to the new Function?',
|
|
255
|
+
default: true,
|
|
256
|
+
});
|
|
265
257
|
return addHelpers;
|
|
266
258
|
}
|
|
267
259
|
async function promptForInstallCommand() {
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
name: '
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
],
|
|
279
|
-
default: 'npm',
|
|
280
|
-
},
|
|
281
|
-
]);
|
|
260
|
+
const command = await select({
|
|
261
|
+
message: 'How to install the @sanity/functions helpers:',
|
|
262
|
+
choices: [
|
|
263
|
+
{ name: 'npm', value: 'npm' },
|
|
264
|
+
{ name: 'pnpm', value: 'pnpm' },
|
|
265
|
+
{ name: 'yarn', value: 'yarn' },
|
|
266
|
+
{ name: 'Skip install', value: null },
|
|
267
|
+
],
|
|
268
|
+
default: 'npm',
|
|
269
|
+
});
|
|
282
270
|
return command;
|
|
283
271
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { confirm } from '@inquirer/prompts';
|
|
1
2
|
import chalk from 'chalk';
|
|
2
|
-
import inquirer from 'inquirer';
|
|
3
3
|
import ora from 'ora';
|
|
4
4
|
import { deleteLogs as deleteLogsAction, logs as getLogsAction, streamLogs as streamLogsAction, } from '../../actions/functions/logs.js';
|
|
5
5
|
import { formatTitle } from '../../utils/display/blueprints-formatting.js';
|
|
@@ -18,9 +18,7 @@ export async function functionLogsCore(options) {
|
|
|
18
18
|
}
|
|
19
19
|
async function deleteLogs({ name, externalId, auth, force, }) {
|
|
20
20
|
if (!force) {
|
|
21
|
-
const
|
|
22
|
-
type: 'confirm',
|
|
23
|
-
name: 'certain',
|
|
21
|
+
const certain = await confirm({
|
|
24
22
|
message: `Are you sure you want to delete ${chalk.bold('all')} logs for function ${chalk.yellow(name)}?`,
|
|
25
23
|
default: false,
|
|
26
24
|
});
|
package/dist/cores/index.js
CHANGED
|
@@ -46,14 +46,14 @@ export async function initDeployedBlueprintConfig(config) {
|
|
|
46
46
|
if (!scopeType || !scopeId)
|
|
47
47
|
return { ok: false, error: 'Missing scope configuration for Blueprint' };
|
|
48
48
|
if (!stackId)
|
|
49
|
-
return { ok: false, error: 'Missing deployment configuration for Blueprint' };
|
|
49
|
+
return { ok: false, error: 'Missing Stack deployment configuration for Blueprint' };
|
|
50
50
|
}
|
|
51
51
|
const auth = { token: config.token, scopeType, scopeId };
|
|
52
52
|
const stackResponse = await getStack({ stackId, auth });
|
|
53
53
|
if (!stackResponse.ok) {
|
|
54
|
-
config.log(`Could not retrieve deployment info for ${niceId(stackId)}.`);
|
|
54
|
+
config.log(`Could not retrieve Stack deployment info for ${niceId(stackId)}.`);
|
|
55
55
|
config.log(`Run \`${config.bin} blueprints doctor\` for diagnostics.`);
|
|
56
|
-
return { ok: false, error: 'Missing deployment' };
|
|
56
|
+
return { ok: false, error: 'Missing Stack deployment' };
|
|
57
57
|
}
|
|
58
58
|
return {
|
|
59
59
|
ok: true,
|