Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to run a TypeScript migration #4

Open
chriscarrillo opened this issue Jan 8, 2020 · 5 comments
Open

Unable to run a TypeScript migration #4

chriscarrillo opened this issue Jan 8, 2020 · 5 comments
Labels
documentation Improvements or additions to documentation

Comments

@chriscarrillo
Copy link

Bug Description

There is a way to create both JavaScript and TypeScript migrations but I can only run JavaScript migrations. When I try to run my new TypeScript migration, it says Couldn't import the migration script from C:\CFAS\KenticoKontentCli\Migrations\test.ts.js due to an error: "Cannot find module C:\CFAS\KenticoKontentCli\Migrations\test.ts.js".

It looks like it is looking for a JavaScript file by default. It assumes the migration is JavaScript.

Repro Steps

  1. Run kontent migration add --name test --template-type "typescript".
  2. Create your migration.
  3. Run kontent migration run --name test --environment DEV.
  4. Observe error.

Expected Behavior

It should run the TypeScript migration file.

Additional Context

I attempted to run the TypeScript migration file provided by the boilerplate. I deleted the JavaScript file and left the TypeScript file alone to see what it would do. It gave me an error because it is looking for a JavaScript file.

I was looking at the code for run and I have a feeling this might have something to do with it.

Perhaps there could be a flag to specify if the migration is JavaScript or TypeScript. If not, have run determine it automatically. If it cannot find the .js file, then look for a .ts file.

Screenshots

image

Please let me know if I can provide any further details. Thank you! :)

@jupl
Copy link

jupl commented Jan 8, 2020

I think the real issue is that the .js extension is hardcoded. I tried to run the lib/index.js command with ts-node and node -r ts-node/register so TypeScript files can be imported, but the hardcoding is messing things up.

@michalpaukert
Copy link

michalpaukert commented Jan 9, 2020

Hello @chriscarrillo this scenario is probably poorly documented but it should work like this:

  1. create typescript migration
  2. run transpilation
  3. run migration

As you can see in the boilerplate there is tsc command before running migration.

This behavior is there so you can write the migrations in any language (for example coffescript).

Let me know if you have more questions about running typescript migrations.

@michalpaukert michalpaukert added the documentation Improvements or additions to documentation label Jan 9, 2020
@chriscarrillo
Copy link
Author

Ah that makes sense. Thank you!

@michalpaukert
Copy link

We have to update documentation for kontent-cli that will explain how this tool works, at least typescript/javascript usage.

@mahpour
Copy link

mahpour commented Jan 27, 2020

It would be preferred as an option to use a json schema to drive the migrations where no deep processing is needed. For simple migrations we shouldn't need to deal with any programming language as a dependency to do the job. just a suggestion...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

4 participants