- Restore analytics.js, the counter id and the consent banner. The banner renders and the "Cookie" reset button exists only when HM_YM_ID is non-zero; at 0 the node is removed and no request reaches mc.yandex.ru. - Release state stays data-free (verified headless): id 0, banner absent, 0 requests to Yandex, 0 external hosts. With an id set, the banner appears, and tag.js loads only after "Принять". - check-release now fails on a non-zero counter instead of banning the code, so the gate protects the release state, not the implementation. - privacy.html says the counter exists but is not activated; ads-readiness section 3 is the enable procedure (id + RKN notice + policy paragraph).
79 lines
4.0 KiB
JavaScript
79 lines
4.0 KiB
JavaScript
// check-release.mjs — гейт релиза: выгрузка = содержимое src/ и ничего больше.
|
||
// Проверяет: локальные пути из index.html и data/*.js существуют внутри src/,
|
||
// в поставляемых файлах нет запрещённых ссылок (Work_files, /api, внешние шрифты,
|
||
// сборщики аналитики, поля ввода), у скриптов стоит метка версии.
|
||
//
|
||
// Запуск: node scripts/check-release.mjs [YYYYMMDD]
|
||
// Exit 0 — можно выгружать; exit 1 — список нарушений.
|
||
import { readFileSync, existsSync, readdirSync, statSync } from 'node:fs';
|
||
import { join, dirname } from 'node:path';
|
||
import { fileURLToPath } from 'node:url';
|
||
|
||
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
|
||
const SRC = join(ROOT, 'src');
|
||
const STAMP = process.argv[2] || '';
|
||
const errors = [];
|
||
|
||
function walk(dir) {
|
||
return readdirSync(dir).flatMap((f) => {
|
||
const p = join(dir, f);
|
||
return statSync(p).isDirectory() ? walk(p) : [p];
|
||
});
|
||
}
|
||
|
||
const files = walk(SRC);
|
||
const text = files.filter((f) => /\.(html|js|css|md)$/.test(f));
|
||
const rel = (f) => f.slice(ROOT.length + 1).replace(/\\/g, '/');
|
||
|
||
// 1. Запрещённые ссылки в поставляемых файлах.
|
||
// Третий элемент — файл, к которому правило относится (иначе правило глобальное).
|
||
const BANNED = [
|
||
[/Work_files/i, 'ссылка на Work_files (вне docroot)'],
|
||
[/contact\.php/i, 'PHP-эндпоинт формы'],
|
||
[/<script>\s*window\.HM_YM_ID\s*=\s*(?!0\b)\d+/, 'счётчик Метрики включён (релиз идёт без сбора данных)', /index\.html$/],
|
||
[/(fonts|ajax)\.googleapis\.com|fonts\.gstatic\.com/i, 'внешние шрифты'],
|
||
[/localhost|127\.0\.0\.1/i, 'локальный адрес'],
|
||
[/<form\b/i, 'поле ввода / форма'],
|
||
];
|
||
for (const f of text) {
|
||
const body = readFileSync(f, 'utf8');
|
||
for (const [re, why, only] of BANNED) {
|
||
if (only && !only.test(f)) continue;
|
||
if (re.test(body)) errors.push(`${rel(f)}: ${why}`);
|
||
}
|
||
}
|
||
// README в docroot тоже уходит на сервер: путь за пределы src/ оттуда убирается (остальное в них
|
||
// законно — команды с 127.0.0.1, имена исходников).
|
||
for (const f of files.filter((p) => /\.md$/.test(p))) {
|
||
if (/Work_files/i.test(readFileSync(f, 'utf8'))) {
|
||
errors.push(`${rel(f)}: ссылка на Work_files (вне docroot)`);
|
||
}
|
||
}
|
||
|
||
// 2. Каждый локальный путь страницы и данных существует внутри src/.
|
||
const index = readFileSync(join(SRC, 'index.html'), 'utf8');
|
||
const paths = new Set();
|
||
for (const m of index.matchAll(/(?:href|src)="([^"]+)"/g)) paths.add(m[1]);
|
||
for (const f of files.filter((p) => /data[\\/].*\.js$/.test(p))) {
|
||
for (const m of readFileSync(f, 'utf8').matchAll(/"(assets\/[^"]+)"/g)) paths.add(m[1]);
|
||
}
|
||
for (const raw of paths) {
|
||
const p = raw.split('?')[0];
|
||
if (!p || /^(https?:|mailto:|tel:|#|\/\/|data:)/.test(p)) continue;
|
||
const target = join(SRC, p.split('#')[0]);
|
||
if (!existsSync(target)) errors.push(`index.html: путь не найден — ${p}`);
|
||
}
|
||
|
||
// 3. Метка версии у скриптов: без неё сервер отдаёт сутки старый js (src/.htaccess, js/css = 1 day).
|
||
for (const m of index.matchAll(/<script src="([^"]+\.js)(?:\?v=(\d+))?"/g)) {
|
||
if (!m[2]) errors.push(`index.html: нет ?v= у ${m[1]}`);
|
||
else if (STAMP && m[2] !== STAMP) errors.push(`index.html: ${m[1]} ?v=${m[2]}, ожидается ${STAMP}`);
|
||
}
|
||
|
||
if (errors.length) {
|
||
console.log('FAIL');
|
||
for (const e of errors) console.log(' -', e);
|
||
process.exit(1);
|
||
}
|
||
console.log(`PASS: ${files.length} файлов, ${paths.size} путей, метка ${STAMP || 'не проверялась'}; выгрузка = src/`);
|