storyblok 3.33.3 → 3.35.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.
- package/LICENSE +21 -0
- package/README.md +6 -0
- package/dist/cli.mjs +182 -35
- package/package.json +1 -1
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) {
|
|
@@ -2827,27 +2853,65 @@ const getAssetJSONSchema = (title) => ({
|
|
|
2827
2853
|
$id: "#/asset",
|
|
2828
2854
|
title,
|
|
2829
2855
|
type: "object",
|
|
2830
|
-
required: ["id", "filename", "name"],
|
|
2856
|
+
required: ["id", "fieldtype", "filename", "name", "title", "focus", "alt"],
|
|
2831
2857
|
properties: {
|
|
2832
2858
|
alt: {
|
|
2833
|
-
type: "string"
|
|
2859
|
+
type: ["string", "null"]
|
|
2834
2860
|
},
|
|
2835
2861
|
copyright: {
|
|
2836
|
-
type: "string"
|
|
2862
|
+
type: ["string", "null"]
|
|
2863
|
+
},
|
|
2864
|
+
fieldtype: {
|
|
2865
|
+
type: "string",
|
|
2866
|
+
enum: ["asset"]
|
|
2837
2867
|
},
|
|
2838
2868
|
id: {
|
|
2839
2869
|
type: "number"
|
|
2840
2870
|
},
|
|
2841
2871
|
filename: {
|
|
2842
|
-
type: "string"
|
|
2872
|
+
type: ["string", "null"]
|
|
2843
2873
|
},
|
|
2844
2874
|
name: {
|
|
2845
2875
|
type: "string"
|
|
2846
2876
|
},
|
|
2847
2877
|
title: {
|
|
2848
|
-
type: "string"
|
|
2878
|
+
type: ["string", "null"]
|
|
2849
2879
|
},
|
|
2850
2880
|
focus: {
|
|
2881
|
+
type: ["string", "null"]
|
|
2882
|
+
},
|
|
2883
|
+
meta_data: {
|
|
2884
|
+
type: "object"
|
|
2885
|
+
},
|
|
2886
|
+
source: {
|
|
2887
|
+
type: ["string", "null"]
|
|
2888
|
+
},
|
|
2889
|
+
is_external_url: {
|
|
2890
|
+
type: "boolean"
|
|
2891
|
+
},
|
|
2892
|
+
is_private: {
|
|
2893
|
+
type: "boolean"
|
|
2894
|
+
},
|
|
2895
|
+
src: {
|
|
2896
|
+
type: "string"
|
|
2897
|
+
},
|
|
2898
|
+
updated_at: {
|
|
2899
|
+
type: "string"
|
|
2900
|
+
},
|
|
2901
|
+
// Cloudinary integration keys
|
|
2902
|
+
width: {
|
|
2903
|
+
type: ["number", "null"]
|
|
2904
|
+
},
|
|
2905
|
+
height: {
|
|
2906
|
+
type: ["number", "null"]
|
|
2907
|
+
},
|
|
2908
|
+
aspect_ratio: {
|
|
2909
|
+
type: ["number", "null"]
|
|
2910
|
+
},
|
|
2911
|
+
public_id: {
|
|
2912
|
+
type: ["string", "null"]
|
|
2913
|
+
},
|
|
2914
|
+
content_type: {
|
|
2851
2915
|
type: "string"
|
|
2852
2916
|
}
|
|
2853
2917
|
}
|
|
@@ -2858,53 +2922,105 @@ const getMultiassetJSONSchema = (title) => ({
|
|
|
2858
2922
|
type: "array",
|
|
2859
2923
|
items: {
|
|
2860
2924
|
type: "object",
|
|
2861
|
-
required: ["id", "filename", "name"],
|
|
2925
|
+
required: ["id", "fieldtype", "filename", "name", "title", "focus", "alt"],
|
|
2862
2926
|
properties: {
|
|
2863
2927
|
alt: {
|
|
2864
|
-
type: "string"
|
|
2928
|
+
type: ["string", "null"]
|
|
2865
2929
|
},
|
|
2866
2930
|
copyright: {
|
|
2867
|
-
type: "string"
|
|
2931
|
+
type: ["string", "null"]
|
|
2932
|
+
},
|
|
2933
|
+
fieldtype: {
|
|
2934
|
+
type: "string",
|
|
2935
|
+
enum: ["asset"]
|
|
2868
2936
|
},
|
|
2869
2937
|
id: {
|
|
2870
2938
|
type: "number"
|
|
2871
2939
|
},
|
|
2872
2940
|
filename: {
|
|
2873
|
-
type: "string"
|
|
2941
|
+
type: ["string", "null"]
|
|
2874
2942
|
},
|
|
2875
2943
|
name: {
|
|
2876
2944
|
type: "string"
|
|
2877
2945
|
},
|
|
2878
2946
|
title: {
|
|
2947
|
+
type: ["string", "null"]
|
|
2948
|
+
},
|
|
2949
|
+
focus: {
|
|
2950
|
+
type: ["string", "null"]
|
|
2951
|
+
},
|
|
2952
|
+
meta_data: {
|
|
2953
|
+
type: "object"
|
|
2954
|
+
},
|
|
2955
|
+
source: {
|
|
2956
|
+
type: ["string", "null"]
|
|
2957
|
+
},
|
|
2958
|
+
is_external_url: {
|
|
2959
|
+
type: "boolean"
|
|
2960
|
+
},
|
|
2961
|
+
is_private: {
|
|
2962
|
+
type: "boolean"
|
|
2963
|
+
},
|
|
2964
|
+
src: {
|
|
2965
|
+
type: "string"
|
|
2966
|
+
},
|
|
2967
|
+
updated_at: {
|
|
2968
|
+
type: "string"
|
|
2969
|
+
},
|
|
2970
|
+
// Cloudinary integration keys
|
|
2971
|
+
width: {
|
|
2972
|
+
type: ["number", "null"]
|
|
2973
|
+
},
|
|
2974
|
+
height: {
|
|
2975
|
+
type: ["number", "null"]
|
|
2976
|
+
},
|
|
2977
|
+
aspect_ratio: {
|
|
2978
|
+
type: ["number", "null"]
|
|
2979
|
+
},
|
|
2980
|
+
public_id: {
|
|
2981
|
+
type: ["string", "null"]
|
|
2982
|
+
},
|
|
2983
|
+
content_type: {
|
|
2879
2984
|
type: "string"
|
|
2880
2985
|
}
|
|
2881
2986
|
}
|
|
2882
2987
|
}
|
|
2883
2988
|
});
|
|
2989
|
+
const multilinkSharedRequiredProps = ["fieldtype", "id", "url", "cached_url", "linktype"];
|
|
2884
2990
|
const getMultilinkJSONSchema = (title) => ({
|
|
2885
2991
|
$id: "#/multilink",
|
|
2886
2992
|
title,
|
|
2887
2993
|
oneOf: [
|
|
2888
2994
|
{
|
|
2889
2995
|
type: "object",
|
|
2996
|
+
required: multilinkSharedRequiredProps,
|
|
2890
2997
|
properties: {
|
|
2891
|
-
|
|
2998
|
+
// Shared props
|
|
2999
|
+
fieldtype: {
|
|
3000
|
+
type: "string",
|
|
3001
|
+
enum: ["multilink"]
|
|
3002
|
+
},
|
|
3003
|
+
id: { type: "string" },
|
|
3004
|
+
url: { type: "string" },
|
|
3005
|
+
cached_url: { type: "string" },
|
|
3006
|
+
target: { type: "string", enum: ["_blank", "_self"] },
|
|
3007
|
+
// Custom props
|
|
3008
|
+
anchor: {
|
|
2892
3009
|
type: "string"
|
|
2893
3010
|
},
|
|
2894
|
-
|
|
3011
|
+
rel: {
|
|
2895
3012
|
type: "string"
|
|
2896
3013
|
},
|
|
2897
|
-
|
|
3014
|
+
title: {
|
|
3015
|
+
type: "string"
|
|
3016
|
+
},
|
|
3017
|
+
prep: {
|
|
2898
3018
|
type: "string"
|
|
2899
3019
|
},
|
|
2900
3020
|
linktype: {
|
|
2901
3021
|
type: "string",
|
|
2902
3022
|
enum: ["story"]
|
|
2903
3023
|
},
|
|
2904
|
-
target: {
|
|
2905
|
-
type: "string",
|
|
2906
|
-
enum: ["_self", "_blank"]
|
|
2907
|
-
},
|
|
2908
3024
|
story: {
|
|
2909
3025
|
type: "object",
|
|
2910
3026
|
required: ["name", "id", "uuid", "slug", "full_slug"],
|
|
@@ -2990,39 +3106,70 @@ const getMultilinkJSONSchema = (title) => ({
|
|
|
2990
3106
|
},
|
|
2991
3107
|
{
|
|
2992
3108
|
type: "object",
|
|
3109
|
+
required: multilinkSharedRequiredProps,
|
|
2993
3110
|
properties: {
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
type: "string"
|
|
2999
|
-
},
|
|
3000
|
-
anchor: {
|
|
3001
|
-
type: "string"
|
|
3111
|
+
// Shared props
|
|
3112
|
+
fieldtype: {
|
|
3113
|
+
type: "string",
|
|
3114
|
+
enum: ["multilink"]
|
|
3002
3115
|
},
|
|
3116
|
+
id: { type: "string" },
|
|
3117
|
+
url: { type: "string" },
|
|
3118
|
+
cached_url: { type: "string" },
|
|
3119
|
+
target: { type: "string", enum: ["_blank", "_self"] },
|
|
3120
|
+
// Custom props
|
|
3003
3121
|
linktype: {
|
|
3004
3122
|
type: "string",
|
|
3005
|
-
enum: ["
|
|
3123
|
+
enum: ["url"]
|
|
3006
3124
|
},
|
|
3007
|
-
|
|
3008
|
-
type: "string"
|
|
3009
|
-
|
|
3125
|
+
rel: {
|
|
3126
|
+
type: "string"
|
|
3127
|
+
},
|
|
3128
|
+
title: {
|
|
3129
|
+
type: "string"
|
|
3010
3130
|
}
|
|
3011
3131
|
}
|
|
3012
3132
|
},
|
|
3013
3133
|
{
|
|
3014
3134
|
type: "object",
|
|
3135
|
+
required: multilinkSharedRequiredProps,
|
|
3015
3136
|
properties: {
|
|
3137
|
+
// Shared props
|
|
3138
|
+
fieldtype: {
|
|
3139
|
+
type: "string",
|
|
3140
|
+
enum: ["multilink"]
|
|
3141
|
+
},
|
|
3142
|
+
id: { type: "string" },
|
|
3143
|
+
url: { type: "string" },
|
|
3144
|
+
cached_url: { type: "string" },
|
|
3145
|
+
target: { type: "string", enum: ["_blank", "_self"] },
|
|
3146
|
+
// Custom props
|
|
3016
3147
|
email: {
|
|
3017
3148
|
type: "string"
|
|
3018
3149
|
},
|
|
3019
3150
|
linktype: {
|
|
3020
3151
|
type: "string",
|
|
3021
3152
|
enum: ["email"]
|
|
3153
|
+
}
|
|
3154
|
+
}
|
|
3155
|
+
},
|
|
3156
|
+
{
|
|
3157
|
+
type: "object",
|
|
3158
|
+
required: multilinkSharedRequiredProps,
|
|
3159
|
+
properties: {
|
|
3160
|
+
// Shared props
|
|
3161
|
+
fieldtype: {
|
|
3162
|
+
type: "string",
|
|
3163
|
+
enum: ["multilink"]
|
|
3022
3164
|
},
|
|
3023
|
-
|
|
3165
|
+
id: { type: "string" },
|
|
3166
|
+
url: { type: "string" },
|
|
3167
|
+
cached_url: { type: "string" },
|
|
3168
|
+
target: { type: "string", enum: ["_blank", "_self"] },
|
|
3169
|
+
// Custom props
|
|
3170
|
+
linktype: {
|
|
3024
3171
|
type: "string",
|
|
3025
|
-
enum: ["
|
|
3172
|
+
enum: ["asset"]
|
|
3026
3173
|
}
|
|
3027
3174
|
}
|
|
3028
3175
|
}
|
|
@@ -3678,10 +3825,10 @@ program.command("pull-languages").description("Download your space's languages s
|
|
|
3678
3825
|
process.exit(1);
|
|
3679
3826
|
}
|
|
3680
3827
|
});
|
|
3681
|
-
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) => {
|
|
3682
3829
|
console.log(`${chalk.blue("-")} Executing pull-components task`);
|
|
3683
3830
|
const space = program.space;
|
|
3684
|
-
const { separateFiles, path: path2, prefixPresetsNames } = options;
|
|
3831
|
+
const { separateFiles, path: path2, prefixPresetsNames, resolveDatasources } = options;
|
|
3685
3832
|
if (!space) {
|
|
3686
3833
|
console.log(chalk.red("X") + " Please provide the space as argument --space YOUR_SPACE_ID.");
|
|
3687
3834
|
process.exit(0);
|
|
@@ -3692,7 +3839,7 @@ program.command(COMMANDS.PULL_COMPONENTS).option("--sf, --separate-files [value]
|
|
|
3692
3839
|
await api.processLogin();
|
|
3693
3840
|
}
|
|
3694
3841
|
api.setSpaceId(space);
|
|
3695
|
-
await tasks.pullComponents(api, { fileName, separateFiles, path: path2, prefixPresetsNames });
|
|
3842
|
+
await tasks.pullComponents(api, { fileName, separateFiles, path: path2, prefixPresetsNames, resolveDatasources });
|
|
3696
3843
|
} catch (e) {
|
|
3697
3844
|
errorHandler(e, COMMANDS.PULL_COMPONENTS);
|
|
3698
3845
|
}
|