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

cf-migrations

v3.0.1

Published

A tool to manage Contentful migrations

Downloads

903

Readme

cf-migrations

cf-migrations is a tool for deploying and managing migrations and environment aliases in Contentful.

⚙️ Installation

Pre-requisites:

  • Node LTS
npm install --save cf-migrations

🔌 Usage

🔐 Contentful credentials

Almost all the cf-migrations commands require contentful credentials besides specific arguments per command. You can pass those arguments as command line arguments or environment variables.

You can use the -h or --help in any command to show its usage help. For example, run npx cf-migrations init -h to see the required and optional arguments of the init command.

💡 cf-migrations uses dotenv to read a .env file so you write your credentials only once when using cf-migrations in your project locally.

🥾 Init environment

In order for you to use cf-migrations deploy or release commands, you should run the following:

npx cf-migrations init

It creates a new content model named cf-migrations that will store every deployed migration file name. cf-migrations uses these names to assess if there're pending migrations yet to be deployed.

🏗 Create migration

After initializing your contentful environment, it's time to write some migrations! To create a new migration file in your project, type the following:

npx cf-migrations create create-foo --migrationsDir src/migrations

It will create a typescript migration file, src/migrations/1660225580514-create-foo.ts for example. Use the flag --useJavascript or --js to create a javascript file instead.

Note that the migrations should have a proper timestamp.

🚚 Deploy migration

After writing your migration, you can deploy a single or every pending migration with the following command:

npx cf-migrations deploy

📢 Note that the "deploy" and "release" commands only support javascript files. See the typescript section for more details about how you could work with typescript migrations.

After the deployment, the pending migrations changes will be applied and their file names will be added to the cf-migrations content type.

🚀 Release new environment version

The release functionality works by assessing if there are pending migrations to be deployed (this verification can be skipped), creating a new environment, deploying pending migrations on it and update the target environment alias to the new environment.

npx cf-migrations release

Since the number of available environments is limited, the oldest release that is not aliased will be removed.

📢 Since contentful does not have a functionality yet to also copy the scheduled actions if you create a new environment from an existing one, we have created a feature as a workaround to do the job. The feature is by default activated and can be deactivated by setting the parameter copy-scheduled-actions to false.

📚 API

Using cf-migrations' CLI isn't the only option: you can integrate its functionalities with your project by using the library's API.

The API documentation can be found here.

🎖 Typescript support

You can use typescript to write the migrations but you'll need to use tools such as ts-node or have compiling tooling for your migrations.

Suppose you have the following project where there is a typescript compilation tooling:

./
├── my_project/
│   ├── tsconfig.json
│   ├── src/
│       ├── migrations/
│           ├── 1660225580514-create-contenty-type.ts
│           ├── 1660225721863-add-field.ts
            ...
│   ├── dist/
│       ├── migrations/
│           ├── 1660225580514-create-contenty-type.js
│           ├── 1660225721863-add-field.js
            ...
...

You could deploy the migrations with the following command:

npx cf-migrations deploy --migrationsDir dist/migrations

An alternative is to run the deployment with ts-node, therefore no need to compile the migrations:

npx ts-node node_modules/.bin/cf-migrations deploy --migrationsDir src/migrations

👥 Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

🏛 License

MIT