This commit is contained in:
zhongluofeng committed 2026-11-06 15:07:02 +08:00
1 parent 787544eec1
commit 4ff9146910
81 files changed
+18417 -545

No files matched your search

+69
View File
@@ -0,0 +1,69 @@
/**
* 按型号目录回填马达 / 扬声器的尺寸、体积、功率。
*
* 示例:
* pnpm tsx scripts/apply-hardware-catalog.mjs # 只统计
* pnpm tsx scripts/apply-hardware-catalog.mjs --write # 写库
*/
import { enrichHardwareSpecs, lookupMotorModel, lookupSpeakerModel } from '../src/lib/hardware-catalog';
import { listDevices, saveDevice } from '../src/lib/repo';
const write = process.argv.includes('--write');
const stats = {
devices: 0,
changed: 0,
motors: 0,
motorSizes: 0,
motorVolumes: 0,
units: 0,
unitFilled: 0,
};
const changedSamples = [];
for (const device of listDevices()) {
stats.devices += 1;
const before = JSON.stringify(device.specs);
const afterSpecs = enrichHardwareSpecs(device.specs);
const after = JSON.stringify(afterSpecs);
if (before === after) continue;
stats.changed += 1;
const motor = device.specs.vibration;
const nextMotor = afterSpecs.vibration;
if (motor?.model && lookupMotorModel(motor.model)) {
stats.motors += 1;
if (!motor.size && nextMotor?.size) stats.motorSizes += 1;
if (!motor.volume && nextMotor?.volume) stats.motorVolumes += 1;
}
const units = device.specs.speakers?.units ?? [];
const nextUnits = afterSpecs.speakers?.units ?? [];
units.forEach((unit, index) => {
if (!unit.model || !lookupSpeakerModel(unit.model)) return;
stats.units += 1;
if ((!unit.size && nextUnits[index]?.size) || (!unit.power && nextUnits[index]?.power)) {
stats.unitFilled += 1;
}
});
if (changedSamples.length < 8) {
changedSamples.push({
slug: device.slug,
motor: afterSpecs.vibration,
units: afterSpecs.speakers?.units,
});
}
if (write) saveDevice({ ...device, specs: afterSpecs });
}
console.log(`扫描 ${stats.devices} 款,需回填 ${stats.changed} 款(${write ? '已写入' : '未写入,加 --write 生效'})`);
console.log(
`马达:可识别 ${stats.motors} 款,补尺寸 ${stats.motorSizes},补体积 ${stats.motorVolumes}`,
);
console.log(`扬声器:可识别单元 ${stats.units},补尺寸/功率 ${stats.unitFilled}`);
console.log('示例:');
for (const sample of changedSamples) {
console.log(JSON.stringify(sample));
}