From 146608b027692302583482f59f5b7d132c67b445 Mon Sep 17 00:00:00 2001 From: Devin Date: Fri, 9 Sep 2016 21:40:07 -0600 Subject: [PATCH 1/4] Angular cli compatibility (#1) * ignore VS Code workspace settings * refactored compile (tsconfig, src/) * fix(build) refactored build scripts & typings * finished build refactoring, verified on other proj * cleared TODO item * removed donation link for now --- .gitignore | 26 ++++++-------- .npmignore | 3 -- README.md | 38 +++++++++++--------- core.d.ts | 48 -------------------------- core.ts | 8 ----- docs/dev/CHANGES.md | 35 +++++++++++++++++++ package.json | 33 +++++++++--------- src/core.ts | 6 ++++ src/index.ts | 6 ++++ src/modules/core/index.ts | 8 +++++ {app => src/modules}/core/level.ts | 0 {app => src/modules}/core/logger.ts | 0 {app => src/modules}/core/providers.ts | 0 tsconfig-es6.json => src/tsconfig.json | 18 +++++----- src/typings.d.ts | 6 ++++ tsconfig-amd.json | 28 --------------- tsconfig-es2015.json | 23 ------------ tsconfig-es5.json | 26 -------------- tsconfig-sys.json | 27 --------------- tsconfig.json | 26 -------------- typings.json | 1 - 21 files changed, 119 insertions(+), 247 deletions(-) delete mode 100644 core.d.ts delete mode 100644 core.ts create mode 100644 docs/dev/CHANGES.md create mode 100644 src/core.ts create mode 100644 src/index.ts create mode 100644 src/modules/core/index.ts rename {app => src/modules}/core/level.ts (100%) rename {app => src/modules}/core/logger.ts (100%) rename {app => src/modules}/core/providers.ts (100%) rename tsconfig-es6.json => src/tsconfig.json (69%) create mode 100644 src/typings.d.ts delete mode 100644 tsconfig-amd.json delete mode 100644 tsconfig-es2015.json delete mode 100644 tsconfig-es5.json delete mode 100644 tsconfig-sys.json delete mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore index 4e572ea..c2acba0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ - -npm-debug.log* - # Dependency directory node_modules typings @@ -11,19 +8,18 @@ typings # Optional REPL history .node_repl_history +# output/generated dist bundles +npm-debug.log* +**/*.js +**/*.js.map +**/*.d.ts -/*.js -/*.js.map -#/*.d.ts - -app/**/*.js -app/**/*.js.map -app/**/*.d.ts - -demos/*/app/**/*.js -demos/*/app/**/*.map -demos/*/app/**/*.d.ts +# Workspace Settings +.idea/workspace.xml +.vscode -.idea/workspace.xml \ No newline at end of file +# DO NOT ignore (must come last) +!demos/*/systemjs.config.js +!src/typings.d.ts diff --git a/.npmignore b/.npmignore index fe8de05..c228b42 100644 --- a/.npmignore +++ b/.npmignore @@ -22,6 +22,3 @@ tsconfig.json typings.json .travis.yml - -#TODO: Modify build process so it doesn't need this file at all. -core.ts \ No newline at end of file diff --git a/README.md b/README.md index 6474fe8..fda9b83 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,14 @@ +# [Summary of Changes](https://github.com/TheFirstDeity/angular2-logger/blob/master/docs/dev/CHANGES.md) +https://github.com/TheFirstDeity/angular2-logger/blob/master/docs/dev/CHANGES.md + +--- + # Angular2-Logger [![Build Status](https://travis-ci.org/code-chunks/angular2-logger.svg?branch=master)](https://travis-ci.org/code-chunks/angular2-logger) [![npm version](https://badge.fury.io/js/angular2-logger.svg)](https://badge.fury.io/js/angular2-logger) [![Join the chat at https://gitter.im/code-chunks/angular2-logger](https://badges.gitter.im/code-chunks/angular2-logger.svg)](https://gitter.im/code-chunks/angular2-logger?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/code-chunks/angular2-logger/master/LICENSE) -[![Support](https://supporter.60devs.com/api/b/cjv93jwfwck3yp8z2mn1d9gay)](https://supporter.60devs.com/give/cjv93jwfwck3yp8z2mn1d9gay) ## What is it? @@ -17,13 +21,13 @@ This is a work in progress and is not ready for production, use with care, the A ### Quickstart 1. Install the npm module. - + npm install --save angular2-logger 2. Add the `angular2-logger` library to your app. If you are following the [Angular 2's Quickstart Guide](https://angular.io/docs/ts/latest/quickstart.html) it should be something like this: In `systemjs.config.js`: - + // map tells the System loader where to look for things var map = { 'app': 'app', // 'dist', @@ -32,7 +36,7 @@ This is a work in progress and is not ready for production, use with care, the A 'rxjs': 'node_modules/rxjs', 'angular2-logger': 'node_modules/angular2-logger' // ADD THIS }; - + //packages tells the System loader how to load when no filename and/or no extension var packages = { 'app': { main: 'main.ts', defaultExtension: 'ts' }, @@ -43,14 +47,14 @@ This is a work in progress and is not ready for production, use with care, the A 3. Setup the Provider. - + In `app.module.ts`: import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppComponent } from './app.component'; import { Logger } from "angular2-logger/core"; // ADD THIS - + @NgModule({ imports: [ BrowserModule ], declarations: [ AppComponent ], @@ -73,8 +77,8 @@ This is a work in progress and is not ready for production, use with care, the A this._logger.log('This is a priority level 5 log message...'); } } - -By default the logger level will be set to `Level.WARN`, so you'll only see Warning and Error messages. + +By default the logger level will be set to `Level.WARN`, so you'll only see Warning and Error messages. ### Going deeper... @@ -82,12 +86,12 @@ In order to see all of the messages you just need to change the logger message h - Dynamically using the console: - logger.level = logger.Level.LOG; // same as: logger.level = 5; - + logger.level = logger.Level.LOG; // same as: logger.level = 5; + - Or using one of the predefined configuration providers: import {LOG_LOGGER_PROVIDERS} from "angular2-logger/core"; - + @NgModule({ ... providers: [ LOG_LOGGER_PROVIDERS ] @@ -116,7 +120,7 @@ If the Providers included don't meet your needs you can configure the default lo @NgModule({ ... - providers: [ + providers: [ { provide: Options, useValue: { store: false } }, Logger ] @@ -163,19 +167,19 @@ You can also override the default configuration options by extending the Options ... @NgModule({ ... - providers: [ + providers: [ { provide: Options, useClass: CustomLoggerOptions }, Logger ] }) - + Class names like `Options` and `Level` might be too common, if you get a conflict you can rename them like this: import { Logger, Options as LoggerOptions, Level as LoggerLevel } from "angular2-logger/core"; @NgModule({ ... - providers: [ + providers: [ { provide: LoggerOptions, useValue: { level: LoggerLevel.WARN } } ] }) @@ -212,8 +216,8 @@ Done. The codebase was updated to handle the breaking changes on Angular2's Release Candidate 5. **Make sure you don't upgrade to this version if you haven't upgraded Angular2 to at least `2.0.0-rc.5`** -- Quickstart guide now follows the pattern in Angular 2's Quickstart to add the references to other libs in `systemjs.config.js`. -However if you still want to do it the old way by adding the system bundle, you can still do so, except now its called `bundles/angular2-logger.sys.min.js`. +- Quickstart guide now follows the pattern in Angular 2's Quickstart to add the references to other libs in `systemjs.config.js`. +However if you still want to do it the old way by adding the system bundle, you can still do so, except now its called `bundles/angular2-logger.sys.min.js`. ## Breaking changes on 0.3.0 The codebase was updated to handle the breaking changes on Angular2's Release Candidate. diff --git a/core.d.ts b/core.d.ts deleted file mode 100644 index 951331e..0000000 --- a/core.d.ts +++ /dev/null @@ -1,48 +0,0 @@ -export enum Level { - OFF = 0, - ERROR = 1, - WARN = 2, - INFO = 3, - DEBUG = 4, - LOG = 5, -} - -export class Options { - level: Level; - global: boolean; - globalAs: string; - store: boolean; - storeAs: string; -} - -export class Logger { - private _level; - private _globalAs; - private _store; - private _storeAs; - Level: any; - constructor(options?: Options); - private _loadLevel; - private _storeLevel(level); - error(message?: any, ...optionalParams: any[]): void; - warn(message?: any, ...optionalParams: any[]): void; - info(message?: any, ...optionalParams: any[]): void; - debug(message?: any, ...optionalParams: any[]): void; - log(message?: any, ...optionalParams: any[]): void; - global: () => this; - store(): Logger; - unstore(): Logger; - isErrorEnabled: () => boolean; - isWarnEnabled: () => boolean; - isInfoEnabled: () => boolean; - isDebugEnabled: () => boolean; - isLogEnabled: () => boolean; - level: Level; -} - -export const OFF_LOGGER_PROVIDERS: any[]; -export const ERROR_LOGGER_PROVIDERS: any[]; -export const WARN_LOGGER_PROVIDERS: any[]; -export const INFO_LOGGER_PROVIDERS: any[]; -export const DEBUG_LOGGER_PROVIDERS: any[]; -export const LOG_LOGGER_PROVIDERS: any[]; \ No newline at end of file diff --git a/core.ts b/core.ts deleted file mode 100644 index 205cb85..0000000 --- a/core.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * @module - * @description - * Public API. - */ -export * from "./app/core/level"; -export * from "./app/core/logger"; -export * from "./app/core/providers"; \ No newline at end of file diff --git a/docs/dev/CHANGES.md b/docs/dev/CHANGES.md new file mode 100644 index 0000000..ae7304e --- /dev/null +++ b/docs/dev/CHANGES.md @@ -0,0 +1,35 @@ +# Status + +#### **Requirements** +- [ ] Tested with both es5 & es6 project +- [ ] Demos, make them to play +- [ ] Satisfied with the file/directory structure +- [ ] All files have cool little headings and stuff + +#### **Experiments** +- [ ] Update angular dep to `rc6` +- [ ] Update Typescript dep +- [ ] Refactor for ts2 features + +# Changes + +## **0.4.666** +- #### **Directories & Modules** + - renamed `app` to `src` since this is more of a library + - added `src/modules` to contain sub-packages in a way that works well with node module resolution. For example, `angular2-logger/subset` will elegantly point to whatever's exported by `src/modules/subset/index.ts`. (Just copy how I set up `core`'s files and make a `src/subset.ts`.) + - **Feature:** Bundlers like Webpack may automatically pick the proper es5 or es6 `js` depending on their target configuration. Works with the `angular-cli`. + - **Feature:** `src/index.ts` can be used to customize what can be imported from `angular2-logger`. It could be used as an alias for `angular2-logger/core`, or it could be like the greatest-hits from a bunch of little sub-packages. + - **Query:** _Is it even worth it to have sub-packages like 'core' and whatever else? I feel like it might just be a bunch of extra typing & memorization for consumers of the api. Since `rc5`, we have NgModules to package sets of resources together._ +- #### **package.json** + - `"main"` points at the es5 entry point, which is the umd `index.js` right now (TODO: point at bundle) + - `"module"` points at the es6 entry point, overriding `main`. This behavior has been adopted for es6 compatible builds using Webpack (`angular-cli` uses it.) + - `"typings"` points to the `.d.ts` entry point. + - `"compile"` tasks now pass configuration to the compiler to avoid duplicate `tsconfig.json` files + - `"clean"` now uses `del-cli` for safer deletes with simpler glob patterns +- #### **typings.json** + - `src/typings.d.ts` added to reference global types and `core-js` was removed from `typings.json`. Instead, the `es6` default lib is forced for all modules. This is done by setting `noLib` in `tsconfig.json` to stop the default lib from loading, and then explicitely referencing the es6 default (`lib.es6.d.ts`) in `typings.d.ts`. Typescript 2.0.0+ lets you do this out of the box, but this hack is needed for older versions +- #### **Miscellanious** + - Organized `.gitignore` entries + +## **0.4.5** +... diff --git a/package.json b/package.json index 6b79ef1..985f5fa 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,15 @@ { "name": "angular2-logger", - "version": "0.4.5", + "version": "0.4.666", "description": "A Log4j inspired Logger for Angular 2.", "repository": { "type": "git", "url": "git+https://github.com/code-chunks/angular2-logger" }, + "main": "es5/index.js", + "module": "index.js", + "typings": "index.d.ts", + "scripts": { "tsc": "tsc", "typings": "typings", @@ -13,14 +17,12 @@ "tslint": "tslint *.ts src/**/*.ts", "lint": "npm run tslint", "prepublish": "npm run build", - "clean": "rimraf *.js *.map app/**/*.js app/**/*.map app/**/*.d.ts demos/*/app**/*.js demos/*/app/*.map demos/*/app/*.d.ts dist bundles", + "clean": "del-cli modules/ bundles/ es5/ **/*{.js,.map,.d.ts} !src/typings.d.ts !demos/*/systemjs.config.js !{node_modules,typings}/** ", "precompile": "typings install", - "compile": "npm run compile:es5 && npm run compile:sys && npm run compile:es6", - "compile:amd": "tsc -p tsconfig-amd.json", - "compile:sys": "tsc -p tsconfig-sys.json", - "compile:es5": "tsc -p tsconfig-es5.json", - "compile:es6": "tsc -p tsconfig-es6.json", - "compile:es2015": "tsc -p tsconfig-es2015.json", + "compile": "npm run compile:es6 && npm run compile:umd && npm run compile:sys", + "compile:es6": "tsc -p src/tsconfig.json --declaration", + "compile:umd": "tsc -p src/tsconfig.json -m umd -t es5 --outDir es5", + "compile:sys": "tsc -p src/tsconfig.json -m system -t es5 --outFile bundles/angular2-logger.sys.js", "pretest": "npm run lint", "test": "echo tests pending...", "prebuild": "npm run clean && npm run compile && npm run test", @@ -71,20 +73,20 @@ "homepage": "https://github.com/code-chunks/angular2-logger#readme", "dependencies": {}, "devDependencies": { - "rimraf": "^2.5.2", - "tslint": "^3.8.1", - "typescript": "1.8.10", - "typings": "^1.0.3", - "uglify-js": "^2.6.2", "@angular/common": "2.0.0-rc.5", "@angular/compiler": "2.0.0-rc.5", "@angular/core": "2.0.0-rc.5", "@angular/platform-browser": "2.0.0-rc.5", "@angular/platform-browser-dynamic": "2.0.0-rc.5", - "systemjs": "0.19.37", "core-js": "^2.4.0", + "del-cli": "0.2.0", "reflect-metadata": "^0.1.3", "rxjs": "5.0.0-beta.6", + "systemjs": "0.19.37", + "tslint": "^3.8.1", + "typescript": "1.8.10", + "typings": "^1.0.3", + "uglify-js": "^2.6.2", "zone.js": "^0.6.12" }, "peerDependencies": { @@ -93,6 +95,5 @@ "@angular/core": "2.0.0-rc.5", "@angular/platform-browser": "2.0.0-rc.5", "@angular/platform-browser-dynamic": "2.0.0-rc.5" - }, - "main": "core.js" + } } diff --git a/src/core.ts b/src/core.ts new file mode 100644 index 0000000..7f23605 --- /dev/null +++ b/src/core.ts @@ -0,0 +1,6 @@ +/** + * @module + * @description + * Entry point for all public APIs of the core bundle. + */ +export * from './modules/core/'; diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..8d6c6b6 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,6 @@ +/** + * @module + * @description + * Main entry point that doesn't currently export anything. Use 'angular2-logger/core'. + */ +export let message: string = 'should probably export cool stuff like NgModules'; diff --git a/src/modules/core/index.ts b/src/modules/core/index.ts new file mode 100644 index 0000000..fd97fb3 --- /dev/null +++ b/src/modules/core/index.ts @@ -0,0 +1,8 @@ +/** + * @module + * @description + * Public API. + */ +export * from "./level"; +export * from "./logger"; +export * from "./providers"; diff --git a/app/core/level.ts b/src/modules/core/level.ts similarity index 100% rename from app/core/level.ts rename to src/modules/core/level.ts diff --git a/app/core/logger.ts b/src/modules/core/logger.ts similarity index 100% rename from app/core/logger.ts rename to src/modules/core/logger.ts diff --git a/app/core/providers.ts b/src/modules/core/providers.ts similarity index 100% rename from app/core/providers.ts rename to src/modules/core/providers.ts diff --git a/tsconfig-es6.json b/src/tsconfig.json similarity index 69% rename from tsconfig-es6.json rename to src/tsconfig.json index f927379..3a39838 100644 --- a/tsconfig-es6.json +++ b/src/tsconfig.json @@ -1,18 +1,18 @@ { "compilerOptions": { - "emitDecoratorMetadata": true, + "sourceMap": true, "experimentalDecorators": true, + "emitDecoratorMetadata": true, "removeComments": true, + + "noLib": true, + "target": "es6", + "module": "es2015", "moduleResolution": "node", - "outDir": "./dist/es6", - "rootDir": ".", - "sourceMap": true, - "target": "es6" + "outDir": "../", + "rootDir": "." }, - "files": [ - "core.ts" - ], "angularCompilerOptions": { "strictMetadataEmit": true } -} \ No newline at end of file +} diff --git a/src/typings.d.ts b/src/typings.d.ts new file mode 100644 index 0000000..f8cffcb --- /dev/null +++ b/src/typings.d.ts @@ -0,0 +1,6 @@ +// Typings reference file, see links for more information +// https://github.com/typings/typings +// https://www.typescriptlang.org/docs/handbook/writing-declaration-files.html + +/// +/// diff --git a/tsconfig-amd.json b/tsconfig-amd.json deleted file mode 100644 index 97567f9..0000000 --- a/tsconfig-amd.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "compilerOptions": { - "emitDecoratorMetadata": true, - - "removeComments": true, - "declaration": true, - "experimentalDecorators": true, - "module": "amd", - "moduleResolution": "node", - - "outFile": "./bundles/angular2-logger.amd.js", - - "rootDir": "./src", - "sourceRoot": "./src", - "sourceMap": true, - "inlineSources": true, - "lib": ["es6", "dom"], - "target": "es5" - }, - "files": [ - "app/core/level.ts", - "app/core/logger.ts", - "app/core/providers.ts" - ], - "angularCompilerOptions": { - "strictMetadataEmit": true - } -} \ No newline at end of file diff --git a/tsconfig-es2015.json b/tsconfig-es2015.json deleted file mode 100644 index a63f718..0000000 --- a/tsconfig-es2015.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "compilerOptions": { - - "emitDecoratorMetadata": true, - - "removeComments": true, - "declaration": true, - "experimentalDecorators": true, - "module": "es2015", - "moduleResolution": "node", - "outDir": "./dist/esm", - "rootDir": ".", - "sourceMap": true, - "inlineSources": true, - "target": "es2015" - }, - "files": [ - "core.ts" - ], - "angularCompilerOptions": { - "strictMetadataEmit": true - } -} \ No newline at end of file diff --git a/tsconfig-es5.json b/tsconfig-es5.json deleted file mode 100644 index 02281e7..0000000 --- a/tsconfig-es5.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "compilerOptions": { - "emitDecoratorMetadata": true, - - "removeComments": true, - "declaration": false, - "experimentalDecorators": true, - "module": "commonjs", - "moduleResolution": "node", - - "outDir": ".", - - "rootDir": ".", - "sourceMap": true, - "inlineSources": true, -// "lib": ["es6", "dom"], - "target": "es5" - }, - "files": [ - "core.ts", - "typings/index.d.ts" - ], - "angularCompilerOptions": { - "strictMetadataEmit": true - } -} \ No newline at end of file diff --git a/tsconfig-sys.json b/tsconfig-sys.json deleted file mode 100644 index c5e63b8..0000000 --- a/tsconfig-sys.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - "emitDecoratorMetadata": true, - - "removeComments": true, - "declaration": false, - "experimentalDecorators": true, - - "module": "system", - "moduleResolution": "node", - - "outFile": "./bundles/angular2-logger.sys.js", - - "rootDir": "../", - "sourceMap": true, - "inlineSources": true, -// "lib": ["es6", "dom"], - "target": "es5" - }, - "files": [ - "core.ts", - "typings/index.d.ts" - ], - "angularCompilerOptions": { - "strictMetadataEmit": true - } -} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index 02281e7..0000000 --- a/tsconfig.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "compilerOptions": { - "emitDecoratorMetadata": true, - - "removeComments": true, - "declaration": false, - "experimentalDecorators": true, - "module": "commonjs", - "moduleResolution": "node", - - "outDir": ".", - - "rootDir": ".", - "sourceMap": true, - "inlineSources": true, -// "lib": ["es6", "dom"], - "target": "es5" - }, - "files": [ - "core.ts", - "typings/index.d.ts" - ], - "angularCompilerOptions": { - "strictMetadataEmit": true - } -} \ No newline at end of file diff --git a/typings.json b/typings.json index 85df769..5be1dd1 100644 --- a/typings.json +++ b/typings.json @@ -1,6 +1,5 @@ { "globalDevDependencies": { - "core-js": "github:DefinitelyTyped/DefinitelyTyped/core-js/core-js.d.ts#23c9f2230960c4a9b83e4297471d082a27d02b74", "jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#d594ef506d1efe2fea15f8f39099d19b39436b71", "node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#23c9f2230960c4a9b83e4297471d082a27d02b74" } From a80eb7cecaf6388b5ac06e9ad4fd8391b200d47c Mon Sep 17 00:00:00 2001 From: Devin Date: Mon, 12 Sep 2016 07:41:58 -0600 Subject: [PATCH 2/4] Revert "Angular cli compatibility (#1)" This reverts commit 146608b027692302583482f59f5b7d132c67b445. --- .gitignore | 26 ++++++++------ .npmignore | 3 ++ README.md | 38 +++++++++----------- {src/modules => app}/core/level.ts | 0 {src/modules => app}/core/logger.ts | 0 {src/modules => app}/core/providers.ts | 0 core.d.ts | 48 ++++++++++++++++++++++++++ core.ts | 8 +++++ docs/dev/CHANGES.md | 35 ------------------- package.json | 33 +++++++++--------- src/core.ts | 6 ---- src/index.ts | 6 ---- src/modules/core/index.ts | 8 ----- src/typings.d.ts | 6 ---- tsconfig-amd.json | 28 +++++++++++++++ tsconfig-es2015.json | 23 ++++++++++++ tsconfig-es5.json | 26 ++++++++++++++ src/tsconfig.json => tsconfig-es6.json | 18 +++++----- tsconfig-sys.json | 27 +++++++++++++++ tsconfig.json | 26 ++++++++++++++ typings.json | 1 + 21 files changed, 247 insertions(+), 119 deletions(-) rename {src/modules => app}/core/level.ts (100%) rename {src/modules => app}/core/logger.ts (100%) rename {src/modules => app}/core/providers.ts (100%) create mode 100644 core.d.ts create mode 100644 core.ts delete mode 100644 docs/dev/CHANGES.md delete mode 100644 src/core.ts delete mode 100644 src/index.ts delete mode 100644 src/modules/core/index.ts delete mode 100644 src/typings.d.ts create mode 100644 tsconfig-amd.json create mode 100644 tsconfig-es2015.json create mode 100644 tsconfig-es5.json rename src/tsconfig.json => tsconfig-es6.json (69%) create mode 100644 tsconfig-sys.json create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore index c2acba0..4e572ea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ + +npm-debug.log* + # Dependency directory node_modules typings @@ -8,18 +11,19 @@ typings # Optional REPL history .node_repl_history -# output/generated dist bundles -npm-debug.log* -**/*.js -**/*.js.map -**/*.d.ts -# Workspace Settings -.idea/workspace.xml -.vscode +/*.js +/*.js.map +#/*.d.ts + +app/**/*.js +app/**/*.js.map +app/**/*.d.ts + +demos/*/app/**/*.js +demos/*/app/**/*.map +demos/*/app/**/*.d.ts -# DO NOT ignore (must come last) -!demos/*/systemjs.config.js -!src/typings.d.ts +.idea/workspace.xml \ No newline at end of file diff --git a/.npmignore b/.npmignore index c228b42..fe8de05 100644 --- a/.npmignore +++ b/.npmignore @@ -22,3 +22,6 @@ tsconfig.json typings.json .travis.yml + +#TODO: Modify build process so it doesn't need this file at all. +core.ts \ No newline at end of file diff --git a/README.md b/README.md index fda9b83..6474fe8 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,10 @@ -# [Summary of Changes](https://github.com/TheFirstDeity/angular2-logger/blob/master/docs/dev/CHANGES.md) -https://github.com/TheFirstDeity/angular2-logger/blob/master/docs/dev/CHANGES.md - ---- - # Angular2-Logger [![Build Status](https://travis-ci.org/code-chunks/angular2-logger.svg?branch=master)](https://travis-ci.org/code-chunks/angular2-logger) [![npm version](https://badge.fury.io/js/angular2-logger.svg)](https://badge.fury.io/js/angular2-logger) [![Join the chat at https://gitter.im/code-chunks/angular2-logger](https://badges.gitter.im/code-chunks/angular2-logger.svg)](https://gitter.im/code-chunks/angular2-logger?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/code-chunks/angular2-logger/master/LICENSE) +[![Support](https://supporter.60devs.com/api/b/cjv93jwfwck3yp8z2mn1d9gay)](https://supporter.60devs.com/give/cjv93jwfwck3yp8z2mn1d9gay) ## What is it? @@ -21,13 +17,13 @@ This is a work in progress and is not ready for production, use with care, the A ### Quickstart 1. Install the npm module. - + npm install --save angular2-logger 2. Add the `angular2-logger` library to your app. If you are following the [Angular 2's Quickstart Guide](https://angular.io/docs/ts/latest/quickstart.html) it should be something like this: In `systemjs.config.js`: - + // map tells the System loader where to look for things var map = { 'app': 'app', // 'dist', @@ -36,7 +32,7 @@ This is a work in progress and is not ready for production, use with care, the A 'rxjs': 'node_modules/rxjs', 'angular2-logger': 'node_modules/angular2-logger' // ADD THIS }; - + //packages tells the System loader how to load when no filename and/or no extension var packages = { 'app': { main: 'main.ts', defaultExtension: 'ts' }, @@ -47,14 +43,14 @@ This is a work in progress and is not ready for production, use with care, the A 3. Setup the Provider. - + In `app.module.ts`: import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppComponent } from './app.component'; import { Logger } from "angular2-logger/core"; // ADD THIS - + @NgModule({ imports: [ BrowserModule ], declarations: [ AppComponent ], @@ -77,8 +73,8 @@ This is a work in progress and is not ready for production, use with care, the A this._logger.log('This is a priority level 5 log message...'); } } - -By default the logger level will be set to `Level.WARN`, so you'll only see Warning and Error messages. + +By default the logger level will be set to `Level.WARN`, so you'll only see Warning and Error messages. ### Going deeper... @@ -86,12 +82,12 @@ In order to see all of the messages you just need to change the logger message h - Dynamically using the console: - logger.level = logger.Level.LOG; // same as: logger.level = 5; - + logger.level = logger.Level.LOG; // same as: logger.level = 5; + - Or using one of the predefined configuration providers: import {LOG_LOGGER_PROVIDERS} from "angular2-logger/core"; - + @NgModule({ ... providers: [ LOG_LOGGER_PROVIDERS ] @@ -120,7 +116,7 @@ If the Providers included don't meet your needs you can configure the default lo @NgModule({ ... - providers: [ + providers: [ { provide: Options, useValue: { store: false } }, Logger ] @@ -167,19 +163,19 @@ You can also override the default configuration options by extending the Options ... @NgModule({ ... - providers: [ + providers: [ { provide: Options, useClass: CustomLoggerOptions }, Logger ] }) - + Class names like `Options` and `Level` might be too common, if you get a conflict you can rename them like this: import { Logger, Options as LoggerOptions, Level as LoggerLevel } from "angular2-logger/core"; @NgModule({ ... - providers: [ + providers: [ { provide: LoggerOptions, useValue: { level: LoggerLevel.WARN } } ] }) @@ -216,8 +212,8 @@ Done. The codebase was updated to handle the breaking changes on Angular2's Release Candidate 5. **Make sure you don't upgrade to this version if you haven't upgraded Angular2 to at least `2.0.0-rc.5`** -- Quickstart guide now follows the pattern in Angular 2's Quickstart to add the references to other libs in `systemjs.config.js`. -However if you still want to do it the old way by adding the system bundle, you can still do so, except now its called `bundles/angular2-logger.sys.min.js`. +- Quickstart guide now follows the pattern in Angular 2's Quickstart to add the references to other libs in `systemjs.config.js`. +However if you still want to do it the old way by adding the system bundle, you can still do so, except now its called `bundles/angular2-logger.sys.min.js`. ## Breaking changes on 0.3.0 The codebase was updated to handle the breaking changes on Angular2's Release Candidate. diff --git a/src/modules/core/level.ts b/app/core/level.ts similarity index 100% rename from src/modules/core/level.ts rename to app/core/level.ts diff --git a/src/modules/core/logger.ts b/app/core/logger.ts similarity index 100% rename from src/modules/core/logger.ts rename to app/core/logger.ts diff --git a/src/modules/core/providers.ts b/app/core/providers.ts similarity index 100% rename from src/modules/core/providers.ts rename to app/core/providers.ts diff --git a/core.d.ts b/core.d.ts new file mode 100644 index 0000000..951331e --- /dev/null +++ b/core.d.ts @@ -0,0 +1,48 @@ +export enum Level { + OFF = 0, + ERROR = 1, + WARN = 2, + INFO = 3, + DEBUG = 4, + LOG = 5, +} + +export class Options { + level: Level; + global: boolean; + globalAs: string; + store: boolean; + storeAs: string; +} + +export class Logger { + private _level; + private _globalAs; + private _store; + private _storeAs; + Level: any; + constructor(options?: Options); + private _loadLevel; + private _storeLevel(level); + error(message?: any, ...optionalParams: any[]): void; + warn(message?: any, ...optionalParams: any[]): void; + info(message?: any, ...optionalParams: any[]): void; + debug(message?: any, ...optionalParams: any[]): void; + log(message?: any, ...optionalParams: any[]): void; + global: () => this; + store(): Logger; + unstore(): Logger; + isErrorEnabled: () => boolean; + isWarnEnabled: () => boolean; + isInfoEnabled: () => boolean; + isDebugEnabled: () => boolean; + isLogEnabled: () => boolean; + level: Level; +} + +export const OFF_LOGGER_PROVIDERS: any[]; +export const ERROR_LOGGER_PROVIDERS: any[]; +export const WARN_LOGGER_PROVIDERS: any[]; +export const INFO_LOGGER_PROVIDERS: any[]; +export const DEBUG_LOGGER_PROVIDERS: any[]; +export const LOG_LOGGER_PROVIDERS: any[]; \ No newline at end of file diff --git a/core.ts b/core.ts new file mode 100644 index 0000000..205cb85 --- /dev/null +++ b/core.ts @@ -0,0 +1,8 @@ +/** + * @module + * @description + * Public API. + */ +export * from "./app/core/level"; +export * from "./app/core/logger"; +export * from "./app/core/providers"; \ No newline at end of file diff --git a/docs/dev/CHANGES.md b/docs/dev/CHANGES.md deleted file mode 100644 index ae7304e..0000000 --- a/docs/dev/CHANGES.md +++ /dev/null @@ -1,35 +0,0 @@ -# Status - -#### **Requirements** -- [ ] Tested with both es5 & es6 project -- [ ] Demos, make them to play -- [ ] Satisfied with the file/directory structure -- [ ] All files have cool little headings and stuff - -#### **Experiments** -- [ ] Update angular dep to `rc6` -- [ ] Update Typescript dep -- [ ] Refactor for ts2 features - -# Changes - -## **0.4.666** -- #### **Directories & Modules** - - renamed `app` to `src` since this is more of a library - - added `src/modules` to contain sub-packages in a way that works well with node module resolution. For example, `angular2-logger/subset` will elegantly point to whatever's exported by `src/modules/subset/index.ts`. (Just copy how I set up `core`'s files and make a `src/subset.ts`.) - - **Feature:** Bundlers like Webpack may automatically pick the proper es5 or es6 `js` depending on their target configuration. Works with the `angular-cli`. - - **Feature:** `src/index.ts` can be used to customize what can be imported from `angular2-logger`. It could be used as an alias for `angular2-logger/core`, or it could be like the greatest-hits from a bunch of little sub-packages. - - **Query:** _Is it even worth it to have sub-packages like 'core' and whatever else? I feel like it might just be a bunch of extra typing & memorization for consumers of the api. Since `rc5`, we have NgModules to package sets of resources together._ -- #### **package.json** - - `"main"` points at the es5 entry point, which is the umd `index.js` right now (TODO: point at bundle) - - `"module"` points at the es6 entry point, overriding `main`. This behavior has been adopted for es6 compatible builds using Webpack (`angular-cli` uses it.) - - `"typings"` points to the `.d.ts` entry point. - - `"compile"` tasks now pass configuration to the compiler to avoid duplicate `tsconfig.json` files - - `"clean"` now uses `del-cli` for safer deletes with simpler glob patterns -- #### **typings.json** - - `src/typings.d.ts` added to reference global types and `core-js` was removed from `typings.json`. Instead, the `es6` default lib is forced for all modules. This is done by setting `noLib` in `tsconfig.json` to stop the default lib from loading, and then explicitely referencing the es6 default (`lib.es6.d.ts`) in `typings.d.ts`. Typescript 2.0.0+ lets you do this out of the box, but this hack is needed for older versions -- #### **Miscellanious** - - Organized `.gitignore` entries - -## **0.4.5** -... diff --git a/package.json b/package.json index 985f5fa..6b79ef1 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,11 @@ { "name": "angular2-logger", - "version": "0.4.666", + "version": "0.4.5", "description": "A Log4j inspired Logger for Angular 2.", "repository": { "type": "git", "url": "git+https://github.com/code-chunks/angular2-logger" }, - "main": "es5/index.js", - "module": "index.js", - "typings": "index.d.ts", - "scripts": { "tsc": "tsc", "typings": "typings", @@ -17,12 +13,14 @@ "tslint": "tslint *.ts src/**/*.ts", "lint": "npm run tslint", "prepublish": "npm run build", - "clean": "del-cli modules/ bundles/ es5/ **/*{.js,.map,.d.ts} !src/typings.d.ts !demos/*/systemjs.config.js !{node_modules,typings}/** ", + "clean": "rimraf *.js *.map app/**/*.js app/**/*.map app/**/*.d.ts demos/*/app**/*.js demos/*/app/*.map demos/*/app/*.d.ts dist bundles", "precompile": "typings install", - "compile": "npm run compile:es6 && npm run compile:umd && npm run compile:sys", - "compile:es6": "tsc -p src/tsconfig.json --declaration", - "compile:umd": "tsc -p src/tsconfig.json -m umd -t es5 --outDir es5", - "compile:sys": "tsc -p src/tsconfig.json -m system -t es5 --outFile bundles/angular2-logger.sys.js", + "compile": "npm run compile:es5 && npm run compile:sys && npm run compile:es6", + "compile:amd": "tsc -p tsconfig-amd.json", + "compile:sys": "tsc -p tsconfig-sys.json", + "compile:es5": "tsc -p tsconfig-es5.json", + "compile:es6": "tsc -p tsconfig-es6.json", + "compile:es2015": "tsc -p tsconfig-es2015.json", "pretest": "npm run lint", "test": "echo tests pending...", "prebuild": "npm run clean && npm run compile && npm run test", @@ -73,20 +71,20 @@ "homepage": "https://github.com/code-chunks/angular2-logger#readme", "dependencies": {}, "devDependencies": { + "rimraf": "^2.5.2", + "tslint": "^3.8.1", + "typescript": "1.8.10", + "typings": "^1.0.3", + "uglify-js": "^2.6.2", "@angular/common": "2.0.0-rc.5", "@angular/compiler": "2.0.0-rc.5", "@angular/core": "2.0.0-rc.5", "@angular/platform-browser": "2.0.0-rc.5", "@angular/platform-browser-dynamic": "2.0.0-rc.5", + "systemjs": "0.19.37", "core-js": "^2.4.0", - "del-cli": "0.2.0", "reflect-metadata": "^0.1.3", "rxjs": "5.0.0-beta.6", - "systemjs": "0.19.37", - "tslint": "^3.8.1", - "typescript": "1.8.10", - "typings": "^1.0.3", - "uglify-js": "^2.6.2", "zone.js": "^0.6.12" }, "peerDependencies": { @@ -95,5 +93,6 @@ "@angular/core": "2.0.0-rc.5", "@angular/platform-browser": "2.0.0-rc.5", "@angular/platform-browser-dynamic": "2.0.0-rc.5" - } + }, + "main": "core.js" } diff --git a/src/core.ts b/src/core.ts deleted file mode 100644 index 7f23605..0000000 --- a/src/core.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * @module - * @description - * Entry point for all public APIs of the core bundle. - */ -export * from './modules/core/'; diff --git a/src/index.ts b/src/index.ts deleted file mode 100644 index 8d6c6b6..0000000 --- a/src/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * @module - * @description - * Main entry point that doesn't currently export anything. Use 'angular2-logger/core'. - */ -export let message: string = 'should probably export cool stuff like NgModules'; diff --git a/src/modules/core/index.ts b/src/modules/core/index.ts deleted file mode 100644 index fd97fb3..0000000 --- a/src/modules/core/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * @module - * @description - * Public API. - */ -export * from "./level"; -export * from "./logger"; -export * from "./providers"; diff --git a/src/typings.d.ts b/src/typings.d.ts deleted file mode 100644 index f8cffcb..0000000 --- a/src/typings.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -// Typings reference file, see links for more information -// https://github.com/typings/typings -// https://www.typescriptlang.org/docs/handbook/writing-declaration-files.html - -/// -/// diff --git a/tsconfig-amd.json b/tsconfig-amd.json new file mode 100644 index 0000000..97567f9 --- /dev/null +++ b/tsconfig-amd.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "emitDecoratorMetadata": true, + + "removeComments": true, + "declaration": true, + "experimentalDecorators": true, + "module": "amd", + "moduleResolution": "node", + + "outFile": "./bundles/angular2-logger.amd.js", + + "rootDir": "./src", + "sourceRoot": "./src", + "sourceMap": true, + "inlineSources": true, + "lib": ["es6", "dom"], + "target": "es5" + }, + "files": [ + "app/core/level.ts", + "app/core/logger.ts", + "app/core/providers.ts" + ], + "angularCompilerOptions": { + "strictMetadataEmit": true + } +} \ No newline at end of file diff --git a/tsconfig-es2015.json b/tsconfig-es2015.json new file mode 100644 index 0000000..a63f718 --- /dev/null +++ b/tsconfig-es2015.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + + "emitDecoratorMetadata": true, + + "removeComments": true, + "declaration": true, + "experimentalDecorators": true, + "module": "es2015", + "moduleResolution": "node", + "outDir": "./dist/esm", + "rootDir": ".", + "sourceMap": true, + "inlineSources": true, + "target": "es2015" + }, + "files": [ + "core.ts" + ], + "angularCompilerOptions": { + "strictMetadataEmit": true + } +} \ No newline at end of file diff --git a/tsconfig-es5.json b/tsconfig-es5.json new file mode 100644 index 0000000..02281e7 --- /dev/null +++ b/tsconfig-es5.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "emitDecoratorMetadata": true, + + "removeComments": true, + "declaration": false, + "experimentalDecorators": true, + "module": "commonjs", + "moduleResolution": "node", + + "outDir": ".", + + "rootDir": ".", + "sourceMap": true, + "inlineSources": true, +// "lib": ["es6", "dom"], + "target": "es5" + }, + "files": [ + "core.ts", + "typings/index.d.ts" + ], + "angularCompilerOptions": { + "strictMetadataEmit": true + } +} \ No newline at end of file diff --git a/src/tsconfig.json b/tsconfig-es6.json similarity index 69% rename from src/tsconfig.json rename to tsconfig-es6.json index 3a39838..f927379 100644 --- a/src/tsconfig.json +++ b/tsconfig-es6.json @@ -1,18 +1,18 @@ { "compilerOptions": { - "sourceMap": true, - "experimentalDecorators": true, "emitDecoratorMetadata": true, + "experimentalDecorators": true, "removeComments": true, - - "noLib": true, - "target": "es6", - "module": "es2015", "moduleResolution": "node", - "outDir": "../", - "rootDir": "." + "outDir": "./dist/es6", + "rootDir": ".", + "sourceMap": true, + "target": "es6" }, + "files": [ + "core.ts" + ], "angularCompilerOptions": { "strictMetadataEmit": true } -} +} \ No newline at end of file diff --git a/tsconfig-sys.json b/tsconfig-sys.json new file mode 100644 index 0000000..c5e63b8 --- /dev/null +++ b/tsconfig-sys.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + "emitDecoratorMetadata": true, + + "removeComments": true, + "declaration": false, + "experimentalDecorators": true, + + "module": "system", + "moduleResolution": "node", + + "outFile": "./bundles/angular2-logger.sys.js", + + "rootDir": "../", + "sourceMap": true, + "inlineSources": true, +// "lib": ["es6", "dom"], + "target": "es5" + }, + "files": [ + "core.ts", + "typings/index.d.ts" + ], + "angularCompilerOptions": { + "strictMetadataEmit": true + } +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..02281e7 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "emitDecoratorMetadata": true, + + "removeComments": true, + "declaration": false, + "experimentalDecorators": true, + "module": "commonjs", + "moduleResolution": "node", + + "outDir": ".", + + "rootDir": ".", + "sourceMap": true, + "inlineSources": true, +// "lib": ["es6", "dom"], + "target": "es5" + }, + "files": [ + "core.ts", + "typings/index.d.ts" + ], + "angularCompilerOptions": { + "strictMetadataEmit": true + } +} \ No newline at end of file diff --git a/typings.json b/typings.json index 5be1dd1..85df769 100644 --- a/typings.json +++ b/typings.json @@ -1,5 +1,6 @@ { "globalDevDependencies": { + "core-js": "github:DefinitelyTyped/DefinitelyTyped/core-js/core-js.d.ts#23c9f2230960c4a9b83e4297471d082a27d02b74", "jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#d594ef506d1efe2fea15f8f39099d19b39436b71", "node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#23c9f2230960c4a9b83e4297471d082a27d02b74" } From 9a4c4a189249e4454396de620bffb5d3d32b6552 Mon Sep 17 00:00:00 2001 From: Devin Date: Mon, 12 Sep 2016 07:47:35 -0600 Subject: [PATCH 3/4] angular-cli will find "dist/es6/core.js" Requires package to be imported as "angular2-logger" instead of "angular2-logger/core" --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 6b79ef1..d3efe9c 100644 --- a/package.json +++ b/package.json @@ -94,5 +94,7 @@ "@angular/platform-browser": "2.0.0-rc.5", "@angular/platform-browser-dynamic": "2.0.0-rc.5" }, - "main": "core.js" + "main": "core.js", + "module": "dist/es6/core.js", + "typings": "core.d.ts" } From 542d4e68cbea8908741d49b797d3c8d1a93a3a82 Mon Sep 17 00:00:00 2001 From: Devin Date: Mon, 12 Sep 2016 07:57:55 -0600 Subject: [PATCH 4/4] Bumped version to 0.5.0 signaling breaking change --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d3efe9c..ed33e0f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular2-logger", - "version": "0.4.5", + "version": "0.5.0", "description": "A Log4j inspired Logger for Angular 2.", "repository": { "type": "git",