sanity 3.76.4-server-side-schemas.18 → 3.76.4-server-side-schemas.20
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/lib/_chunks-cjs/fetchSchemaAction.js +7 -3
- package/lib/_chunks-cjs/fetchSchemaAction.js.map +1 -1
- package/lib/_chunks-cjs/storeSchemasAction.js +14 -19
- package/lib/_chunks-cjs/storeSchemasAction.js.map +1 -1
- package/lib/_chunks-cjs/version.js +1 -1
- package/lib/_chunks-es/version.mjs +1 -1
- package/lib/_legacy/version.esm.js +1 -1
- package/package.json +10 -10
- package/src/_internal/cli/actions/schema/fetchSchemaAction.ts +13 -7
- package/src/_internal/cli/actions/schema/storeSchemasAction.ts +22 -17
@@ -8,11 +8,15 @@ async function fetchSchemaAction(args, context) {
|
|
8
8
|
requireProject: !0
|
9
9
|
}).withConfig({
|
10
10
|
apiVersion: "v2024-08-01"
|
11
|
-
}), projectId = client.config().projectId, dataset = client.config().dataset, schema = await client.withConfig({
|
11
|
+
}), projectId = client.config().projectId, dataset = client.config().dataset, schema = (await client.withConfig({
|
12
12
|
dataset,
|
13
13
|
projectId
|
14
|
-
}).fetch(`*[_type == "sanity.workspace.schema" && _id == "${schemaId}"]`);
|
15
|
-
|
14
|
+
}).fetch(`*[_type == "sanity.workspace.schema" && _id == "${schemaId}"]`))[0];
|
15
|
+
if (!schema) {
|
16
|
+
spinner.fail(`Schema ${schemaId} not found`);
|
17
|
+
return;
|
18
|
+
}
|
19
|
+
spinner.succeed("Schema fetched:"), spinner.info(`${JSON.stringify(schema, null, 2)}`);
|
16
20
|
}
|
17
21
|
exports.default = fetchSchemaAction;
|
18
22
|
//# sourceMappingURL=fetchSchemaAction.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"fetchSchemaAction.js","sources":["../../src/_internal/cli/actions/schema/fetchSchemaAction.ts"],"sourcesContent":["import {type CliCommandArguments, type CliCommandContext} from '@sanity/cli'\
|
1
|
+
{"version":3,"file":"fetchSchemaAction.js","sources":["../../src/_internal/cli/actions/schema/fetchSchemaAction.ts"],"sourcesContent":["import {type CliCommandArguments, type CliCommandContext} from '@sanity/cli'\nimport {type SanityDocumentLike} from '@sanity/types'\n\nexport interface FetchSchemaFlags {\n id: string\n}\n\nexport default async function fetchSchemaAction(\n args: CliCommandArguments<FetchSchemaFlags>,\n context: CliCommandContext,\n): Promise<void> {\n const {apiClient, output} = context\n const flags = args.extOptions\n const schemaId = flags.id\n const spinner = output.spinner({}).start('Fetching schema')\n const client = apiClient({\n requireUser: true,\n requireProject: true,\n }).withConfig({apiVersion: 'v2024-08-01'})\n\n const projectId = client.config().projectId\n const dataset = client.config().dataset\n\n const schemas = await client\n .withConfig({\n dataset: dataset,\n projectId: projectId,\n })\n .fetch<SanityDocumentLike[]>(`*[_type == \"sanity.workspace.schema\" && _id == \"${schemaId}\"]`)\n\n //ids are unique so we can just take the first one\n const schema = schemas[0]\n if (!schema) {\n spinner.fail(`Schema ${schemaId} not found`)\n return\n }\n\n spinner.succeed('Schema fetched:')\n\n spinner.info(`${JSON.stringify(schema, null, 2)}`)\n}\n"],"names":["fetchSchemaAction","args","context","apiClient","output","schemaId","extOptions","id","spinner","start","client","requireUser","requireProject","withConfig","apiVersion","projectId","config","dataset","schema","fetch","fail","succeed","info","JSON","stringify"],"mappings":";AAO8BA,eAAAA,kBAC5BC,MACAC,SACe;AACT,QAAA;AAAA,IAACC;AAAAA,IAAWC;AAAAA,EAAAA,IAAUF,SAEtBG,WADQJ,KAAKK,WACIC,IACjBC,UAAUJ,OAAOI,QAAQ,CAAA,CAAE,EAAEC,MAAM,iBAAiB,GACpDC,SAASP,UAAU;AAAA,IACvBQ,aAAa;AAAA,IACbC,gBAAgB;AAAA,EACjB,CAAA,EAAEC,WAAW;AAAA,IAACC,YAAY;AAAA,EAAc,CAAA,GAEnCC,YAAYL,OAAOM,OAASD,EAAAA,WAC5BE,UAAUP,OAAOM,SAASC,SAU1BC,UARU,MAAMR,OACnBG,WAAW;AAAA,IACVI;AAAAA,IACAF;AAAAA,EAAAA,CACD,EACAI,MAA4B,mDAAmDd,QAAQ,IAAI,GAGvE,CAAC;AACxB,MAAI,CAACa,QAAQ;AACHE,YAAAA,KAAK,UAAUf,QAAQ,YAAY;AAC3C;AAAA,EAAA;AAGFG,UAAQa,QAAQ,iBAAiB,GAEjCb,QAAQc,KAAK,GAAGC,KAAKC,UAAUN,QAAQ,MAAM,CAAC,CAAC,EAAE;AACnD;;"}
|
@@ -1,9 +1,9 @@
|
|
1
1
|
"use strict";
|
2
|
-
var fs = require("node:fs"), path = require("node:path");
|
2
|
+
var fs = require("node:fs"), path = require("node:path"), chalk = require("chalk");
|
3
3
|
function _interopDefaultCompat(e) {
|
4
4
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
5
5
|
}
|
6
|
-
var path__default = /* @__PURE__ */ _interopDefaultCompat(path);
|
6
|
+
var path__default = /* @__PURE__ */ _interopDefaultCompat(path), chalk__default = /* @__PURE__ */ _interopDefaultCompat(chalk);
|
7
7
|
async function storeManifestSchemas(args, context) {
|
8
8
|
const flags = args.extOptions, workspaceName = flags.workspace, idPrefix = flags["id-prefix"], verbose = flags.verbose, {
|
9
9
|
output,
|
@@ -20,17 +20,15 @@ async function storeManifestSchemas(args, context) {
|
|
20
20
|
let manifest;
|
21
21
|
try {
|
22
22
|
manifest = JSON.parse(fs.readFileSync(`${manifestPath}/create-manifest.json`, "utf-8"));
|
23
|
-
} catch (
|
24
|
-
throw spinner.fail(`Manifest not found at ${manifestPath}/create-manifest.json`), output.error(
|
23
|
+
} catch (error2) {
|
24
|
+
throw spinner.fail(`Manifest not found at ${manifestPath}/create-manifest.json`), output.error(error2), error2;
|
25
25
|
}
|
26
|
-
let storedCount = 0;
|
26
|
+
let storedCount = 0, error;
|
27
27
|
const saveSchema = async (workspace) => {
|
28
28
|
const id = `${idPrefix || "sanity.workspace.schema"}.${workspace.name}`;
|
29
29
|
try {
|
30
|
-
if (workspace.projectId !== projectId)
|
31
|
-
|
32
|
-
return;
|
33
|
-
}
|
30
|
+
if (workspace.projectId !== projectId)
|
31
|
+
throw new Error(`No rights to store schema for workspace ${workspace.name} with projectId: ${workspace.projectId}`);
|
34
32
|
const schema = JSON.parse(fs.readFileSync(`${manifestPath}/${workspace.schema}`, "utf-8"));
|
35
33
|
await client.withConfig({
|
36
34
|
dataset: workspace.dataset,
|
@@ -40,10 +38,10 @@ async function storeManifestSchemas(args, context) {
|
|
40
38
|
_id: id,
|
41
39
|
workspace,
|
42
40
|
schema
|
43
|
-
}).commit(), storedCount++, spinner.text = `Stored ${storedCount} schemas so far...`, spinner.succeed(`Schema stored for workspace '${workspace.name}'`);
|
44
|
-
} catch (
|
45
|
-
|
46
|
-
|
41
|
+
}).commit(), storedCount++, spinner.text = `Stored ${storedCount} schemas so far...`, verbose && spinner.succeed(`Schema stored for workspace '${workspace.name}'`);
|
42
|
+
} catch (err) {
|
43
|
+
error = err, spinner.fail(`Error storing schema for workspace '${workspace.name}':
|
44
|
+
${chalk__default.default.red(`-${err.message}`)}`);
|
47
45
|
} finally {
|
48
46
|
verbose && spinner.info(`${JSON.stringify({
|
49
47
|
id,
|
@@ -55,18 +53,15 @@ async function storeManifestSchemas(args, context) {
|
|
55
53
|
};
|
56
54
|
if (workspaceName) {
|
57
55
|
const workspaceToSave = manifest.workspaces.find((workspace) => workspace.name === workspaceName);
|
58
|
-
|
59
|
-
throw spinner.fail(`Workspace ${workspaceName} not found in manifest`), new Error(`Workspace ${workspaceName} not found in manifest: projectID: ${projectId}`);
|
60
|
-
await saveSchema(workspaceToSave);
|
56
|
+
workspaceToSave ? await saveSchema(workspaceToSave) : (spinner.fail(`Workspace ${workspaceName} not found in manifest`), error = new Error(`Workspace ${workspaceName} not found in manifest: projectID: ${projectId}`));
|
61
57
|
} else
|
62
58
|
await Promise.all(manifest.workspaces.map(async (workspace) => {
|
63
59
|
await saveSchema(workspace);
|
64
60
|
}));
|
65
|
-
spinner.succeed(`Stored ${storedCount}/${manifest.workspaces.length} schemas`);
|
61
|
+
if (spinner.succeed(`Stored ${storedCount}/${manifest.workspaces.length} schemas`), error) throw error;
|
66
62
|
return;
|
67
63
|
} catch (err) {
|
68
|
-
if (
|
69
|
-
throw err;
|
64
|
+
if (flags["schema-required"]) throw err;
|
70
65
|
return err;
|
71
66
|
}
|
72
67
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"storeSchemasAction.js","sources":["../../src/_internal/cli/actions/schema/storeSchemasAction.ts"],"sourcesContent":["import {readFileSync} from 'node:fs'\nimport path, {join, resolve} from 'node:path'\n\nimport {type CliCommandArguments, type CliCommandContext} from '@sanity/cli'\n\nimport {\n type CreateManifest,\n type ManifestSchemaType,\n type ManifestWorkspaceFile,\n} from '../../../manifest/manifestTypes'\n\nexport interface StoreManifestSchemasFlags {\n 'path'?: string\n 'workspace'?: string\n 'id-prefix'?: string\n 'schema-required'?: boolean\n 'verbose'?: boolean\n}\n\nexport default async function storeManifestSchemas(\n args: CliCommandArguments<StoreManifestSchemasFlags>,\n context: CliCommandContext,\n): Promise<Error | undefined> {\n const flags = args.extOptions\n const workspaceName = flags.workspace\n const idPrefix = flags['id-prefix']\n const verbose = flags.verbose\n const {output, workDir, apiClient} = context\n\n const defaultOutputDir = resolve(join(workDir, 'dist'))\n\n const outputDir = resolve(defaultOutputDir)\n const defaultStaticPath = join(outputDir, 'static')\n\n const staticPath = flags.path ?? defaultStaticPath\n\n const spinner = output.spinner({}).start('Storing schemas')\n\n try {\n const manifestPath = path.resolve(process.cwd(), staticPath)\n const client = apiClient({\n requireUser: true,\n requireProject: true,\n }).withConfig({apiVersion: 'v2024-08-01'})\n\n const projectId = client.config().projectId\n\n let manifest: CreateManifest\n\n try {\n manifest = JSON.parse(readFileSync(`${manifestPath}/create-manifest.json`, 'utf-8'))\n } catch (error) {\n spinner.fail(`Manifest not found at ${manifestPath}/create-manifest.json`)\n output.error(error)\n throw error\n }\n\n let storedCount = 0\n\n const saveSchema = async (workspace: ManifestWorkspaceFile) => {\n const id = `${idPrefix || 'sanity.workspace.schema'}.${workspace.name}`\n try {\n if (workspace.projectId !== projectId) {\n
|
1
|
+
{"version":3,"file":"storeSchemasAction.js","sources":["../../src/_internal/cli/actions/schema/storeSchemasAction.ts"],"sourcesContent":["import {readFileSync} from 'node:fs'\nimport path, {join, resolve} from 'node:path'\n\nimport {type CliCommandArguments, type CliCommandContext} from '@sanity/cli'\nimport chalk from 'chalk'\n\nimport {\n type CreateManifest,\n type ManifestSchemaType,\n type ManifestWorkspaceFile,\n} from '../../../manifest/manifestTypes'\n\nexport interface StoreManifestSchemasFlags {\n 'path'?: string\n 'workspace'?: string\n 'id-prefix'?: string\n 'schema-required'?: boolean\n 'verbose'?: boolean\n}\n\nexport default async function storeManifestSchemas(\n args: CliCommandArguments<StoreManifestSchemasFlags>,\n context: CliCommandContext,\n): Promise<Error | undefined> {\n const flags = args.extOptions\n const workspaceName = flags.workspace\n const idPrefix = flags['id-prefix']\n const verbose = flags.verbose\n const {output, workDir, apiClient} = context\n\n const defaultOutputDir = resolve(join(workDir, 'dist'))\n\n const outputDir = resolve(defaultOutputDir)\n const defaultStaticPath = join(outputDir, 'static')\n\n const staticPath = flags.path ?? defaultStaticPath\n\n const spinner = output.spinner({}).start('Storing schemas')\n\n try {\n const manifestPath = path.resolve(process.cwd(), staticPath)\n const client = apiClient({\n requireUser: true,\n requireProject: true,\n }).withConfig({apiVersion: 'v2024-08-01'})\n\n const projectId = client.config().projectId\n\n let manifest: CreateManifest\n\n try {\n manifest = JSON.parse(readFileSync(`${manifestPath}/create-manifest.json`, 'utf-8'))\n } catch (error) {\n spinner.fail(`Manifest not found at ${manifestPath}/create-manifest.json`)\n output.error(error)\n throw error\n }\n\n let storedCount = 0\n\n let error: Error | undefined\n\n const saveSchema = async (workspace: ManifestWorkspaceFile) => {\n const id = `${idPrefix || 'sanity.workspace.schema'}.${workspace.name}`\n try {\n if (workspace.projectId !== projectId) {\n throw new Error(\n `No rights to store schema for workspace ${workspace.name} with projectId: ${workspace.projectId}`,\n )\n }\n const schema = JSON.parse(\n readFileSync(`${manifestPath}/${workspace.schema}`, 'utf-8'),\n ) as ManifestSchemaType\n await client\n .withConfig({\n dataset: workspace.dataset,\n projectId: workspace.projectId,\n })\n .transaction()\n .createOrReplace({_type: 'sanity.workspace.schema', _id: id, workspace, schema})\n .commit()\n storedCount++\n spinner.text = `Stored ${storedCount} schemas so far...`\n if (verbose) spinner.succeed(`Schema stored for workspace '${workspace.name}'`)\n } catch (err) {\n error = err\n spinner.fail(\n `Error storing schema for workspace '${workspace.name}':\\n${chalk.red(`-${err.message}`)}`,\n )\n } finally {\n if (verbose) {\n spinner.info(\n `${JSON.stringify(\n {\n id,\n workspace: workspace.name,\n projectId: workspace.projectId,\n dataset: workspace.dataset,\n },\n null,\n 2,\n )}`,\n )\n }\n }\n }\n\n // If a workspace name is provided, only save the schema for that workspace\n if (workspaceName) {\n const workspaceToSave = manifest.workspaces.find(\n (workspace) => workspace.name === workspaceName,\n )\n if (workspaceToSave) {\n await saveSchema(workspaceToSave)\n } else {\n spinner.fail(`Workspace ${workspaceName} not found in manifest`)\n error = new Error(\n `Workspace ${workspaceName} not found in manifest: projectID: ${projectId}`,\n )\n }\n } else {\n await Promise.all(\n manifest.workspaces.map(async (workspace): Promise<void> => {\n await saveSchema(workspace)\n }),\n )\n }\n\n spinner.succeed(`Stored ${storedCount}/${manifest.workspaces.length} schemas`)\n\n if (error) throw error\n return undefined\n } catch (err) {\n // if this flag is set, throw the error and exit without deploying otherwise just log the error\n if (flags['schema-required']) throw err\n return err\n }\n}\n"],"names":["storeManifestSchemas","args","context","flags","extOptions","workspaceName","workspace","idPrefix","verbose","output","workDir","apiClient","defaultOutputDir","resolve","join","outputDir","defaultStaticPath","staticPath","path","spinner","start","manifestPath","process","cwd","client","requireUser","requireProject","withConfig","apiVersion","projectId","config","manifest","JSON","parse","readFileSync","error","fail","storedCount","saveSchema","id","name","Error","schema","dataset","transaction","createOrReplace","_type","_id","commit","text","succeed","err","chalk","red","message","info","stringify","workspaceToSave","workspaces","find","Promise","all","map","length"],"mappings":"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"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "sanity",
|
3
|
-
"version": "3.76.4-server-side-schemas.
|
3
|
+
"version": "3.76.4-server-side-schemas.20+4a00da364b",
|
4
4
|
"description": "Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches",
|
5
5
|
"keywords": [
|
6
6
|
"sanity",
|
@@ -160,11 +160,11 @@
|
|
160
160
|
"@rexxars/react-json-inspector": "^9.0.1",
|
161
161
|
"@sanity/asset-utils": "^2.0.6",
|
162
162
|
"@sanity/bifur-client": "^0.4.1",
|
163
|
-
"@sanity/cli": "3.76.4-server-side-schemas.
|
163
|
+
"@sanity/cli": "3.76.4-server-side-schemas.20+4a00da364b",
|
164
164
|
"@sanity/client": "^6.28.0",
|
165
165
|
"@sanity/color": "^3.0.0",
|
166
166
|
"@sanity/comlink": "^3.0.1",
|
167
|
-
"@sanity/diff": "3.76.4-server-side-schemas.
|
167
|
+
"@sanity/diff": "3.76.4-server-side-schemas.20+4a00da364b",
|
168
168
|
"@sanity/diff-match-patch": "^3.1.1",
|
169
169
|
"@sanity/diff-patch": "^5.0.0",
|
170
170
|
"@sanity/eventsource": "^5.0.0",
|
@@ -174,15 +174,15 @@
|
|
174
174
|
"@sanity/import": "^3.37.9",
|
175
175
|
"@sanity/insert-menu": "^1.1.2",
|
176
176
|
"@sanity/logos": "^2.1.13",
|
177
|
-
"@sanity/migrate": "3.76.4-server-side-schemas.
|
178
|
-
"@sanity/mutator": "3.76.4-server-side-schemas.
|
177
|
+
"@sanity/migrate": "3.76.4-server-side-schemas.20+4a00da364b",
|
178
|
+
"@sanity/mutator": "3.76.4-server-side-schemas.20+4a00da364b",
|
179
179
|
"@sanity/presentation-comlink": "^1.0.7",
|
180
180
|
"@sanity/preview-url-secret": "^2.1.4",
|
181
|
-
"@sanity/schema": "3.76.4-server-side-schemas.
|
181
|
+
"@sanity/schema": "3.76.4-server-side-schemas.20+4a00da364b",
|
182
182
|
"@sanity/telemetry": "^0.7.7",
|
183
|
-
"@sanity/types": "3.76.4-server-side-schemas.
|
183
|
+
"@sanity/types": "3.76.4-server-side-schemas.20+4a00da364b",
|
184
184
|
"@sanity/ui": "^2.14.0",
|
185
|
-
"@sanity/util": "3.76.4-server-side-schemas.
|
185
|
+
"@sanity/util": "3.76.4-server-side-schemas.20+4a00da364b",
|
186
186
|
"@sanity/uuid": "^3.0.2",
|
187
187
|
"@sentry/react": "^8.33.0",
|
188
188
|
"@tanstack/react-table": "^8.16.0",
|
@@ -280,7 +280,7 @@
|
|
280
280
|
"@repo/dev-aliases": "3.76.3",
|
281
281
|
"@repo/package.config": "3.76.3",
|
282
282
|
"@repo/test-config": "3.76.3",
|
283
|
-
"@sanity/codegen": "3.76.4-server-side-schemas.
|
283
|
+
"@sanity/codegen": "3.76.4-server-side-schemas.20+4a00da364b",
|
284
284
|
"@sanity/generate-help-url": "^3.0.0",
|
285
285
|
"@sanity/pkg-utils": "6.13.4",
|
286
286
|
"@sanity/tsdoc": "1.0.169",
|
@@ -325,5 +325,5 @@
|
|
325
325
|
"engines": {
|
326
326
|
"node": ">=18"
|
327
327
|
},
|
328
|
-
"gitHead": "
|
328
|
+
"gitHead": "4a00da364baa5b79537d61df8e733a7016bb3bbf"
|
329
329
|
}
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import {type CliCommandArguments, type CliCommandContext} from '@sanity/cli'
|
2
|
-
|
3
|
-
import {type ManifestSchemaType} from '../../../manifest/manifestTypes'
|
2
|
+
import {type SanityDocumentLike} from '@sanity/types'
|
4
3
|
|
5
4
|
export interface FetchSchemaFlags {
|
6
5
|
id: string
|
@@ -22,14 +21,21 @@ export default async function fetchSchemaAction(
|
|
22
21
|
const projectId = client.config().projectId
|
23
22
|
const dataset = client.config().dataset
|
24
23
|
|
25
|
-
const
|
24
|
+
const schemas = await client
|
26
25
|
.withConfig({
|
27
26
|
dataset: dataset,
|
28
27
|
projectId: projectId,
|
29
28
|
})
|
30
|
-
.fetch<
|
29
|
+
.fetch<SanityDocumentLike[]>(`*[_type == "sanity.workspace.schema" && _id == "${schemaId}"]`)
|
30
|
+
|
31
|
+
//ids are unique so we can just take the first one
|
32
|
+
const schema = schemas[0]
|
33
|
+
if (!schema) {
|
34
|
+
spinner.fail(`Schema ${schemaId} not found`)
|
35
|
+
return
|
36
|
+
}
|
37
|
+
|
38
|
+
spinner.succeed('Schema fetched:')
|
31
39
|
|
32
|
-
spinner.
|
33
|
-
// print schema as json
|
34
|
-
output.success(JSON.stringify(schema, null, 2))
|
40
|
+
spinner.info(`${JSON.stringify(schema, null, 2)}`)
|
35
41
|
}
|
@@ -2,6 +2,7 @@ import {readFileSync} from 'node:fs'
|
|
2
2
|
import path, {join, resolve} from 'node:path'
|
3
3
|
|
4
4
|
import {type CliCommandArguments, type CliCommandContext} from '@sanity/cli'
|
5
|
+
import chalk from 'chalk'
|
5
6
|
|
6
7
|
import {
|
7
8
|
type CreateManifest,
|
@@ -57,14 +58,15 @@ export default async function storeManifestSchemas(
|
|
57
58
|
|
58
59
|
let storedCount = 0
|
59
60
|
|
61
|
+
let error: Error | undefined
|
62
|
+
|
60
63
|
const saveSchema = async (workspace: ManifestWorkspaceFile) => {
|
61
64
|
const id = `${idPrefix || 'sanity.workspace.schema'}.${workspace.name}`
|
62
65
|
try {
|
63
66
|
if (workspace.projectId !== projectId) {
|
64
|
-
|
65
|
-
`
|
67
|
+
throw new Error(
|
68
|
+
`No rights to store schema for workspace ${workspace.name} with projectId: ${workspace.projectId}`,
|
66
69
|
)
|
67
|
-
return
|
68
70
|
}
|
69
71
|
const schema = JSON.parse(
|
70
72
|
readFileSync(`${manifestPath}/${workspace.schema}`, 'utf-8'),
|
@@ -79,12 +81,12 @@ export default async function storeManifestSchemas(
|
|
79
81
|
.commit()
|
80
82
|
storedCount++
|
81
83
|
spinner.text = `Stored ${storedCount} schemas so far...`
|
82
|
-
spinner.succeed(`Schema stored for workspace '${workspace.name}'`)
|
83
|
-
} catch (
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
84
|
+
if (verbose) spinner.succeed(`Schema stored for workspace '${workspace.name}'`)
|
85
|
+
} catch (err) {
|
86
|
+
error = err
|
87
|
+
spinner.fail(
|
88
|
+
`Error storing schema for workspace '${workspace.name}':\n${chalk.red(`-${err.message}`)}`,
|
89
|
+
)
|
88
90
|
} finally {
|
89
91
|
if (verbose) {
|
90
92
|
spinner.info(
|
@@ -103,15 +105,19 @@ export default async function storeManifestSchemas(
|
|
103
105
|
}
|
104
106
|
}
|
105
107
|
|
108
|
+
// If a workspace name is provided, only save the schema for that workspace
|
106
109
|
if (workspaceName) {
|
107
110
|
const workspaceToSave = manifest.workspaces.find(
|
108
111
|
(workspace) => workspace.name === workspaceName,
|
109
112
|
)
|
110
|
-
if (
|
113
|
+
if (workspaceToSave) {
|
114
|
+
await saveSchema(workspaceToSave)
|
115
|
+
} else {
|
111
116
|
spinner.fail(`Workspace ${workspaceName} not found in manifest`)
|
112
|
-
|
117
|
+
error = new Error(
|
118
|
+
`Workspace ${workspaceName} not found in manifest: projectID: ${projectId}`,
|
119
|
+
)
|
113
120
|
}
|
114
|
-
await saveSchema(workspaceToSave)
|
115
121
|
} else {
|
116
122
|
await Promise.all(
|
117
123
|
manifest.workspaces.map(async (workspace): Promise<void> => {
|
@@ -121,13 +127,12 @@ export default async function storeManifestSchemas(
|
|
121
127
|
}
|
122
128
|
|
123
129
|
spinner.succeed(`Stored ${storedCount}/${manifest.workspaces.length} schemas`)
|
130
|
+
|
131
|
+
if (error) throw error
|
124
132
|
return undefined
|
125
133
|
} catch (err) {
|
126
|
-
|
127
|
-
|
128
|
-
if (flags['schema-required']) {
|
129
|
-
throw err
|
130
|
-
}
|
134
|
+
// if this flag is set, throw the error and exit without deploying otherwise just log the error
|
135
|
+
if (flags['schema-required']) throw err
|
131
136
|
return err
|
132
137
|
}
|
133
138
|
}
|