5.4.1 • Published 1 month ago

sb-mig v5.4.1

Weekly downloads
56
License
MIT
Repository
github
Last release
1 month ago

npm npm GitHub issues npm

Requirements:

NodeLTS (18.x.x)

5.x.x version released!

Important Updates

  • Complete codebase overhaul to facilitate the utilization of features and requests to Storyblok. This development decreases the tight coupling with CLI, while improving folder and file structure.
  • New feature: Content synchronization (including stories and assets) in various directions, ranging from space to space, from space to file, and from file to space.
  • New feature: Introduced support for TypeScript Schema, with the added ability to precompile them on-the-fly before synchronization, improving usage with sb-mig.
  • New feature: Plugin synchronization capabilities.
  • New feature: 'Discover' command.
  • New feature: 'Migrate' command (tailored for Storyblok's Site Builder).
  • Upgraded eslint configuration for more efficient coding practices.
  • Updated all dependencies to their latest stable versions.
  • Refreshed Github Actions workflows to enhance development practices.
  • Expanded test coverage (with more additions anticipated).

Breaking changes

  • Please note that sb-mig no longer extends support for Node versions older than 18.x.x, as part of its adoption of native ESM support.
  • The sb-mig backup command has now been aligned with all other commands, causing minor changes in its execution (although functionalities have been preserved).

Do not hesitate to get in touch if you encounter any issues or require further clarification on any points.

4.x.x version released!

  • Whole deployment now, is handled by semantic-release. And is just normal repository, instead of Lerna monorepo which is not needed anymore, and it was recently unmaintained (now it was passed to nrwl to maintain (https://github.com/lerna/lerna/issues/3121) will see what will happen in future with it :)
  • Fromt the code perspective, there are no breaking changes between 3.x.x and 4.x.x but i'm going to fix some stuff now and add some more functionalities to it. So stay tuned!
  • This Readme, which is also kinda documentation, will also be updated. Cause in some places there is misleading information. The best documentation though is just sb-mig --help command.

3.x.x version released!

  • completely rewritten to simple Meow lib with help of Typescript. Check migration guide
  • support native es modules
  • thinner then Oclif framework, still with Typescript
  • decide to remove plugin support, cause it was not used enough
  • make all commands follow same standard (backup command, had some very weird syntax before, now it works like sync)

Contents


How to install and configure

npm install --global sb-mig

In your working directory (usually root of your repo where u have your app/webpage using Storyblok), you have to create a .env file with your variables:

STORYBLOK_OAUTH_TOKEN=1234567890qwertyuiop
STORYBLOK_SPACE_ID=12345

# For nextjs
# NEXT_PUBLIC_STORYBLOK_ACCESS_TOKEN=zxcvbnmasdfghjkl

# For gatsby
# GATSBY_STORYBLOK_ACCESS_TOKEN=zxcvbnmasdfghjkl

# any other (you have to handle '.env' access in frontend yourself (for example with dotenv package)
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 = {
  storyblokComponentsLocalDirectory: "src/@storyblok-components",
  sbmigWorkingDirectory: "sbmig",
  componentsDirectories: ["src", "storyblok"],
  schemaFileExt: "sb.js",
  datasourceExt: "sb.datasource.js",
  rolesExt: "sb.roles.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 = {
  componentsDirectories: ["src", "storyblok", "@storyblok-components"],
};

Schema documentation:

Basics

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

export default {
  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 .sb.js schema need to match .sb.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 .sb.js component schema files with your Storyblok space.

In v4.x.x There is 1 way to sync your schemas, which is to name all your schemas with .sb.js extension. You can have them in any place of your repositories, as long as this place is pointed in storyblok.config.js componentDirectories field, which is set to componentsDirectories: ["src", "storyblok"], by default:

sb-mig sync components row column

This command will look for row.sb.js and column.sb.js files inside a directories mentioned in componentDirectories field. (You can change directories name mapping by modifying componentDirectories inside storyblok.config.js). You can also change the extension searched by changing schemaFileExt. How to install and configure)

Syncing datasources

You can also sync your datasources.

Add datasourceExt: "your-own-extension", to your storyblok.config.js. If u will not add it, will be used default one (sb.datasource.js)

// storyblok.config.js
export default {
  ...
  datasourcesDirectory: "mydatasource.ext.js"
  ...
};

Create file with .sb.datasource.js (or your defined one) extension inside it. Basic schema for datasources file:

export default {
  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 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)

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.

You can also sync all datasources, and that's the command we strongly recommend. It will sync all datasources also the one from node_modules, so potentially from storyblok-components. But will prefer syncing local ones, if there will be clash of datasources filenames (for example, you can have datasource from node_modules, but wanted to overwrite some fields, you will be able to do that.

sb-mig sync datasources --all

Presets support

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 .sb.js file to be picked up while syncing.

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

then run

sb-mig backup component-presets --one 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.

import allPresets from './presets/_text-block-preset.json'

export default {
  ...
  schema: {
    title: {
      type: "text",
      pos: 1
    },
  },
  all_presets: allPresets,
  ...
};

Now, sync your component

sb-mig sync components text-block --presets

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


Development

To develop and make changes to the library:

git clone git@github.com:sb-mig/sb-mig.git

Install packages

yarn

Run development command

yarn build:dev

It will watch a file change, and on every change, will rebuild typescript and build the whole lib/cli.

The you can use

node dist/index.js debug 

to access sb-mig

For your conveniece, you can also, link it to proper sb-mi name:

yarn link

And then you can use it like that:

sb-mig debug

Releasing

Flow of branching out and merging

  • Before creating feature branch from beta, make sure you have newest beta. (by git pull origin beta).
  • Create feature branch from beta
  • Do your changes
  • Create PR from feature branch to beta (it will run checks on your feature branch)
  • Merge PR to beta (it will release beta channel)
  • Create PR from beta to master (it will run checks on beta branch)
  • Merge PR to master (it will release stable channel)
  • After release properly done, make sure to pull master to beta (by git pull origin master), Push directly, resolve conflicts in favor of master.

Roadmap

  • Sync / Migrate content (stories)
  • Improve preset creation/update
  • Sync Roles
  • Sync / Migrate datasources
  • Sync components with extensions
  • Sync presets
  • Sync single component
  • Sync all components
  • Sync components using schema based .sb.js file (based on idea from storyblok-migrate)
  • Component groups
  • Sync custom fields

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

5.4.1-beta.1

1 month ago

5.4.1

1 month ago

5.3.0-beta.7

2 months ago

5.4.0

2 months ago

5.4.0-beta.1

2 months ago

5.3.0-beta.6

4 months ago

5.3.0

4 months ago

5.3.0-beta.2

1 year ago

5.3.0-beta.1

1 year ago

5.3.0-beta.4

1 year ago

5.3.0-beta.3

1 year ago

5.3.0-beta.5

1 year ago

5.2.2-beta.1

1 year ago

5.2.1-beta.1

1 year ago

5.2.1-beta.2

1 year ago

5.2.2

1 year ago

5.2.1

1 year ago

5.0.8-beta.2

1 year ago

5.0.8-beta.3

1 year ago

5.0.8-beta.4

1 year ago

5.0.8

1 year ago

5.0.7

1 year ago

5.0.6

1 year ago

5.0.5

1 year ago

5.0.4

1 year ago

5.0.3

1 year ago

5.0.0

1 year ago

5.0.5-beta.1

1 year ago

5.0.5-beta.2

1 year ago

5.0.5-beta.3

1 year ago

5.0.8-beta.1

1 year ago

5.1.4-beta.1

1 year ago

5.1.3-beta.1

1 year ago

5.1.1-beta.1

1 year ago

5.1.3

1 year ago

5.1.2

1 year ago

5.1.1

1 year ago

5.1.0

1 year ago

5.0.6-beta.1

1 year ago

4.1.0-beta.76

1 year ago

4.1.0-beta.78

1 year ago

4.1.0-beta.77

1 year ago

5.2.0

1 year ago

4.1.0-beta.79

1 year ago

4.1.0-beta.81

1 year ago

4.1.0-beta.80

1 year ago

4.1.0-beta.83

1 year ago

4.1.0-beta.82

1 year ago

5.0.4-beta.1

1 year ago

5.0.4-beta.2

1 year ago

5.2.0-beta.1

1 year ago

5.0.7-beta.5

1 year ago

5.0.7-beta.3

1 year ago

5.0.7-beta.4

1 year ago

5.0.7-beta.1

1 year ago

5.0.7-beta.2

1 year ago

5.1.0-beta.1

1 year ago

5.1.0-beta.2

1 year ago

5.1.2-beta.3

1 year ago

5.1.2-beta.4

1 year ago

5.1.2-beta.1

1 year ago

5.1.2-beta.2

1 year ago

5.1.2-beta.7

1 year ago

5.1.2-beta.8

1 year ago

5.1.2-beta.5

1 year ago

5.1.2-beta.6

1 year ago

5.1.0-beta.3

1 year ago

5.1.0-beta.4

1 year ago

4.1.0-beta.36

2 years ago

4.1.0-beta.38

2 years ago

4.1.0-beta.37

2 years ago

4.1.0-beta.39

2 years ago

4.1.0-beta.43

2 years ago

4.1.0-beta.42

2 years ago

4.1.0-beta.45

2 years ago

4.1.0-beta.44

2 years ago

4.1.0-beta.47

2 years ago

4.1.0-beta.46

2 years ago

4.1.0-beta.49

2 years ago

4.1.0-beta.48

2 years ago

4.1.0-beta.41

2 years ago

4.1.0-beta.40

2 years ago

4.1.0-beta.54

2 years ago

4.1.0-beta.53

2 years ago

4.1.0-beta.56

2 years ago

4.1.0-beta.55

2 years ago

4.1.0-beta.58

2 years ago

4.1.0-beta.57

2 years ago

4.1.0-beta.59

2 years ago

4.1.0-beta.50

2 years ago

4.1.0-beta.52

2 years ago

4.1.0-beta.51

2 years ago

4.1.0-beta.65

2 years ago

4.1.0-beta.64

2 years ago

4.1.0-beta.67

2 years ago

4.1.0-beta.66

2 years ago

4.1.0-beta.69

2 years ago

4.1.0-beta.68

2 years ago

4.1.0-beta.61

2 years ago

4.1.0-beta.60

2 years ago

4.1.0-beta.63

2 years ago

4.1.0-beta.62

2 years ago

4.1.0-beta.75

2 years ago

4.1.0-beta.70

2 years ago

4.1.0-beta.72

2 years ago

4.1.0-beta.71

2 years ago

4.1.0-beta.74

2 years ago

4.1.0-beta.73

2 years ago

4.1.0-beta.10

2 years ago

4.1.0-beta.12

2 years ago

4.1.0-beta.11

2 years ago

4.1.0-beta.14

2 years ago

4.1.0-beta.13

2 years ago

4.1.0-beta.16

2 years ago

4.1.0-beta.15

2 years ago

4.1.0-beta.18

2 years ago

4.1.0-beta.17

2 years ago

4.1.0-beta.19

2 years ago

4.1.0-beta.21

2 years ago

4.1.0-beta.20

2 years ago

4.1.0-beta.23

2 years ago

4.1.0-beta.22

2 years ago

4.1.0-beta.25

2 years ago

4.1.0-beta.24

2 years ago

4.1.0-beta.27

2 years ago

4.1.0-beta.26

2 years ago

4.1.0-beta.29

2 years ago

4.1.0-beta.28

2 years ago

4.1.0-beta.32

2 years ago

4.1.0-beta.31

2 years ago

4.1.0-beta.34

2 years ago

4.1.0-beta.33

2 years ago

4.1.0-beta.35

2 years ago

4.1.0-beta.30

2 years ago

4.1.0-beta.8

2 years ago

4.1.0-beta.9

2 years ago

4.1.0-beta.6

2 years ago

4.1.0-beta.7

2 years ago

4.1.0-beta.4

2 years ago

4.1.0-beta.5

2 years 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

3 years ago

4.0.4

3 years ago

4.0.7

3 years ago

4.0.6

3 years ago

4.0.1

3 years ago

4.0.0

3 years ago

4.0.3

3 years ago

4.0.2

3 years ago

3.0.0-beta.1

3 years ago

3.0.0-beta.3

3 years ago

3.0.0-beta.2

3 years ago

4.0.9

3 years ago

3.0.0-beta.5

3 years ago

4.0.8

3 years ago

3.0.0-beta.4

3 years ago

3.1.11

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

4.0.10

3 years ago

4.0.11

3 years ago

2.9.13

3 years ago

3.1.3

3 years ago

3.1.2

3 years ago

3.1.1

3 years ago

3.1.0

3 years ago

3.1.7

3 years ago

3.1.6

3 years ago

3.1.5

3 years ago

3.1.4

3 years ago

3.1.10

3 years ago

3.1.9

3 years ago

3.1.8

3 years ago

2.9.3

3 years ago

2.9.2

4 years ago

2.9.1

4 years ago

2.9.0

4 years ago

2.8.5

4 years ago

2.8.6

4 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

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

2.0.0-beta.14

5 years ago

2.0.0-beta.13

5 years ago

2.0.0-beta.12

5 years ago

2.0.0-beta.11

5 years ago

2.0.0-beta.10

5 years ago

2.0.0-beta.9

5 years ago

2.0.0-beta.8

5 years ago

2.0.0-beta.7

5 years ago

2.0.0-beta.6

5 years ago

2.0.0-beta.5

5 years ago

2.0.0-beta.4

5 years ago

2.0.0-beta.3

5 years ago

2.0.0-beta.1

5 years ago

2.0.0-beta.0

5 years ago

1.3.10

5 years ago

1.3.9

5 years ago

1.3.8

5 years ago

1.3.7

5 years ago

1.3.6

5 years ago

1.3.5

5 years ago

1.3.4

5 years ago

1.3.3

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.9

5 years ago

1.2.8

5 years ago

1.2.7

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.18

5 years ago

1.1.17

5 years ago

1.1.16

5 years ago

1.1.15

5 years ago

1.1.14

5 years ago

1.1.13

5 years ago

1.1.12

5 years ago

1.1.11

5 years ago

1.1.1

5 years ago

1.0.2

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.10

5 years ago

1.0.0

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.2

5 years ago

0.0.13

5 years ago

0.1.0

5 years ago

0.0.12

5 years ago

0.0.10

5 years ago

0.0.11

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.5

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago