UNPKG

@eljs/release

Version:
137 lines (135 loc) 5.33 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/utils/changelog.ts var changelog_exports = {}; __export(changelog_exports, { getChangelog: () => getChangelog }); module.exports = __toCommonJS(changelog_exports); var import_concat_stream = __toESM(require("concat-stream")); async function getChangelog(options) { const conventionalChangelog = (await import("conventional-changelog")).default; const conventionalChangelogOptions = await getConventionalChangelogOptions(options); return new Promise((resolve, reject) => { const stream = conventionalChangelog(...conventionalChangelogOptions); stream.pipe((0, import_concat_stream.default)((result) => resolve(result.toString().trim()))); stream.on("error", reject); }); } async function getConventionalChangelogOptions(options) { const { cwd = process.cwd(), independent = false, preset } = options; if (preset) { return [ { cwd, preset } ]; } else { const config = (await import("@eljs/conventional-changelog-preset")).default; const tagPrefix = independent ? /^.+@/ : ""; return [ // https://github.com/conventional-changelog/conventional-changelog/blob/standard-changelog-v6.0.0/packages/conventional-changelog/index.js#L21 // options { cwd, config, tagPrefix }, // context { commit: "commit" }, // gitRawCommitsOpts {}, // parserOpts {}, { // https://github.com/conventional-changelog/conventional-changelog/blob/standard-changelog-v6.0.0/packages/conventional-changelog-core/lib/merge-config.js#L305 finalizeContext: function(context, writerOpts, filteredCommits, keyCommit, originalCommits) { const semverTags = context.gitSemverTags; const firstCommit = originalCommits[0]; const lastCommit = originalCommits[originalCommits.length - 1]; const firstCommitHash = firstCommit ? firstCommit.hash : null; const lastCommitHash = lastCommit ? lastCommit.hash : null; if ((!context.currentTag || !context.previousTag) && keyCommit) { const match = /tag:\s*(.+?)[,)]/gi.exec(keyCommit.gitTags); const currentTag = context.currentTag; context.currentTag = currentTag || match ? match == null ? void 0 : match[1] : null; const index = semverTags.indexOf(context.currentTag); if (index === -1) { context.currentTag = currentTag || null; } else { const previousTag = context.previousTag = semverTags[index + 1]; if (!previousTag) { context.previousTag = context.previousTag || lastCommitHash; } } } else { context.previousTag = context.previousTag || semverTags[0]; if (context.version === "Unreleased") { context.currentTag = context.currentTag || firstCommitHash; } else if (!context.currentTag) { context.currentTag = guessNextTag(context, independent); } } if (typeof context.linkCompare !== "boolean" && context.previousTag && context.currentTag) { context.linkCompare = true; } return context; } } ]; } } function guessNextTag(context, independent) { const { previousTag, version } = context; if (independent && previousTag) { return previousTag.replace( /(\d+\.\d+\.\d+)/, version[0] === "v" ? version.slice(1) : version ); } if (previousTag) { if (previousTag[0] === "v" && version[0] !== "v") { return "v" + version; } if (previousTag[0] !== "v" && version[0] === "v") { return version.replace(/^v/, ""); } return version; } if (version[0] !== "v") { return "v" + version; } return version; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { getChangelog });