import fs from 'node:fs/promises'; import path from 'node:path'; import { resolveRules } from '../src/rules.mjs'; import { atomic, digest } from '../src/store.mjs'; const [configFile, packFile, brandName] = process.argv.slice(2); if (!configFile || !packFile || !brandName) throw Error('用法:<本地 QA 配置> <离线规则包路径> <品牌名称>'); const config = JSON.parse(await fs.readFile(configFile, 'utf8')); const packPath = path.resolve(packFile); const bytes = await fs.readFile(packPath, 'utf8'), pack = JSON.parse(bytes); const profile = pack.brands.find(b => b.name === brandName); if (!profile) throw Error(`离线规则包没有品牌「${brandName}」`); const brandId = 'local-import:' + digest(brandName); const catalog = { brands: [{ id: brandId, name: brandName, profile, revision: pack.version, source: 'local-import:' + path.basename(packPath) }], shops: [{ id: 'QA-A店', brandId, platform: 'local-qa', revision: 'qa-1', source: 'explicit-qa-fixture', rules: ['A店书桌规则口令:晨雾-2168'] }, { id: 'QA-B店', brandId, platform: 'local-qa', revision: 'qa-1', source: 'explicit-qa-fixture', rules: ['B店餐椅规则口令:海盐-7391'] }], categories: [{ id: 'QA-书桌', revision: 'qa-1', source: 'explicit-qa-fixture', rules: ['没有承重或检测报告时不编造相应参数'] }, { id: 'QA-餐椅', revision: 'qa-1', source: 'explicit-qa-fixture', rules: ['不能把另一产品的尺寸与材质用于当前餐椅'] }], bindings: [{ id: 'QA-A-desk', shopId: 'QA-A店', categoryId: 'QA-书桌', revision: 'qa-1', source: 'explicit-qa-fixture', state: 'ready', rules: [] }, { id: 'QA-B-chair', shopId: 'QA-B店', categoryId: 'QA-餐椅', revision: 'qa-1', source: 'explicit-qa-fixture', state: 'ready', rules: [] }], }; config.canvasBinding = resolveRules({ brandId, shopId: 'QA-A店', categoryId: 'QA-书桌' }, catalog); config.otherBinding = resolveRules({ brandId, shopId: 'QA-B店', categoryId: 'QA-餐椅' }, catalog); await atomic(configFile, config); await atomic(path.join(config.output, 'rule-source-manifest.json'), { brandSource: packPath, importedVersion: pack.version, hash: digest(bytes), status: profile.status, shopsAndCategories: 'explicit-local-qa-fixtures', productionCatalog: 'GET currently unavailable; no automatic fallback or deployment performed' }); console.log('Selected the existing local enterprise import explicitly; shop/category rules are labelled QA fixtures.');