npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng2-template-cli

v1.1.0

Published

Command Line Tool to generate Angular 2 components

Downloads

4

Readme

NG2-Template-Cli

Command line tool to generate components based off of the official Angular 2 style guide

Installation

npm install ng2-template-cli -g

NOTE: You can also install it local to your project but you will only be able to use it from npm scripts.

Usage

  • If you are in the root of your project the cli will generate all files/folders in the ./src/app directory by default. You can use the --parent(-p) flag to change this.
  • If you are in any other folder other than the root it will use the current working directory to generate the files/folders. --parent(-p) will be relative to the current working directory.
  Usage: ng2t [options]

  Generate component templates based off of the Angular 2 style guide

  Options:

    -h, --help             output usage information
    -V, --version          output the version number
    -t, --type <type>      Define the type of component you want to generate(eg. component,service,etc)
    -n, --name <name>      Give your component a name
    -p, --parent [parent]  Define a new relative path to generate your template at(this path is relative to ./src/app/ if you are in the root of your project. Otherwise it uses the current working directory)

Examples

From the command line: Generate an enum with the name first

$ ng2t -t enum -n first
// or
$ ng2t --type enum --name first

Generate a component in src/app/common. This assumes you are in the root of your project

$ ng2t -t component -n first -p common
// or
$ ng2t --type component --name first --parent common

You can also do the above examples as npm scripts in your package.json:

Generate an enum with the name first

"generate:enum": "ng2t -t enum"
// then from the command line
$ npm run generate:enum -- -n first

Components

The following angular component types and their corresponding files can be generated using this cli:

  • Component
    • folder name
      • name.component.ts
      • name.component.html
      • name.component.css
      • name.component.spec.ts
  • Directive
    • name.directive.ts
    • name.directive.spec.ts
  • Service
    • name.service.ts
    • name.service.spec.ts
  • Enum
    • name.enum.ts
  • Interface
    • name.ts
  • Pipe
    • name.pipe.ts
    • name.pipe.spec.ts
  • Route
    • name.routing.ts
  • Module
    • name.module.ts

API

-t, --type

Define the type of component you want to generate(eg. component,service,etc)

  • This flag is required
  • Valid options
    • component
    • directive
    • service
    • enum
    • interface
    • pipe
    • route
    • module

This will generate a service and the related files/folder named first. Refer to the Components section to see the files/folders generated.

$ ng2t -t service -n first

This is equivalant to the above example

$ ng2t --type service --name first

-n, --name

Give your component a name

  • This flag is required
  • When supplying the name omit the word Component, Service, etc. For example, if you want the name of your service to be firstService your command would look like --name first

This will generate an enum and the related files/folder named first. Refer to the Components section to see the files/folders generated.

$ ng2t -t enum -n first

This is equivalant to the above example

$ ng2t --type enum --name first

-p, --parent

Define a new relative path to generate your template at(this path is relative to ./src/app/ if you are in the root of your project. Otherwise it uses the current working directory

  • This flag is optional
  • Say you wanted to store all your components in a components folder under ./src/app/components. You would then want to set the parent flag to -p components
  • Maybe you have a common component that you want to generate in ./src/app/common/components. The parent flag would be -p common/components
  • If you define a path and some or all of the folders don't exist the cli will create all the necessary folders.

This will generate an enum and the related files/folder named first and place the files under ./src/app/enums. If you omitted the -p flag it will place the files under ./src/app. Refer to the Components section to see the files/folders generated.

$ ng2t -t enum -n first -p enums

This is equivalant to the above example

$ ng2t --type enum --name first --parent enums