/* eslint-env node */ import fs from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' const currentDir = path.dirname(fileURLToPath(import.meta.url)) const pageDir = path.resolve(currentDir, '..') const srcDir = path.resolve(pageDir, '..', '..', '..') const constantsSource = fs.readFileSync(path.join(srcDir, 'constants', 'dictCodes.ts'), 'utf8') const indexSource = fs.readFileSync(path.join(pageDir, 'index.vue'), 'utf8') const equipmentFormSource = fs.readFileSync(path.join(pageDir, 'components', 'EquipmentForm.vue'), 'utf8') const expectations = [ ['dict code defines terminal model', /LEDGER_TERMINAL_MODEL:\s*'Dev_Type'/.test(constantsSource)], [ 'addLedger uses terminal model dict for equipment model options', /typeof DICT_CODES\.LEDGER_TERMINAL_MODEL/.test(indexSource) && /resolveDictOptions\(DICT_CODES\.LEDGER_TERMINAL_MODEL,\s*fallbackDeviceModelOptions\)/.test(indexSource) && /ensureLedgerDictOptionById\(DICT_CODES\.LEDGER_TERMINAL_MODEL,\s*form\.dev_model\s*\|\|\s*''\)/.test( indexSource ) && /loadLedgerDictOptionsByCode\(DICT_CODES\.LEDGER_TERMINAL_MODEL\)/.test(indexSource) ], [ 'equipment form labels terminal dict as device model', /label="装置型号"[\s\S]*placeholder="请选择装置型号"/.test(equipmentFormSource) && /dev_model:\s*\[\{ required:\s*true,\s*message:\s*'请选择装置型号'/.test(equipmentFormSource) ] ] const failures = expectations.filter(([, matched]) => !matched) if (failures.length) { console.error('addLedger terminal model contract check failed:') for (const [name] of failures) { console.error(`- ${name}`) } process.exit(1) } console.log('addLedger terminal model contract check passed')