@moneko/core 3.44.0 → 3.44.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/bin/commit-lint.d.mts +40 -0
- package/lib/bin/commit-lint.mjs +2 -0
- package/package.json +3 -2
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { loadFileSync, println } from '@moneko/utils';
|
|
3
|
+
import log from '../commom/log.mjs';
|
|
4
|
+
interface FormatProblem {
|
|
5
|
+
level: number;
|
|
6
|
+
message: string;
|
|
7
|
+
name: string;
|
|
8
|
+
}
|
|
9
|
+
interface FormatResult {
|
|
10
|
+
valid: boolean;
|
|
11
|
+
errors: FormatProblem[];
|
|
12
|
+
warnings: FormatProblem[];
|
|
13
|
+
}
|
|
14
|
+
declare const LEVEL: {
|
|
15
|
+
readonly DISABLED: number;
|
|
16
|
+
readonly WARNING: number;
|
|
17
|
+
readonly ERROR: number;
|
|
18
|
+
};
|
|
19
|
+
declare const RULE_OUTCOME: {
|
|
20
|
+
readonly ALWAYS: string;
|
|
21
|
+
readonly NEVER: string;
|
|
22
|
+
};
|
|
23
|
+
declare function isSentenceCase(text: string);
|
|
24
|
+
declare function isStartCase(text: string);
|
|
25
|
+
declare function isPascalCase(text: string);
|
|
26
|
+
declare function isUpperCase(text: string);
|
|
27
|
+
interface CommitMessage {
|
|
28
|
+
header: string;
|
|
29
|
+
type: string;
|
|
30
|
+
subject: string;
|
|
31
|
+
body: string;
|
|
32
|
+
footer: string;
|
|
33
|
+
raw: string;
|
|
34
|
+
lines: string[];
|
|
35
|
+
}
|
|
36
|
+
declare function parseCommitMessage(message: string): CommitMessage;
|
|
37
|
+
type Rules = Record<string, [number, string, ...unknown[]]>;
|
|
38
|
+
declare function lint(message: string, rules: Rules);
|
|
39
|
+
declare function format(result: FormatResult);
|
|
40
|
+
declare function main();
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{loadFileSync as e,println as t}from"@moneko/utils";import a from"../commom/log.mjs";let s={DISABLED:0,WARNING:1,ERROR:2},n={ALWAYS:"always",NEVER:"never"};function r(e){return/^[A-Z][a-z\d\s]*$/.test(e)}function l(e){return/^([A-Z][a-z\d]*\s*)+$/.test(e)}function o(e){return/^([A-Z][a-z\d]*)+$/.test(e)}function c(e){return e===e.toUpperCase()}!function(){let i=process.argv[2];i||(a("Commit message file path is required."),process.exit(1));let m=e(i);null===m&&(a("Commit message cannot be empty"),process.exit(1));let u=function(e,t){let a=function(e){let t=e.split("\n"),a=t[0]||"",s=a.match(/^([a-zA-Z]+)(?:\([a-zA-Z0-9-]+\))?:\s*(.+)$/),n=s?s[1]:"",r=s?s[2]:a,l=1;for(;l<t.length&&""===t[l].trim();)l++;let o=t.length;for(let e=l,a=/^(BREAKING CHANGE|[A-Za-z-]+(?:\([A-Za-z-]+\))?:)/,s=t.length;e<s;e++)if(a.test(t[e])){o=e;break}return{header:a,type:n,subject:r,body:t.slice(l,o).join("\n"),footer:t.slice(o).join("\n"),raw:e,lines:t}}(e),i={valid:!0,errors:[],warnings:[]};return Object.entries(t).forEach(([e,t])=>{let[m,u,...b]=t;if(m===s.DISABLED)return;let p=!0,h="";switch(e){case"body-leading-blank":p=!a.body||a.lines.length>1&&""===a.lines[1].trim(),h="body must have leading blank line";break;case"body-max-line-length":{let e=b[0]||100;p=a.body.split("\n").every(t=>t.length<=e),h=`body's lines must not be longer than ${e} characters`;break}case"footer-leading-blank":p=!a.footer||""===a.lines[a.lines.length-a.footer.split("\n").length-1].trim(),h="footer must have leading blank line";break;case"footer-max-line-length":{let e=b[0]||100;p=a.footer.split("\n").every(t=>t.length<=e),h=`footer's lines must not be longer than ${e} characters`;break}case"header-max-length":{let e=b[0]||100;p=a.header.length<=e,h=`header must not be longer than ${e} characters`;break}case"header-trim":p=a.header.trim()===a.header,h="header must not have leading or trailing whitespace";break;case"subject-case":{let e=b[0]||[],t=a.subject.trim(),s={"sentence-case":r,"start-case":l,"pascal-case":o,"upper-case":c};p=!e.some(e=>s[e]&&s[e](t)),h=`subject must not be in ${e.join(", ")}`;break}case"subject-empty":p=""!==a.subject.trim(),h="subject cannot be empty";break;case"subject-full-stop":{let e=b[0]||".";p=!a.subject.trim().endsWith(e),h=`subject must not end with ${e}`;break}case"type-case":"lower-case"==(u===n.ALWAYS?"lower-case":"upper-case")?(p=a.type===a.type.toLowerCase(),h="type must be lower-case"):(p=a.type===a.type.toUpperCase(),h="type must be upper-case");break;case"type-empty":p=""!==a.type,h="type cannot be empty";break;case"type-enum":{let e=b[0]||[];p=e.includes(a.type.toLowerCase()),h=`type must be one of [${e.join(", ")}]`}}if(u===n.NEVER&&(p=!p,h=h.replace("must ","must not ").replace("cannot ","can ")),!p){let t={level:m,message:h,name:e};m===s.ERROR?(i.errors.push(t),i.valid=!1):m===s.WARNING&&i.warnings.push(t)}}),i}(m,{"body-leading-blank":[1,"always"],"body-max-line-length":[2,"always",100],"footer-leading-blank":[1,"always"],"footer-max-line-length":[2,"always",100],"header-max-length":[2,"always",100],"header-trim":[2,"always"],"subject-case":[2,"never",["sentence-case","start-case","pascal-case","upper-case"]],"subject-empty":[2,"never"],"subject-full-stop":[2,"never","."],"type-case":[2,"always","lower-case"],"type-empty":[2,"never"],"type-enum":[2,"always",["build","chore","ci","docs","feat","fix","perf","refactor","revert","style","test"]]});(function(e){let t=[" ","⚠","✖"],a={green:"\x1b[32m",yellow:"\x1b[33m",red:"\x1b[31m",gray:"\x1b[90m",reset:"\x1b[0m",bold:"\x1b[1m"},{errors:s=[],warnings:n=[]}=e,r=[...s,...n].map(e=>{let s=a[2===e.level?"red":"yellow"]+t[e.level]+a.reset;return`${s} ${e.message} ${a.gray}[${e.name}]${a.reset}`}),l=s.length>0?"✖":n.length?"⚠":"✔",o=s.length>0?a.red:n.length?a.yellow:a.green,c=r.length>0;return[...r,c?"":null,`${o}${l}${a.reset} ${a.gray}${a.bold}found ${s.length} problems, ${n.length} warnings${a.reset}`,c?"":null].filter(e=>null!==e)})(u).forEach(e=>{t(e)}),process.exit(u.valid?0:1)}();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moneko/core",
|
|
3
|
-
"version": "3.44.
|
|
3
|
+
"version": "3.44.2",
|
|
4
4
|
"description": "core",
|
|
5
5
|
"main": "lib/index.mjs",
|
|
6
6
|
"type": "module",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
},
|
|
11
11
|
"bin": {
|
|
12
12
|
"mo": "lib/bin/index.mjs",
|
|
13
|
-
"pure-lint": "lib/bin/pure-lint.mjs"
|
|
13
|
+
"pure-lint": "lib/bin/pure-lint.mjs",
|
|
14
|
+
"commit-lint": "lib/bin/commit-lint.mjs"
|
|
14
15
|
},
|
|
15
16
|
"exports": {
|
|
16
17
|
".": {
|