contentful / contentful-cli

The official Contentful command line interface. Use Contentful features straight from the command line!
https://www.contentful.com/developers/docs/tutorials/cli/
MIT License
328 stars 62 forks source link

TypeScript Support for migration scripts #1417

Open diminutivesloop opened 2 years ago

diminutivesloop commented 2 years ago

Expected Behavior

The contentful space migration command should support migration scripts written in TypeScript.

Actual Behavior

Passing TypeScript migration scripts causes the command to fail and report syntax errors.

Context

I'm currently using the legacy contentful-migration cli tool following the instructions for using it with TypeScript here. However this is inconvenient because contentful-migration doesn't use the config options I've set via contentful config. If built-in support for TypeScript isn't feasible, then the documentation for running TypeScript migrations with contentful-migration should at least be updated for contentful-cli.

Environment

samhanes-glooko commented 2 years ago

For what it's worth, this setup works for me:

yarn run contentful space migration migrations/test.ts

package.json:

{
  "private": true,
  "scripts": {
    "contentful": "NODE_OPTIONS=\"-r ts-node/register\" contentful"
  },
  "dependencies": {
    "contentful-migration": "^4.9.2"
  },
  "devDependencies": {
    "@types/node": "^18.0.0",
    "contentful-cli": "^1.14.15",
    "ts-node": "^10.8.1",
    "typescript": "^4.7.4"
  }
}

tsconfig.json:

{
  "compilerOptions": {
    "target": "ES2021",
    "module": "commonJS",
    "moduleResolution": "node",
    "lib": ["ES2021"],
    "strict": true,
    "types": ["node"]
  },
  "include": ["migrations/**/*.ts"]
}

migrations/test.ts:

import Migration from "contentful-migration";
export = function (migration: Migration) {
    // ...
};