Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions lib/codegen/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ export class CodegenCommand {
_cli.success(`Successfully created ${filePath}`);
} catch (e) {
_cli.error(e['message']);
return;
}

process.exit();
}

@Command('make:controller {name}', { desc: 'Command to create a controller' })
Expand All @@ -50,8 +51,9 @@ export class CodegenCommand {
_cli.success(`Successfully created ${filePath}`);
} catch (e) {
_cli.error(e['message']);
return;
}

process.exit();
}

@Command('make:service {name}', { desc: 'Command to create a service' })
Expand All @@ -67,8 +69,9 @@ export class CodegenCommand {
_cli.success(`Successfully created ${filePath}`);
} catch (e) {
_cli.error(e['message']);
return;
}

process.exit();
}

@Command('make:job {name}', { desc: 'Command to create a job' })
Expand All @@ -90,8 +93,8 @@ export class CodegenCommand {
} catch (e) {
console.log(e);
_cli.error(e['message']);
return;
}
process.exit();
}

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

@Command('make:repo {repoName} {modelFileName} {--without-interface}', {
Expand Down Expand Up @@ -147,8 +150,9 @@ export class CodegenCommand {
_cli.success(`Successfully created ${filePath}`);
} catch (e) {
_cli.error(e['message']);
return;
}

process.exit();
}

@Command('make:exception {name}', {
Expand All @@ -166,8 +170,9 @@ export class CodegenCommand {
_cli.success(`Successfully created ${filePath}`);
} catch (e) {
_cli.error(e['message']);
return;
}

process.exit();
}

@Command('make:resource {name}', { desc: 'Command to create a service' })
Expand All @@ -183,8 +188,9 @@ export class CodegenCommand {
await CommandRunner.run(`make:service ${name}`, { silent: true });
} catch (e) {
_cli.error(e['message']);
return;
}

process.exit();
}

@Command('make:event {name}', {
Expand All @@ -206,8 +212,9 @@ export class CodegenCommand {
_cli.success(`Successfully created ${filePath}`);
} catch (e) {
_cli.error(e['message']);
return;
}

process.exit();
}

@Command(
Expand All @@ -232,8 +239,9 @@ export class CodegenCommand {
_cli.success(`Successfully created ${filePath}`);
} catch (e) {
_cli.error(e['message']);
return;
}

process.exit();
}

@Command(
Expand All @@ -256,8 +264,9 @@ export class CodegenCommand {
_cli.success(`Successfully created ${filePath}`);
} catch (e) {
_cli.error(e['message']);
return;
}

process.exit();
}

@Command('make:mail {name}', {
Expand All @@ -278,7 +287,8 @@ export class CodegenCommand {
_cli.success(`Successfully created ${filePath}`);
} catch (e) {
_cli.error(e['message']);
return;
}

process.exit();
}
}
2 changes: 2 additions & 0 deletions lib/config/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ export class ViewConfigCommand {

// eslint-disable-next-line no-console
console.log(printRows.join('\n'));

process.exit();
}
}
3 changes: 2 additions & 1 deletion lib/console/commands/listCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class ListCommands {
console.log();
console.log(printRows.join('\n'));
console.log();
return;

process.exit();
}
}
18 changes: 13 additions & 5 deletions lib/database/commands/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class DbOperationsCommand {
}

_cli.table(['Migration', 'Status'], statusList);
process.exit();
}

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

if (migrations.length === 0) {
_cli.info('No migrations to run');
return;
process.exit();
}

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

process.exit();
}

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

if (migrations.length === 0) {
_cli.info('No migrations to rollback. Already at the base migration');
return;
process.exit();
}

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

process.exit();
}

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

if (!confirm) {
_cli.info('Thank you! Exiting...');
return;
process.exit();
}

const password = await _cli.password(
Expand All @@ -107,7 +112,7 @@ export class DbOperationsCommand {
const conPassword = connConfig.connection?.['password'];
if (conPassword && password !== conPassword) {
_cli.error(' Wrong Password. Exiting... ');
return;
process.exit();
}
}

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

if (migrations.length === 0) {
_cli.info('No migrations to rollback. Already at the base migration');
return;
process.exit();
}

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

process.exit();
}

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

const paths = res.split('/');
_cli.success(paths[paths.length - 1]);
process.exit();
}
}
29 changes: 0 additions & 29 deletions lib/database/commands/utils.ts

This file was deleted.

38 changes: 38 additions & 0 deletions lib/dev-server/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Command, ConsoleIO } from '../console';
import { getTime, Package } from '../utils';
import pc from 'picocolors';

@Command(
`server:build
{--c|config : Path to the .intentrc file.}
{--t|tsconfig : Path to tsconfig file.}
{--d|debug : Run in debug mode (with --inspect flag).}
{--dtc|disable-type-check : Disable type checking. Enabled by default.}`,
{ desc: 'Command to build the application' },
)
export class BuildProjectCommand {
async handle(_cli: ConsoleIO): Promise<void> {
const debug = _cli.option('debug');
const disableTypeCheck = _cli.option('disable-type-check');
const tsConfig = _cli.option('tsconfig');
const config = _cli.option('config');

const now = Date.now();
const { BuildCommand } = Package.load('@intentjs/cli');
const command = new BuildCommand();
await command.handle({
debug,
disableTypeCheck,
tsConfig,
config,
});

console.log(
pc.gray(`[${getTime()}]`),
pc.bgWhite(pc.black(` INTENT `)),
`Build process completed in ${Date.now() - now}ms`,
);

process.exit();
}
}
30 changes: 30 additions & 0 deletions lib/dev-server/serve.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Command, ConsoleIO } from '../console';
import { Package } from '../utils';

@Command(
`server:dev
{--config : Path to intent.config.json file}
{--debug : Start debug mode in the server}
`,
{ desc: 'Command to start a server in watch (live-reload) mode.' },
)
export class DevServerCommand {
async handle(_cli: ConsoleIO): Promise<void> {
const debug = _cli.option('debug');
const disableTypeCheck = _cli.option('debug');
const tsConfig = _cli.option('tsConfig');
const config = _cli.option('config');
const port = +_cli.option('port');

const { StartServerCommand } = Package.load('@intentjs/cli');
const command = new StartServerCommand();
await command.handle({
watch: true,
debug,
disableTypeCheck,
tsConfig,
config,
port,
});
}
}
14 changes: 14 additions & 0 deletions lib/foundation/container-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,24 @@ export class ContainerFactory {
containerCls: Type<IntentAppContainer>,
): Promise<IntentApplicationContext> {
const container = new containerCls();

container.build();

/**
* Build a module for NestJS DI Container
*/
const module = ModuleBuilder.build(container);

/**
* Build NestJS DI Container
*/
const app = await NestFactory.createApplicationContext(module);

/**
* Run the `boot` method of the main application container
*/
container.boot(app);

return app;
}
}
4 changes: 4 additions & 0 deletions lib/serviceProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { QueueService } from './queue';
import { QueueConsoleCommands } from './queue/console';
import { QueueMetadata } from './queue/metadata';
import { StorageService } from './storage/service';
import { BuildProjectCommand } from './dev-server/build';
import { DevServerCommand } from './dev-server/serve';

export const IntentProvidersFactory = (
config: any[],
Expand Down Expand Up @@ -51,6 +53,8 @@ export const IntentProvidersFactory = (
LocalizationService,
EventQueueWorker,
LoggerService,
BuildProjectCommand,
DevServerCommand,
);
}

Expand Down
14 changes: 14 additions & 0 deletions lib/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,17 @@ const parseError = (error: ValidationError) => {

return errors;
};

export const getTime = () => {
const date = new Date();
const hours = date.getHours();
const minutes = date.getMinutes();
const seconds = date.getSeconds();
const ampm = hours >= 12 ? 'PM' : 'AM';

const formattedHours = hours % 12 || 12;
const formattedMinutes = minutes.toString().padStart(2, '0');
const formattedSeconds = seconds.toString().padStart(2, '0');

return `${formattedHours}:${formattedMinutes}:${formattedSeconds} ${ampm}`;
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@intentjs/core",
"version": "0.1.31",
"version": "0.1.32",
"description": "Core module for Intent",
"main": "dist/lib/index.js",
"types": "dist/lib/index.d.ts",
Expand Down
Loading