npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

contentful-schema-diff

v0.10.3

Published

[![npm version](https://img.shields.io/npm/v/contentful-schema-diff.svg)](https://www.npmjs.com/package/contentful-schema-diff) [![License](https://img.shields.io/npm/l/contentful-schema-diff.svg)](LICENSE.txt) [![CircleCI](https://circleci.com/gh/waterma

Downloads

2,087

Readme

contentful-schema-diff

npm version License CircleCI Coverage Status

A tool to automatically generate a starting point for a schema migration between two Contentful spaces

npm install --global contentful-schema-diff

usage:

contentful-schema-diff --from <export file or space> --to <export file or space>

Options:
  --help              Show help                                        [boolean]
  --version           Show version number                              [boolean]
  --from, -f          A contentful export file, or Contentful Space ID[required]
  --to, -t            A contentful export file, space ID, or environment within
                      the "from" space                                [required]
  --content-type, -c  Generate a migration only for this content type.  Repeat
                      to select multiple types.
  --out, -o           The output directory (or file if "--one-file" was
                      specified) in which to place the migration
  --js                force writing javascript files                   [boolean]
  --ts                force writing typescript files                   [boolean]
  --token, -a         A Contentful management token to download content types
                      from a space
  --one-file          Write all the migrations in a single file
  --no-format, -F     disables formatting the output file              [boolean]

Note: "from" indicates the space with the old versions of the content types. You will be generating a migration from the state of the current production space to the state of your dev space. Thus 'from = production' and 'to = dev'.

The tool works either on Contentful export files, or by directly downloading content from a space.

⚠️ WARNING! ⚠️

This tool outputs Typescript files by default. You cannot run these files directly with the contenful-migration tool. See https://github.com/watermarkchurch/contentful-schema-diff/issues/49 for instructions on how to run them directly, or https://github.com/watermarkchurch/contentful-schema-diff/issues/59 for how to run them programmatically. Or better yet, send us a pull request that would make the tool output javascript migrations!

Method 1: download content types from the space directly

$ contentful-schema-diff --from <from space> --to <to space> --token <my contentful management token>

Or you can compare any environment to master, for example to generate a migration that will fast-forward your master environment to match the staging environment in that space:

$ contentful-schema-diff --from <from space> --to staging --token <my contentful management token>

Or you can use another environment as the source with the 'slash syntax', for example to do a migration that will fast-forward the tip of the unreleased "develop" branch (which runs in staging against the "Staging" environment in contentful) to your current working environment. Then you can check this migration into your pull request.

$ contentful-schema-diff --from 1xab12345678/staging --to dev --token <my contentful management token>

Method 2: Export the files first

$ contentful-export --space-id <from space> --management-token $CONTENTFUL_MANAGEMENT_TOKEN \
  --skip-content --skip-roles --skip-webhooks


$ contentful-export --space-id <to space> --management-token $CONTENTFUL_MANAGEMENT_TOKEN \
  --skip-content --skip-roles --skip-webhooks

Alternately this could also used to generate a migration between two environments

$ contentful-export --space-id <space> --management-token $CONTENTFUL_MANAGEMENT_TOKEN \
  --skip-content --skip-roles --skip-webhooks --environment-id=gburgett


$ contentful-export --space-id <space> --management-token $CONTENTFUL_MANAGEMENT_TOKEN \
  --skip-content --skip-roles --skip-webhooks --environment-id=dev

After you have downloaded the files, run the contentful-schema-diff tool:

$ contentful-schema-diff --from contentful-export-<from space>-<date>.json \
  --to contentful-export-<to space>-<date>.json

Results

One or many new typescript file(s) will be created. They will include many of the migrations necessary to transition the "from" space to have the same structure as the "to" space. Where it couldn't figure out how to do the migration, it has left a code comment with the diff of the fields for that content type.

example:

import Migration from 'contentful-migration'

// Generated by contentful-schema-diff
// from 7yx6ovlj39n5/staging
// to   gburgett
export = function(migration : Migration) {

  const resource = migration.createContentType('resource', {
    displayField: 'name',
    name: 'Resource',
    description: ''
  })

  resource.createField('name', {
    name: 'Name',
    type: 'Symbol',
    localized: false,
    required: true,
    validations: [],
    disabled: false,
    omitted: false
  })

  resource.createField('type', {
    name: 'Type',
    type: 'Symbol',
    localized: false,
    required: false,
    validations:
      [{
        in:
          ['document',
            'video',
            'article',
            'asset']
      }],
    disabled: false,
    omitted: false
  })

  resource.createField('tags', {
    name: 'Tags',
    type: 'Array',
    localized: false,
    required: false,
    validations: [],
    disabled: false,
    omitted: false,
    items:
      {
        type: 'Symbol',
        validations: []
      }
  })

  resource.createField('asset', {
    name: 'Asset',
    type: 'Link',
    localized: false,
    required: false,
    validations: [],
    disabled: false,
    omitted: false,
    linkType: 'Asset'
  })

  resource.createField('externalAsset', {
    name: 'External Asset',
    type: 'Symbol',
    localized: false,
    required: false,
    validations: [{ regexp: { pattern: '^(ftp|http|https):\\/\\/(\\w+:{0,1}\\w*@)?(\\S+)(:[0-9]+)?(\\/|\\/([\\w#!:.?+=&%@!\\-\\/]))?$' } }],
    disabled: false,
    omitted: false
  })

  resource.changeEditorInterface('name', 'singleLine')

  resource.changeEditorInterface('type', 'dropdown')

  resource.changeEditorInterface('tags', 'tagEditor')

  resource.changeEditorInterface('asset', 'assetLinkEditor')

  resource.changeEditorInterface('externalAsset', 'urlEditor')

}
import Migration from 'contentful-migration'

// Generated by contentful-schema-diff
// from 7yx6ovlj39n5
// to   gburgett
export = function(migration : Migration) {

  let menu = migration.editContentType('menu')

  /*
 [
   ...
   {
     items: {
       validations: [
         {
           linkContentType: [
-            "menu"
+            "dropdownMenu"
             "menuButton"
           ]
         }
       ]
     }
   }
-  {
-    id: "sideMenu"
-    name: "Side Menu"
-    type: "Link"
-    validations: [
-      {
-        linkContentType: [
-          "menu"
-        ]
-        message: "The Side Menu must be a Menu"
-      }
-    ]
-    linkType: "Entry"
-  }
 ]
 */

  menu.deleteField('sideMenu')

  menu.editField('items')
    .items({
      type: 'Link',
      validations:
        [{
          linkContentType:
            ['dropdownMenu',
              'menuButton'],
          message: 'The items must be either buttons or drop-down menus.'
        }],
      linkType: 'Entry',
    })

}