Skip to content

Commit a24c21b

Browse files
committed
Use knexfile as js file and run knex cli commands as with ts-node
1 parent 1d437e4 commit a24c21b

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

knexfile.ts renamed to knexfile.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as dotenv from 'dotenv';
2-
dotenv.config();
1+
require('dotenv').config();
32

43
/**
54
* This is the database configuration for the migrations and

package.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "A delightful way to building a RESTful API with NodeJs & TypeScript",
55
"main": "src/app.ts",
66
"scripts": {
7-
"banner": "./node_modules/.bin/ts-node --fast ./src/console/lib/banner.ts",
7+
"banner": "npm run ts-node:fast -- ./src/console/lib/banner.ts",
88
"pretest": "./node_modules/.bin/tslint -c ./tslint.json -t stylish './test/unit/**/*.ts'",
99
"test:pretty": "npm run test -- --verbose",
1010
"test:coverage": "npm run test -- --coverage",
@@ -17,18 +17,20 @@
1717
"copy:assets": "npm run copy:swagger && npm run copy:public",
1818
"copy:swagger": "./node_modules/.bin/copyup ./src/api/swagger.json ./dist",
1919
"copy:public": "./node_modules/.bin/copyup ./src/public/* ./dist",
20-
"db:migrate": "npm run banner migrate && ./node_modules/.bin/knex migrate:latest",
21-
"db:migrate:rollback": "npm run banner rollback && ./node_modules/.bin/knex migrate:rollback",
22-
"db:seed": "npm run banner seed && ./node_modules/.bin/knex seed:run",
20+
"db:migrate": "npm run banner migrate && npm run ts-node:fast -- ./node_modules/.bin/knex migrate:latest",
21+
"db:migrate:rollback": "npm run banner rollback && npm run ts-node:fast -- ./node_modules/.bin/knex migrate:rollback",
22+
"db:seed": "npm run banner seed && npm run ts-node:fast -- ./node_modules/.bin/knex seed:run",
2323
"db:reset": "npm run console db:reset",
24-
"console": "./node_modules/.bin/ts-node --fast ./src/console/commander.ts",
25-
"console:dev": "./node_modules/.bin/ts-node ./src/console/commander.ts",
26-
"console:help": "./node_modules/.bin/ts-node --fast ./src/console/commander.ts --help",
24+
"console": "npm run ts-node:fast -- ./src/console/commander.ts",
25+
"console:dev": "npm run ts-node -- ./src/console/commander.ts",
26+
"console:help": "npm run ts-node:fast -- ./src/console/commander.ts --help",
2727
"setup": "yarn install && npm run db:migrate && npm run db:seed",
2828
"serve": "npm run banner serve && ./node_modules/.bin/nodemon --watch 'src/**/*.ts' --watch 'src/**/*.json' --watch '.env'",
2929
"test": "npm run banner test && NODE_ENV=test ./node_modules/.bin/jest ./test/unit",
3030
"build": "npm run banner build && npm run lint && npm run clean:dist && npm run transpile && npm run copy:assets",
31-
"start": "node dist/app.js"
31+
"start": "node dist/app.js",
32+
"ts-node": "./node_modules/.bin/ts-node",
33+
"ts-node:fast": "./node_modules/.bin/ts-node -F"
3234
},
3335
"repository": "git+ssh://git@github.com/w3tec/express-typescript-boilerplate.git",
3436
"engines": {

src/types/knexfile.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module '*knexfile' {
2+
let knexfile: any;
3+
export default knexfile;
4+
}

0 commit comments

Comments
 (0)