import { spawnSync } from 'node:child_process' import { readFileSync } from 'node:fs' function git(args,input) { const out=spawnSync('git',args,{input,encoding:'utf8'}) if(out.status!==0) throw new Error(out.stderr) return out.stdout } function replaceOnce(text,oldValue,newValue) { if(text.split(oldValue).length!==2) throw new Error('Expected exactly one stage anchor: '+oldValue.slice(0,70)) return text.replace(oldValue,newValue) } const head=git(['rev-parse','HEAD']).trim() const paths=['src/modules/cockpit/services/cesiumPipeLayer.js','src/modules/cockpit/services/mapService.js','src/modules/cockpit/components/MapInfoPanel.vue'] for(const path of paths) { let staged=git(['show',`${head}:${path}`]) const current=readFileSync(path,'utf8').replace(/\r\n/g,'\n') if(path.endsWith('cesiumPipeLayer.js')) { const commentStart=' * 渲染口径' const a=staged.indexOf(commentStart),b=staged.indexOf('\n */',a) const c=current.indexOf(commentStart),d=current.indexOf('\n */',c) staged=staged.slice(0,a)+current.slice(c,d)+staged.slice(b) const constants=current.slice(current.indexOf('// Viewer-scoped'),current.indexOf('/** 与 `cesiumEngine')) staged=replaceOnce(staged,'/** 与 `cesiumEngine',constants+'/** 与 `cesiumEngine') staged=replaceOnce(staged,'export async function syncPipeLayer(viewer, network) {','export async function syncPipeLayer(viewer, network, { onModelChange = () => {} } = {}) {') const versions=' const version = (layerVersions.get(viewer) || 0) + 1\n layerVersions.set(viewer, version)\n' staged=replaceOnce(staged,' clearIndex(viewer)\n',versions+' clearIndex(viewer)\n') staged=replaceOnce(staged,' const source = await ensureSource(viewer)\n',' const source = await ensureSource(viewer)\n if (layerVersions.get(viewer) !== version) return { pipes: 0, components: 0, rendered: false }\n') const models=current.slice(current.indexOf(' // Keep fallback entities'),current.indexOf(' return { pipes: pipes.length',current.indexOf(' // Keep fallback entities'))) staged=replaceOnce(staged,' return { pipes: pipes.length, components: components.length, rendered: true }',models+' return { pipes: pipes.length, components: components.length, rendered: true }') const cleanup=current.slice(current.indexOf(' if (viewer) layerVersions'),current.indexOf(' const source = viewer &&')) staged=replaceOnce(staged,' const source = viewer &&',cleanup+' const source = viewer &&') } else if(path.endsWith('mapService.js')) { staged=replaceOnce(staged,' if (record.viewer) {\n record.engine.destroyViewer(record.viewer)',' if (record.viewer) {\n if (record.pipeLayer) record.pipeLayer.clearPipeLayer(record.viewer)\n record.engine.destroyViewer(record.viewer)') const old=" const engine = await import('./cesiumPipeLayer.js')\n await engine.syncPipeLayer(instance.viewer, layer)\n const host = instance.host" const start=current.indexOf(' const record = instance\n const engine = await import(\'./cesiumPipeLayer.js\')') const end=current.indexOf(' const host = record.host\n if (host',start)+' const host = record.host'.length if(start<0||end') const noteEnd=current.indexOf('