5.2.2 • Published 6 months ago

sb-mig v5.2.2

Weekly downloads
56
License
MIT
Repository
github
Last release
6 months ago

npm npm GitHub issues

Contents


How to install and configure

npm install --global sb-mig

You have to create a .env file with your variables:

STORYBLOK_OAUTH_TOKEN=1234567890qwertyuiop
STORYBLOK_SPACE_ID=12345
STORYBLOK_ACCESS_TOKEN=zxcvbnmasdfghjkl

You can also provide your custom config. To do that u have to create storyblok.config.js file in your root catalog with following structure:

// storyblok.config.js
module.exports = {
  sbmigWorkingDirectory: "sbmig",
  componentDirectory: "sbmig/storyblok",
  componentsDirectories: ["src", "storyblok"],
  schemaFileExt: "sb.js",
  storyblokApiUrl: "https://api.storyblok.com/v1",
  oauthToken: process.env.STORYBLOK_OAUTH_TOKEN,
  spaceId: process.env.STORYBLOK_SPACE_ID,
  accessToken: process.env.STORYBLOK_ACCESS_TOKEN,
};

You 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:

// storyblok.config.js
module.exports = {
  componentDirectory: 'storyblok',
};

Usage

$ npm install -g sb-mig

$ sb-mig help
CLI to rule the world. (and handle stuff related to Storyblok CMS)

VERSION
  sb-mig/2.0.0-beta.5 darwin-x64 node-v12.16.2

USAGE
  $ sb-mig [COMMAND]

COMMANDS
  backup  Command for backing up anything related to Storyblok
  debug   Output extra debugging
  help    display help for sb-mig
  sync    Synchronize components, datasources with Storyblok space.

Commands

sb-mig backup

Command for backing up anything related to Storyblok

USAGE
  $ sb-mig backup

OPTIONS
  -a, --allComponents                            Backup all components.
  -d, --allDatasources                           Backup all datasources.
  -e, --datasourceEntries=datasourceEntries      Backup one datasource entries by datasource name.
  -f, --oneComponentsGroup=oneComponentsGroup    Backup one components group by name.
  -g, --allComponentsGroups                      Backup all components groups.
  -h, --help                                     show CLI help
  -i, --onePreset=onePreset                      Backup one preset by id.
  -l, --allPresets                               Backup all presets.
  -o, --oneComponent=oneComponent                Backup one component by name.
  -p, --oneComponentPresets=oneComponentPresets  Backup all presets for one component
  -x, --oneDatasource=oneDatasource              Backup one datasource by name.

See code: src/commands/backup.ts

sb-mig debug

Output extra debugging

USAGE
  $ sb-mig debug

OPTIONS
  -h, --help  show CLI help

See code: src/commands/debug.ts

sb-mig help [COMMAND]

display help for sb-mig

USAGE
  $ sb-mig help [COMMAND]

ARGUMENTS
  COMMAND  command to show help for

OPTIONS
  --all  see all commands in CLI

See code: @oclif/plugin-help

sb-mig sync TYPE [LIST]

Synchronize components, datasources with Storyblok space.

USAGE
  $ sb-mig sync TYPE [LIST]

ARGUMENTS
  TYPE  (components|datasources) What to synchronize
  LIST  Space separated list of component names. Example: card product-card row layout

OPTIONS
  -a, --all      Synchronize all components.
  -e, --ext      Synchronize with file extension. Default extension: '.sb.js'
  -h, --help     show CLI help
  -p, --presets  Synchronize components with presets.

See code: src/commands/sync.ts

Schema documentation:

Basics

This is what a basic storyblok .js schema file which maps to a component looks like:

module.exports = {
  name: "text-block",
  display_name: "Text block",
  is_root: false,
  is_nestable: true,
  component_group_name: "Some group",
  schema: {
    title: {
      type: "text",
    },
  }
};

Important notice: name inside .js schema need to match .js filename.

You 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).

You can also add tabs to your component schema (which is not documented in above storyblok documentation):

...
  schema: {
    title: {
      type: "text",
    },
    Settings: {
      type: "tab",
      display_name: "Settings",
      "keys": [
        "title"
      ]
    },
  }
...

There is also support for sections inside components:

...
  schema: {
    title: {
      type: "text",
    },
    somesection: {
      type: "section",
      "keys": [
        "title"
      ]
    },
  }
...

Syncing components

The main purpose of sb-mig is to sync your .js component schema files with your Storyblok space.

There 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:

sb-mig --sync row column

This 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)

sb-mig --sync --ext row column

This 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)

Syncing datasources

Beta feature: You can also sync your datasources. Add datasourcesDirectory to storyblok.config.js. (default: 'storyblok')

// storyblok.config.js
module.exports = {
  ...
  datasourcesDirectory: "datasources"
  ...
};

Create file with .datasource.js extension inside it. Basic schema for datasources file:

module.exports = {
  name: "icons",
  slug: "icons",
  datasource_entries: [
    {
      componentName: "icon1",
      importPath: "icon 2"
    },
    {
      componentName: "icon2",
      importPath: "icon 2"
    },
    {
      componentName: "icon3",
      importPath: "icon 3"
    },
    {
      componentName: "icon4",
      importPath: "icon 4"
    },
  ]
};

Above snippet will create datasource with icons name and icons slug. datasource_entries will be your name <-> value array. Single datasource entry consist of precisely 2 fieldds. 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)

Command for syncing datasources:

sb-mig --sync-datasources icons

Example output from above command

Synciong priovided datasources icons...
Trying to sync provided datasources: icons
Trying to get all Datasources.
Trying to get 'icons' datasource entries.
Trying to get 'icons' datasource.
✓ Datasource entries for 15558 datasource id has been successfully synced

Like with syncing component, you can also use syncing multiple datasources at once:

sb-mig --sync-datasources icons logos
✓ Datasource entries for 15558 datasource id has been successfully synced.
✓ Datasource entries for 15559 datasource id has been successfully synced.

Presets support

  • Experimental

Writing 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.

To do so, first create a preset for your component in storyblok:

then run

sb-mig --component-presets text-block    // component you've created preset for

The tool will now download all presets related to the text-block component. Now you can go to your folder structure (by default: ./sbmig/component-presets/), and rename the generated file to (for example): text-block-preset.

You should remove the id field from the preset (it will be looked up by name)

Finally, add the all_presets field to your text-block component schema.

const allPresets = require('./presets/_text-block-preset.json');

module.exports = {
  ...
  schema: {
    title: {
      type: "text",
      pos: 1
    },
  },
  all_presets: allPresets,
  ...
};

Now, sync your component

sb-mig --sync text-block

output:

Checking preset for 'text-block-2' component
Trying to get all 'text-block-2' presets.
Trying to get all components.
Trying to get preset by id: 437086
Preset: 'My Preset' with '437086' id has been updated.

This feature is still quite experimental, that's why it's not completely straightforward to do. Workin on it :)


5.3.0-beta.2

6 months ago

5.3.0-beta.1

6 months ago

5.3.0-beta.4

6 months ago

5.3.0-beta.3

6 months ago

5.3.0-beta.5

6 months ago

5.2.2-beta.1

7 months ago

5.2.1-beta.1

7 months ago

5.2.1-beta.2

7 months ago

5.2.2

7 months ago

5.2.1

7 months ago

5.0.8-beta.2

10 months ago

5.0.8-beta.3

10 months ago

5.0.8-beta.4

10 months ago

5.0.8

11 months ago

5.0.7

11 months ago

5.0.6

11 months ago

5.0.5

11 months ago

5.0.4

11 months ago

5.0.3

11 months ago

5.0.0

11 months ago

5.0.5-beta.1

11 months ago

5.0.5-beta.2

11 months ago

5.0.5-beta.3

11 months ago

5.0.8-beta.1

11 months ago

5.1.4-beta.1

9 months ago

5.1.3-beta.1

9 months ago

5.1.1-beta.1

10 months ago

5.1.3

9 months ago

5.1.2

9 months ago

5.1.1

10 months ago

5.1.0

10 months ago

5.0.6-beta.1

11 months ago

4.1.0-beta.76

11 months ago

4.1.0-beta.78

11 months ago

4.1.0-beta.77

11 months ago

5.2.0

9 months ago

4.1.0-beta.79

11 months ago

4.1.0-beta.81

11 months ago

4.1.0-beta.80

11 months ago

4.1.0-beta.83

11 months ago

4.1.0-beta.82

11 months ago

5.0.4-beta.1

11 months ago

5.0.4-beta.2

11 months ago

5.2.0-beta.1

9 months ago

5.0.7-beta.5

11 months ago

5.0.7-beta.3

11 months ago

5.0.7-beta.4

11 months ago

5.0.7-beta.1

11 months ago

5.0.7-beta.2

11 months ago

5.1.0-beta.1

10 months ago

5.1.0-beta.2

10 months ago

5.1.2-beta.3

10 months ago

5.1.2-beta.4

10 months ago

5.1.2-beta.1

10 months ago

5.1.2-beta.2

10 months ago

5.1.2-beta.7

9 months ago

5.1.2-beta.8

9 months ago

5.1.2-beta.5

10 months ago

5.1.2-beta.6

10 months ago

5.1.0-beta.3

10 months ago

5.1.0-beta.4

10 months ago

4.1.0-beta.36

1 year ago

4.1.0-beta.38

1 year ago

4.1.0-beta.37

1 year ago

4.1.0-beta.39

1 year ago

4.1.0-beta.43

1 year ago

4.1.0-beta.42

1 year ago

4.1.0-beta.45

1 year ago

4.1.0-beta.44

1 year ago

4.1.0-beta.47

1 year ago

4.1.0-beta.46

1 year ago

4.1.0-beta.49

1 year ago

4.1.0-beta.48

1 year ago

4.1.0-beta.41

1 year ago

4.1.0-beta.40

1 year ago

4.1.0-beta.54

1 year ago

4.1.0-beta.53

1 year ago

4.1.0-beta.56

1 year ago

4.1.0-beta.55

1 year ago

4.1.0-beta.58

1 year ago

4.1.0-beta.57

1 year ago

4.1.0-beta.59

1 year ago

4.1.0-beta.50

1 year ago

4.1.0-beta.52

1 year ago

4.1.0-beta.51

1 year ago

4.1.0-beta.65

1 year ago

4.1.0-beta.64

1 year ago

4.1.0-beta.67

1 year ago

4.1.0-beta.66

1 year ago

4.1.0-beta.69

1 year ago

4.1.0-beta.68

1 year ago

4.1.0-beta.61

1 year ago

4.1.0-beta.60

1 year ago

4.1.0-beta.63

1 year ago

4.1.0-beta.62

1 year ago

4.1.0-beta.75

12 months ago

4.1.0-beta.70

1 year ago

4.1.0-beta.72

1 year ago

4.1.0-beta.71

1 year ago

4.1.0-beta.74

1 year ago

4.1.0-beta.73

1 year ago

4.1.0-beta.10

1 year ago

4.1.0-beta.12

1 year ago

4.1.0-beta.11

1 year ago

4.1.0-beta.14

1 year ago

4.1.0-beta.13

1 year ago

4.1.0-beta.16

1 year ago

4.1.0-beta.15

1 year ago

4.1.0-beta.18

1 year ago

4.1.0-beta.17

1 year ago

4.1.0-beta.19

1 year ago

4.1.0-beta.21

1 year ago

4.1.0-beta.20

1 year ago

4.1.0-beta.23

1 year ago

4.1.0-beta.22

1 year ago

4.1.0-beta.25

1 year ago

4.1.0-beta.24

1 year ago

4.1.0-beta.27

1 year ago

4.1.0-beta.26

1 year ago

4.1.0-beta.29

1 year ago

4.1.0-beta.28

1 year ago

4.1.0-beta.32

1 year ago

4.1.0-beta.31

1 year ago

4.1.0-beta.34

1 year ago

4.1.0-beta.33

1 year ago

4.1.0-beta.35

1 year ago

4.1.0-beta.30

1 year ago

4.1.0-beta.8

1 year ago

4.1.0-beta.9

1 year ago

4.1.0-beta.6

1 year ago

4.1.0-beta.7

1 year ago

4.1.0-beta.4

2 years ago

4.1.0-beta.5

1 year ago

4.1.0-beta.3

2 years ago

4.0.12-beta.1

2 years ago

4.0.12-beta.2

2 years ago

4.0.12-beta.3

2 years ago

4.1.0-beta.1

2 years ago

4.1.0-beta.2

2 years ago

4.0.5

2 years ago

4.0.4

2 years ago

4.0.7

2 years ago

4.0.6

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

4.0.3

2 years ago

4.0.2

2 years ago

3.0.0-beta.1

2 years ago

3.0.0-beta.3

2 years ago

3.0.0-beta.2

2 years ago

4.0.9

2 years ago

3.0.0-beta.5

2 years ago

4.0.8

2 years ago

3.0.0-beta.4

2 years ago

3.1.11

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

4.0.10

2 years ago

4.0.11

2 years ago

2.9.13

2 years ago

3.1.3

2 years ago

3.1.2

2 years ago

3.1.1

2 years ago

3.1.0

2 years ago

3.1.7

2 years ago

3.1.6

2 years ago

3.1.5

2 years ago

3.1.4

2 years ago

3.1.10

2 years ago

3.1.9

2 years ago

3.1.8

2 years ago

2.9.3

3 years ago

2.9.2

3 years ago

2.9.1

3 years ago

2.9.0

3 years ago

2.8.5

3 years ago

2.8.6

3 years ago

2.8.3

4 years ago

2.8.4

4 years ago

2.8.2

4 years ago

2.8.1

4 years ago

2.8.0

4 years ago

2.7.0

4 years ago

2.6.0

4 years ago

2.5.0

4 years ago

2.5.1

4 years ago

2.4.0-beta.0

4 years ago

2.4.0-beta.2

4 years ago

2.4.0-beta.1

4 years ago

2.3.6

4 years ago

2.3.5

4 years ago

2.3.4

4 years ago

2.3.2

4 years ago

2.3.3

4 years ago

2.2.1

4 years ago

2.1.12

4 years ago

2.1.11

4 years ago

2.1.9

4 years ago

2.1.10

4 years ago

2.1.8

4 years ago

2.1.7

4 years ago

2.1.6

4 years ago

2.1.5

4 years ago

2.1.3

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

2.0.0-beta.14

4 years ago

2.0.0-beta.13

4 years ago

2.0.0-beta.12

4 years ago

2.0.0-beta.11

4 years ago

2.0.0-beta.10

4 years ago

2.0.0-beta.9

4 years ago

2.0.0-beta.8

4 years ago

2.0.0-beta.7

4 years ago

2.0.0-beta.6

4 years ago

2.0.0-beta.5

4 years ago

2.0.0-beta.4

4 years ago

2.0.0-beta.3

4 years ago

2.0.0-beta.1

4 years ago

2.0.0-beta.0

4 years ago

1.3.10

4 years ago

1.3.9

4 years ago

1.3.8

4 years ago

1.3.7

4 years ago

1.3.6

4 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.9

4 years ago

1.2.8

4 years ago

1.2.7

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.18

4 years ago

1.1.17

4 years ago

1.1.16

4 years ago

1.1.15

4 years ago

1.1.14

4 years ago

1.1.13

4 years ago

1.1.12

4 years ago

1.1.11

4 years ago

1.1.1

4 years ago

1.0.2

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.10

4 years ago

1.0.0

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.2

4 years ago

0.0.13

4 years ago

0.1.0

4 years ago

0.0.12

4 years ago

0.0.10

4 years ago

0.0.11

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.5

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago