forked from badges/shields
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gh-badge.js
executable file
·76 lines (71 loc) · 2.08 KB
/
gh-badge.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env node
var path = require('path');
var badge = require(path.join(__dirname, 'lib', 'badge.js'));
var svg2img = require(path.join(__dirname, 'lib', 'svg-to-img.js'));
var colorscheme = require(path.join(__dirname, 'lib', 'colorscheme.json'));
if (process.argv.length < 4) {
console.log('Usage: badge subject status [:colorscheme] [.output] [@style]');
console.log('Or: badge subject status right-color [left-color] [.output] [@style]');
console.log();
console.log(' colorscheme: one of '
+ Object.keys(colorscheme).join(', ') + '.');
console.log(' left-color, right-color:');
console.log(' #xxx (three hex digits)');
console.log(' #xxxxxx (six hex digits)');
console.log(' color (CSS color)');
console.log(' output:');
console.log(' svg, png, jpg, or gif');
console.log();
console.log('Eg: badge cactus grown :green @flat');
console.log();
process.exit();
}
// Find a format specifier.
var format = 'svg';
var style = '';
for (var i = 4; i < process.argv.length; i++) {
if (process.argv[i][0] === '.') {
format = process.argv[i].slice(1);
process.argv.splice(i, 1);
continue;
}
if (process.argv[i][0] === '@') {
style = process.argv[i].slice(1);
process.argv.splice(i, 1);
continue;
}
}
var subject = process.argv[2];
var status = process.argv[3];
var color = process.argv[4] || ':green';
var colorA = process.argv[5];
var badgeData = {text: [subject, status], format: format};
if (style) {
badgeData.template = style;
}
if (color[0] === ':') {
color = color.slice(1);
if (colorscheme[color] == null) {
// Colorscheme not found.
console.error('Invalid color scheme.');
process.exit(1);
}
badgeData.colorscheme = color;
} else {
badgeData.colorB = color;
if (colorA) { badgeData.colorA = colorA; }
}
badge(badgeData, function produceOutput(svg) {
if (/png|jpg|gif/.test(format)) {
svg2img(svg, format, function (err, data) {
if (err) {
console.error(err);
process.exit(1);
} else {
process.stdout.write(data);
}
});
} else {
console.log(svg);
}
});