@sanity/runtime-cli 17.13.1 → 17.14.0-next.g792820f
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/pre-deploy.d.ts +1 -0
- package/dist/actions/blueprints/pre-deploy.js +21 -4
- package/dist/actions/blueprints/stacks.d.ts +6 -5
- package/dist/actions/blueprints/stacks.js +25 -12
- package/dist/baseCommands.js +7 -2
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +2 -0
- package/dist/cores/blueprints/deploy.js +10 -5
- package/dist/cores/blueprints/destroy.js +28 -17
- package/dist/cores/blueprints/plan.js +6 -2
- package/dist/cores/index.d.ts +2 -0
- package/dist/utils/bundles/prepare-asset.d.ts +38 -0
- package/dist/utils/bundles/prepare-asset.js +271 -0
- package/dist/utils/bundles/stamp-config-version.d.ts +5 -0
- package/dist/utils/bundles/stamp-config-version.js +45 -0
- package/dist/utils/display/blueprints-formatting.d.ts +5 -1
- package/dist/utils/display/blueprints-formatting.js +15 -2
- package/dist/utils/{blueprints → functions}/extract-durable-config.d.ts +2 -2
- package/dist/utils/functions/extract-durable-config.js +58 -0
- package/dist/utils/request-id.d.ts +4 -0
- package/dist/utils/request-id.js +19 -0
- package/dist/utils/types.d.ts +15 -0
- package/oclif.manifest.json +1 -1
- package/package.json +2 -2
- package/dist/utils/blueprints/extract-durable-config.js +0 -60
- package/dist/utils/studios/prepare-asset.d.ts +0 -6
- package/dist/utils/studios/prepare-asset.js +0 -166
|
@@ -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
|
-
}
|