Skip to content

Commit 78bbce0

Browse files
authored
ADD dev and build commands (#22)
* ADD dev and build commands * refactor commands and add descriptions
1 parent 51a6d6a commit 78bbce0

File tree

12 files changed

+143
-48
lines changed

12 files changed

+143
-48
lines changed

lib/codegen/command.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ export class CodegenCommand {
2828
_cli.success(`Successfully created ${filePath}`);
2929
} catch (e) {
3030
_cli.error(e['message']);
31-
return;
3231
}
32+
33+
process.exit();
3334
}
3435

3536
@Command('make:controller {name}', { desc: 'Command to create a controller' })
@@ -50,8 +51,9 @@ export class CodegenCommand {
5051
_cli.success(`Successfully created ${filePath}`);
5152
} catch (e) {
5253
_cli.error(e['message']);
53-
return;
5454
}
55+
56+
process.exit();
5557
}
5658

5759
@Command('make:service {name}', { desc: 'Command to create a service' })
@@ -67,8 +69,9 @@ export class CodegenCommand {
6769
_cli.success(`Successfully created ${filePath}`);
6870
} catch (e) {
6971
_cli.error(e['message']);
70-
return;
7172
}
73+
74+
process.exit();
7275
}
7376

7477
@Command('make:job {name}', { desc: 'Command to create a job' })
@@ -90,8 +93,8 @@ export class CodegenCommand {
9093
} catch (e) {
9194
console.log(e);
9295
_cli.error(e['message']);
93-
return;
9496
}
97+
process.exit();
9598
}
9699

97100
@Command('make:model {name}', { desc: 'Command to create a model' })
@@ -111,8 +114,8 @@ export class CodegenCommand {
111114
_cli.success(`Successfully created ${filePath}`);
112115
} catch (e) {
113116
_cli.error(e['message']);
114-
return;
115117
}
118+
process.exit();
116119
}
117120

118121
@Command('make:repo {repoName} {modelFileName} {--without-interface}', {
@@ -147,8 +150,9 @@ export class CodegenCommand {
147150
_cli.success(`Successfully created ${filePath}`);
148151
} catch (e) {
149152
_cli.error(e['message']);
150-
return;
151153
}
154+
155+
process.exit();
152156
}
153157

154158
@Command('make:exception {name}', {
@@ -166,8 +170,9 @@ export class CodegenCommand {
166170
_cli.success(`Successfully created ${filePath}`);
167171
} catch (e) {
168172
_cli.error(e['message']);
169-
return;
170173
}
174+
175+
process.exit();
171176
}
172177

173178
@Command('make:resource {name}', { desc: 'Command to create a service' })
@@ -183,8 +188,9 @@ export class CodegenCommand {
183188
await CommandRunner.run(`make:service ${name}`, { silent: true });
184189
} catch (e) {
185190
_cli.error(e['message']);
186-
return;
187191
}
192+
193+
process.exit();
188194
}
189195

190196
@Command('make:event {name}', {
@@ -206,8 +212,9 @@ export class CodegenCommand {
206212
_cli.success(`Successfully created ${filePath}`);
207213
} catch (e) {
208214
_cli.error(e['message']);
209-
return;
210215
}
216+
217+
process.exit();
211218
}
212219

213220
@Command(
@@ -232,8 +239,9 @@ export class CodegenCommand {
232239
_cli.success(`Successfully created ${filePath}`);
233240
} catch (e) {
234241
_cli.error(e['message']);
235-
return;
236242
}
243+
244+
process.exit();
237245
}
238246

239247
@Command(
@@ -256,8 +264,9 @@ export class CodegenCommand {
256264
_cli.success(`Successfully created ${filePath}`);
257265
} catch (e) {
258266
_cli.error(e['message']);
259-
return;
260267
}
268+
269+
process.exit();
261270
}
262271

263272
@Command('make:mail {name}', {
@@ -278,7 +287,8 @@ export class CodegenCommand {
278287
_cli.success(`Successfully created ${filePath}`);
279288
} catch (e) {
280289
_cli.error(e['message']);
281-
return;
282290
}
291+
292+
process.exit();
283293
}
284294
}

lib/config/command.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@ export class ViewConfigCommand {
3030

3131
// eslint-disable-next-line no-console
3232
console.log(printRows.join('\n'));
33+
34+
process.exit();
3335
}
3436
}

lib/console/commands/listCommands.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export class ListCommands {
6161
console.log();
6262
console.log(printRows.join('\n'));
6363
console.log();
64-
return;
64+
65+
process.exit();
6566
}
6667
}

lib/database/commands/migrations.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class DbOperationsCommand {
3131
}
3232

3333
_cli.table(['Migration', 'Status'], statusList);
34+
process.exit();
3435
}
3536

3637
@Command('migrate {--connection==}', {
@@ -48,13 +49,15 @@ export class DbOperationsCommand {
4849

4950
if (migrations.length === 0) {
5051
_cli.info('No migrations to run');
51-
return;
52+
process.exit();
5253
}
5354

5455
_cli.info(`Batch Number: ${batch}`);
5556
for (const migration of migrations) {
5657
_cli.success(migration);
5758
}
59+
60+
process.exit();
5861
}
5962

6063
@Command('migrate:rollback {--connection==}', {
@@ -72,13 +75,15 @@ export class DbOperationsCommand {
7275

7376
if (migrations.length === 0) {
7477
_cli.info('No migrations to rollback. Already at the base migration');
75-
return;
78+
process.exit();
7679
}
7780

7881
_cli.info(`Reverted Batch: ${batch}`);
7982
for (const migration of migrations) {
8083
_cli.success(migration);
8184
}
85+
86+
process.exit();
8287
}
8388

8489
@Command('migrate:reset {--connection==}', {
@@ -96,7 +101,7 @@ export class DbOperationsCommand {
96101

97102
if (!confirm) {
98103
_cli.info('Thank you! Exiting...');
99-
return;
104+
process.exit();
100105
}
101106

102107
const password = await _cli.password(
@@ -107,7 +112,7 @@ export class DbOperationsCommand {
107112
const conPassword = connConfig.connection?.['password'];
108113
if (conPassword && password !== conPassword) {
109114
_cli.error(' Wrong Password. Exiting... ');
110-
return;
115+
process.exit();
111116
}
112117
}
113118

@@ -117,13 +122,15 @@ export class DbOperationsCommand {
117122

118123
if (migrations.length === 0) {
119124
_cli.info('No migrations to rollback. Already at the base migration');
120-
return;
125+
process.exit();
121126
}
122127

123128
_cli.info('Rollback of following migrations are done:');
124129
for (const migration of migrations) {
125130
_cli.success(migration);
126131
}
132+
133+
process.exit();
127134
}
128135

129136
@Command('make:migration {name} {--connection=}', {
@@ -143,5 +150,6 @@ export class DbOperationsCommand {
143150

144151
const paths = res.split('/');
145152
_cli.success(paths[paths.length - 1]);
153+
process.exit();
146154
}
147155
}

lib/database/commands/utils.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

lib/dev-server/build.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Command, ConsoleIO } from '../console';
2+
import { getTime, Package } from '../utils';
3+
import pc from 'picocolors';
4+
5+
@Command(
6+
`server:build
7+
{--c|config : Path to the .intentrc file.}
8+
{--t|tsconfig : Path to tsconfig file.}
9+
{--d|debug : Run in debug mode (with --inspect flag).}
10+
{--dtc|disable-type-check : Disable type checking. Enabled by default.}`,
11+
{ desc: 'Command to build the application' },
12+
)
13+
export class BuildProjectCommand {
14+
async handle(_cli: ConsoleIO): Promise<void> {
15+
const debug = _cli.option('debug');
16+
const disableTypeCheck = _cli.option('disable-type-check');
17+
const tsConfig = _cli.option('tsconfig');
18+
const config = _cli.option('config');
19+
20+
const now = Date.now();
21+
const { BuildCommand } = Package.load('@intentjs/cli');
22+
const command = new BuildCommand();
23+
await command.handle({
24+
debug,
25+
disableTypeCheck,
26+
tsConfig,
27+
config,
28+
});
29+
30+
console.log(
31+
pc.gray(`[${getTime()}]`),
32+
pc.bgWhite(pc.black(` INTENT `)),
33+
`Build process completed in ${Date.now() - now}ms`,
34+
);
35+
36+
process.exit();
37+
}
38+
}

lib/dev-server/serve.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Command, ConsoleIO } from '../console';
2+
import { Package } from '../utils';
3+
4+
@Command(
5+
`server:dev
6+
{--config : Path to intent.config.json file}
7+
{--debug : Start debug mode in the server}
8+
`,
9+
{ desc: 'Command to start a server in watch (live-reload) mode.' },
10+
)
11+
export class DevServerCommand {
12+
async handle(_cli: ConsoleIO): Promise<void> {
13+
const debug = _cli.option('debug');
14+
const disableTypeCheck = _cli.option('debug');
15+
const tsConfig = _cli.option('tsConfig');
16+
const config = _cli.option('config');
17+
const port = +_cli.option('port');
18+
19+
const { StartServerCommand } = Package.load('@intentjs/cli');
20+
const command = new StartServerCommand();
21+
await command.handle({
22+
watch: true,
23+
debug,
24+
disableTypeCheck,
25+
tsConfig,
26+
config,
27+
port,
28+
});
29+
}
30+
}

lib/foundation/container-factory.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,24 @@ export class ContainerFactory {
88
containerCls: Type<IntentAppContainer>,
99
): Promise<IntentApplicationContext> {
1010
const container = new containerCls();
11+
1112
container.build();
13+
14+
/**
15+
* Build a module for NestJS DI Container
16+
*/
1217
const module = ModuleBuilder.build(container);
18+
19+
/**
20+
* Build NestJS DI Container
21+
*/
1322
const app = await NestFactory.createApplicationContext(module);
23+
24+
/**
25+
* Run the `boot` method of the main application container
26+
*/
1427
container.boot(app);
28+
1529
return app;
1630
}
1731
}

lib/serviceProvider.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import { QueueService } from './queue';
1919
import { QueueConsoleCommands } from './queue/console';
2020
import { QueueMetadata } from './queue/metadata';
2121
import { StorageService } from './storage/service';
22+
import { BuildProjectCommand } from './dev-server/build';
23+
import { DevServerCommand } from './dev-server/serve';
2224

2325
export const IntentProvidersFactory = (
2426
config: any[],
@@ -51,6 +53,8 @@ export const IntentProvidersFactory = (
5153
LocalizationService,
5254
EventQueueWorker,
5355
LoggerService,
56+
BuildProjectCommand,
57+
DevServerCommand,
5458
);
5559
}
5660

lib/utils/helpers.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,17 @@ const parseError = (error: ValidationError) => {
121121

122122
return errors;
123123
};
124+
125+
export const getTime = () => {
126+
const date = new Date();
127+
const hours = date.getHours();
128+
const minutes = date.getMinutes();
129+
const seconds = date.getSeconds();
130+
const ampm = hours >= 12 ? 'PM' : 'AM';
131+
132+
const formattedHours = hours % 12 || 12;
133+
const formattedMinutes = minutes.toString().padStart(2, '0');
134+
const formattedSeconds = seconds.toString().padStart(2, '0');
135+
136+
return `${formattedHours}:${formattedMinutes}:${formattedSeconds} ${ampm}`;
137+
};

0 commit comments

Comments
 (0)