goods-exporter 0.5.3 → 0.5.6
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/LICENSE +21 -21
- package/README.md +103 -102
- package/dist/cjs/index.cjs +90 -103
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.mjs +90 -103
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +86 -86
package/dist/esm/index.mjs
CHANGED
|
@@ -2,15 +2,11 @@ import { PassThrough } from 'stream';
|
|
|
2
2
|
import pkg from 'exceljs';
|
|
3
3
|
import { JsonStreamStringify } from 'json-stream-stringify';
|
|
4
4
|
import { XMLBuilder } from 'fast-xml-parser';
|
|
5
|
-
import xml from 'xml';
|
|
6
5
|
import fs from 'fs';
|
|
7
6
|
|
|
8
7
|
var __defProp$9 = Object.defineProperty;
|
|
9
8
|
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
-
var __publicField$9 = (obj, key, value) =>
|
|
11
|
-
__defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
12
|
-
return value;
|
|
13
|
-
};
|
|
9
|
+
var __publicField$9 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
14
10
|
class CSVStream {
|
|
15
11
|
constructor({ delimiter, lineSeparator, emptyFieldValue }) {
|
|
16
12
|
__publicField$9(this, "stream", new PassThrough());
|
|
@@ -18,12 +14,9 @@ class CSVStream {
|
|
|
18
14
|
__publicField$9(this, "lineSeparator", "\n");
|
|
19
15
|
__publicField$9(this, "emptyFieldValue", "");
|
|
20
16
|
__publicField$9(this, "columns", /* @__PURE__ */ new Set());
|
|
21
|
-
if (delimiter !== void 0)
|
|
22
|
-
|
|
23
|
-
if (
|
|
24
|
-
this.lineSeparator = lineSeparator;
|
|
25
|
-
if (emptyFieldValue !== void 0)
|
|
26
|
-
this.emptyFieldValue = emptyFieldValue;
|
|
17
|
+
if (delimiter !== void 0) this.delimiter = delimiter;
|
|
18
|
+
if (lineSeparator !== void 0) this.lineSeparator = lineSeparator;
|
|
19
|
+
if (emptyFieldValue !== void 0) this.emptyFieldValue = emptyFieldValue;
|
|
27
20
|
}
|
|
28
21
|
getWritableStream() {
|
|
29
22
|
return this.stream;
|
|
@@ -55,10 +48,7 @@ var Extension = /* @__PURE__ */ ((Extension2) => {
|
|
|
55
48
|
|
|
56
49
|
var __defProp$8 = Object.defineProperty;
|
|
57
50
|
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
58
|
-
var __publicField$8 = (obj, key, value) =>
|
|
59
|
-
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
60
|
-
return value;
|
|
61
|
-
};
|
|
51
|
+
var __publicField$8 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
62
52
|
class CSVFormatter {
|
|
63
53
|
constructor() {
|
|
64
54
|
__publicField$8(this, "formatterName", "CSV");
|
|
@@ -100,8 +90,7 @@ class CSVFormatter {
|
|
|
100
90
|
]);
|
|
101
91
|
products.forEach((product) => {
|
|
102
92
|
Object.entries(product).forEach(([key, value]) => {
|
|
103
|
-
if (value)
|
|
104
|
-
columns.add(key);
|
|
93
|
+
if (value) columns.add(key);
|
|
105
94
|
});
|
|
106
95
|
});
|
|
107
96
|
csvStream.setColumns(columns);
|
|
@@ -121,16 +110,14 @@ class CSVFormatter {
|
|
|
121
110
|
};
|
|
122
111
|
csvStream.addRow(row);
|
|
123
112
|
});
|
|
113
|
+
csvStream.getWritableStream().end();
|
|
124
114
|
return csvStream.getWritableStream();
|
|
125
115
|
}
|
|
126
116
|
}
|
|
127
117
|
|
|
128
118
|
var __defProp$7 = Object.defineProperty;
|
|
129
119
|
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
130
|
-
var __publicField$7 = (obj, key, value) =>
|
|
131
|
-
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
132
|
-
return value;
|
|
133
|
-
};
|
|
120
|
+
var __publicField$7 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
134
121
|
const { stream: stream$2 } = pkg;
|
|
135
122
|
class ExcelFormatter {
|
|
136
123
|
constructor() {
|
|
@@ -168,11 +155,13 @@ class ExcelFormatter {
|
|
|
168
155
|
]);
|
|
169
156
|
products.forEach((product) => {
|
|
170
157
|
Object.entries(product).forEach(([key, value]) => {
|
|
171
|
-
if (value)
|
|
172
|
-
columns.add(key);
|
|
158
|
+
if (value) columns.add(key);
|
|
173
159
|
});
|
|
174
160
|
});
|
|
175
|
-
const
|
|
161
|
+
const passThroughStream = new PassThrough();
|
|
162
|
+
const workbook = new stream$2.xlsx.WorkbookWriter({
|
|
163
|
+
stream: passThroughStream
|
|
164
|
+
});
|
|
176
165
|
const worksheet = workbook.addWorksheet("products");
|
|
177
166
|
worksheet.columns = Array.from(columns).map((column) => ({
|
|
178
167
|
key: column,
|
|
@@ -196,16 +185,14 @@ class ExcelFormatter {
|
|
|
196
185
|
});
|
|
197
186
|
worksheet.commit();
|
|
198
187
|
await workbook.commit();
|
|
199
|
-
|
|
188
|
+
passThroughStream.end();
|
|
189
|
+
return passThroughStream;
|
|
200
190
|
}
|
|
201
191
|
}
|
|
202
192
|
|
|
203
193
|
var __defProp$6 = Object.defineProperty;
|
|
204
194
|
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
205
|
-
var __publicField$6 = (obj, key, value) =>
|
|
206
|
-
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
207
|
-
return value;
|
|
208
|
-
};
|
|
195
|
+
var __publicField$6 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
209
196
|
const { stream: stream$1 } = pkg;
|
|
210
197
|
class InsalesFormatter {
|
|
211
198
|
constructor() {
|
|
@@ -235,8 +222,7 @@ class InsalesFormatter {
|
|
|
235
222
|
const categories2 = {};
|
|
236
223
|
const categoryList = new Array();
|
|
237
224
|
function addCategory(categoryId) {
|
|
238
|
-
if (categoryId === void 0)
|
|
239
|
-
return;
|
|
225
|
+
if (categoryId === void 0) return;
|
|
240
226
|
const category = mappedCategories[categoryId];
|
|
241
227
|
if (category) {
|
|
242
228
|
categoryList.push(category.name);
|
|
@@ -251,7 +237,10 @@ class InsalesFormatter {
|
|
|
251
237
|
});
|
|
252
238
|
return categories2;
|
|
253
239
|
};
|
|
254
|
-
const
|
|
240
|
+
const passThroughStream = new PassThrough();
|
|
241
|
+
const workbook = new stream$1.xlsx.WorkbookWriter({
|
|
242
|
+
stream: passThroughStream
|
|
243
|
+
});
|
|
255
244
|
const worksheet = workbook.addWorksheet("products");
|
|
256
245
|
const columns = /* @__PURE__ */ new Set([
|
|
257
246
|
"\u0412\u043D\u0435\u0448\u043D\u0438\u0439 ID",
|
|
@@ -335,16 +324,14 @@ class InsalesFormatter {
|
|
|
335
324
|
});
|
|
336
325
|
worksheet.commit();
|
|
337
326
|
await workbook.commit();
|
|
338
|
-
|
|
327
|
+
passThroughStream.end();
|
|
328
|
+
return passThroughStream;
|
|
339
329
|
}
|
|
340
330
|
}
|
|
341
331
|
|
|
342
332
|
var __defProp$5 = Object.defineProperty;
|
|
343
333
|
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
344
|
-
var __publicField$5 = (obj, key, value) =>
|
|
345
|
-
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
346
|
-
return value;
|
|
347
|
-
};
|
|
334
|
+
var __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
348
335
|
class JSONFormatter {
|
|
349
336
|
constructor() {
|
|
350
337
|
__publicField$5(this, "formatterName", "JSON");
|
|
@@ -361,10 +348,7 @@ class JSONFormatter {
|
|
|
361
348
|
|
|
362
349
|
var __defProp$4 = Object.defineProperty;
|
|
363
350
|
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
364
|
-
var __publicField$4 = (obj, key, value) =>
|
|
365
|
-
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
366
|
-
return value;
|
|
367
|
-
};
|
|
351
|
+
var __publicField$4 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
368
352
|
class SimpleJSONFormatter {
|
|
369
353
|
constructor() {
|
|
370
354
|
__publicField$4(this, "formatterName", "JSON");
|
|
@@ -373,19 +357,16 @@ class SimpleJSONFormatter {
|
|
|
373
357
|
async format(products, categories, brands, _) {
|
|
374
358
|
const groupedProduct = /* @__PURE__ */ new Map();
|
|
375
359
|
products.forEach((product) => {
|
|
376
|
-
if (product.parentId !== void 0)
|
|
377
|
-
return;
|
|
360
|
+
if (product.parentId !== void 0) return;
|
|
378
361
|
groupedProduct.set(product.variantId, {
|
|
379
362
|
...product,
|
|
380
363
|
children: []
|
|
381
364
|
});
|
|
382
365
|
});
|
|
383
366
|
products.forEach((product) => {
|
|
384
|
-
if (product.parentId === void 0)
|
|
385
|
-
return;
|
|
367
|
+
if (product.parentId === void 0) return;
|
|
386
368
|
const parent = groupedProduct.get(product.parentId);
|
|
387
|
-
if (!parent)
|
|
388
|
-
return;
|
|
369
|
+
if (!parent) return;
|
|
389
370
|
parent.children.push(product);
|
|
390
371
|
});
|
|
391
372
|
return new JsonStreamStringify({
|
|
@@ -398,10 +379,7 @@ class SimpleJSONFormatter {
|
|
|
398
379
|
|
|
399
380
|
var __defProp$3 = Object.defineProperty;
|
|
400
381
|
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
401
|
-
var __publicField$3 = (obj, key, value) =>
|
|
402
|
-
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
403
|
-
return value;
|
|
404
|
-
};
|
|
382
|
+
var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
405
383
|
const { stream } = pkg;
|
|
406
384
|
class TgShopFormatter {
|
|
407
385
|
constructor() {
|
|
@@ -426,7 +404,10 @@ class TgShopFormatter {
|
|
|
426
404
|
size: getParameter(product, "size")?.value,
|
|
427
405
|
priority: void 0
|
|
428
406
|
});
|
|
429
|
-
const
|
|
407
|
+
const passThroughStream = new PassThrough();
|
|
408
|
+
const workbook = new stream.xlsx.WorkbookWriter({
|
|
409
|
+
stream: passThroughStream
|
|
410
|
+
});
|
|
430
411
|
const categoryWorksheet = workbook.addWorksheet("categories");
|
|
431
412
|
const productsWorksheet = workbook.addWorksheet("offers");
|
|
432
413
|
categoryWorksheet.columns = [
|
|
@@ -472,16 +453,13 @@ class TgShopFormatter {
|
|
|
472
453
|
categoryWorksheet.commit();
|
|
473
454
|
productsWorksheet.commit();
|
|
474
455
|
await workbook.commit();
|
|
475
|
-
return
|
|
456
|
+
return passThroughStream;
|
|
476
457
|
}
|
|
477
458
|
}
|
|
478
459
|
|
|
479
460
|
var __defProp$2 = Object.defineProperty;
|
|
480
461
|
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
481
|
-
var __publicField$2 = (obj, key, value) =>
|
|
482
|
-
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
483
|
-
return value;
|
|
484
|
-
};
|
|
462
|
+
var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
485
463
|
class TildaFormatter {
|
|
486
464
|
constructor() {
|
|
487
465
|
__publicField$2(this, "formatterName", "Tilda");
|
|
@@ -527,16 +505,14 @@ class TildaFormatter {
|
|
|
527
505
|
};
|
|
528
506
|
csvStream.addRow(row);
|
|
529
507
|
});
|
|
508
|
+
csvStream.getWritableStream().end();
|
|
530
509
|
return csvStream.getWritableStream();
|
|
531
510
|
}
|
|
532
511
|
}
|
|
533
512
|
|
|
534
513
|
var __defProp$1 = Object.defineProperty;
|
|
535
514
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
536
|
-
var __publicField$1 = (obj, key, value) =>
|
|
537
|
-
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
538
|
-
return value;
|
|
539
|
-
};
|
|
515
|
+
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
540
516
|
class YMLFormatter {
|
|
541
517
|
constructor() {
|
|
542
518
|
__publicField$1(this, "formatterName", "YMl");
|
|
@@ -546,53 +522,67 @@ class YMLFormatter {
|
|
|
546
522
|
const result = new PassThrough();
|
|
547
523
|
const builder = new XMLBuilder({
|
|
548
524
|
ignoreAttributes: false,
|
|
549
|
-
cdataPropName: "__cdata"
|
|
525
|
+
cdataPropName: "__cdata",
|
|
526
|
+
format: true,
|
|
527
|
+
indentBy: " "
|
|
550
528
|
});
|
|
551
|
-
const
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
{
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
529
|
+
const date = (/* @__PURE__ */ new Date()).toISOString().replace(/.\d+Z/, "");
|
|
530
|
+
result.write('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n');
|
|
531
|
+
result.write('<yml_catalog date="' + date + '">\n');
|
|
532
|
+
result.write("<shop>\n");
|
|
533
|
+
if (options?.shopName) {
|
|
534
|
+
result.write(builder.build({ name: options.shopName }));
|
|
535
|
+
result.write("\n");
|
|
536
|
+
}
|
|
537
|
+
if (options?.companyName) {
|
|
538
|
+
result.write(builder.build({ company: options.companyName }));
|
|
539
|
+
result.write("\n");
|
|
540
|
+
}
|
|
541
|
+
if (categories) {
|
|
542
|
+
result.write(
|
|
543
|
+
builder.build({
|
|
544
|
+
// tagname: "categories",
|
|
545
|
+
categories: { category: this.getCategories(categories) }
|
|
546
|
+
})
|
|
547
|
+
);
|
|
548
|
+
result.write("\n");
|
|
549
|
+
}
|
|
550
|
+
if (brands) {
|
|
551
|
+
result.write(
|
|
552
|
+
builder.build({ brands: { brand: this.getBrands(brands) } })
|
|
553
|
+
);
|
|
554
|
+
result.write("\n");
|
|
555
|
+
}
|
|
556
|
+
result.write("<offers>\n");
|
|
557
|
+
const offerStream = new PassThrough();
|
|
558
|
+
offerStream.pipe(result, { end: false });
|
|
573
559
|
products.forEach((product) => {
|
|
574
|
-
|
|
560
|
+
const offer = builder.build({ offer: this.getOffer(product) });
|
|
561
|
+
offerStream.write(offer + "\n");
|
|
562
|
+
});
|
|
563
|
+
offerStream.end();
|
|
564
|
+
offerStream.on("end", () => {
|
|
565
|
+
result.write("</offers>\n");
|
|
566
|
+
result.write("</shop>\n");
|
|
567
|
+
result.write("</yml_catalog>\n");
|
|
568
|
+
result.end();
|
|
575
569
|
});
|
|
576
|
-
streamOffers.pipe(result, { end: false });
|
|
577
|
-
offers.close();
|
|
578
|
-
shop.close();
|
|
579
|
-
ymlCatalog.close();
|
|
580
570
|
return result;
|
|
581
571
|
}
|
|
582
572
|
getBrands(brands) {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
573
|
+
if (!brands) return [];
|
|
574
|
+
return brands.map((brand) => ({
|
|
575
|
+
"@_id": brand.id,
|
|
576
|
+
"@_url": brand.coverURL ?? "",
|
|
577
|
+
"#text": brand.name
|
|
588
578
|
}));
|
|
589
579
|
}
|
|
590
580
|
getCategories(categories) {
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
581
|
+
if (!categories) return [];
|
|
582
|
+
return categories.map((cat) => ({
|
|
583
|
+
"@_id": cat.id,
|
|
584
|
+
"@_parentId": cat.parentId ?? "",
|
|
585
|
+
"#text": cat.name
|
|
596
586
|
}));
|
|
597
587
|
}
|
|
598
588
|
getOffer(product) {
|
|
@@ -686,10 +676,7 @@ const Formatters = {
|
|
|
686
676
|
|
|
687
677
|
var __defProp = Object.defineProperty;
|
|
688
678
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
689
|
-
var __publicField = (obj, key, value) =>
|
|
690
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
691
|
-
return value;
|
|
692
|
-
};
|
|
679
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
693
680
|
class GoodsExporter {
|
|
694
681
|
constructor() {
|
|
695
682
|
__publicField(this, "formatter", new Formatters.YMLFormatter());
|