Skip to content

Commit

Permalink
support typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
tortuvshin committed Sep 17, 2019
1 parent e112896 commit 9e01440
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

lib/
# Runtime data
pids
*.pid
Expand Down
128 changes: 125 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 20 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "uptime.js",
"version": "1.2.10",
"version": "1.3.1",
"description": "Uptime monitor in Node.js that send status changes to Chatbots",
"author": "Turtuvshin Byambaa",
"homepage": "https://uptime.js.org",
"copyright": "Copyright 2019 Intelligo Systems",
"license": "MIT",
"main": "index.js",
"main": "lib/index.js",
"typings": "./lib/index.d.ts",
"repository": "intelligo-systems/uptime.js",
"keywords": [
"uptime",
Expand All @@ -25,22 +26,32 @@
"check"
],
"scripts": {
"start": "node index.js",
"dev": "vuepress dev web",
"build": "vuepress build web",
"build": "tsc",
"build:docs": "vuepress build web",
"lint": "tslint -p tsconfig.json",
"release": "release-it"
},
"files": [
"/lib",
"/src"
],
"dependencies": {
"request": "2.88.0",
"intelligo": "1.2.1"
"intelligo": "1.2.6"
},
"devDependencies": {
"@vuepress/plugin-google-analytics": "1.0.3",
"release-it": "12.3.6",
"vuepress": "1.0.3",
"@vuepress/plugin-google-analytics": "1.1.0",
"@types/request": "2.48.3",
"@types/node": "12.7.5",
"release-it": "12.4.0",
"vuepress": "1.1.0",
"vuepress-plugin-janitor": "1.0.0",
"vuepress-plugin-reading-time": "0.1.1",
"vuepress-plugin-rss": "2.0.0",
"yaml-front-matter": "4.0.0"
"yaml-front-matter": "4.0.0",
"tslint": "5.20.0",
"tslint-config-prettier": "1.18.0",
"typescript": "3.6.3"
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Uptime } from "./uptime";
22 changes: 10 additions & 12 deletions src/Uptime.js → src/uptime.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use strict";
import * as request from "request";

const request = require("request");

class Uptime {
constructor(options) {
super();
export class Uptime {
SLACK_WEBHOOK_URL: any;
pingInterval: number;
serviceStatus: {};
constructor(options: any) {
if (!options || (options && !options.SLACK_WEBHOOK_URL)) {
throw new Error("You need to specify an SLACK_WEBHOOK_URL");
}
Expand All @@ -13,7 +13,7 @@ class Uptime {
this.serviceStatus = {};
}

pingService(url, cb) {
pingService(url: string, cb: any) {
request(
{
method: "GET",
Expand All @@ -32,7 +32,7 @@ class Uptime {
);
}

postToSlack(serviceUrl) {
postToSlack(serviceUrl: any) {
var message = "";
if (this.serviceStatus[serviceUrl].status == "DEGRADED") {
message = "`Degraded System Service !!!` :skull: ";
Expand All @@ -58,7 +58,7 @@ class Uptime {
);
}

monitor(websites) {
monitor(websites: any) {
websites.forEach(service => {
this.serviceStatus[service.url] = {
status: "OPERATIONAL", // initialize all services as operational when we start
Expand Down Expand Up @@ -108,6 +108,4 @@ class Uptime {
}, this.pingInterval);
});
}
}

module.exports = Uptime;
}
13 changes: 13 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"declaration": true,
"sourceMap": true,
"outDir": "./lib",
"rootDir": "./src",
"types": ["node"],
"lib": ["es5", "es2015", "es2016.array.include", "esnext.asynciterable"]
},
"include": ["src/**/*"]
}
60 changes: 60 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"extends": ["tslint-config-airbnb"],
"rules": {
"align": [true, "parameters", "arguments", "statements", "members", "elements"],
"indent": [true, "spaces", 2],
"max-line-length": [true, 120],
"quotemark": [true, "single", "avoid-escape", "avoid-template"],
"variable-name": [true, "ban-keywords", "check-format", "allow-leading-underscore"],
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-preblock",
"check-type",
"check-module",
"check-separator",
"check-rest-spread",
"check-typecast",
"check-type-operator"
],
"await-promise": true,
"ban-comma-operator": true,
"interface-over-type-literal": true,
"jsdoc-format": [true, "check-multiline-start"],
"member-access": [true, "check-accessor"],
"no-duplicate-imports": true,
"no-duplicate-switch-case": true,
"no-duplicate-variable": true,
"no-dynamic-delete": true,
"no-empty": true,
"no-floating-promises": true,
"no-for-in-array": true,
"no-implicit-dependencies": true,
"no-object-literal-type-assertion": true,
"no-redundant-jsdoc": true,
"no-require-imports": true,
"no-return-await": true,
"no-submodule-imports": true,
"no-this-assignment": true,
"no-unused-expression": true,
"no-var-requires": true,
"one-line": [true, "check-else", "check-whitespace", "check-open-brace", "check-catch", "check-finally"],
"strict-boolean-expressions": [true, "allow-boolean-or-undefined"],
"typedef": [true, "call-signature"],
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}
]
},
"linterOptions": {
"format": "verbose"
}
}

0 comments on commit 9e01440

Please sign in to comment.