Skip to content

Commit 35fe95d

Browse files
author
hirsch88
committed
Fix console commands with knex
1 parent d3d90ac commit 35fe95d

File tree

7 files changed

+26
-22
lines changed

7 files changed

+26
-22
lines changed

knexfile.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,4 @@ require('dotenv').config();
44
* This is the database configuration for the migrations and
55
* the seeders.
66
*/
7-
module.exports = {
8-
client: process.env.DB_CLIENT,
9-
connection: process.env.DB_CONNECTION,
10-
migrations: {
11-
directory: process.env.DB_MIGRATION_DIR,
12-
tableName: process.env.DB_MIGRATION_TABLE
13-
},
14-
seeds: {
15-
directory: process.env.DB_SEEDS_DIR
16-
}
17-
};
7+
module.exports = require('./src/config/Database').DatabaseConfig;

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
"db:migrate:rollback": "npm run banner rollback && \"./node_modules/.bin/knex\" migrate:rollback",
2020
"db:seed": "npm run banner seed && \"./node_modules/.bin/knex\" seed:run",
2121
"db:reset": "npm run console db:reset",
22-
"console": "npm run ts-node:fast -- ./src/console/lib/commander.ts",
23-
"console:dev": "npm run ts-node -- ./src/console/lib/commander.ts",
24-
"console:help": "npm run ts-node:fast -- ./src/console/lib/commander.ts --help",
22+
"console": "npm run ts-node:fast -- ./src/console/lib/console.ts",
23+
"console:dev": "npm run ts-node -- ./src/console/lib/console.ts",
24+
"console:help": "npm run ts-node:fast -- ./src/console/lib/console.ts --help",
2525
"lint": "./node_modules/.bin/tslint -c ./tslint.json -p tsconfig.json 'src/**/*.ts' --format stylish",
2626
"transpile": "./node_modules/.bin/tsc",
2727
"clean": "npm run banner clean && npm run clean:dist",

src/config/Database.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,23 @@ import * as knex from 'knex';
1212
import * as bookshelf from 'bookshelf';
1313

1414

15-
export const Knex = (): knex => knex({
15+
export const DatabaseConfig = {
1616
client: process.env.DB_CLIENT,
1717
connection: process.env.DB_CONNECTION,
1818
pool: {
1919
min: parseInt(process.env.DB_POOL_MIN, 10),
2020
max: parseInt(process.env.DB_POOL_MAX, 10)
21+
},
22+
migrations: {
23+
directory: process.env.DB_MIGRATION_DIR,
24+
tableName: process.env.DB_MIGRATION_TABLE
25+
},
26+
seeds: {
27+
directory: process.env.DB_SEEDS_DIR
2128
}
22-
});
29+
};
30+
31+
export const Knex = (): knex => knex(DatabaseConfig);
2332

2433
export const Bookshelf: bookshelf = bookshelf(Knex() as any);
2534
Bookshelf.plugin(['bookshelf-camelcase']);

src/console/DatabaseResetCommand.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Logger } from '../core/Logger';
22

33
import * as Knex from 'knex';
44
import { AbstractCommand } from './lib/AbstractCommand';
5-
import * as options from './../../knexfile';
5+
import { DatabaseConfig } from '../config/Database';
66

77
const log = new Logger(__filename);
88

@@ -20,7 +20,7 @@ export class DatabaseResetCommand extends AbstractCommand {
2020
public static description = 'Reverse all current migrations and migrate to latest.';
2121

2222
public async run(): Promise<void> {
23-
const knex = Knex(options as Knex.Config);
23+
const knex = Knex(DatabaseConfig as Knex.Config);
2424

2525
const migrate: any = knex.migrate;
2626

src/console/MakeResourceCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* -------------------------------------
44
*
55
*/
6-
import { askFileName, askProperties } from './lib/utils';
6+
import { askProperties } from './lib/utils';
77
import { AbstractMakeCommand } from './lib/AbstractMakeCommand';
88
import { MakeModelCommand } from './MakeModelCommand';
99
import { MakeRepoCommand } from './MakeRepoCommand';
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,16 @@ figlet('console', (error: any, data: any) => {
4646
const keys = commands.map(c => c.command);
4747
const key = process.argv[2];
4848

49-
if (keys.indexOf(key) < 0) {
49+
if (keys.indexOf(key) < 0 && key !== '--help') {
5050
console.log(chalk.red('➜ ') + chalk.bold(`Command ${key} was not found!`));
5151
console.log();
5252
return;
5353
}
5454

55-
console.log(chalk.green('➜ ') + chalk.bold(key));
56-
console.log();
55+
if (key !== '--help') {
56+
console.log(chalk.green('➜ ') + chalk.bold(key));
57+
console.log();
58+
}
5759

5860
commands.forEach((c) => {
5961
commander

tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,8 @@
3434
},
3535
"include": [
3636
"src/**/*"
37+
],
38+
"exclude": [
39+
"knexfile.ts"
3740
]
3841
}

0 commit comments

Comments
 (0)