Skip to content

Commit

Permalink
v5.0.0:
Browse files Browse the repository at this point in the history
- rework all build process
- angular 5
  • Loading branch information
Noémi Salaün committed Nov 3, 2017
1 parent 41449a3 commit 5d7db0e
Show file tree
Hide file tree
Showing 27 changed files with 3,566 additions and 990 deletions.
20 changes: 5 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
.idea/

/node_modules/
/npm-debug.log

/src/*.js
/src/*.js.map
/src/*.d.ts
/test/*.js
/test/*.js.map
/test/*.d.ts
/index.js
/index.js.map
/index.d.ts
*.metadata.json
*.ngfactory.ts

/bundles/
/dist/
/documentation/
/coverage/

*.log
*.tgz
22 changes: 0 additions & 22 deletions .npmignore

This file was deleted.

23 changes: 17 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
sudo: required
dist: trusty
addons:
apt:
sources:
- google-chrome
packages:
- google-chrome-stable
language: node_js
node_js:
- "6"
- "5"
- "4"
- "8"
before_install:
- export CHROME_BIN=chromium-browser
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- npm i npm@^4 -g
install:
- npm install
script:
- npm test
- npm run build
before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- sleep 3
notifications:
email: false
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 5.0.0 (Angular v5.0.0) (2017-11-03)
* Because of the incompatibility with the previous version, the versioning now follow major Angular version.
* Change all the build process. It's now based on [robisim74/angular-library-starter](https://github.com/robisim74/angular-library-starter).
* Update compatibility for **Angular 5**.

# 2.0.2 (2017-10-26)
* Replace deprecated `OpaqueToken` by `InjectionToken` (issue [#11](https://github.com/noemi-salaun/ng-logger/issues/11)).

Expand Down
68 changes: 35 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
- A log level system to be able to disable certain calls as needed. *We do not want to see our debug trace on production.*
- A logger that keeps trace of the original log call. *We do not want all our logs to be referenced in some `logger.service.js` all the time.*

This package is compatible with [Angular AoT compiler](https://angular.io/docs/ts/latest/cookbook/aot-compiler.html) and can be bundle with [RollupJS](http://rollupjs.org/).
This package is compatible with **Angular 5**, [Angular AoT compiler](https://angular.io/docs/ts/latest/cookbook/aot-compiler.html) and [Angular CLI](https://cli.angular.io/).

## Installation

1. Install the npm package.
### 1 - Install the npm package.

```
```shell
npm install --save @nsalaun/ng-logger
```
2. Import `NgLoggerModule` in your application and use `forRoot(level: Level)` to choose your log level :
### 2 - Import `NgLoggerModule` in your application and use `forRoot(level: Level)` to choose your log level :

```typescript
import { NgModule } from '@angular/core';
Expand All @@ -37,35 +37,37 @@ This package is compatible with [Angular AoT compiler](https://angular.io/docs/t
export class AppModule { }
```

3. Tells your application how to load `ng-logger`.
* Like Angular modules
* All the compiled JS use ES2015 module format. *You cannot use them with SystemJS.*
* UMD bundles are available for SystemJS loading.
* With SystemJS, it can look like :
```javascript
System.config({
paths: {
'npm:': 'node_modules/'
},
map: {
app: 'app',
'@angular/core' : 'npm:@angular/core/bundles/core.umd.js',
'@angular/common' : 'npm:@angular/common/bundles/common.umd.js',
// others angular bundles...
'@nsalaun/ng-logger': 'npm:@nsalaun/ng-logger/bundles/ng-logger.umd.js',
rxjs: 'npm:rxjs',
},
packages: {
app : {defaultExtension: 'js', main: './main.js'},
rxjs: {defaultExtension: 'js'}
}
});
```
* With AoT compilation, you don't have to do anything, `.metadata.json` files are here for you.
* With RollupJS, you don't have to do anything either, JS files use ES2015 module.
### 3 - Loading

#### Using SystemJS configuration

```JavaScript
System.config({
map: {
'my-library': 'node_modules/my-library/bundles/my-library.umd.js'
}
});
```

#### Angular-CLI

No need to set up anything, just import it in your code.

#### Rollup or webpack

No need to set up anything, just import it in your code.

#### Plain JavaScript

Include the `umd` bundle in your `index.html`:
```Html
<script src="node_modules/my-library/bundles/my-library.umd.js"></script>
```
and use global `ng.myLibrary` namespace.

### AoT compilation
The library is compatible with _AoT compilation_.
Because of the new metadata version with Angular 5, the library is not compatible with previous Angular version.

## Usage

Expand Down
73 changes: 73 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"use strict";

const shell = require('shelljs');
const chalk = require('chalk');

const PACKAGE = `ng-logger`;
const NPM_DIR = `dist`;
const ESM2015_DIR = `${NPM_DIR}/esm2015`;
const ESM5_DIR = `${NPM_DIR}/esm5`;
const BUNDLES_DIR = `${NPM_DIR}/bundles`;
const OUT_DIR_ESM5 = `${NPM_DIR}/package/esm5`;

shell.echo(`Start building...`);

shell.rm(`-Rf`, `${NPM_DIR}/*`);
shell.mkdir(`-p`, `./${ESM2015_DIR}`);
shell.mkdir(`-p`, `./${ESM5_DIR}`);
shell.mkdir(`-p`, `./${BUNDLES_DIR}`);

/* TSLint with Codelyzer */
// https://github.com/palantir/tslint/blob/master/src/configs/recommended.ts
// https://github.com/mgechev/codelyzer
shell.echo(`Start TSLint`);
shell.exec(`tslint -p . -c tslint.json -t stylish src/**/*.ts`);
shell.echo(chalk.green(`TSLint completed`));

/* AoT compilation */
shell.echo(`Start AoT compilation`);
if (shell.exec(`ngc -p tsconfig-build.json`).code !== 0) {
shell.echo(chalk.red(`Error: AoT compilation failed`));
shell.exit(1);
}
shell.echo(chalk.green(`AoT compilation completed`));

/* BUNDLING PACKAGE */
shell.echo(`Start bundling`);
shell.echo(`Rollup package`);
if (shell.exec(`rollup -c rollup.es.config.js -i ${NPM_DIR}/${PACKAGE}.js -o ${ESM2015_DIR}/${PACKAGE}.js`).code !== 0) {
shell.echo(chalk.red(`Error: Rollup package failed`));
shell.exit(1);
}

shell.echo(`Produce ESM5 version`);
shell.exec(`ngc -p tsconfig-build.json --target es5 -d false --outDir ${OUT_DIR_ESM5} --importHelpers true --sourceMap`);
if (shell.exec(`rollup -c rollup.es.config.js -i ${OUT_DIR_ESM5}/${PACKAGE}.js -o ${ESM5_DIR}/${PACKAGE}.js`).code !== 0) {
shell.echo(chalk.red(`Error: ESM5 version failed`));
shell.exit(1);
}

shell.echo(`Run Rollup conversion on package`);
if (shell.exec(`rollup -c rollup.config.js -i ${ESM5_DIR}/${PACKAGE}.js -o ${BUNDLES_DIR}/${PACKAGE}.umd.js`).code !== 0) {
shell.echo(chalk.red(`Error: Rollup conversion failed`));
shell.exit(1);
}

shell.echo(`Minifying`);
shell.cd(`${BUNDLES_DIR}`);
shell.exec(`uglifyjs ${PACKAGE}.umd.js -c --comments -o ${PACKAGE}.umd.min.js --source-map "filename='${PACKAGE}.umd.min.js.map', includeSources"`);
shell.cd(`..`);
shell.cd(`..`);

shell.echo(chalk.green(`Bundling completed`));

shell.rm(`-Rf`, `${NPM_DIR}/package`);
shell.rm(`-Rf`, `${NPM_DIR}/node_modules`);
shell.rm(`-Rf`, `${NPM_DIR}/*.js`);
shell.rm(`-Rf`, `${NPM_DIR}/*.js.map`);
shell.rm(`-Rf`, `${NPM_DIR}/src/**/*.js`);
shell.rm(`-Rf`, `${NPM_DIR}/src/**/*.js.map`);

shell.cp(`-Rf`, [`package.json`, `LICENSE`, `README.md`], `${NPM_DIR}`);

shell.echo(chalk.green(`End building`));
74 changes: 0 additions & 74 deletions karma-test-shim.js

This file was deleted.

Loading

0 comments on commit 5d7db0e

Please sign in to comment.