小编oba*_*ram的帖子

如何配置 husky 预推钩来运行测试

我正在尝试配置 husky 预推送挂钩以在推送之前运行测试。一切看起来都很好。运行git push origin钩子被触发并且测试正在运行后。问题是,当测试完成后,即使操作成功,推送也会被冻结,并且没有其他事情发生。

包.json

  "scripts": {
    ...
    "pre-commit": "npm run lint",
    "pre-push": "npm run test"
  }
Run Code Online (Sandbox Code Playgroud)

.husky/预推

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run pre-push
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

githooks husky angular git-husky

6
推荐指数
1
解决办法
1万
查看次数

如何在 Nest.JS 中使用 .env 文件设置 Type ORM 的配置

我想使用.env文件设置 TypeORM 的配置,但是当我尝试运行迁移脚本时遇到问题。

我做了什么:

1.在package.json中添加脚本

    "migration:generate": "node_modules/.bin/typeorm migration:generate -n",
    "migration:run": "node_modules/.bin/typeorm migration:run",
    "migration:revert": "node_modules/.bin/typeorm migration:revert",
Run Code Online (Sandbox Code Playgroud)

2.在app.module*中导入TypeOrmModule

    TypeOrmModule.forRootAsync({
        imports: [ConfigModule],
        inject: [ConfigService],
        useFactory: (configService: ConfigService) => ({
          type: 'mysql',
          host: configService.get('HOST'),
          port: +configService.get<number>('PORT'),
          username: configService.get('DATABASE_USERNAME'),
          password: configService.get('DATABASE_PASSWORD'),
          database: configService.get('DATABASE'),
          entities: [__dirname + '/**/*.entity{.ts,.js}'],
          synchronize: true,
        })
      }
    )],
Run Code Online (Sandbox Code Playgroud)

3.在根文件夹中创建.env文件

    HOST=localhost
    PORT=5432
    DATABASE_USER=dbuser
    DATABASE_PASSWORD=dbpassword
    DATABASE=dbname
Run Code Online (Sandbox Code Playgroud)

现在我尝试运行这样的迁移脚本:

npm run migration:generate -n AddUserTable
Run Code Online (Sandbox Code Playgroud)

我收到这样的错误:

Error during migration generation:
Error: No connection options were found in any orm configuration files.
Run Code Online (Sandbox Code Playgroud)

根据文档,它应该是一些ormconfig.json但它也应该与.env …

javascript node.js typeorm nestjs

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

angular ×1

git-husky ×1

githooks ×1

husky ×1

javascript ×1

nestjs ×1

node.js ×1

typeorm ×1