@sanity/runtime-cli 17.13.0 → 17.13.1-next.g09af4b8
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 +21 -21
- package/dist/actions/blueprints/pre-deploy.js +3 -3
- package/dist/commands/functions/dev.js +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/server/app.d.ts +2 -1
- package/dist/server/app.js +4 -1
- package/dist/server/static/web-socket.js +4 -2
- package/dist/utils/applications/prepare-asset.d.ts +31 -0
- package/dist/utils/applications/prepare-asset.js +245 -0
- package/dist/utils/applications/types.d.ts +46 -0
- package/dist/utils/applications/types.js +1 -0
- package/dist/utils/display/blueprints-formatting.js +5 -1
- package/oclif.manifest.json +2 -2
- package/package.json +1 -1
- package/skills/functions-dev.md +1 -1
- package/dist/utils/studios/prepare-asset.d.ts +0 -6
- package/dist/utils/studios/prepare-asset.js +0 -166
package/README.md
CHANGED
|
@@ -90,7 +90,7 @@ EXAMPLES
|
|
|
90
90
|
$ sanity-run blueprints add function --name my-function --fn-type document-create --fn-type document-update --lang js
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
-
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.
|
|
93
|
+
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.1-next.g09af4b8/src/commands/blueprints/add.ts)_
|
|
94
94
|
|
|
95
95
|
## `sanity-run blueprints config`
|
|
96
96
|
|
|
@@ -127,7 +127,7 @@ EXAMPLES
|
|
|
127
127
|
$ sanity-run blueprints config --edit --project-id <projectId> --stack <name-or-id>
|
|
128
128
|
```
|
|
129
129
|
|
|
130
|
-
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.
|
|
130
|
+
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.1-next.g09af4b8/src/commands/blueprints/config.ts)_
|
|
131
131
|
|
|
132
132
|
## `sanity-run blueprints deploy`
|
|
133
133
|
|
|
@@ -183,7 +183,7 @@ EXAMPLES
|
|
|
183
183
|
$ sanity-run blueprints deploy --new-stack-name <new-name>
|
|
184
184
|
```
|
|
185
185
|
|
|
186
|
-
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.
|
|
186
|
+
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.1-next.g09af4b8/src/commands/blueprints/deploy.ts)_
|
|
187
187
|
|
|
188
188
|
## `sanity-run blueprints destroy`
|
|
189
189
|
|
|
@@ -221,7 +221,7 @@ EXAMPLES
|
|
|
221
221
|
$ sanity-run blueprints destroy --stack <name-or-id> --project-id <projectId> --force --no-wait
|
|
222
222
|
```
|
|
223
223
|
|
|
224
|
-
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.
|
|
224
|
+
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.1-next.g09af4b8/src/commands/blueprints/destroy.ts)_
|
|
225
225
|
|
|
226
226
|
## `sanity-run blueprints doctor`
|
|
227
227
|
|
|
@@ -253,7 +253,7 @@ EXAMPLES
|
|
|
253
253
|
$ sanity-run blueprints doctor --fix
|
|
254
254
|
```
|
|
255
255
|
|
|
256
|
-
_See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.
|
|
256
|
+
_See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.1-next.g09af4b8/src/commands/blueprints/doctor.ts)_
|
|
257
257
|
|
|
258
258
|
## `sanity-run blueprints info`
|
|
259
259
|
|
|
@@ -291,7 +291,7 @@ EXAMPLES
|
|
|
291
291
|
$ sanity-run blueprints info --organization-id <orgId> --stack <name-or-id>
|
|
292
292
|
```
|
|
293
293
|
|
|
294
|
-
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.
|
|
294
|
+
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.1-next.g09af4b8/src/commands/blueprints/info.ts)_
|
|
295
295
|
|
|
296
296
|
## `sanity-run blueprints init [DIR]`
|
|
297
297
|
|
|
@@ -355,7 +355,7 @@ EXAMPLES
|
|
|
355
355
|
$ sanity-run blueprints init old-stack --type <json|js|ts> --project-id <projectId> --stack-id <existingStackId>
|
|
356
356
|
```
|
|
357
357
|
|
|
358
|
-
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.
|
|
358
|
+
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.1-next.g09af4b8/src/commands/blueprints/init.ts)_
|
|
359
359
|
|
|
360
360
|
## `sanity-run blueprints logs`
|
|
361
361
|
|
|
@@ -401,7 +401,7 @@ EXAMPLES
|
|
|
401
401
|
$ sanity-run blueprints logs --before 2026-05-01T00:00:00Z
|
|
402
402
|
```
|
|
403
403
|
|
|
404
|
-
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.
|
|
404
|
+
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.1-next.g09af4b8/src/commands/blueprints/logs.ts)_
|
|
405
405
|
|
|
406
406
|
## `sanity-run blueprints mint-deploy-token`
|
|
407
407
|
|
|
@@ -446,7 +446,7 @@ EXAMPLES
|
|
|
446
446
|
$ sanity-run blueprints mint-deploy-token --organization-id <orgId>
|
|
447
447
|
```
|
|
448
448
|
|
|
449
|
-
_See code: [src/commands/blueprints/mint-deploy-token.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.
|
|
449
|
+
_See code: [src/commands/blueprints/mint-deploy-token.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.1-next.g09af4b8/src/commands/blueprints/mint-deploy-token.ts)_
|
|
450
450
|
|
|
451
451
|
## `sanity-run blueprints plan`
|
|
452
452
|
|
|
@@ -479,7 +479,7 @@ EXAMPLES
|
|
|
479
479
|
$ sanity-run blueprints plan --organization-id <orgId> --stack <name-or-id>
|
|
480
480
|
```
|
|
481
481
|
|
|
482
|
-
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.
|
|
482
|
+
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.1-next.g09af4b8/src/commands/blueprints/plan.ts)_
|
|
483
483
|
|
|
484
484
|
## `sanity-run blueprints promote`
|
|
485
485
|
|
|
@@ -515,7 +515,7 @@ EXAMPLES
|
|
|
515
515
|
$ sanity-run blueprints promote --new-stack-name <new-name>
|
|
516
516
|
```
|
|
517
517
|
|
|
518
|
-
_See code: [src/commands/blueprints/promote.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.
|
|
518
|
+
_See code: [src/commands/blueprints/promote.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.1-next.g09af4b8/src/commands/blueprints/promote.ts)_
|
|
519
519
|
|
|
520
520
|
## `sanity-run blueprints stacks`
|
|
521
521
|
|
|
@@ -556,7 +556,7 @@ EXAMPLES
|
|
|
556
556
|
$ sanity-run blueprints stacks --organization-id <organizationId> --include-projects
|
|
557
557
|
```
|
|
558
558
|
|
|
559
|
-
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.
|
|
559
|
+
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.1-next.g09af4b8/src/commands/blueprints/stacks.ts)_
|
|
560
560
|
|
|
561
561
|
## `sanity-run functions add`
|
|
562
562
|
|
|
@@ -608,7 +608,7 @@ EXAMPLES
|
|
|
608
608
|
$ sanity-run functions add --name my-function --type document-create --type document-update --lang js
|
|
609
609
|
```
|
|
610
610
|
|
|
611
|
-
_See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.
|
|
611
|
+
_See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.1-next.g09af4b8/src/commands/functions/add.ts)_
|
|
612
612
|
|
|
613
613
|
## `sanity-run functions dev`
|
|
614
614
|
|
|
@@ -632,8 +632,8 @@ DESCRIPTION
|
|
|
632
632
|
|
|
633
633
|
Open the emulator in your browser to interactively test your functions with the payload editor.
|
|
634
634
|
|
|
635
|
-
Optionally, set the host and port with the --host and --port flags.
|
|
636
|
-
|
|
635
|
+
Optionally, set the host and port with the --host and --port flags. The live-reload WebSocket server shares this host
|
|
636
|
+
and port. Function timeout can be configured with the --timeout flag.
|
|
637
637
|
|
|
638
638
|
To invoke a function with the CLI, use 'functions test'.
|
|
639
639
|
|
|
@@ -643,7 +643,7 @@ EXAMPLES
|
|
|
643
643
|
$ sanity-run functions dev --timeout 60
|
|
644
644
|
```
|
|
645
645
|
|
|
646
|
-
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.
|
|
646
|
+
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.1-next.g09af4b8/src/commands/functions/dev.ts)_
|
|
647
647
|
|
|
648
648
|
## `sanity-run functions env add NAME KEY VALUE`
|
|
649
649
|
|
|
@@ -676,7 +676,7 @@ EXAMPLES
|
|
|
676
676
|
$ sanity-run functions env add --stack <name-or-id> MyFunction API_URL https://api.example.com/
|
|
677
677
|
```
|
|
678
678
|
|
|
679
|
-
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.
|
|
679
|
+
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.1-next.g09af4b8/src/commands/functions/env/add.ts)_
|
|
680
680
|
|
|
681
681
|
## `sanity-run functions env list NAME`
|
|
682
682
|
|
|
@@ -706,7 +706,7 @@ EXAMPLES
|
|
|
706
706
|
$ sanity-run functions env list --stack <name-or-id> MyFunction
|
|
707
707
|
```
|
|
708
708
|
|
|
709
|
-
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.
|
|
709
|
+
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.1-next.g09af4b8/src/commands/functions/env/list.ts)_
|
|
710
710
|
|
|
711
711
|
## `sanity-run functions env remove NAME KEY`
|
|
712
712
|
|
|
@@ -738,7 +738,7 @@ EXAMPLES
|
|
|
738
738
|
$ sanity-run functions env remove --stack <name-or-id> MyFunction API_URL
|
|
739
739
|
```
|
|
740
740
|
|
|
741
|
-
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.
|
|
741
|
+
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.1-next.g09af4b8/src/commands/functions/env/remove.ts)_
|
|
742
742
|
|
|
743
743
|
## `sanity-run functions logs [NAME]`
|
|
744
744
|
|
|
@@ -778,7 +778,7 @@ EXAMPLES
|
|
|
778
778
|
$ sanity-run functions logs <name> --delete
|
|
779
779
|
```
|
|
780
780
|
|
|
781
|
-
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.
|
|
781
|
+
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.1-next.g09af4b8/src/commands/functions/logs.ts)_
|
|
782
782
|
|
|
783
783
|
## `sanity-run functions test [NAME]`
|
|
784
784
|
|
|
@@ -836,7 +836,7 @@ EXAMPLES
|
|
|
836
836
|
$ sanity-run functions test <name> --event update --data-before '{ "title": "before" }' --data-after '{ "title": "after" }'
|
|
837
837
|
```
|
|
838
838
|
|
|
839
|
-
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.
|
|
839
|
+
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.1-next.g09af4b8/src/commands/functions/test.ts)_
|
|
840
840
|
|
|
841
841
|
## `sanity-run help [COMMAND]`
|
|
842
842
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { SANITY_FUNCTION_PREFIX } from '../../constants.js';
|
|
2
|
+
import { APP_BUILD_SPECS, prepareApplicationAsset, } from '../../utils/applications/prepare-asset.js';
|
|
2
3
|
import { resolveDeployedResources } from '../../utils/blueprints/resolve-deployed-resources.js';
|
|
3
4
|
import { CODE_OPERATION_UNCONFIRMED, EXIT_OPERATION_UNCONFIRMED } from '../../utils/exit-codes.js';
|
|
4
5
|
import { prepareAsset as prepareFunctionAsset } from '../../utils/functions/prepare-asset.js';
|
|
5
6
|
import { runCommand } from '../../utils/package-manager.js';
|
|
6
|
-
import { prepareStudioAsset } from '../../utils/studios/prepare-asset.js';
|
|
7
7
|
import { setupLogPolling } from './logs-polling.js';
|
|
8
8
|
import { getOperationStateInfo } from './operations-state.js';
|
|
9
9
|
import { processAssets } from './process-assets.js';
|
|
@@ -13,9 +13,9 @@ import { updateStack } from './stacks.js';
|
|
|
13
13
|
*/
|
|
14
14
|
const preDeployConfigs = [
|
|
15
15
|
{
|
|
16
|
-
resourceType:
|
|
16
|
+
resourceType: (type) => type in APP_BUILD_SPECS,
|
|
17
17
|
async prepareAsset(options) {
|
|
18
|
-
return
|
|
18
|
+
return prepareApplicationAsset({
|
|
19
19
|
resource: options.resource,
|
|
20
20
|
blueprintFileDir: options.blueprintFileDir,
|
|
21
21
|
});
|
|
@@ -9,7 +9,7 @@ export default class DevCommand extends ResolvedCommand {
|
|
|
9
9
|
|
|
10
10
|
Open the emulator in your browser to interactively test your functions with the payload editor.
|
|
11
11
|
|
|
12
|
-
Optionally, set the host and port with the --host and --port flags.
|
|
12
|
+
Optionally, set the host and port with the --host and --port flags. The live-reload WebSocket server shares this host and port. Function timeout can be configured with the --timeout flag.
|
|
13
13
|
|
|
14
14
|
To invoke a function with the CLI, use 'functions test'.`;
|
|
15
15
|
static examples = [
|
package/dist/constants.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare const SANITY_PROJECT_CORS = "sanity.project.cors";
|
|
|
13
13
|
export declare const SANITY_PROJECT_DATASET = "sanity.project.dataset";
|
|
14
14
|
export declare const SANITY_PROJECT_WEBHOOK = "sanity.project.webhook";
|
|
15
15
|
export declare const SANITY_STUDIO = "sanity.studio";
|
|
16
|
+
export declare const SANITY_APPLICATION = "sanity.application";
|
|
16
17
|
export declare const EVENT_DOCUMENT_PUBLISH = "document-publish";
|
|
17
18
|
export declare const EVENT_DOCUMENT_CREATE = "document-create";
|
|
18
19
|
export declare const EVENT_DOCUMENT_UPDATE = "document-update";
|
package/dist/constants.js
CHANGED
|
@@ -12,6 +12,7 @@ export const SANITY_PROJECT_CORS = 'sanity.project.cors';
|
|
|
12
12
|
export const SANITY_PROJECT_DATASET = 'sanity.project.dataset';
|
|
13
13
|
export const SANITY_PROJECT_WEBHOOK = 'sanity.project.webhook';
|
|
14
14
|
export const SANITY_STUDIO = 'sanity.studio';
|
|
15
|
+
export const SANITY_APPLICATION = 'sanity.application';
|
|
15
16
|
export const EVENT_DOCUMENT_PUBLISH = 'document-publish';
|
|
16
17
|
export const EVENT_DOCUMENT_CREATE = 'document-create';
|
|
17
18
|
export const EVENT_DOCUMENT_UPDATE = 'document-update';
|
package/dist/server/app.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import * as http from 'node:http';
|
|
1
2
|
import { type InvokeExecutionOptions } from '../utils/types.js';
|
|
2
|
-
declare const app: (host: string, port: number, validateResources: boolean, executionOptions?: Partial<InvokeExecutionOptions>) =>
|
|
3
|
+
declare const app: (host: string, port: number, validateResources: boolean, executionOptions?: Partial<InvokeExecutionOptions>) => http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
3
4
|
declare function parseDocumentUrl(url: string): {
|
|
4
5
|
projectId: string;
|
|
5
6
|
dataset: string;
|
package/dist/server/app.js
CHANGED
|
@@ -11,7 +11,6 @@ import { isRecord } from '../utils/is-record.js';
|
|
|
11
11
|
import { isEventType, isGroqContextOptions, } from '../utils/types.js';
|
|
12
12
|
import { handleInvokeRequest } from './handlers/invoke.js';
|
|
13
13
|
const app = (host, port, validateResources, executionOptions) => {
|
|
14
|
-
const wss = new WebSocketServer({ port: 8974 });
|
|
15
14
|
// Send a JSON envelope to every connected UI client.
|
|
16
15
|
const broadcast = (envelope) => {
|
|
17
16
|
const message = JSON.stringify(envelope);
|
|
@@ -268,6 +267,9 @@ const app = (host, port, validateResources, executionOptions) => {
|
|
|
268
267
|
}
|
|
269
268
|
};
|
|
270
269
|
const server = http.createServer(requestListener);
|
|
270
|
+
// Share the HTTP server so live-reload upgrades on the emulator's own port,
|
|
271
|
+
// rather than reserving a second port that may already be taken.
|
|
272
|
+
const wss = new WebSocketServer({ server });
|
|
271
273
|
server.listen(port, host, () => { });
|
|
272
274
|
wss.on('connection', function connection(ws) {
|
|
273
275
|
ws.on('error', console.error);
|
|
@@ -280,6 +282,7 @@ const app = (host, port, validateResources, executionOptions) => {
|
|
|
280
282
|
ws.send('reload-blueprint');
|
|
281
283
|
});
|
|
282
284
|
});
|
|
285
|
+
return server;
|
|
283
286
|
};
|
|
284
287
|
// Helper function to test URL parsing and document fetching logic
|
|
285
288
|
function parseDocumentUrl(url) {
|
|
@@ -2,8 +2,10 @@ import apiConstructor from '../api.js'
|
|
|
2
2
|
|
|
3
3
|
const api = apiConstructor()
|
|
4
4
|
|
|
5
|
-
// Create WebSocket connection
|
|
6
|
-
|
|
5
|
+
// Create WebSocket connection on the same origin the emulator is served from,
|
|
6
|
+
// so it follows the --host and --port the server was started with.
|
|
7
|
+
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'
|
|
8
|
+
const socket = new WebSocket(`${protocol}//${window.location.host}`)
|
|
7
9
|
|
|
8
10
|
// Connection opened
|
|
9
11
|
socket.addEventListener('open', () => {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type BuildStudioEventListener } from '@sanity/cli-build/_internal/build';
|
|
2
|
+
import type { Output } from '@sanity/cli-core';
|
|
3
|
+
import type { AssetPrepResult } from '../types.js';
|
|
4
|
+
import type { BlueprintApplicationResource, BlueprintStudioResource } from './types.js';
|
|
5
|
+
export type ApplicationBuildResource = BlueprintStudioResource | BlueprintApplicationResource;
|
|
6
|
+
type BuildContext<R extends ApplicationBuildResource> = {
|
|
7
|
+
resource: R;
|
|
8
|
+
appId: string;
|
|
9
|
+
workDir: string;
|
|
10
|
+
outDir: string;
|
|
11
|
+
output: Output;
|
|
12
|
+
eventListener: Partial<BuildStudioEventListener>;
|
|
13
|
+
};
|
|
14
|
+
type BuildResult = {
|
|
15
|
+
mismatchedPackages?: string[];
|
|
16
|
+
};
|
|
17
|
+
export declare const APP_BUILD_SPECS: {
|
|
18
|
+
'sanity.studio': {
|
|
19
|
+
build: typeof buildStudioBundle;
|
|
20
|
+
};
|
|
21
|
+
'sanity.application': {
|
|
22
|
+
build: typeof buildApplicationBundle;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export declare function prepareApplicationAsset<R extends ApplicationBuildResource>({ blueprintFileDir, resource, }: {
|
|
26
|
+
blueprintFileDir: string;
|
|
27
|
+
resource: R;
|
|
28
|
+
}): Promise<AssetPrepResult>;
|
|
29
|
+
declare function buildStudioBundle({ resource, appId, workDir, outDir, output, eventListener, }: BuildContext<BlueprintStudioResource>): Promise<BuildResult>;
|
|
30
|
+
declare function buildApplicationBundle({ resource, appId, workDir, outDir, output, eventListener, }: BuildContext<BlueprintApplicationResource>): Promise<BuildResult>;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { createWriteStream } from 'node:fs';
|
|
2
|
+
import { mkdtemp, readFile, rm, stat } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import path, { basename, dirname, join } from 'node:path';
|
|
5
|
+
import { pipeline } from 'node:stream/promises';
|
|
6
|
+
import { createGzip } from 'node:zlib';
|
|
7
|
+
import { buildApp, buildStudio, compareDependencyVersions, } from '@sanity/cli-build/_internal/build';
|
|
8
|
+
import { getLocalPackageVersion } from '@sanity/cli-core';
|
|
9
|
+
import { pack } from 'tar-fs';
|
|
10
|
+
export const APP_BUILD_SPECS = {
|
|
11
|
+
'sanity.studio': { build: buildStudioBundle },
|
|
12
|
+
'sanity.application': { build: buildApplicationBundle },
|
|
13
|
+
};
|
|
14
|
+
export async function prepareApplicationAsset({ blueprintFileDir, resource, }) {
|
|
15
|
+
// The lookup can't prove it yields the spec matching this R, so it's asserted once here.
|
|
16
|
+
const spec = APP_BUILD_SPECS[resource.type];
|
|
17
|
+
const appId = getAppId(resource);
|
|
18
|
+
if (!appId) {
|
|
19
|
+
return {
|
|
20
|
+
success: false,
|
|
21
|
+
async cleanup() { },
|
|
22
|
+
error: `Unable to determine appId for ${resource.type} resource '${resource.name}'`,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
let cleanup = async () => { };
|
|
26
|
+
const assetPath = String(resource.root);
|
|
27
|
+
const workDir = path.resolve(blueprintFileDir, assetPath);
|
|
28
|
+
try {
|
|
29
|
+
const workDirStat = await stat(workDir);
|
|
30
|
+
if (!workDirStat.isDirectory()) {
|
|
31
|
+
return {
|
|
32
|
+
success: false,
|
|
33
|
+
cleanup,
|
|
34
|
+
error: `Property 'root' on resource with type '${resource.type}' must be a directory`,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
40
|
+
return {
|
|
41
|
+
success: false,
|
|
42
|
+
cleanup,
|
|
43
|
+
error: `Unable to read given 'root' on resource with type '${resource.type}': ${msg}`,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
const outDir = await mkdtemp(join(tmpdir(), `app-build-`));
|
|
48
|
+
const outFile = `${outDir}.tar.gz`;
|
|
49
|
+
cleanup = async () => {
|
|
50
|
+
await rm(outDir, { force: true, recursive: true });
|
|
51
|
+
await rm(outFile, { force: true });
|
|
52
|
+
};
|
|
53
|
+
let mismatchedPackages;
|
|
54
|
+
try {
|
|
55
|
+
;
|
|
56
|
+
({ mismatchedPackages } = await spec.build({
|
|
57
|
+
resource,
|
|
58
|
+
appId,
|
|
59
|
+
workDir,
|
|
60
|
+
outDir,
|
|
61
|
+
output: createSilentOutput(),
|
|
62
|
+
eventListener,
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
67
|
+
return {
|
|
68
|
+
success: false,
|
|
69
|
+
cleanup,
|
|
70
|
+
error: message,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
await pipeline(pack(dirname(outDir), { entries: [basename(outDir)] }), createGzip(), createWriteStream(outFile));
|
|
74
|
+
const buffer = await readFile(outFile);
|
|
75
|
+
return {
|
|
76
|
+
success: true,
|
|
77
|
+
cleanup,
|
|
78
|
+
outputBuffer: buffer,
|
|
79
|
+
fileExtension: 'tar.gz',
|
|
80
|
+
assetParameter: 'root',
|
|
81
|
+
metadata: {
|
|
82
|
+
sanityVersion: await getInstalledSanityVersion(workDir),
|
|
83
|
+
mismatchedPackages,
|
|
84
|
+
assetBytes: buffer.length,
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
return {
|
|
90
|
+
success: false,
|
|
91
|
+
cleanup,
|
|
92
|
+
error: error instanceof Error ? error.message : String(error),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async function buildStudioBundle({ resource, appId, workDir, outDir, output, eventListener, }) {
|
|
97
|
+
let mismatchedPackages;
|
|
98
|
+
await buildStudio({
|
|
99
|
+
appId,
|
|
100
|
+
autoUpdatesEnabled: resource.autoUpdates.enabled,
|
|
101
|
+
checkAppId() { },
|
|
102
|
+
async compareDependencyVersions(packages) {
|
|
103
|
+
const result = await compareDependencyVersions(packages, workDir, { appId });
|
|
104
|
+
mismatchedPackages = result.mismatched.map((m) => m.pkg);
|
|
105
|
+
return result;
|
|
106
|
+
},
|
|
107
|
+
determineBasePath() {
|
|
108
|
+
return resource.basePath ?? '/';
|
|
109
|
+
},
|
|
110
|
+
// a studio is a standalone app, not a workbench module-federation app
|
|
111
|
+
isApp: false,
|
|
112
|
+
isBlueprints: true,
|
|
113
|
+
isWorkbenchApp: false,
|
|
114
|
+
minify: resource.minify ?? true,
|
|
115
|
+
outDir,
|
|
116
|
+
output,
|
|
117
|
+
reactCompiler: resource.reactCompiler || false,
|
|
118
|
+
schemaExtraction: undefined,
|
|
119
|
+
sourceMap: resource.sourceMap ?? false,
|
|
120
|
+
stats: false,
|
|
121
|
+
unattendedMode: true,
|
|
122
|
+
// TODO pass in vite config from the studio resource
|
|
123
|
+
vite: undefined,
|
|
124
|
+
workDir,
|
|
125
|
+
eventListener,
|
|
126
|
+
});
|
|
127
|
+
return { mismatchedPackages };
|
|
128
|
+
}
|
|
129
|
+
async function buildApplicationBundle({ resource, appId, workDir, outDir, output, eventListener, }) {
|
|
130
|
+
const views = resource.views ?? [];
|
|
131
|
+
const [window, extraWindow] = views.filter((v) => v.type === 'app');
|
|
132
|
+
if (extraWindow) {
|
|
133
|
+
throw new Error(`Application resource '${resource.name}' declares more than one window view; at most one is allowed`);
|
|
134
|
+
}
|
|
135
|
+
let mismatchedPackages;
|
|
136
|
+
await buildApp({
|
|
137
|
+
appId,
|
|
138
|
+
appTitle: resource.title,
|
|
139
|
+
autoUpdatesEnabled: false,
|
|
140
|
+
checkAppId() { },
|
|
141
|
+
async compareDependencyVersions(packages) {
|
|
142
|
+
const result = await compareDependencyVersions(packages, workDir, { appId });
|
|
143
|
+
mismatchedPackages = result.mismatched.map((m) => m.pkg);
|
|
144
|
+
return result;
|
|
145
|
+
},
|
|
146
|
+
determineBasePath() {
|
|
147
|
+
return '/';
|
|
148
|
+
},
|
|
149
|
+
entry: window?.src,
|
|
150
|
+
isWorkbenchApp: true,
|
|
151
|
+
isBlueprints: true,
|
|
152
|
+
workbenchAppId: appId,
|
|
153
|
+
minify: true,
|
|
154
|
+
outDir,
|
|
155
|
+
output,
|
|
156
|
+
reactCompiler: false,
|
|
157
|
+
schemaExtraction: undefined,
|
|
158
|
+
sourceMap: false,
|
|
159
|
+
stats: false,
|
|
160
|
+
unattendedMode: true,
|
|
161
|
+
vite: undefined,
|
|
162
|
+
workDir,
|
|
163
|
+
eventListener,
|
|
164
|
+
exposes: {
|
|
165
|
+
views: views.map(toWorkbenchView),
|
|
166
|
+
webWorkers: resource.webWorkers,
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
return { mismatchedPackages };
|
|
170
|
+
}
|
|
171
|
+
// blueprints-node emits `type` (window views as `app`); workbench-cli discriminates on `surface`.
|
|
172
|
+
function toWorkbenchView(view) {
|
|
173
|
+
switch (view.type) {
|
|
174
|
+
case 'app': {
|
|
175
|
+
const { type: _type, ...rest } = view;
|
|
176
|
+
return { ...rest, surface: 'window' };
|
|
177
|
+
}
|
|
178
|
+
case 'panel': {
|
|
179
|
+
const { type, ...rest } = view;
|
|
180
|
+
return { ...rest, surface: type };
|
|
181
|
+
}
|
|
182
|
+
case 'asset_source': {
|
|
183
|
+
const { type, ...rest } = view;
|
|
184
|
+
return { ...rest, surface: type };
|
|
185
|
+
}
|
|
186
|
+
case 'tile': {
|
|
187
|
+
const { type, ...rest } = view;
|
|
188
|
+
return { ...rest, surface: type };
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const eventListener = {
|
|
193
|
+
onBuildFail({ message }) {
|
|
194
|
+
throw new Error(message);
|
|
195
|
+
},
|
|
196
|
+
onInvalidStyledComponentsVersionRange({ message }) {
|
|
197
|
+
throw new Error(message);
|
|
198
|
+
},
|
|
199
|
+
onNoDeclaredStyledComponentsVersion({ message }) {
|
|
200
|
+
throw new Error(message);
|
|
201
|
+
},
|
|
202
|
+
onNoInstalledSanityVersion({ message }) {
|
|
203
|
+
throw new Error(message);
|
|
204
|
+
},
|
|
205
|
+
onNoInstalledStyledComponentsVersion({ message }) {
|
|
206
|
+
throw new Error(message);
|
|
207
|
+
},
|
|
208
|
+
onPreReleaseInNonInteractiveAutoUpdate({ message }) {
|
|
209
|
+
throw new Error(message);
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
function createSilentOutput() {
|
|
213
|
+
return {
|
|
214
|
+
error(input, options) {
|
|
215
|
+
if (typeof options?.exit === 'number') {
|
|
216
|
+
if (input instanceof Error) {
|
|
217
|
+
throw input;
|
|
218
|
+
}
|
|
219
|
+
throw new Error(input);
|
|
220
|
+
}
|
|
221
|
+
return undefined;
|
|
222
|
+
},
|
|
223
|
+
log() { },
|
|
224
|
+
warn(input) {
|
|
225
|
+
return input;
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
async function getInstalledSanityVersion(workDir) {
|
|
230
|
+
try {
|
|
231
|
+
return (await getLocalPackageVersion('sanity', workDir)) ?? undefined;
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function getAppId(resource) {
|
|
238
|
+
if ('externalId' in resource && typeof resource.externalId === 'string' && resource.externalId) {
|
|
239
|
+
return resource.externalId;
|
|
240
|
+
}
|
|
241
|
+
else if (resource.lifecycle?.ownershipAction?.type === 'attach') {
|
|
242
|
+
return resource.lifecycle.ownershipAction.id;
|
|
243
|
+
}
|
|
244
|
+
return undefined;
|
|
245
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { BlueprintProjectResourceLifecycle, BlueprintResource, BlueprintStudioResource as PublishedStudioResource } from '@sanity/blueprints';
|
|
2
|
+
/** Studios point at their directory with `root`, same as applications. */
|
|
3
|
+
export type BlueprintStudioResource = Omit<PublishedStudioResource, 'src'> & {
|
|
4
|
+
root: string;
|
|
5
|
+
};
|
|
6
|
+
type ApplicationDock = {
|
|
7
|
+
group?: 'system' | 'applications' | 'user';
|
|
8
|
+
order?: number;
|
|
9
|
+
};
|
|
10
|
+
type ChildBase = {
|
|
11
|
+
name: string;
|
|
12
|
+
title: string;
|
|
13
|
+
src: string;
|
|
14
|
+
};
|
|
15
|
+
type WindowView = ChildBase & {
|
|
16
|
+
type: 'app';
|
|
17
|
+
dock?: ApplicationDock;
|
|
18
|
+
};
|
|
19
|
+
type PanelView = ChildBase & {
|
|
20
|
+
type: 'panel';
|
|
21
|
+
dock?: ApplicationDock;
|
|
22
|
+
};
|
|
23
|
+
type AssetSourceView = ChildBase & {
|
|
24
|
+
type: 'asset_source';
|
|
25
|
+
};
|
|
26
|
+
type TileView = ChildBase & {
|
|
27
|
+
type: 'tile';
|
|
28
|
+
size: 'small' | 'large' | 'banner';
|
|
29
|
+
order?: number;
|
|
30
|
+
};
|
|
31
|
+
type WebWorker = ChildBase & {
|
|
32
|
+
type: 'worker';
|
|
33
|
+
};
|
|
34
|
+
export type ApplicationView = WindowView | PanelView | AssetSourceView | TileView;
|
|
35
|
+
export interface BlueprintApplicationResource extends BlueprintResource<BlueprintProjectResourceLifecycle> {
|
|
36
|
+
type: 'sanity.application';
|
|
37
|
+
slug: string;
|
|
38
|
+
title: string;
|
|
39
|
+
/** Application directory, relative to the blueprint file; contains package.json. */
|
|
40
|
+
root: string;
|
|
41
|
+
icon?: string;
|
|
42
|
+
visibility?: 'default' | 'unlisted' | 'disabled';
|
|
43
|
+
views?: ApplicationView[];
|
|
44
|
+
webWorkers?: WebWorker[];
|
|
45
|
+
}
|
|
46
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { formatDateTime, formatElapsed } from '@sanity/cli-core/dates';
|
|
2
2
|
import { treeify } from 'array-treeify';
|
|
3
|
-
import { SANITY_ACCESS_ROBOT, SANITY_ACCESS_ROLE, SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_DURABLE, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET, SANITY_FUNCTION_PUBSUB, SANITY_FUNCTION_SCHEDULED, SANITY_FUNCTION_SYNC_TAG_INVALIDATE, SANITY_PROJECT, SANITY_PROJECT_CORS, SANITY_PROJECT_DATASET, SANITY_PROJECT_WEBHOOK, SANITY_STUDIO, } from '../../constants.js';
|
|
3
|
+
import { SANITY_ACCESS_ROBOT, SANITY_ACCESS_ROLE, SANITY_APPLICATION, SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_DURABLE, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET, SANITY_FUNCTION_PUBSUB, SANITY_FUNCTION_SCHEDULED, SANITY_FUNCTION_SYNC_TAG_INVALIDATE, SANITY_PROJECT, SANITY_PROJECT_CORS, SANITY_PROJECT_DATASET, SANITY_PROJECT_WEBHOOK, SANITY_STUDIO, } from '../../constants.js';
|
|
4
4
|
import { styleText } from '../style-text.js';
|
|
5
5
|
import { isCorsOriginResource, isDatasetResource, isRobotResource, isRoleResource, isStudioResource, isWebhookResource, } from '../types.js';
|
|
6
6
|
import { capitalize, niceId, renderSection } from './presenters.js';
|
|
@@ -65,6 +65,10 @@ const RESOURCE_CATEGORIES = {
|
|
|
65
65
|
return isStudioResource(res) ? arrayifyStudio(res) : [];
|
|
66
66
|
},
|
|
67
67
|
},
|
|
68
|
+
[SANITY_APPLICATION]: {
|
|
69
|
+
label: 'Applications',
|
|
70
|
+
displayNameAttribute: 'title',
|
|
71
|
+
},
|
|
68
72
|
};
|
|
69
73
|
const categoryByLabel = Object.values(RESOURCE_CATEGORIES).reduce((acc, curr) => {
|
|
70
74
|
acc[curr.label] = curr;
|
package/oclif.manifest.json
CHANGED
|
@@ -2042,7 +2042,7 @@
|
|
|
2042
2042
|
"functions:dev": {
|
|
2043
2043
|
"aliases": [],
|
|
2044
2044
|
"args": {},
|
|
2045
|
-
"description": "Runs a local, web-based development server to test your functions before deploying.\n\nOpen the emulator in your browser to interactively test your functions with the payload editor.\n\nOptionally, set the host and port with the --host and --port flags.
|
|
2045
|
+
"description": "Runs a local, web-based development server to test your functions before deploying.\n\nOpen the emulator in your browser to interactively test your functions with the payload editor.\n\nOptionally, set the host and port with the --host and --port flags. The live-reload WebSocket server shares this host and port. Function timeout can be configured with the --timeout flag.\n\nTo invoke a function with the CLI, use 'functions test'.",
|
|
2046
2046
|
"examples": [
|
|
2047
2047
|
"<%= config.bin %> <%= command.id %> --host 127.0.0.1 --port 3333",
|
|
2048
2048
|
"<%= config.bin %> <%= command.id %> --timeout 60"
|
|
@@ -3148,5 +3148,5 @@
|
|
|
3148
3148
|
]
|
|
3149
3149
|
}
|
|
3150
3150
|
},
|
|
3151
|
-
"version": "17.13.
|
|
3151
|
+
"version": "17.13.1-next.g09af4b8"
|
|
3152
3152
|
}
|
package/package.json
CHANGED
package/skills/functions-dev.md
CHANGED
|
@@ -16,6 +16,6 @@ The emulator is available at `http://localhost:8080`. Choose another loopback po
|
|
|
16
16
|
npx @sanity/cli functions dev --host 127.0.0.1 --port 3333 --timeout 60
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
The emulator's live-reload WebSocket server shares the same host and port, so no additional port is reserved. `--timeout` sets the execution limit in seconds for every Function, taking precedence over each Function's configured `timeout` (default 10 seconds). Bind to a non-loopback interface only when network access is requested and exposing the development server is acceptable.
|
|
20
20
|
|
|
21
21
|
Run this command in a persistent terminal, report the URL, and stop the process when development is complete. For one bounded invocation without a web server, use `functions test`.
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { BlueprintStudioResource } from '@sanity/blueprints';
|
|
2
|
-
import type { AssetPrepResult } from '../types.js';
|
|
3
|
-
export declare function prepareStudioAsset({ blueprintFileDir, resource, }: {
|
|
4
|
-
blueprintFileDir: string;
|
|
5
|
-
resource: BlueprintStudioResource;
|
|
6
|
-
}): Promise<AssetPrepResult>;
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { createWriteStream } from 'node:fs';
|
|
2
|
-
import { mkdtemp, readFile, rm, stat } from 'node:fs/promises';
|
|
3
|
-
import { tmpdir } from 'node:os';
|
|
4
|
-
import path, { basename, dirname, join } from 'node:path';
|
|
5
|
-
import { pipeline } from 'node:stream/promises';
|
|
6
|
-
import { createGzip } from 'node:zlib';
|
|
7
|
-
import { buildStudio, compareDependencyVersions } from '@sanity/cli-build/_internal/build';
|
|
8
|
-
import { getLocalPackageVersion } from '@sanity/cli-core';
|
|
9
|
-
import { pack } from 'tar-fs';
|
|
10
|
-
export async function prepareStudioAsset({ blueprintFileDir, resource, }) {
|
|
11
|
-
// validate resource has an appId
|
|
12
|
-
const appId = getAppId(resource);
|
|
13
|
-
if (!appId) {
|
|
14
|
-
return {
|
|
15
|
-
success: false,
|
|
16
|
-
async cleanup() {
|
|
17
|
-
// no op
|
|
18
|
-
},
|
|
19
|
-
error: `Unable to determine appId for sanity.studio resource '${resource.name}'`,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
let cleanup = async () => {
|
|
23
|
-
// no op
|
|
24
|
-
};
|
|
25
|
-
const studioPath = path.resolve(blueprintFileDir, resource.src);
|
|
26
|
-
// set only when auto-updates is on, because the build compares versions only then
|
|
27
|
-
let mismatchedPackages;
|
|
28
|
-
try {
|
|
29
|
-
const studioPathStat = await stat(studioPath);
|
|
30
|
-
if (!studioPathStat.isDirectory()) {
|
|
31
|
-
return {
|
|
32
|
-
success: false,
|
|
33
|
-
cleanup,
|
|
34
|
-
error: `Property 'src' on resource with type '${resource.type}' must be a directory`,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
const msg = error instanceof Error ? error.message : String(error);
|
|
40
|
-
return {
|
|
41
|
-
success: false,
|
|
42
|
-
cleanup,
|
|
43
|
-
error: `Unable to read given 'src' on resource with type '${resource.type}': ${msg}`,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
try {
|
|
47
|
-
const outDir = await mkdtemp(join(tmpdir(), `studio-build-`));
|
|
48
|
-
const outFile = `${outDir}.tar.gz`;
|
|
49
|
-
cleanup = async () => {
|
|
50
|
-
await rm(outDir, { force: true, recursive: true });
|
|
51
|
-
await rm(outFile, { force: true });
|
|
52
|
-
};
|
|
53
|
-
try {
|
|
54
|
-
await buildStudio({
|
|
55
|
-
appId,
|
|
56
|
-
autoUpdatesEnabled: resource.autoUpdates.enabled,
|
|
57
|
-
checkAppId() { },
|
|
58
|
-
async compareDependencyVersions(packages) {
|
|
59
|
-
const result = await compareDependencyVersions(packages, studioPath, { appId });
|
|
60
|
-
mismatchedPackages = result.mismatched.map((m) => m.pkg);
|
|
61
|
-
return result;
|
|
62
|
-
},
|
|
63
|
-
determineBasePath() {
|
|
64
|
-
return resource.basePath ?? '/';
|
|
65
|
-
},
|
|
66
|
-
isApp: false,
|
|
67
|
-
isWorkbenchApp: false,
|
|
68
|
-
minify: resource.minify ?? true,
|
|
69
|
-
outDir,
|
|
70
|
-
output: createSilentOutput(),
|
|
71
|
-
reactCompiler: resource.reactCompiler || false,
|
|
72
|
-
schemaExtraction: undefined,
|
|
73
|
-
sourceMap: resource.sourceMap ?? false,
|
|
74
|
-
stats: false,
|
|
75
|
-
unattendedMode: true,
|
|
76
|
-
// TODO pass in vite config from the studio resource
|
|
77
|
-
vite: undefined,
|
|
78
|
-
workDir: studioPath,
|
|
79
|
-
eventListener: {
|
|
80
|
-
onBuildFail({ message }) {
|
|
81
|
-
throw new Error(message);
|
|
82
|
-
},
|
|
83
|
-
onInvalidStyledComponentsVersionRange({ message }) {
|
|
84
|
-
throw new Error(message);
|
|
85
|
-
},
|
|
86
|
-
onNoDeclaredStyledComponentsVersion({ message }) {
|
|
87
|
-
throw new Error(message);
|
|
88
|
-
},
|
|
89
|
-
onNoInstalledSanityVersion({ message }) {
|
|
90
|
-
throw new Error(message);
|
|
91
|
-
},
|
|
92
|
-
onNoInstalledStyledComponentsVersion({ message }) {
|
|
93
|
-
throw new Error(message);
|
|
94
|
-
},
|
|
95
|
-
onPreReleaseInNonInteractiveAutoUpdate({ message }) {
|
|
96
|
-
throw new Error(message);
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
103
|
-
return {
|
|
104
|
-
success: false,
|
|
105
|
-
cleanup,
|
|
106
|
-
error: message,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
// tar/gzip/write the built output
|
|
110
|
-
await pipeline(pack(dirname(outDir), { entries: [basename(outDir)] }), createGzip(), createWriteStream(outFile));
|
|
111
|
-
const buffer = await readFile(outFile);
|
|
112
|
-
return {
|
|
113
|
-
success: true,
|
|
114
|
-
cleanup,
|
|
115
|
-
outputBuffer: buffer,
|
|
116
|
-
fileExtension: 'tar.gz',
|
|
117
|
-
assetParameter: 'src',
|
|
118
|
-
metadata: {
|
|
119
|
-
sanityVersion: await getInstalledSanityVersion(studioPath),
|
|
120
|
-
mismatchedPackages,
|
|
121
|
-
assetBytes: buffer.length,
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
catch (error) {
|
|
126
|
-
return {
|
|
127
|
-
success: false,
|
|
128
|
-
cleanup,
|
|
129
|
-
error: error instanceof Error ? error.message : String(error),
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
function createSilentOutput() {
|
|
134
|
-
return {
|
|
135
|
-
error(input, options) {
|
|
136
|
-
if (typeof options?.exit === 'number') {
|
|
137
|
-
if (input instanceof Error) {
|
|
138
|
-
throw input;
|
|
139
|
-
}
|
|
140
|
-
throw new Error(input);
|
|
141
|
-
}
|
|
142
|
-
return undefined;
|
|
143
|
-
},
|
|
144
|
-
log() { },
|
|
145
|
-
warn(input) {
|
|
146
|
-
return input;
|
|
147
|
-
},
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
async function getInstalledSanityVersion(studioPath) {
|
|
151
|
-
try {
|
|
152
|
-
return (await getLocalPackageVersion('sanity', studioPath)) ?? undefined;
|
|
153
|
-
}
|
|
154
|
-
catch {
|
|
155
|
-
return undefined;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
function getAppId(resource) {
|
|
159
|
-
if ('externalId' in resource && typeof resource.externalId === 'string' && resource.externalId) {
|
|
160
|
-
return resource.externalId;
|
|
161
|
-
}
|
|
162
|
-
else if (resource.lifecycle?.ownershipAction?.type === 'attach') {
|
|
163
|
-
return resource.lifecycle.ownershipAction.id;
|
|
164
|
-
}
|
|
165
|
-
return undefined;
|
|
166
|
-
}
|