Coder Social home page Coder Social logo

angular2-generator's Introduction

Angular2 Generator

Angular2 Generator is a command line code generator for Angular 2 applications. It supports initialising a starter application and creating components, directives, services and pipes through the command line.

Setup

Install globally for easiest use.

npm install -g angular2-generator

Init

Run the following command to create an empty starter project for an angular2 application based on the 5 Min Quickstart. The created application uses SystemJs as the module loader.

ng2 init

The init command will also generate an ng2config.json file which contains all the necessary configuration for using Angular2 Generator.

At the end of the init you will be prompted to create a starting app. If you chose to create one make sure you have typings installed globaly because the script will try to run typings install after executing npm install.

ng2config.json values:

Key Value Description
appFolder String Route of the angular2 aplication folder with out the leading slash. For example "foo/bar" or "app" is ok but "/app" or "app/" might cause errors.
bootLocation String Path to the file where the application is bootstraped (this is only needed if you want the option of auto injecting services). The path starts from the appFolder route. For example if bootLocation has the value "boot.ts" then angular2-generator will expect to find it at: appFolder/boot.ts
componentsFolder String Location of the folder where all generated components get placed. This route also starts with the appFolder. So for example if componentsFolder has the value "something/components" angular2-generator will generate componets at this location: appFolder/something/components
servicesFolder String Location of the folder where all the generated services get placed. Also starts with the appFolder.
directivesFolder String Location of the folder where all the generated directives get placed. Starts with the appFolder.
pipesFolder String Location of the folder where all the generated pipes get placed. Starts with the appFolder.

Generating Files

Command Functionality Additional Options
c or component [fileName] Create a component true
d or directive [fileName] Create a directive false
s or service [fileName] Create a service true
p or pipe [fileName] Create a pipe false

Example command:

ng2 c test

When this command runs the file test.component.ts gets created at the location specified in the ng2config.json file or if no location was provided then it gets created in the appFolder of the application or in the root folder if the appFolder was also not provided.

The following is also a valid [fileName] format: "something/foo/bar/test". In this case the file test.component.ts would be created at this location appFolder/something/foo/bar/.

Component additional option

Option: -t or -template

ng2 c test -t

Would create the file test.component.ts and the file test.html at the same location

Service additional option

Option: -i or -inject

To use this option you need to provide a bootLocation in the ng2config.json file and comments specifying inject locations.

boot.ts

import {bootstrap}    from 'angular2/platform/browser';
import {AppComponent} from './app.component';
// ng2:bootImport

bootstrap(AppComponent, [
    // ng2:bootInject

]);

The "// ng2:bootImport" comment sets the location of the import that should be injected. The "// ng2:bootInject" comment sets the location of the service that should be injected.

Command example

ng2 s test -i

Generated files content

###Component

When the following command is called:

ng2 c test
import {Component} from "angular2/core"

@Component({
    selector: "test",
    template: "<p>We Work!</p>"
})
export class TestComponent {
    constructor() {}
}

###Service

When the following command is called:

ng2 s test
import {Injectable} from "angular2/core";

@Injectable()
export class TestService {
    constructor() {}
}

###Directive

When the following command is called:

ng2 d test
import {Directive, Input, ElementRef, TemplateRef, ViewContainerRef} from "angular2/core";

/*
 * Description:
 *
 * Usage:
 *
 * Example:
 *
 */
@Directive({ selector: "[test]" })
export class TestDirective {
    constructor(
        private _templateRef: TemplateRef,
        private _viewContainer: ViewContainerRef,
        private  _elementRef: ElementRef
    ) {}

}

###Pipe

When the following command is called:

ng2 p test
import {Pipe, PipeTransform} from "angular2/core";

/*
 * Description:
 *
 * Usage:
 *
 * Example:
 *
 */
@Pipe({name: "test"})
export class TestPipe implements PipeTransform {
    transform(value: any, args: string[]): any {

    }
}

angular2-generator's People

Contributors

flauc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

angular2-generator's Issues

can't execute the generator command.

I installed angualr2-generator directly, but when I execute the ng2 command, I got the following errors:

/usr/bin/env: "node\r": no such file or dictionary

my nodejs version is 7.2.1

and /usr/bin/node command exist.

hope any help. thx

Behind the proxy

Hi ,

How we can add proxy if we are working behind the corporate firewall ?

Tried :
I put the proxy in .npmrc file . Still, It is not getting resolve.

Trace :
Application created. Attempting to run scripts now.

> [email protected] postinstall C:\MyMachine\WorkSpace\POC\Sample-Angular2
> typings install

typings ERR! message Unable to read typings for "jasmine". You should check the entry paths in "jasmine.d.ts" are up to date
typings ERR! caused by Unable to connect to "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/5c182b9af717f73146399c2485f70f1e2ac0ff2b/jasmine/jasmine.d.ts"
typings ERR! caused by connect ETIMEDOUT 151.101.48.133:443

typings ERR! cwd C:\MyMachine\WorkSpace\POC\Sample-Angular2
typings ERR! system Windows_NT 6.1.7601
typings ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\MyMachine\\WorkSpace\\POC\\Sample-Angular2\\node_modules\\typings\\dist\\bin.js" "install"
typings ERR! node -v v6.9.1
typings ERR! typings -v 0.7.12

typings ERR! If you need help, you may report this error at:
typings ERR!   <https://github.com/typings/typings/issues>

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN [email protected] No repository field.
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! node v6.9.1
npm ERR! npm  v3.10.8
npm ERR! code ELIFECYCLE
npm ERR! [email protected] postinstall: `typings install`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script 'typings install'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the Google-Map package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     typings install
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs Google-Map
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls Google-Map
npm ERR! There is likely additional logging output above.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.