0.0.5 • Published 4 years ago

ngx-feat-generator-cli v0.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

:rocket: NgxFeatGeneratorCLI

Node.js CI

CLI for generating Angular feature from a json config input file.

NgxFeatGeneratorCLI is a simple CLI for generating Angular feature directory, inside an existing Angular application. Under the hood it uses the angular schematics to generate components, services, guard etc.

Alt Text

Prerequisites

First, you should install the Angular CLI globally.

npm i -g @angular/cli

Installation

npm i -g ngx-feat-generator-cli

Usage

To display CLI help use the following command :

ngx-feat-generator --help


Usage: ngx-feat-generator [options]

Ngx CLI for generating Angular feature directory from a json config input file

Options:
  -V, --version             output the version number
  -f, --file-config <type>  JSON input config file
  -h, --help                output usage information

Generating a new Angular feature directory

You must create a json input file, in order to orchestrate the CLI. The json describes your desired files tree.

Below an example json config file :

{
  "feature": "broadcast",
  "projectPath": "test/fake-ng-project",
  "featurePath": "src/app/broadcast",
  "tree": [
    {
      "type": "module",
      "name": "broadcast",
      "opts": "--routing=true"
    },
    {
      "type": "component",
      "name": "broadcast/components/real-estate-card",
      "opts": "--changeDetection=OnPush --module=broadcast/broadcast.module.ts",
      "extra": {
        "isolatedTest": true
      }
    },
    {
      "type": "component",
      "name": "broadcast/components/broadcast-information-dialog",
      "opts": "--changeDetection=OnPush --module=broadcast/broadcast.module.ts",
      "extra": {
        "isolatedTest": true
      }
    },
    {
      "type": "guard",
      "name": "broadcast/shared/guard/elysium-guard",
      "opts": "--implements=CanActivate",
      "extra": {
        "isolatedTest": true
      }
    },
    {
      "type": "interface",
      "name": "broadcast/shared/models/broadcast"
    },
    {
      "type": "interface",
      "name": "broadcast/shared/models/shopping-cart"
    },
    {
      "type": "interface",
      "name": "broadcast/shared/models/cart-item"
    },
    {
      "type": "enum",
      "name": "broadcast/shared/models/cart-item-type"
    },
    {
      "type": "service",
      "name": "broadcast/shared/services/broadcast",
      "extra": {
        "isolatedTest": true
      }
    },
    {
      "type": "service",
      "name": "broadcast/shared/services/pack",
      "extra": {
        "isolatedTest": true
      }
    }
  ]
}

You 'll find below the json fields description :

FieldTypeDescription
featurestringThe name of the feature to generate
projectPathstringThe location of the existing Angular project
featurePathstringThe path of the feature inside the existing Angular project
treeTreeItem[]TreeItem Array which describes the tree files of the desired feature

Below the description of the TreeItem object :

FieldTypeDescription
typestringAngular CLI schematic type : 'component', 'module', 'interface', 'guard', 'enum', 'service'. A special type has been added for our needs : 'spec'. It allows us to update the default Angular test to make isolated-test.
namestringthe path of the generated item.
opts?stringAngular CLI options. ex: --changeDetection=OnPush --module=broadcast/broadcast.module.ts
extra?ExtraConfigExtra config for our needs for isolated test generation

Finally, run the generation command :

ngx-feat-generator --file-config ./test/broadcast.json

Contributing

If you want to contribute, you could setup the project in your local machine, with a standard git clone :

git clone git@github.com:IAD-INTERNATIONAL/NgxFeatGeneratorCLI.git

Next you must generate the fake ng project in ./test/fake-ng-project:

npm run setup:fake-project

To run the integration test :

npm run test:integration

To run the Jest test :

npm test

or

npm run test:watch

License

ISC