• Stars
    star
    129
  • Rank 279,262 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 7 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ”₯ Easily create Angular libraries using Schematics

Angular Library Schematics

Create Angular libraries in no time using Schematics. Think of ng generate component, but for libraries.

Features

  • Easily generate libraries from scratch or within your existing Angular project.
  • Release a build that follows Angular standards: UMD, ES5 and ES2015 bundles + typings.
  • Seemless integration with Angular CLI. Your library playground will just be your well known Angular app.
  • Test your library using karma + jasmine as you normally do in your Angular apps
  • Support for dry run
  • SASS and autoprefixer support.

Installation

  1. It's recommended to install the schematics globally because you'll likely use it to create projects from scratch where no node_modules is yet available.
npm i -g ng-lib-schematics
  1. Make sure you have the Angular DevKit dependencies to run the schematics:
npm i -g @angular-devkit/core @angular-devkit/schematics-cli

Basic Usage

This schematic will generate the library inside of an existing Angular project. If you already have a project in which you want to include your library then you can skip step 1.

  1. Create an Angular project using the CLI. It's recommendable to skip install now to run npm i only once at step 3.
ng new <library-name> --skip-install
  1. cd into your new project and run the schematics inside:
schematics ng-lib-schematics:lib-standalone --name <library-name>
  1. Install dependencies
npm i
  1. Import your library module inside app.module.ts. Your library is now just another module of your app:
import { SampleModule } from '../lib';
...
imports: [ BrowserModule, SampleModule ]
  1. Start using it! Go to your app.component.html and add the sample component:<sample-component></sample-component>. It should render this:
sample component rendering

Note: Make sure you run the schematics in dry run mode first to know upfront what this thing will do to your project. Once you get comfortable with all the changes you can run the schematics again without dry run. To dry run the schematic simply append the --dry-run flag to the command in step 2.

Building and publishing your library

  1. npm run build:lib
  2. cd dist
  3. npm publish

Important:

  1. If you already have an npm script named build:lib in your project, then you'll have to manually run gulp --gulpfile gulpfile.lib.js to build the library.
  2. TODO sync version

Generated files

It's important that you know what this schematic will do and how your project will look like after applying it:

  1. The library will live inside src/lib.
  2. All your components, services, directives, etc will live inside the folder src/lib/src. You can safely change the names of the existing files inside this folder and go nuts building your library.
  3. The build script will live inside src/lib/build-tools along with all the build utils.
  4. A file gulpfile.lib.js will be created at the root of the project. It will simple import the main gulpfile located at src/lib/src/build-tools/gulpfile.js.
  5. New dependencies will be added to your devDependencies. These are needed to build your library at the release stage.
  6. Two npm scripts will be added to thet scripts object inside your main package.json file: a. "build:lib": "gulp --gulpfile gulpfile.lib.js": Script to build the release artifacts of your library. b. "version": "sync-json -v --property version --source package.json src/lib/package.json": Version hook to sync versions between your root package.json and src/lib/package.json. This will allow you to run npm version <type> at the root of your project and still have your library version up to date.

Contributing

Thanks for even thinking about contributing. Open up issues or PRs and we'll discuss about it.

Testing your schematics build

  1. Fork the project
  2. Install dependencies npm i
  3. Run npm run watch. This will output the schematic package to dist and watch for changes.
  4. cd into dist and run npm link. At this point, ng-lib-schematics is symlinked to your global node_modules.
  5. Create a dummy Angular project ng new lib-test
  6. You can now run schematics ng-lib-schematics:lib-standalone --name <library-name>

Hall of fame

Find below some of the libraries built on top of these schematics:

Credits

I took a bunch of ideas from the Yeoman's Angular library generator by Jurgen Van de Moere. Feel free to use whatever works best for you, both Schematics and Yeoman will get you to the same exact point.

Licence

MIT

More Repositories

1

notyf

πŸ‘» A minimalistic, responsive, vanilla JavaScript library to show toast notifications.
JavaScript
2,607
star
2

amazon-autocomplete

πŸš€ Unlock the full power of the Amazon autocompletion engine right into your search input. JavaScript Plugin.
JavaScript
399
star
3

ng-popups

πŸŽ‰ Alert, confirm and prompt dialogs for Angular. Simple as that.
TypeScript
83
star
4

angular2-shop

πŸ’ A fancy, minimal, responsive shop made on Angular 2
TypeScript
71
star
5

wapy

πŸ€– A fully featured, easy to use Python wrapper for the Walmart Open API
Python
43
star
6

node-reminders

🐝A NodeJS and TypeScript wrapper for macOS Reminders
TypeScript
40
star
7

ast-viewer

πŸ•ΊTypeScript AST Viewer
TypeScript
38
star
8

rmind

🎩 A minimalist CLI for the macOS Reminders app
TypeScript
30
star
9

awesome-deepracer

A curated list of resources for the AWS DeepRacer League 🏎
15
star
10

node-dotconfig

🧩 Easily create and read config files from the user's home directory.
CSS
8
star
11

dribbble-autozoom-chrome-ext

Google Chrome extension for automagically zooming any Dribbble shot
JavaScript
5
star
12

rxjs-pausable

πŸš‚RxJS pipeable operator to pause and resume streams
TypeScript
4
star
13

100dayui-htmls

This is a repo for functional implementations of some of the Paul Flavius' 100 day UI challenge designs.
CSS
2
star
14

instagram-logo

A not so clean attempt to implement the new Instagram logo with plain html and css
CSS
2
star
15

tripper

TypeScript
1
star
16

MifareClassicReader

Android App to read a Mifare Classic 1k.
Java
1
star
17

tslint-playground

TSLint Playground
TypeScript
1
star
18

capp-america

Facebook bot for pushing notifications about Copa America Centenario 2016
JavaScript
1
star
19

mibank-ionic

MiBank Ionic App
JavaScript
1
star
20

ng-schematics-utils

A comprehensive set of utilities to build Angular schematics.
TypeScript
1
star
21

deliverit

https://deliverit-7dd9f.firebaseapp.com/
TypeScript
1
star