feat: configuration for seamless cli use in a typescript project#1439
feat: configuration for seamless cli use in a typescript project#1439malik-samad wants to merge 2 commits intosequelize:mainfrom
Conversation
- In this commit, i have modified the templates and did other related changes to add support for typescript projects. - The new changes I made, will automatically detect if the project that uses sequelize-cli is on typescirpt or not and will switch logic based on it.
| } else if (split.length === 3) { | ||
| const validValues = /^\{(,? ?[A-z0-9 ]+)+\}$/; | ||
| const validValues = | ||
| /^\{((('[A-z0-9 ]+')|("[A-z0-9 ]+")|([A-z0-9 ]+)))(, ?(('[A-z0-9 ]+')|("[A-z0-9 ]+")|([A-z0-9 ]+)))*\}$/; |
Check failure
Code scanning / CodeQL
Inefficient regular expression
There was a problem hiding this comment.
it's a false positive, @WikiRik can you please dismiss this alert?
| } else if (split.length === 3) { | ||
| const validValues = /^\{(,? ?[A-z0-9 ]+)+\}$/; | ||
| const validValues = | ||
| /^\{((('[A-z0-9 ]+')|("[A-z0-9 ]+")|([A-z0-9 ]+)))(, ?(('[A-z0-9 ]+')|("[A-z0-9 ]+")|([A-z0-9 ]+)))*\}$/; |
Check warning
Code scanning / CodeQL
Overly permissive regular expression range
| } else if (split.length === 3) { | ||
| const validValues = /^\{(,? ?[A-z0-9 ]+)+\}$/; | ||
| const validValues = | ||
| /^\{((('[A-z0-9 ]+')|("[A-z0-9 ]+")|([A-z0-9 ]+)))(, ?(('[A-z0-9 ]+')|("[A-z0-9 ]+")|([A-z0-9 ]+)))*\}$/; |
Check warning
Code scanning / CodeQL
Overly permissive regular expression range
| } else if (split.length === 3) { | ||
| const validValues = /^\{(,? ?[A-z0-9 ]+)+\}$/; | ||
| const validValues = | ||
| /^\{((('[A-z0-9 ]+')|("[A-z0-9 ]+")|([A-z0-9 ]+)))(, ?(('[A-z0-9 ]+')|("[A-z0-9 ]+")|([A-z0-9 ]+)))*\}$/; |
Check warning
Code scanning / CodeQL
Overly permissive regular expression range
| } else if (split.length === 3) { | ||
| const validValues = /^\{(,? ?[A-z0-9 ]+)+\}$/; | ||
| const validValues = | ||
| /^\{((('[A-z0-9 ]+')|("[A-z0-9 ]+")|([A-z0-9 ]+)))(, ?(('[A-z0-9 ]+')|("[A-z0-9 ]+")|([A-z0-9 ]+)))*\}$/; |
Check warning
Code scanning / CodeQL
Overly permissive regular expression range
| } else if (split.length === 3) { | ||
| const validValues = /^\{(,? ?[A-z0-9 ]+)+\}$/; | ||
| const validValues = | ||
| /^\{((('[A-z0-9 ]+')|("[A-z0-9 ]+")|([A-z0-9 ]+)))(, ?(('[A-z0-9 ]+')|("[A-z0-9 ]+")|([A-z0-9 ]+)))*\}$/; |
Check warning
Code scanning / CodeQL
Overly permissive regular expression range
| } else if (split.length === 3) { | ||
| const validValues = /^\{(,? ?[A-z0-9 ]+)+\}$/; | ||
| const validValues = | ||
| /^\{((('[A-z0-9 ]+')|("[A-z0-9 ]+")|([A-z0-9 ]+)))(, ?(('[A-z0-9 ]+')|("[A-z0-9 ]+")|([A-z0-9 ]+)))*\}$/; |
Check warning
Code scanning / CodeQL
Overly permissive regular expression range
| <%= isTypescriptProject ? `import { QueryInterface, DataTypes } from 'sequelize';` : '' %> | ||
|
|
||
| /** @type {import('sequelize-cli').Migration} */ | ||
| module.exports = { |
There was a problem hiding this comment.
i think also worth export default no?
| } | ||
| } | ||
|
|
||
| const isTypescriptProject = isPackageInstalled('typescript'); |
There was a problem hiding this comment.
what about having a way to decide it from the CLI? e.g. npx sequelize-cli migration:generate --name XXX --typescript and then inside each *_generate.js provide the isTypescript to the render function?
There was a problem hiding this comment.
This is also how we are going to do it in the new CLI; https://github.com/sequelize/sequelize/blob/main/packages/cli/src/commands/migration/generate.ts
In this commit, I have modified the templates and made other related changes to add support for typescript projects.
The new changes I made, will automatically detect if the project that uses sequelize-cli is on typescript or not and will switch logic based on it.
Pull Request check-list
Please make sure to review and check all of these items:
npm run testpass with this change (including linting)?Description of change
Link to the issue: #1436
The sequelize-cli didn't have the support for typescript projects and in this PR I implemented certain changes that will make it capable of handling the CLI for both typescript and javascript files, additionally, I have improved the templates to be able to generate both
.tsand.jsfiles for migrations, models, and seeds.