fix: pipeline asset riproducibile con script di ottimizzazione
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
// Pipeline asset: extract-fig-images.sh → apply-asset-map.mjs → optimize-assets.sh
|
||||
// 1. extract-fig-images.sh: estrae hash-named images da .fig → assets-src/
|
||||
// 2. apply-asset-map.mjs: copia da assets-src/ → destinazioni (src/assets/img, public/img)
|
||||
// 3. optimize-assets.sh: converte PNG fotografici → JPG q85, ridimensiona ≤1400px
|
||||
|
||||
import { copyFileSync, mkdirSync, existsSync } from 'node:fs';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { join, dirname } from 'node:path';
|
||||
@@ -6,7 +11,10 @@ import { fileURLToPath } from 'node:url';
|
||||
const root = join(dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const map = JSON.parse(readFileSync(join(root, 'scripts/asset-map.json'), 'utf8'));
|
||||
let n = 0, missing = 0;
|
||||
|
||||
// Sezione principale: copia da assets-src/
|
||||
for (const [destDir, entries] of Object.entries(map)) {
|
||||
if (destDir === 'fallbacks') continue;
|
||||
mkdirSync(join(root, destDir), { recursive: true });
|
||||
for (const [src, dest] of Object.entries(entries)) {
|
||||
const from = join(root, 'assets-src', src);
|
||||
@@ -15,5 +23,19 @@ for (const [destDir, entries] of Object.entries(map)) {
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
// Sezione fallbacks: copia da path relativo alla root del repo (es. ../Dati/)
|
||||
if (map.fallbacks) {
|
||||
for (const [destDir, entries] of Object.entries(map.fallbacks)) {
|
||||
mkdirSync(join(root, destDir), { recursive: true });
|
||||
for (const [srcRelPath, dest] of Object.entries(entries)) {
|
||||
const from = join(root, srcRelPath);
|
||||
if (!existsSync(from)) { console.error(`MANCANTE (fallback): ${srcRelPath}`); missing++; continue; }
|
||||
copyFileSync(from, join(root, destDir, dest));
|
||||
n++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Copiate ${n} immagini${missing ? `, ${missing} mancanti` : ''}`);
|
||||
process.exit(missing ? 1 : 0);
|
||||
|
||||
Reference in New Issue
Block a user