storyblok 3.34.0 → 3.35.1
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/LICENSE +21 -0
- package/README.md +6 -0
- package/dist/cli.mjs +31 -5
- package/package.json +2 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Storyblok GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -98,6 +98,8 @@ Download your space's components schema as json. By default this command will do
|
|
|
98
98
|
|
|
99
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
100
|
|
|
101
|
+
If you want to resolve datasources for single/multiple option field from your Storyblok components, you can use `--resolve-datasources` or `--rd`, it will fill up the options fields with the datasource's options.
|
|
102
|
+
|
|
101
103
|
```sh
|
|
102
104
|
$ storyblok pull-components --space <SPACE_ID> # Will save files like components-1234.json
|
|
103
105
|
```
|
|
@@ -106,6 +108,10 @@ $ storyblok pull-components --space <SPACE_ID> # Will save files like components
|
|
|
106
108
|
$ storyblok pull-components --space <SPACE_ID> --separate-files --prefix-presets-names --file-name production # Will save files like feature-production.json grid-production.json
|
|
107
109
|
```
|
|
108
110
|
|
|
111
|
+
```sh
|
|
112
|
+
$ storyblok pull-components --space <SPACE_ID> --resolve-datasources # Will resolve datasources for single/multiple option field
|
|
113
|
+
```
|
|
114
|
+
|
|
109
115
|
#### Options
|
|
110
116
|
|
|
111
117
|
* `space`: your space id
|
package/dist/cli.mjs
CHANGED
|
@@ -707,6 +707,10 @@ const api = {
|
|
|
707
707
|
const client = this.getClient();
|
|
708
708
|
return client.get(this.getPath("datasources")).then((data) => data.data.datasources || []).catch((err) => Promise.reject(err));
|
|
709
709
|
},
|
|
710
|
+
getDatasourceEntries(id) {
|
|
711
|
+
const client = this.getClient();
|
|
712
|
+
return client.get(this.getPath(`datasource_entries?datasource_id=${id}`)).then((data) => data.data.datasource_entries || []).catch((err) => Promise.reject(err));
|
|
713
|
+
},
|
|
710
714
|
deleteDatasource(id) {
|
|
711
715
|
const client = this.getClient();
|
|
712
716
|
return client.delete(this.getPath(`datasources/${id}`)).catch((err) => Promise.reject(err));
|
|
@@ -1857,12 +1861,34 @@ const getNameFromComponentGroups = (groups, uuid) => {
|
|
|
1857
1861
|
}
|
|
1858
1862
|
return "";
|
|
1859
1863
|
};
|
|
1864
|
+
const resolveDatasourceOptions = async (api, components) => {
|
|
1865
|
+
const datasources = await api.getDatasources();
|
|
1866
|
+
for (const datasource of datasources) {
|
|
1867
|
+
const datasourceEntries = await api.getDatasourceEntries(datasource.id);
|
|
1868
|
+
datasource.entries = datasourceEntries;
|
|
1869
|
+
}
|
|
1870
|
+
return components.map((component) => {
|
|
1871
|
+
const schema = component.schema;
|
|
1872
|
+
for (const field in schema) {
|
|
1873
|
+
if (schema[field].source === "internal" && schema[field].datasource_slug) {
|
|
1874
|
+
const datasource = datasources.find((ds) => ds.slug === schema[field].datasource_slug);
|
|
1875
|
+
if (datasource) {
|
|
1876
|
+
schema[field].options = datasource.entries.map((entry) => ({ value: entry.value, name: entry.name }));
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
return component;
|
|
1881
|
+
});
|
|
1882
|
+
};
|
|
1860
1883
|
const pullComponents = async (api, options) => {
|
|
1861
|
-
const { fileName, separateFiles, path, prefixPresetsNames } = options;
|
|
1884
|
+
const { fileName, separateFiles, path, prefixPresetsNames, resolveDatasources } = options;
|
|
1862
1885
|
try {
|
|
1863
1886
|
const componentGroups = await api.getComponentGroups();
|
|
1864
|
-
|
|
1887
|
+
let components = await api.getComponents();
|
|
1865
1888
|
const presets = await api.getPresets();
|
|
1889
|
+
if (resolveDatasources) {
|
|
1890
|
+
components = await resolveDatasourceOptions(api, components);
|
|
1891
|
+
}
|
|
1866
1892
|
components.forEach((component) => {
|
|
1867
1893
|
const groupUuid = component.component_group_uuid;
|
|
1868
1894
|
if (groupUuid) {
|
|
@@ -3799,10 +3825,10 @@ program.command("pull-languages").description("Download your space's languages s
|
|
|
3799
3825
|
process.exit(1);
|
|
3800
3826
|
}
|
|
3801
3827
|
});
|
|
3802
|
-
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) => {
|
|
3828
|
+
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").option("--rd, --resolve-datasources", "Fill options for single/multiple option field with the linked datasource").description("Download your space's components schema as json").action(async (options) => {
|
|
3803
3829
|
console.log(`${chalk.blue("-")} Executing pull-components task`);
|
|
3804
3830
|
const space = program.space;
|
|
3805
|
-
const { separateFiles, path: path2, prefixPresetsNames } = options;
|
|
3831
|
+
const { separateFiles, path: path2, prefixPresetsNames, resolveDatasources } = options;
|
|
3806
3832
|
if (!space) {
|
|
3807
3833
|
console.log(chalk.red("X") + " Please provide the space as argument --space YOUR_SPACE_ID.");
|
|
3808
3834
|
process.exit(0);
|
|
@@ -3813,7 +3839,7 @@ program.command(COMMANDS.PULL_COMPONENTS).option("--sf, --separate-files [value]
|
|
|
3813
3839
|
await api.processLogin();
|
|
3814
3840
|
}
|
|
3815
3841
|
api.setSpaceId(space);
|
|
3816
|
-
await tasks.pullComponents(api, { fileName, separateFiles, path: path2, prefixPresetsNames });
|
|
3842
|
+
await tasks.pullComponents(api, { fileName, separateFiles, path: path2, prefixPresetsNames, resolveDatasources });
|
|
3817
3843
|
} catch (e) {
|
|
3818
3844
|
errorHandler(e, COMMANDS.PULL_COMPONENTS);
|
|
3819
3845
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "storyblok",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.35.1",
|
|
4
4
|
"description": "A simple CLI to start Storyblok from your command line.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"p-series": "^2.1.0",
|
|
51
51
|
"path": "^0.12.7",
|
|
52
52
|
"simple-uuid": "^0.0.1",
|
|
53
|
-
"storyblok-js-client": "
|
|
53
|
+
"storyblok-js-client": "6.10.3",
|
|
54
54
|
"update-notifier": "^5.1.0",
|
|
55
55
|
"xml-js": "^1.6.11"
|
|
56
56
|
},
|