Skip to content

Commit

Permalink
feat: add typeorm CLI variations that include ts-node (#8776)
Browse files Browse the repository at this point in the history
* feat: add typeorm CLI variations that include `ts-node`

Add `typeorm-ts-node-commonjs` and `typeorm-ts-node-esm` CLI commands.
This removes the need to manually write `node --require ts-node/register ./node_modules/typeorm/cli.js` or `node --loader ts-node/esm ./node_modules/typeorm/cli.js` in order to use TypeORM CLI without transpiling the code in advance.

* style: formatting
  • Loading branch information
giladgd committed Mar 22, 2022
1 parent 97699e8 commit 05fc744
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 40 deletions.
4 changes: 2 additions & 2 deletions docs/faq.md
Expand Up @@ -160,13 +160,13 @@ make sure to use the `outDir` compiler option to prevent
Also, if you want to use the ts-node CLI, you can execute TypeORM the following way:

```
ts-node ./node_modules/.bin/typeorm schema:sync
npx typeorm-ts-node-commonjs schema:sync
```

For ESM projects use this instead:

```
node --loader ts-node/esm ./node_modules/.bin/typeorm schema:sync
npx typeorm-ts-node-esm schema:sync
```

## How to use Webpack for the backend?
Expand Down
10 changes: 2 additions & 8 deletions docs/migrations.md
Expand Up @@ -140,19 +140,13 @@ typeorm migration:run
Example with `ts-node`:

```
ts-node --transpile-only ./node_modules/typeorm/cli.js migration:run
npx typeorm-ts-node-commonjs migration:run
```

Example with `ts-node` in ESM projects:

```
node --loader ts-node/esm ./node_modules/typeorm/cli.js migration:run
```

Example `ts-node` not using `node_modules` directly:

```
ts-node $(yarn bin typeorm) migration:run
npx typeorm-ts-node-esm migration:run
```

This command will execute all pending migrations and run them in a sequence ordered by their timestamps.
Expand Down
4 changes: 2 additions & 2 deletions docs/using-cli.md
Expand Up @@ -42,7 +42,7 @@ Add typeorm command under scripts section in package.json
```
"scripts": {
...
"typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js"
"typeorm": "typeorm-ts-node-commonjs"
}
```

Expand All @@ -51,7 +51,7 @@ For ESM projects add this instead:
```
"scripts": {
...
"typeorm": "node --loader ts-node/esm ./node_modules/typeorm/cli.js"
"typeorm": "typeorm-ts-node-esm"
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/zh_CN/faq.md
Expand Up @@ -168,7 +168,7 @@ createConnection({
此外,如果要使用 ts-node CLI,可以通过以下方式执行 TypeORM:

```
ts-node ./node_modules/bin/typeorm schema:sync
npx typeorm-ts-node-commonjs schema:sync
```

## 后端如何使用Webpack?
Expand Down
2 changes: 1 addition & 1 deletion docs/zh_CN/migrations.md
Expand Up @@ -138,7 +138,7 @@ typeorm migration:run
`ts-node`的示例:

```
ts-node ./node_modules/typeorm/cli.js migration:run
npx typeorm-ts-node-commonjs migration:run
```

此命令将执行所有挂起的迁移,并按其时间戳排序的顺序运行它们。
Expand Down
4 changes: 2 additions & 2 deletions docs/zh_CN/using-cli.md
Expand Up @@ -24,15 +24,15 @@
你可以在项目中设置 ts-node 以简化操作,如下所示:

```
npm install -g ts-node
npm install ts-node --save-dev
```

在 package.json 中的 scripts 下添加 typeorm 命令

```
"script" {
...
"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js"
"typeorm": "typeorm-ts-node-commonjs"
}
```

Expand Down

0 comments on commit 05fc744

Please sign in to comment.