Skip to content

CloudCannon/bookshop-to-split-config-migrator

Repository files navigation

Bookshop to Split Configuration Migration Tool

This tool helps migrate Bookshop components to CloudCannon's new split configuration format.

What it does

  1. Scans for Bookshop files: Finds all *.bookshop.{yml,yaml,json,toml} files in your project
  2. Transforms the structure:
    • Removes spec and moves its subkeys (except structures) to the root
    • Renames blueprint to value
    • Preserves _inputs and preview as-is
    • Adds _name field to the value based on the file path
  3. Tracks structures: Maps which files reference which structures
  4. Generates CloudCannon config: Creates the necessary split config files
  5. Creates output files: Saves transformed files with matching extensions:
    • .bookshop.yml.cloudcannon.structure-value.yml
    • .bookshop.json.cloudcannon.structure-value.json
    • .bookshop.toml.cloudcannon.structure-value.yml (converted to YAML)

Installation

cd migration-tools
npm install

Usage

npm run migrate

Or run directly:

node migrate.js

Supported File Formats

Input Format Output Format Notes
.bookshop.yml .cloudcannon.structure-value.yml Standard YAML format
.bookshop.yaml .cloudcannon.structure-value.yml Alternative YAML extension
.bookshop.json .cloudcannon.structure-value.json JSON format preserved
.bookshop.toml .cloudcannon.structure-value.yml TOML converted to YAML

Example Transformation

Input (src/components/about/team/team.bookshop.yml):

spec:
  structures:
    - content_blocks
  label: About Team
  description: About Team section
  icon: "groups"
  tags: []

blueprint:
  title: Our leadership & Team Members
  team_members:
    - name: Cody Fisher
      designation: Co-Founder & CEO

preview:

_inputs:
  image:
    type: image

Output (src/components/about/team/team.cloudcannon.structure-value.yml):

label: About Team
description: About Team section
icon: groups
tags: []
value:
  title: Our leadership & Team Members
  team_members:
    - name: Cody Fisher
      designation: Co-Founder & CEO
  _name: about/team
preview:
_inputs:
  image:
    type: image

JSON Input Example (src/components/hero/hero.bookshop.json):

{
  "spec": {
    "structures": ["content_blocks"],
    "label": "Hero Component",
    "icon": "hero"
  },
  "blueprint": {
    "title": "Welcome to our site"
  },
  "_inputs": {
    "title": {
      "type": "text"
    }
  }
}

JSON Output (src/components/hero/hero.cloudcannon.structure-value.json):

{
  "label": "Hero Component",
  "icon": "hero",
  "value": {
    "title": "Welcome to our site",
    "_name": "hero"
  },
  "_inputs": {
    "title": {
      "type": "text"
    }
  }
}

Generated Files

The tool creates:

  1. Individual structure value files: *.cloudcannon.structure-value.yml next to each original bookshop file
  2. Structures configuration: .cloudcannon/components.cloudcannon.structures.yml
  3. Main config: cloudcannon.config.yml (if it doesn't exist)
  4. Migration report: migration-tools/migration-report.json

ID Generation

File paths are converted to IDs by extracting the component path:

  • src/components/about/team/team.bookshop.ymlabout/team
  • src/components/global/faq/faq.bookshop.ymlglobal/faq

Testing

Run the test suite:

npm test

Files Generated

After migration, you'll have:

  • All original .bookshop.yml files preserved
  • New .cloudcannon.structure-value.yml files created
  • CloudCannon split config files in .cloudcannon/ directory
  • A detailed migration report in JSON format

Next Steps

  1. Review the generated files
  2. Test your components in CloudCannon
  3. Remove original .bookshop.yml files when satisfied
  4. Commit the new CloudCannon configuration

Portability

This tool is designed to be portable and can be:

  • Copied to other projects
  • Published as an npm package
  • Integrated into build processes

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published