|
|
import fs from "fs";
|
|
|
|
|
|
const path = "src/services/parse/packing-list.ts";
|
|
|
let src = fs.readFileSync(path, "utf8");
|
|
|
|
|
|
if (!src.includes("function isInstructionNoiseRow")) {
|
|
|
const insertAt = src.indexOf("export async function parsePackingListBuffer");
|
|
|
if (insertAt < 0) throw new Error("fn missing");
|
|
|
const helper = `/** Template footer instruction row <20>?not a shipment */
|
|
|
export function isInstructionNoiseRow(raw: Record<string, unknown>): boolean {
|
|
|
const parts = Object.values(raw).map((v) => String(v ?? "").trim());
|
|
|
const blob = parts.join(" ");
|
|
|
if (!blob) return false;
|
|
|
if (/^\u6ce8\u610f\\s*[\uFF1A:]/.test(blob)) return true;
|
|
|
if (parts.some((p) => /^\u6ce8\u610f\\s*[\uFF1A:]/.test(p))) return true;
|
|
|
const channel = String(raw.F_Transporter ?? "").trim();
|
|
|
const fba = String(raw.F_FBACode ?? "").trim();
|
|
|
const addr = String(raw.F_Address ?? "").trim();
|
|
|
if (
|
|
|
(channel.length > 40 || fba.length > 40 || addr.length > 80) &&
|
|
|
/\u6ce8\u610f|\u586b\u5199|\u5355\u5143\u683c|\u5fc5\u987b\u586b\u5199/.test(blob)
|
|
|
) {
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
`;
|
|
|
src = src.slice(0, insertAt) + helper + src.slice(insertAt);
|
|
|
}
|
|
|
|
|
|
if (!src.includes("isInstructionNoiseRow(raw)")) {
|
|
|
const re = /if \(!hasAny\) continue;/;
|
|
|
if (!re.test(src)) throw new Error("no hasAny continue");
|
|
|
src = src.replace(
|
|
|
re,
|
|
|
"if (!hasAny) continue;\n if (isInstructionNoiseRow(raw)) continue;",
|
|
|
);
|
|
|
}
|
|
|
|
|
|
fs.writeFileSync(path, src);
|
|
|
console.log({
|
|
|
helper: src.includes("function isInstructionNoiseRow"),
|
|
|
call: src.includes("isInstructionNoiseRow(raw)"),
|
|
|
});
|