@kazupon/lerna-changelog
Version:
Generate a changelog for a lerna monorepo
93 lines (92 loc) • 3.53 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.run = void 0;
const chalk_1 = __importDefault(require("chalk"));
const cli_highlight_1 = require("cli-highlight");
const changelog_1 = __importDefault(require("./changelog"));
const configuration_1 = require("./configuration");
const configuration_error_1 = __importDefault(require("./configuration-error"));
const yargs_1 = __importDefault(require("yargs"));
async function run() {
const argv = yargs_1.default
.usage('lerna-changelog [options]')
.options({
from: {
type: 'string',
desc: 'A git tag or commit hash that determines the lower bound of the range of commits',
defaultDescription: 'latest tagged commit'
},
to: {
type: 'string',
desc: 'A git tag or commit hash that determines the upper bound of the range of commits'
},
'tag-from': {
hidden: true,
type: 'string',
desc: 'A git tag that determines the lower bound of the range of commits (defaults to last available)'
},
'tag-to': {
hidden: true,
type: 'string',
desc: 'A git tag that determines the upper bound of the range of commits'
},
'next-version': {
type: 'string',
desc: 'The name of the next version',
default: 'Unreleased'
},
'next-version-from-metadata': {
type: 'boolean',
desc: 'Infer the name of the next version from package metadata',
default: false
},
package: {
type: 'string',
desc: 'The name of the package to generate a changelog for monorepo',
default: ''
}
})
.example('lerna-changelog', 'create a changelog for the changes after the latest available tag, under "Unreleased" section')
.example('lerna-changelog --from=0.1.0 --to=0.3.0', 'create a changelog for the changes in all tags within the given range')
.epilog('For more information, see https://github.com/lerna/lerna-changelog')
.wrap(Math.min(100, yargs_1.default.terminalWidth()))
.parse();
const options = {
tagFrom: argv['from'] || argv['tag-from'],
tagTo: argv['to'] || argv['tag-to']
};
try {
const config = await configuration_1.load({
nextVersionFromMetadata: argv['next-version-from-metadata']
});
if (argv['next-version']) {
config.nextVersion = argv['next-version'];
}
if (argv['package']) {
config.package = argv['package'];
}
const result = await new changelog_1.default(config).createMarkdown(options);
const highlighted = cli_highlight_1.highlight(result, {
language: 'Markdown',
theme: {
section: chalk_1.default.bold,
string: chalk_1.default.hex('#0366d6'),
link: chalk_1.default.dim
}
});
console.log(highlighted);
}
catch (e) {
if (e instanceof configuration_error_1.default) {
console.log(chalk_1.default.red(e.message));
}
else {
console.log(chalk_1.default.red(e.stack));
}
process.exitCode = 1;
}
}
exports.run = run;