Skip to content

Commit

Permalink
Nestjs 10 + commander 11 (#666)
Browse files Browse the repository at this point in the history
* remove support of Ora
* upgrade peerDependencies to nestjs 10 and commander to 11
* change test matrix
* set minimum nod engine (required by commander)
* clean helpers
* update changelog
  • Loading branch information
Rmannn authored Jul 16, 2023
1 parent 5a54860 commit c2cd90b
Show file tree
Hide file tree
Showing 8 changed files with 1,758 additions and 1,984 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v1
Expand Down
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [9.0.0] - 2023-07-15

### Changed

- Support nestjs v10
- Support commander v11
- Update dependencies
- Remove Ora from dependencies and helpers
- Revert node engine in the runtime requirements to minimum version node v16 (required by commander v11)

## [8.0.0] - 2022-07-28

### Changed
Expand Down Expand Up @@ -244,7 +254,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- Update the dependencies to support nestjs ^6.0.0

[unreleased]: https://github.com/Pop-Code/nestjs-console/compare/v8.0.0...HEAD
[unreleased]: https://github.com/Pop-Code/nestjs-console/compare/v9.0.0...HEAD
[9.0.0]: https://github.com/Pop-Code/nestjs-console/compare/v8.0.0...v9.0.0
[8.0.0]: https://github.com/Pop-Code/nestjs-console/compare/v7.0.1...v8.0.0
[7.0.1]: https://github.com/Pop-Code/nestjs-console/compare/v7.0.0...v7.0.1
[7.0.0]: https://github.com/Pop-Code/nestjs-console/compare/v6.0.0...v5.0.1
Expand Down
50 changes: 26 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nestjs-console",
"version": "8.0.0",
"version": "9.0.0",
"description": "A NestJS module that provide a cli",
"keywords": [
"nestjs",
Expand All @@ -16,36 +16,35 @@
"author": "Rmannn <[email protected]>",
"license": "MIT",
"peerDependencies": {
"@nestjs/common": "^9",
"@nestjs/core": "^9"
"@nestjs/common": "^9.0.0 || ^10.0.0",
"@nestjs/core": "^9.0.0 || ^10.0.0"
},
"dependencies": {
"ora": "5.4.1",
"commander": "^8.1.0"
"commander": "^11.0.0"
},
"devDependencies": {
"@nestjs/common": "9.0.5",
"@nestjs/core": "9.0.5",
"@nestjs/platform-express": "9.0.5",
"@nestjs/testing": "9.0.5",
"@types/jest": "27.0.3",
"@types/node": "16.11.10",
"@typescript-eslint/eslint-plugin": "5.54.1",
"@typescript-eslint/parser": "5.4.0",
"@nestjs/common": "10.0.5",
"@nestjs/core": "10.0.5",
"@nestjs/platform-express": "10.0.5",
"@nestjs/testing": "10.0.5",
"@types/jest": "29.5.3",
"@types/node": "20.4.2",
"@typescript-eslint/eslint-plugin": "6.0.0",
"@typescript-eslint/parser": "6.0.0",
"codecov": "3.8.3",
"eslint": "8.3.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-import": "2.25.3",
"eslint": "8.45.0",
"eslint-config-prettier": "8.8.0",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-prefer-arrow": "1.2.3",
"jest": "27.3.1",
"prettier": "2.4.1",
"jest": "29.6.1",
"prettier": "3.0.0",
"reflect-metadata": "0.1.13",
"rxjs": "7.4.0",
"ts-jest": "27.0.7",
"ts-node": "10.4.0",
"tsconfig-paths": "3.12.0",
"typedoc": "0.22.10",
"typescript": "4.5.2"
"rxjs": "7.8.1",
"ts-jest": "29.1.1",
"ts-node": "10.9.1",
"tsconfig-paths": "4.2.0",
"typedoc": "0.24.8",
"typescript": "5.1.6"
},
"scripts": {
"build": "rm -Rf ./dist && tsc -b tsconfig.build.json",
Expand Down Expand Up @@ -78,5 +77,8 @@
"!**/test/**"
],
"coverageDirectory": "./coverage"
},
"engines": {
"node": ">=16.0.0"
}
}
10 changes: 0 additions & 10 deletions src/helpers.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export * from './bootstrap/abstract';
export * from './bootstrap/console';
export * from './constants';
export * from './decorators';
export * from './helpers';
export * from './module';
export * from './scanner';
export * from './service';
26 changes: 23 additions & 3 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as commander from 'commander';

import { CreateCommandOptions, InjectCli } from './decorators';
import { CommandActionHandler, CommandActionWrapper, CommandResponse } from './interfaces';
import { EventEmitter } from 'stream';

@Injectable()
export class ConsoleService {
Expand All @@ -25,6 +26,8 @@ export class ConsoleService {
*/
protected cli: commander.Command;

protected responseListener: EventEmitter = new EventEmitter();;

constructor(@InjectCli() cli: commander.Command) {
this.cli = cli;
}
Expand Down Expand Up @@ -102,8 +105,16 @@ export class ConsoleService {
* Execute the cli
*/
async init(argv: string[]): Promise<CommandResponse> {
const userArgs = (this.cli as any)._prepareUserArgs(argv);
return await (this.cli as any)._parseCommand([], userArgs);
const userArgs = (this.cli as any)._prepareUserArgs(argv);
return new Promise((resolve, reject) => {
this.responseListener.once('response', (res) => {
resolve(res)
});
this.responseListener.once('error', (error) => {
reject(error);
});
(this.cli as any)._parseCommand([], userArgs);
})
}

/**
Expand Down Expand Up @@ -143,14 +154,23 @@ export class ConsoleService {
}
}
// here as any is required cause commander bad typing on action for promise
command.action(ConsoleService.createHandler(handler) as any);
command.action(async (...args) => {
try{
const res = await ConsoleService.createHandler(handler)(...args)
this.responseListener.emit('response', res);
}catch(e){
this.responseListener.emit('error', e);
}
});

// add the command to the parent
parent.addCommand(command, commanderOptions);

// add the command to cli stack
this.commands.set(this.getCommandFullName(command), command);

command.on('response', (res) => {})

return command;
}

Expand Down
8 changes: 0 additions & 8 deletions test/helpers.spec.ts

This file was deleted.

Loading

0 comments on commit c2cd90b

Please sign in to comment.