forked from LegendApp/legend-list
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprebuild.ts
More file actions
43 lines (34 loc) · 1.24 KB
/
Copy pathprebuild.ts
File metadata and controls
43 lines (34 loc) · 1.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
import { readdir, readFile } from "node:fs/promises";
import path from "node:path";
const SRC_DIR = path.resolve(process.cwd(), "src");
const TARGET_LINE = 'import * as React from "react";';
async function collectTSXFiles(): Promise<string[]> {
const entries = await readdir(SRC_DIR, { recursive: true });
return entries
.filter((entry) => entry.endsWith(".tsx"))
.map((entry) => path.join(SRC_DIR, entry));
}
async function run() {
const files = await collectTSXFiles();
const missing: string[] = [];
for (const file of files) {
const contents = await readFile(file, "utf8");
const hasTargetLine = contents.split(/\r?\n/).some((line) => line.trim() === TARGET_LINE);
if (!hasTargetLine) {
missing.push(path.relative(process.cwd(), file));
}
}
if (missing.length > 0) {
console.error("Missing React import in the following files:");
for (const file of missing) {
console.error(` - ${file}`);
}
process.exitCode = 1;
return;
}
console.log(`Verified React import in ${files.length} .tsx files.`);
}
run().catch((error) => {
console.error("Failed to run prebuild check:", error);
process.exitCode = 1;
});