@speedy-js/mono
Version:
Monorepo development & continuous integration tooling.
63 lines • 2.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.changelog = void 0;
/**
* Module dependencies
*/
const fs_1 = require("fs");
const path_1 = require("path");
const helpers_1 = require("./helpers");
const shared_1 = require("../shared");
const pipelines_1 = require("./pipelines");
/**
* Expose `changelog`
*/
async function changelog(options = {}) {
options = {
beautify: false,
commit: false,
gitPush: false,
attachAuthor: true,
authorNameType: 'name',
...options,
};
let { version } = options;
if (!version) {
try {
const config = (0, shared_1.resolveLernaConfig)(options.cwd);
version = config === null || config === void 0 ? void 0 : config.data.version;
}
catch (e) {
// dot not handle it for now
}
if (!version) {
const pkgJson = (0, shared_1.resolvePackageJson)();
version = pkgJson.version;
}
}
const changelogPath = (0, path_1.join)(options.cwd, 'CHANGELOG.md');
const isFirst = !(0, fs_1.existsSync)(changelogPath);
await (0, helpers_1.generateChangelog)(options.cwd, isFirst);
let changelogContent = (0, fs_1.readFileSync)(changelogPath, 'utf-8');
const processor = new pipelines_1.ChangelogProcessor(options.cwd, changelogContent);
processor.addProcessor(pipelines_1.ChangelogProcessor4NormalizeCommitUrl, {});
if (options.attachAuthor) {
processor.addProcessor(pipelines_1.ChangelogProcessor4AttachAuthor, {
displayType: options.authorNameType,
getAuthorPage: options.getAuthorPage,
});
}
if (options.beautify) {
processor.addProcessor(pipelines_1.ChangelogProcessor4Beautify, {});
}
changelogContent = processor.process();
(0, fs_1.writeFileSync)(changelogPath, changelogContent, 'utf-8');
if (options.commit) {
await (0, helpers_1.createChangelogCommit)(options.cwd, version);
}
if (options.gitPush) {
await (0, shared_1.gitPush)();
}
}
exports.changelog = changelog;
//# sourceMappingURL=index.js.map