storyblok 4.26.1 → 4.26.2

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 CHANGED
@@ -3,13 +3,13 @@
3
3
  ![Storyblok ImagoType](https://raw.githubusercontent.com/storyblok/.github/refs/heads/main/profile/public/github-banner.png)
4
4
 
5
5
  <h1>Storyblok CLI</h1>
6
- <p>A powerful CLI tool to improve the DX of your <a href="https://www.storyblok.com?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok" target="_blank">Storyblok</a> projects.</p>
6
+ <p>The command-line interface for <a href="https://www.storyblok.com?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok" target="_blank">Storyblok</a> projects.</p>
7
7
  <br />
8
8
  </div>
9
9
 
10
10
  <p align="center">
11
11
  <a href="https://npmjs.com/package/storyblok">
12
- <img src="https://img.shields.io/npm/v/storyblok/latest.svg?style=flat-square&color=8d60ff" alt="Storyblok JS Client" />
12
+ <img src="https://img.shields.io/npm/v/storyblok/latest.svg?style=flat-square&color=8d60ff" alt="Storyblok CLI" />
13
13
  </a>
14
14
  <a href="https://npmjs.com/package/storyblok" rel="nofollow">
15
15
  <img src="https://img.shields.io/npm/dt/storyblok.svg?style=appveyor&color=8d60ff" alt="npm">
@@ -27,94 +27,32 @@
27
27
 
28
28
  ## Features
29
29
 
30
- - 🛡️ **Type Safety** - Generate TypeScript type definitions for your Storyblok components, ensuring
31
- type safety in your frontend applications
32
- - 🔐 **Authentication** - Secure login system with support for different regions and CI environments
33
- - 🧩 **Component Management** - Pull and push component schemas, groups, presets, and internal tags
34
- between spaces
35
- - 🔄 **Migration System** - Generate and run migrations to transform or update field values across
36
- your Storyblok content
37
- - 🌐 **Language Management** - Pull and manage languages for your Storyblok space
38
- - 📁 **File Organization** - Organized file structure with the `.storyblok` directory as default
39
- - 🛠️ **Customizable Paths** - Flexible path configuration for all generated files
40
- - 📝 **Naming Conventions** - Consistent file naming with customizable suffixes and prefixes
41
- - 📂 **Separate Files Support** - Option to work with individual component files or consolidated
42
- files
43
- - 👀 **Dry Run Mode** - Preview migrations changes before applying them to your Storyblok space
44
- - 🔍 **Filtering Capabilities** - Filter components and stories using glob patterns and Storyblok
45
- query syntax
46
- - 🔎 **Content Search** - Find stories by text, block usage, tags, workflow stage, or a JSONPath
47
- expression over their content, and stream the matches as JSONL for `jq` and other commands
48
- - 📊 **Verbose Logging** - Improved error handling and detailed logging options for debugging and
49
- monitoring
50
-
51
- ## Pre-requisites
52
-
53
- - [Node.js >= 18.0.0](https://nodejs.org/en/download/)
54
- - Storyblok account (sign up
55
- [here](https://app.storyblok.com/#!/signup?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-cli))
56
- - Personal access token from Storyblok (get it
57
- [here](https://app.storyblok.com/#/me/account?tab=token))
30
+ - **Type generation**: Generate TypeScript types from component schemas
31
+ - **Code-defined schema**: Validate, diff, push, and roll back schemas authored with
32
+ `@storyblok/schema`
33
+ - **Content sync**: Pull and push stories, components, assets, datasources, and languages between
34
+ spaces
35
+ - **Content migrations**: Generate, run, and roll back migrations that transform story content
36
+ - **Content search**: Find stories by text, block, tag, workflow stage, or JSONPath expression and
37
+ stream the matches as JSONL
38
+ - **Project scaffolding**: Create a project from a core blueprint, connected to a new space
39
+ - **CI-friendly**: Token login, configuration files, logs, and run reports
58
40
 
59
41
  ## Documentation
60
42
 
61
43
  For complete documentation, please visit the
62
44
  [package reference](https://www.storyblok.com/docs/tooling/cli).
63
45
 
64
- ## Setup
65
-
66
- This package relies on [pnpm](https://pnpm.io/) to manage dependencies. For instructions on how to
67
- install pnpm, please visit [pnpm.io](https://pnpm.io/installation).
68
-
69
- ```bash
70
- pnpm install
71
- ```
72
-
73
- ## Build
74
-
75
- ```bash
76
- pnpm build
77
- ```
78
-
79
- ### Testing
80
-
81
- To run the tests you can use the following command:
82
-
83
- ```bash
84
- pnpm run test
85
- ```
86
-
87
- If you prefer a more visual experience while writing tests you can use this command powered by
88
- [vitest/ui](https://vitest.dev/guide/ui):
89
-
90
- ```bash
91
- pnpm run test:ui
92
- ```
93
-
94
- You can also check the coverage with:
95
-
96
- ```bash
97
- pnpm run test:coverage
98
- ```
99
-
100
- ### Debugging
101
-
102
- To debug the CLI you can use the `launch.json` configuration in the `.vscode` folder. You can run
103
- any command with the debugger attached.
104
-
105
- ![A screenshot of the Visual Studio Code debugger](/.github/assets/debug-vscode.png)
106
-
107
- Then you can set breakpoints directly to the typescript files and the debugger will handle the rest
108
- with sourcempaps.
46
+ ## Contributing
109
47
 
110
- ![A screenshot of a breakpoint set in the Visual Studio Code debugger](/.github/assets/breakpoints.png)
48
+ If you'd like to contribute, please refer to the [contributing guidelines](../../CONTRIBUTING.md).
111
49
 
112
50
  ## Community
113
51
 
114
52
  For help, discussion about best practices, or any other conversation that would benefit from being
115
53
  searchable:
116
54
 
117
- - [Discuss Storyblok on GitHub Discussions](https://github.com/storyblok/storyblok/discussions)
55
+ - [Discuss Storyblok on GitHub Discussions](https://github.com/storyblok/monoblok/discussions)
118
56
 
119
57
  For community support, chatting with other users, please visit:
120
58
 
@@ -123,7 +61,7 @@ For community support, chatting with other users, please visit:
123
61
  ## Support
124
62
 
125
63
  For bugs or feature requests, please
126
- [submit an issue](https://github.com/storyblok/storyblok-cli/issues/new/choose).
64
+ [submit an issue](https://github.com/storyblok/monoblok/issues/new/choose).
127
65
 
128
66
  > [!IMPORTANT] Please search existing issues before submitting a new one. Issues without a minimal
129
67
  > reproducible example will be closed.
@@ -137,16 +75,11 @@ minimal reproducible example that demonstrates the issue by using tools like
137
75
  README file with the instructions to build and run the project, important not to include any access
138
76
  token, password or personal information of any kind.
139
77
 
140
- ### I only have a question
78
+ ### Feedback
141
79
 
142
80
  If you have a question, please ask in the
143
81
  [Discuss Storyblok on Discord](https://storyblok.com/join-discord) channel.
144
82
 
145
- ## Contributing
146
-
147
- If you're interested in contributing to Storyblok CLI, please read our
148
- [contributing docs](../../CONTRIBUTING.md) before submitting a pull request.
149
-
150
83
  ## License
151
84
 
152
- [License](/LICENSE)
85
+ [License](./LICENSE)
package/dist/index.mjs CHANGED
@@ -22,13 +22,13 @@ import { Readable, Transform, Writable, pipeline } from "node:stream";
22
22
  import { Sema } from "async-sema";
23
23
  import { hash } from "ohash";
24
24
  import { compile } from "json-schema-to-typescript";
25
+ import { DENIABLE_FIELD_TYPES, TAG_LIST_KEYS, isLayoutFieldType } from "@storyblok/schema";
25
26
  import open from "open";
26
27
  import { Octokit } from "octokit";
27
28
  import { pipeline as pipeline$1 } from "node:stream/promises";
28
29
  import { Buffer } from "node:buffer";
29
30
  import { ClientError, createApiClient } from "@storyblok/api-client";
30
31
  import { compile as compile$1 } from "json-p3";
31
- import { DENIABLE_FIELD_TYPES, TAG_LIST_KEYS } from "@storyblok/schema";
32
32
  import * as officialFieldPlugins from "@storyblok/schema/field-plugins";
33
33
  import { createTwoFilesPatch } from "diff";
34
34
  //#region src/constants.ts
@@ -1722,6 +1722,51 @@ const __dirname = dirname(__filename);
1722
1722
  function isRegion(value) {
1723
1723
  return Object.values(regions).includes(value);
1724
1724
  }
1725
+ //#endregion
1726
+ //#region src/utils/filesystem.ts
1727
+ /** `runId` is the run's start time in ms; it orders log and report files for listing and pruning. */
1728
+ function getRunFileName(commandPieces, runId, extension) {
1729
+ return `${commandPieces.join("-")}-${runId}${extension}`;
1730
+ }
1731
+ const RUN_ID_PATTERN = /-(\d+)$/;
1732
+ function getRunId(file) {
1733
+ const match = RUN_ID_PATTERN.exec(parse(file).name);
1734
+ return match ? Number(match[1]) : void 0;
1735
+ }
1736
+ function compareCodeUnits(a, b) {
1737
+ if (a === b) return 0;
1738
+ return a < b ? -1 : 1;
1739
+ }
1740
+ /**
1741
+ * Lists the log or report file names in `directory`, oldest run first. Ignores
1742
+ * files without a run ID.
1743
+ */
1744
+ function listRunFiles(directory, extension) {
1745
+ if (!existsSync(directory)) return [];
1746
+ return readdirSync(directory, { withFileTypes: true }).filter((entry) => !entry.isDirectory() && extname(entry.name) === extension).flatMap((entry) => {
1747
+ const runId = getRunId(entry.name);
1748
+ return runId === void 0 ? [] : [{
1749
+ name: entry.name,
1750
+ runId
1751
+ }];
1752
+ }).sort((a, b) => a.runId - b.runId || compareCodeUnits(a.name, b.name)).map((file) => file.name);
1753
+ }
1754
+ /** Deletes the oldest files until `keep` remain, never `currentFile`, and returns how many it deleted. */
1755
+ function pruneRunFiles(directory, extension, keep, currentFile) {
1756
+ const files = listRunFiles(directory, extension);
1757
+ const filesToDelete = files.filter((file) => file !== currentFile).slice(0, Math.max(0, files.length - keep));
1758
+ for (const file of filesToDelete) try {
1759
+ unlinkSync(join(directory, file));
1760
+ } catch (maybeError) {
1761
+ const error = toError(maybeError);
1762
+ if (!("code" in error && error.code === "ENOENT")) throw error;
1763
+ }
1764
+ return filesToDelete.length;
1765
+ }
1766
+ /** Prunes the run files next to `currentFilePath`, never deleting it. */
1767
+ function pruneSiblingRunFiles(currentFilePath, keep) {
1768
+ return pruneRunFiles(dirname(currentFilePath), extname(currentFilePath), keep, basename(currentFilePath));
1769
+ }
1725
1770
  const getStoryblokGlobalPath = () => {
1726
1771
  const homeDirectory = process.env[process.platform.startsWith("win") ? "USERPROFILE" : "HOME"] || process.cwd();
1727
1772
  return join(homeDirectory, ".storyblok");
@@ -1903,6 +1948,7 @@ const REPORT_STATUS = {
1903
1948
  failure: "FAILURE"
1904
1949
  };
1905
1950
  var Reporter = class Reporter {
1951
+ static FILE_EXTENSION = ".json";
1906
1952
  filePath;
1907
1953
  enabled;
1908
1954
  startedAt = /* @__PURE__ */ new Date();
@@ -1914,7 +1960,7 @@ var Reporter = class Reporter {
1914
1960
  };
1915
1961
  constructor(options) {
1916
1962
  this.enabled = options?.enabled || false;
1917
- this.filePath = options?.filePath ?? `./${Date.now()}.json`;
1963
+ this.filePath = options?.filePath ?? `./${Date.now()}${Reporter.FILE_EXTENSION}`;
1918
1964
  this.maxFiles = options?.maxFiles;
1919
1965
  }
1920
1966
  addMeta(key, value) {
@@ -1932,7 +1978,7 @@ var Reporter = class Reporter {
1932
1978
  this.report.meta.durationMs = endedAt.getTime() - this.startedAt.getTime();
1933
1979
  this.updateStatus();
1934
1980
  saveToFileSync(this.filePath, JSON.stringify(this.report, null, 2));
1935
- if (this.maxFiles !== void 0) this.pruneOldFiles();
1981
+ if (this.maxFiles !== void 0) pruneSiblingRunFiles(this.filePath, this.maxFiles);
1936
1982
  }
1937
1983
  updateStatus() {
1938
1984
  let succeededTotal = 0;
@@ -1945,23 +1991,11 @@ var Reporter = class Reporter {
1945
1991
  else if (succeededTotal > 0) this.report.status = REPORT_STATUS.partialSuccess;
1946
1992
  else this.report.status = REPORT_STATUS.failure;
1947
1993
  }
1948
- pruneOldFiles() {
1949
- if (this.maxFiles === void 0) return;
1950
- const dir = dirname(this.filePath);
1951
- const ext = extname(this.filePath);
1952
- Reporter.pruneReportFiles(dir, this.maxFiles, ext);
1953
- }
1954
- static pruneReportFiles(directory, keep, extension = ".json") {
1955
- if (!existsSync(directory)) return 0;
1956
- const files = readdirSync(directory).filter((file) => extname(file) === extension).sort();
1957
- const filesToDelete = files.length - keep;
1958
- if (filesToDelete <= 0) return 0;
1959
- for (const file of files.slice(0, filesToDelete)) unlinkSync(join(directory, file));
1960
- return filesToDelete;
1994
+ static pruneReportFiles(directory, keep) {
1995
+ return pruneRunFiles(directory, Reporter.FILE_EXTENSION, keep);
1961
1996
  }
1962
- static listReportFiles(directory, extension = ".json") {
1963
- if (!existsSync(directory)) return [];
1964
- return readdirSync(directory).filter((file) => extname(file) === extension).map((f) => relative(process.cwd(), join(directory, f))).sort();
1997
+ static listReportFiles(directory) {
1998
+ return listRunFiles(directory, Reporter.FILE_EXTENSION).map((file) => relative(process.cwd(), join(directory, file)));
1965
1999
  }
1966
2000
  };
1967
2001
  let reporterInstance = null;
@@ -1972,12 +2006,13 @@ function getReporter(options) {
1972
2006
  //#endregion
1973
2007
  //#region src/lib/logger/logger-transport-file.ts
1974
2008
  var FileTransport = class FileTransport {
2009
+ static FILE_EXTENSION = ".jsonl";
1975
2010
  filePath;
1976
2011
  level;
1977
2012
  maxFiles;
1978
2013
  hasPruned = false;
1979
2014
  constructor(options) {
1980
- this.filePath = options?.filePath ?? `./${Date.now()}.jsonl`;
2015
+ this.filePath = options?.filePath ?? `./${Date.now()}${FileTransport.FILE_EXTENSION}`;
1981
2016
  this.level = options?.level ?? "info";
1982
2017
  this.maxFiles = options?.maxFiles;
1983
2018
  }
@@ -1987,34 +2022,14 @@ var FileTransport = class FileTransport {
1987
2022
  appendToFileSync(this.filePath, line);
1988
2023
  if (!this.hasPruned && this.maxFiles !== void 0) {
1989
2024
  this.hasPruned = true;
1990
- this.pruneOldFiles();
1991
- }
1992
- }
1993
- pruneOldFiles() {
1994
- if (this.maxFiles === void 0) return;
1995
- const dir = dirname(this.filePath);
1996
- const ext = extname(this.filePath);
1997
- FileTransport.pruneLogFiles(dir, this.maxFiles, ext);
1998
- }
1999
- static pruneLogFiles(directory, keep, extension = ".jsonl") {
2000
- if (!existsSync(directory)) return 0;
2001
- const files = readdirSync(directory).filter((file) => extname(file) === extension).sort();
2002
- const filesToDelete = files.length - keep;
2003
- if (filesToDelete <= 0) return 0;
2004
- let deleted = 0;
2005
- for (const file of files.slice(0, filesToDelete)) {
2006
- try {
2007
- unlinkSync(join(directory, file));
2008
- } catch (error) {
2009
- if (error.code !== "ENOENT") throw error;
2010
- }
2011
- deleted += 1;
2025
+ pruneSiblingRunFiles(this.filePath, this.maxFiles);
2012
2026
  }
2013
- return deleted;
2014
2027
  }
2015
- static listLogFiles(directory, extension = ".jsonl") {
2016
- if (!existsSync(directory)) return [];
2017
- return readdirSync(directory).filter((file) => extname(file) === extension).sort().map((f) => join(directory, f).replace(process.cwd(), "."));
2028
+ static pruneLogFiles(directory, keep) {
2029
+ return pruneRunFiles(directory, FileTransport.FILE_EXTENSION, keep);
2030
+ }
2031
+ static listLogFiles(directory) {
2032
+ return listRunFiles(directory, FileTransport.FILE_EXTENSION).map((file) => join(directory, file).replace(process.cwd(), "."));
2018
2033
  }
2019
2034
  levelRank(level) {
2020
2035
  switch (level) {
@@ -2299,7 +2314,7 @@ function getProgram() {
2299
2314
  if (resolvedConfig.log.console.enabled) transports.push(new ConsoleTransport({ level: resolvedConfig.log.console.level }));
2300
2315
  if (resolvedConfig.log.file.enabled) {
2301
2316
  const logsPath = resolveCommandPath(directories.logs, options.space, options.path);
2302
- const logFilename = `${commandPieces.join("-")}-${runId}.jsonl`;
2317
+ const logFilename = getRunFileName(commandPieces, runId, FileTransport.FILE_EXTENSION);
2303
2318
  logFilePath = join(logsPath, logFilename);
2304
2319
  transports.push(new FileTransport({
2305
2320
  filePath: logFilePath,
@@ -2319,7 +2334,7 @@ function getProgram() {
2319
2334
  getUI({ enabled: resolvedConfig.ui.enabled });
2320
2335
  if (resolvedConfig.report.enabled) {
2321
2336
  const reportPath = resolveCommandPath(directories.reports, options.space, options.path);
2322
- const reportFilename = `${commandPieces.join("-")}-${runId}.json`;
2337
+ const reportFilename = getRunFileName(commandPieces, runId, Reporter.FILE_EXTENSION);
2323
2338
  const reporter = getReporter({
2324
2339
  enabled: true,
2325
2340
  filePath: join(reportPath, reportFilename),
@@ -5831,8 +5846,6 @@ const DECLARATION_REGION_START = "//#region";
5831
5846
  const DECLARATION_REGION_MARKER = /^\/\/#(?:end)?region\b.*\n?/gm;
5832
5847
  const SOURCE_MAP_START = "//# sourceMappingURL=";
5833
5848
  const IMPORT_STATEMENT = /^import\s+(?:(.+?)\s+from\s+)?["'][^"']+["'];?[ \t]*$/gm;
5834
- const LAYOUT_FIELD_TYPES = /* @__PURE__ */ new Set(["section", "tab"]);
5835
- const isLayoutFieldType = (type) => LAYOUT_FIELD_TYPES.has(type);
5836
5849
  const getDatasourceTypeTitle = (slug) => `${toPascalCase(slug)}DataSource`;
5837
5850
  const getImportedBindings = (content) => [...content.matchAll(IMPORT_STATEMENT)].flatMap(([, clause]) => clause?.split(/[{},]/) ?? []).map((binding) => binding.trim().split(/\s+as\s+/).pop() ?? "").filter(Boolean);
5838
5851
  /**
@@ -5888,11 +5901,20 @@ const getPropertyTypeAnnotation = (property, prefix, suffix) => {
5888
5901
  case "boolean": return { type: "boolean" };
5889
5902
  case "datetime":
5890
5903
  case "image":
5904
+ case "file":
5905
+ case "link":
5891
5906
  case "markdown":
5892
5907
  case "number":
5893
5908
  case "text":
5894
5909
  case "textarea": return { type: "string" };
5895
- default: return { type: "any" };
5910
+ case "commerce":
5911
+ case "custom": return { type: "any" };
5912
+ case "section":
5913
+ case "tab":
5914
+ case "group": return { type: "any" };
5915
+ default:
5916
+ property.type;
5917
+ return { type: "any" };
5896
5918
  }
5897
5919
  };
5898
5920
  function getStoryType(property, prefix, suffix) {
@@ -7309,7 +7331,7 @@ logsCommand.command("list").description("List logs").option("-s, --space <space>
7309
7331
  });
7310
7332
  //#endregion
7311
7333
  //#region src/commands/logs/prune/index.ts
7312
- logsCommand.command("prune").description("Prune logs").option("--keep <number>", "Max number of log files to keep (default `0`, meaning remove all)", Number.parseInt, 0).option("-s, --space <space>", "space ID").action(async (options, command) => {
7334
+ logsCommand.command("prune").description("Prune logs").option("--keep <number>", "Number of most recent log files to keep", Number.parseInt, 0).option("-s, --space <space>", "space ID").action(async (options, command) => {
7313
7335
  const { space, path } = command.optsWithGlobals();
7314
7336
  const ui = getUI();
7315
7337
  const logsPath = resolveCommandPath(directories.logs, space, path);
@@ -7334,7 +7356,7 @@ reportsCommand.command("list").description("List reports").option("-s, --space <
7334
7356
  });
7335
7357
  //#endregion
7336
7358
  //#region src/commands/reports/prune/index.ts
7337
- reportsCommand.command("prune").description("Prune reports").option("--keep <number>", "Max number of report files to keep (default `0`, meaning remove all)", Number.parseInt, 0).option("-s, --space <space>", "space ID").action(async (options, command) => {
7359
+ reportsCommand.command("prune").description("Prune reports").option("--keep <number>", "Number of most recent report files to keep", Number.parseInt, 0).option("-s, --space <space>", "space ID").action(async (options, command) => {
7338
7360
  const { space, path } = command.optsWithGlobals();
7339
7361
  const ui = getUI();
7340
7362
  const reportsPath = resolveCommandPath(directories.reports, space, path);
@@ -14625,6 +14647,69 @@ Without --exit-code, differences exit 0 and failures exit non-zero.`).action(asy
14625
14647
  //#region src/commands/schema/init/generate-code.ts
14626
14648
  /** Fields to strip from individual schema field entries (`pos` is implicit in array order). */
14627
14649
  const FIELD_STRIP_KEYS = /* @__PURE__ */ new Set(["id", "pos"]);
14650
+ const BASE_FIELD_KEYS = [
14651
+ "type",
14652
+ "id",
14653
+ "display_name",
14654
+ "description",
14655
+ "tooltip",
14656
+ "pos",
14657
+ "conditional_settings"
14658
+ ];
14659
+ const SECTION_KEYS = [
14660
+ ...BASE_FIELD_KEYS,
14661
+ "keys",
14662
+ "fieldset"
14663
+ ];
14664
+ const TAB_KEYS = [...BASE_FIELD_KEYS, "keys"];
14665
+ /**
14666
+ * The editor keeps every key when a field's type changes, so a layout field in a
14667
+ * space can carry keys its type doesn't own.
14668
+ */
14669
+ const LAYOUT_FIELD_KEYS = new Map(Object.entries({
14670
+ section: new Set(SECTION_KEYS),
14671
+ tab: new Set(TAB_KEYS),
14672
+ group: new Set(BASE_FIELD_KEYS)
14673
+ }));
14674
+ /**
14675
+ * Removes the keys a layout field's type doesn't own and turns each conditional
14676
+ * `required: true` into the editor's "Not Required". Rewriting in place keeps
14677
+ * every modification at its index, which matters because the editor and the
14678
+ * Management API read only the first one. Other field types pass through unchanged.
14679
+ */
14680
+ function toLayoutDslField(field) {
14681
+ const ownedKeys = LAYOUT_FIELD_KEYS.get(String(field.type));
14682
+ if (!ownedKeys) return {
14683
+ field,
14684
+ removedRequired: false
14685
+ };
14686
+ let removedRequired = field.required === true;
14687
+ const out = Object.fromEntries(Object.entries(field).filter(([key]) => ownedKeys.has(key)));
14688
+ if (Array.isArray(out.conditional_settings)) out.conditional_settings = out.conditional_settings.map((setting) => {
14689
+ if (!isRecord(setting) || !Array.isArray(setting.modifications)) return setting;
14690
+ return {
14691
+ ...setting,
14692
+ modifications: setting.modifications.map((modification) => {
14693
+ if (!isRecord(modification) || modification.required !== true) return modification;
14694
+ removedRequired = true;
14695
+ return {
14696
+ ...modification,
14697
+ required: false
14698
+ };
14699
+ })
14700
+ };
14701
+ });
14702
+ return {
14703
+ field: out,
14704
+ removedRequired
14705
+ };
14706
+ }
14707
+ /** `<block>.<field>` paths of layout fields whose `required` `toLayoutDslField` removes. */
14708
+ function collectRequiredLayoutFields(components) {
14709
+ const result = [];
14710
+ for (const component of components) for (const [fieldName, field] of Object.entries(component.schema ?? {})) if (isRecord(field) && toLayoutDslField(field).removedRequired) result.push(`${component.name}.${fieldName}`);
14711
+ return result;
14712
+ }
14628
14713
  /**
14629
14714
  * Converts an arbitrary name into a valid camelCase JS identifier.
14630
14715
  * `slugify` reduces the input to `[a-z0-9_-]` (symbols stripped, spaces → `-`);
@@ -15063,7 +15148,8 @@ function omitResetMetadata(obj) {
15063
15148
  * Position is implicit in the array index, so `pos` is stripped from the config.
15064
15149
  */
15065
15150
  function generateFieldCode(fieldName, fieldData, depth, folderVarByUuid, tagNameById) {
15066
- const clean = omitEmptyArrays(toDslField(stripKeys(fieldData, FIELD_STRIP_KEYS), folderVarByUuid, tagNameById));
15151
+ const { field } = toLayoutDslField(stripKeys(fieldData, FIELD_STRIP_KEYS));
15152
+ const clean = omitEmptyArrays(toDslField(field, folderVarByUuid, tagNameById));
15067
15153
  return `defineField(${quoteString(fieldName)}, ${formatValue(clean, depth)})`;
15068
15154
  }
15069
15155
  /**
@@ -15335,7 +15421,8 @@ async function writeSchemaFiles(targetPath, components, componentFolders, dataso
15335
15421
  return {
15336
15422
  writtenFiles,
15337
15423
  placeholderFieldPlugins,
15338
- fieldsWithoutFieldType
15424
+ fieldsWithoutFieldType,
15425
+ requiredLayoutFields: collectRequiredLayoutFields(components)
15339
15426
  };
15340
15427
  }
15341
15428
  //#endregion
@@ -15386,13 +15473,14 @@ schemaCommand.command("init").description("Initialize a local code-driven schema
15386
15473
  const { rawComponents, rawComponentFolders, rawInternalTags, rawDatasources } = fetchResult;
15387
15474
  fetchSpinner.succeed(`Found: ${rawComponents.length} components, ${rawComponentFolders.length} component folders, ${rawDatasources.length} datasources`);
15388
15475
  const writeSpinner = ui.createSpinner(`Generating TypeScript files to ${targetDisplayPath}...`);
15389
- const { writtenFiles, placeholderFieldPlugins, fieldsWithoutFieldType } = await writeSchemaFiles(targetPath, rawComponents, rawComponentFolders, rawDatasources, rawInternalTags);
15476
+ const { writtenFiles, placeholderFieldPlugins, fieldsWithoutFieldType, requiredLayoutFields } = await writeSchemaFiles(targetPath, rawComponents, rawComponentFolders, rawDatasources, rawInternalTags);
15390
15477
  summary.total = writtenFiles.length;
15391
15478
  summary.succeeded = writtenFiles.length;
15392
15479
  writeSpinner.succeed(`Generated ${writtenFiles.length} files`);
15393
15480
  ui.list(writtenFiles.map((file) => displayPath(file, options.outDir)));
15394
15481
  if (placeholderFieldPlugins.length > 0) ui.warn(["Generated placeholder field plugins that accept any value. Define the value each one stores:", ...placeholderFieldPlugins.map(({ fieldType, filePath }) => ` - ${fieldType} (${displayPath(filePath, options.outDir)})`)].join("\n"));
15395
15482
  if (fieldsWithoutFieldType.length > 0) ui.warn(["Skipped custom fields that name no field plugin:", ...fieldsWithoutFieldType.map((field) => ` - ${field}`)].join("\n"));
15483
+ if (requiredLayoutFields.length > 0) ui.warn(["Made these group and tab fields not required. They hold no value, so a required one can prevent publishing. The next schema push updates the space:", ...requiredLayoutFields.map((entry) => ` - ${entry}`)].join("\n"));
15396
15484
  ui.ok(`Schema workspace initialized from space ${space} in ${chalk.hex(colorPalette.PRIMARY)(targetDisplayPath)}`, true);
15397
15485
  ui.br();
15398
15486
  ui.info([
@@ -16211,7 +16299,7 @@ async function writeLocalComponents({ space, basePath, resolved, diffResult, del
16211
16299
  }
16212
16300
  //#endregion
16213
16301
  //#region src/commands/schema/push/index.ts
16214
- schemaCommand.command("push <entry-file>").description("Push local TypeScript schema and datasource definitions to a Storyblok space").option("-s, --space <space>", "space ID").option("-p, --path <path>", "path for file storage").option("--dry-run", "Show diffs without applying changes", false).option("--delete", "Delete remote entities not present in local schema", false).option("--migrations", "Generate scaffold migration files for breaking changes", true).addOption(new Option("--no-migrations", "Skip migration generation for breaking changes")).option("--write-components", "Write component schemas as local JSON files after push (also removes local files for components deleted via --delete)", true).addOption(new Option("--no-write-components", "Skip writing local component files")).action(async (entryFile, options, command) => {
16302
+ schemaCommand.command("push <entry-file>").description("Push local TypeScript schema and datasource definitions to a Storyblok space").option("-s, --space <space>", "space ID").option("--dry-run", "Show diffs without applying changes", false).option("--delete", "Delete remote entities not present in local schema", false).option("--migrations", "Generate scaffold migration files for breaking changes", true).addOption(new Option("--no-migrations", "Skip migration generation for breaking changes")).option("--write-components", "Write component schemas as local JSON files after push (also removes local files for components deleted via --delete)", true).addOption(new Option("--no-write-components", "Skip writing local component files")).action(async (entryFile, options, command) => {
16215
16303
  const ui = getUI();
16216
16304
  const logger = getLogger();
16217
16305
  const reporter = getReporter();
@@ -16746,7 +16834,7 @@ async function executeRollback(spaceId, ops, remote) {
16746
16834
  }
16747
16835
  //#endregion
16748
16836
  //#region src/commands/schema/rollback/index.ts
16749
- schemaCommand.command("rollback [changeset-file]").description("Roll back a Storyblok space to the state captured in a changeset").option("-s, --space <space>", "space ID").option("-p, --path <path>", "path for file storage").option("--dry-run", "Show what would be undone without applying changes", false).option("--yes", "Skip confirmation prompt", false).option("--latest", "Automatically select the most recent changeset", false).action(async (changesetFile, options, command) => {
16837
+ schemaCommand.command("rollback [changeset-file]").description("Roll back a Storyblok space to the state captured in a changeset").option("-s, --space <space>", "space ID").option("--dry-run", "Show what would be undone without applying changes", false).option("--yes", "Skip confirmation prompt", false).option("--latest", "Automatically select the most recent changeset", false).action(async (changesetFile, options, command) => {
16750
16838
  const ui = getUI();
16751
16839
  const logger = getLogger();
16752
16840
  const reporter = getReporter();