@sanity/runtime-cli 17.21.6-next.gaa32f6f → 17.21.6-next.gd629c70
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 +19 -19
- package/dist/actions/blueprints/assets.d.ts +2 -1
- package/dist/actions/blueprints/assets.js +8 -2
- package/dist/actions/blueprints/pre-deploy.d.ts +1 -1
- package/dist/actions/blueprints/pre-deploy.js +38 -5
- package/dist/actions/blueprints/process-assets.d.ts +3 -0
- package/dist/actions/blueprints/process-assets.js +13 -4
- package/dist/cores/blueprints/deploy.js +2 -1
- package/dist/utils/bundles/prepare-asset.d.ts +6 -2
- package/dist/utils/bundles/prepare-asset.js +10 -2
- package/dist/utils/bundles/resolve-resource-bindings.d.ts +10 -0
- package/dist/utils/bundles/resolve-resource-bindings.js +37 -0
- package/dist/utils/icons/prepare-asset.d.ts +10 -0
- package/dist/utils/icons/prepare-asset.js +40 -0
- package/dist/utils/types.d.ts +17 -2
- package/oclif.manifest.json +1 -1
- package/package.json +3 -3
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.21.6-next.
|
|
93
|
+
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.gd629c70/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.21.6-next.
|
|
130
|
+
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.gd629c70/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.21.6-next.
|
|
186
|
+
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.gd629c70/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.21.6-next.
|
|
224
|
+
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.gd629c70/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.21.6-next.
|
|
256
|
+
_See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.gd629c70/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.21.6-next.
|
|
294
|
+
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.gd629c70/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.21.6-next.
|
|
358
|
+
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.gd629c70/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.21.6-next.
|
|
404
|
+
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.gd629c70/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.21.6-next.
|
|
449
|
+
_See code: [src/commands/blueprints/mint-deploy-token.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.gd629c70/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.21.6-next.
|
|
482
|
+
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.gd629c70/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.21.6-next.
|
|
518
|
+
_See code: [src/commands/blueprints/promote.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.gd629c70/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.21.6-next.
|
|
559
|
+
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.gd629c70/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.21.6-next.
|
|
611
|
+
_See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.gd629c70/src/commands/functions/add.ts)_
|
|
612
612
|
|
|
613
613
|
## `sanity-run functions dev`
|
|
614
614
|
|
|
@@ -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.21.6-next.
|
|
646
|
+
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.gd629c70/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.21.6-next.
|
|
679
|
+
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.gd629c70/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.21.6-next.
|
|
709
|
+
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.gd629c70/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.21.6-next.
|
|
741
|
+
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.gd629c70/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.21.6-next.
|
|
781
|
+
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.gd629c70/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.21.6-next.
|
|
839
|
+
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v17.21.6-next.gd629c70/src/commands/functions/test.ts)_
|
|
840
840
|
|
|
841
841
|
## `sanity-run help [COMMAND]`
|
|
842
842
|
|
|
@@ -18,9 +18,10 @@ export type StashAssetResult = {
|
|
|
18
18
|
success: false;
|
|
19
19
|
error: string;
|
|
20
20
|
};
|
|
21
|
-
export declare function stashAsset<R extends BlueprintResource>({ resolvedResource, prepAsset, auth, blueprintFileDir, fetchFn, installer, }: {
|
|
21
|
+
export declare function stashAsset<R extends BlueprintResource>({ resolvedResource, prepAsset, stackId, auth, blueprintFileDir, fetchFn, installer, }: {
|
|
22
22
|
resolvedResource: ResolvedResource<R>;
|
|
23
23
|
prepAsset: PrepAssetFn<R>;
|
|
24
|
+
stackId: string;
|
|
24
25
|
auth: AuthParams;
|
|
25
26
|
blueprintFileDir: string;
|
|
26
27
|
fetchFn: typeof fetch;
|
|
@@ -4,10 +4,16 @@ import getHeaders from '../../utils/get-headers.js';
|
|
|
4
4
|
const assetsUrl = blueprintsUrl('assets');
|
|
5
5
|
export const assetCheckUrl = `${assetsUrl}/check`;
|
|
6
6
|
export const assetStashUrl = `${assetsUrl}/stash`;
|
|
7
|
-
export async function stashAsset({ resolvedResource, prepAsset, auth, blueprintFileDir, fetchFn, installer, }) {
|
|
7
|
+
export async function stashAsset({ resolvedResource, prepAsset, stackId, auth, blueprintFileDir, fetchFn, installer, }) {
|
|
8
8
|
let cleanup = async () => { };
|
|
9
9
|
try {
|
|
10
|
-
const prepResult = await prepAsset({
|
|
10
|
+
const prepResult = await prepAsset({
|
|
11
|
+
resolvedResource,
|
|
12
|
+
blueprintFileDir,
|
|
13
|
+
installer,
|
|
14
|
+
stackId,
|
|
15
|
+
auth,
|
|
16
|
+
});
|
|
11
17
|
if (prepResult.success === false) {
|
|
12
18
|
await prepResult.cleanup();
|
|
13
19
|
return {
|
|
@@ -12,7 +12,7 @@ type PreDeployFailure = {
|
|
|
12
12
|
};
|
|
13
13
|
export type PreDeployResult = PreDeployFailure | {
|
|
14
14
|
success: true;
|
|
15
|
-
/** One entry per prepared asset, for the deploy metadata */
|
|
15
|
+
/** One entry per prepared bundle or source asset (icons get none), for the deploy metadata */
|
|
16
16
|
resourceMetadata: ResourceMetadata[];
|
|
17
17
|
};
|
|
18
18
|
export type PreDeployAssetEvent<R extends BlueprintResource> = {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
1
2
|
import { SANITY_AGENT_TYPE, SANITY_FUNCTION_PREFIX } from '../../constants.js';
|
|
2
3
|
import { prepareAsset as prepareAgentAsset } from '../../utils/agents/prepare-asset.js';
|
|
3
4
|
import { resolveDeployedResources } from '../../utils/blueprints/resolve-deployed-resources.js';
|
|
@@ -6,6 +7,7 @@ import { stampConfigVersion } from '../../utils/bundles/stamp-config-version.js'
|
|
|
6
7
|
import { CODE_OPERATION_UNCONFIRMED, EXIT_OPERATION_UNCONFIRMED } from '../../utils/exit-codes.js';
|
|
7
8
|
import { extractDurableConfig } from '../../utils/functions/extract-durable-config.js';
|
|
8
9
|
import { prepareAsset as prepareFunctionAsset } from '../../utils/functions/prepare-asset.js';
|
|
10
|
+
import { prepareIconAsset } from '../../utils/icons/prepare-asset.js';
|
|
9
11
|
import { runCommand } from '../../utils/package-manager.js';
|
|
10
12
|
import { setupLogPolling } from './logs-polling.js';
|
|
11
13
|
import { getOperationStateInfo } from './operations-state.js';
|
|
@@ -21,11 +23,20 @@ const preDeployConfigs = [
|
|
|
21
23
|
return prepareBundleAsset({
|
|
22
24
|
resolvedResource: options.resolvedResource,
|
|
23
25
|
blueprintFileDir: options.blueprintFileDir,
|
|
26
|
+
stackId: options.stackId,
|
|
27
|
+
token: options.auth.token,
|
|
24
28
|
});
|
|
25
29
|
},
|
|
26
30
|
async prepareResource(options) {
|
|
27
31
|
await stampConfigVersion(options.resource, options.blueprintFileDir);
|
|
28
32
|
},
|
|
33
|
+
getIconInfo({ resolvedResource, blueprintFileDir }) {
|
|
34
|
+
// An installation config is a bundle too, but only applications and studios have an icon
|
|
35
|
+
const { icon, root } = resolvedResource.resource;
|
|
36
|
+
if (!icon || !root)
|
|
37
|
+
return undefined;
|
|
38
|
+
return { iconKey: 'icon', workDir: path.resolve(blueprintFileDir, root) };
|
|
39
|
+
},
|
|
29
40
|
},
|
|
30
41
|
{
|
|
31
42
|
resourceType: (type) => type.startsWith(SANITY_FUNCTION_PREFIX),
|
|
@@ -51,9 +62,14 @@ const preDeployConfigs = [
|
|
|
51
62
|
},
|
|
52
63
|
},
|
|
53
64
|
];
|
|
54
|
-
function hasPreDeployResources(resources) {
|
|
65
|
+
function hasPreDeployResources(resources, blueprintFileDir) {
|
|
55
66
|
return resources.some((r) => {
|
|
56
|
-
|
|
67
|
+
const config = getPredeployConfig(r);
|
|
68
|
+
if (!config)
|
|
69
|
+
return false;
|
|
70
|
+
return (!!config.prepareAsset ||
|
|
71
|
+
!!config.prepareResource ||
|
|
72
|
+
!!config.getIconInfo?.({ resolvedResource: { resource: r }, blueprintFileDir }));
|
|
57
73
|
});
|
|
58
74
|
}
|
|
59
75
|
function getPredeployConfig(r) {
|
|
@@ -65,7 +81,7 @@ function getPredeployConfig(r) {
|
|
|
65
81
|
export async function preDeploy(options) {
|
|
66
82
|
const { resources, stackId, auth, blueprintFileDir, installer, fetchFn } = options;
|
|
67
83
|
const resourceMetadata = [];
|
|
68
|
-
if (hasPreDeployResources(resources)) {
|
|
84
|
+
if (hasPreDeployResources(resources, blueprintFileDir)) {
|
|
69
85
|
for (const r of resources) {
|
|
70
86
|
const config = getPredeployConfig(r);
|
|
71
87
|
if (typeof config !== 'undefined' && typeof config.prepareResource === 'function') {
|
|
@@ -89,11 +105,20 @@ export async function preDeploy(options) {
|
|
|
89
105
|
if (typeof config !== 'undefined' && typeof config.prepareAsset === 'function') {
|
|
90
106
|
assetResources.push({ resource: r, prepareAsset: config.prepareAsset });
|
|
91
107
|
}
|
|
108
|
+
const iconInfo = config?.getIconInfo?.({ resolvedResource: r, blueprintFileDir });
|
|
109
|
+
if (iconInfo) {
|
|
110
|
+
assetResources.push({
|
|
111
|
+
resource: r,
|
|
112
|
+
prepareAsset: ({ blueprintFileDir }) => prepareIconAsset({ resolvedResource: r, blueprintFileDir, ...iconInfo }),
|
|
113
|
+
isIcon: true,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
92
116
|
}
|
|
93
117
|
let processedAssets = [];
|
|
94
118
|
try {
|
|
95
119
|
processedAssets = await processAssets({
|
|
96
120
|
assetResources,
|
|
121
|
+
stackId,
|
|
97
122
|
auth,
|
|
98
123
|
blueprintFileDir,
|
|
99
124
|
installer,
|
|
@@ -114,8 +139,16 @@ export async function preDeploy(options) {
|
|
|
114
139
|
// ! I think this error message is wrong. we somehow have an extra asset
|
|
115
140
|
if (idx === -1)
|
|
116
141
|
throw new Error('Unable to update resource asset');
|
|
117
|
-
|
|
118
|
-
|
|
142
|
+
if (!asset.success)
|
|
143
|
+
continue;
|
|
144
|
+
// A resource can have two assets (its bundle and its icon), so set only this one's parameter
|
|
145
|
+
const { assetParameter } = asset;
|
|
146
|
+
resources[idx] = {
|
|
147
|
+
...resources[idx],
|
|
148
|
+
[assetParameter]: asset.resource[assetParameter],
|
|
149
|
+
};
|
|
150
|
+
// the deploy metadata describes a resource's bundle, so an icon adds no second entry for it
|
|
151
|
+
if (!asset.isIcon) {
|
|
119
152
|
const { name, type } = asset.resource;
|
|
120
153
|
resourceMetadata.push({
|
|
121
154
|
name,
|
|
@@ -2,6 +2,7 @@ import type { BlueprintResource } from '@sanity/blueprints';
|
|
|
2
2
|
import type { AssetResource, AuthParams, InstallerType } from '../../utils/types.js';
|
|
3
3
|
type ProcessAssetsOptions<R extends BlueprintResource> = {
|
|
4
4
|
assetResources: AssetResource<R>[];
|
|
5
|
+
stackId: string;
|
|
5
6
|
auth: AuthParams;
|
|
6
7
|
blueprintFileDir: string;
|
|
7
8
|
installer: InstallerType;
|
|
@@ -23,6 +24,8 @@ export type ProcessedAsset<R extends BlueprintResource> = {
|
|
|
23
24
|
success: true;
|
|
24
25
|
resource: R;
|
|
25
26
|
assetParameter: string;
|
|
27
|
+
/** The asset is the resource's icon, not its source. */
|
|
28
|
+
isIcon?: boolean;
|
|
26
29
|
hash: string;
|
|
27
30
|
exists: boolean;
|
|
28
31
|
metadata?: Record<string, unknown>;
|
|
@@ -22,7 +22,7 @@ export async function processAssets(options) {
|
|
|
22
22
|
for (let start = 0; start < total; start += concurrency) {
|
|
23
23
|
const batch = assetResources.slice(start, start + concurrency);
|
|
24
24
|
const batchResults = await Promise.all(batch.map(async (assetResource) => {
|
|
25
|
-
const result = await processAsset(assetResource
|
|
25
|
+
const result = await processAsset(assetResource, options);
|
|
26
26
|
completed += 1;
|
|
27
27
|
reportProgress();
|
|
28
28
|
onResult?.(result);
|
|
@@ -42,14 +42,22 @@ function getAssetConcurrency() {
|
|
|
42
42
|
const configured = Number(env.SANITY_ASSET_CONCURRENCY);
|
|
43
43
|
return Number.isSafeInteger(configured) && configured > 0 ? configured : DEFAULT_ASSET_CONCURRENCY;
|
|
44
44
|
}
|
|
45
|
-
async function processAsset(resolvedResource, prepAsset, options) {
|
|
45
|
+
async function processAsset({ resource: resolvedResource, prepareAsset: prepAsset, isIcon }, options) {
|
|
46
46
|
const { resource } = resolvedResource;
|
|
47
|
-
const { auth, blueprintFileDir, installer, fetchFn } = options;
|
|
47
|
+
const { stackId, auth, blueprintFileDir, installer, fetchFn } = options;
|
|
48
48
|
let assetTimeoutTimer;
|
|
49
49
|
let result;
|
|
50
50
|
try {
|
|
51
51
|
result = await Promise.race([
|
|
52
|
-
stashAsset({
|
|
52
|
+
stashAsset({
|
|
53
|
+
resolvedResource,
|
|
54
|
+
prepAsset,
|
|
55
|
+
blueprintFileDir,
|
|
56
|
+
stackId,
|
|
57
|
+
auth,
|
|
58
|
+
fetchFn,
|
|
59
|
+
installer,
|
|
60
|
+
}),
|
|
53
61
|
new Promise((_, reject) => {
|
|
54
62
|
assetTimeoutTimer = setTimeout(() => {
|
|
55
63
|
reject(new Error(`Processing ${resource.name} timed out after ${assetTimeoutS}s`));
|
|
@@ -69,6 +77,7 @@ async function processAsset(resolvedResource, prepAsset, options) {
|
|
|
69
77
|
success: true,
|
|
70
78
|
resource: { ...resource, [result.assetParameter]: result.assetId },
|
|
71
79
|
assetParameter: result.assetParameter,
|
|
80
|
+
isIcon,
|
|
72
81
|
hash: result.hash,
|
|
73
82
|
exists: result.exists,
|
|
74
83
|
metadata: result.metadata,
|
|
@@ -228,7 +228,8 @@ function createAssetEventHandler(logger) {
|
|
|
228
228
|
}
|
|
229
229
|
const r = resource;
|
|
230
230
|
const assetParameter = String(r[result.assetParameter]);
|
|
231
|
-
|
|
231
|
+
const label = result.isIcon ? `${resource.name} ${result.assetParameter}` : resource.name;
|
|
232
|
+
logger(` ${check(`${label} ${niceId(assetParameter)}`)}`);
|
|
232
233
|
logger(` Source: ${assetParameter}`);
|
|
233
234
|
if (result.hash) {
|
|
234
235
|
const hash = result.hash;
|
|
@@ -2,6 +2,7 @@ import type { BlueprintApplicationResource, BlueprintInstallationConfigResource,
|
|
|
2
2
|
import { type BuildStudioEventListener } from '@sanity/cli-build/_internal/build';
|
|
3
3
|
import type { Output } from '@sanity/cli-core';
|
|
4
4
|
import type { AssetPrepResult, ResolvedResource } from '../types.js';
|
|
5
|
+
import { type ResourceBinding } from './resolve-resource-bindings.js';
|
|
5
6
|
export type BundleResource = BlueprintStudioResource | BlueprintApplicationResource | BlueprintInstallationConfigResource;
|
|
6
7
|
type BuildContext<R extends BundleResource> = {
|
|
7
8
|
resource: R;
|
|
@@ -9,6 +10,7 @@ type BuildContext<R extends BundleResource> = {
|
|
|
9
10
|
workDir: string;
|
|
10
11
|
outDir: string;
|
|
11
12
|
output: Output;
|
|
13
|
+
resourceBindings: ResourceBinding[];
|
|
12
14
|
eventListener: Partial<BuildStudioEventListener>;
|
|
13
15
|
};
|
|
14
16
|
type BuildResult = {
|
|
@@ -28,11 +30,13 @@ export declare const BUNDLE_SPECS: {
|
|
|
28
30
|
build: typeof buildInstallationConfigBundle;
|
|
29
31
|
};
|
|
30
32
|
};
|
|
31
|
-
export declare function prepareBundleAsset<R extends BundleResource>({ blueprintFileDir, resolvedResource, }: {
|
|
33
|
+
export declare function prepareBundleAsset<R extends BundleResource>({ blueprintFileDir, resolvedResource, stackId, token, }: {
|
|
32
34
|
blueprintFileDir: string;
|
|
33
35
|
resolvedResource: ResolvedResource<R>;
|
|
36
|
+
stackId: string;
|
|
37
|
+
token: string;
|
|
34
38
|
}): Promise<AssetPrepResult>;
|
|
35
|
-
declare function buildStudioBundle({ resource, appId, workDir, outDir, output, eventListener, }: BuildContext<BlueprintStudioResource>): Promise<BuildResult>;
|
|
39
|
+
declare function buildStudioBundle({ resource, appId, workDir, outDir, output, resourceBindings, eventListener, }: BuildContext<BlueprintStudioResource>): Promise<BuildResult>;
|
|
36
40
|
declare function buildApplicationBundle({ resource, appId, workDir, outDir, output, eventListener, }: BuildContext<BlueprintApplicationResource>): Promise<BuildResult>;
|
|
37
41
|
declare function buildInstallationConfigBundle({ resource, workDir, outDir, output, eventListener, }: BuildContext<BlueprintInstallationConfigResource>): Promise<BuildResult>;
|
|
38
42
|
export {};
|
|
@@ -9,12 +9,13 @@ import { buildStudioSchemasAndManifests } from '@sanity/cli-build/_internal/extr
|
|
|
9
9
|
import { getLocalPackageVersion } from '@sanity/cli-core';
|
|
10
10
|
import { pack } from 'tar-fs';
|
|
11
11
|
import { isRecord } from '../is-record.js';
|
|
12
|
+
import { resolveResourceBindings } from './resolve-resource-bindings.js';
|
|
12
13
|
export const BUNDLE_SPECS = {
|
|
13
14
|
'sanity.studio': { requiresAppId: true, build: buildStudioBundle },
|
|
14
15
|
'sanity.application': { requiresAppId: true, build: buildApplicationBundle },
|
|
15
16
|
'sanity.installation.config': { requiresAppId: false, build: buildInstallationConfigBundle },
|
|
16
17
|
};
|
|
17
|
-
export async function prepareBundleAsset({ blueprintFileDir, resolvedResource, }) {
|
|
18
|
+
export async function prepareBundleAsset({ blueprintFileDir, resolvedResource, stackId, token, }) {
|
|
18
19
|
const resource = resolvedResource.resource;
|
|
19
20
|
// The lookup can't prove it yields the spec matching this R, so it's asserted once here.
|
|
20
21
|
const spec = BUNDLE_SPECS[resource.type];
|
|
@@ -63,6 +64,11 @@ export async function prepareBundleAsset({ blueprintFileDir, resolvedResource, }
|
|
|
63
64
|
await rm(outDir, { force: true, recursive: true });
|
|
64
65
|
await rm(outFile, { force: true });
|
|
65
66
|
};
|
|
67
|
+
const resourceBindings = await resolveResourceBindings({
|
|
68
|
+
projectRootDir: workDir,
|
|
69
|
+
stackId,
|
|
70
|
+
token,
|
|
71
|
+
});
|
|
66
72
|
let mismatchedPackages;
|
|
67
73
|
try {
|
|
68
74
|
;
|
|
@@ -72,6 +78,7 @@ export async function prepareBundleAsset({ blueprintFileDir, resolvedResource, }
|
|
|
72
78
|
workDir,
|
|
73
79
|
outDir,
|
|
74
80
|
output: createSilentOutput(),
|
|
81
|
+
resourceBindings,
|
|
75
82
|
eventListener,
|
|
76
83
|
}));
|
|
77
84
|
}
|
|
@@ -106,7 +113,7 @@ export async function prepareBundleAsset({ blueprintFileDir, resolvedResource, }
|
|
|
106
113
|
};
|
|
107
114
|
}
|
|
108
115
|
}
|
|
109
|
-
async function buildStudioBundle({ resource, appId, workDir, outDir, output, eventListener, }) {
|
|
116
|
+
async function buildStudioBundle({ resource, appId, workDir, outDir, output, resourceBindings, eventListener, }) {
|
|
110
117
|
// this has been checked before we got here but this helps the type checker
|
|
111
118
|
if (!appId)
|
|
112
119
|
throw new Error(`Unable to determine appId for ${resource.type} resource '${resource.name}'`);
|
|
@@ -148,6 +155,7 @@ async function buildStudioBundle({ resource, appId, workDir, outDir, output, eve
|
|
|
148
155
|
configPath: resource.root,
|
|
149
156
|
isExternal: false,
|
|
150
157
|
outPath: outDir,
|
|
158
|
+
resourceBindings,
|
|
151
159
|
schemaRequired: false,
|
|
152
160
|
verbose: false,
|
|
153
161
|
workDir,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type ResourceBinding = {
|
|
2
|
+
type: string;
|
|
3
|
+
name: string;
|
|
4
|
+
id: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function resolveResourceBindings({ projectRootDir, stackId, token, }: {
|
|
7
|
+
projectRootDir: string;
|
|
8
|
+
stackId: string;
|
|
9
|
+
token: string;
|
|
10
|
+
}): Promise<ResourceBinding[]>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { dirname, resolve } from 'node:path';
|
|
2
|
+
import { findBlueprintFile, readBlueprint, readStack } from '@sanity/blueprints/resolve';
|
|
3
|
+
export async function resolveResourceBindings({ projectRootDir, stackId, token, }) {
|
|
4
|
+
try {
|
|
5
|
+
const blueprintFile = findBlueprintFile(projectRootDir);
|
|
6
|
+
if (!blueprintFile)
|
|
7
|
+
return [];
|
|
8
|
+
const localBlueprint = await readBlueprint({
|
|
9
|
+
path: blueprintFile,
|
|
10
|
+
});
|
|
11
|
+
const blueprintReferencesStudio = localBlueprint.resources.some((r) => {
|
|
12
|
+
if ('root' in r && typeof r.root === 'string') {
|
|
13
|
+
const root = resolve(dirname(blueprintFile), r.root);
|
|
14
|
+
return root === projectRootDir;
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
});
|
|
18
|
+
if (!blueprintReferencesStudio)
|
|
19
|
+
return [];
|
|
20
|
+
const stack = await readStack({
|
|
21
|
+
token,
|
|
22
|
+
overrides: { stackId },
|
|
23
|
+
});
|
|
24
|
+
return stack.resources
|
|
25
|
+
.filter((r) => r.externalId)
|
|
26
|
+
.map((r) => ({
|
|
27
|
+
type: r.type,
|
|
28
|
+
name: r.name,
|
|
29
|
+
id: r.externalId || '',
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
throw new Error(`Unable to resolve resources from blueprint in ${projectRootDir}`, {
|
|
34
|
+
cause: error,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { BlueprintResource } from '@sanity/blueprints';
|
|
2
|
+
import type { AssetPrepResult, IconInfo, ResolvedResource } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Reads the image at `resource[iconKey]`. The returned `assetParameter` is `iconKey`, so once
|
|
5
|
+
* the bytes are stashed that property is rewritten from the path to the asset ID.
|
|
6
|
+
*/
|
|
7
|
+
export declare function prepareIconAsset({ blueprintFileDir, resolvedResource, iconKey, workDir, }: IconInfo & {
|
|
8
|
+
blueprintFileDir: string;
|
|
9
|
+
resolvedResource: ResolvedResource<BlueprintResource>;
|
|
10
|
+
}): Promise<AssetPrepResult>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { readImageFile } from '@sanity/cli-core/images';
|
|
3
|
+
/**
|
|
4
|
+
* Reads the image at `resource[iconKey]`. The returned `assetParameter` is `iconKey`, so once
|
|
5
|
+
* the bytes are stashed that property is rewritten from the path to the asset ID.
|
|
6
|
+
*/
|
|
7
|
+
export async function prepareIconAsset({ blueprintFileDir, resolvedResource, iconKey, workDir, }) {
|
|
8
|
+
const { resource } = resolvedResource;
|
|
9
|
+
const cleanup = async () => { };
|
|
10
|
+
const icon = String(resource[iconKey]);
|
|
11
|
+
const baseDir = workDir ?? blueprintFileDir;
|
|
12
|
+
const iconPath = path.resolve(baseDir, icon);
|
|
13
|
+
// Defence in depth alongside blueprints-node's own check, as for 'root'
|
|
14
|
+
if (workDir && (path.isAbsolute(icon) || path.relative(workDir, iconPath).startsWith('..'))) {
|
|
15
|
+
return {
|
|
16
|
+
success: false,
|
|
17
|
+
cleanup,
|
|
18
|
+
error: `Property '${iconKey}' on resource '${resource.name}' must be a path inside "${path.relative(blueprintFileDir, workDir) || '.'}", such as './${iconKey}.png'.`,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const { image } = await readImageFile(iconPath);
|
|
23
|
+
return {
|
|
24
|
+
success: true,
|
|
25
|
+
cleanup,
|
|
26
|
+
outputBuffer: image,
|
|
27
|
+
// the provider derives the image's Content-Type from the stashed filename's extension
|
|
28
|
+
fileExtension: path.extname(iconPath).slice(1).toLowerCase(),
|
|
29
|
+
assetParameter: iconKey,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
34
|
+
return {
|
|
35
|
+
success: false,
|
|
36
|
+
cleanup,
|
|
37
|
+
error: `Unable to read '${iconKey}' on resource '${resource.name}': ${msg}`,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
package/dist/utils/types.d.ts
CHANGED
|
@@ -395,14 +395,25 @@ export type AssetPrepResult = {
|
|
|
395
395
|
export type PrepAssetFn<R extends BlueprintResource> = (options: {
|
|
396
396
|
resolvedResource: ResolvedResource<R>;
|
|
397
397
|
blueprintFileDir: string;
|
|
398
|
+
stackId: string;
|
|
399
|
+
auth: AuthParams;
|
|
398
400
|
installer?: InstallerType;
|
|
399
|
-
/** Deploy auth; the agent prep uses `auth.scopeId` for the manifest `sanityID`. */
|
|
400
|
-
auth?: AuthParams;
|
|
401
401
|
}) => Promise<AssetPrepResult>;
|
|
402
402
|
export type PrepResourceFn<R extends BlueprintResource> = (options: {
|
|
403
403
|
resource: R;
|
|
404
404
|
blueprintFileDir: string;
|
|
405
405
|
}) => Promise<void>;
|
|
406
|
+
/** Where a resource's icon image is, so it can be stashed as its own asset. */
|
|
407
|
+
export type IconInfo = {
|
|
408
|
+
/** The resource property holding the icon's path, such as `icon`. It's replaced with the asset ID. */
|
|
409
|
+
iconKey: string;
|
|
410
|
+
/** The directory the path is relative to, and must stay inside. Defaults to the blueprint file directory, without that limit. */
|
|
411
|
+
workDir?: string;
|
|
412
|
+
};
|
|
413
|
+
export type GetIconInfoFn<R extends BlueprintResource> = (options: {
|
|
414
|
+
resolvedResource: ResolvedResource<R>;
|
|
415
|
+
blueprintFileDir: string;
|
|
416
|
+
}) => IconInfo | undefined;
|
|
406
417
|
export type PreDeployConfig = {
|
|
407
418
|
/** The resource type this config applies to or a function that returns true if this config applies to the given type. */
|
|
408
419
|
resourceType: string | ((type: string) => boolean);
|
|
@@ -410,10 +421,14 @@ export type PreDeployConfig = {
|
|
|
410
421
|
prepareAsset?: PrepAssetFn<BlueprintResource>;
|
|
411
422
|
/** Function that mutates the resource before the pre-deploy is executed. */
|
|
412
423
|
prepareResource?: PrepResourceFn<BlueprintResource>;
|
|
424
|
+
/** Function that says where the resource's icon is, or returns nothing when it has none. */
|
|
425
|
+
getIconInfo?: GetIconInfoFn<BlueprintResource>;
|
|
413
426
|
};
|
|
414
427
|
export type AssetResource<R extends BlueprintResource> = {
|
|
415
428
|
resource: ResolvedResource<R>;
|
|
416
429
|
prepareAsset: PrepAssetFn<R>;
|
|
430
|
+
/** The asset is the resource's icon, not its source. */
|
|
431
|
+
isIcon?: boolean;
|
|
417
432
|
};
|
|
418
433
|
export type Warning = {
|
|
419
434
|
code: string;
|
package/oclif.manifest.json
CHANGED
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": "17.21.6-next.
|
|
4
|
+
"version": "17.21.6-next.gd629c70",
|
|
5
5
|
"author": "Sanity Runtime Team",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
"@sanity-labs/oclif-plugin-skills-flag": "^0.2.1",
|
|
73
73
|
"@sanity/blueprints": "^0.34.1",
|
|
74
74
|
"@sanity/blueprints-parser": "^0.5.0",
|
|
75
|
-
"@sanity/cli-build": "^7.
|
|
76
|
-
"@sanity/cli-core": "^3.
|
|
75
|
+
"@sanity/cli-build": "^7.4.0",
|
|
76
|
+
"@sanity/cli-core": "^3.16.0",
|
|
77
77
|
"@sanity/client": "^8.16.0",
|
|
78
78
|
"adm-zip": "^0.6.1",
|
|
79
79
|
"array-treeify": "^0.2.0",
|