goods-exporter 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +48 -49
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.mjs +48 -49
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,13 +1,56 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var events = require('events');
|
|
4
4
|
var stream$3 = require('stream');
|
|
5
5
|
var pkg = require('exceljs');
|
|
6
6
|
var jsonStreamStringify = require('json-stream-stringify');
|
|
7
|
-
var events = require('events');
|
|
8
7
|
var fastXmlParser = require('fast-xml-parser');
|
|
9
8
|
var fs = require('fs');
|
|
10
9
|
|
|
10
|
+
const buildCategoryPaths = (categories) => {
|
|
11
|
+
const idToCategory = /* @__PURE__ */ new Map();
|
|
12
|
+
categories.forEach((category) => {
|
|
13
|
+
idToCategory.set(category.id, category);
|
|
14
|
+
});
|
|
15
|
+
const categoryPaths = /* @__PURE__ */ new Map();
|
|
16
|
+
categories.forEach((category) => {
|
|
17
|
+
const path = [];
|
|
18
|
+
let currentCategory = category;
|
|
19
|
+
while (currentCategory) {
|
|
20
|
+
path.unshift(currentCategory);
|
|
21
|
+
if (currentCategory.parentId !== void 0) {
|
|
22
|
+
currentCategory = idToCategory.get(currentCategory.parentId);
|
|
23
|
+
} else {
|
|
24
|
+
currentCategory = void 0;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
categoryPaths.set(category.id, path);
|
|
28
|
+
});
|
|
29
|
+
return categoryPaths;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const writeWithDrain = (stream) => {
|
|
33
|
+
return async (chunk) => {
|
|
34
|
+
const canWrite = stream.write(chunk);
|
|
35
|
+
if (!canWrite) {
|
|
36
|
+
await events.once(stream, "drain");
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const delay = async (ms) => await new Promise((resolve) => setTimeout(resolve, ms));
|
|
42
|
+
|
|
43
|
+
const urlQueryEncode = (inputUrl) => {
|
|
44
|
+
try {
|
|
45
|
+
const url = new URL(inputUrl);
|
|
46
|
+
url.search = url.search.replace(/^\?/, "").replace(/,/g, "%2C");
|
|
47
|
+
return url.toString();
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error("Invalid URL:", error);
|
|
50
|
+
return "";
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
11
54
|
var __defProp$b = Object.defineProperty;
|
|
12
55
|
var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
56
|
var __publicField$b = (obj, key, value) => {
|
|
@@ -21,7 +64,7 @@ class CSVStream {
|
|
|
21
64
|
__publicField$b(this, "lineSeparator", "\n");
|
|
22
65
|
__publicField$b(this, "emptyFieldValue", "");
|
|
23
66
|
__publicField$b(this, "columns", /* @__PURE__ */ new Set());
|
|
24
|
-
__publicField$b(this, "writer",
|
|
67
|
+
__publicField$b(this, "writer", writeWithDrain(this.stream));
|
|
25
68
|
if (delimiter !== void 0)
|
|
26
69
|
this.delimiter = delimiter;
|
|
27
70
|
if (lineSeparator !== void 0)
|
|
@@ -547,50 +590,6 @@ class TildaFormatter {
|
|
|
547
590
|
}
|
|
548
591
|
}
|
|
549
592
|
|
|
550
|
-
const buildCategoryPaths = (categories) => {
|
|
551
|
-
const idToCategory = /* @__PURE__ */ new Map();
|
|
552
|
-
categories.forEach((category) => {
|
|
553
|
-
idToCategory.set(category.id, category);
|
|
554
|
-
});
|
|
555
|
-
const categoryPaths = /* @__PURE__ */ new Map();
|
|
556
|
-
categories.forEach((category) => {
|
|
557
|
-
const path = [];
|
|
558
|
-
let currentCategory = category;
|
|
559
|
-
while (currentCategory) {
|
|
560
|
-
path.unshift(currentCategory);
|
|
561
|
-
if (currentCategory.parentId !== void 0) {
|
|
562
|
-
currentCategory = idToCategory.get(currentCategory.parentId);
|
|
563
|
-
} else {
|
|
564
|
-
currentCategory = void 0;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
categoryPaths.set(category.id, path);
|
|
568
|
-
});
|
|
569
|
-
return categoryPaths;
|
|
570
|
-
};
|
|
571
|
-
|
|
572
|
-
const writeWithDrain = (stream) => {
|
|
573
|
-
return async (chunk) => {
|
|
574
|
-
const canWrite = stream.write(chunk);
|
|
575
|
-
if (!canWrite) {
|
|
576
|
-
await events.once(stream, "drain");
|
|
577
|
-
}
|
|
578
|
-
};
|
|
579
|
-
};
|
|
580
|
-
|
|
581
|
-
const delay = async (ms) => await new Promise((resolve) => setTimeout(resolve, ms));
|
|
582
|
-
|
|
583
|
-
const urlQueryEncode = (inputUrl) => {
|
|
584
|
-
try {
|
|
585
|
-
const url = new URL(inputUrl);
|
|
586
|
-
url.search = url.search.replace(/^\?/, "").replace(/,/g, "%2C");
|
|
587
|
-
return url.toString();
|
|
588
|
-
} catch (error) {
|
|
589
|
-
console.error("Invalid URL:", error);
|
|
590
|
-
return "";
|
|
591
|
-
}
|
|
592
|
-
};
|
|
593
|
-
|
|
594
593
|
var __defProp$3 = Object.defineProperty;
|
|
595
594
|
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
596
595
|
var __publicField$3 = (obj, key, value) => {
|
|
@@ -863,7 +862,7 @@ class YMLFormatter {
|
|
|
863
862
|
result.write('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n');
|
|
864
863
|
result.write('<yml_catalog date="' + date + '">\n');
|
|
865
864
|
result.write("<shop>\n");
|
|
866
|
-
const resultWriter =
|
|
865
|
+
const resultWriter = writeWithDrain(result);
|
|
867
866
|
if (options?.shopName) {
|
|
868
867
|
await resultWriter(builder.build({ name: options.shopName }));
|
|
869
868
|
await resultWriter("\n");
|
|
@@ -889,7 +888,7 @@ class YMLFormatter {
|
|
|
889
888
|
}
|
|
890
889
|
await resultWriter("<offers>\n");
|
|
891
890
|
const offerStream = new stream$3.PassThrough();
|
|
892
|
-
const offerWriter =
|
|
891
|
+
const offerWriter = writeWithDrain(offerStream);
|
|
893
892
|
offerStream.pipe(result, { end: false });
|
|
894
893
|
for (const product of products) {
|
|
895
894
|
const offer = builder.build({ offer: this.getOffer(product) });
|