changelog-guru
Version:
Git changelog generator
56 lines (55 loc) • 3.21 kB
JavaScript
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _SectionGroupRule_blocks, _SectionGroupRule_types;
import TaskTree from 'tasktree-cli';
import { findSame, unify } from '../../utils/text.js';
import { SectionPosition } from '../entities/Section.js';
import { BaseRule } from './BaseRule.js';
class SectionGroupRule extends BaseRule {
constructor(config) {
super(config);
_SectionGroupRule_blocks.set(this, new Map());
_SectionGroupRule_types.set(this, []);
__classPrivateFieldSet(this, _SectionGroupRule_types, [...Object.values(this.config)].map(({ types }) => types).flat(), "f");
if (__classPrivateFieldGet(this, _SectionGroupRule_types, "f").length > new Set(__classPrivateFieldGet(this, _SectionGroupRule_types, "f")).size) {
TaskTree.fail('One commit type assigned to {bold >2} sections');
}
}
lint({ type, task }) {
if (type) {
const key = findSame(type, __classPrivateFieldGet(this, _SectionGroupRule_types, "f"));
if (!key)
task.error(`Commit type {bold ${type}} is not assigned with section`);
}
}
parse({ commit }) {
if (commit.type) {
const name = findSame(commit.type, __classPrivateFieldGet(this, _SectionGroupRule_types, "f"));
if (name && __classPrivateFieldGet(this, _SectionGroupRule_blocks, "f").has(name)) {
const block = __classPrivateFieldGet(this, _SectionGroupRule_blocks, "f").get(name);
if (block)
block.add(commit);
}
}
}
prepare({ context }) {
Object.entries(this.config).forEach(([name, { emoji, types }], order) => {
if (Array.isArray(types) && types.length) {
const section = context.addSection({ name, position: SectionPosition.Body, order, emoji });
if (section)
types.forEach(type => __classPrivateFieldGet(this, _SectionGroupRule_blocks, "f").set(unify(type), section));
}
});
}
}
_SectionGroupRule_blocks = new WeakMap(), _SectionGroupRule_types = new WeakMap();
export default SectionGroupRule;