storyblok 3.36.1 → 4.0.0-beta.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/README.md +82 -620
- package/dist/index.d.mts +91 -0
- package/dist/index.d.ts +91 -0
- package/dist/index.mjs +3511 -0
- package/package.json +42 -58
- package/dist/chunks/teaser.mjs +0 -27
- package/dist/cli.d.mts +0 -69
- package/dist/cli.d.ts +0 -69
- package/dist/cli.mjs +0 -4172
package/README.md
CHANGED
|
@@ -1,667 +1,129 @@
|
|
|
1
|
-
<
|
|
2
|
-
<h1 align="center">Storyblok CLI</h1>
|
|
3
|
-
<p align="center">A simple CLI for scaffolding <a href="https://www.storyblok.com?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok" target="_blank">Storyblok</a> projects and fieldtypes.</p>
|
|
4
|
-
</p>
|
|
5
|
-
|
|
6
|
-
[](https://www.npmjs.com/package/storyblok)
|
|
7
|
-
[](ttps://img.shields.io/npm/dt/storyblok.svg)
|
|
8
|
-
[](https://github.com/storyblok/storyblok/issues?q=is%3Aopen+is%3Aissue)
|
|
9
|
-
[](https://github.com/storyblok/storyblok-cli/issues?q=is%3Aissue+is%3Aclosed)
|
|
10
|
-
|
|
11
|
-
## BREAKING CHANGE
|
|
12
|
-
|
|
13
|
-
We added the `region` option upon login. If you are using the CLI, please `logout` and `login` again providing your user region.
|
|
14
|
-
|
|
15
|
-
## Installation
|
|
16
|
-
|
|
17
|
-
Make sure you have Node `>= 18.0.0` installed.
|
|
18
|
-
|
|
19
|
-
```sh
|
|
20
|
-
$ npm i storyblok -g
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Commands
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
### login
|
|
27
|
-
|
|
28
|
-
Login to the Storyblok cli
|
|
29
|
-
|
|
30
|
-
```sh
|
|
31
|
-
$ storyblok login
|
|
32
|
-
```
|
|
33
|
-
#### Login options
|
|
34
|
-
|
|
35
|
-
##### Options for Login with email and password
|
|
36
|
-
* `email`: your user's email address
|
|
37
|
-
* `password`: your user's password
|
|
38
|
-
|
|
39
|
-
##### Options for Login with token (Recomended to SSO user's but works with all user accounts)
|
|
40
|
-
* `token`: your personal access token
|
|
41
|
-
|
|
42
|
-
**Get your personal access token**
|
|
43
|
-
* Go to [https://app.storyblok.com/#/me/account?tab=token](https://app.storyblok.com/#/me/account?tab=token) and click on Generate new token.
|
|
44
|
-
|
|
45
|
-
**For Both login options you nedd to pass the region**
|
|
46
|
-
|
|
47
|
-
* `region` (default: `eu`): the region you would like to work in. All the supported regions can be found [here](https://www.storyblok.com/faq/define-specific-region-storyblok-api).
|
|
48
|
-
|
|
49
|
-
> [!NOTE]
|
|
50
|
-
> Please keep in mind that the region must match the region of your space, and also that it will be used for all future commands you may perform.
|
|
51
|
-
|
|
52
|
-
#### Login with token flag
|
|
53
|
-
You can also add the token directly from the login’s command, like the example below:
|
|
54
|
-
|
|
55
|
-
```sh
|
|
56
|
-
$ storyblok login --token <PERSONAL_ACCESS_TOKEN> --region eu
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
### logout
|
|
60
|
-
|
|
61
|
-
Logout from the Storyblok cli
|
|
62
|
-
|
|
63
|
-
```sh
|
|
64
|
-
$ storyblok logout
|
|
65
|
-
```
|
|
66
|
-
### user
|
|
67
|
-
|
|
68
|
-
Get the currently logged in user
|
|
69
|
-
|
|
70
|
-
```sh
|
|
71
|
-
$ storyblok user
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
### select
|
|
76
|
-
|
|
77
|
-
Usage to kickstart a boilerplate, fieldtype or theme
|
|
78
|
-
|
|
79
|
-
```sh
|
|
80
|
-
$ storyblok select
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
### pull-languages
|
|
84
|
-
|
|
85
|
-
Download your space's languages schema as json. This command will download 1 file.
|
|
86
|
-
|
|
87
|
-
```sh
|
|
88
|
-
$ storyblok pull-languages --space <SPACE_ID>
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
#### Options
|
|
92
|
-
|
|
93
|
-
* `space`: your space id
|
|
94
|
-
|
|
95
|
-
### pull-components
|
|
96
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
103
|
-
```sh
|
|
104
|
-
$ storyblok pull-components --space <SPACE_ID> # Will save files like components-1234.json
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
```sh
|
|
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
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
```sh
|
|
112
|
-
$ storyblok pull-components --space <SPACE_ID> --resolve-datasources # Will resolve datasources for single/multiple option field
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
#### Options
|
|
116
|
-
|
|
117
|
-
* `space`: your space id
|
|
118
|
-
* `separate-files`: boolean flag to save components and presets in single files instead a file with all
|
|
119
|
-
* `path`: the path to save your components and preset files
|
|
120
|
-
* `file-name`(optional): a custom filename used to generate the component and present files, default is the space id
|
|
121
|
-
|
|
122
|
-
### push-components
|
|
123
|
-
|
|
124
|
-
Push your components file to your/another space
|
|
125
|
-
|
|
126
|
-
```sh
|
|
127
|
-
$ storyblok push-components <SOURCE> --space <SPACE_ID> --presets-source <PRESETS_SOURCE>
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
#### Parameters
|
|
131
|
-
|
|
132
|
-
* `source`: can be a URL or path to JSON file, the path to a json file could be to a single or multiple files separated by comma, like `./pages-1234.json,../User/components/grid-1234.json`
|
|
133
|
-
|
|
134
|
-
Using an **URL**
|
|
135
|
-
|
|
136
|
-
```sh
|
|
137
|
-
$ storyblok push-components https://raw.githubusercontent.com/storyblok/nuxtdoc/master/seed.components.json --space 67819
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
Using a **path** to a single file
|
|
141
|
-
|
|
142
|
-
```sh
|
|
143
|
-
$ storyblok push-components ./components.json --space 67819
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
Using a **path** to a multiple files
|
|
147
|
-
|
|
148
|
-
```sh
|
|
149
|
-
$ storyblok push-components ./page.json,../grid.json,./feature.json --space 67819
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
#### Options
|
|
153
|
-
|
|
154
|
-
* `space`: your space id
|
|
155
|
-
* `presets-source` (optional): it can be a URL or path to JSON file with the presets
|
|
156
|
-
|
|
157
|
-
#### Examples
|
|
158
|
-
|
|
159
|
-
Using an **URL** for `presets-source`
|
|
160
|
-
|
|
161
|
-
```sh
|
|
162
|
-
$ storyblok push-components https://raw.githubusercontent.com/storyblok/nuxtdoc/master/seed.components.json --presets-source https://url-to-your-presets-file.json --space 67819
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
Using a **path** to file
|
|
166
|
-
|
|
167
|
-
```sh
|
|
168
|
-
$ storyblok push-components ./components.json --presets-source ./presets.json --space 67819
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
### delete-component
|
|
172
|
-
|
|
173
|
-
Delete a single component on your space.
|
|
174
|
-
|
|
175
|
-
```sh
|
|
176
|
-
storyblok delete-component <component> --space <SPACE_ID>
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
#### Parameters
|
|
180
|
-
* `component`: The name or id of the component
|
|
181
|
-
|
|
182
|
-
#### Options
|
|
183
|
-
* `space_id`: the space where the command should be executed.
|
|
184
|
-
|
|
185
|
-
#### Examples
|
|
186
|
-
|
|
187
|
-
Delete a component on your space.
|
|
188
|
-
```sh
|
|
189
|
-
storyblok delete-component 111111 --space 67819
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
```sh
|
|
193
|
-
storyblok delete-component teaser --space 67819
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
### delete-components
|
|
197
|
-
|
|
198
|
-
Delete all components from your Space that occur in your Local JSON.
|
|
199
|
-
Or delete those components on your Space that do not appear in the JSON. (`--reverse`)
|
|
200
|
-
|
|
201
|
-
```sh
|
|
202
|
-
storyblok delete-components <SOURCE> --space <SPACE_ID>
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
#### Parameters
|
|
206
|
-
* `source`: can be a URL or path to JSON file, the path to a json file could be to a single or multiple files separated by comma, like `./pages-1234.json,../User/components/grid-1234.json`
|
|
207
|
-
|
|
208
|
-
Using an **URL**
|
|
209
|
-
|
|
210
|
-
```sh
|
|
211
|
-
$ storyblok push-components https://raw.githubusercontent.com/storyblok/nuxtdoc/master/seed.components.json --space 67819
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
Using a **path** to a single file
|
|
215
|
-
|
|
216
|
-
```sh
|
|
217
|
-
$ storyblok push-components ./components.json --space 67819
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
Using a **path** to a multiple files
|
|
221
|
-
|
|
222
|
-
```sh
|
|
223
|
-
$ storyblok push-components ./page.json,../grid.json,./feature.json --space 67819
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
#### Options
|
|
227
|
-
* `space_id`: the space where the command should be executed.
|
|
228
|
-
* `reverse`: When passed as an argument, deletes only those components on your space that do not appear in the JSON.
|
|
229
|
-
* `dryrun`: when passed as an argument, does not perform any changes on the given space.
|
|
230
|
-
|
|
231
|
-
#### Examples
|
|
232
|
-
|
|
233
|
-
Delete all components on a certain space that occur in your local JSON.
|
|
234
|
-
```sh
|
|
235
|
-
storyblok delete-components ./components.json --space 67819
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
Delete only those components which do not occur in your local json from your space.
|
|
239
|
-
```sh
|
|
240
|
-
storyblok delete-components ./components.json --space 67819 --reverse
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
To see the result in your console output but to not perform the command on your space, use the `--dryrun` argument.
|
|
244
|
-
```sh
|
|
245
|
-
storyblok delete-components ./components.json --space 67819 --reverse --dryrun
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
### sync
|
|
249
|
-
|
|
250
|
-
Sync components, folder, roles, datasources or stories between spaces
|
|
251
|
-
|
|
252
|
-
```sh
|
|
253
|
-
$ storyblok sync --type <COMMAND> --source <SPACE_ID> --target <SPACE_ID>
|
|
254
|
-
```
|
|
1
|
+
<div align="center">
|
|
255
2
|
|
|
256
|
-
|
|
3
|
+

|
|
257
4
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
* `filter`: sync stories based on the given filter. Required Options: Required options: `--keys`, `--operations`, `--values`
|
|
263
|
-
* `keys`: Multiple keys should be separated by comma. Example: `--keys key1,key2`, `--keys key1`
|
|
264
|
-
* `operations`: Operations to be used for filtering. Can be: `is`, `in`, `not_in`, `like`, `not_like`, `any_in_array`, `all_in_array`, `gt_date`, `lt_date`, `gt_int`, `lt_int`, `gt_float`, `lt_float`. Multiple operations should be separated by comma.
|
|
265
|
-
* `components-full-sync`: If used, the CLI will override the full component object when synching across spaces.
|
|
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>
|
|
7
|
+
<br />
|
|
8
|
+
</div>
|
|
266
9
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
```
|
|
286
|
-
|
|
287
|
-
### quickstart
|
|
288
|
-
|
|
289
|
-
Create a space in Storyblok and select the boilerplate to use
|
|
290
|
-
|
|
291
|
-
```sh
|
|
292
|
-
$ storyblok quickstart
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
### generate-migration
|
|
296
|
-
|
|
297
|
-
Create a migration file (with the name `change_<COMPONENT>_<FIELD>.js`) inside the `migrations` folder. Check **Migrations** section to more details
|
|
298
|
-
|
|
299
|
-
```sh
|
|
300
|
-
$ storyblok generate-migration --space <SPACE_ID> --component <COMPONENT_NAME> --field <FIELD>
|
|
301
|
-
```
|
|
302
|
-
It's important to note that the `component` and `field` parameters are required and must be spelled exactly as they are in Storyblok. You can check the exact name by looking at the `Block library` inside your space.
|
|
303
|
-
|
|
304
|
-
#### Options
|
|
305
|
-
|
|
306
|
-
* `space`: space where the component is
|
|
307
|
-
* `component`: component name. It needs to be a valid component
|
|
308
|
-
* `field`: name of field
|
|
309
|
-
|
|
310
|
-
### run-migration
|
|
311
|
-
|
|
312
|
-
Execute a specific migration file. Check **Migrations** section to more details
|
|
313
|
-
|
|
314
|
-
```sh
|
|
315
|
-
$ storyblok run-migration --space <SPACE_ID> --component <COMPONENT_NAME> --field <FIELD> --dryrun
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
Optionally you can provide the publish parameter to publish content after saving. Example:
|
|
319
|
-
|
|
320
|
-
```sh
|
|
321
|
-
$ storyblok run-migration --publish published --space 1234 --component article --field image
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
#### Options
|
|
325
|
-
|
|
326
|
-
* `space`: the space you get from the space settings area
|
|
327
|
-
* `component`: component name. It needs to be a valid component
|
|
328
|
-
* `field`: name of field
|
|
329
|
-
* `dryrun`: when passed as an argument, does not perform the migration
|
|
330
|
-
* `publish` (optional): publish the content when update
|
|
331
|
-
* `all`: publish all stories, even if they have not yet been published
|
|
332
|
-
* `published`: only publish stories that already are published and don't have unpublished changes
|
|
333
|
-
* `published-with-changes`: publish stories that are published and have unpublished changes
|
|
334
|
-
* `publish-languages` (optional): publish specific languages. You can publish more than one language at a time by separating the languages by `,`
|
|
335
|
-
|
|
336
|
-
### rollback-migration
|
|
337
|
-
|
|
338
|
-
The `rollback-migration` command gives the possibility to undo the changes made from the execution of the last `run-migrations` command.
|
|
339
|
-
|
|
340
|
-
```sh
|
|
341
|
-
$ storyblok rollback-migration --space 1234 --component Product --field title
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
**Important**: The `rollback-migrations` command will only work if there where changes done with `run-migrations`. Therefore running `run-migrations` command with the `--dryrun` flag will NOT create a rollback file.
|
|
345
|
-
|
|
346
|
-
#### options
|
|
347
|
-
|
|
348
|
-
* `space`: the space you get from the space settings area
|
|
349
|
-
* `component`: component name. It needs to be a valid component
|
|
350
|
-
* `field`: name of field
|
|
351
|
-
|
|
352
|
-
### spaces
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
List all spaces of the logged account
|
|
356
|
-
|
|
357
|
-
```sh
|
|
358
|
-
$ storyblok spaces
|
|
359
|
-
```
|
|
360
|
-
|
|
361
|
-
### import
|
|
362
|
-
|
|
363
|
-
This command gives you the possibility to import flat content from `.csv`, `.xml` and `.json` files coming from other systems.
|
|
364
|
-
|
|
365
|
-
The attributes `path` and `title` are required.
|
|
366
|
-
|
|
367
|
-
```sh
|
|
368
|
-
$ storyblok import --file <FILE_NAME> --type <TYPE_OF_CONTENT> --folder <FOLDER_ID> --delimiter <DELIMITER_TO_CSV_FILES> --space <SPACE_ID>
|
|
369
|
-
```
|
|
370
|
-
|
|
371
|
-
A xml file needs to have following format:
|
|
372
|
-
|
|
373
|
-
```
|
|
374
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
375
|
-
<root>
|
|
376
|
-
<row>
|
|
377
|
-
<path>this-is-my-title</path>
|
|
378
|
-
<title>This is my title</title>
|
|
379
|
-
<text>Lorem ipsum dolor sit amet</text>
|
|
380
|
-
<image>https://a.storyblok.com/f/51376/x/1502f01431/corporate-website.svg</image>
|
|
381
|
-
<category>press</category>
|
|
382
|
-
</row>
|
|
383
|
-
</root>
|
|
384
|
-
```
|
|
385
|
-
|
|
386
|
-
A csv file needs to have following format. The first row is used to identify the attribute names:
|
|
387
|
-
|
|
388
|
-
```
|
|
389
|
-
path;title;text;image;category
|
|
390
|
-
this-is-my-title;This is my title;"Lorem ipsum dolor sit amet";https://a.storyblok.com/f/51376/x/1502f01431/corporate-website.svg;press
|
|
391
|
-
```
|
|
392
|
-
|
|
393
|
-
A json file need to have following format:
|
|
394
|
-
|
|
395
|
-
```json
|
|
396
|
-
[
|
|
397
|
-
{
|
|
398
|
-
"path": "this-is-my-title",
|
|
399
|
-
"title": "This is my title",
|
|
400
|
-
"text": "Lorem ipsum dolor sit amet",
|
|
401
|
-
"image": "https://a.storyblok.com/f/51376/x/1502f01431/corporate-website.svg",
|
|
402
|
-
"category": "press"
|
|
403
|
-
}
|
|
404
|
-
]
|
|
405
|
-
```
|
|
406
|
-
|
|
407
|
-
#### Options
|
|
408
|
-
|
|
409
|
-
* `file`: name of the file
|
|
410
|
-
* `type`: name of the content type you want to use for the import
|
|
411
|
-
* `space`: id of your space
|
|
412
|
-
* `delimiter` (optional): delimiter of the `.cvs` files, only necessary if you are uploading a csv file (Default value is **;** )
|
|
413
|
-
* `folder` (optional): id of the folder where you want to store the content in Storyblok
|
|
414
|
-
|
|
415
|
-
### Help
|
|
416
|
-
|
|
417
|
-
For global help
|
|
418
|
-
|
|
419
|
-
```sh
|
|
420
|
-
$ storyblok --help
|
|
421
|
-
```
|
|
422
|
-
|
|
423
|
-
For command help
|
|
424
|
-
|
|
425
|
-
```sh
|
|
426
|
-
$ storyblok sync --help
|
|
427
|
-
```
|
|
428
|
-
|
|
429
|
-
### Version
|
|
430
|
-
|
|
431
|
-
For view the CLI version
|
|
432
|
-
|
|
433
|
-
```sh
|
|
434
|
-
$ storyblok -V # or --version
|
|
435
|
-
```
|
|
436
|
-
|
|
437
|
-
### delete-datasources
|
|
438
|
-
|
|
439
|
-
The delete-datasources command enables you to remove all datasources within the designated space. By utilizing the `--by-slug` option, you can filter the datasources based on their slugs, selectively deleting specific datasources. Similarly, the `--by-name` option functions in the same way, allowing you to filter and delete datasources based on their names.
|
|
440
|
-
|
|
441
|
-
```sh
|
|
442
|
-
$ storyblok delete-datasources --space-id <SPACE_ID> # Will delete all datasources
|
|
443
|
-
```
|
|
444
|
-
|
|
445
|
-
```sh
|
|
446
|
-
$ storyblok delete-datasources --space-id <SPACE_ID> --by-slug global-translations # Will only delete datasources where the slug starts with global-translations
|
|
447
|
-
```
|
|
448
|
-
|
|
449
|
-
#### Options
|
|
450
|
-
|
|
451
|
-
* `space-id`: your space id
|
|
452
|
-
* `by-slug`: Filter Datasources by slug
|
|
453
|
-
* `by-name`: Filter Datasources by name
|
|
454
|
-
|
|
455
|
-
## Content migrations
|
|
456
|
-
|
|
457
|
-
Content migrations are a convenient way to change fields of your content.
|
|
458
|
-
|
|
459
|
-
To execute a migration you first need to create a migration file. This file is a pure Javascript function where the content of a specific content type or component gets passed through.
|
|
460
|
-
|
|
461
|
-
### 1. Creating a migration file
|
|
462
|
-
|
|
463
|
-
To create a migration file, you need to execute the `generate-migration` command:
|
|
464
|
-
|
|
465
|
-
```sh
|
|
466
|
-
# creating a migration file to product component to update the price
|
|
467
|
-
$ storyblok generate-migration --space 00000 --component product --field price
|
|
468
|
-
```
|
|
469
|
-
|
|
470
|
-
When you run this command a file called `change_product_price.js` will be created inside a folder called `migrations`.
|
|
471
|
-
|
|
472
|
-
The created file will have the following content:
|
|
473
|
-
|
|
474
|
-
```js
|
|
475
|
-
// here, 'subtitle' is the name of the field defined when you execute the generate command
|
|
476
|
-
module.exports = function (block) {
|
|
477
|
-
// Example to change a string to boolean
|
|
478
|
-
// block.subtitle = !!(block.subtitle)
|
|
479
|
-
|
|
480
|
-
// Example to transfer content from other field
|
|
481
|
-
// block.subtitle = block.other_field
|
|
482
|
-
}
|
|
483
|
-
```
|
|
484
|
-
|
|
485
|
-
In the migration function you can manipulate the block variable to add or modify existing fields of the component.
|
|
486
|
-
|
|
487
|
-
### 2. Running the migration file
|
|
488
|
-
|
|
489
|
-
To run the migration function you need to execute the `run-migration` command. Pass the --dryrun option to not execute the updates and only show the changes in the terminal:
|
|
490
|
-
|
|
491
|
-
```sh
|
|
492
|
-
$ storyblok run-migration --space 00000 --component product --field price --dryrun
|
|
493
|
-
```
|
|
494
|
-
|
|
495
|
-
After checking the output of the dryrun you can execute the updates:
|
|
496
|
-
|
|
497
|
-
```sh
|
|
498
|
-
# you can use the --dryrun option to not execute the updates
|
|
499
|
-
$ storyblok run-migration --space 00000 --component product --field price
|
|
500
|
-
```
|
|
501
|
-
|
|
502
|
-
### 3. Publishing the content
|
|
503
|
-
|
|
504
|
-
You can execute the migration and, when update the content, publish it using the `--publish` and `--publish-languages` options. When you use the `publish` option, **you need to specific one of these following options**: 'all', 'published' or 'published-with-changes':
|
|
505
|
-
|
|
506
|
-
```sh
|
|
507
|
-
$ storyblok run-migration --space 00000 --component product --field price --publish all
|
|
508
|
-
```
|
|
509
|
-
|
|
510
|
-
You can specify the languages to update using `--publish-languages=<LANGUAGE>` or update all languages using `--publish-languages=ALL_LANGUAGES`:
|
|
511
|
-
|
|
512
|
-
```sh
|
|
513
|
-
# to update only one language
|
|
514
|
-
$ storyblok run-migration --space 00000 --component product --field price --publish all --publish-languages=de
|
|
515
|
-
|
|
516
|
-
# to update more than one language
|
|
517
|
-
$ storyblok run-migration --space 00000 --component product --field price --publish all --publish-languages=de,pt
|
|
518
|
-
```
|
|
10
|
+
<p align="center">
|
|
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" />
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://npmjs.com/package/storyblok" rel="nofollow">
|
|
15
|
+
<img src="https://img.shields.io/npm/dt/storyblok.svg?style=appveyor&color=8d60ff" alt="npm">
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://discord.gg/jKrbAMz">
|
|
18
|
+
<img src="https://img.shields.io/discord/700316478792138842?label=Join%20Our%20Discord%20Community&style=appveyor&logo=discord&color=8d60ff">
|
|
19
|
+
</a>
|
|
20
|
+
<a href="https://twitter.com/intent/follow?screen_name=storyblok">
|
|
21
|
+
<img src="https://img.shields.io/badge/Follow-%40storyblok-8d60ff?style=appveyor&logo=twitter" alt="Follow @Storyblok" />
|
|
22
|
+
</a><br/>
|
|
23
|
+
<a href="https://app.storyblok.com/#!/signup?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-cli">
|
|
24
|
+
<img src="https://img.shields.io/badge/Try%20Storyblok-Free-8d60ff?style=appveyor&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAABGdBTUEAALGPC/xhBQAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAHqADAAQAAAABAAAAHgAAAADpiRU/AAACRElEQVRIDWNgGGmAEd3D3Js3LPrP8D8WXZwSPiMjw6qvPoHhyGYwIXNAbGpbCjbzP0MYuj0YFqMroBV/wCxmIeSju64eDNzMBJUxvP/9i2Hnq5cM1devMnz984eQsQwETeRhYWHgIcJiXqC6VHlFBjUeXgav40cIWkz1oLYXFmGwFBImaDFBHyObcOzdW4aSq5eRhRiE2dgYlpuYoYSKJi8vw3GgWnyAJIs/AuPu4scPGObd/fqVQZ+PHy7+6udPOBsXgySLDfn5GRYYmaKYJcXBgWLpsx8/GPa8foWiBhuHJIsl2DkYQqWksZkDFgP5PObcKYYff//iVAOTIDlx/QPqRMb/YSYBaWlOToZIaVkGZmAZSQiQ5OPtwHwacuo4iplMQEu6tXUZMhSUGDiYmBjylFQYvv/7x9B04xqKOnQOyT5GN+Df//8M59ASXKyMHLoyDD5JPtbj42OYrm+EYgg70JfuYuIoYmLs7AwMjIzA+uY/zjAnyWJpDk6GOFnCvrn86SOwmsNtKciVFAc1ileBHFDC67lzG10Yg0+SjzF0ownsf/OaofvOLYaDQJoQIGix94ljv1gIZI8Pv38zPvj2lQWYf3HGKbpDCFp85v07NnRN1OBTPY6JdRSGxcCw2k6sZuLVMZ5AV4s1TozPnGGFKbz+/PE7IJsHmC//MDMyhXBw8e6FyRFLv3Z0/IKuFqvFyIqAzd1PwBzJw8jAGPfVx38JshwlbIygxmYY43/GQmpais0ODDHuzevLMARHBcgIAQAbOJHZW0/EyQAAAABJRU5ErkJggg==" alt="Follow @Storyblok" />
|
|
25
|
+
</a>
|
|
26
|
+
</p>
|
|
519
27
|
|
|
520
|
-
|
|
28
|
+
## Features
|
|
521
29
|
|
|
522
|
-
|
|
30
|
+
- 🛡️ **Type Safety** - Generate TypeScript type definitions for your Storyblok components, ensuring type safety in your frontend applications
|
|
31
|
+
- 🔐 **Authentication** - Secure login system with support for different regions and CI environments
|
|
32
|
+
- 🧩 **Component Management** - Pull and push component schemas, groups, presets, and internal tags between spaces
|
|
33
|
+
- 🔄 **Migration System** - Generate and run migrations to transform or update field values across your Storyblok content
|
|
34
|
+
- 🌐 **Language Management** - Pull and manage languages for your Storyblok space
|
|
35
|
+
- 📁 **File Organization** - Organized file structure with the `.storyblok` directory as default
|
|
36
|
+
- 🛠️ **Customizable Paths** - Flexible path configuration for all generated files
|
|
37
|
+
- 📝 **Naming Conventions** - Consistent file naming with customizable suffixes and prefixes
|
|
38
|
+
- 📂 **Separate Files Support** - Option to work with individual component files or consolidated files
|
|
39
|
+
- 👀 **Dry Run Mode** - Preview migrations changes before applying them to your Storyblok space
|
|
40
|
+
- 🔍 **Filtering Capabilities** - Filter components and stories using glob patterns and Storyblok query syntax
|
|
41
|
+
- 📊 **Verbose Logging** - Improved error handling and detailed logging options for debugging and monitoring
|
|
523
42
|
|
|
524
|
-
|
|
43
|
+
## Pre-requisites
|
|
525
44
|
|
|
526
|
-
|
|
45
|
+
- [Node.js >= 18.0.0](https://nodejs.org/en/download/)
|
|
46
|
+
- Storyblok account (sign up [here](https://app.storyblok.com/#!/signup?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-cli))
|
|
47
|
+
- Personal access token from Storyblok (get it [here](https://app.storyblok.com/#/me/account?tab=token))
|
|
527
48
|
|
|
528
|
-
|
|
49
|
+
## Documentation
|
|
529
50
|
|
|
530
|
-
|
|
51
|
+
> [!WARNING]
|
|
52
|
+
> Official documentation for this package v4 is still in development. In the meantime, please refer to the internal documentation for the [v4 beta](src/README.md).
|
|
531
53
|
|
|
532
|
-
|
|
54
|
+
## Setup
|
|
533
55
|
|
|
534
|
-
|
|
535
|
-
$ storyblok generate-migration --space 00000 --component product --field image
|
|
536
|
-
```
|
|
56
|
+
This package relies on [pnpm](https://pnpm.io/) to manage dependencies. For instructions on how to install pnpm, please visit [pnpm.io](https://pnpm.io/installation).
|
|
537
57
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
```js
|
|
541
|
-
module.exports = function (block) {
|
|
542
|
-
block.image = block.image.replace('a.storyblok.com', 'my-custom-domain.com')
|
|
543
|
-
}
|
|
58
|
+
```bash
|
|
59
|
+
pnpm install
|
|
544
60
|
```
|
|
545
61
|
|
|
546
|
-
|
|
62
|
+
## Build
|
|
547
63
|
|
|
548
|
-
```
|
|
549
|
-
|
|
64
|
+
```bash
|
|
65
|
+
pnpm build
|
|
550
66
|
```
|
|
551
67
|
|
|
552
|
-
|
|
553
|
-
|
|
68
|
+
### Testing
|
|
554
69
|
|
|
555
|
-
To
|
|
70
|
+
To run the tests you can use the following command:
|
|
556
71
|
|
|
557
|
-
```
|
|
558
|
-
|
|
72
|
+
```bash
|
|
73
|
+
pnpm run test
|
|
559
74
|
```
|
|
560
75
|
|
|
561
|
-
|
|
76
|
+
If you prefer a more visual experience while writing tests you can use this command powered by [vitest/ui](https://vitest.dev/guide/ui):
|
|
562
77
|
|
|
563
|
-
```
|
|
564
|
-
|
|
78
|
+
```bash
|
|
79
|
+
pnpm run test:ui
|
|
565
80
|
```
|
|
566
81
|
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
```js
|
|
570
|
-
var richtextConverter = require('/usr/local/lib/node_modules/storyblok-markdown-richtext')
|
|
82
|
+
You can also check the coverage with:
|
|
571
83
|
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
block.intro = richtextConverter.markdownToRichtext(block.intro)
|
|
575
|
-
}
|
|
576
|
-
}
|
|
84
|
+
```bash
|
|
85
|
+
pnpm run coverage
|
|
577
86
|
```
|
|
578
87
|
|
|
579
|
-
|
|
580
|
-
It is possible to generate Typescript type definitions for your Storyblok components. The type definitions are based on the components' JSON Schema that can be retrieved with the [pull-components](#pull-components) command.
|
|
88
|
+
### Debugging
|
|
581
89
|
|
|
582
|
-
|
|
90
|
+
To debug the CLI you can use the `launch.json` configuration in the `.vscode` folder. You can run any command with the debugger attached.
|
|
583
91
|
|
|
584
|
-
|
|
92
|
+

|
|
585
93
|
|
|
586
|
-
|
|
587
|
-
$ storyblok generate-typescript-typedefs
|
|
588
|
-
--sourceFilePaths <PATHS>
|
|
589
|
-
--destinationFilePath <PATH>
|
|
590
|
-
--typeNamesPrefix <STRING>
|
|
591
|
-
--typeNamesSuffix <STRING>
|
|
592
|
-
--JSONSchemaToTSOptionsPath <PATH>
|
|
593
|
-
--customFieldTypesParserPath <PATH>
|
|
594
|
-
```
|
|
595
|
-
|
|
596
|
-
#### Options
|
|
94
|
+
Then you can set breakpoints directly to the typescript files and the debugger will handle the rest with sourcempaps.
|
|
597
95
|
|
|
598
|
-
|
|
599
|
-
* `destinationFilePath` <sub>(alias `target`) *optional*</sub> : Path to the Typescript file that will be generated (*default*: `storyblok-component-types.d.ts`)
|
|
600
|
-
* `typeNamesPrefix` <sub>(alias `titlePrefix`) *optional*</sub> : A prefix that will be prepended to all the names of the generated types
|
|
601
|
-
* `typeNamesSuffix` <sub>(alias `titleSuffix`) *optional*</sub> : A suffix that will be appended to all the names of the generated types (*default*: `Storyblok`)
|
|
602
|
-
* `JSONSchemaToTSOptionsPath` <sub>(alias `compilerOptions`) *optional*</sub> : Path to a JSON file with a list of options supported by `json-schema-to-typescript`
|
|
603
|
-
* `customFieldTypesParserPath` <sub>(alias `customTypeParser`) *optional*</sub> : Path to the parser file for Custom Field Types
|
|
96
|
+

|
|
604
97
|
|
|
605
|
-
|
|
98
|
+
## Community
|
|
606
99
|
|
|
607
|
-
|
|
608
|
-
# Generate typedefs for the components retrieved for the space `12345` via the `storyblok pull-components` command
|
|
609
|
-
$ storyblok generate-typescript-typedefs --sourceFilePaths ./components.12345.json
|
|
100
|
+
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
|
|
610
101
|
|
|
611
|
-
|
|
612
|
-
$ storyblok generate-typescript-typedefs --sourceFilePaths ./fooComponent-12345.json,./barComponent-12345.json
|
|
102
|
+
- [Discuss Storyblok on Github Discussions](https://github.com/storyblok/storyblok/discussions)
|
|
613
103
|
|
|
614
|
-
|
|
615
|
-
$ storyblok generate-typescript-typedefs --sourceFilePaths ./components.12345.json --destinationFilePath ./types/my-custom-type-file.d.ts
|
|
104
|
+
For community support, chatting with other users, please visit:
|
|
616
105
|
|
|
617
|
-
|
|
618
|
-
$ storyblok generate-typescript-typedefs --sourceFilePaths ./components.12345.json --JSONSchemaToTSOptionsPath ./PathToJSONFileWithCustomOptions.json
|
|
106
|
+
- [Discuss Storyblok on Discord](https://discord.gg/jKrbAMz)
|
|
619
107
|
|
|
620
|
-
|
|
621
|
-
$ storyblok generate-typescript-typedefs --sourceFilePaths ./components.12345.json --customFieldTypesParserPath ./customFieldTypesParser.js
|
|
622
|
-
|
|
623
|
-
```
|
|
108
|
+
## Support
|
|
624
109
|
|
|
625
|
-
|
|
626
|
-
This script uses the `json-schema-to-typescript` library under the hood. Values of the [JSON Schema to Typescript options](https://www.npmjs.com/package/json-schema-to-typescript#options) can be customized providing a JSON file to the `JSONSchemaToTSOptionsPath`.
|
|
110
|
+
For bugs or feature requests, please [submit an issue](https://github.com/storyblok/storyblok-cli/issues/new/choose).
|
|
627
111
|
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
* `unknownAny` - The default value is `false` because it can help a smoother Typescript adoption on a JS project
|
|
112
|
+
> [!IMPORTANT]
|
|
113
|
+
> Please search existing issues before submitting a new one. Issues without a minimal reproducible example will be closed. [Why reproductions are Required](https://antfu.me/posts/why-reproductions-are-required).
|
|
631
114
|
|
|
632
|
-
|
|
115
|
+
### I can't share my company project code
|
|
633
116
|
|
|
634
|
-
|
|
635
|
-
{
|
|
636
|
-
"additionalProperties": false,
|
|
637
|
-
}
|
|
638
|
-
```
|
|
639
|
-
|
|
640
|
-
##### Custom Field Types parser
|
|
641
|
-
Storyblok [Custom Field Types](https://www.storyblok.com/docs/plugins/field-plugins/introduction) do not have inherent JSONSchema definitions. To overcome this issue, you can provide a path to a script exporting a parser function that should render a [JSONSchema Node](https://json-schema.org/learn/getting-started-step-by-step#define-properties) for each of your Custom Field Types. The parser function should be exported as a default export, like in the following example:
|
|
642
|
-
```js
|
|
643
|
-
export default function (key, obj) {
|
|
644
|
-
switch (obj.field_type) {
|
|
645
|
-
case 'my-custom-field-type-name':
|
|
646
|
-
return {
|
|
647
|
-
[key]: {
|
|
648
|
-
type: 'object',
|
|
649
|
-
properties: {
|
|
650
|
-
color: { type: 'string' }
|
|
651
|
-
},
|
|
652
|
-
required: ['color']
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
default:
|
|
656
|
-
return {}
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
```
|
|
117
|
+
We understand that you might not be able to share your company's project code. Please provide a minimal reproducible example that demonstrates the issue by using tools like [Stackblitz](https://stackblitz.com) or a link to a Github Repo lease make sure you include a README file with the instructions to build and run the project, important not to include any access token, password or personal information of any kind.
|
|
660
118
|
|
|
119
|
+
### I only have a question
|
|
661
120
|
|
|
121
|
+
If you have a question, please ask in the [Discuss Storyblok on Discord](https://discord.gg/jKrbAMz) channel.
|
|
662
122
|
|
|
123
|
+
## Contributing
|
|
663
124
|
|
|
125
|
+
If you're interested in contributing to Storyblok CLI, please read our [contributing docs](https://github.com/storyblok/.github/blob/main/contributing.md) before submitting a pull request.
|
|
664
126
|
|
|
665
|
-
##
|
|
127
|
+
## License
|
|
666
128
|
|
|
667
|
-
|
|
129
|
+
[License](/LICENSE)
|