core/plugins/manifest.governance.plugin.ts
core/plugins/manifest.governance.plugin.ts is a file in GovLab Docs. 31 lines of code and 7 definitions.
import { selfGovernedField, selfGovernedShape } from "#configuration/strings/manifest.strings";
import type { ManifestPlugin } from "#types/manifest.types";
import { SELF_GOVERNED_KEY } from "#configuration/constants/manifest.constants";
import { isNonEmptyString } from "#core/predicates/readme.predicate";
import { isPlainRecord } from "#core/predicates/record.predicate";
const REQUIRED_FIELDS: readonly string[] = ["checker", "paths"];
const OPTIONAL_FIELDS: readonly string[] = ["tests", "writes"];
export const plugin: ManifestPlugin = {
contribute(manifest, entry) {
if (isPlainRecord(manifest[SELF_GOVERNED_KEY])) {
entry[SELF_GOVERNED_KEY] = true;
}
},
name: "self-governance",
section: {
keys: [SELF_GOVERNED_KEY],
validate(manifest) {
const declared = manifest[SELF_GOVERNED_KEY];
if (declared === undefined) {
return [];
}
if (!isPlainRecord(declared)) {
return [selfGovernedShape(SELF_GOVERNED_KEY)];
}
const optional = OPTIONAL_FIELDS.filter((field) => Object.hasOwn(declared, field));
return [...REQUIRED_FIELDS, ...optional]
.filter((field) => !isNonEmptyString(declared[field]))
.map((field) => selfGovernedField(SELF_GOVERNED_KEY, field));
},
},
};