{"_id":"@amabios/nestjs-command","_rev":"1-2b684eddda1356af6386127b87dbca32","name":"@amabios/nestjs-command","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@amabios/nestjs-command","version":"1.0.0","description":"nest.js command tool","license":"MIT","scripts":{"build":"rimraf dist && tsc -b tsconfig.build.json","format":"prettier lib/**/*.ts --write","test":"tsx scripts/test.ts"},"main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"require":"./dist/index.js"},"./*":"./*"},"dependencies":{"lodash.compact":"^3.0.1","lodash.flattendeep":"^4.4.0"},"bin":{"nestjs-command":"bin/cli"},"devDependencies":{"@nestjs/common":"^6.0.5","@nestjs/core":"^6.0.5","@nestjs/testing":"^6.0.5","@types/jest":"^27.0.1","@types/lodash.compact":"^3.0.6","@types/lodash.flattendeep":"^4.4.6","@types/node":"^10.3.5","@types/yargs":"^16.0.4","cross-env":"^7.0.3","execa":"^5.1.1","jest":"^27.0.6","nestjs-common-6":"npm:@nestjs/common@^6.0.5","nestjs-common-7":"npm:@nestjs/common@^7.0.0","nestjs-common-8":"npm:@nestjs/common@^8.0.0","nestjs-common-9":"npm:@nestjs/common@^9.0.0","nestjs-core-6":"npm:@nestjs/core@^6.0.5","nestjs-core-7":"npm:@nestjs/core@^7.0.0","nestjs-core-8":"npm:@nestjs/core@^8.0.0","nestjs-core-9":"npm:@nestjs/core@^9.0.0","nestjs-testing-6":"npm:@nestjs/testing@^6.0.5","nestjs-testing-7":"npm:@nestjs/testing@^7.0.0","nestjs-testing-8":"npm:@nestjs/testing@^8.0.0","nestjs-testing-9":"npm:@nestjs/testing@^9.0.0","prettier":"^1.14.2","reflect-metadata":"^0.1.12","rimraf":"^3.0.2","rxjs":"7.3.0","rxjs-6":"npm:rxjs@6.0.0","rxjs-7":"npm:rxjs@7.3.0","ts-jest":"^27.0.5","tsx":"^3.12.1","typescript":"^4.4.2","yargs-16":"npm:yargs@^16.0.0","yargs-17":"npm:yargs@^17.0.0"},"peerDependencies":{"@nestjs/common":"^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0","@nestjs/core":"^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0","yargs":"^16.0.0 || ^17.0.0"},"repository":{"type":"git","url":"git+https://gitlab.com/aa900031/nestjs-command.git"},"keywords":["nestjs","command","cli","yargs"],"bugs":{"url":"https://gitlab.com/aa900031/nestjs-command/issues"},"homepage":"https://gitlab.com/aa900031/nestjs-command#readme","directories":{"example":"examples","lib":"lib","test":"test"},"author":{"name":"@amabios"},"gitHead":"0982aa4a0b19673eb98254e1dde01f52090179a4","_id":"@amabios/nestjs-command@1.0.0","_nodeVersion":"18.16.0","_npmVersion":"9.5.1","dist":{"integrity":"sha512-/CzyiMyKP+DQNEyqABJb2dQJi5OfI4Jrt9xo/JdzMoeY9EZFWiqbnNxNomNtglHgEwEjm/ILNhWoNCY5DCxIuw==","shasum":"c3246fbf1efab82eabdf6da94a29cef6da4efcdb","tarball":"https://registry.npmjs.org/@amabios/nestjs-command/-/nestjs-command-1.0.0.tgz","fileCount":4,"unpackedSize":10367,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIB9ozvu0lqNnS4iv9MieaJ4FRAaCbE1F3kFP/og2LwwWAiEA9ITpdyMrik+BmHPdjYfw97HxmrvG7UmjeMM2WpbGYao="}]},"_npmUser":{"name":"amabios","email":"roberto.amadio97@gmail.com"},"maintainers":[{"name":"amabios","email":"roberto.amadio97@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/nestjs-command_1.0.0_1687515040823_0.5660475287888811"},"_hasShrinkwrap":false},"1.0.1":{"name":"@amabios/nestjs-command","version":"1.0.1","description":"nest.js command tool","license":"MIT","scripts":{"build":"rimraf dist && tsc -b tsconfig.build.json","format":"prettier lib/**/*.ts --write","test":"tsx scripts/test.ts"},"main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"require":"./dist/index.js"},"./*":"./*"},"dependencies":{"lodash.compact":"^3.0.1","lodash.flattendeep":"^4.4.0"},"bin":{"nestjs-command":"bin/cli"},"devDependencies":{"@nestjs/common":"^6.0.5","@nestjs/core":"^6.0.5","@nestjs/testing":"^6.0.5","@types/jest":"^27.0.1","@types/lodash.compact":"^3.0.6","@types/lodash.flattendeep":"^4.4.6","@types/node":"^10.3.5","@types/yargs":"^16.0.4","cross-env":"^7.0.3","execa":"^5.1.1","jest":"^27.0.6","nestjs-common-6":"npm:@nestjs/common@^6.0.5","nestjs-common-7":"npm:@nestjs/common@^7.0.0","nestjs-common-8":"npm:@nestjs/common@^8.0.0","nestjs-common-9":"npm:@nestjs/common@^9.0.0","nestjs-core-6":"npm:@nestjs/core@^6.0.5","nestjs-core-7":"npm:@nestjs/core@^7.0.0","nestjs-core-8":"npm:@nestjs/core@^8.0.0","nestjs-core-9":"npm:@nestjs/core@^9.0.0","nestjs-testing-6":"npm:@nestjs/testing@^6.0.5","nestjs-testing-7":"npm:@nestjs/testing@^7.0.0","nestjs-testing-8":"npm:@nestjs/testing@^8.0.0","nestjs-testing-9":"npm:@nestjs/testing@^9.0.0","prettier":"^1.14.2","reflect-metadata":"^0.1.12","rimraf":"^3.0.2","rxjs":"7.3.0","rxjs-6":"npm:rxjs@6.0.0","rxjs-7":"npm:rxjs@7.3.0","ts-jest":"^27.0.5","tsx":"^3.12.1","typescript":"^4.4.2","yargs-16":"npm:yargs@^16.0.0","yargs-17":"npm:yargs@^17.0.0"},"peerDependencies":{"@nestjs/common":"^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0","@nestjs/core":"^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0","yargs":"^16.0.0 || ^17.0.0"},"repository":{"type":"git","url":"git+https://gitlab.com/aa900031/nestjs-command.git"},"keywords":["nestjs","command","cli","yargs"],"bugs":{"url":"https://gitlab.com/aa900031/nestjs-command/issues"},"homepage":"https://gitlab.com/aa900031/nestjs-command#readme","directories":{"example":"examples","lib":"lib","test":"test"},"author":{"name":"@amabios"},"gitHead":"0982aa4a0b19673eb98254e1dde01f52090179a4","_id":"@amabios/nestjs-command@1.0.1","_nodeVersion":"18.16.0","_npmVersion":"9.5.1","dist":{"integrity":"sha512-XYJdwRAY825RhDOh8wfPoJ5EvZfBooRo3XgZG6phdSvzHBYI4vAud9zQbS2tyv+8fOb5MG6J8/iQfNmKzIkrkw==","shasum":"804f1f6c8827174a450a8030e11bfc0fa2a94a52","tarball":"https://registry.npmjs.org/@amabios/nestjs-command/-/nestjs-command-1.0.1.tgz","fileCount":16,"unpackedSize":28446,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCcE53688ocz7yTMIP42CP/VH/7kpqOVJtTSl6oP65dcwIgGB1TeZJcFx0UCR2PR2kgkERqYul9ta8y/PGT3pMjpXc="}]},"_npmUser":{"name":"amabios","email":"roberto.amadio97@gmail.com"},"maintainers":[{"name":"amabios","email":"roberto.amadio97@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/nestjs-command_1.0.1_1687515476592_0.7430713260914361"},"_hasShrinkwrap":false}},"time":{"created":"2023-06-23T10:10:40.730Z","1.0.0":"2023-06-23T10:10:41.035Z","modified":"2023-06-23T10:17:56.899Z","1.0.1":"2023-06-23T10:17:56.781Z"},"maintainers":[{"name":"amabios","email":"roberto.amadio97@gmail.com"}],"description":"nest.js command tool","homepage":"https://gitlab.com/aa900031/nestjs-command#readme","keywords":["nestjs","command","cli","yargs"],"repository":{"type":"git","url":"git+https://gitlab.com/aa900031/nestjs-command.git"},"author":{"name":"@amabios"},"bugs":{"url":"https://gitlab.com/aa900031/nestjs-command/issues"},"license":"MIT","readme":"# Nestjs Command\n\n## Description\n\n[Nest.js](https://github.com/nestjs/nest) Command tools, based on [yargs](https://github.com/yargs/yargs).\n(This Nestjs Command version include a )\n## Dependency\n\n- Use version `1.*` for nestjs `6.*`, `7.*`, `8.*`, `9.*`, `10.*`, yargs `16.*`, `17.*`\n\n## Installation\n\n```bash\n$ npm install --save @amabios/nestjs-command yargs\n\n# if you use typescript\n$ npm install --save-dev @types/yargs\n```\n\n## Quick Start\n\nRegister the command module in your base module: `./src/app.module.ts`\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { CommandModule } from '@amabios/nestjs-command';\n\n@Module({\n  imports: [CommandModule]\n})\nexport class AppModule {}\n```\n\nCreate a Cli entrypoint: `./src/cli.ts`\n\n```typescript\nimport { NestFactory } from '@nestjs/core';\nimport { CommandModule, CommandService } from '@amabios/nestjs-command';\nimport { AppModule } from './app.module.ts';\n\nasync function bootstrap () {\n  const app = await NestFactory.createApplicationContext(AppModule, {\n    logger: false\n  });\n\n  try {\n    await app\n      .select(CommandModule)\n      .get(CommandService)\n      .exec();\n    await app.close()\n  } catch (error) {\n    console.error(error);\n    await app.close();\n    process.exit(1);\n  }\n}\n\nbootstrap();\n```\n\nAnd create your command providers (see the example below).\n\nRun your program in either ways:\n\n- `npx @amabios/nestjs-command`: run by default `./src/cli.ts`\n- `CLI_PATH=./dist/cli.js npx @amabios/nestjs-command`: run `/dist/cli.js` with the `CLI_PATH` env\n\n\n**Notice**\n\nMake sure to set `CLI_ENV=./dist/cli.js` when using commands in production with pre-compiled typescript\n\n\n## Usage example\n\n> Note: you will find documentation about yargs `command positional` [here](https://yargs.js.org/docs/#api-reference-positionalkey-opt), and yargs `command options` [here](https://yargs.js.org/docs/#api-reference-optionskey-opt).\n\nCreate a simple Command File: `./src/user/user.command.ts`\n\n```typescript\nimport { Command, Positional, Option } from '@amabios/nestjs-command';\nimport { Injectable } from '@nestjs/common';\nimport { UserService } from './user.service';\n\n@Injectable()\nexport class UserCommand {\n  constructor(private readonly userService: UserService) {}\n\n  @Command({\n    command: 'create:user <username>',\n    describe: 'create a user',\n  })\n  async create(\n    @Positional({\n      name: 'username',\n      describe: 'the username',\n      type: 'string'\n    })\n    username: string,\n    @Option({\n      name: 'group',\n      describe: 'user group (ex: \"jedi\")',\n      type: 'string',\n      alias: 'g',\n      required: false\n    })\n    group: string,\n    @Option({\n      name: 'saber',\n      describe: 'if user has a lightsaber',\n      type: 'boolean',\n      default: false,\n      required: false\n    })\n    saber: boolean\n  ) {\n    this.userService.add({\n      username,\n      group,\n      saber\n    });\n  }\n}\n```\n\nCreate a simple Service File: `./src/user/user.service.ts`\n\n```typescript\nimport { Injectable } from '@nestjs/common';\n\n@Injectable()\nexport class UserService {\n  async add(user: any): Promise<any> {\n    return Promise.resolve().then(() => {\n      console.log('user added:', user);\n    });\n  }\n}\n```\n\nRegister this _UserCommand_ and _UserService_ as providers in your base module: `./src/app.module.ts`\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { CommandModule } from '@amabios/nestjs-command';\nimport { UserCommand } from './user/user.command';\nimport { UserService } from './user/user.service';\n\n@Module({\n  imports: [CommandModule],\n  providers: [UserCommand, UserService]\n})\nexport class AppModule {}\n```\n\nAnd create a cli entrypoint: `./src/cli.ts`\n\n```typescript\nimport { NestFactory } from '@nestjs/core';\nimport { CommandModule, CommandService } from '@amabios/nestjs-command';\nimport { AppModule } from './app.module';\n\nasync function bootstrap() {\n  const app = await NestFactory.createApplicationContext(AppModule, {\n    logger: ['error'] // only errors\n  });\n\n  try {\n    await app\n      .select(CommandModule)\n      .get(CommandService)\n      .exec();\n    await app.close()\n  } catch (error) {\n    console.error(error);\n    await app.close();\n    process.exit(1);\n  }\n}\nbootstrap();\n```\n\n### Run your program in a terminal\n\n**Get some help**:\n\n```bash\n$ npx @amabios/nestjs-command create:user --help\ncli create:user <username>\n\ncreate a user\n\nPositionals:\n  username  the username                                     [string] [required]\n\nOptions:\n  -h, --help     Show help                                             [boolean]\n  --saber        if user has a lightsaber             [boolean] [default: false]\n  --group, -g    user group (ex: \"jedi\")                                [string]\n  -v, --version  Show version number                                   [boolean]\n```\n\n**Add a new user**:\n\n```bash\n$ npx @amabios/nestjs-command create:user anakin --group jedi --no-saber\nuser added: { username: 'anakin', group: 'jedi', saber: false }\n\n$ npx @amabios/nestjs-command create:user yoda --group jedi --saber\nuser added: { username: 'yoda', group: 'jedi', saber: true }\n```\n\n### How to test it?\n\n```typescript\nimport { Test } from '@nestjs/testing';\nimport { CommandModule, CommandModuleTest } from '@amabios/nestjs-command';\nimport { AppModule } from './app.module';\n\ndescribe('AppModule', () => {\n  let commandModule: CommandModuleTest;\n\n  beforeEach(async () => {\n    const moduleFixture = await Test.createTestingModule({\n      imports: [AppModule]\n    }).compile();\n\n    const app = moduleFixture.createNestApplication();\n    await app.init();\n    commandModule = new CommandModuleTest(app.select(CommandModule));\n  });\n\n  it('test command module', async () => {\n    const command = 'create:user <username>';\n    const args = { username: 'Foo', group: 'Bar', saber: false };\n\n    const user = await commandModule.execute(command, args);\n    expect(user.username).toBe('Foo')\n    expect(user.group).toBe('Bar')\n  });\n});\n```\n","readmeFilename":"README.md"}