@sanity/runtime-cli 17.1.0 → 17.2.0-blueprinit.gd1553d6

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.
Files changed (104) hide show
  1. package/README.md +38 -28
  2. package/dist/actions/blueprinit/manifest.d.ts +13 -0
  3. package/dist/actions/blueprinit/manifest.js +57 -0
  4. package/dist/actions/blueprinit/studio.d.ts +6 -0
  5. package/dist/actions/blueprinit/studio.js +43 -0
  6. package/dist/actions/blueprinit/templates.d.ts +34 -0
  7. package/dist/actions/blueprinit/templates.js +83 -0
  8. package/dist/actions/blueprinit/workspace.d.ts +15 -0
  9. package/dist/actions/blueprinit/workspace.js +142 -0
  10. package/dist/actions/blueprints/assets.d.ts +2 -1
  11. package/dist/actions/blueprints/assets.js +17 -26
  12. package/dist/actions/blueprints/blueprint.d.ts +1 -1
  13. package/dist/actions/blueprints/pre-deploy.d.ts +29 -0
  14. package/dist/actions/blueprints/pre-deploy.js +164 -0
  15. package/dist/actions/blueprints/wait-for-operation.js +4 -0
  16. package/dist/actions/sanity/datasets.d.ts +15 -0
  17. package/dist/actions/sanity/datasets.js +26 -0
  18. package/dist/actions/sanity/examples.d.ts +4 -4
  19. package/dist/baseCommands.d.ts +4 -4
  20. package/dist/commands/blueprinit.d.ts +13 -0
  21. package/dist/commands/blueprinit.js +44 -0
  22. package/dist/commands/blueprints/add.d.ts +1 -1
  23. package/dist/commands/blueprints/config.d.ts +1 -1
  24. package/dist/commands/blueprints/deploy.d.ts +1 -1
  25. package/dist/commands/blueprints/destroy.d.ts +1 -1
  26. package/dist/commands/blueprints/doctor.d.ts +0 -1
  27. package/dist/commands/blueprints/doctor.js +3 -7
  28. package/dist/commands/blueprints/info.d.ts +1 -1
  29. package/dist/commands/blueprints/logs.d.ts +1 -1
  30. package/dist/commands/blueprints/mint-deploy-token.d.ts +1 -1
  31. package/dist/commands/blueprints/plan.d.ts +1 -1
  32. package/dist/commands/blueprints/promote.d.ts +1 -1
  33. package/dist/commands/blueprints/stacks.d.ts +1 -1
  34. package/dist/commands/functions/add.d.ts +1 -1
  35. package/dist/commands/functions/build.d.ts +1 -1
  36. package/dist/commands/functions/dev.d.ts +1 -1
  37. package/dist/commands/functions/env/add.d.ts +4 -1
  38. package/dist/commands/functions/env/add.js +6 -2
  39. package/dist/commands/functions/env/list.d.ts +4 -1
  40. package/dist/commands/functions/env/list.js +9 -3
  41. package/dist/commands/functions/env/remove.d.ts +4 -1
  42. package/dist/commands/functions/env/remove.js +9 -3
  43. package/dist/commands/functions/logs.d.ts +1 -1
  44. package/dist/commands/functions/test.d.ts +1 -1
  45. package/dist/constants.d.ts +1 -0
  46. package/dist/constants.js +1 -0
  47. package/dist/cores/blueprinit/adopt.d.ts +6 -0
  48. package/dist/cores/blueprinit/adopt.js +90 -0
  49. package/dist/cores/blueprinit/finish.d.ts +14 -0
  50. package/dist/cores/blueprinit/finish.js +36 -0
  51. package/dist/cores/blueprinit/fresh.d.ts +3 -0
  52. package/dist/cores/blueprinit/fresh.js +88 -0
  53. package/dist/cores/blueprinit/prompts.d.ts +4 -0
  54. package/dist/cores/blueprinit/prompts.js +14 -0
  55. package/dist/cores/blueprinit/selection.d.ts +15 -0
  56. package/dist/cores/blueprinit/selection.js +63 -0
  57. package/dist/cores/blueprinit/types.d.ts +13 -0
  58. package/dist/cores/blueprinit/types.js +1 -0
  59. package/dist/cores/blueprinit.d.ts +7 -0
  60. package/dist/cores/blueprinit.js +39 -0
  61. package/dist/cores/blueprints/deploy.js +18 -65
  62. package/dist/cores/blueprints/doctor.js +15 -12
  63. package/dist/cores/functions/build.js +3 -2
  64. package/dist/cores/functions/test.js +4 -2
  65. package/dist/server/app.js +8 -2
  66. package/dist/server/static/favicon-dark.svg +1 -0
  67. package/dist/server/static/favicon.svg +1 -0
  68. package/dist/server/static/index.html +1 -1
  69. package/dist/server/static/vendor/vendor.bundle.js +5 -0
  70. package/dist/utils/functions/child-process-wrapper.js +13 -171
  71. package/dist/utils/functions/child-runtime/console.d.ts +1 -0
  72. package/dist/utils/functions/child-runtime/console.js +50 -0
  73. package/dist/utils/functions/child-runtime/invoke.d.ts +4 -0
  74. package/dist/utils/functions/child-runtime/invoke.js +47 -0
  75. package/dist/utils/functions/child-runtime/resources.d.ts +4 -0
  76. package/dist/utils/functions/child-runtime/resources.js +59 -0
  77. package/dist/utils/functions/find-entry-point.d.ts +1 -1
  78. package/dist/utils/functions/find-entry-point.js +10 -12
  79. package/dist/utils/functions/invoke/local.js +1 -1
  80. package/dist/utils/functions/invoke/prepare.d.ts +1 -1
  81. package/dist/utils/functions/invoke/prepare.js +19 -8
  82. package/dist/utils/functions/package-json.d.ts +1 -2
  83. package/dist/utils/functions/package-json.js +4 -6
  84. package/dist/utils/functions/prepare-asset.d.ts +2 -2
  85. package/dist/utils/functions/prepare-asset.js +18 -7
  86. package/dist/utils/functions/resolve-dependencies.d.ts +4 -1
  87. package/dist/utils/functions/resolve-dependencies.js +5 -6
  88. package/dist/utils/functions/resource-to-arc.d.ts +1 -1
  89. package/dist/utils/functions/resource-to-arc.js +4 -5
  90. package/dist/utils/functions/should-transpile.d.ts +7 -1
  91. package/dist/utils/functions/should-transpile.js +10 -10
  92. package/dist/utils/functions/transpile/function.d.ts +4 -1
  93. package/dist/utils/functions/transpile/function.js +9 -14
  94. package/dist/utils/functions/transpile/verify-handler.js +1 -1
  95. package/dist/utils/logger.d.ts +7 -5
  96. package/dist/utils/logger.js +33 -1
  97. package/dist/utils/progress.d.ts +5 -0
  98. package/dist/utils/progress.js +40 -0
  99. package/dist/utils/studios/prepare-asset.d.ts +6 -0
  100. package/dist/utils/studios/prepare-asset.js +139 -0
  101. package/dist/utils/types.d.ts +9 -8
  102. package/dist/utils/types.js +2 -3
  103. package/oclif.manifest.json +1049 -951
  104. package/package.json +30 -23
@@ -0,0 +1,139 @@
1
+ import { createWriteStream } from 'node:fs';
2
+ import { mkdtemp, 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 { pack } from 'tar-fs';
9
+ export async function prepareStudioAsset({ blueprintFileDir, resource, }) {
10
+ // validate resource has an externalId
11
+ if (!('externalId' in resource) ||
12
+ typeof resource.externalId !== 'string' ||
13
+ !resource.externalId) {
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
+ try {
27
+ const studioPathStat = await stat(studioPath);
28
+ if (!studioPathStat.isDirectory()) {
29
+ return {
30
+ success: false,
31
+ cleanup,
32
+ error: `Property 'src' on resource with type '${resource.type}' must be a directory`,
33
+ };
34
+ }
35
+ }
36
+ catch (error) {
37
+ const msg = error instanceof Error ? error.message : String(error);
38
+ return {
39
+ success: false,
40
+ cleanup,
41
+ error: `Unable to read given 'src' on resource with type '${resource.type}': ${msg}`,
42
+ };
43
+ }
44
+ try {
45
+ const outDir = await mkdtemp(join(tmpdir(), `studio-build-`));
46
+ const outFile = `${outDir}.tar.gz`;
47
+ cleanup = async () => {
48
+ await rm(outDir, { force: true, recursive: true });
49
+ await rm(outFile, { force: true });
50
+ };
51
+ const appId = resource.externalId;
52
+ try {
53
+ await buildStudio({
54
+ appId,
55
+ autoUpdatesEnabled: resource.autoUpdates.enabled,
56
+ checkAppId() { },
57
+ async compareDependencyVersions(packages) {
58
+ return compareDependencyVersions(packages, studioPath, { appId });
59
+ },
60
+ determineBasePath() {
61
+ return resource.basePath ?? '/';
62
+ },
63
+ isApp: false,
64
+ isWorkbenchApp: false,
65
+ minify: resource.minify ?? true,
66
+ outDir,
67
+ output: createSilentOutput(),
68
+ reactCompiler: resource.reactCompiler || false,
69
+ schemaExtraction: undefined,
70
+ sourceMap: resource.sourceMap ?? false,
71
+ stats: false,
72
+ unattendedMode: true,
73
+ // TODO pass in vite config from the studio resource
74
+ vite: undefined,
75
+ workDir: studioPath,
76
+ eventListener: {
77
+ onBuildFail({ message }) {
78
+ throw new Error(message);
79
+ },
80
+ onInvalidStyledComponentsVersionRange({ message }) {
81
+ throw new Error(message);
82
+ },
83
+ onNoDeclaredStyledComponentsVersion({ message }) {
84
+ throw new Error(message);
85
+ },
86
+ onNoInstalledSanityVersion({ message }) {
87
+ throw new Error(message);
88
+ },
89
+ onNoInstalledStyledComponentsVersion({ message }) {
90
+ throw new Error(message);
91
+ },
92
+ onPreReleaseInNonInteractiveAutoUpdate({ message }) {
93
+ throw new Error(message);
94
+ },
95
+ },
96
+ });
97
+ }
98
+ catch (error) {
99
+ const message = error instanceof Error ? error.message : String(error);
100
+ return {
101
+ success: false,
102
+ cleanup,
103
+ error: message,
104
+ };
105
+ }
106
+ // tar/gzip/write the built output
107
+ await pipeline(pack(dirname(outDir), { entries: [basename(outDir)] }), createGzip(), createWriteStream(outFile));
108
+ return {
109
+ success: true,
110
+ cleanup,
111
+ // studio must be pre built (e.g. with `npm run build`) and tarred/gzipped
112
+ outputPath: outFile,
113
+ };
114
+ }
115
+ catch (error) {
116
+ return {
117
+ success: false,
118
+ cleanup,
119
+ error: error instanceof Error ? error.message : String(error),
120
+ };
121
+ }
122
+ }
123
+ function createSilentOutput() {
124
+ return {
125
+ error(input, options) {
126
+ if (typeof options?.exit === 'number') {
127
+ if (input instanceof Error) {
128
+ throw input;
129
+ }
130
+ throw new Error(input);
131
+ }
132
+ return undefined;
133
+ },
134
+ log() { },
135
+ warn(input) {
136
+ return input;
137
+ },
138
+ };
139
+ }
@@ -1,4 +1,4 @@
1
- import { type BlueprintCorsOriginResource, type BlueprintDatasetResource, type BlueprintDocumentFunctionResource, type BlueprintDocumentWebhookResource, type BlueprintMediaLibraryAssetFunctionResource, type BlueprintProjectResource, type BlueprintResource, type BlueprintRobotResource, type BlueprintRoleResource, type BlueprintScheduledFunctionResource, type BlueprintSyncTagInvalidateFunctionResource } from '@sanity/blueprints';
1
+ import { type BlueprintCorsOriginResource, type BlueprintDatasetResource, type BlueprintDocumentFunctionResource, type BlueprintDocumentWebhookResource, type BlueprintMediaLibraryAssetFunctionResource, type BlueprintProjectResource, type BlueprintResource, type BlueprintRobotResource, type BlueprintRoleResource, type BlueprintScheduledFunctionResource, type BlueprintStudioResource, type BlueprintSyncTagInvalidateFunctionResource } from '@sanity/blueprints';
2
2
  export type ScopeType = 'organization' | 'project';
3
3
  /** Result utility type */
4
4
  export type Result<T, E = string> = {
@@ -16,12 +16,8 @@ export interface ActionResponse {
16
16
  /** @internal */
17
17
  export type FunctionGroqResource = BlueprintDocumentFunctionResource | BlueprintMediaLibraryAssetFunctionResource;
18
18
  export type FunctionResource = FunctionGroqResource | BlueprintScheduledFunctionResource | BlueprintSyncTagInvalidateFunctionResource;
19
- export interface StudioResource extends BlueprintResource {
20
- type: 'sanity.studio';
21
- src: string;
22
- }
23
19
  /** Resource types that carry a deployable asset (have src: string) */
24
- export type AssetResource = FunctionResource | StudioResource;
20
+ export type AssetResource = FunctionResource | BlueprintStudioResource;
25
21
  /** @internal */
26
22
  export interface AuthParams {
27
23
  token: string;
@@ -46,7 +42,7 @@ export declare function isProjectResource(r: unknown): r is BlueprintProjectReso
46
42
  export declare function isRobotResource(r: unknown): r is BlueprintRobotResource;
47
43
  export declare function isRoleResource(r: unknown): r is BlueprintRoleResource;
48
44
  export declare function isDatasetResource(r: unknown): r is BlueprintDatasetResource;
49
- export declare function isStudioResource(r: BlueprintResource): r is StudioResource;
45
+ export declare function isStudioResource(r: BlueprintResource): r is BlueprintStudioResource;
50
46
  export declare function isAssetResource(r: BlueprintResource): r is AssetResource;
51
47
  export declare function isWebhookResource(r: unknown): r is BlueprintDocumentWebhookResource;
52
48
  interface StackBase {
@@ -84,6 +80,7 @@ export interface StackMutation {
84
80
  resources?: BlueprintResource[];
85
81
  };
86
82
  userMessage?: string;
83
+ preDeploy?: boolean;
87
84
  }
88
85
  /** @internal */
89
86
  export interface BuildPayloadOptions {
@@ -126,6 +123,8 @@ export interface InvokeGroqContextOptions {
126
123
  functionResourceId: string;
127
124
  /** All resources declared by the blueprint, used to populate `context.resources` at invoke time. */
128
125
  resources?: BlueprintResource[];
126
+ /** The directory where the blueprint manifest is located. */
127
+ blueprintFileDir: string;
129
128
  }
130
129
  /** @internal */
131
130
  export interface InvokeScheduleContextOptions {
@@ -134,6 +133,8 @@ export interface InvokeScheduleContextOptions {
134
133
  };
135
134
  /** All resources declared by the blueprint, used to populate `context.resources` at invoke time. */
136
135
  resources?: BlueprintResource[];
136
+ /** The directory where the blueprint manifest is located. */
137
+ blueprintFileDir: string;
137
138
  }
138
139
  export type InvokeContextOptions = InvokeGroqContextOptions | InvokeScheduleContextOptions;
139
140
  export declare function isGroqContextOptions(context: InvokeContextOptions): context is InvokeGroqContextOptions;
@@ -265,7 +266,7 @@ export declare interface FetchConfig {
265
266
  apiHost?: string;
266
267
  apiVersion?: string;
267
268
  }
268
- export declare const INSTALLER_OPTIONS: readonly ["npm", "pnpm", "yarn"];
269
+ export declare const INSTALLER_OPTIONS: readonly ['npm', 'pnpm', 'yarn'];
269
270
  export type InstallerType = 'npm' | 'pnpm' | 'yarn';
270
271
  export type AssetPrepResult = {
271
272
  success: true;
@@ -1,5 +1,5 @@
1
1
  import { validateCorsOrigin, validateDataset, validateDocumentWebhook, validateProject, validateRobot, validateRole, } from '@sanity/blueprints';
2
- import { SANITY_FUNCTION_PREFIX } from '../constants.js';
2
+ import { SANITY_FUNCTION_PREFIX, SANITY_STUDIO } from '../constants.js';
3
3
  export function isLocalFunctionResource(r) {
4
4
  return r.type.startsWith(SANITY_FUNCTION_PREFIX);
5
5
  }
@@ -22,9 +22,8 @@ export function isRoleResource(r) {
22
22
  export function isDatasetResource(r) {
23
23
  return validateDataset(r).length === 0;
24
24
  }
25
- // TODO: update to use blueprints helpers once available
26
25
  export function isStudioResource(r) {
27
- return r.type === 'sanity.studio';
26
+ return r.type === SANITY_STUDIO;
28
27
  }
29
28
  export function isAssetResource(r) {
30
29
  return isLocalFunctionResource(r) || isStudioResource(r);