-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
103 lines (92 loc) · 3.67 KB
/
index.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env node
const https = require('https');
const cmp = require('semver-compare');
const colors = require('colors');
const cliSelect = require('cli-select');
const program = require('commander').program;
const exec = require('child_process').exec;
program.version('0.0.1');
program
.option('-c, --component <component>', 'component name - without `ds` prefix')
.option('-s, --start-version <startVersion>', 'start version of component', '0.1.0')
.option('-e, --end-version <endVersion>', 'end version of component')
.option('-n, --skip-notes', 'skip version bumps');
program.parse(process.argv);
const { component, startVersion, endVersion, skipNotes } = program;
if (!component) {
exec('npm search @synerise/ds- --searchLimit=100 --json', (error, stdout, strerr) => {
if (error) {
console.log(colors.red(error));
}
const packages = JSON.parse(stdout).map(package => package.name);
console.log(packages.length)
cliSelect({
values: packages,
valueRenderer: (value) => value,
}).then(response => {
const packageName = response.value.replace('@synerise/ds-', '');
showChangelog(packageName);
});
});
} else {
showChangelog(component);
}
function showChangelog(package) {
https.get(`https://raw.githubusercontent.com/Synerise/synerise-design/master/packages/components/${package}/CHANGELOG.md`, (response) => {
let body = '';
response.on('data', chunk => body += chunk);
response.on('end', () => {
const parsedResponse = body.split('\n').filter(row => row !== '').filter(row => row[0] !== '#' || row[0] !== '*');
const arrayOfVersions = parsedResponse.reduce((result, currentValue, index) => {
if (currentValue.substr(0, 3) === '## ' || currentValue.substr(0, 2) === '# ') {
const version = currentValue.substring(currentValue.indexOf('[') + 1, currentValue.indexOf(']'));
result.data[version] = [];
result.currentVersion = version;
}
if (currentValue.substr(0, 3) === '###') {
result.currentType = currentValue.split('### ')[1];
}
if (currentValue[0] === '*' || currentValue[0] === '-') {
if (currentValue.substr(0, 9) === '**Note:**') {
result.data[result.currentVersion].push({
type: 'Note',
note: currentValue,
});
} else {
result.data[result.currentVersion].push({
type: result.currentType,
note: currentValue,
});
}
}
return result
}, {
data: {},
currentVersion: '',
currentType: ''
});
showResult(arrayOfVersions.data);
});
});
}
const getColor = (type) => {
const typeColor = {
Note: 'grey',
'Bug Fixes': 'red',
Features: 'green'
};
return typeColor[type];
}
const showResult = (versions) => {
const result = Object.keys(versions).filter(key => {
return cmp(key, startVersion) >= 0 && (endVersion ? cmp(key, endVersion) <= 0 : true);
});
result.forEach(v => {
if (!(versions[v].length === 1 && versions[v][0].type === 'Note' && skipNotes)) {
console.log(v.yellow.bold);
versions[v].forEach(n => {
console.log(colors[getColor(n.type)](n.note));
})
}
});
};