Skip to content

Commit

Permalink
fix(changelog): fix issues with ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed Oct 28, 2023
1 parent dd7e731 commit 0f2324a
Showing 1 changed file with 55 additions and 68 deletions.
123 changes: 55 additions & 68 deletions tools/changelog.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,61 @@
import spawnSync from 'child_process';
import {spawnSync} from 'child_process';

import gitSemverTags from 'git-semver-tags';
import argv from 'yargs'
argv
.usage('node tools/changelog.js <cmd> [args]')
.option('escape', {
description: 'Escapes outpu (useful for github action)',
type: 'boolean',
})
.command('generate', 'generate changelog')
.command('nextTag', 'get next tag')
.command('nextTagMajor', 'get next major tag')
.command('cli [commit]', 'create changelog between commits/tags', (yargs) => {
yargs.demandOption(['commit'], 'Please provide commit or tag argument to work with this tool');
yargs.positional('commit', {
type: 'string',
describe: 'commit(preferred) or tag interval e.g. 9.0.3 or 9.0.2..9.0.3',
});
import yargs from 'yargs'
import { hideBin } from 'yargs/helpers'

yargs(hideBin(process.argv))
.command('cli <commit>', 'create changelog between commits/tags', (yargs) => {
return yargs
.positional('commit', {
describe: 'commit(preferred) or tag interval e.g. 9.0.3 or 9.0.2..9.0.3',
type: 'string',
})
}, (argv) => {
const changesSpawn = spawnSync('git', ['log', argv.commit, '--oneline']);
for (const output of changes(changesSpawn.stdout.toString().split('\n'))) {
process.stdout.write(output);
}
})
.demandCommand()
.help()
.argv;

if (argv._[0] === 'nextTag') {
gitSemverTags(function(err, tags) {
const latestTag = tags[0];
.command('nextTagMajor', 'get next major tag', () => {}, (argv) => {
gitSemverTags().then((tags) => {
const latestTag = tags[0];

const changesList = [];
const changesSpawn = spawnSync('git', ['log', `${latestTag}...HEAD`, '--oneline']);
changesList.push(...changes(changesSpawn.stdout.toString().split('\n')));

const [ latestMajorVersion, latestMinorVersion, latestPatchVersion ] = tags[0].split('.');
const changesList = [];
const changesSpawn = spawnSync('git', ['log', `${latestTag}...HEAD`, '--oneline']);
changesList.push(...changes(changesSpawn.stdout.toString().split('\n')));

if (changesList.includes('### BREAKING CHANGES\n')) {
const [ latestMajorVersion, latestMinorVersion, latestPatchVersion ] = tags[0].split('.');
process.stdout.write(`${Number(latestMajorVersion)+1}.0.0`);
} else if (changesList.join().includes('-feat-blue')) {
// new tag
process.stdout.write(`${latestMajorVersion}.${Number(latestMinorVersion)+1}.0`);
} else {
process.stdout.write(`${latestMajorVersion}.${latestMinorVersion}.${Number(latestPatchVersion)+1}`);
}
});
}

if (argv._[0] === 'nextTagMajor') {
gitSemverTags(function(err, tags) {
const latestTag = tags[0];

const changesList = [];
const changesSpawn = spawnSync('git', ['log', `${latestTag}...HEAD`, '--oneline']);
changesList.push(...changes(changesSpawn.stdout.toString().split('\n')));

const [ latestMajorVersion, latestMinorVersion, latestPatchVersion ] = tags[0].split('.');
process.stdout.write(`${Number(latestMajorVersion)+1}.0.0`);
});
}

if (argv._[0] === 'nextSnapshot') {
gitSemverTags(function(err, tags) {
const [ latestMajorVersion, latestMinorVersion ] = tags[0].split('.');
process.stdout.write(`${latestMajorVersion}.${Number(latestMinorVersion)+1}.0-SNAPSHOT`);
});
}

if (argv._[0] === 'generate') {
gitSemverTags(function(err, tags) {
});
})
.command('nextTag', 'get next tag', () => {}, (argv) => {
gitSemverTags().then((tags) => {
const latestTag = tags[0];

const changesList = [];
const changesSpawn = spawnSync('git', ['log', `${latestTag}...HEAD`, '--oneline']);
changesList.push(...changes(changesSpawn.stdout.toString().split('\n')));

const [ latestMajorVersion, latestMinorVersion, latestPatchVersion ] = tags[0].split('.');

if (changesList.includes('### BREAKING CHANGES\n')) {
process.stdout.write(`${Number(latestMajorVersion)+1}.0.0`);
} else if (changesList.join().includes('-feat-blue')) {
// new tag
process.stdout.write(`${latestMajorVersion}.${Number(latestMinorVersion)+1}.0`);
} else {
process.stdout.write(`${latestMajorVersion}.${latestMinorVersion}.${Number(latestPatchVersion)+1}`);
}
});
})
.command('nextSnapshot', 'get next tag', () => {}, (argv) => {
gitSemverTags().then((tags) => {
const [ latestMajorVersion, latestMinorVersion ] = tags[0].split('.');
process.stdout.write(`${latestMajorVersion}.${Number(latestMinorVersion)+1}.0-SNAPSHOT`);
});
})
.command('generate', 'generate changelog', () => {}, (argv) => {// gitSemverTags().then((tags) => {
const tagsToGenerate = [];
const [ latestMajorVersion, latestMinorVersion, latestPatchVersion ] = tags[0].split('.');

Expand Down Expand Up @@ -109,14 +100,10 @@ if (argv._[0] === 'generate') {
}
}
});
}

if (argv._[0] === 'cli') {
const changesSpawn = spawnSync('git', ['log', argv.commit, '--oneline']);
for (const output of changes(changesSpawn.stdout.toString().split('\n'))) {
process.stdout.write(output);
}
}
})
.demandCommand()
.parse()

function changes(changesList) {
// sort alphabetically
Expand Down

0 comments on commit 0f2324a

Please sign in to comment.