ux improved
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import "dotenv/config";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { parse } from "csv-parse/sync";
|
||||
@@ -62,7 +63,7 @@ function extractAttributes(row) {
|
||||
}
|
||||
|
||||
function normalizeRow(row) {
|
||||
const wooId = Number(row["ID"] || row["Id"] || row["id"] || null);
|
||||
const wooId = Number(row["ID"] || row["ID"] || row["\uFEFFID"] || row["Id"] || row["id"] || null);
|
||||
const type = String(row["Tipo"] || "").trim().toLowerCase();
|
||||
const parentId = Number(row["Superior"] || null) || null;
|
||||
const name = String(row["Nombre"] || "").trim();
|
||||
@@ -194,7 +195,13 @@ async function main() {
|
||||
const { file, tenantKey, replace } = parseArgs();
|
||||
const abs = path.resolve(file);
|
||||
const content = fs.readFileSync(abs);
|
||||
const records = parse(content, { columns: true, skip_empty_lines: true });
|
||||
const records = parse(content, {
|
||||
columns: true,
|
||||
skip_empty_lines: true,
|
||||
relax_column_count: true,
|
||||
relax_column_count_less: true,
|
||||
relax_column_count_more: true,
|
||||
});
|
||||
const normalized = records.map((r) => ({ item: normalizeRow(r), raw: r })).filter((r) => r.item.woo_id && r.item.name);
|
||||
|
||||
const tenants = await getTenants(tenantKey);
|
||||
|
||||
Reference in New Issue
Block a user