import { execFile } from 'node:child_process' import { promisify } from 'node:util' const exec = promisify(execFile) const enabled = process.env.ADMIN_GIT_SYNC === 'true' const cwd = process.cwd() async function git(...args: string[]): Promise { const { stdout } = await exec('git', args, { cwd }) return stdout.trim() } /** * Commit et push les modifications admin vers le dépôt git. * Activé uniquement si ADMIN_GIT_SYNC=true (prod). * Ne bloque jamais la réponse HTTP — exécution fire-and-forget. */ export function gitSyncContent(description: string, paths: string[] = ['.']) { if (!enabled) return const run = async () => { try { for (const p of paths) { await git('add', p) } // Vérifier s'il y a vraiment des changements stagés const status = await git('diff', '--cached', '--name-only') if (!status) return await git('commit', '-m', `[admin] ${description}`) await git('push') console.log(`[gitSync] pushed: ${description}`) } catch (err: any) { console.error(`[gitSync] error:`, err.message ?? err) } } // Fire-and-forget : ne pas bloquer la réponse HTTP run() }