changelog-guru
Version:
Git changelog generator
50 lines (49 loc) • 3.02 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 _ScopeRenameRule_names, _ScopeRenameRule_onlyPresented;
import { findSame, unify } from '../../utils/text.js';
import { BaseRule } from './BaseRule.js';
const MIN_SCOPE_SHORTNAME_LENGTH = 2;
class ScopeRenameRule extends BaseRule {
constructor(config) {
super(config);
_ScopeRenameRule_names.set(this, new Map());
_ScopeRenameRule_onlyPresented.set(this, false);
__classPrivateFieldSet(this, _ScopeRenameRule_onlyPresented, config.onlyPresented, "f");
__classPrivateFieldSet(this, _ScopeRenameRule_names, new Map(Object.entries(config.names).map(([abbr, name]) => [unify(abbr), name])), "f");
}
lint({ scope, task }) {
const names = [...__classPrivateFieldGet(this, _ScopeRenameRule_names, "f").keys()];
if (scope.length) {
scope.split(',').forEach(name => {
if (name.length < MIN_SCOPE_SHORTNAME_LENGTH)
task.error(`Scope name {bold ${name}} is too short`);
if (__classPrivateFieldGet(this, _ScopeRenameRule_onlyPresented, "f") && !findSame(name, names))
task.error(`Scope {bold ${name}} is not available`);
});
}
}
parse({ commit }) {
if (commit.scope) {
const scopes = commit.scope.split(',');
scopes.forEach(name => {
const actualName = findSame(name, [...__classPrivateFieldGet(this, _ScopeRenameRule_names, "f").keys()]);
const accent = actualName ? __classPrivateFieldGet(this, _ScopeRenameRule_names, "f").get(actualName) : undefined;
if (accent || (!__classPrivateFieldGet(this, _ScopeRenameRule_onlyPresented, "f") && name.length)) {
commit.accent((accent || name).trim());
}
});
}
}
}
_ScopeRenameRule_names = new WeakMap(), _ScopeRenameRule_onlyPresented = new WeakMap();
export default ScopeRenameRule;