-
Notifications
You must be signed in to change notification settings - Fork 0
Standalone CAMO project using Typescript migration files
Using your favourite package manager:
# Create a new project directory
$ mkdir my-camo-ts
$ cd my-camo-ts
# npm
$ npm init
# or yarn
$ yarn init
# or ppm
$ pnpm init
Then answer all the package manager setup questions.
# npm
$ npm install --save-dev @sambauers/camo typescript @types/node @tsconfig/node16
# or yarn
$ yarn add --dev @sambauers/camo typescript @types/node @tsconfig/node16
# or pnpm
$ pnpm add --save-dev @sambauers/camo typescript @types/node @tsconfig/node16
In your projects package.json
add these scripts in the scripts
definitions. Adjust the migrate
script to call your preferred package manager (npm
shown):
{
"scripts": {
"build": "rm -rf migrations && tsc",
"migrate": "npm build && camo"
}
}
This will contain the Typescript migrations.
$ mkdir -p src/migrations
Add a file in the root of your project named tsconfig.json
containing:
{
"extends": "@tsconfig/node16/tsconfig.json",
"include": [
"src/migrations/*.ts"
],
"compilerOptions": {
"outDir": "./migrations"
}
}
Now when you run tsc
on the command line to compile the migrations, it will:
- Look in
src/migrations
for the source migration scripts - Compile those migration scripts
- Output the compiled Javascript files to a
migrations
directory, which is the default location that CAMO looks for migration scripts
Create a .env
file in the project root containing (at least):
# Contentful Active Migration Organiser (CAMO)
# The space ID to connect to
CONTENTFUL_MIGRATION_SPACE_ID='<your-contentful-space-id>'
# The access token to connect with
CONTENTFUL_MIGRATION_ACCESS_TOKEN='<your-contentful-access-token>'
Run the migrate --list
command:
# npm
$ npm run migrate --list
# or yarn
$ yarn migrate --list
# or pnpm
$ pnpm migrate --list
You will be asked if you want CAMO create the content type in Contentful.
Create a Typescript migration file in the src/migrations
folder with your desired schema.
The compiled Javascript version of the file you created above should now be visible with the --list
option:
# npm
$ npm run migrate --list
# or yarn
$ yarn migrate --list
# or pnpm
$ pnpm migrate --list
The compiled Javascript version of the file you created above should now be applied when running CAMO:
# npm
$ npm run migrate
# or yarn
$ yarn migrate
# or pnpm
$ pnpm migrate