独立副本采用RX=-2范围最低加200、最高加100,RX=-1.1最低减100、最高减300。 四站逐层工具Z正反90度,切换姿态Y退50毫米,X端余量100毫米。 13个已发布方案及任务、新扫描组件默认点间距统一0.7,激光亮度保持原值。 保留旧路径、显式任务参数和冻结版本,补充迁移保护、既有回归及中文发布记录。
72 lines
3.8 KiB
JavaScript
72 lines
3.8 KiB
JavaScript
import fs from 'node:fs'
|
|
import assert from 'node:assert/strict'
|
|
|
|
// Offline migration input must be a captured current-published snapshot, not a draft.
|
|
const [snapshotPath,outputPath]=process.argv.slice(2)
|
|
if(!snapshotPath||!outputPath)throw new Error('Usage: node normalize_scanner_parameter_defaults.mjs <snapshot.json> <output-flow.json>')
|
|
const snapshot=JSON.parse(fs.readFileSync(snapshotPath,'utf8').replace(/^\uFEFF/,''))
|
|
assert(snapshot.current?.publishedVersionId&&snapshot.published?.flowData,'A current published version snapshot is required')
|
|
assert.equal(snapshot.current.publishedVersionId,snapshot.published.id)
|
|
const graph=JSON.parse(snapshot.published.flowData),before=structuredClone(graph)
|
|
// Replace only the top-level value token. In particular, never parse/stringify
|
|
// unrelated SDK integers or overwrite a saved brightness (including zero).
|
|
function distanceBody(text,body){
|
|
const stringEnd=start=>{
|
|
for(let i=start+1;i<text.length;i++){
|
|
if(text[i]==='\\')i++
|
|
else if(text[i]==='"')return i+1
|
|
}
|
|
throw new Error('Unterminated scanner JSON string')
|
|
}
|
|
const spaces=start=>{while(/\s/.test(text[start]||'')&&start<text.length)start++;return start}
|
|
let depth=0;const ranges=[]
|
|
for(let i=0;i<text.length;i++){
|
|
if(text[i]==='"'){
|
|
const end=stringEnd(i),colon=spaces(end)
|
|
if(depth===1&&text[colon]===':'&&JSON.parse(text.slice(i,end))==='pointDistance'){
|
|
const start=spaces(colon+1);let stop=start,nested=0
|
|
for(;stop<text.length;stop++){
|
|
if(text[stop]==='"'){stop=stringEnd(stop)-1;continue}
|
|
if(text[stop]==='{'||text[stop]==='[')nested++
|
|
else if(text[stop]==='}'||text[stop]===']'){if(nested===0)break;nested--}
|
|
else if(text[stop]===','&&nested===0)break
|
|
}
|
|
while(stop>start&&/\s/.test(text[stop-1]))stop--
|
|
ranges.push([start,stop])
|
|
}
|
|
i=end-1
|
|
}else if(text[i]==='{'||text[i]==='[')depth++
|
|
else if(text[i]==='}'||text[i]===']')depth--
|
|
}
|
|
assert(ranges.length<=1,'Duplicate scanner pointDistance requires review')
|
|
if(ranges.length){const [start,end]=ranges[0];return text.slice(0,start)+'0.7'+text.slice(end)}
|
|
const end=text.lastIndexOf('}')
|
|
return text.slice(0,end)+(Object.keys(body).length?',':'')+'\n "pointDistance": 0.7\n'+text.slice(end)
|
|
}
|
|
let nodes=0,changed=0
|
|
for(const node of graph.nodes){
|
|
if(node.properties?.action!=='SCANNER_PARAMETERS')continue
|
|
nodes++
|
|
const parameter=node.properties.nodeParams?.find(field=>field.name==='requestJson')
|
|
assert.equal(parameter?.type,'input',`Dynamic scanner request requires a separate review: ${node.id}`)
|
|
assert(!node.properties.nodeParams?.find(field=>field.name==='requestFields')?.children?.some(field=>field.name==='pointDistance'),`Bound pointDistance requires a separate review: ${node.id}`)
|
|
const body=JSON.parse(parameter.input)
|
|
assert(body&&typeof body==='object'&&!Array.isArray(body))
|
|
if(body.pointDistance===0.7)continue
|
|
parameter.input=distanceBody(parameter.input,body)
|
|
const previous={...body},next={...JSON.parse(parameter.input)}
|
|
delete previous.pointDistance;delete next.pointDistance
|
|
assert.deepEqual(next,previous,'Only pointDistance may change inside scanner parameters')
|
|
changed++
|
|
}
|
|
assert(nodes>0,'No scanner parameter nodes')
|
|
// No path, edge, resource assignment or other scanner setting may change.
|
|
const verified=structuredClone(graph)
|
|
for(let i=0;i<verified.nodes.length;i++)if(verified.nodes[i].properties?.action==='SCANNER_PARAMETERS'){
|
|
const old=before.nodes[i].properties.nodeParams.find(field=>field.name==='requestJson')
|
|
verified.nodes[i].properties.nodeParams.find(field=>field.name==='requestJson').input=old.input
|
|
}
|
|
assert.deepEqual(verified,before)
|
|
fs.writeFileSync(outputPath,JSON.stringify(graph,null,2))
|
|
console.log(JSON.stringify({flowId:snapshot.current.id,nodes,changed,brightnessUnchanged:true,pointDistance:0.7,pathUnchanged:true}))
|