diff --git a/package.json b/package.json index c36efa6..fb07ac2 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "build": "astro build", "preview": "astro preview", "astro": "astro", - "fetch-data": "npx tsx src/scripts/fetch-indicators.ts", + "fetch-data": "tsx src/scripts/fetch-indicators.ts", "fetch-and-build": "npm run fetch-data && npm run build" }, "dependencies": { diff --git a/src/integrations/fetch-indicators.ts b/src/integrations/fetch-indicators.ts index fb83c51..13d5c70 100644 --- a/src/integrations/fetch-indicators.ts +++ b/src/integrations/fetch-indicators.ts @@ -31,7 +31,9 @@ export function fetchIndicatorsIntegration(): AstroIntegration { // Import dynamique pour éviter les problèmes de résolution au démarrage const { spawnSync } = await import('child_process'); const scriptPath = new URL('../scripts/fetch-indicators.ts', import.meta.url).pathname; - const result = spawnSync('npx', ['tsx', scriptPath], { + // Utilise tsx installé dans node_modules (pas npx qui nécessite internet) + const tsxBin = new URL('../../node_modules/.bin/tsx', import.meta.url).pathname; + const result = spawnSync(tsxBin, [scriptPath], { stdio: 'inherit', encoding: 'utf-8', timeout: 120_000, // 2 min max diff --git a/src/pages/donnees/index.astro b/src/pages/donnees/index.astro index ae39eb0..2440236 100644 --- a/src/pages/donnees/index.astro +++ b/src/pages/donnees/index.astro @@ -2,14 +2,19 @@ import BaseLayout from '../../layouts/BaseLayout.astro'; import KpiLive from '../../components/KpiLive.astro'; import { INDICATEURS_BY_THEME, PAYS_LABEL } from '../../lib/indicators-config.ts'; +import { existsSync, readFileSync } from 'node:fs'; +import { join } from 'node:path'; // Charger le JSON des indicateurs (généré en pré-build) +// Utilise readFileSync + existsSync pour éviter l'échec de résolution statique Vite let indicateursData: any = { indicators: [], insee: {}, generated_at: null }; -try { - const raw = await import('../../data/live/indicators.json'); - indicateursData = raw.default || raw; -} catch { - // Données non disponibles (premier build sans fetch) +const jsonPath = join(process.cwd(), 'src/data/live/indicators.json'); +if (existsSync(jsonPath)) { + try { + indicateursData = JSON.parse(readFileSync(jsonPath, 'utf-8')); + } catch { + // fichier corrompu, on utilise les défauts + } } // Indexer par ID pour accès rapide