Skip to content

Commit

Permalink
1.2.3
Browse files Browse the repository at this point in the history
- replaces openbadge with badgeit
- removes commander and makes arg parser more efficient
  • Loading branch information
gabrielcsapo committed Dec 8, 2017
1 parent aeb17fe commit bd4f4a7
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 47 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.2.3 (12/07/2017)

- replaces `openbadge` with `badgeit`
- removes commander and makes arg parser more efficient
- updates dependencies

# 1.2.2 (10/29/2017)

- fixes a bug where coverage.get would kill the entire server
Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,18 @@ npm install lcov-server -g
```
Usage: lcov-server [options]
Commands:
upload, --upload, -u [server ] Set the url to upload lcov data too (default: http://localhost:8080)
serve, -s, --serve Pass this option to startup a lcov-server instance
version, -v, --version output the version number
help, -h, --help output usage information
Options:
-V, --version output the version number
-u, --upload [server] Set the url to upload lcov data too
-s, --serve Pass this option to startup a lcov-server instance
-d, --db [db] Set the db connection
-p, --parser <parser> Set the parser value [lcov, cobertura, golang, jacoco], defaults to lcov
-bp, --basePath <path> The path that defines the base directory where the files that were covered will be located
-h, --help output usage information
db, -d, --db [db] Set the db connection (default: mongodb://localhost:32768/lcov-server)
parser, -p, --parser <parser> Set the parser value [lcov, cobertura, golang, jacoco], defaults to lcov (default: lcov)
basePath, -bp, --basePath <path> The path that defines the base directory where the files that were covered will be located
```

## Upload
Expand Down
77 changes: 64 additions & 13 deletions bin/lcov-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require('babel-polyfill');

const program = require('commander');
const updateNotifier = require('update-notifier');

const cli = require('../lib/cli');
Expand All @@ -11,21 +10,73 @@ const pkg = require('../package.json');

updateNotifier({pkg}).notify();

program
.version(pkg.version)
.option('-u, --upload [server]', 'Set the url to upload lcov data too', 'http://localhost:8080')
.option('-s, --serve', 'Pass this option to startup a lcov-server instance')
.option('-d, --db [db]', 'Set the db connection', 'mongodb://localhost:32768/lcov-server')
.option('-p, --parser <parser>', 'Set the parser value [lcov, cobertura, golang, jacoco], defaults to lcov', 'lcov')
.option('-bp, --basePath <path>', 'The path that defines the base directory where the files that were covered will be located')
.parse(process.argv);
const args = process.argv.slice(2);

let program = {};

args.forEach((a, i) => {
switch(a) {
case '-v':
case '--version':
console.log(`v${require('../package.json').version}`); // eslint-disable-line
process.exit(0);
break;
case 'help':
case '-h':
case '--help':
console.log(``+ // eslint-disable-line
`
Usage: lcov-server [options]
Commands:
upload, --upload, -u [server ] Set the url to upload lcov data too (default: http://localhost:8080)
serve, -s, --serve Pass this option to startup a lcov-server instance
version, -v, --version output the version number
help, -h, --help output usage information
Options:
db, -d, --db [db] Set the db connection (default: mongodb://localhost:32768/lcov-server)
parser, -p, --parser <parser> Set the parser value [lcov, cobertura, golang, jacoco], defaults to lcov (default: lcov)
basePath, -bp, --basePath <path> The path that defines the base directory where the files that were covered will be located
`);
process.exit(0);
break;
case '-db':
case '--db':
case 'db':
program.db = args[i + 1];
break;
case '-u':
case '--upload':
case 'upload':
program.upload = args[i + 1];
break;
case '-s':
case '--serve':
case 'serve':
program.serve = true;
break;
case '-p':
case '--parser':
case 'parser':
program.parser = args[i + 1];
if(['lcov', 'cobertura', 'golang', 'jacoco'].indexOf(program.parser) === -1) {
console.error(`parser ${program.parser} not supported`); // eslint-disable-line
process.exit(1);
}
break;
case '-bp':
case '--basePath':
case 'basePath':
program.basePath = args[i + 1];
break;
}
});

const { parser, upload, serve, db, basePath } = program;

if(parser && ['lcov', 'cobertura', 'golang', 'jacoco'].indexOf(parser) === -1) {
console.error(`parser ${parser} not supported`); // eslint-disable-line
process.exit(1);
}

if(serve) {
process.env.MONGO_URL = process.env.MONGO_URL || db;
Expand Down
18 changes: 7 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mongoose.connect(process.env.MONGO_URL, { useMongoClient: true }, function(error
});

const express = require('express');
const Badge = require('openbadge');
const Badge = require('badgeit');
const parse = require('git-url-parse');
const path = require('path');
const serveStatic = require('serve-static');
Expand Down Expand Up @@ -123,17 +123,13 @@ app.get('/badge/:service/:owner/:repo.svg', asyncMiddleware(async (req, res) =>
const percentage = parseInt((hit / found) * 100);
const color = percentage >= 85 ? '#3DB712' : percentage <= 85 && percentage >= 70 ? '#caa300' : '#cc5338';

Badge({ color: { right: color }, text: ['coverage', `${percentage}%`] }, function(err, badge) {
if(err) { throw new Error(err); }
res.set('Content-Type', 'image/svg+xml; charset=utf-8');
res.send(badge);
});
const badge = await Badge({ color: { right: color }, text: ['coverage', `${percentage}%`] });
res.set('Content-Type', 'image/svg+xml; charset=utf-8');
res.send(badge);
} catch(error) {
Badge({ color: { right: "#b63b3b" }, text: ['coverage', 'not found'] }, function(err, badge) {
if(err) { throw new Error(err); }
res.set('Content-Type', 'image/svg+xml; charset=utf-8');
res.send(badge);
});
const badge = await Badge({ color: { right: "#b63b3b" }, text: ['coverage', 'not found'] });
res.set('Content-Type', 'image/svg+xml; charset=utf-8');
res.send(badge);
}
}));

Expand Down
32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lcov-server",
"version": "1.2.2",
"version": "1.2.3",
"description": "🎯 A simple lcov server & cli parser",
"main": "index.js",
"homepage": "https://github.com/gabrielcsapo/lcov-server#readme",
Expand Down Expand Up @@ -52,20 +52,20 @@
"license": "Apache-2.0",
"dependencies": {
"babel-polyfill": "^6.26.0",
"commander": "^2.11.0",
"badgeit": "0.0.2",
"compression": "^1.7.1",
"express": "^4.16.2",
"git-url-parse": "^7.0.1",
"mongoose": "^4.12.4",
"moment": "^2.19.1",
"moment": "^2.19.3",
"mongoose": "^4.13.6",
"openbadge": "^1.0.4",
"serve-static": "^1.13.1",
"update-notifier": "^2.3.0",
"xml2js": "^0.4.19"
},
"devDependencies": {
"@storybook/addon-knobs": "^3.2.13",
"@storybook/react": "^3.2.13",
"@storybook/addon-knobs": "^3.2.17",
"@storybook/react": "^3.2.17",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
Expand All @@ -75,25 +75,25 @@
"body-parser": "^1.18.2",
"css-loader": "^0.28.7",
"docdash": "^0.4.0",
"eslint": "^4.10.0",
"eslint-plugin-react": "^7.4.0",
"eslint": "^4.12.1",
"eslint-plugin-react": "^7.5.1",
"getstorybook": "^1.7.0",
"highlight.js": "^9.12.0",
"jsdoc": "^3.5.4",
"pkg": "^4.2.5",
"pkg": "^4.2.6",
"prop-types": "^15.6.0",
"psychic.css": "0.0.1",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-router-dom": "^4.2.2",
"react-select": "^1.0.0-rc.10",
"react-select": "^1.1.0",
"shelljs": "^0.7.8",
"style-loader": "^0.19.0",
"tap": "^10.7.2",
"tap": "^11.0.0",
"tape": "^4.8.0",
"tryitout": "^0.3.7",
"webpack": "^3.8.1",
"webpack-dev-server": "^2.9.3",
"tryitout": "^1.2.0",
"webpack": "^3.10.0",
"webpack-dev-server": "^2.9.7",
"whatwg-fetch": "^2.0.3"
}
}

0 comments on commit bd4f4a7

Please sign in to comment.