UNPKG

18.5 kBMarkdownView Raw
1<p align="center">
2 <img width="250" height="250" src="./sb-mig-logo.png" alt="Logo" />
3</p>
4If you've found an issue or you have feature request - <a href="https://github.com/marckraw/sb-mig/issues/new">open an issue</a> or look if it was <a href="https://github.com/sb-mig/sb-mig/issues/">already created</a>.
5
6[![npm](https://img.shields.io/npm/v/sb-mig.svg)](https://www.npmjs.com/package/sb-mig)
7[![npm](https://img.shields.io/npm/dt/sb-mig.svg)](ttps://img.shields.io/npm/dt/sb-mig.svg)
8[![GitHub issues](https://img.shields.io/github/issues/sb-mig/sb-mig.svg?style=flat-square&v=1)](https://github.com/sb-mig/sb-mig/issues?q=is%3Aopen+is%3Aissue)
9
10# 2.x.x version released!
11
12- completely rewritten to [Oclif](https://github.com/oclif/oclif) framework written in Typescript (with as little changes to usage as possible, check [migration guide](https://github.com/sb-mig/sb-mig/blob/oclif-research/MIGRATION-GUIDE.md))
13- support for Oclif plugin system
14- created [sb-mig](https://github.com/sb-mig) organization for better grouping related stuff
15- created npm `@sb-mig` scope aswell, for the same reason
16
17## Contents
18
19- [How to install and configure](#how-to-install-and-configure)
20- [Generate whole starter project](#generate-whole-starter-project)
21- [Usage](#usage)
22- [Commands](#commands)
23 - [`sb-mig backup`](#sb-mig-backup)
24 - [`sb-mig debug`](#sb-mig-debug)
25 - [`sb-mig help [COMMAND]`](#sb-mig-help-command)
26 - [`sb-mig plugins`](#sb-mig-plugins)
27 - [`sb-mig sync TYPE [LIST]`](#sb-mig-sync-type-list)
28- [Plugins](#plugins)
29- [Schema documentation:](#schema-documentation)
30 - [Basics](#basics)
31 - [Syncing components](#syncing-components)
32 - [Syncing datasources](#syncing-datasources)
33 - [Presets support](#presets-support)
34- [Development](#development)
35- [Roadmap](#roadmap)
36
37---
38
39# How to install and configure
40
41```
42npm install --global sb-mig
43```
44
45You have to create a `.env` file with your variables:
46
47```
48STORYBLOK_OAUTH_TOKEN=1234567890qwertyuiop
49STORYBLOK_SPACE_ID=12345
50STORYBLOK_ACCESS_TOKEN=zxcvbnmasdfghjkl
51```
52
53You can also provide your custom config. To do that u have to create `storyblok.config.js` file in your root catalog with following structure:
54
55```
56// storyblok.config.js
57module.exports = {
58 sbmigWorkingDirectory: "sbmig",
59 componentDirectory: "sbmig/storyblok",
60 componentsDirectories: ["src", "storyblok"],
61 schemaFileExt: "sb.js",
62 storyblokApiUrl: "https://api.storyblok.com/v1",
63 oauthToken: process.env.STORYBLOK_OAUTH_TOKEN,
64 spaceId: process.env.STORYBLOK_SPACE_ID,
65 accessToken: process.env.STORYBLOK_ACCESS_TOKEN,
66};
67```
68
69You don't need to pass everything to the config file, just add what you need and it will be merged with the original config. If you just need to set the `componentDirectory`, for example, add the following:
70
71```
72// storyblok.config.js
73module.exports = {
74 componentDirectory: 'storyblok',
75};
76```
77
78## Generate whole starter project
79
801. Create folder with custom name and get inside
812. Create `storyblok.config.js` file if u want to use custom gatsby storyblok starter, or custom npm component scope
82
83```
84module.exports = {
85 ...
86 boilerplateUrl: "git@github.com:your-custom-gatsby-storyblok-boilerplate.git",
87 componentsDirectories: ["src", "storyblok","node_modules/@custom-scope","node_modules/@storyblok-components"],
88 ...
89}
90
91```
92
933. Create `.env` file only with your storyblok oauth token (which you can get from your storyblok account - this is needed for script to have access to creating space api)
94
95```
96STORYBLOK_OAUTH_TOKEN=1234567890qwertyuiop
97```
98
994. Install `generate-project` `sb-mig` plugin.
100```
101sb-mig plugins:install generate-project
102```
103
1045. Run
105
106```
107sb-mig generate "My Greatest Project"
108```
109
110It will generate basic boilerplate.
111
112If u want to specify components you would like to add you can do that by adding parameter to the command, and list of components (list of all public available components in @storyblok-components scope: [npm list](https://www.npmjs.com/settings/storyblok-components/packages)):
113
114```
115sb-mig generate "My Greatest Project" --add @custom-scope/ui-text-block @storyblok-components/ui-surface
116```
117
1186. You can also pass `--copy` flag, which will copy component files from `node_modules` to your local, and add it properly to `components.js` file.
119```
120sb-mig generate "My Greatest Project" --add @custom-scope/ui-text-block @storyblok-components/ui-surface --copy
121```
122
1237. Wait for magic to happen.
1248. Run sync command to sync all components to storyblok.
125
126```
127sb-mig sync components --all --ext
128```
129
1307. `npm start`
1318. Enjoy your new project.
132
133# Usage
134
135```sh-session
136$ sb-mig help
137CLI to rule the world. (and handle stuff related to Storyblok CMS)
138
139VERSION
140 sb-mig/2.0.0-beta.5 darwin-x64 node-v12.16.2
141
142USAGE
143 $ sb-mig [COMMAND]
144
145COMMANDS
146 backup Command for backing up anything related to Storyblok
147 debug Output extra debugging
148 help display help for sb-mig
149 sync Synchronize components, datasources with Storyblok space.
150```
151
152# Commands
153
154<!-- commands -->
155* [`sb-mig backup`](#sb-mig-backup)
156* [`sb-mig debug`](#sb-mig-debug)
157* [`sb-mig help [COMMAND]`](#sb-mig-help-command)
158* [`sb-mig plugins`](#sb-mig-plugins)
159* [`sb-mig plugins:install PLUGIN...`](#sb-mig-pluginsinstall-plugin)
160* [`sb-mig plugins:link PLUGIN`](#sb-mig-pluginslink-plugin)
161* [`sb-mig plugins:uninstall PLUGIN...`](#sb-mig-pluginsuninstall-plugin)
162* [`sb-mig plugins:update`](#sb-mig-pluginsupdate)
163* [`sb-mig sync TYPE [LIST]`](#sb-mig-sync-type-list)
164
165## `sb-mig backup`
166
167Command for backing up anything related to Storyblok
168
169```
170USAGE
171 $ sb-mig backup
172
173OPTIONS
174 -a, --allComponents Backup all components.
175 -d, --allDatasources Backup all datasources.
176 -e, --datasourceEntries=datasourceEntries Backup one datasource entries by datasource name.
177 -f, --oneComponentsGroup=oneComponentsGroup Backup one components group by name.
178 -g, --allComponentsGroups Backup all components groups.
179 -h, --help show CLI help
180 -i, --onePreset=onePreset Backup one preset by id.
181 -l, --allPresets Backup all presets.
182 -o, --oneComponent=oneComponent Backup one component by name.
183 -p, --oneComponentPresets=oneComponentPresets Backup all presets for one component
184 -x, --oneDatasource=oneDatasource Backup one datasource by name.
185```
186
187_See code: [src/commands/backup.ts](https://github.com/sb-mig/sb-mig/blob/v2.2.1/src/commands/backup.ts)_
188
189## `sb-mig debug`
190
191Output extra debugging
192
193```
194USAGE
195 $ sb-mig debug
196
197OPTIONS
198 -h, --help show CLI help
199```
200
201_See code: [src/commands/debug.ts](https://github.com/sb-mig/sb-mig/blob/v2.2.1/src/commands/debug.ts)_
202
203## `sb-mig help [COMMAND]`
204
205display help for sb-mig
206
207```
208USAGE
209 $ sb-mig help [COMMAND]
210
211ARGUMENTS
212 COMMAND command to show help for
213
214OPTIONS
215 --all see all commands in CLI
216```
217
218_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v2.2.3/src/commands/help.ts)_
219
220## `sb-mig plugins`
221
222list installed plugins
223
224```
225USAGE
226 $ sb-mig plugins
227
228OPTIONS
229 --core show core plugins
230
231EXAMPLE
232 $ sb-mig plugins
233```
234
235_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v1.7.10/src/commands/plugins/index.ts)_
236
237## `sb-mig plugins:install PLUGIN...`
238
239installs a plugin into the CLI
240
241```
242USAGE
243 $ sb-mig plugins:install PLUGIN...
244
245ARGUMENTS
246 PLUGIN plugin to install
247
248OPTIONS
249 -f, --force yarn install with force flag
250 -h, --help show CLI help
251 -v, --verbose
252
253DESCRIPTION
254 Can be installed from npm or a git url.
255
256 Installation of a user-installed plugin will override a core plugin.
257
258 e.g. If you have a core plugin that has a 'hello' command, installing a user-installed plugin with a 'hello' command
259 will override the core plugin implementation. This is useful if a user needs to update core plugin functionality in
260 the CLI without the need to patch and update the whole CLI.
261
262ALIASES
263 $ sb-mig plugins:add
264
265EXAMPLES
266 $ sb-mig plugins:install myplugin
267 $ sb-mig plugins:install https://github.com/someuser/someplugin
268 $ sb-mig plugins:install someuser/someplugin
269```
270
271_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v1.7.10/src/commands/plugins/install.ts)_
272
273## `sb-mig plugins:link PLUGIN`
274
275links a plugin into the CLI for development
276
277```
278USAGE
279 $ sb-mig plugins:link PLUGIN
280
281ARGUMENTS
282 PATH [default: .] path to plugin
283
284OPTIONS
285 -h, --help show CLI help
286 -v, --verbose
287
288DESCRIPTION
289 Installation of a linked plugin will override a user-installed or core plugin.
290
291 e.g. If you have a user-installed or core plugin that has a 'hello' command, installing a linked plugin with a 'hello'
292 command will override the user-installed or core plugin implementation. This is useful for development work.
293
294EXAMPLE
295 $ sb-mig plugins:link myplugin
296```
297
298_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v1.7.10/src/commands/plugins/link.ts)_
299
300## `sb-mig plugins:uninstall PLUGIN...`
301
302removes a plugin from the CLI
303
304```
305USAGE
306 $ sb-mig plugins:uninstall PLUGIN...
307
308ARGUMENTS
309 PLUGIN plugin to uninstall
310
311OPTIONS
312 -h, --help show CLI help
313 -v, --verbose
314
315ALIASES
316 $ sb-mig plugins:unlink
317 $ sb-mig plugins:remove
318```
319
320_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v1.7.10/src/commands/plugins/uninstall.ts)_
321
322## `sb-mig plugins:update`
323
324update installed plugins
325
326```
327USAGE
328 $ sb-mig plugins:update
329
330OPTIONS
331 -h, --help show CLI help
332 -v, --verbose
333```
334
335_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v1.7.10/src/commands/plugins/update.ts)_
336
337## `sb-mig sync TYPE [LIST]`
338
339Synchronize components, datasources with Storyblok space.
340
341```
342USAGE
343 $ sb-mig sync TYPE [LIST]
344
345ARGUMENTS
346 TYPE (components|datasources) What to synchronize
347 LIST Space separated list of component names. Example: card product-card row layout
348
349OPTIONS
350 -a, --all Synchronize all components.
351 -e, --ext Synchronize with file extension. Default extension: '.sb.js'
352 -h, --help show CLI help
353 -n, --packageName Synchronize based on installed package name.
354 -p, --presets Synchronize components with presets.
355```
356
357_See code: [src/commands/sync.ts](https://github.com/sb-mig/sb-mig/blob/v2.2.1/src/commands/sync.ts)_
358<!-- commandsstop -->
359
360# Plugins
361`sb-mig` core features are part of this repository. But `sb-mig` is build in a way that you can easily add your own command as a plugin. Here will be the list of plugins, which are already supported by `sb-mig`. For installation instructions see: [TBD](#)
362
363- [plugin-add-components](https://github.com/sb-mig/plugin-add-components) - with this plugin, you can easily install storyblok react components to your project ( compliant with `components.js` file syntax: [TBD](#) )
364- [plugin-create-component](https://github.com/sb-mig/plugin-create-component) - with this plugin, you can easily add working dummy component with all needed syntax to monorepos with storyblok components, like this unofficial one [storyblok-components/components](https://github.com/storyblok-components/components) which is deployed to `@storyblok-components` scope of public npm
365- [plugin-generate-project](https://github.com/sb-mig/plugin-generate-project) - with this plugin, you need only one command, to generate and bootstrap whole new Storyblok project with provided list of available components. It is also created storyblok space for you, and after command is done, you are ready to develop, edit and use installed components. ()
366
367To build your own plugin, head over to this instruction: [TBD](#)
368
369# Schema documentation:
370
371## Basics
372
373This is what a basic storyblok `.js` schema file which maps to a component looks like:
374
375```
376module.exports = {
377 name: "text-block",
378 display_name: "Text block",
379 is_root: false,
380 is_nestable: true,
381 component_group_name: "Some group",
382 schema: {
383 title: {
384 type: "text",
385 },
386 }
387};
388```
389
390**Important notice:** name inside `.js` schema need to match `.js` filename.
391
392You can add anything mentioned here: https://www.storyblok.com/docs/api/management#core-resources/components/components to your component. (with the exception of `component_group_uuid`: insert `component_group_name` and `sb-mig` will resolve `uuid` automagically).
393
394You can also add `tabs` to your component schema (which is not documented in above storyblok documentation):
395
396```
397...
398 schema: {
399 title: {
400 type: "text",
401 },
402 Settings: {
403 type: "tab",
404 display_name: "Settings",
405 "keys": [
406 "title"
407 ]
408 },
409 }
410...
411```
412
413There is also support for `sections` inside components:
414
415```
416...
417 schema: {
418 title: {
419 type: "text",
420 },
421 somesection: {
422 type: "section",
423 "keys": [
424 "title"
425 ]
426 },
427 }
428...
429```
430
431## Syncing components
432
433The main purpose of `sb-mig` is to sync your `.js` component schema files with your `Storyblok` space.
434
435There are 2 ways to sync your schemas, which to use depends on your file structure. If you are keeping all of your schema files in a single folder, use:
436
437```
438sb-mig sync components row column
439```
440
441This command will look for `row.js` and `column.js` files inside a directory named `storyblok`. You can change the directory name mapping by modifying `componentDirectory` inside `storyblok.config.js`). [How to install and configure](#how-to-install-and-configure))
442
443```
444sb-mig sync components --ext row column
445```
446
447This command will look for any file named `row.sb.js` and `column.sb.js` inside `src` and `storyblok` folders. To modify the directories in this case you can set `componentsDirectories` in the config. You can also change the extension searched by changing `schemaFileExt`. [How to install and configure](#how-to-install-and-configure))
448
449## Syncing datasources
450
451**Beta feature:** You can also sync your `datasources`.
452Add `datasourcesDirectory` to `storyblok.config.js`. (default: 'storyblok')
453
454```
455// storyblok.config.js
456module.exports = {
457 ...
458 datasourcesDirectory: "datasources"
459 ...
460};
461```
462
463Create file with `.datasource.js` extension inside it. Basic schema for datasources file:
464
465```
466module.exports = {
467 name: "icons",
468 slug: "icons",
469 datasource_entries: [
470 {
471 componentName: "icon1",
472 importPath: "icon 2"
473 },
474 {
475 componentName: "icon2",
476 importPath: "icon 2"
477 },
478 {
479 componentName: "icon3",
480 importPath: "icon 3"
481 },
482 {
483 componentName: "icon4",
484 importPath: "icon 4"
485 },
486 ]
487};
488```
489
490Above snippet will create `datasource` with `icons` name and `icons` slug. `datasource_entries` will be your `name <-> value` array.
491Single `datasource entry` consist of **precisely** 2 fields. But they can be named however you like (advise to name it: `name` and `value`, it will be anyway translated to that, due to how storyblok stores them)
492
493Command for syncing datasources:
494
495```
496sb-mig sync datasources icons
497```
498
499Example output from above command
500
501```
502Synciong priovided datasources icons...
503Trying to sync provided datasources: icons
504Trying to get all Datasources.
505Trying to get 'icons' datasource entries.
506Trying to get 'icons' datasource.
507✓ Datasource entries for 15558 datasource id has been successfully synced
508```
509
510Like with syncing component, you can also use syncing multiple datasources at once:
511
512```
513sb-mig sync datasources icons logos
514```
515
516```
517✓ Datasource entries for 15558 datasource id has been successfully synced.
518✓ Datasource entries for 15559 datasource id has been successfully synced.
519```
520
521## Presets support
522
523- Experimental
524
525Writing your own predefined data (presets) for components can be a pain, so with `sb-mig` you can create presets for your components in the storyblok gui, and then export them to a schema based `.js` file to be picked up while syncing.
526
527To do so, first create a preset for your component in storyblok:
528
529<img src="https://user-images.githubusercontent.com/8228270/72166029-caf8cc00-33c8-11ea-891b-194f57974653.png" width=300 />
530<br>
531<img src="https://user-images.githubusercontent.com/8228270/72166255-33e04400-33c9-11ea-9431-c6d0b684f5fb.png" width=300 />
532
533then run
534
535```
536sb-mig backup --oneComponentPresets text-block // component you've created preset for
537```
538
539The tool will now download all presets related to the `text-block` component.
540Now you can go to your folder structure (by default: `./sbmig/component-presets/`), and rename the generated file to (for example): `text-block-preset`.
541
542You should remove the id field from the preset (it will be looked up by name)
543
544Finally, add the `all_presets` field to your `text-block` component schema.
545
546```
547const allPresets = require('./presets/_text-block-preset.json');
548
549module.exports = {
550 ...
551 schema: {
552 title: {
553 type: "text",
554 pos: 1
555 },
556 },
557 all_presets: allPresets,
558 ...
559};
560```
561
562Now, sync your component
563
564```
565sb-mig sync components --presets text-block
566```
567
568output:
569
570```
571Checking preset for 'text-block-2' component
572Trying to get all 'text-block-2' presets.
573Trying to get all components.
574Trying to get preset by id: 437086
575Preset: 'My Preset' with '437086' id has been updated.
576```
577
578---
579
580_This feature is still quite experimental, that's why it's not completely straightforward to do. Workin on it :)_
581
582---
583
584## Development
585
586To develop and make changes to the library:
587
588```
589git clone git@github.com:sb-mig/sb-mig.git
590```
591
592Install packages
593
594```
595yarn
596```
597
598Link package to easy test it with `sb-mig` command
599
600```
601yarn link
602```
603
604or use it like that without linking:
605
606```
607./bin/run // same as linked `sb-mig` command
608```
609
610## Roadmap
611
612- [ ] Sync / Migrate content (stories)
613- [ ] Improve preset creation/update
614- ~~[ ] End-to-end solution to add / update components~~ // it will be responsibility of different plugin. Check [here](https://github.com/sb-mig/plugin-generate-project)
615- [x] Sync / Migrate datasources
616- [x] Sync components with extensions
617- [x] Sync presets
618- [x] Sync single component
619- [x] Sync all components
620- [x] Sync components using schema based .js file (based on idea from [storyblok-migrate](https://github.com/maoberlehner/storyblok-migrate))
621- [x] Component groups
622- [x] Sync custom fields
623
624The general purpose of this package is to manage creation and maintenance of components from code/command line, to be able to create a whole space and project structure without using GUI.