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

@xolvio/contentful-pipelines

v1.2.2

Published

## How to Install

Downloads

4

Readme

Contentful Pipelines

How to Install

npm -D install @xolvio/contentful-pipelines

API

The contentful pipelines package exposes two commands which can be run either as a package.json script or executed in the code (runtime).

Migrations

Given directory structure:

your-project
├── README.md
├── src
│   └── components
│       ├── Title
│       │    └── migrations
│       │         └── title
│       │               └── 1513695986378-create-title-type.js
│       └── Sections
│            └── migrations
│                 └── sections
│                       └── 1513695986378-create-title-type.js
├── package.json

Running as package.json command:

"migrations": "CONTENTFUL_MANAGEMENT_API=<contentful-management-api-key> CONTENTFUL_SPACE_ID=<contentful-space-id> CONTENTFUL_ENVIRONMENT_ID=<contentful-environment-id> xolvio-contentful-migrations src/components/Title src/components/Sections"

Running from code:

async function runMigrations(migrationPaths, options);

| Parameter | Type | Default | Description | | :--------------- | :----------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------------------- | | migrationPaths | string[] | [] | Required. List of paths to the components containing migration scripts. Paths should be relative to the project's root. | | options | {targetEnvironment: string,spaceId: string,contentfulManagementApiKey: string} | targetEnvironment = process.env.CONTENTFUL_ENVIRONMENT_ID spaceId = process.env.CONTENTFUL_SPACE_IDcontentfulManagementApiKey = process.env.CONTENTFUL_MANAGEMENT_API | Optional. Overwrites the process.env variables |

const { runMigrations } = require("@xolvio/contentful-pipelines");

await runMigrations(["src/components/Title", "src/components/Sections"]);

Creating the contentful environment

Running as package.json command:

"createQaEnvironmentFromProd": "CONTENTFUL_MANAGEMENT_API=<contentful-management-api-key> CONTENTFUL_SPACE_ID=<contentful-space-id> CONTENTFUL_SOURCE_ENVIRONMENT=<contentful-prod-environment-id> CONTENTFUL_ENVIRONMENT_ID=<contentful-environment-id> xolvio-contentful-create-environment"

Running from code:

async function createEnvironmentFromSource(options);

| Parameter | Type | Default | Description | | :-------- | :----------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------- | | options | {sourceEnvironment: string,targetEnvironment: string,spaceId: string,contentfulManagementApiKey: string} | sourceEnvironment=process.env.CONTENTFUL_SOURCE_ENVIRONMENTtargetEnvironment = process.env.CONTENTFUL_ENVIRONMENT_ID spaceId = process.env.CONTENTFUL_SPACE_IDcontentfulManagementApiKey = process.env.CONTENTFUL_MANAGEMENT_API | Optional. Overwrites the process.env variables |

Example:

await createEnvironmentFromSource();

Writing migration scripts

For executing the migrations we're using Contentful Migrate Tool so the migrations are written using their syntax. Using their CLI tool you can quickly create the migration scripts based on the existing Contentful Content Types.

Useful scripts

Fetch existing entry data (used for initial data migration scripts)

module.exports.up = async (migration, { makeRequest }) => {
  const existing = await makeRequest({
    method: "GET",
    url: `/entries/ENTRY_ID_TO_QUERY`,
  }).catch(console.log);

  console.log("existing: ", JSON.stringify(existing.fields));
};

Create contentful entry from within the contentful migration script:

module.exports.up = async (migration, { makeRequest }) => {
  await makeRequest({
    method: "PUT",
    url: `/entries/NEW_ENTRY_ID`,
    data: EXISTING_FIELDS_FROM_SNIPPET_ABOVE,
    headers: {
      "X-Contentful-Content-Type": "CONTENT_TYPE_ID",
    },
  });
};

TODO

  • CLI for running migrations for all of the components listed in the package.json