goods-exporter 0.4.7 → 0.5.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/README.md +18 -12
- package/dist/bundle.d.ts +12 -11
- package/dist/cjs/index.cjs +377 -194
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.mjs +379 -177
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +8 -8
package/dist/esm/index.mjs
CHANGED
|
@@ -1,40 +1,47 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { PassThrough } from 'stream';
|
|
2
|
+
import pkg from 'exceljs';
|
|
3
|
+
import { JsonStreamStringify } from 'json-stream-stringify';
|
|
3
4
|
import { XMLBuilder } from 'fast-xml-parser';
|
|
4
|
-
import
|
|
5
|
+
import xml from 'xml';
|
|
6
|
+
import fs from 'fs';
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
product.params?.forEach(
|
|
12
|
-
({ key, value }) => params[`Param [${key}]`] = value
|
|
13
|
-
);
|
|
14
|
-
return params;
|
|
8
|
+
var __defProp$8 = Object.defineProperty;
|
|
9
|
+
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __publicField$8 = (obj, key, value) => {
|
|
11
|
+
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
12
|
+
return value;
|
|
15
13
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
class CSVStream {
|
|
15
|
+
constructor({ delimiter, lineSeparator, emptyFieldValue }) {
|
|
16
|
+
__publicField$8(this, "stream", new PassThrough());
|
|
17
|
+
__publicField$8(this, "delimiter", ";");
|
|
18
|
+
__publicField$8(this, "lineSeparator", "\n");
|
|
19
|
+
__publicField$8(this, "emptyFieldValue", "");
|
|
20
|
+
__publicField$8(this, "columns", /* @__PURE__ */ new Set());
|
|
21
|
+
if (delimiter !== void 0)
|
|
22
|
+
this.delimiter = delimiter;
|
|
23
|
+
if (lineSeparator !== void 0)
|
|
24
|
+
this.lineSeparator = lineSeparator;
|
|
25
|
+
if (emptyFieldValue !== void 0)
|
|
26
|
+
this.emptyFieldValue = emptyFieldValue;
|
|
20
27
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
28
|
+
getWritableStream() {
|
|
29
|
+
return this.stream;
|
|
30
|
+
}
|
|
31
|
+
setColumns(columns) {
|
|
32
|
+
this.columns = columns;
|
|
33
|
+
this.stream.write(
|
|
34
|
+
Array.from(this.columns).join(this.delimiter) + this.lineSeparator
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
addRow(items) {
|
|
38
|
+
this.stream.write(
|
|
39
|
+
Array.from(this.columns).map(
|
|
40
|
+
(key) => items[key] === void 0 ? this.emptyFieldValue : items[key] + ""
|
|
41
|
+
).join(this.delimiter) + this.lineSeparator
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
38
45
|
|
|
39
46
|
class FormatterAbstract {
|
|
40
47
|
}
|
|
@@ -57,25 +64,64 @@ class CSVFormatter {
|
|
|
57
64
|
__publicField$7(this, "formatterName", "CSV");
|
|
58
65
|
__publicField$7(this, "fileExtension", Extension.CSV);
|
|
59
66
|
}
|
|
60
|
-
async format(products, categories, _,
|
|
67
|
+
async format(products, categories, _, __) {
|
|
61
68
|
const mappedCategories = {};
|
|
62
69
|
categories?.forEach(({ id, name }) => mappedCategories[id] = name);
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
70
|
+
const csvStream = new CSVStream({
|
|
71
|
+
delimiter: ";",
|
|
72
|
+
emptyFieldValue: "",
|
|
73
|
+
lineSeparator: "\n"
|
|
74
|
+
});
|
|
75
|
+
const columns = /* @__PURE__ */ new Set([
|
|
76
|
+
"url",
|
|
77
|
+
"productId",
|
|
78
|
+
"parentId",
|
|
79
|
+
"variantId",
|
|
80
|
+
"title",
|
|
81
|
+
"description",
|
|
82
|
+
"vendor",
|
|
83
|
+
"vendorCode",
|
|
84
|
+
"category",
|
|
85
|
+
"images",
|
|
86
|
+
"videos",
|
|
87
|
+
"price",
|
|
88
|
+
"oldPrice",
|
|
89
|
+
"purchasePrice",
|
|
90
|
+
"currency",
|
|
91
|
+
"saleDate",
|
|
92
|
+
"countryOfOrigin",
|
|
93
|
+
"tags",
|
|
94
|
+
"codesTN",
|
|
95
|
+
"params",
|
|
96
|
+
"properties",
|
|
97
|
+
"sizes",
|
|
98
|
+
"keywords",
|
|
99
|
+
"relatedProducts"
|
|
100
|
+
]);
|
|
101
|
+
products.forEach((product) => {
|
|
102
|
+
Object.entries(product).forEach(([key, value]) => {
|
|
103
|
+
if (value)
|
|
104
|
+
columns.add(key);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
csvStream.setColumns(columns);
|
|
108
|
+
products.forEach((product) => {
|
|
109
|
+
const row = {
|
|
110
|
+
...product,
|
|
111
|
+
category: mappedCategories[product.categoryId],
|
|
112
|
+
images: product.images?.join(","),
|
|
113
|
+
videos: product.videos?.join(","),
|
|
114
|
+
tags: product.tags?.join(","),
|
|
115
|
+
codesTN: product.codesTN?.join(", "),
|
|
116
|
+
params: product.params?.map(({ key, value }) => `${key}=${value}`).join(", "),
|
|
117
|
+
properties: product.properties?.map(({ key, value }) => `${key}=${value}`).join(", "),
|
|
118
|
+
sizes: product.sizes?.map(({ name, value }) => `${name}=${value}`).join(", "),
|
|
119
|
+
keywords: product.keywords?.join(","),
|
|
120
|
+
relatedProducts: product.relatedProducts?.join(",")
|
|
121
|
+
};
|
|
122
|
+
csvStream.addRow(row);
|
|
123
|
+
});
|
|
124
|
+
return csvStream.getWritableStream();
|
|
79
125
|
}
|
|
80
126
|
}
|
|
81
127
|
|
|
@@ -85,34 +131,72 @@ var __publicField$6 = (obj, key, value) => {
|
|
|
85
131
|
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
86
132
|
return value;
|
|
87
133
|
};
|
|
88
|
-
const {
|
|
134
|
+
const { stream: stream$2 } = pkg;
|
|
89
135
|
class ExcelFormatter {
|
|
90
136
|
constructor() {
|
|
91
137
|
__publicField$6(this, "formatterName", "Excel");
|
|
92
138
|
__publicField$6(this, "fileExtension", Extension.XLSX);
|
|
93
139
|
}
|
|
94
|
-
async format(products, categories, _,
|
|
140
|
+
async format(products, categories, _, __) {
|
|
95
141
|
const mappedCategories = {};
|
|
96
142
|
categories?.forEach(({ id, name }) => mappedCategories[id] = name);
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
143
|
+
const columns = /* @__PURE__ */ new Set([
|
|
144
|
+
"url",
|
|
145
|
+
"productId",
|
|
146
|
+
"parentId",
|
|
147
|
+
"variantId",
|
|
148
|
+
"title",
|
|
149
|
+
"description",
|
|
150
|
+
"vendor",
|
|
151
|
+
"vendorCode",
|
|
152
|
+
"category",
|
|
153
|
+
"images",
|
|
154
|
+
"videos",
|
|
155
|
+
"price",
|
|
156
|
+
"oldPrice",
|
|
157
|
+
"purchasePrice",
|
|
158
|
+
"currency",
|
|
159
|
+
"saleDate",
|
|
160
|
+
"countryOfOrigin",
|
|
161
|
+
"tags",
|
|
162
|
+
"codesTN",
|
|
163
|
+
"params",
|
|
164
|
+
"properties",
|
|
165
|
+
"sizes",
|
|
166
|
+
"keywords",
|
|
167
|
+
"relatedProducts"
|
|
168
|
+
]);
|
|
169
|
+
products.forEach((product) => {
|
|
170
|
+
Object.entries(product).forEach(([key, value]) => {
|
|
171
|
+
if (value)
|
|
172
|
+
columns.add(key);
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
const workbook = new stream$2.xlsx.WorkbookWriter({});
|
|
176
|
+
const worksheet = workbook.addWorksheet("products");
|
|
177
|
+
worksheet.columns = Array.from(columns).map((column) => ({
|
|
178
|
+
key: column,
|
|
179
|
+
header: column
|
|
111
180
|
}));
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
181
|
+
products.forEach((product) => {
|
|
182
|
+
const row = {
|
|
183
|
+
...product,
|
|
184
|
+
category: mappedCategories[product.categoryId],
|
|
185
|
+
images: product.images?.join(","),
|
|
186
|
+
videos: product.videos?.join(","),
|
|
187
|
+
tags: product.tags?.join(","),
|
|
188
|
+
keywords: product.keywords?.join(","),
|
|
189
|
+
relatedProducts: product.relatedProducts?.join(","),
|
|
190
|
+
codesTN: product.codesTN?.join(", "),
|
|
191
|
+
params: product.params?.map(({ key, value }) => `${key}=${value}`).join(", "),
|
|
192
|
+
properties: product.properties?.map(({ key, value }) => `${key}=${value}`).join(", "),
|
|
193
|
+
sizes: product.sizes?.map(({ name, value }) => `${name}=${value}`).join(", ")
|
|
194
|
+
};
|
|
195
|
+
worksheet.addRow(row).commit();
|
|
196
|
+
});
|
|
197
|
+
worksheet.commit();
|
|
198
|
+
await workbook.commit();
|
|
199
|
+
return workbook.stream;
|
|
116
200
|
}
|
|
117
201
|
}
|
|
118
202
|
|
|
@@ -122,6 +206,7 @@ var __publicField$5 = (obj, key, value) => {
|
|
|
122
206
|
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
123
207
|
return value;
|
|
124
208
|
};
|
|
209
|
+
const { stream: stream$1 } = pkg;
|
|
125
210
|
class InsalesFormatter {
|
|
126
211
|
constructor() {
|
|
127
212
|
__publicField$5(this, "formatterName", "Insales");
|
|
@@ -166,41 +251,91 @@ class InsalesFormatter {
|
|
|
166
251
|
});
|
|
167
252
|
return categories2;
|
|
168
253
|
};
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
\
|
|
173
|
-
"\
|
|
174
|
-
"\
|
|
175
|
-
"\
|
|
176
|
-
"\
|
|
177
|
-
|
|
178
|
-
\
|
|
179
|
-
"\
|
|
180
|
-
"\
|
|
181
|
-
"\
|
|
182
|
-
"\
|
|
183
|
-
\
|
|
184
|
-
"\
|
|
185
|
-
\
|
|
186
|
-
"\
|
|
187
|
-
"\
|
|
188
|
-
\
|
|
189
|
-
"\
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
"\
|
|
193
|
-
"\
|
|
194
|
-
"\
|
|
195
|
-
"\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440
|
|
196
|
-
"\
|
|
197
|
-
"\
|
|
198
|
-
"\
|
|
254
|
+
const workbook = new stream$1.xlsx.WorkbookWriter({});
|
|
255
|
+
const worksheet = workbook.addWorksheet("products");
|
|
256
|
+
const columns = /* @__PURE__ */ new Set([
|
|
257
|
+
"\u0412\u043D\u0435\u0448\u043D\u0438\u0439 ID",
|
|
258
|
+
"\u0421\u0441\u044B\u043B\u043A\u0430 \u043D\u0430 \u0442\u043E\u0432\u0430\u0440",
|
|
259
|
+
"\u0410\u0440\u0442\u0438\u043A\u0443\u043B",
|
|
260
|
+
"\u041A\u043E\u0440\u043D\u0435\u0432\u0430\u044F",
|
|
261
|
+
"\u041F\u043E\u0434\u043A\u0430\u0442\u0435\u0433\u043E\u0440\u0438\u044F 1",
|
|
262
|
+
"\u041F\u043E\u0434\u043A\u0430\u0442\u0435\u0433\u043E\u0440\u0438\u044F 2",
|
|
263
|
+
"\u041D\u0430\u0437\u0432\u0430\u043D\u0438\u0435 \u0442\u043E\u0432\u0430\u0440\u0430 \u0438\u043B\u0438 \u0443\u0441\u043B\u0443\u0433\u0438",
|
|
264
|
+
"\u0421\u0442\u0430\u0440\u0430\u044F \u0446\u0435\u043D\u0430",
|
|
265
|
+
"\u0426\u0435\u043D\u0430 \u043F\u0440\u043E\u0434\u0430\u0436\u0438",
|
|
266
|
+
"C\u0435\u0431\u0435\u0441\u0442\u043E\u0438\u043C\u043E\u0441\u0442\u044C",
|
|
267
|
+
"\u041A\u0430\u0442\u0435\u0433\u043E\u0440\u0438\u0438",
|
|
268
|
+
"\u041E\u0441\u0442\u0430\u0442\u043E\u043A",
|
|
269
|
+
"\u0428\u0442\u0440\u0438\u0445-\u043A\u043E\u0434",
|
|
270
|
+
"\u041A\u0440\u0430\u0442\u043A\u043E\u0435 \u043E\u043F\u0438\u0441\u0430\u043D\u0438\u0435",
|
|
271
|
+
"\u041F\u043E\u043B\u043D\u043E\u0435 \u043E\u043F\u0438\u0441\u0430\u043D\u0438\u0435",
|
|
272
|
+
"\u0413\u0430\u0431\u0430\u0440\u0438\u0442\u044B \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u0430",
|
|
273
|
+
"\u0412\u0435\u0441",
|
|
274
|
+
"\u0420\u0430\u0437\u043C\u0435\u0449\u0435\u043D\u0438\u0435 \u043D\u0430 \u0441\u0430\u0439\u0442\u0435",
|
|
275
|
+
"\u041D\u0414\u0421",
|
|
276
|
+
"\u0412\u0430\u043B\u044E\u0442\u0430 \u0441\u043A\u043B\u0430\u0434\u0430",
|
|
277
|
+
"\u0418\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u0430",
|
|
278
|
+
"\u0418\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F",
|
|
279
|
+
"\u0421\u0441\u044B\u043B\u043A\u0430 \u043D\u0430 \u0432\u0438\u0434\u0435\u043E",
|
|
280
|
+
"\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B",
|
|
281
|
+
"\u0421\u0432\u043E\u0439\u0441\u0442\u0432\u0430",
|
|
282
|
+
"\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u0411\u0440\u0435\u043D\u0434",
|
|
283
|
+
"\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u041A\u043E\u043B\u043B\u0435\u043A\u0446\u0438\u044F",
|
|
284
|
+
"\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u041F\u043E\u043B",
|
|
285
|
+
"\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u0414\u0430\u0442\u0430 \u0432\u044B\u0445\u043E\u0434\u0430",
|
|
286
|
+
"\u0420\u0430\u0437\u043C\u0435\u0440\u043D\u0430\u044F \u0441\u0435\u0442\u043A\u0430",
|
|
287
|
+
"\u0421\u0432\u044F\u0437\u0430\u043D\u043D\u044B\u0435 \u0442\u043E\u0432\u0430\u0440\u044B",
|
|
288
|
+
"\u041A\u043B\u044E\u0447\u0435\u0432\u044B\u0435 \u0441\u043B\u043E\u0432\u0430"
|
|
289
|
+
]);
|
|
290
|
+
products.forEach((product) => {
|
|
291
|
+
Object.keys({
|
|
292
|
+
...getParams(product),
|
|
293
|
+
...getProperties(product)
|
|
294
|
+
}).forEach((key) => {
|
|
295
|
+
columns.add(key);
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
worksheet.columns = Array.from(columns).map((column) => ({
|
|
299
|
+
header: column,
|
|
300
|
+
key: column
|
|
199
301
|
}));
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
302
|
+
products.forEach((product) => {
|
|
303
|
+
const row = {
|
|
304
|
+
"\u0412\u043D\u0435\u0448\u043D\u0438\u0439 ID": product.productId,
|
|
305
|
+
"\u0421\u0441\u044B\u043B\u043A\u0430 \u043D\u0430 \u0442\u043E\u0432\u0430\u0440": product.url,
|
|
306
|
+
\u0410\u0440\u0442\u0438\u043A\u0443\u043B: product.vendorCode,
|
|
307
|
+
"\u041D\u0430\u0437\u0432\u0430\u043D\u0438\u0435 \u0442\u043E\u0432\u0430\u0440\u0430 \u0438\u043B\u0438 \u0443\u0441\u043B\u0443\u0433\u0438": product.title,
|
|
308
|
+
"\u0421\u0442\u0430\u0440\u0430\u044F \u0446\u0435\u043D\u0430": product.oldPrice,
|
|
309
|
+
"\u0426\u0435\u043D\u0430 \u043F\u0440\u043E\u0434\u0430\u0436\u0438": product.price,
|
|
310
|
+
C\u0435\u0431\u0435\u0441\u0442\u043E\u0438\u043C\u043E\u0441\u0442\u044C: product.purchasePrice,
|
|
311
|
+
...getCategories(product),
|
|
312
|
+
\u041E\u0441\u0442\u0430\u0442\u043E\u043A: product.count,
|
|
313
|
+
"\u0428\u0442\u0440\u0438\u0445-\u043A\u043E\u0434": product.barcode,
|
|
314
|
+
"\u041A\u0440\u0430\u0442\u043A\u043E\u0435 \u043E\u043F\u0438\u0441\u0430\u043D\u0438\u0435": void 0,
|
|
315
|
+
"\u041F\u043E\u043B\u043D\u043E\u0435 \u043E\u043F\u0438\u0441\u0430\u043D\u0438\u0435": product.description,
|
|
316
|
+
"\u0413\u0430\u0431\u0430\u0440\u0438\u0442\u044B \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u0430": product.dimensions,
|
|
317
|
+
\u0412\u0435\u0441: product.weight,
|
|
318
|
+
"\u0420\u0430\u0437\u043C\u0435\u0449\u0435\u043D\u0438\u0435 \u043D\u0430 \u0441\u0430\u0439\u0442\u0435": product.available,
|
|
319
|
+
\u041D\u0414\u0421: product.vat.toString(),
|
|
320
|
+
"\u0412\u0430\u043B\u044E\u0442\u0430 \u0441\u043A\u043B\u0430\u0434\u0430": product.currency.toString(),
|
|
321
|
+
"\u0418\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u0430": product.parentId === void 0 ? product.images?.join(" ") : void 0,
|
|
322
|
+
\u0418\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F: product.parentId === void 0 ? void 0 : product.images?.join(" "),
|
|
323
|
+
"\u0421\u0441\u044B\u043B\u043A\u0430 \u043D\u0430 \u0432\u0438\u0434\u0435\u043E": product.videos ? product.videos[0] : void 0,
|
|
324
|
+
...getParams(product),
|
|
325
|
+
...getProperties(product),
|
|
326
|
+
"\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u0411\u0440\u0435\u043D\u0434": product.vendor,
|
|
327
|
+
"\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u041A\u043E\u043B\u043B\u0435\u043A\u0446\u0438\u044F": product.seriesName,
|
|
328
|
+
"\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u041F\u043E\u043B": product.gender,
|
|
329
|
+
"\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u0414\u0430\u0442\u0430 \u0432\u044B\u0445\u043E\u0434\u0430": product.saleDate,
|
|
330
|
+
"\u0420\u0430\u0437\u043C\u0435\u0440\u043D\u0430\u044F \u0441\u0435\u0442\u043A\u0430": JSON.stringify(product.sizes),
|
|
331
|
+
"\u0421\u0432\u044F\u0437\u0430\u043D\u043D\u044B\u0435 \u0442\u043E\u0432\u0430\u0440\u044B": product.relatedProducts?.join(","),
|
|
332
|
+
"\u041A\u043B\u044E\u0447\u0435\u0432\u044B\u0435 \u0441\u043B\u043E\u0432\u0430": product.keywords?.join(",")
|
|
333
|
+
};
|
|
334
|
+
worksheet.addRow(row).commit();
|
|
335
|
+
});
|
|
336
|
+
worksheet.commit();
|
|
337
|
+
await workbook.commit();
|
|
338
|
+
return workbook.stream;
|
|
204
339
|
}
|
|
205
340
|
}
|
|
206
341
|
|
|
@@ -216,12 +351,11 @@ class JSONFormatter {
|
|
|
216
351
|
__publicField$4(this, "fileExtension", Extension.JSON);
|
|
217
352
|
}
|
|
218
353
|
async format(products, categories, brands, _) {
|
|
219
|
-
|
|
354
|
+
return new JsonStreamStringify({
|
|
220
355
|
categories,
|
|
221
356
|
brands,
|
|
222
357
|
products
|
|
223
|
-
};
|
|
224
|
-
return JSON.stringify(result);
|
|
358
|
+
});
|
|
225
359
|
}
|
|
226
360
|
}
|
|
227
361
|
|
|
@@ -231,6 +365,7 @@ var __publicField$3 = (obj, key, value) => {
|
|
|
231
365
|
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
232
366
|
return value;
|
|
233
367
|
};
|
|
368
|
+
const { stream } = pkg;
|
|
234
369
|
class TgShopFormatter {
|
|
235
370
|
constructor() {
|
|
236
371
|
__publicField$3(this, "formatterName", "TgShop");
|
|
@@ -238,7 +373,7 @@ class TgShopFormatter {
|
|
|
238
373
|
}
|
|
239
374
|
async format(products, categories, _, __) {
|
|
240
375
|
const getParameter = (product, key) => product.params?.find((value) => value.key === key);
|
|
241
|
-
const
|
|
376
|
+
const convertProduct = (product) => ({
|
|
242
377
|
"category id": product.categoryId,
|
|
243
378
|
"group id": product.parentId,
|
|
244
379
|
"id product": product.variantId,
|
|
@@ -248,18 +383,59 @@ class TgShopFormatter {
|
|
|
248
383
|
vendorCode: product.vendorCode,
|
|
249
384
|
oldprice: product.oldPrice,
|
|
250
385
|
description: product.description,
|
|
251
|
-
shortDescription:
|
|
386
|
+
shortDescription: "",
|
|
252
387
|
quantityInStock: product.count,
|
|
253
388
|
color: getParameter(product, "color")?.value,
|
|
254
389
|
size: getParameter(product, "size")?.value,
|
|
255
390
|
priority: void 0
|
|
391
|
+
});
|
|
392
|
+
const workbook = new stream.xlsx.WorkbookWriter({});
|
|
393
|
+
const categoryWorksheet = workbook.addWorksheet("categories");
|
|
394
|
+
const productsWorksheet = workbook.addWorksheet("offers");
|
|
395
|
+
categoryWorksheet.columns = [
|
|
396
|
+
{
|
|
397
|
+
header: "id",
|
|
398
|
+
key: "id"
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
header: "parentId",
|
|
402
|
+
key: "parentId"
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
header: "name",
|
|
406
|
+
key: "name"
|
|
407
|
+
}
|
|
408
|
+
];
|
|
409
|
+
const columns = [
|
|
410
|
+
"category id",
|
|
411
|
+
"group id",
|
|
412
|
+
"id product",
|
|
413
|
+
"name product",
|
|
414
|
+
"price",
|
|
415
|
+
"picture",
|
|
416
|
+
"vendorCode",
|
|
417
|
+
"oldprice",
|
|
418
|
+
"description",
|
|
419
|
+
"shortDescription",
|
|
420
|
+
"quantityInStock",
|
|
421
|
+
"color",
|
|
422
|
+
"size",
|
|
423
|
+
"priority"
|
|
424
|
+
];
|
|
425
|
+
productsWorksheet.columns = columns.map((column) => ({
|
|
426
|
+
header: column,
|
|
427
|
+
key: column
|
|
256
428
|
}));
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
429
|
+
categories?.forEach((category) => {
|
|
430
|
+
categoryWorksheet.addRow(category).commit();
|
|
431
|
+
});
|
|
432
|
+
products.forEach((product) => {
|
|
433
|
+
productsWorksheet.addRow(convertProduct(product)).commit();
|
|
434
|
+
});
|
|
435
|
+
categoryWorksheet.commit();
|
|
436
|
+
productsWorksheet.commit();
|
|
437
|
+
await workbook.commit();
|
|
438
|
+
return workbook.stream;
|
|
263
439
|
}
|
|
264
440
|
}
|
|
265
441
|
|
|
@@ -277,21 +453,44 @@ class TildaFormatter {
|
|
|
277
453
|
async format(products, categories, _, __) {
|
|
278
454
|
const mappedCategories = {};
|
|
279
455
|
categories?.forEach(({ id, name }) => mappedCategories[id] = name);
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
"
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
"
|
|
292
|
-
"
|
|
293
|
-
|
|
294
|
-
|
|
456
|
+
const csvStream = new CSVStream({
|
|
457
|
+
delimiter: ";",
|
|
458
|
+
emptyFieldValue: "",
|
|
459
|
+
lineSeparator: "\n"
|
|
460
|
+
});
|
|
461
|
+
const columns = /* @__PURE__ */ new Set([
|
|
462
|
+
"SKU",
|
|
463
|
+
"Brand",
|
|
464
|
+
"Category",
|
|
465
|
+
"Title",
|
|
466
|
+
"Text",
|
|
467
|
+
"Photo",
|
|
468
|
+
"Price",
|
|
469
|
+
"Price Old",
|
|
470
|
+
"Quantity",
|
|
471
|
+
"Editions",
|
|
472
|
+
"External ID",
|
|
473
|
+
"Parent UID"
|
|
474
|
+
]);
|
|
475
|
+
csvStream.setColumns(columns);
|
|
476
|
+
products.forEach((product) => {
|
|
477
|
+
const row = {
|
|
478
|
+
SKU: product.vendorCode,
|
|
479
|
+
Brand: product.vendor,
|
|
480
|
+
Category: mappedCategories[product.categoryId],
|
|
481
|
+
Title: product.title,
|
|
482
|
+
Text: product.description,
|
|
483
|
+
Photo: product.images?.join(";"),
|
|
484
|
+
Price: product.price,
|
|
485
|
+
"Price Old": product.oldPrice,
|
|
486
|
+
Quantity: product.count,
|
|
487
|
+
Editions: product.params?.map(({ key, value }) => `${key}:${value}`).join(";"),
|
|
488
|
+
"External ID": product.variantId,
|
|
489
|
+
"Parent UID": product.parentId
|
|
490
|
+
};
|
|
491
|
+
csvStream.addRow(row);
|
|
492
|
+
});
|
|
493
|
+
return csvStream.getWritableStream();
|
|
295
494
|
}
|
|
296
495
|
}
|
|
297
496
|
|
|
@@ -305,51 +504,57 @@ class YMLFormatter {
|
|
|
305
504
|
constructor() {
|
|
306
505
|
__publicField$1(this, "formatterName", "YMl");
|
|
307
506
|
__publicField$1(this, "fileExtension", Extension.YML);
|
|
308
|
-
__publicField$1(this, "builder", new XMLBuilder({
|
|
309
|
-
ignoreAttributes: false,
|
|
310
|
-
processEntities: false,
|
|
311
|
-
format: true,
|
|
312
|
-
cdataPropName: "__cdata"
|
|
313
|
-
}));
|
|
314
507
|
}
|
|
315
508
|
async format(products, categories, brands, options) {
|
|
316
|
-
const
|
|
317
|
-
const
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
brands: this.getBrands(brands),
|
|
330
|
-
offers
|
|
331
|
-
}
|
|
509
|
+
const result = new PassThrough();
|
|
510
|
+
const builder = new XMLBuilder({
|
|
511
|
+
ignoreAttributes: false,
|
|
512
|
+
cdataPropName: "__cdata"
|
|
513
|
+
});
|
|
514
|
+
const ymlCatalog = xml.element({
|
|
515
|
+
_attr: { date: (/* @__PURE__ */ new Date()).toISOString().replace(/.\d+Z/, "") }
|
|
516
|
+
});
|
|
517
|
+
const stream = xml(
|
|
518
|
+
{ yml_catalog: ymlCatalog },
|
|
519
|
+
{
|
|
520
|
+
stream: true,
|
|
521
|
+
declaration: { standalone: "yes", encoding: "UTF-8" }
|
|
332
522
|
}
|
|
333
|
-
|
|
334
|
-
|
|
523
|
+
);
|
|
524
|
+
const shop = xml.element();
|
|
525
|
+
const streamShop = xml({ shop }, { stream: true });
|
|
526
|
+
shop.push({ name: options?.shopName });
|
|
527
|
+
shop.push({ company: options?.companyName });
|
|
528
|
+
shop.push({ categories: this.getCategories(categories) });
|
|
529
|
+
shop.push({ brands: this.getBrands(brands) });
|
|
530
|
+
streamShop.pipe(result, { end: false });
|
|
531
|
+
const offers = xml.element();
|
|
532
|
+
const streamOffers = xml({ offers }, { stream: true });
|
|
533
|
+
streamOffers.pipe(result, { end: false });
|
|
534
|
+
products.forEach((product) => {
|
|
535
|
+
result.write(builder.build({ offer: this.getOffers(product) }));
|
|
536
|
+
});
|
|
537
|
+
stream.pipe(result, { end: false });
|
|
538
|
+
offers.close();
|
|
539
|
+
shop.close();
|
|
540
|
+
ymlCatalog.close();
|
|
541
|
+
return result;
|
|
335
542
|
}
|
|
336
543
|
getBrands(brands) {
|
|
337
|
-
return {
|
|
338
|
-
brand:
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
};
|
|
544
|
+
return brands?.map((brand) => ({
|
|
545
|
+
brand: [
|
|
546
|
+
{ _attr: { id: brand.id, url: brand.coverURL ?? "" } },
|
|
547
|
+
brand.name
|
|
548
|
+
]
|
|
549
|
+
}));
|
|
344
550
|
}
|
|
345
551
|
getCategories(categories) {
|
|
346
|
-
return {
|
|
347
|
-
category:
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
};
|
|
552
|
+
return categories?.map((cat) => ({
|
|
553
|
+
category: [
|
|
554
|
+
{ _attr: { id: cat.id, parentId: cat.parentId ?? "" } },
|
|
555
|
+
cat.name
|
|
556
|
+
]
|
|
557
|
+
}));
|
|
353
558
|
}
|
|
354
559
|
getOffers(product) {
|
|
355
560
|
const result = {
|
|
@@ -447,10 +652,10 @@ var __publicField = (obj, key, value) => {
|
|
|
447
652
|
class GoodsExporter {
|
|
448
653
|
constructor() {
|
|
449
654
|
__publicField(this, "formatter", new Formatters.YMLFormatter());
|
|
450
|
-
__publicField(this, "exporter", (
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
655
|
+
__publicField(this, "exporter", () => {
|
|
656
|
+
return fs.createWriteStream(
|
|
657
|
+
`${this.formatter.formatterName}.output.${this.formatter.fileExtension}`
|
|
658
|
+
);
|
|
454
659
|
});
|
|
455
660
|
__publicField(this, "transformers", new Array());
|
|
456
661
|
}
|
|
@@ -467,16 +672,13 @@ class GoodsExporter {
|
|
|
467
672
|
let transformedProducts = products;
|
|
468
673
|
for (const transformer of this.transformers)
|
|
469
674
|
transformedProducts = await transformer(transformedProducts);
|
|
470
|
-
const
|
|
675
|
+
const stream = await this.formatter.format(
|
|
471
676
|
transformedProducts,
|
|
472
677
|
categories,
|
|
473
678
|
brands,
|
|
474
679
|
option
|
|
475
680
|
);
|
|
476
|
-
|
|
477
|
-
return await this.exporter(Buffer.from(data, "utf-8"));
|
|
478
|
-
}
|
|
479
|
-
return await this.exporter(data);
|
|
681
|
+
stream.pipe(this.exporter());
|
|
480
682
|
}
|
|
481
683
|
}
|
|
482
684
|
|