Installations
npm install generator-ng-cli-lib
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
8.2.1
NPM Version
5.3.0
Score
41.9
Supply Chain
87.3
Quality
68.9
Maintenance
25
Vulnerability
97.6
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (84.9%)
TypeScript (12.58%)
HTML (2.52%)
Developer
jvandemo
Download Statistics
Total Downloads
1,004
Last Day
1
Last Week
1
Last Month
3
Last Year
121
GitHub Statistics
751 Stars
241 Commits
122 Forks
33 Watching
1 Branches
28 Contributors
Package Meta Information
Latest Version
11.0.3
Package Id
generator-ng-cli-lib@11.0.3
Size
11.51 kB
NPM Version
5.3.0
Node Version
8.2.1
Total Downloads
Cumulative downloads
Total Downloads
1,004
Last day
0%
1
Compared to previous day
Last week
0%
1
Compared to previous week
Last month
-70%
3
Compared to previous month
Last year
7.1%
121
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Yeoman generator to create a standalone Angular library in seconds.
If you want to create an Angular library with directives, services and/or pipes, then this generator is just what you need.
This generator aligns with the official Angular Package Format and automatically generates a Flat ES Module, a UMD bundle, a single metadata.json and type definitions to make your library ready for AOT compilation by the consuming Angular application.
Watch Jason Aden's talk to learn more about the Angular Package Format.
More specifically, this generator:
- creates and configures
package.json
for the development of your library - creates and configures a second
package.json
for the distribution of your library - creates and configures
tsconfig.json
for your editor during development - creates and configures
tslint.json
for linting purposes - creates and configures
.gitignore
,.npmignore
and.travis.yml
- creates the main library file, a sample directive, a sample component, a sample service and a sample pipe
- configures tslint for you with codelyzer support
- creates and configures build scripts to generate a Flat ES Module (FESM), type definitions and metadata files for your library to make it ready for AOT compilation
- creates and configures build scripts to generate a Universal Module Definition (UMD) bundle to use your library in Node.js, SystemJS and with script tags (Plunker, Fiddle, etc)
- inlines templates automatically for you so you can use external HTML templates
- inlines styles automatically for you so you can use external CSS templates
- supports .scss files
- supports unit tests and code coverage using jest
This generator is built for Angular version 2 and above, hence the name generator-angular2-library. If you are looking for a similar generator for AngularJS 1.x, please visit generator-angularjs-library.
Quick start
First, install Yeoman and generator-angular2-library using npm (assuming you already have node.js pre-installed).
1$ npm install -g yo 2$ npm install -g generator-angular2-library
make a new directory and cd
into it:
1$ mkdir angular-library-name 2$ cd angular-library-name
and generate your new library:
1$ yo angular2-library
The generator will prompt you for:
1? Your full name: Jurgen Van de Moere 2? Your email address: jurgen.van.de.moere@gmail.com 3? Your library name (kebab case): angular-library-name 4? Git repository url: https://github.com/jvandemo/angular2-library-name
and create the following files for you:
1. 2├── README.MD 3├── gulpfile.js 4├── package.json 5├── src 6│  ├── index.ts 7│  ├── package.json 8│  ├── sample.component.ts 9│  ├── sample.directive.ts 10│  ├── sample.pipe.ts 11│  ├── sample.service.ts 12│  └── tsconfig.es5.json 13├── tsconfig.json 14└── tslint.json
You can then add or edit *.ts
files in the src/
directory and run:
1$ npm run build
to automatically create all *.js
, *.d.ts
and *.metadata.json
files in the dist
directory:
1dist 2├── index.d.ts # Typings for AOT compilation 3├── index.js # Flat ES Module (FESM) for us with webpack 4├── lib.d.ts # Typings for AOT compilation 5├── lib.metadata.json # Metadata for AOT compilation 6├── lib.umd.js # UMD bundle for use with Node.js, SystemJS or script tag 7├── package.json # package.json for consumer of your library 8├── sample.component.d.ts # Typings for AOT compilation 9├── sample.directive.d.ts # Typings for AOT compilation 10├── sample.pipe.d.ts # Typings for AOT compilation 11└── sample.service.d.ts # Typings for AOT compilation
Finally you publish your library to NPM by publishing the contents of the dist
directory:
1$ npm publish dist
TypeScript config
The generator creates 2 TypeScript config files:
tsconfig.json
is used to configure your editor during development and is not used for building your librarysrc/tsconfig.es5.json
is used by the Angular compiler to build the files in thedist
directory when you runnpm run build
Linting your code
Your library comes pre-configured with tslint and codelyzer support. To lint your code:
1$ npm run lint
Building your library
From the root of your library directory, run:
1$ npm run build
This will generate a dist
directory with:
- a
package.json
file specifically for distribution with Angular listed in thepeerDependencies
sample-library.js
: a Flat ES Module (FESM) file that contains all your library code in a single filesample-library.umd.js
: a Universal Module Definition (UMD) bundle file that contains all your library code in UMD format for use in Node.js, SystemJS or via a script tag (e.g. in Plunker, Fiddle, etc)*.d.ts
: type definitions for you librarysample-library.metadata.json
: metadata for your library to support AOT compilation
Generating documentation for your library
From the root of your library directory, run:
1$ npm run docs:build
This will generate a docs
directory with all documentation of your library.
To serve your documentation, run:
1$ npm run docs:serve
and navigate your browser to http://localhost:8080
.
To automatically rebuild your documentation every time a file in the src
directory changes, run:
1$ npm run docs:watch
For more features, check out the compodoc website.
Publishing your library to NPM
To publish your library to NPM, first generate the dist
directory:
1$ npm run build
and then publish the contents of the dist
directory to NPM:
1$ npm publish dist
Consuming your library
Once you have published your library to the NPM registry, you can import it in any Angular application by first installing it using NPM:
1$ npm install sample-library # use the name you used to publish to npm
and then importing your library in your Angular AppModule
(or whatever module you wish to import your library into):
1import { BrowserModule } from '@angular/platform-browser'; 2import { NgModule } from '@angular/core'; 3 4import { AppComponent } from './app.component'; 5 6// Import your library 7import { SampleModule } from 'sample-library'; 8 9@NgModule({ 10 declarations: [ 11 AppComponent 12 ], 13 imports: [ 14 BrowserModule, 15 16 // Specify your library as an import 17 SampleModule.forRoot() 18 ], 19 providers: [], 20 bootstrap: [AppComponent] 21}) 22export class AppModule { }
Once your shared library is imported, you can use its components, directives and pipes in your Angular application templates:
1<!-- app.component.html --> 2<h1>{{ title }}</h1> 3<sample-component> 4 This component is part of the shared library and will now work as expected. 5</sample-component>
and if you need to access a service from your shared library, you can inject it using Dependency Injection:
1import { Component } from '@angular/core'; 2 3// Import the shared service 4import { SampleService } from 'sample-library'; 5 6@Component({ 7 template: 'Injecting a service from the shared library' 8}) 9export class HomeComponent { 10 11 // Inject the service using Angular DI 12 constructor(private sampleService: SampleService){ 13 14 } 15 16}
To learn more about Angular Dependency Injection, check out the Official Angular Documentation.
Consuming your library during development
To consume your library before you publish it to npm, you can follow the following steps:
- Create your library:
$ yo angular2-library
Let's assume you name your library sample-library
.
- Navigate to the
sample-library
directory:
$ cd sample-library
- Compile your library files:
$ npm run build
- From the
sample-library/dist
directory, create a symlink in the global node_modules directory to thedist
directory of your library:
$ cd dist
$ npm link
- Create a new Angular app. Let's assume you use angular-cli:
$ cd /your-projects-path
$ ng new my-app
- Navigate to the
my-app
directory:
$ cd my-app
- From the
my-app
directory, link the globalsample-library
directory to node_modules of themy-app
directory:
$ npm link sample-library
- Import
SampleModule
in your Angular application:
1import { BrowserModule } from '@angular/platform-browser'; 2import { NgModule } from '@angular/core'; 3 4import { AppComponent } from './app.component'; 5 6// Import your library 7import { SampleModule } from 'sample-library'; 8 9@NgModule({ 10 declarations: [ 11 AppComponent 12 ], 13 imports: [ 14 BrowserModule, 15 16 // Specify your library as an import 17 SampleModule.forRoot() 18 ], 19 providers: [], 20 bootstrap: [AppComponent] 21}) 22export class AppModule { }
- Once your shared library is imported, you can use its components, directives and pipes in your Angular application templates:
1<!-- app.component.html --> 2<h1>{{ title }}</h1> 3<sample-component> 4 This component is part of the shared library and will now work as expected. 5</sample-component>
and if you need to access a service from your shared library, you can inject it using Dependency Injection:
1import { Component } from '@angular/core'; 2 3// Import the shared service 4import { SampleService } from 'sample-library'; 5 6@Component({ 7 template: 'Injecting a service from the shared library' 8}) 9export class HomeComponent { 10 11 // Inject the service using Angular DI 12 constructor(private sampleService: SampleService){ 13 14 } 15 16}
- When you make a change to your library, recompile your library files again from your
sample-library
directory:
$ npm run build
- If you want to automatically recompile the library files when a file in
src
changes, run
$ npm run build:watch
- If you are using an Angular CLI application to consume your library, make sure to set up a path mapping in
/src/tsconfig.app.json
of your consuming application (not your library):
1{ 2 "compilerOptions": { 3 // ... 4 // Note: these paths are relative to `baseUrl` path. 5 "paths": { 6 "@angular/*": [ 7 "../node_modules/@angular/*" 8 ] 9 } 10 } 11}
Frequently asked questions
How can I configure Karma?
Currently, the generator does not create a custom Karma configuration for running unit tests.
If your library requires a custom Karma setup, please check out this tutorial on how to configure Karma for your libraray (Credits to Raphael).
As soon as official recommendations are available on how to set up Karma for testing libraries, this generator will be updated accordingly.
How can I use a scoped package name?
First update the package name in src/package.json
:
1"name": "@scope/library-name"
and then also update flatModuleId
in src/tsconfig.es5.json
accordingly:
1"flatModuleId": "@scope/library-name"
See #75 for more information.
How can I avoid recompilation during development
If you experience issues (#72) or want to avoid constant recompilation of your library during development, you can also npm link src
instead of npm link dist
in step 4 of the process above.
This will let you consume the TypeScript code directly from the src
directory of your library instead of the generated bundle from the dist
directory. This increases development speed if you are testing your library in a local Angular application, but remember to test the generated bundle using npm link dist
after you finish writing your code, to ensure that your generated bundle is working as expected before you publish your library to NPM.
How can I use .scss files?
Simply store your styles in a file with a filename extension of scss
and reference it in your component's styleUrls
property.
So if you have a sample.component.scss
:
1h1 { 2 color: red; 3}
then reference it in your component's styleUrls
in sample.component.ts
accordingly:
1@Component({ 2 selector: 'sample-component', 3 template: `<h1>Sample component</h1>`, 4 styleUrls: [ 5 'sample.component.scss' 6 ] 7})
The .scss files will automatically be compiled and inlined in your library bundle.
How can I import .scss files
To import a .scss file in an existing .scss file, you can specify a relative path:
@import '../relative/path/to/other.scss';
or use a tilde to import a file from the nearest parent node_modules
directory:
@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';
How can I update my generator to the latest version?
From the command line, run
1$ yo
and select the option Update your generators.
Issues
Please report bugs and issues here.
Development
To run the generator unit tests:
1$ npm run test
License
MIT © Jurgen Van de Moere
Change log
v11.0.2
- Fixed package.json for Jest (Credits to Fabrizio Fortunato)
v11.0.1
- Updated
styleUrls
to fix #140
v11.0.0
- Added support for Jest (Credits to Fabrizio Fortunato)
- Updated Compodoc (Credits to Artem Kuznetsov)
v10.2.2
- Avoid deletion of dist directory to prevent npm link errors (See #91) (Credits to Filipe Silva and Brenden Niedermeyer)
v10.2.1
- Allow real files in rollup to fix #105
v10.2.0
v10.1.1
- Fix README
v10.1.0
v10.0.0
- Added support for generating UMD bundle
v9.3.0
- Added support for .scss files (Credits to Thomas Deblock)
v9.2.0
- Added convenience scripts for generating documentation
v9.1.0
- Added compodoc for generating documentation (#76)
- Removed comments from TypeScript config files to allow JSON validity checks
v9.0.0
- Added Gulp for support on Mac, Linux and Windows (Credits to Carlos Roso)
- Added template inlining (Credits to Filipe Silva)
- Added style inlining (Credits to Filipe Silva)
v8.2.1
- Updated TypeScript files in gitignore
v8.2.0
- Added build:watch script
- Added dist folder to gitignore
v8.1.0
- Remove prepublish script
v8.0.0
- Update build process
- Add support for AOT compilation
v7.0.0
- Update to Angular 4
v6.0.0
- Update to Yeoman 1.x
v5.6.0
- Ignore files generated by ngc in .gitignore
v5.5.2
- Remove obsolete files in package.json
v5.5.1
- Add README.md to package.json so NPM registry can display it
v5.5.0
- Update devDependencies
v5.4.0
- Update to latest tslint and codelyzer
v5.3.0
- Update TypeScript version to fix #41
v5.2.1
- Fix eslint errors
- Remove duplicate dependency
v5.2.0
- Suggest better default library name
v5.1.0
- Add support for AOT compilation
- Update Angular 2 references to just Angular
v5.0.0
- Replace typings with @types (#29)
v4.0.0
- Remove default keyword when exporting module to fix #23
v3.0.4
- Updated version of Codelyzer
- Updated selector of sample component to kebab case to fix #21
v3.0.3
- Fixed unit tests
v3.0.2
- Fixed
README.md
example code
v3.0.1
- Fixed
tsconfig.json
files
v3.0.0
- Added support for
NgModule
v2.2.0
- Updated dependencies in package.json to Angular 2 final
v2.1.0
- Updated templates to Angular 2.0.0 RC3 syntax
v2.0.0
- Updated with file structure using
src
anddist
directory
v1.1.1
- Updated templates to Angular 2.0.0 RC1 syntax
v1.1.0
- Added codelyzer support
- Added tslint support
- Added typings support
v1.0.0
- BREAKING CHANGE: Updated to support Angular 2.0.0-rc.1
v0.6.0
- Updated dependency versions
v0.5.0
- Added
browser.d.ts
to files intsconfig.json
instead of using tripleslash (see #9)
v0.4.0
- Added reference to Angular typings
v0.3.1
- Removed explicit RxJS dependency
v0.3.0
- Updated to Angular 2 beta
v0.2.0
- Added documentation
- Added support for
PROVIDERS
,DIRECTIVES
andPIPES
v0.1.0
- Added documentation
- Added boilerplate scaffolding
- Initial version
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 12/30 approved changesets -- score normalized to 4
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 12 are checked with a SAST tool
Reason
64 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-6chw-6frg-f759
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9
- Warn: Project is vulnerable to: GHSA-phwq-j96m-2c2q
- Warn: Project is vulnerable to: GHSA-ghr5-ch3p-vcr6
- Warn: Project is vulnerable to: GHSA-4gmj-3p3h-gm8h
- Warn: Project is vulnerable to: GHSA-qrmc-fj45-qfc2
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-qh2h-chj9-jffq
- Warn: Project is vulnerable to: GHSA-q42p-pg8m-cqh6
- Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9
- Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f
- Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p
- Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv
- Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8
- Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65
- Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-44pw-h2cw-w3vq
- Warn: Project is vulnerable to: GHSA-jp4x-w63m-7wgm
- Warn: Project is vulnerable to: GHSA-c429-5p7v-vgjp
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-pc5p-h8pf-mvwp
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546
- Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-282f-qqgm-c34q
- Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm
- Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-4xcv-9jjx-gfj3
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-hxm2-r34f-qmc5
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-fhjf-83wg-r2j9
- Warn: Project is vulnerable to: GHSA-w9mr-4mfr-499f
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-4g88-fppr-53pp
- Warn: Project is vulnerable to: GHSA-4jqc-8m5r-9rpr
- Warn: Project is vulnerable to: GHSA-4rq4-32rv-6wp6
- Warn: Project is vulnerable to: GHSA-64g7-mvw6-v9qj
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-xc7v-wxcw-j472
- Warn: Project is vulnerable to: GHSA-v2p6-4mp7-3r9v
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
2.3
/10
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More