zemdomu 1.3.0 → 1.3.3

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/out/cli.js ADDED
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const glob_1 = __importDefault(require("glob"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const project_linter_1 = require("./project-linter");
10
+ function parsePatterns(inputs) {
11
+ const result = [];
12
+ for (const input of inputs) {
13
+ const splits = input
14
+ .split(/\r?\n/)
15
+ .flatMap((p) => p.split(/[ ,]+/))
16
+ .filter(Boolean);
17
+ result.push(...splits);
18
+ }
19
+ return result;
20
+ }
21
+ async function run() {
22
+ var _a;
23
+ const args = process.argv.slice(2);
24
+ const rawPatterns = [];
25
+ const customRules = [];
26
+ let cross = false;
27
+ let depth;
28
+ for (let i = 0; i < args.length; i++) {
29
+ const arg = args[i];
30
+ if (arg === '--custom' || arg === '-c') {
31
+ const file = args[++i];
32
+ if (!file)
33
+ throw new Error('Missing file for --custom');
34
+ const resolved = path_1.default.resolve(file);
35
+ const customDir = path_1.default.resolve('custom-rules');
36
+ const relative = path_1.default.relative(customDir, resolved);
37
+ if (relative.startsWith('..') || path_1.default.isAbsolute(relative)) {
38
+ throw new Error('Custom rule file must be inside ./custom-rules');
39
+ }
40
+ const mod = require(resolved);
41
+ const rules = (_a = mod.default) !== null && _a !== void 0 ? _a : mod;
42
+ if (Array.isArray(rules))
43
+ customRules.push(...rules);
44
+ else
45
+ customRules.push(rules);
46
+ }
47
+ else if (arg === '--cross') {
48
+ cross = true;
49
+ }
50
+ else if (arg === '--cross-depth') {
51
+ const val = args[++i];
52
+ if (!val)
53
+ throw new Error('Missing value for --cross-depth');
54
+ depth = parseInt(val, 10);
55
+ if (isNaN(depth))
56
+ throw new Error('Invalid number for --cross-depth');
57
+ cross = true;
58
+ }
59
+ else {
60
+ rawPatterns.push(arg);
61
+ }
62
+ }
63
+ const patterns = parsePatterns(rawPatterns);
64
+ if (patterns.length === 0) {
65
+ patterns.push('**/*.{html,jsx,tsx}');
66
+ }
67
+ const files = new Set();
68
+ for (const pattern of patterns) {
69
+ const matches = glob_1.default.sync(pattern, { nodir: true });
70
+ for (const m of matches)
71
+ files.add(m);
72
+ }
73
+ const linter = new project_linter_1.ProjectLinter({ customRules, crossComponentAnalysis: cross, crossComponentDepth: depth });
74
+ const results = await linter.lintFiles(Array.from(files));
75
+ let hasIssues = false;
76
+ for (const [file, issues] of results.entries()) {
77
+ for (const issue of issues) {
78
+ console.error(`${file}:${issue.line + 1}:${issue.column + 1} ${issue.rule}: ${issue.message}`);
79
+ hasIssues = true;
80
+ }
81
+ }
82
+ if (hasIssues)
83
+ process.exit(1);
84
+ }
85
+ run().catch((e) => {
86
+ console.error(e);
87
+ process.exit(1);
88
+ });