Skip to content

Commit

Permalink
Add eslint (#5)
Browse files Browse the repository at this point in the history
* add eslint

* bump version
  • Loading branch information
pamepeixinho authored Dec 24, 2018
1 parent bb567b3 commit 068feb8
Show file tree
Hide file tree
Showing 4 changed files with 1,794 additions and 1,098 deletions.
6 changes: 6 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "airbnb",
"env": {
"node": true
}
}
91 changes: 52 additions & 39 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,36 @@ const mkdirp = require('mkdirp');
const { get } = require('https');
const { readFile, writeFile } = require('fs');

const outputPath = _findArgument('output', './coverage');
const inputPath = _findArgument('input', './coverage/coverage-summary.json');
/**
* Will lookup the argument in the cli arguments list and will return a
* value passed as CLI arg (if found)
* Otherwise will return default value passed
* @param argName - name of hte argument to look for
* @param defaultOutput - default value to return if could not find argument in cli command
* @private
*/
const findArgument = (argName, defaultOutput) => {
if (!argName) {
return defaultOutput;
}

const index = process.argv.findIndex(a => a.match(argName))
if (index < 0) {
return defaultOutput;
}

try {
return process.argv[index + 1];
} catch (e) {
return defaultOutput;
}
}

const getColour = coverage => {

const outputPath = findArgument('output', './coverage');
const inputPath = findArgument('input', './coverage/coverage-summary.json');

const getColour = (coverage) => {
if (coverage < 80) {
return 'red';
}
Expand All @@ -32,58 +58,45 @@ const getBadge = (report, key) => {
}

const download = (url, cb) => {
get(url, res => {
get(url, (res) => {
let file = '';
res.on('data', chunk => (file += chunk));
res.on('data', (chunk) => {
file += chunk;
});
res.on('end', () => cb(null, file));
}).on('error', err => cb(err));
}

const getBadgeByKey = (report) => (key) => {
const writeBadgeInFolder = (key, res) => {
writeFile(`${outputPath}/badge-${key}.svg`, res, 'utf8', (writeError) => {
if (writeError) {
throw writeError;
}
});
}

const getBadgeByKey = report => (key) => {
const url = getBadge(report, key);

download(url, (err, res) => {
if (err) throw err
mkdirp(outputPath, function (err) {
if (err) {
console.error(`Could not create output directory ${err}`);
if (err) {
throw err;
}
mkdirp(outputPath, (folderError) => {
if (folderError) {
console.error(`Could not create output directory ${folderError}`);
} else {
writeFile(`${outputPath}/badge-${key}.svg`, res, 'utf8', err => {
if (err) throw err;
})
writeBadgeInFolder(key, res);
}
})
})
}

readFile(`${inputPath}`, 'utf8', (err, res) => {
if (err) {
throw err
throw err;
}

const report = JSON.parse(res);
reportKeys.forEach(getBadgeByKey(report));
})

/**
* Will lookup the argument in the cli arguments list and will return a value passed as CLI arg (if found)
* Otherwise will return default value passed
* @param argName - name of hte argument to look for
* @param defaultOutput - default value to return if could not find argument in cli command
* @private
*/
function _findArgument (argName, defaultOutput) {
if (!argName) {
return defaultOutput;
}

const index = process.argv.findIndex(a => a.match(argName))
if (index < 0) {
return defaultOutput;
}

try {
return process.argv[index + 1];
} catch (e) {
return defaultOutput;
}
}
});
Loading

0 comments on commit 068feb8

Please sign in to comment.