Skip to content

Commit

Permalink
1.1.4
Browse files Browse the repository at this point in the history
- removes babel-register, ships a pre-compiled bundle
  • Loading branch information
gabrielcsapo committed Oct 25, 2017
1 parent e1de012 commit 9b9ebad
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 149 deletions.
22 changes: 22 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.storybook
/bin
/dist
/docs
/lib
/src
/stories
/test
/coverage
.babelrc
.eslintignore
.eslintrc
.gitignore
.travis.yml
CHANGELOG.md
index.js
jsdoc.json
tryitout.js
webpack.config.js
packed
.nyc_output
package-lock.json
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.1.4 (10/24/2017)

- removes babel-register, ships a pre-compiled bundle

# 1.1.3 (10/24/2017)

- fixes compatibility with older versions of node <8
Expand Down
133 changes: 0 additions & 133 deletions bin/index.js

This file was deleted.

138 changes: 132 additions & 6 deletions bin/lcov-server.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,137 @@
#!/usr/bin/env node

const semver = require('semver');
require('babel-polyfill');

if (semver.lt(process.version, '8.5.0')) {
// only shim pre 8 binaries
require('babel-polyfill');
require('babel-register');
const program = require('commander');
const http = require('http');
const https = require('https');
const fs = require('fs');
const Path = require('path');
const Url = require('url');
const updateNotifier = require('update-notifier');

const lcov = require('../lib/lcov');
const cobertura = require('../lib/cobertura');
const golang = require('../lib/golang');
const jacoco = require('../lib/jacoco');

const git = require('../lib/git');
const ci = require('../lib/ci');

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 { 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);
}

require('./index.js');
if(serve) {
process.env.MONGO_URL = process.env.MONGO_URL || db;

require('../index');
} else {
const parsedUrl = Url.parse(upload);

let input = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', (chunk) => {
input += chunk;
});
process.stdin.on('end', (async () => {
const env = ci();
const output = {
service_job_id: env.service_job_id,
service_pull_request: env.service_pull_request,
service_name: env.service_name,
source_files: [],
git: {
commit: env.commit,
branch: env.branch,
message: env.message,
committer_name: env.committer_name,
committer_email: env.committer_email
},
run_at: new Date()
};

let _lcov = {};
switch(parser) {
case 'lcov':
_lcov = await lcov.parse(input);
break;
case 'cobertura':
_lcov = await cobertura.parse(input);
break;
case 'golang':
_lcov = await golang.parse(input);
break;
case 'jacoco':
_lcov = await jacoco.parse(input);
break;
}

const _git = await git.parse();

// Go through and set the file contents
for (let i = 0; i < _lcov.length; i++) {
let path = basePath ? Path.resolve(process.cwd(), basePath, _lcov[i].file) : _lcov[i].file;

_lcov[i].source = fs.readFileSync(path).toString('utf8');
_lcov[i].title = _lcov[i].file.substring(_lcov[i].file.lastIndexOf('/') + 1, _lcov[i].file.length);
}

output['source_files'] = _lcov;
output['git'] = Object.assign(output['git'], _git);

const options = {
hostname: parsedUrl.hostname,
port: parsedUrl.port || 80,
path: '/api/upload',
method: 'POST',
headers: {
'Content-Type': 'application/json',
}
};
let operation = http;
let data = '';

if(parsedUrl.protocol == 'https:') {
options.port = 443;
operation = https;
}

let req = operation.request(options, (res) => {
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
try {
const response = JSON.parse(data);
if(response.error) {
console.error(response.error); // eslint-disable-line
} else {
console.log(`\n coverage sent successfully 💚 \n`); // eslint-disable-line
}
} catch(ex) {
console.log(`\n uhoh something went wrong, ${ex.toString()}`); // eslint-disable-line
}
});
});
req.write(JSON.stringify(output));
req.end();
}));
}
6 changes: 3 additions & 3 deletions dist/bundle.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lcov-server",
"version": "1.1.3",
"version": "1.1.4",
"description": "🎯 A simple lcov server & cli parser",
"main": "index.js",
"homepage": "https://github.com/gabrielcsapo/lcov-server#readme",
Expand All @@ -18,7 +18,9 @@
"lint": "eslint .",
"test": "tape test/lib/**/*.js test/index.js",
"coverage": "tap test/lib/**.js --coverage --coverage-report=lcov",
"build": "NODE_ENV=production webpack --progress",
"build": "npm run build:client && npm run build:server",
"build:server": "babel index.js --out-dir ./distributed && babel lib --out-dir ./distributed/lib && babel bin --out-dir ./distributed/bin && cp package.json ./distributed/ && cp -r dist ./distributed",
"build:client": "NODE_ENV=production webpack --progress",
"start": "./bin/lcov-server.js --serve",
"dev": "NODE_ENV=development webpack-dev-server --hot --port 5000",
"pack": "pkg bin/lcov-server.js -c package.json -o packed/lcov-server",
Expand All @@ -28,7 +30,7 @@
},
"author": "Gabriel J. Csapo <gabecsapo@gmail.com>",
"bin": {
"lcov-server": "./bin/lcov-server.js"
"lcov-server": "./distributed/bin/lcov-server.js"
},
"pkg": {
"scripts": [
Expand All @@ -43,33 +45,31 @@
],
"targets": [
"node8-macos-x64",
"node8-alpine-x64",
"node8-linux-x64",
"node8-win-x64"
]
},
"license": "Apache-2.0",
"dependencies": {
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-register": "^6.26.0",
"commander": "^2.11.0",
"compression": "^1.7.1",
"express": "^4.16.2",
"git-url-parse": "^7.0.1",
"mongoose": "^4.12.1",
"openbadge": "^1.0.4",
"semver": "^5.4.1",
"serve-static": "^1.13.1",
"update-notifier": "^2.3.0",
"xml2js": "^0.4.19"
},
"devDependencies": {
"@storybook/addon-knobs": "^3.2.12",
"@storybook/react": "^3.2.12",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-minify-webpack-plugin": "^0.2.0",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"body-parser": "^1.18.2",
"css-loader": "^0.28.7",
Expand Down

0 comments on commit 9b9ebad

Please sign in to comment.