storyblok 3.31.0 → 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 +38 -30
  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
@@ -525,21 +525,31 @@ const api = {
525
525
  oauthToken: "",
526
526
  spaceId: null,
527
527
  region: "",
528
- getClient() {
529
- const { region } = creds.get();
530
- try {
531
- return new Storyblok({
532
- accessToken: this.accessToken,
533
- oauthToken: this.oauthToken,
534
- region: this.region,
535
- headers: {
536
- ...DEFAULT_AGENT
537
- }
538
- }, this.apiSwitcher(region));
539
- } catch (error) {
540
- throw new Error(error);
541
- }
542
- },
528
+ getClient: /* @__PURE__ */ function() {
529
+ let client, accessToken, oauthToken, region, credsRegion;
530
+ return function getClient() {
531
+ const { region: _credsRegion } = creds.get();
532
+ if (client && accessToken === this.accessToken && oauthToken === this.oauthToken && region === this.region && credsRegion === _credsRegion) {
533
+ return client;
534
+ }
535
+ accessToken = this.accessToken;
536
+ oauthToken = this.oauthToken;
537
+ region = this.region;
538
+ credsRegion = _credsRegion;
539
+ try {
540
+ return client = new Storyblok({
541
+ accessToken,
542
+ oauthToken,
543
+ region,
544
+ headers: {
545
+ ...DEFAULT_AGENT
546
+ }
547
+ }, this.apiSwitcher(credsRegion));
548
+ } catch (error) {
549
+ throw new Error(error);
550
+ }
551
+ };
552
+ }(),
543
553
  getPath(path) {
544
554
  if (this.spaceId) {
545
555
  return `spaces/${this.spaceId}/${path}`;
@@ -772,16 +782,14 @@ const parserError = (responseError) => {
772
782
  };
773
783
  };
774
784
 
775
- const saveFileFactory = async (fileName, content, path = "./") => {
776
- return new Promise((resolve, reject) => {
777
- fs.writeFile(`${path}${fileName}`, content, (err) => {
778
- if (err) {
779
- Promise.reject(err);
780
- return;
781
- }
782
- Promise.resolve(true);
783
- });
784
- });
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
+ }
785
793
  };
786
794
 
787
795
  const buildFilterQuery = (keys, operations, values) => {
@@ -1813,7 +1821,7 @@ const getNameFromComponentGroups = (groups, uuid) => {
1813
1821
  return "";
1814
1822
  };
1815
1823
  const pullComponents = async (api, options) => {
1816
- const { fileName, separateFiles, path } = options;
1824
+ const { fileName, separateFiles, path, prefixPresetsNames } = options;
1817
1825
  try {
1818
1826
  const componentGroups = await api.getComponentGroups();
1819
1827
  const components = await api.getComponents();
@@ -1835,7 +1843,7 @@ const pullComponents = async (api, options) => {
1835
1843
  if (presets.length === 0)
1836
1844
  return;
1837
1845
  for (const preset in presets) {
1838
- const presetFileName = `${presets[preset].name}-${fileName}.json`;
1846
+ const presetFileName = `${prefixPresetsNames ? `${presets[preset].preset.component}-` : ""}${presets[preset].name}-${fileName}.json`;
1839
1847
  const data2 = JSON.stringify(presets[preset], null, 2);
1840
1848
  saveFileFactory(presetFileName, data2, path);
1841
1849
  }
@@ -3574,10 +3582,10 @@ program.command("pull-languages").description("Download your space's languages s
3574
3582
  process.exit(1);
3575
3583
  }
3576
3584
  });
3577
- 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) => {
3578
3586
  console.log(`${chalk.blue("-")} Executing pull-components task`);
3579
3587
  const space = program.space;
3580
- const { separateFiles, path: path2 } = options;
3588
+ const { separateFiles, path: path2, prefixPresetsNames } = options;
3581
3589
  if (!space) {
3582
3590
  console.log(chalk.red("X") + " Please provide the space as argument --space YOUR_SPACE_ID.");
3583
3591
  process.exit(0);
@@ -3588,7 +3596,7 @@ program.command(COMMANDS.PULL_COMPONENTS).option("--sf, --separate-files [value]
3588
3596
  await api.processLogin();
3589
3597
  }
3590
3598
  api.setSpaceId(space);
3591
- await tasks.pullComponents(api, { fileName, separateFiles, path: path2 });
3599
+ await tasks.pullComponents(api, { fileName, separateFiles, path: path2, prefixPresetsNames });
3592
3600
  } catch (e) {
3593
3601
  errorHandler(e, COMMANDS.PULL_COMPONENTS);
3594
3602
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storyblok",
3
- "version": "3.31.0",
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",