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