Skip to content

Commit 716aeca

Browse files
authored
Urgent fixes (#25)
* changed the default grouping logic for command listing * change dev-server commands to build and dev * now a command can wait if it doesnt accept true as the return value.
1 parent 1fee1a6 commit 716aeca

9 files changed

Lines changed: 31 additions & 508 deletions

File tree

lib/config/command.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class ViewConfigCommand {
1313
@Command('config:view {namespace}', {
1414
desc: 'Command to view config for a given namespace',
1515
})
16-
async handle(_cli: ConsoleIO): Promise<void> {
16+
async handle(_cli: ConsoleIO): Promise<boolean> {
1717
const namespace = _cli.argument<string>('namespace');
1818
const config = this.config.get(namespace);
1919
if (!config) {
@@ -31,6 +31,6 @@ export class ViewConfigCommand {
3131
// eslint-disable-next-line no-console
3232
console.log(printRows.join('\n'));
3333

34-
process.exit();
34+
return true;
3535
}
3636
}

lib/console/commands/listCommands.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { CommandMeta } from '../metadata';
1111
@Injectable()
1212
@Command('list', { desc: 'Command to list all the commands' })
1313
export class ListCommands {
14-
public async handle(): Promise<void> {
14+
public async handle(): Promise<boolean> {
1515
const commands = CommandMeta.getAllCommands();
1616

1717
const list = [];
@@ -29,7 +29,9 @@ export class ListCommands {
2929
const formattedRows = columnify(list, { padStart: 2 });
3030
const groups = {};
3131
for (const row of formattedRows) {
32-
const group = Str.before(row[0], ':').trim();
32+
const group = Str.contains(row[0], ':')
33+
? Str.before(row[0], ':').trim()
34+
: '#';
3335
if (groups[group]) {
3436
groups[group].push(row);
3537
} else {
@@ -60,8 +62,7 @@ export class ListCommands {
6062
);
6163
console.log();
6264
console.log(printRows.join('\n'));
63-
console.log();
6465

65-
process.exit();
66+
return true;
6667
}
6768
}

lib/console/interfaces/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface CommandMetaOptions {
66
}
77

88
export interface CommandObject extends ArgumentParserOutput {
9-
target: (cli: ConsoleIO) => Promise<void>;
9+
target: (cli: ConsoleIO) => Promise<void | boolean>;
1010
expression: string;
1111
meta: CommandMetaOptions;
1212
}

lib/console/runner.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ export class CommandRunner {
4242
console.log(_cli);
4343
}
4444

45-
await command.target(_cli);
45+
const returnFromCommand = await command.target(_cli);
46+
returnFromCommand && process.exit(1);
47+
4648
return;
4749
}
4850

lib/database/commands/migrations.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class DbOperationsCommand {
1111
@Command('migrate:status {--connection==}', {
1212
desc: 'Command to show the status of all migrations',
1313
})
14-
async migrateStatus(_cli: ConsoleIO): Promise<void> {
14+
async migrateStatus(_cli: ConsoleIO): Promise<void | boolean> {
1515
const options = ObjectionService.config;
1616

1717
const conn = _cli.option<string>('connection') || options.default;
@@ -31,13 +31,13 @@ export class DbOperationsCommand {
3131
}
3232

3333
_cli.table(['Migration', 'Status'], statusList);
34-
process.exit();
34+
return true;
3535
}
3636

3737
@Command('migrate {--connection==}', {
3838
desc: 'Command to run the pending migrations',
3939
})
40-
async migrationUp(_cli: ConsoleIO): Promise<void> {
40+
async migrationUp(_cli: ConsoleIO): Promise<void | boolean> {
4141
const options = ObjectionService.config;
4242
const conn = _cli.option<string>('connection') || options.default;
4343
const knex = ObjectionService.connection(conn);
@@ -49,21 +49,21 @@ export class DbOperationsCommand {
4949

5050
if (migrations.length === 0) {
5151
_cli.info('No migrations to run');
52-
process.exit();
52+
return true;
5353
}
5454

5555
_cli.info(`Batch Number: ${batch}`);
5656
for (const migration of migrations) {
5757
_cli.success(migration);
5858
}
5959

60-
process.exit();
60+
return true;
6161
}
6262

6363
@Command('migrate:rollback {--connection==}', {
6464
desc: 'Command to rollback the previous batch of migrations',
6565
})
66-
async migrateRollback(_cli: ConsoleIO) {
66+
async migrateRollback(_cli: ConsoleIO): Promise<void | boolean> {
6767
const options = ObjectionService.config;
6868
const conn = _cli.option<string>('connection') || options.default;
6969
const knex = ObjectionService.connection(conn);
@@ -75,21 +75,21 @@ export class DbOperationsCommand {
7575

7676
if (migrations.length === 0) {
7777
_cli.info('No migrations to rollback. Already at the base migration');
78-
process.exit();
78+
return true;
7979
}
8080

8181
_cli.info(`Reverted Batch: ${batch}`);
8282
for (const migration of migrations) {
8383
_cli.success(migration);
8484
}
8585

86-
process.exit();
86+
return true;
8787
}
8888

8989
@Command('migrate:reset {--connection==}', {
9090
desc: 'Command to reset the migration',
9191
})
92-
async migrateReset(_cli: ConsoleIO) {
92+
async migrateReset(_cli: ConsoleIO): Promise<boolean> {
9393
const options = ObjectionService.config;
9494
const conn = _cli.option<string>('connection') || options.default;
9595
const knex = ObjectionService.connection(conn);
@@ -101,7 +101,7 @@ export class DbOperationsCommand {
101101

102102
if (!confirm) {
103103
_cli.info('Thank you! Exiting...');
104-
process.exit();
104+
return true;
105105
}
106106

107107
const password = await _cli.password(
@@ -112,7 +112,7 @@ export class DbOperationsCommand {
112112
const conPassword = connConfig.connection?.['password'];
113113
if (conPassword && password !== conPassword) {
114114
_cli.error(' Wrong Password. Exiting... ');
115-
process.exit();
115+
return true;
116116
}
117117
}
118118

@@ -122,21 +122,21 @@ export class DbOperationsCommand {
122122

123123
if (migrations.length === 0) {
124124
_cli.info('No migrations to rollback. Already at the base migration');
125-
process.exit();
125+
return true;
126126
}
127127

128128
_cli.info('Rollback of following migrations are done:');
129129
for (const migration of migrations) {
130130
_cli.success(migration);
131131
}
132132

133-
process.exit();
133+
return true;
134134
}
135135

136136
@Command('make:migration {name} {--connection=}', {
137137
desc: 'Command to create a new migration',
138138
})
139-
async makeMigration(_cli: ConsoleIO) {
139+
async makeMigration(_cli: ConsoleIO): Promise<boolean> {
140140
const options = ObjectionService.config;
141141
const name = _cli.argument<string>('name');
142142
const conn = _cli.option<string>('connection') || options.default;
@@ -150,6 +150,6 @@ export class DbOperationsCommand {
150150

151151
const paths = res.split('/');
152152
_cli.success(paths[paths.length - 1]);
153-
process.exit();
153+
return true;
154154
}
155155
}

lib/dev-server/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getTime, Package } from '../utils';
33
import pc from 'picocolors';
44

55
@Command(
6-
`server:build
6+
`build
77
{--c|config : Path to the .intentrc file.}
88
{--t|tsconfig : Path to tsconfig file.}
99
{--d|debug : Run in debug mode (with --inspect flag).}

lib/dev-server/serve.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Command, ConsoleIO } from '../console';
22
import { Package } from '../utils';
33

44
@Command(
5-
`server:dev
5+
`dev
66
{--config : Path to intent.config.json file}
77
{--debug : Start debug mode in the server}
88
`,

0 commit comments

Comments
 (0)