storyblok 3.31.1 → 3.32.0

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 (3) hide show
  1. package/README.md +3 -1
  2. package/dist/cli.mjs +13 -15
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -96,12 +96,14 @@ $ storyblok pull-languages --space <SPACE_ID>
96
96
 
97
97
  Download your space's components schema as json. By default this command will download 2 files: 1 for the components and 1 for the presets; But if you pass a flag `--separate-files or --sf` the command will create file for each component and presets. And also you could pass a path `--path or -p` to save your components and presets.
98
98
 
99
+ It's highly recommended to use also the `--prefix-presets-names` or `-ppn` parameter if you use `--separate-files` because it will prefix the names of the individual files with the name of the component. This feature solves the issue of multiple presets from different components but with the same name, being written in the same file. In a future major version this will become the default behavior.
100
+
99
101
  ```sh
100
102
  $ storyblok pull-components --space <SPACE_ID> # Will save files like components-1234.json
101
103
  ```
102
104
 
103
105
  ```sh
104
- $ storyblok pull-components --space <SPACE_ID> --separate-files --file-name production # Will save files like feature-production.json grid-production.json
106
+ $ storyblok pull-components --space <SPACE_ID> --separate-files --prefix-presets-names --file-name production # Will save files like feature-production.json grid-production.json
105
107
  ```
106
108
 
107
109
  #### Options
package/dist/cli.mjs CHANGED
@@ -782,16 +782,14 @@ const parserError = (responseError) => {
782
782
  };
783
783
  };
784
784
 
785
- const saveFileFactory = async (fileName, content, path = "./") => {
786
- return new Promise((resolve, reject) => {
787
- fs.writeFile(`${path}${fileName}`, content, (err) => {
788
- if (err) {
789
- Promise.reject(err);
790
- return;
791
- }
792
- Promise.resolve(true);
793
- });
794
- });
785
+ const saveFileFactory = (fileName, content, path = "./") => {
786
+ try {
787
+ fs.writeFileSync(`${path}${fileName}`, content);
788
+ return true;
789
+ } catch (err) {
790
+ console.log(err);
791
+ return false;
792
+ }
795
793
  };
796
794
 
797
795
  const buildFilterQuery = (keys, operations, values) => {
@@ -1823,7 +1821,7 @@ const getNameFromComponentGroups = (groups, uuid) => {
1823
1821
  return "";
1824
1822
  };
1825
1823
  const pullComponents = async (api, options) => {
1826
- const { fileName, separateFiles, path } = options;
1824
+ const { fileName, separateFiles, path, prefixPresetsNames } = options;
1827
1825
  try {
1828
1826
  const componentGroups = await api.getComponentGroups();
1829
1827
  const components = await api.getComponents();
@@ -1845,7 +1843,7 @@ const pullComponents = async (api, options) => {
1845
1843
  if (presets.length === 0)
1846
1844
  return;
1847
1845
  for (const preset in presets) {
1848
- const presetFileName = `${presets[preset].name}-${fileName}.json`;
1846
+ const presetFileName = `${prefixPresetsNames ? `${presets[preset].preset.component}-` : ""}${presets[preset].name}-${fileName}.json`;
1849
1847
  const data2 = JSON.stringify(presets[preset], null, 2);
1850
1848
  saveFileFactory(presetFileName, data2, path);
1851
1849
  }
@@ -3584,10 +3582,10 @@ program.command("pull-languages").description("Download your space's languages s
3584
3582
  process.exit(1);
3585
3583
  }
3586
3584
  });
3587
- program.command(COMMANDS.PULL_COMPONENTS).option("--sf, --separate-files [value]", "Argument to create a single file for each component").option("-p, --path <path>", "Path to save the component files").option("-f, --file-name <fileName>", "custom name to be used in file(s) name instead of space id").description("Download your space's components schema as json").action(async (options) => {
3585
+ program.command(COMMANDS.PULL_COMPONENTS).option("--sf, --separate-files [value]", "Argument to create a single file for each component").option("-p, --path <path>", "Path to save the component files").option("-f, --file-name <fileName>", "custom name to be used in file(s) name instead of space id").option("-ppn, --prefix-presets-names", "Prefixes the names of presets with the name of the components").description("Download your space's components schema as json").action(async (options) => {
3588
3586
  console.log(`${chalk.blue("-")} Executing pull-components task`);
3589
3587
  const space = program.space;
3590
- const { separateFiles, path: path2 } = options;
3588
+ const { separateFiles, path: path2, prefixPresetsNames } = options;
3591
3589
  if (!space) {
3592
3590
  console.log(chalk.red("X") + " Please provide the space as argument --space YOUR_SPACE_ID.");
3593
3591
  process.exit(0);
@@ -3598,7 +3596,7 @@ program.command(COMMANDS.PULL_COMPONENTS).option("--sf, --separate-files [value]
3598
3596
  await api.processLogin();
3599
3597
  }
3600
3598
  api.setSpaceId(space);
3601
- await tasks.pullComponents(api, { fileName, separateFiles, path: path2 });
3599
+ await tasks.pullComponents(api, { fileName, separateFiles, path: path2, prefixPresetsNames });
3602
3600
  } catch (e) {
3603
3601
  errorHandler(e, COMMANDS.PULL_COMPONENTS);
3604
3602
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storyblok",
3
- "version": "3.31.1",
3
+ "version": "3.32.0",
4
4
  "description": "A simple CLI to start Storyblok from your command line.",
5
5
  "repository": {
6
6
  "type": "git",