Files
arsam 2ba227a0e8 Import source: global/scripts/check-no-cdn.mjs
Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality.
2026-09-18 23:27:03 +03:30

55 lines
1.3 KiB
JavaScript

#!/usr/bin/env node
// Fails build if any CDN references are found in dist/
import { readdirSync, readFileSync, statSync } from 'fs';
import { join } from 'path';
const CDN_PATTERNS = [
/cdn\./i,
/googleapis\.com/i,
/gstatic\.com/i,
/cloudflare\.com\/ajax/i,
/jsdelivr\.net/i,
/unpkg\.com/i,
/bootstrapcdn/i,
/cdnjs\.cloudflare/i,
];
const ALLOWED = [
'teknavglobal.com',
'teknav.ir',
'x.com',
'twitter.com',
'linkedin.com',
];
function walk(dir) {
const results = [];
for (const f of readdirSync(dir)) {
const p = join(dir, f);
if (statSync(p).isDirectory()) results.push(...walk(p));
else if (f.endsWith('.html') || f.endsWith('.js') || f.endsWith('.css')) results.push(p);
}
return results;
}
let errors = 0;
for (const file of walk('dist')) {
const content = readFileSync(file, 'utf8');
for (const pattern of CDN_PATTERNS) {
const matches = content.match(new RegExp(pattern.source, 'gi'));
if (matches) {
const filtered = matches.filter(m => !ALLOWED.some(a => m.includes(a)));
if (filtered.length) {
console.error(`[check-no-cdn] ${file}: ${filtered.join(', ')}`);
errors++;
}
}
}
}
if (errors > 0) {
console.error(`[check-no-cdn] FAILED: ${errors} CDN references found`);
process.exit(1);
}
console.log('[check-no-cdn] clean — no external CDN references found');