Skip to content

Commit 9990ed5

Browse files
committed
fix(changelog): fix cli generate
1 parent 11896bf commit 9990ed5

1 file changed

Lines changed: 36 additions & 34 deletions

File tree

tools/changelog.js

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -55,50 +55,52 @@ yargs(hideBin(process.argv))
5555
process.stdout.write(`${latestMajorVersion}.${Number(latestMinorVersion)+1}.0-SNAPSHOT`);
5656
});
5757
})
58-
.command('generate', 'generate changelog', () => {}, (argv) => {// gitSemverTags().then((tags) => {
59-
const tagsToGenerate = [];
60-
const [ latestMajorVersion, latestMinorVersion, latestPatchVersion ] = tags[0].split('.');
58+
.command('generate', 'generate changelog', () => {}, (argv) => {
59+
gitSemverTags().then((tags) => {
60+
const tagsToGenerate = [];
61+
const [ latestMajorVersion, latestMinorVersion, latestPatchVersion ] = tags[0].split('.');
6162

62-
for (let i = latestPatchVersion; i >= 0; i--) {
63-
tagsToGenerate.push(`${latestMajorVersion}.${latestMinorVersion}.${i}`);
64-
}
63+
for (let i = latestPatchVersion; i >= 0; i--) {
64+
tagsToGenerate.push(`${latestMajorVersion}.${latestMinorVersion}.${i}`);
65+
}
6566

66-
// we need last release before
67-
const beforeTag = tags[tags.findIndex((val) => val === tagsToGenerate[tagsToGenerate.length - 1]) + 1];
68-
const majorTagRelease = tagsToGenerate[tagsToGenerate.length - 1];
69-
const changesList = [];
67+
// we need last release before
68+
const beforeTag = tags[tags.findIndex((val) => val === tagsToGenerate[tagsToGenerate.length - 1]) + 1];
69+
const majorTagRelease = tagsToGenerate[tagsToGenerate.length - 1];
70+
const changesList = [];
7071

71-
// we have minor patches
72-
if (tagsToGenerate.length > 1) {
73-
const latestMinorTag = tagsToGenerate[0];
72+
// we have minor patches
73+
if (tagsToGenerate.length > 1) {
74+
const latestMinorTag = tagsToGenerate[0];
7475

75-
// get change between new and last versions
76-
changesList.push(`## ${latestMinorTag}\n\n`);
76+
// get change between new and last versions
77+
changesList.push(`## ${latestMinorTag}\n\n`);
78+
let changesSpawn;
79+
if (tagsToGenerate[tagsToGenerate.length - 2] === latestMinorTag) {
80+
changesSpawn = spawnSync('git', ['log', `${majorTagRelease}...${latestMinorTag}`, '--oneline']);
81+
} else {
82+
changesSpawn = spawnSync('git', ['log', `${tagsToGenerate[1]}...${latestMinorTag}`, '--oneline']);
83+
}
84+
changesList.push(...changes(changesSpawn.stdout.toString().split('\n')));
85+
}
86+
87+
// major patch changelog
7788
let changesSpawn;
78-
if (tagsToGenerate[tagsToGenerate.length - 2] === latestMinorTag) {
79-
changesSpawn = spawnSync('git', ['log', `${majorTagRelease}...${latestMinorTag}`, '--oneline']);
89+
if (tagsToGenerate.length > 1 && tagsToGenerate[1] !== majorTagRelease) {
90+
changesList.push(`## ${latestMajorVersion}.${latestMinorVersion}.0 - ${tagsToGenerate[1]}\n\n`);
91+
changesSpawn = spawnSync('git', ['log', `${beforeTag}...${tagsToGenerate[1]}`, '--oneline']);
8092
} else {
81-
changesSpawn = spawnSync('git', ['log', `${tagsToGenerate[1]}...${latestMinorTag}`, '--oneline']);
93+
changesList.push(`## ${latestMajorVersion}.${latestMinorVersion}.0\n\n`);
94+
changesSpawn = spawnSync('git', ['log', `${beforeTag}...${majorTagRelease}`, '--oneline']);
8295
}
8396
changesList.push(...changes(changesSpawn.stdout.toString().split('\n')));
84-
}
8597

86-
// major patch changelog
87-
let changesSpawn;
88-
if (tagsToGenerate.length > 1 && tagsToGenerate[1] !== majorTagRelease) {
89-
changesList.push(`## ${latestMajorVersion}.${latestMinorVersion}.0 - ${tagsToGenerate[1]}\n\n`);
90-
changesSpawn = spawnSync('git', ['log', `${beforeTag}...${tagsToGenerate[1]}`, '--oneline']);
91-
} else {
92-
changesList.push(`## ${latestMajorVersion}.${latestMinorVersion}.0\n\n`);
93-
changesSpawn = spawnSync('git', ['log', `${beforeTag}...${majorTagRelease}`, '--oneline']);
94-
}
95-
changesList.push(...changes(changesSpawn.stdout.toString().split('\n')));
96-
97-
for (const output of changesList) {
98-
for (const line of output) {
99-
process.stdout.write(line);
98+
for (const output of changesList) {
99+
for (const line of output) {
100+
process.stdout.write(line);
101+
}
100102
}
101-
}
103+
})
102104
})
103105
.demandCommand()
104106
.parse()

0 commit comments

Comments
 (0)