Repository navigation
Expand file tree
/
Copy pathvalidate-app-entry.js
More file actions
807 lines (690 loc) · 24 KB
/
Copy pathvalidate-app-entry.js
File metadata and controls
807 lines (690 loc) · 24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
#!/usr/bin/env node
/**
* Validate App Entry Script
*
* Usage: node validate-app-entry.js <app-name>
* Example: node validate-app-entry.js dsub
*/
const fs = require("fs");
const path = require("path");
const { execFileSync } = require("child_process");
// Detect if running in CI environment
const isCI = process.env.CI === "true" || process.env.GITHUB_ACTIONS === "true";
// Minimum stars an open source app's public repository should have.
// Keep in sync with content/en/docs/developers/adding-apps.md
const MIN_REPO_STARS = 15;
// Limits every catalog image must meet. convert-app-images.js produces
// images within them. Keep in sync with content/en/docs/developers/adding-apps.md
const MAX_IMAGE_DIMENSION = 1200;
const MAX_IMAGE_KB = 500;
const KEBAB_CASE = /^[a-z0-9]+(-[a-z0-9]+)*$/;
// Hosts known to expose a star count, so a lookup that comes back empty there
// is a broken check rather than an unsupported forge
const KNOWN_STAR_HOSTS = ["github.com", "gitlab.com", "codeberg.org"];
const USER_AGENT = "Navidrome-App-Validator/1.0";
// Deadline for a whole request, not a per-socket idle timer
const REQUEST_TIMEOUT = 10000; // 10 seconds
// A host that resolves to nothing is worth reporting; a dropped connection is
// noise, so it is ignored the way the URL check has always ignored it
const UNREACHABLE_ERROR_CODES = ["ENOTFOUND", "ECONNREFUSED"];
const TRANSIENT_ERROR_CODES = ["ETIMEDOUT", "ECONNRESET"];
// Classify a request that produced no response. fetch reports network trouble
// as a TypeError and keeps the real code and message on the cause.
function classifyRequestError(err) {
if (err.name === "TimeoutError") return { kind: "timeout" };
const cause = err.cause || err;
if (UNREACHABLE_ERROR_CODES.includes(cause.code)) {
return { kind: "unreachable" };
}
if (TRANSIENT_ERROR_CODES.includes(cause.code)) return { kind: "transient" };
return { kind: "failed", message: cause.message || err.message };
}
// Release the connection for a reply whose body will never be read. A HEAD
// reply has no body at all, hence the optional chain.
function discardBody(res) {
return res.body?.cancel().catch(() => {});
}
// Token that lifts the anonymous GitHub API rate limit. HUGO_GITHUB_TOKEN is
// the name the site build already uses, see layouts/partials/last-updated/
function githubToken() {
return process.env.GITHUB_TOKEN || process.env.HUGO_GITHUB_TOKEN;
}
// Run a git command, reporting only whether it succeeded
function gitSucceeds(args) {
try {
execFileSync("git", args, { stdio: "ignore" });
return true;
} catch (err) {
return false;
}
}
// The branch a new entry would be merged into. GITHUB_BASE_REF is set by
// GitHub Actions on pull requests; the rest covers local runs.
let cachedBaseRef;
function baseRef() {
if (cachedBaseRef !== undefined) return cachedBaseRef;
const candidates = [
process.env.VALIDATE_BASE_REF,
process.env.GITHUB_BASE_REF && `origin/${process.env.GITHUB_BASE_REF}`,
"origin/master",
"master",
].filter(Boolean);
cachedBaseRef =
candidates.find((ref) =>
// Resolve the ref first: cat-file alone cannot tell a missing ref from a
// missing path, and those two must not mean the same thing here
gitSucceeds(["rev-parse", "--verify", "--quiet", `${ref}^{commit}`])
) || null;
return cachedBaseRef;
}
// Is this entry absent from the base branch? Rules that only bind new entries
// ask this. Whenever git cannot answer - no repo, shallow clone, unknown base
// ref - the answer is "not new", so a rule can never block an existing entry.
function isNewApp(appName) {
const ref = baseRef();
if (!ref) return false;
return !gitSucceeds([
"cat-file",
"-e",
`${ref}:assets/apps/${appName}/index.yaml`,
]);
}
// Single HTTP entry point for every check in this file. Never throws -
// validation is advisory, so a broken host must not abort the run. Returns
// { res } for any reply, or { error } when nothing came back.
async function request(
url,
{ method = "GET", redirect = "follow", headers = {} } = {}
) {
try {
const res = await fetch(url, {
method,
redirect,
headers: { "User-Agent": USER_AGENT, ...headers },
signal: AbortSignal.timeout(REQUEST_TIMEOUT),
});
return { res };
} catch (err) {
return { error: classifyRequestError(err) };
}
}
// Status-only request. Redirects are reported rather than followed, and any
// body that does come back is dropped rather than read.
async function requestStatus(url, method) {
const { res, error } = await request(url, { method, redirect: "manual" });
if (res) await discardBody(res);
return { status: res?.status, error };
}
// Fetch and parse a JSON endpoint. Never throws. Returns the status next to
// the body, so callers can tell "this host has no such API" (404, or a
// non-JSON reply) from "the lookup failed" (no answer, throttled, server
// error). A null status means nothing usable came back at all.
async function fetchJson(url) {
const headers = { Accept: "application/json" };
// CI runners share outbound IPs, so anonymous GitHub API calls can be
// throttled by unrelated traffic. Authenticate whenever a token is around.
const token = githubToken();
if (token && url.startsWith("https://api.github.com/")) {
headers.Authorization = `Bearer ${token}`;
}
const { res, error } = await request(url, { headers });
if (error) return { status: null, json: null, error };
if (!res.ok) {
await discardBody(res);
return { status: res.status, json: null };
}
try {
return { status: res.status, json: await res.json() };
} catch (err) {
// Timing out mid-body is a failed lookup; anything else means the host
// answered with something that is not JSON, so it lacks this API
if (err.name === "TimeoutError") {
return { status: null, json: null, error: classifyRequestError(err) };
}
return { status: res.status, json: null };
}
}
// Split a repo URL into the pieces the star lookup needs, or null when it
// cannot be parsed. Deep links such as /tree/<ref>/... or /-/blob/... and a
// trailing .git are trimmed so the repository itself is left.
function parseRepoUrl(repoUrl) {
let parsedUrl;
try {
parsedUrl = new URL(repoUrl);
} catch (err) {
return null;
}
return {
host: parsedUrl.hostname.replace(/^www\./, ""),
origin: parsedUrl.origin,
repoPath: parsedUrl.pathname
.replace(/\.git$/, "")
.replace(/\/(-|tree|blob|src|commit)\/.*$/, "")
.replace(/^\/+|\/+$/g, ""),
};
}
// Build the API endpoints that can report a star count for a repo. GitHub
// gets a dedicated probe; any other host is tried as Gitea/Forgejo first and
// GitLab second, which covers Codeberg, self-hosted Gitea, and both
// gitlab.com and self-hosted GitLab.
function getStarProbes(repo) {
const [owner, name] = repo.repoPath.split("/");
if (!name) return [];
const ownerRepo = `${owner}/${name}`;
if (repo.host === "github.com") {
return [
{
host: "api.github.com",
url: `https://api.github.com/repos/${ownerRepo}`,
field: "stargazers_count",
},
];
}
return [
{
host: repo.host,
url: `${repo.origin}/api/v1/repos/${ownerRepo}`,
field: "stars_count",
},
{
host: repo.host,
// GitLab supports subgroups, so keep the full path here
url: `${repo.origin}/api/v4/projects/${encodeURIComponent(
repo.repoPath
)}`,
field: "star_count",
},
];
}
// Explain why a probe could not answer, or return null when the host simply
// does not speak that API and the next probe should be tried. A 404 or a
// non-JSON reply means "wrong forge"; a timeout, throttle, or server error
// means the check itself is broken and must not pass silently.
function probeFailure(host, status, error) {
// Reuse the vocabulary validateUrl already reports network trouble with
if (error) {
if (error.kind === "timeout") return `${host} request timed out`;
if (error.kind === "unreachable") return `${host} appears unreachable`;
if (error.kind === "transient") return `${host} dropped the connection`;
return `${host} lookup failed: ${error.message}`;
}
if (status === 401) return `${host} rejected the token (401)`;
if (status === 403 || status === 429) {
return host === "api.github.com"
? `${host} rate limit reached, set GITHUB_TOKEN to raise it`
: `${host} refused the request (${status})`;
}
if (status >= 500) return `${host} returned ${status}`;
return null;
}
// Color codes for terminal output (disabled in CI)
const colors = isCI
? {
reset: "",
red: "",
green: "",
yellow: "",
blue: "",
cyan: "",
}
: {
reset: "\x1b[0m",
red: "\x1b[31m",
green: "\x1b[32m",
yellow: "\x1b[33m",
blue: "\x1b[34m",
cyan: "\x1b[36m",
};
class AppValidator {
constructor(appName, options = {}) {
this.appName = appName;
this.appDir = path.join(process.cwd(), "assets", "apps", appName);
this.yamlPath = path.join(this.appDir, "index.yaml");
this.schemaPath = path.join(
process.cwd(),
"assets",
"apps",
"app-schema.json"
);
this.errors = [];
this.warnings = [];
this.quiet = options.quiet || false;
}
log(message, color = "reset") {
if (isCI) {
// In CI, just output plain text
console.log(message);
} else {
console.log(`${colors[color]}${message}${colors.reset}`);
}
}
addError(message) {
this.errors.push(message);
}
addWarning(message) {
this.warnings.push(message);
}
// Check if app directory exists
checkDirectory() {
if (!fs.existsSync(this.appDir)) {
this.addError(`App directory not found: ${this.appDir}`);
return false;
}
// The rule binds new entries, so older folders named before it existed
// only get a warning
if (!KEBAB_CASE.test(this.appName)) {
const message = `Folder name "${this.appName}" is not kebab-case (e.g. my-awesome-app)`;
if (isNewApp(this.appName)) {
this.addError(message);
} else {
this.addWarning(`${message} (existing entry, not blocking)`);
}
}
return true;
}
// Check if index.yaml exists and is valid YAML
async validateYaml() {
if (!fs.existsSync(this.yamlPath)) {
this.addError("index.yaml file not found");
return null;
}
try {
const yaml = require("js-yaml");
const content = fs.readFileSync(this.yamlPath, "utf8");
const data = yaml.load(content);
return data;
} catch (err) {
this.addError(`Invalid YAML syntax: ${err.message}`);
return null;
}
}
// Validate against JSON Schema
async validateSchema(data) {
if (!data) return;
try {
const Ajv = require("ajv");
const addFormats = require("ajv-formats");
const ajv = new Ajv({ allErrors: true, strict: false });
addFormats(ajv);
const schema = JSON.parse(fs.readFileSync(this.schemaPath, "utf8"));
const validate = ajv.compile(schema);
const valid = validate(data);
if (!valid) {
validate.errors.forEach((err) => {
const field = err.instancePath || "root";
const message = err.message;
const detail = err.params ? JSON.stringify(err.params) : "";
this.addError(
`Schema validation: ${field} ${message} ${detail}`.trim()
);
});
}
} catch (err) {
this.addError(`Schema validation failed: ${err.message}`);
}
}
// Check that image files exist and meet the catalog limits
async validateImages(data) {
if (!data || !data.screenshots) return;
const images = [];
if (data.screenshots.thumbnail) {
images.push({ file: data.screenshots.thumbnail, label: "Thumbnail image" });
}
if (Array.isArray(data.screenshots.gallery)) {
data.screenshots.gallery.forEach((file) =>
images.push({ file, label: "Gallery image" })
);
}
for (const image of images) {
await this.validateImage(image);
}
}
async validateImage({ file, label }) {
const fullPath = path.join(this.appDir, file);
if (!fs.existsSync(fullPath)) {
this.addError(`${label} not found: ${file}`);
return;
}
const sharp = require("sharp");
let metadata;
try {
metadata = await sharp(fullPath).metadata();
} catch (err) {
this.addError(`${label} ${file} is not a readable image: ${err.message}`);
return;
}
// Everything convert-app-images.js fixes goes into one error, with the
// command that fixes it
const problems = [];
if (metadata.format !== "webp") {
problems.push(`is ${metadata.format}, not WebP`);
} else if (path.extname(file).toLowerCase() !== ".webp") {
problems.push("is WebP but its name does not end in .webp");
}
const { width, height } = metadata;
if (Math.max(width, height) > MAX_IMAGE_DIMENSION) {
problems.push(
`is ${width}x${height}px (maximum: ${MAX_IMAGE_DIMENSION}px on the longest side)`
);
}
const sizeInKB = fs.statSync(fullPath).size / 1024;
if (sizeInKB > MAX_IMAGE_KB) {
problems.push(
`is ${Math.round(sizeInKB)}KB (maximum: ${MAX_IMAGE_KB}KB)`
);
}
if (problems.length > 0) {
this.addError(
`${label} ${file} ${problems.join(", ")}. Fix with: npm run convert:images ${this.appName}`
);
}
}
// Check for image files in the app folder that are not referenced in index.yaml
validateDanglingImages(data) {
if (!data) return;
// Collect all images referenced by the entry
const referenced = new Set();
if (data.screenshots) {
if (data.screenshots.thumbnail) {
referenced.add(data.screenshots.thumbnail);
}
if (Array.isArray(data.screenshots.gallery)) {
data.screenshots.gallery.forEach((img) => referenced.add(img));
}
}
const imageExtensions = [".png", ".webp", ".jpg", ".jpeg"];
let files;
try {
files = fs.readdirSync(this.appDir, { withFileTypes: true });
} catch (err) {
this.addError(`Unable to read app directory: ${err.message}`);
return;
}
files.forEach((dirent) => {
if (!dirent.isFile()) return;
const ext = path.extname(dirent.name).toLowerCase();
if (!imageExtensions.includes(ext)) return;
if (!referenced.has(dirent.name)) {
this.addError(
`Dangling image not referenced in index.yaml: ${dirent.name}`
);
}
});
}
// Validate URL (checks if it's reachable)
async validateUrl(url, description) {
if (!url) return;
// Basic URL format check
try {
new URL(url);
} catch (err) {
this.addError(`Invalid URL format for ${description}: ${url}`);
return;
}
// HEAD is enough to prove a URL resolves, and is cheaper than GET
let { status, error } = await requestStatus(url, "HEAD");
// Retry with GET if the server doesn't support HEAD
if (status === 405) {
({ status, error } = await requestStatus(url, "GET"));
// Only a timeout on the retry is worth reporting
if (error && error.kind !== "timeout") return;
}
if (error) {
if (error.kind === "timeout") {
this.addWarning(`${description} request timed out: ${url}`);
} else if (error.kind === "unreachable") {
this.addWarning(`${description} appears unreachable: ${url}`);
} else if (error.kind === "failed") {
this.addWarning(`${description} validation failed: ${error.message}`);
}
// "transient" stays quiet on purpose: a dropped connection says more
// about the network than about the URL. validateRepoStars is stricter,
// because a star lookup that fails quietly would look like a clean pass.
return;
}
// A redirect still proves the URL resolves, so only 4xx/5xx is a problem
if (status >= 400) {
this.addWarning(`${description} returned status ${status}: ${url}`);
}
}
// Validate all URLs in the app data
async validateUrls(data) {
if (!data) return;
const urlChecks = [];
// Main app URL
if (data.url) {
urlChecks.push(this.validateUrl(data.url, "App URL"));
}
// Repository URL
if (data.repoUrl) {
urlChecks.push(this.validateUrl(data.repoUrl, "Repository URL"));
}
// Platform store URLs
if (data.platforms) {
["android", "ios", "macos"].forEach((platform) => {
if (
data.platforms[platform] &&
typeof data.platforms[platform] === "object"
) {
if (data.platforms[platform].store) {
urlChecks.push(
this.validateUrl(
data.platforms[platform].store,
`${platform} store URL`
)
);
}
}
});
}
await Promise.all(urlChecks);
}
// Warn when an open source app's public repository has too few stars.
// Hosts without a usable star API (cgit, tangled, ...) are skipped silently.
async validateRepoStars(data) {
if (!data || !data.repoUrl) return;
// Same rule the site renders with, see layouts/partials/app-card.html
if (data.isOpenSource === false) return;
const repo = parseRepoUrl(data.repoUrl);
if (!repo) return; // validateUrl already reports a malformed repoUrl
let failure = null;
for (const probe of getStarProbes(repo)) {
const { status, json, error } = await fetchJson(probe.url);
const stars = json?.[probe.field];
if (typeof stars === "number") {
if (stars < MIN_REPO_STARS) {
// The rule binds new entries. An app already on the base branch
// keeps a warning, so the rule cannot block a PR that merely
// touches it - its star count can drop long after it was merged.
if (isNewApp(this.appName)) {
this.addError(
`Repository has ${stars} star(s), below the required minimum of ${MIN_REPO_STARS}: ${data.repoUrl}`
);
} else {
this.addWarning(
`Repository has ${stars} star(s), below the minimum of ${MIN_REPO_STARS} (existing entry, not blocking): ${data.repoUrl}`
);
}
}
return;
}
failure ??= probeFailure(probe.host, status, error);
}
// Keeping quiet here would make a broken lookup look like a clean pass, so
// say so - but only when the host was supposed to be able to answer
if (!failure && !KNOWN_STAR_HOSTS.includes(repo.host)) return;
const reason = failure ? ` - ${failure}` : "";
this.addWarning(
`Could not verify the star count (minimum ${MIN_REPO_STARS}): ${data.repoUrl}${reason}`
);
}
// Main validation method
async validate() {
if (!this.quiet) {
if (isCI) {
console.log(`App: ${this.appName}`);
} else {
this.log(
`\nValidating app: ${colors.cyan}${this.appName}${colors.reset}\n`
);
}
}
// Check directory
if (!this.checkDirectory()) {
return this.printResults();
}
// Validate YAML
const data = await this.validateYaml();
// Validate against schema
await this.validateSchema(data);
// Validate images
await this.validateImages(data);
// Check for dangling (unreferenced) images
this.validateDanglingImages(data);
// Validate URLs
if (!isCI && !this.quiet) {
this.log("Checking URLs (this may take a moment)...", "blue");
}
// Both only read data and append warnings, so they can run together
await Promise.all([this.validateUrls(data), this.validateRepoStars(data)]);
return this.printResults();
}
// Print validation results
printResults() {
if (this.errors.length === 0 && this.warnings.length === 0) {
if (!this.quiet) {
if (isCI) {
console.log("Status: PASSED ✅");
} else {
console.log("");
this.log(
"✅ Validation passed! No errors or warnings found.",
"green"
);
}
}
return 0;
}
if (isCI) {
console.log("Status: FAILED ❌\n");
}
if (this.errors.length > 0) {
if (isCI) {
console.log(`Errors (${this.errors.length}):`);
this.errors.forEach((error, index) => {
console.log(` ${index + 1}. ${error}`);
});
} else {
this.log(`\n❌ Found ${this.errors.length} error(s):`, "red");
this.errors.forEach((error, index) => {
this.log(` ${index + 1}. ${error}`, "red");
});
}
}
if (this.warnings.length > 0) {
if (isCI) {
console.log(`\nWarnings (${this.warnings.length}):`);
this.warnings.forEach((warning, index) => {
console.log(` ${index + 1}. ${warning}`);
});
} else {
this.log(`\n⚠️ Found ${this.warnings.length} warning(s):`, "yellow");
this.warnings.forEach((warning, index) => {
this.log(` ${index + 1}. ${warning}`, "yellow");
});
}
}
console.log("");
return this.errors.length > 0 ? 1 : 0;
}
}
// Main execution
async function main() {
// Parse arguments
const args = process.argv.slice(2);
const quiet = args.includes("-q") || args.includes("--quiet");
const appName = args.find((arg) => !arg.startsWith("-"));
// Check for required dependencies
const requiredModules = ["js-yaml", "ajv", "ajv-formats", "sharp"];
const missingModules = [];
for (const mod of requiredModules) {
try {
require.resolve(mod);
} catch (e) {
missingModules.push(mod);
}
}
if (missingModules.length > 0) {
console.error(
`${colors.red}Error: Missing required dependencies${colors.reset}`
);
console.log(`\nPlease install the following packages:`);
console.log(` npm install ${missingModules.join(" ")}\n`);
process.exit(1);
}
// If no app name provided, validate all apps
if (!appName) {
const appsDir = path.join(process.cwd(), "assets", "apps");
if (!fs.existsSync(appsDir)) {
console.error(
`${colors.red}Error: Apps directory not found: ${appsDir}${colors.reset}`
);
process.exit(1);
}
const appDirs = fs
.readdirSync(appsDir, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory() && dirent.name !== "_template")
.map((dirent) => dirent.name)
.sort();
if (appDirs.length === 0) {
console.log("No app entries found to validate");
process.exit(0);
}
// One GitHub API call per app busts the 60/hour anonymous limit, which
// would turn every star check into an "unverified" warning. Say it once
// here rather than once per app.
if (!githubToken()) {
console.log(
`${colors.yellow}Note:${colors.reset} checking every app needs a GitHub token.`
);
console.log(
"Without one the anonymous API limit runs out and star counts stay unverified."
);
console.log(" export GITHUB_TOKEN=$(gh auth token)\n");
}
if (!quiet) {
console.log(`Validating ${appDirs.length} app(s)...\n`);
}
let totalErrors = 0;
let failedApps = [];
for (const app of appDirs) {
const validator = new AppValidator(app, { quiet });
const exitCode = await validator.validate();
if (exitCode !== 0) {
totalErrors++;
failedApps.push(app);
}
// Add separator between apps (except for last one) when not quiet
if (!quiet && app !== appDirs[appDirs.length - 1]) {
console.log("\n" + "=".repeat(60) + "\n");
}
}
console.log("\n" + "=".repeat(60));
console.log("\nValidation Summary:");
console.log(` Total apps: ${appDirs.length}`);
console.log(` Passed: ${appDirs.length - totalErrors}`);
console.log(` Failed: ${totalErrors}`);
if (failedApps.length > 0) {
console.log(`\nFailed apps: ${failedApps.join(", ")}`);
}
process.exit(totalErrors > 0 ? 1 : 0);
}
// Single app validation
const validator = new AppValidator(appName, { quiet });
const exitCode = await validator.validate();
process.exit(exitCode);
}
main().catch((err) => {
console.error(`${colors.red}Unexpected error: ${err.message}${colors.reset}`);
process.exit(1);
});