From 1f2b9b0275063989642a3474a15601438da51a62 Mon Sep 17 00:00:00 2001 From: Rafal Wilinski Date: Sat, 29 Jul 2017 20:36:14 +0200 Subject: [PATCH] Dependencies, CI & Eslint upgrade, automate release process (#84) * Update dependencies * Small styling changes * Fix no-param-reassign rule * Fix example command for noobies * Test module on LTS and current version * Code style fix * Fix CircleCI command * Bump version to 0.2 * Automate release process * Fix CircleCI command * Fix CI tests on LTS and current * Override CI tests * Apply code review fixes * Use debug module instead of console.log * Run tests on Node 6 and 8 versions --- circle.yml | 15 +++++++++++---- package.json | 24 ++++++++++++++---------- src/helpers/gather-os-metrics.js | 5 ++--- src/helpers/socket-io-init.js | 2 +- src/helpers/validate.js | 5 ----- src/middleware-wrapper.js | 16 +++++++--------- 6 files changed, 35 insertions(+), 32 deletions(-) diff --git a/circle.yml b/circle.yml index 3684e7d..c76271c 100644 --- a/circle.yml +++ b/circle.yml @@ -2,10 +2,17 @@ machine: node: version: 4.0.0 test: - pre: + override: - npm run eslint - - npm test - - nvm install 6.9.1 && nvm use 6.9.1 && npm test - - nvm install 7.10.0 && nvm use 7.10.0 && npm test + - npm run test-ci + - nvm install 6 && nvm use 6 && npm run test-ci + - nvm install 8 && nvm use 8 && npm run test-ci post: - bithound check git@github.com:RafalWilinski/express-status-monitor.git + +deployment: + npm: + branch: master + commands: + - echo -e "$NPM_USERNAME\nNPM_PASSWORD\nNPM_EMAIL" | npm login + - npm run publish diff --git a/package.json b/package.json index 7b89d13..b5df33b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "express-status-monitor", - "version": "0.1.9", + "version": "1.0.0", "description": "Realtime Monitoring for Express-based Node applications", "main": "index.js", "keywords": [ @@ -42,26 +42,30 @@ }, "license": "MIT", "dependencies": { + "debug": "^2.6.8", "on-headers": "^1.0.1", - "pidusage": "^1.1.0", - "socket.io": "^1.5.1" + "pidusage": "^1.1.6", + "socket.io": "^2.0.3" }, "scripts": { "coverage": "istanbul cover _mocha test -- --recursive", - "test": "mocha --recursive", + "test-ci": "mocha --recursive", + "test": "mocha --recursive --watch", "snyk-protect": "snyk protect", + "publish": "publish", "prepublish": "npm run snyk-protect", - "example": "cd examples && npm start", + "example": "npm i && npm i --prefix examples && npm start --prefix examples", "eslint": "eslint ." }, "devDependencies": { "bithound": "^1.7.0", - "chai": "^3.5.0", - "eslint": "^3.12.2", + "chai": "^4.1.0", + "eslint": "^4.3.0", "istanbul": "^0.4.5", - "mocha": "^3.0.2", - "sinon": "^1.17.5", - "snyk": "^1.19.1" + "mocha": "^3.4.2", + "publish": "^0.6.0", + "sinon": "^2.4.1", + "snyk": "^1.37.0" }, "snyk": true } diff --git a/src/helpers/gather-os-metrics.js b/src/helpers/gather-os-metrics.js index 05ca386..9d5e2d8 100644 --- a/src/helpers/gather-os-metrics.js +++ b/src/helpers/gather-os-metrics.js @@ -1,8 +1,7 @@ -/* eslint no-console: "off" */ - const pidusage = require('pidusage'); const os = require('os'); const sendMetrics = require('./send-metrics'); +const debug = require('debug')('express-status-monitor'); module.exports = (io, span) => { const defaultResponse = { @@ -17,7 +16,7 @@ module.exports = (io, span) => { pidusage.stat(process.pid, (err, stat) => { if (err) { - console.error(err); + debug(err); return; } diff --git a/src/helpers/socket-io-init.js b/src/helpers/socket-io-init.js index 9848dc3..e060e04 100644 --- a/src/helpers/socket-io-init.js +++ b/src/helpers/socket-io-init.js @@ -40,7 +40,7 @@ module.exports = (server, config) => { span.responses = []; const interval = setInterval(() => gatherOsMetrics(io, span), span.interval * 1000); - // Don't keep node.js process up + // Don't keep Node.js process up interval.unref(); }); } diff --git a/src/helpers/validate.js b/src/helpers/validate.js index 240a97a..74a4904 100644 --- a/src/helpers/validate.js +++ b/src/helpers/validate.js @@ -6,15 +6,10 @@ module.exports = config => { } config.title = (typeof config.title === 'string') ? config.title : defaultConfig.title; - config.path = (typeof config.path === 'string') ? config.path : defaultConfig.path; - config.spans = (typeof config.spans === 'object') ? config.spans : defaultConfig.spans; - config.port = (typeof config.port === 'number') ? config.port : defaultConfig.port; - config.websocket = (typeof config.websocket === 'object') ? config.websocket : defaultConfig.websocket; - config.iframe = (typeof config.iframe === 'boolean') ? config.iframe : defaultConfig.iframe; return config; diff --git a/src/middleware-wrapper.js b/src/middleware-wrapper.js index 3d9acb9..1498649 100644 --- a/src/middleware-wrapper.js +++ b/src/middleware-wrapper.js @@ -1,5 +1,3 @@ -/* eslint no-param-reassign: "off" */ - const fs = require('fs'); const path = require('path'); const onHeaders = require('on-headers'); @@ -8,23 +6,23 @@ const onHeadersListener = require('./helpers/on-headers-listener'); const socketIoInit = require('./helpers/socket-io-init'); const middlewareWrapper = config => { - config = validate(config); + const validatedConfig = validate(config); const renderedHtml = fs.readFileSync(path.join(__dirname, '/public/index.html')) .toString() - .replace(/{{title}}/g, config.title) - .replace(/{{port}}/g, config.port) + .replace(/{{title}}/g, validatedConfig.title) + .replace(/{{port}}/g, validatedConfig.port) .replace(/{{script}}/g, fs.readFileSync(path.join(__dirname, '/public/javascripts/app.js'))) .replace(/{{style}}/g, fs.readFileSync(path.join(__dirname, '/public/stylesheets/style.css'))); const middleware = (req, res, next) => { - socketIoInit(req.socket.server, config); + socketIoInit(req.socket.server, validatedConfig); const startTime = process.hrtime(); - if (req.path === config.path) { - if (config.iframe) { + if (req.path === validatedConfig.path) { + if (validatedConfig.iframe) { if (res.removeHeader) { res.removeHeader('X-Frame-Options'); } @@ -36,7 +34,7 @@ const middlewareWrapper = config => { res.send(renderedHtml); } else { onHeaders(res, () => { - onHeadersListener(res.statusCode, startTime, config.spans); + onHeadersListener(res.statusCode, startTime, validatedConfig.spans); }); next();