| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Feel free to keep using Angular Librarian, though, but it will receive few, if any, more updates. Thanks to everyone who helped in its development and utilized it!
An Angular 2+ scaffolding setup. Generates AOT-compliant code using similar paradigms to the Angular CLI.
The ngl command does not install globally by default. To get it working there are some additional steps. To learn how to install it on your system, take a look at CLI.md.
If you do not want to use the ngl command, please see the commands in "Generative Commands" and "Project Commands" for the alternative usage.
Create a new folder and initialize an NPM project:
> mkdir my-lib
> cd my-lib
> npm init -fInstall this package to your project:
> npm i -D angular-librarianThe following command (ngl) is not available out of the box. To set it up, see "To Use the ngl Command".
Then initialize your project:
> ngl i
Library name: my-lib
README Title: My Library
Repository URL: https://github.com/me/my-lib
Reinitialize Git project (y/N)?
Installing Node modules
...NPM install occurs
Node modules installedGenerative commands create files for different parts of your library. There are multiple ways to execute commands:
ngl <command_name> [<args>]or
npm run g <command_name> [<args>]or
node ./node_modules/angular-librarian <command_name> [<args>]The ngl command-line tool and npm run g are both aliases for calling node ./node_modules/angular-librarian. Note that all arguments are optional.
| Command | Purpose |
|---|---|
| initial | Sets up the project |
| component | Creates a component |
| directive | Creates a directive |
| pipe | Creates a pipe |
| service | Creates a service |
Sets up the project. Can also be run to update a project to the latest Angular Librarian configuration.
ngl i <options>
ngl init <options>
ngl initialize <options>
npm run g i <options>
npm run g init <options>
npm run g initialize <options>Creates the project structure and a slew of files:
|__examples/ |__example.component.html |__example.component.ts |__example.main.ts |__example.module.ts |__index.html |__node_modules/ |__... |__src/ |__<library name>.module.ts |__index.ts |__test.ts |__webpack/ |__webpack.dev.js |__webpack.test.js |__.gitignore |__.npmignore |__index.ts |__karma.conf.js |__package.json |__README.md |__tsconfig.json |__tsconfig.doc.json |__tsconfig.es5.json |__tsconfig.es2015.json |__tsconfig.test.json |__tslint.json
Generates a component
ngl c <options>
ngl component <selector> <options>
npm run g c <options>
npm run g component <selector> <options>In the src directory, a sub-directory will be created with the selector name and a component.ts, component.spec.ts, and, if necessary, component.html and component.scss files.
|__src
|__<selector>
|__<selector>.component.html
|__<selector>.component.scss
|__<selector>.component.spec.ts
|__<selector>.component.tsGenerates a directive
ngl d <options>
ngl directive <directive-name> <options>
npm run g d <options>
npm run g directive <directive-name> <options>In the src directory, under a directives sub-directory, two files will be added for a service--a directive.ts and directive.spec.ts file.
|__src
|__directives
|__<directive-name>.directive.spec.ts
|__<directive-name>.directive.tsGenerates a service
ngl s <options>
ngl service <service-name> <options>
npm run g s <options>
npm run g service <service-name> <options>In the src directory, under a services sub-directory, two files will be added for a service--a service.ts and service.spec.ts file.
|__src
|__services
|__<service-name>.service.spec.ts
|__<service-name>.service.tsGenerates a pipe
ngl p <options>
ngl p <pipe-name> <options>
npm run g p <options>
npm run g p <pipe-name> <options>In the src directory, under a pipes sub-directory, two files will be added for a service--a pipe.ts and pipe.spec.ts file.
|__src
|__pipes
|__<pipe-name>.pipe.spec.ts
|__<pipe-name>.pipe.tsThere are commands provided out of the box, as NPM scripts. They are:
| Command | Purpose |
|---|---|
| build | Runs code through build process via Angular compiler (ngc) |
| lint | Verify code matches linting rules |
| publish | Creates tag for new version and publishes |
| serve | Run Webpack's dev-server on project |
| test | Execute unit tests |
| upgrade | Upgrade current project to latest Angular Librarian |
Build the library's code. This will run the code through the ngc compiler and compile the code for distribution.
ngl build
ngl b
npm run buildLint code through TSLint
ngl lint
ngl l
npm run lintCreate a tag and publish the library code using the np library. Optionally, arguments can be passe to make the build work faster.
Note: only use the optional arguments if you are 100% confident your code works with the current dependencies & passes all tests!
Important! To use Librarian's publishing capabilities, you need to have np installed globally. This is required because Angular & np require separate versions of RxJS. Using the Angular-required version of RxJS will break np and using np's will raise a peerDependency warning.
You can install np by running the following command:
npm install -g np
ngl publish <option>
ngl pub <option>
npm run tagVersion <option>Start the webpack dev server and run the library code through it.
ngl serve
ngl v
npm startWe use start for direct npm commands to keep the command as concise as possible.
Run unit tests on code. For unit test types, see the unit testing section below.
ngl test <type>
ngl t <type>
npm test <type>
Upgrades the current project to the latest Angular Librarian (if necessary) and update managed files to the latest versions.
Managed files are:
Any files with a asterisk (*) next to their name have a merge strategy associated with them:
ngl upgrade
ngl up
ngl u
npm run g upgrade
npm run g up
npm run g uUnit testing is done using Karma and Webpack. The setup is all done during the initialize command. The provided testing commands will watch your files for changes.
The following commands are described in the test command section.
These commands call the script at tasks/test.js and runs the Karma test runner to execute the tests. Prior to running Karma, the test command looks for a command line argument, if the argument is known, it will run the associated configuration, otherwise it will run the default configuration.
Configurations:
| Command | Testing TypeScript |
|---|---|
| default | Run through PhantomJS one time with no file watching |
| headless (aliases: hl, h) | Run through PhantomJS with files being watched & tests automatically re-run |
| watch (alias: w) | Run through Chrome with files being watched & tests automatically re-run |
Note that Chrome still requires a manual refresh on the Debug tab to see updated test results.
Some configurations can be extended with custom properties. These configurations should be placed in a configs directory under the project's root directory with the corresponding name:
A custom Karma configuration should be a Node module that exports a function. The exported function will be relay the Karma config variable. If provided, any supported attributes provided will be merged.
Those attributes and their merge strategies are:
The rollup configuration will append the provided attributes to create a new attribute of unique values. The attributes supported:
Note: there is no file provided named rollup.config.js like other configuration files--instead the configuration is maintained in tasks/rollup.js.
Either of the Webpack configurations can be extended by providing a file with a matching name in configs. The configuration is applied using the webpack-merge library.
To test your packages output before publishing, run the following commands:
ngl build
cd dist
npm packThese commands will build the output files into a dist directory, change into the dist directory, and generate a compressed file containing your library as it will look when packaged up and published to NPM. The packaging process removes any files specific to developing your library, such as *.spec.ts files and .npmignore.
The basic structure of a published, unscoped library is:
|__bundles/ |__<library name>.umd.js |__<library name>.umd.js.map |__<library name>.umd.min.js |__<library name>.bundle.min.js.map |__index.d.ts |__package.json |__README.md |__*.d.ts |__<library name>.d.ts |__<library name>.es5.js |__<library name>.es5.js.map |__<library name>.js |__<library name>.js.map |__<library name>.metadata.json |__<library name>.module.d.ts
For a scoped package, the structure will appear slightly different:
|__@<scope name>/ |__<library name>.es5.js |__<library name>.es5.js.map |__<library name>.js |__<library name>.js.map |__bundles/ |__<library name>.umd.js |__<library name>.umd.js.map |__<library name>.umd.min.js |__<library name>.bundle.min.js.map |__index.d.ts |__package.json |__README.md |__*.d.ts |__<library name>.d.ts |__<library name>.metadata.json |__<library name>.module.d.ts
If you'd like to contribute to Angular Librarian, please see the contributing guide!
| Back | FazBrowse Home | New Git URL |