Skip to content

Commit

Permalink
Dependencies, CI & Eslint upgrade, automate release process (#84)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
RafalWilinski authored Jul 29, 2017
1 parent 933fcab commit 1f2b9b0
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 32 deletions.
15 changes: 11 additions & 4 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]:RafalWilinski/express-status-monitor.git

deployment:
npm:
branch: master
commands:
- echo -e "$NPM_USERNAME\nNPM_PASSWORD\nNPM_EMAIL" | npm login
- npm run publish
24 changes: 14 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down Expand Up @@ -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
}
5 changes: 2 additions & 3 deletions src/helpers/gather-os-metrics.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -17,7 +16,7 @@ module.exports = (io, span) => {

pidusage.stat(process.pid, (err, stat) => {
if (err) {
console.error(err);
debug(err);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/socket-io-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
Expand Down
5 changes: 0 additions & 5 deletions src/helpers/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 7 additions & 9 deletions src/middleware-wrapper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint no-param-reassign: "off" */

const fs = require('fs');
const path = require('path');
const onHeaders = require('on-headers');
Expand All @@ -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');
}
Expand All @@ -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();
Expand Down

0 comments on commit 1f2b9b0

Please sign in to comment.