mirror of
https://github.com/pbakaus/impeccable.git
synced 2026-09-11 21:57:14 +03:00
Merges the impeccable-detect CLI repo (pbakaus/impeccable-cli@831a6cc) into this repo. The BSL-1.1 license that motivated the split is gone; everything is now Apache 2.0. - Add bin/, src/, detection tests and fixtures from CLI repo - Merge package.json: name → "impeccable", add bin/exports/files fields - Internal refs now read from local src/ instead of node_modules/ - Update SPDX headers, NOTICE.md, CLAUDE.md, FAQ, npm README - Add prepack/postpack scripts for CLI-focused README on npm - Remove terminal license labels (no longer needed) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Generates src/detect-antipatterns-browser.js
|
|
* by stripping Node-specific sections from the universal source and wrapping in an IIFE.
|
|
*
|
|
* Run: node scripts/build-browser-detector.js
|
|
*/
|
|
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const ROOT = path.resolve(__dirname, '..');
|
|
|
|
const SOURCE = path.join(ROOT, 'src/detect-antipatterns.mjs');
|
|
const OUTPUT = path.join(ROOT, 'src/detect-antipatterns-browser.js');
|
|
|
|
let code = fs.readFileSync(SOURCE, 'utf-8');
|
|
|
|
// Strip shebang
|
|
code = code.replace(/^#!.*\n/, '');
|
|
// Strip sections between @browser-strip-start / @browser-strip-end markers
|
|
code = code.replace(/^\/\/ @browser-strip-start\n[\s\S]*?^\/\/ @browser-strip-end\n?/gm, '');
|
|
// Set IS_BROWSER = true (dead-code eliminates Node paths)
|
|
code = code.replace(/^const IS_BROWSER = .*$/m, 'const IS_BROWSER = true;');
|
|
|
|
const output = `/**
|
|
* Anti-Pattern Browser Detector for Impeccable
|
|
* Copyright (c) 2026 Paul Bakaus
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* GENERATED -- do not edit. Source: detect-antipatterns.mjs
|
|
* Rebuild: node scripts/build-browser-detector.js
|
|
*
|
|
* Usage: <script src="detect-antipatterns-browser.js"></script>
|
|
* Re-scan: window.impeccableScan()
|
|
*/
|
|
(function () {
|
|
if (typeof window === 'undefined') return;
|
|
${code}
|
|
})();
|
|
`;
|
|
|
|
fs.writeFileSync(OUTPUT, output);
|
|
console.log(`Generated ${path.relative(ROOT, OUTPUT)} (${(output.length / 1024).toFixed(1)} KB)`);
|