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-migration-tool

v1.3.0

Published

Run Contentful migrations easier.

Downloads

1,005

Readme

Contentful Migration Tool

Test Npm Docker

Run Contentful migrations more easily with just one command.

Why another CLI?

I decided to create this CLI when I read this article: "Integrating migrations in a continuous delivery pipeline with CircleCI". I found that approach very interesting, so I decided to build something very close to that.

With this CLI you can run migrations easier and keep track of migrations you already run.

You can integrate this into your existing CI without any effort.

CLI usage

The official contentful-migration is a peerDependency, so it is required.

You can run this command:

npx -p contentful-migration@latest -p contentful-migration-tool@latest contentful-migration-tool run ./migrations

Or you can install contentful-migration and contentful-migration-tool as devDependencies and then just run:

# install dependencies
npm install --save-dev contentful-migration@latest contentful-migration-tool@latest

# run migrations
npx contentful-migration-tool run ./migrations

If you use TypeScript, you will also need tsx to run TypeScript migrations:

# install dependencies
npm install --save-dev contentful-migration@latest contentful-migration-tool@latest tsx

# run migrations
npx tsx ./node_modules/.bin/contentful-migration-tool run ./migrations

Remember to set the required environment variables before running the above commands.

Options

Environment Variables

  • CONTENT_MANAGEMENT_TOKEN - required - Contentful Content Management Token. You can create one from the section API keys under your space settings.

  • SPACE_ID - required - Contentful Space ID. You can get the Space ID from the section General settings under your space settings. The Space ID is also visibile in the url.

  • ENVIRONMENT_ID - required - Contentful Environment ID.

Docker usage

With this Docker image, you don't even need Node.js

docker run --rm --tty --name contentful-migration-runner -e CONTENT_MANAGEMENT_TOKEN=$CONTENT_MANAGEMENT_TOKEN -e SPACE_ID=$SPACE_ID -e ENVIRONMENT_ID=$ENVIRONMENT_ID -v $(pwd)/migrations:/app/migrations marcomontalbano/contentful-migration

Options

Environment Variables

  • CONTENT_MANAGEMENT_TOKEN - required - Contentful Content Management Token. You can create one from the section API keys under your space settings.

  • SPACE_ID - required - Contentful Space ID. You can get the Space ID from the section General settings under your space settings. The Space ID is also visible in the url.

  • ENVIRONMENT_ID - required - Contentful Environment ID.

Volumes

  • /app/migrations - required - Migrations folder.

Arguments

  • --cfmversion 4.0.0 - optional - Use this argument if you want to change the contentful-migration version. (default to latest)

Migrations folder

Either you use Docker or CLI, you should create a /migrations (or whatever name) folder. This folder will contain all your migration description files.

A migration description file is a .js or .ts file that contains a migration script. These scripts are written using Contentful Migration syntax which you are already familiar with.

The filename must follow this naming convention:

<version> - <description> .ts

version starts from 1 and must be incremental.

description is used to easily recognize the purpose of the migration.

A real example can be: 1-create-author.ts


e.g. javascript

module.exports = function (migration, context) {
  const author = migration.createContentType('author');
  const name = author.createField('name');
  name.type('Symbol').required(true);
};

e.g. typescript

import { MigrationFunction } from 'contentful-migration'

const migrate: MigrationFunction = (migration) => {
  const author = migration.createContentType('author');
  const name = author.createField('name');
  name.type('Symbol').required(true);
}

export = migrate

Useful Readings