#!/usr/bin/env node // R2 — EXTRACT : workflow JSON → src/nodes/*.js (+ template snapshot). // À utiliser UNIQUEMENT pour (re)synchroniser src/ après une modification faite // directement dans l'UI n8n (à éviter). En temps normal : éditer src/nodes/, // puis tools/n8n-push.mjs reconstruit le JSON automatiquement. import fs from 'fs'; import path from 'path'; import { WORKFLOW_FILE, SRC_DIR, NODE_MAP, getCode } from './lib-node-map.mjs'; const wf = JSON.parse(fs.readFileSync(WORKFLOW_FILE, 'utf8')); fs.mkdirSync(SRC_DIR, { recursive: true }); for (const { file, node, kind } of NODE_MAP) { const n = wf.nodes.find(x => x.name === node); if (!n) throw new Error(`Node introuvable: ${node}`); const code = getCode(n, kind); fs.writeFileSync(path.join(SRC_DIR, file), code); console.log(`${file} ← "${node}" (${code.length} chars)`); } console.log(`\nExtraction OK dans ${SRC_DIR}/`);