diff --git a/README.md b/README.md index eb219824..acc00a4b 100644 --- a/README.md +++ b/README.md @@ -4,19 +4,19 @@ Have you been building amazing REST and RPC applications with [NestJS](https://d ## Installation -Before you get started, you'll need to install a few packages. First and foremost, this one: `nestjs-commander` (name pending). You'll also need to install `@nestjs/common` and `@nestjs/core` as this package makes use of them under the hood, but doesn't want to tie you down to a specific version, yay peerDependencies! +Before you get started, you'll need to install a few packages. First and foremost, this one: `nest-commander` (name pending). You'll also need to install `@nestjs/common` and `@nestjs/core` as this package makes use of them under the hood, but doesn't want to tie you down to a specific version, yay peerDependencies! ```sh -npm i nestjs-commander @nestjs/common @nestjs/core +npm i nest-commander @nestjs/common @nestjs/core # OR -yarn add nestjs-commander @nestjs/common @nestjs/core +yarn add nest-commander @nestjs/common @nestjs/core # OR -pnpm i nestjs-commander @nestjs/common @nestjs/core +pnpm i nest-commander @nestjs/common @nestjs/core ``` ## A Command File -`nestjs-commander` makes it easy to write new command line applications with [decorators](https://www.typescriptlang.org/docs/handbook/decorators.html) via the `@Command()` decorator for classes and the `@Option()` decorator for methods of that class. Every command file _should_ implement the `CommandRunner` interface and _should_ be decorated with a `@Command()` decorator. +`nest-commander` makes it easy to write new command line applications with [decorators](https://www.typescriptlang.org/docs/handbook/decorators.html) via the `@Command()` decorator for classes and the `@Option()` decorator for methods of that class. Every command file _should_ implement the `CommandRunner` interface and _should_ be decorated with a `@Command()` decorator. ### CommandRunner @@ -50,10 +50,10 @@ Under the hood, the method that the`@Option()` is decorating is the custom parse ## Running the Command -Similar to how in a NestJS application we can use the `NestFactory` to create a server for us, and run it using `listen`, the `nestjs-commander` package exposes a simple to use API to run your server. Import the `CommandFactory` and use the `static` method `run` and pass in the root module of your application. This would probably look like below +Similar to how in a NestJS application we can use the `NestFactory` to create a server for us, and run it using `listen`, the `nest-commander` package exposes a simple to use API to run your server. Import the `CommandFactory` and use the `static` method `run` and pass in the root module of your application. This would probably look like below ```ts -import { CommandFactory } from 'nestjs-commander'; +import { CommandFactory } from 'nest-commander'; import { AppModule } from './app.module'; async function bootstrap() { @@ -67,14 +67,14 @@ And that's it. Under the hood, `CommandFactory` will worry about calling `NestFa ## Testing -So what's the use of writing a super awesome command line script if you can't test it super easily, right? Fortunately, `nestjs-commander` has some utilities you can make use of that fits in perfectly with the NestJS ecosystem, it'll feel right at home to any Nestlings out there. Instead of using the `CommandFactory` for building the command in test mode, you can use `CommandTestFactory` and pass in your metadata, very similarly to how `Test.createTestingModule` from `@nestjs/testing` works. In fact, it uses this package under the hood. You're also still able to chain on the `overrideProvider` methods before calling `compile()` so you can swap out DI pieces right in the test. [A nice example of this can be seen in the basic.command.factory.spec.ts file](./integration/test/basic.command.factory.spec.ts). +So what's the use of writing a super awesome command line script if you can't test it super easily, right? Fortunately, `nest-commander` has some utilities you can make use of that fits in perfectly with the NestJS ecosystem, it'll feel right at home to any Nestlings out there. Instead of using the `CommandFactory` for building the command in test mode, you can use `CommandTestFactory` and pass in your metadata, very similarly to how `Test.createTestingModule` from `@nestjs/testing` works. In fact, it uses this package under the hood. You're also still able to chain on the `overrideProvider` methods before calling `compile()` so you can swap out DI pieces right in the test. [A nice example of this can be seen in the basic.command.factory.spec.ts file](./integration/test/basic.command.factory.spec.ts). ## Putting it All Together The following class would equate to having a CLI command that can take in the subcommand `basic` or be called directly, with `-n`, `-s`, and `-b` (along with their long flags) all being supported and with custom parsers for each option. The `--help` flag is also supported, as is customary with commander. ```ts -import { Command, CommandRunner, Option } from 'nestjs-commander'; +import { Command, CommandRunner, Option } from 'nest-commander'; import { LogService } from './log.service'; interface BasicCommandOptions { diff --git a/integration/package.json b/integration/package.json index a8a679ae..0c526039 100644 --- a/integration/package.json +++ b/integration/package.json @@ -1,8 +1,8 @@ { "private": "true", "dependencies": { - "nestjs-commander": "workspace:*", - "nestjs-commander-testing": "workspace:*", + "nest-commander": "workspace:*", + "nest-commander-testing": "workspace:*", "commander": "^6.2.1", "@nestjs/common": "^7.6.5", "@nestjs/core": "^7.6.5", diff --git a/integration/src/basic.command.ts b/integration/src/basic.command.ts index 3b77281f..aa6f634c 100644 --- a/integration/src/basic.command.ts +++ b/integration/src/basic.command.ts @@ -1,4 +1,4 @@ -import { Command, CommandRunner, Option } from 'nestjs-commander'; +import { Command, CommandRunner, Option } from 'nest-commander'; import { LogService } from './log.service'; interface BasicCommandOptions { diff --git a/integration/test/basic.command.factory.spec.ts b/integration/test/basic.command.factory.spec.ts index 26cf3a81..2d184e7d 100644 --- a/integration/test/basic.command.factory.spec.ts +++ b/integration/test/basic.command.factory.spec.ts @@ -1,5 +1,5 @@ import { TestingModule } from '@nestjs/testing'; -import { CommandTestFactory } from 'nestjs-commander-testing'; +import { CommandTestFactory } from 'nest-commander-testing'; import { LogService } from '../src/log.service'; import { RootModule } from '../src/root.module'; import { commandMock } from './utils'; diff --git a/integration/test/basic.command.spec.ts b/integration/test/basic.command.spec.ts index f2d3f3aa..0a1dc839 100644 --- a/integration/test/basic.command.spec.ts +++ b/integration/test/basic.command.spec.ts @@ -1,4 +1,4 @@ -import { CommandFactory } from 'nestjs-commander'; +import { CommandFactory } from 'nest-commander'; import { RootModule } from '../src/root.module'; import { commandMock, setArgv } from './utils'; diff --git a/packages/nest-commander-testing/README.md b/packages/nest-commander-testing/README.md new file mode 100644 index 00000000..7b83a3c3 --- /dev/null +++ b/packages/nest-commander-testing/README.md @@ -0,0 +1,19 @@ +# NestJS Commander Testing + +So you;'ve built a CLI application, but you want to test it, and you want to be able to do your usual NestJS DI mocking. Well, here's your solution :fireworks: + +## Installation + +Before you get started, you'll need to install a few packages. First and foremost, this one: `nest-commander-testing` (name pending). You'll also need to install `@nestjs/testing` as this package makes use of them under the hood, but doesn't want to tie you down to a specific version, yay peerDependencies! + +```sh +npm i nest-commander-testing @nestjs/testing +# OR +yarn add nest-commander-testing @nestjs/testing +# OR +pnpm i nest-commander-testing @nestjs/testing +``` + +## Testing With Mocks + +So what's the use of writing a super awesome command line script if you can't test it super easily, right? Fortunately, `nest-commander` has some utilities you can make use of that fits in perfectly with the NestJS ecosystem, it'll feel right at home to any Nestlings out there. Instead of using the `CommandFactory` for building the command in test mode, you can use `CommandTestFactory` and pass in your metadata, very similarly to how `Test.createTestingModule` from `@nestjs/testing` works. In fact, it uses this package under the hood. You're also still able to chain on the `overrideProvider` methods before calling `compile()` so you can swap out DI pieces right in the test. [A nice example of this can be seen in the basic.command.factory.spec.ts file](./../../integration/test/basic.command.factory.spec.ts). diff --git a/packages/nestjs-commander-testing/package.json b/packages/nest-commander-testing/package.json similarity index 92% rename from packages/nestjs-commander-testing/package.json rename to packages/nest-commander-testing/package.json index 64ae2901..7c58912e 100644 --- a/packages/nestjs-commander-testing/package.json +++ b/packages/nest-commander-testing/package.json @@ -1,5 +1,5 @@ { - "name": "nestjs-commander-testing", + "name": "nest-commander-testing", "version": "1.0.0", "description": "A module for making CLI applications with NestJS. Decorators for running commands and separating out config parsers included. This package works on top of commander.", "scripts": { @@ -41,7 +41,7 @@ "@nestjs/core": "^7.6.5", "@nestjs/testing": "^7.6.5", "jest": "^26.6.3", - "nestjs-commander": "workspace:*", + "nest-commander": "workspace:*", "reflect-metadata": "^0.1.13", "ts-jest": "^26.4.4", "typescript": "^4.1.3" @@ -50,6 +50,6 @@ "@nestjs/common": "^7.0.0", "@nestjs/core": "^7.0.0", "@nestjs/testing": "^7.0.0", - "nestjs-commander": "*" + "nest-commander": "*" } } diff --git a/packages/nestjs-commander-testing/src/command-test.factory.ts b/packages/nest-commander-testing/src/command-test.factory.ts similarity index 96% rename from packages/nestjs-commander-testing/src/command-test.factory.ts rename to packages/nest-commander-testing/src/command-test.factory.ts index 7660d3c6..7a3998b6 100644 --- a/packages/nestjs-commander-testing/src/command-test.factory.ts +++ b/packages/nest-commander-testing/src/command-test.factory.ts @@ -1,6 +1,6 @@ import { ModuleMetadata } from '@nestjs/common'; import { Test, TestingModule, TestingModuleBuilder } from '@nestjs/testing'; -import { CommandRunnerCoreModule, CommandRunnerCoreService } from 'nestjs-commander'; +import { CommandRunnerCoreModule, CommandRunnerCoreService } from 'nest-commander'; export class CommandTestFactory { static createTestingCommand(moduleMetadata: ModuleMetadata): TestingModuleBuilder { diff --git a/packages/nestjs-commander-testing/src/index.ts b/packages/nest-commander-testing/src/index.ts similarity index 100% rename from packages/nestjs-commander-testing/src/index.ts rename to packages/nest-commander-testing/src/index.ts diff --git a/packages/nestjs-commander-testing/tsconfig.build.json b/packages/nest-commander-testing/tsconfig.build.json similarity index 100% rename from packages/nestjs-commander-testing/tsconfig.build.json rename to packages/nest-commander-testing/tsconfig.build.json diff --git a/packages/nestjs-commander/README.md b/packages/nest-commander/README.md similarity index 84% rename from packages/nestjs-commander/README.md rename to packages/nest-commander/README.md index b83da34d..783fc0a3 100644 --- a/packages/nestjs-commander/README.md +++ b/packages/nest-commander/README.md @@ -4,19 +4,19 @@ Have you been building amazing REST and RPC applications with [NestJS](https://d ## Installation -Before you get started, you'll need to install a few packages. First and foremost, this one: `nestjs-commander` (name pending). You'll also need to install `@nestjs/common` and `@nestjs/core` as this package makes use of them under the hood, but doesn't want to tie you down to a specific version, yay peerDependencies! +Before you get started, you'll need to install a few packages. First and foremost, this one: `nest-commander` (name pending). You'll also need to install `@nestjs/common` and `@nestjs/core` as this package makes use of them under the hood, but doesn't want to tie you down to a specific version, yay peerDependencies! ```sh -npm i nestjs-commander @nestjs/common @nestjs/core +npm i nest-commander @nestjs/common @nestjs/core # OR -yarn add nestjs-commander @nestjs/common @nestjs/core +yarn add nest-commander @nestjs/common @nestjs/core # OR -pnpm i nestjs-commander @nestjs/common @nestjs/core +pnpm i nest-commander @nestjs/common @nestjs/core ``` ## A Command File -`nestjs-commander` makes it easy to write new command line applications with [decorators](https://www.typescriptlang.org/docs/handbook/decorators.html) via the `@Command()` decorator for classes and the `@Option()` decorator for methods of that class. Every command file _should_ implement the `CommandRunner` interface and _should_ be decorated with a `@Command()` decorator. +`nest-commander` makes it easy to write new command line applications with [decorators](https://www.typescriptlang.org/docs/handbook/decorators.html) via the `@Command()` decorator for classes and the `@Option()` decorator for methods of that class. Every command file _should_ implement the `CommandRunner` interface and _should_ be decorated with a `@Command()` decorator. ### CommandRunner @@ -50,10 +50,10 @@ Under the hood, the method that the`@Option()` is decorating is the custom parse ## Running the Command -Similar to how in a NestJS application we can use the `NestFactory` to create a server for us, and run it using `listen`, the `nestjs-commander` package exposes a simple to use API to run your server. Import the `CommandFactory` and use the `static` method `run` and pass in the root module of your application. This would probably look like below +Similar to how in a NestJS application we can use the `NestFactory` to create a server for us, and run it using `listen`, the `nest-commander` package exposes a simple to use API to run your server. Import the `CommandFactory` and use the `static` method `run` and pass in the root module of your application. This would probably look like below ```ts -import { CommandFactory } from 'nestjs-commander'; +import { CommandFactory } from 'nest-commander'; import { AppModule } from './app.module'; async function bootstrap() { @@ -67,14 +67,14 @@ And that's it. Under the hood, `CommandFactory` will worry about calling `NestFa ## Testing -There is a testing helper package called [`nestjs-commander-testing`](./../nestjs-commander-testing/README.md) that works very similarly to `@nestjs/testing`. Check out it's documentation and examples for help. +There is a testing helper package called [`nest-commander-testing`](./../nest-commander-testing/README.md) that works very similarly to `@nestjs/testing`. Check out it's documentation and examples for help. ## Putting it All Together The following class would equate to having a CLI command that can take in the subcommand `basic` or be called directly, with `-n`, `-s`, and `-b` (along with their long flags) all being supported and with custom parsers for each option. The `--help` flag is also supported, as is customary with commander. ```ts -import { Command, CommandRunner, Option } from 'nestjs-commander'; +import { Command, CommandRunner, Option } from 'nest-commander'; import { LogService } from './log.service'; interface BasicCommandOptions { diff --git a/packages/nestjs-commander/package.json b/packages/nest-commander/package.json similarity index 97% rename from packages/nestjs-commander/package.json rename to packages/nest-commander/package.json index 4d98c343..f05c8a28 100644 --- a/packages/nestjs-commander/package.json +++ b/packages/nest-commander/package.json @@ -1,5 +1,5 @@ { - "name": "nestjs-commander", + "name": "nest-commander", "version": "1.0.0", "description": "A module for making CLI applications with NestJS. Decorators for running commands and separating out config parsers included. This package works on top of commander.", "scripts": { diff --git a/packages/nestjs-commander/src/command-runner-core.module.ts b/packages/nest-commander/src/command-runner-core.module.ts similarity index 100% rename from packages/nestjs-commander/src/command-runner-core.module.ts rename to packages/nest-commander/src/command-runner-core.module.ts diff --git a/packages/nestjs-commander/src/command-runner-core.service.ts b/packages/nest-commander/src/command-runner-core.service.ts similarity index 100% rename from packages/nestjs-commander/src/command-runner-core.service.ts rename to packages/nest-commander/src/command-runner-core.service.ts diff --git a/packages/nestjs-commander/src/command-runner.interface.ts b/packages/nest-commander/src/command-runner.interface.ts similarity index 100% rename from packages/nestjs-commander/src/command-runner.interface.ts rename to packages/nest-commander/src/command-runner.interface.ts diff --git a/packages/nestjs-commander/src/command.decorators.ts b/packages/nest-commander/src/command.decorators.ts similarity index 100% rename from packages/nestjs-commander/src/command.decorators.ts rename to packages/nest-commander/src/command.decorators.ts diff --git a/packages/nestjs-commander/src/command.factory.ts b/packages/nest-commander/src/command.factory.ts similarity index 100% rename from packages/nestjs-commander/src/command.factory.ts rename to packages/nest-commander/src/command.factory.ts diff --git a/packages/nestjs-commander/src/constants.ts b/packages/nest-commander/src/constants.ts similarity index 100% rename from packages/nestjs-commander/src/constants.ts rename to packages/nest-commander/src/constants.ts diff --git a/packages/nestjs-commander/src/index.ts b/packages/nest-commander/src/index.ts similarity index 100% rename from packages/nestjs-commander/src/index.ts rename to packages/nest-commander/src/index.ts diff --git a/packages/nestjs-commander/tsconfig.build.json b/packages/nest-commander/tsconfig.build.json similarity index 100% rename from packages/nestjs-commander/tsconfig.build.json rename to packages/nest-commander/tsconfig.build.json diff --git a/packages/nestjs-commander-testing/README.md b/packages/nestjs-commander-testing/README.md deleted file mode 100644 index ec28f8ca..00000000 --- a/packages/nestjs-commander-testing/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# NestJS Commander Testing - -So you;'ve built a CLI application, but you want to test it, and you want to be able to do your usual NestJS DI mocking. Well, here's your solution :fireworks: - -## Installation - -Before you get started, you'll need to install a few packages. First and foremost, this one: `nestjs-commander-testing` (name pending). You'll also need to install `@nestjs/testing` as this package makes use of them under the hood, but doesn't want to tie you down to a specific version, yay peerDependencies! - -```sh -npm i nestjs-commander-testing @nestjs/testing -# OR -yarn add nestjs-commander-testing @nestjs/testing -# OR -pnpm i nestjs-commander-testing @nestjs/testing -``` - -## Testing With Mocks - -So what's the use of writing a super awesome command line script if you can't test it super easily, right? Fortunately, `nestjs-commander` has some utilities you can make use of that fits in perfectly with the NestJS ecosystem, it'll feel right at home to any Nestlings out there. Instead of using the `CommandFactory` for building the command in test mode, you can use `CommandTestFactory` and pass in your metadata, very similarly to how `Test.createTestingModule` from `@nestjs/testing` works. In fact, it uses this package under the hood. You're also still able to chain on the `overrideProvider` methods before calling `compile()` so you can swap out DI pieces right in the test. [A nice example of this can be seen in the basic.command.factory.spec.ts file](./../../integration/test/basic.command.factory.spec.ts). diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ef9a78b2..7a9e8bf4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -51,8 +51,8 @@ importers: '@nestjs/testing': 7.6.5_0c0a57cf47818081758771caab802b19 commander: 6.2.1 jest: 26.6.3 - nestjs-commander: 'link:../packages/nestjs-commander' - nestjs-commander-testing: 'link:../packages/nestjs-commander-testing' + nest-commander: 'link:../packages/nest-commander' + nest-commander-testing: 'link:../packages/nest-commander-testing' ts-jest: 26.4.4_jest@26.6.3+typescript@4.1.3 typescript: 4.1.3 specifiers: @@ -61,11 +61,11 @@ importers: '@nestjs/testing': ^7.6.5 commander: ^6.2.1 jest: ^26.6.3 - nestjs-commander: 'workspace:*' - nestjs-commander-testing: 'workspace:*' + nest-commander: 'workspace:*' + nest-commander-testing: 'workspace:*' ts-jest: ^26.4.4 typescript: ^4.1.3 - packages/nestjs-commander: + packages/nest-commander: dependencies: '@golevelup/nestjs-discovery': 2.3.1 commander: 6.2.1 @@ -89,14 +89,14 @@ importers: reflect-metadata: ^0.1.13 ts-jest: ^26.4.4 typescript: ^4.1.3 - packages/nestjs-commander-testing: + packages/nest-commander-testing: devDependencies: '@nestjs/cli': 7.5.4 '@nestjs/common': 7.6.5_reflect-metadata@0.1.13 '@nestjs/core': 7.6.5_f545d9736447f44a5b3cb1701b885beb '@nestjs/testing': 7.6.5_0c0a57cf47818081758771caab802b19 jest: 26.6.3 - nestjs-commander: 'link:../nestjs-commander' + nest-commander: 'link:../nest-commander' reflect-metadata: 0.1.13 ts-jest: 26.4.4_jest@26.6.3+typescript@4.1.3 typescript: 4.1.3 @@ -106,7 +106,7 @@ importers: '@nestjs/core': ^7.6.5 '@nestjs/testing': ^7.6.5 jest: ^26.6.3 - nestjs-commander: 'workspace:*' + nest-commander: 'workspace:*' reflect-metadata: ^0.1.13 ts-jest: ^26.4.4 typescript: ^4.1.3 diff --git a/tsconfig.json b/tsconfig.json index 519dde35..38ebbc37 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,8 +13,8 @@ "noUnusedLocals": false, "lib": ["ES7"], "paths": { - "nestjs-commander": ["packages/nestjs-commander/dist/index.d.ts"], - "nestjs-commander-testing": ["packages/nestjs-commander-testing/dist/index.d.ts"] + "nest-commander": ["packages/nest-commander/dist/index.d.ts"], + "nest-commander-testing": ["packages/nest-commander-testing/dist/index.d.ts"] } }, "exclude": ["node_modules", "dist"]