MCPcopy Create free account
hub / github.com/adobe/react-spectrum / main

Function main

packages/dev/s2-docs/scripts/validateS2DocsBuild.mjs:48–106  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46}
47
48async function main() {
49 const targetDir = process.argv[2] || join(__dirname, '..', 'dist');
50
51 console.log('\nValidating s2-docs build output...');
52 console.log(`Directory: ${targetDir}\n`);
53
54 let dirStats;
55 try {
56 dirStats = await stat(targetDir);
57 } catch {
58 console.error(`Build directory does not exist: ${targetDir}`);
59 process.exit(1);
60 }
61
62 if (!dirStats.isDirectory()) {
63 console.error(`Build path is not a directory: ${targetDir}`);
64 process.exit(1);
65 }
66
67 let htmlFiles;
68 let totalFiles;
69 try {
70 ({htmlFiles, totalFiles} = await collectBuildFiles(targetDir));
71 } catch (error) {
72 console.error(`Error reading build directory: ${error.message}`);
73 process.exit(1);
74 }
75
76 if (totalFiles === 0) {
77 console.error('Build directory is empty. No files found.');
78 process.exit(1);
79 }
80
81 if (htmlFiles.length === 0) {
82 console.error('No HTML files found in the build output.');
83 process.exit(1);
84 }
85
86 console.log(`Found ${htmlFiles.length} HTML files to check.\n`);
87
88 const results = await Promise.all(htmlFiles.map(checkFile));
89 const duplicates = results.filter(r => r.hasDuplicate);
90
91 if (duplicates.length === 0) {
92 console.log("✅ All HTML validated for duplicate '</script></body></html>' occurrences.");
93 } else {
94 console.log(
95 `❌ Found ${duplicates.length} file(s) with duplicate '</script></body></html>' occurrences:\n`
96 );
97
98 for (const {filePath, count} of duplicates) {
99 const relativePath = filePath.replace(targetDir, '').replace(/^\//, '');
100 console.log(` 📄 ${relativePath}`);
101 console.log(` Pattern appears ${count} times (expected: 1)\n`);
102 }
103
104 process.exit(1);
105 }

Callers 1

Calls 2

collectBuildFilesFunction · 0.85
filterMethod · 0.65

Tested by

no test coverage detected