deluan / contentful-migrate

🐎 Schema migration tooling for Contentful, with state management
https://www.contentful.com/blog/2018/09/13/content-model-changes-scale-telus-cms-as-code/
MIT License
60 stars 37 forks source link

Provide --compiler flag for `up`, `down`, `list` #82

Open trptcolin opened 4 years ago

trptcolin commented 4 years ago

This allows folks to write migrations in TypeScript, with a setup like the following:

require("ts-node/register")
module.exports = () => {}

See https://github.com/tj/node-migrate/issues/108#issuecomment-371107685 for more here.

$ ctf-migrate list --compiler "ts:./migrations/tsnode.js" \
    --space-id $CONTENTFUL_SPACE_ID \
    --environment-id $CONTENTFUL_ENVIRONMENT_ID \
    --access-token $CONTENTFUL_MANAGEMENT_ACCESS_TOKEN 
    -a

And just to reiterate some of the tradeoffs I see from the related issue (#53):

Pros

Cons

No worries if you want to go a different way - just figured showing the code might be easier than talking about it (also might save others some time).

trptcolin commented 4 years ago

One additional caveat I just ran into that I wanted to call out:

deluan commented 4 years ago

Hey, thanks very much for this, and sorry for not replying earlier.

Even though I like the simple/open approach you took, I think I'd like to have something like a flag in bootstrap (something like --language typescript), and have the up/down/list commands automatically detect the language based on the extension (.ts, .js, .coffee...). That way we could detect which language was used and use the appropriate compiler, without the need to specify an additional argument in every command.

We could have this approach and also keep the --compiler flag you proposed for open extensibility, as long as we can solve the Error: Missing migration file: 20200210202532-create-blog-post.js issue.

Thoughts?

trptcolin commented 4 years ago

@deluan Yep, absolutely, makes sense. It'll definitely be user-friendlier and seems like that approach could also allow migrations to be run in different languages (e.g. project started off in javascript but migrated to typescript a couple years later, and they don't have to rewrite old migrations to get them running).

Just to set expectations & make sure nobody's waiting on me: I'm probably not going to tackle this anytime soon, just depending on my fork for now, which is going fine for my purposes. Feel free to close or repurpose this PR!

fr0609 commented 4 years ago

Hello, will we get typescript support? for new projects that file error might not be an issue.

deluan commented 4 years ago

I'll take a stab at this, hopefully will have a new release by end of this week

deluan commented 3 years ago

Hey @fr0609 and @trptcolin, sorry for the delay. I'm not a TypeScript user myself, so testing this (setting up the dev env, etc..) is not something I've been able to do in my free time.

What do you guys think about @devlato's approach on PR https://github.com/deluan/contentful-migrate/pull/131?