Skip to content

Commit

Permalink
chore: change package names to not collide with existing
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcdo29 committed Jan 15, 2021
1 parent c39112c commit 648ed46
Show file tree
Hide file tree
Showing 23 changed files with 57 additions and 57 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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() {
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions integration/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion integration/src/basic.command.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion integration/test/basic.command.factory.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion integration/test/basic.command.spec.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
19 changes: 19 additions & 0 deletions packages/nest-commander-testing/README.md
Original file line number Diff line number Diff line change
@@ -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).
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -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"
Expand All @@ -50,6 +50,6 @@
"@nestjs/common": "^7.0.0",
"@nestjs/core": "^7.0.0",
"@nestjs/testing": "^7.0.0",
"nestjs-commander": "*"
"nest-commander": "*"
}
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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() {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 0 additions & 19 deletions packages/nestjs-commander-testing/README.md

This file was deleted.

16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 648ed46

Please sign in to comment.