From 51ff371fb8b138f5a782f1352edccb29d763aa64 Mon Sep 17 00:00:00 2001 From: Aaron Newman Date: Sat, 18 Feb 2017 19:47:04 -0600 Subject: [PATCH] Cleaned up project a bit and renamed to ngx --- .gitignore | 25 ++++- .npmignore | 27 +++++ .travis.yml | 4 + README.md | 10 +- index.ts | 23 +++- package.json | 88 +++++++-------- src/{loggly-service.ts => loggly.service.ts} | 32 +++--- tsconfig.json | 29 +++-- tslint.json | 111 +++++++++++++++++++ 9 files changed, 267 insertions(+), 82 deletions(-) create mode 100644 .npmignore create mode 100644 .travis.yml rename src/{loggly-service.ts => loggly.service.ts} (87%) create mode 100644 tslint.json diff --git a/.gitignore b/.gitignore index 6246bc2..0f2190e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,26 @@ +# Node +node_modules/* +npm-debug.log + +# TypeScript +*.js +*.map +*.d.ts + +# JetBrains .idea +.project +.settings +.idea/* *.iml -node_modules \ No newline at end of file + +# VS Code +.vscode/* + +# Windows +Thumbs.db +Desktop.ini + +# Mac +.DS_Store +**/.DS_Store diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..1205d5c --- /dev/null +++ b/.npmignore @@ -0,0 +1,27 @@ +# Node +node_modules/* +npm-debug.log + +# DO NOT IGNORE TYPESCRIPT FILES FOR NPM +# TypeScript +# *.js +# *.map +# *.d.ts + +# JetBrains +.idea +.project +.settings +.idea/* +*.iml + +# VS Code +.vscode/* + +# Windows +Thumbs.db +Desktop.ini + +# Mac +.DS_Store +**/.DS_Store diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2567e63 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +sudo: false +node_js: +- '4.2.1' diff --git a/README.md b/README.md index c298854..860cd08 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,19 @@ -# angular2-loggly-logger +# ngx-loggly-logger ## Description -Simple library to log to loggly in Angular2 +Simple library to log to loggly in Angular ## Installation To install follow this procedure: -1. __npm install angular2-loggly-logger --save__ +1. __npm install ngx-loggly-logger --save__ 2. Add __LogglyService__ import to your __@NgModule__ like example below ```js import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { MyTestApp } from './my-test-app'; - import { LogglyService } from 'angular2-loggly-logger'; + import { NgxLogglyModule } from 'ngx-loggly-logger'; @NgModule({ providers: [ LogglyService ], @@ -25,7 +25,7 @@ To install follow this procedure: ``` 3. Use the following in your components, etc. ```js - import {LogglyService} from 'angular2-loggly-logger'; + import {LogglyService} from 'ngx-loggly-logger'; constructor(private _logglyService:LogglyService) { } diff --git a/index.ts b/index.ts index 880d5fa..9134c15 100644 --- a/index.ts +++ b/index.ts @@ -1,2 +1,21 @@ -export * from "./src/loggly-service"; -export class LogglyModule {} \ No newline at end of file +import {NgModule, ModuleWithProviders} from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {LogglyService} from './src/loggly.service'; + +export * from './src/loggly.service'; + +@NgModule({ + imports: [ + CommonModule + ], + declarations: [], + exports: [] +}) +export class NgxLogglyModule { + static forRoot(): ModuleWithProviders { + return { + ngModule: NgxLogglyModule, + providers: [LogglyService] + }; + } +} diff --git a/package.json b/package.json index 0c74ae3..8785ff1 100644 --- a/package.json +++ b/package.json @@ -1,53 +1,51 @@ { - "name": "angular2-loggly-logger", - "version": "0.0.10", - "description": "Angular2 Service for logging to Loggly", - "scripts": {}, - "contributors": [], - "license": "MIT", - "devDependencies": { - "@types/node": "^6.0.38", - "angular2-template-loader": "^0.6.0", - "awesome-typescript-loader": "~3.0.0-beta.17", - "css-loader": "^0.26.0", - "raw-loader": "^0.5.1", - "to-string-loader": "^1.1.4", - "typescript": "^2.0.10", - "webpack": "2.2.0-rc.3", - "webpack-dev-server": "2.2.0-rc.0", - "webpack-merge": "~2.3.1" + "name": "ngx-loggly-logger", + "version": "0.0.19", + "scripts": { + "build": "ngc -p tsconfig.json", + "lint": "tslint src/**/*.ts", + "test": "tsc && karma start", + "prepublish": "tsc", + "tsc": "tsc" }, - "dependencies": { - "@angular/common": "~2.4.1", - "@angular/compiler": "~2.4.1", - "@angular/core": "~2.4.1", - "@angular/forms": "~2.4.1", - "@angular/http": "~2.4.1", - "@angular/platform-browser": "~2.4.1", - "@angular/platform-browser-dynamic": "~2.4.1", - "@angular/platform-server": "~2.4.1", - "@angular/router": "~3.4.1", - "@angular/upgrade": "~2.4.1", - "core-js": "^2.4.1", - "ie-shim": "^0.1.0", - "ng2-cookies": "^1.0.4", - "reflect-metadata": "^0.1.9", - "rxjs": "~5.0.2", - "zone.js": "~0.7.4" - }, - "keywords": [ - "Angular2", - "angular2-loggly", - "ng2-loggly", - "angular2-loggly-logger", - "ng2-loggly-logger" - ], "repository": { "type": "git", - "url": "git+https://github.com/Tgure/angular2-loggly-logger.git" + "url": "https://github.com/Tgure/ngx-loggly-logger" + }, + "author": { + "name": "Aaron Newman", + "email": "aftermathinc@gmail.com" }, + "keywords": [ + "angular" + ], + "license": "MIT", "bugs": { - "url": "https://github.com/Tgure/angular2-loggly-logger/issues" + "url": "https://github.com/Tgure/ngx-loggly-logger/issues" + }, + "main": "./dist/index.js", + "dependencies": { + "ng2-cookies": "~1.0.4" + }, + "devDependencies": { + "@angular/common": "~2.4.8", + "@angular/http": "~2.4.1", + "@angular/platform-browser": "~2.4.1", + "@angular/compiler": "~2.4.5", + "@angular/compiler-cli": "~2.4.5", + "@angular/core": "~2.4.8", + "@angular/platform-server": "~2.4.5", + "codelyzer": "~2.0.0", + "rxjs": "~5.1.1", + "tslint": "~4.4.2", + "typescript": "~2.1.6", + "zone.js": "~0.7.7", + "@types/es6-shim": "~0.31.32", + "@types/protractor": "~4.0.0", + "@types/jasmine": "~2.5.40", + "@types/selenium-webdriver": "~2.53.39" }, - "homepage": "https://github.com/Tgure/angular2-loggly-logger#readme" + "engines": { + "node": ">=0.8.0" + } } diff --git a/src/loggly-service.ts b/src/loggly.service.ts similarity index 87% rename from src/loggly-service.ts rename to src/loggly.service.ts index 800ba42..f3b0744 100644 --- a/src/loggly-service.ts +++ b/src/loggly.service.ts @@ -1,7 +1,8 @@ import {Injectable} from '@angular/core'; -import {Http, Headers, RequestOptions} from '@angular/http'; -import {Cookie} from 'ng2-cookies/ng2-cookies'; +import {Observable} from 'rxjs/Observable'; import 'rxjs/add/operator/map'; +import {Http, Headers, RequestOptions, Response} from '@angular/http'; +import {Cookie} from 'ng2-cookies'; @Injectable() export class LogglyService { @@ -10,10 +11,6 @@ export class LogglyService { private LOGGLY_SESSION_KEY: any; private LOGGLY_SESSION_KEY_LENGTH: any; private LOGGLY_PROXY_DOMAIN: any; - private key: boolean; - private sendConsoleErrors: boolean; - private tag: string; - private useDomainProxy: boolean; private session_id: any; private inputUrl: any; @@ -28,7 +25,7 @@ export class LogglyService { uuid() { // lifted from here -> http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#2117523 return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { - var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); + let r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); } @@ -45,7 +42,7 @@ export class LogglyService { setDomainProxy(tracker: any, useDomainProxy: any) { tracker.useDomainProxy = useDomainProxy; - //refresh inputUrl value + // refresh inputUrl value this.setInputUrl(tracker); } @@ -53,8 +50,8 @@ export class LogglyService { tracker.sendConsoleErrors = sendConsoleErrors; if (tracker.sendConsoleErrors === true) { - var _onerror = window.onerror; - //send console error messages to Loggly + let _onerror = window.onerror; + // send console error messages to Loggly window.onerror = function (msg, url, line, col) { tracker.push({ category: 'BrowserJsException', @@ -74,7 +71,7 @@ export class LogglyService { } setInputUrl(tracker: any) { - if (tracker.useDomainProxy == true) { + if (tracker.useDomainProxy === true) { tracker.inputUrl = this.LOGGLY_INPUT_PREFIX + window.location.host + '/' @@ -83,8 +80,7 @@ export class LogglyService { + tracker.key + '/tag/' + tracker.tag; - } - else { + } else { tracker.inputUrl = this.LOGGLY_INPUT_PREFIX + (tracker.logglyCollectorDomain || this.LOGGLY_COLLECTOR_DOMAIN) + '/inputs/' @@ -108,13 +104,13 @@ export class LogglyService { } push(data: any) { - var type = typeof data; + let type = typeof data; if (!data || !(type === 'object' || type === 'string')) { return; } - var self: any = this; + let self: any = this; if (type === 'string') { @@ -173,13 +169,13 @@ export class LogglyService { } readCookie(): any { - var cookie = Cookie.get(this.LOGGLY_SESSION_KEY); + let cookie = Cookie.get(this.LOGGLY_SESSION_KEY); if (cookie) { - var i = cookie.indexOf(this.LOGGLY_SESSION_KEY); + let i = cookie.indexOf(this.LOGGLY_SESSION_KEY); if (i < 0) { return false; } else { - var end = cookie.indexOf(';', i + 1); + let end = cookie.indexOf(';', i + 1); end = end < 0 ? cookie.length : end; return cookie.slice(i + this.LOGGLY_SESSION_KEY_LENGTH, end); } diff --git a/tsconfig.json b/tsconfig.json index 6f628e1..8f3aea3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,19 +1,26 @@ { "compilerOptions": { + "noImplicitAny": true, "module": "commonjs", - "target": "es5", - "outDir": "dist", - "rootDir": ".", - "sourceMap": true, + "target": "ES5", "emitDecoratorMetadata": true, "experimentalDecorators": true, - "moduleResolution": "node", - "types": [ - "core-js", - "node" - ] + "sourceMap": true, + "declaration": true, + "outDir": "./dist", + "typeRoots": [ + "node_modules/@types" + ] }, + "files": [ + "index.ts" + ], "exclude": [ - "node_modules" - ] + "node_modules", + "dist", + "**/*.spec.ts" + ], + "angularCompilerOptions": { + "strictMetadataEmit": true + } } diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000..21ed5b3 --- /dev/null +++ b/tslint.json @@ -0,0 +1,111 @@ +{ + "rulesDirectory": [ + "node_modules/codelyzer" + ], + "rules": { + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "curly": true, + "eofline": true, + "forin": true, + "indent": [ + true, + "spaces" + ], + "label-position": true, + "label-undefined": true, + "max-line-length": [ + true, + 140 + ], + "member-access": false, + "member-ordering": [ + true, + "static-before-instance", + "variables-before-functions" + ], + "no-arg": true, + "no-bitwise": false, + "no-console": [ + true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-debugger": true, + "no-duplicate-key": true, + "no-duplicate-variable": true, + "no-empty": false, + "no-eval": true, + "no-inferrable-types": true, + "no-shadowed-variable": true, + "no-string-literal": false, + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unused-expression": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "no-unreachable": true, + "no-use-before-declare": true, + "no-var-keyword": true, + "object-literal-sort-keys": false, + "one-line": [ + true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [ + true, + "single" + ], + "radix": true, + "semicolon": [ + "always" + ], + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "variable-name": false, + "whitespace": [ + true, + "check-branch", + "check-decl", + "check-operator", + "check-separator", + "check-type" + ], + + "directive-selector-name": [true, "camelCase"], + "component-selector-name": [true, "kebab-case"], + "directive-selector-type": [true, "attribute"], + "component-selector-type": [true, "element"], + "use-input-property-decorator": true, + "use-output-property-decorator": true, + "use-host-property-decorator": true, + "no-input-rename": true, + "no-output-rename": true, + "use-life-cycle-interface": true, + "use-pipe-transform-interface": true, + "component-class-suffix": true, + "directive-class-suffix": true + } +}