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/cjs/index.cjs
CHANGED
|
@@ -1,61 +1,49 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var stream$3 = require('stream');
|
|
4
|
+
var pkg = 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$3.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,72 @@ 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 {
|
|
136
|
+
const { stream: stream$2 } = pkg;
|
|
110
137
|
class ExcelFormatter {
|
|
111
138
|
constructor() {
|
|
112
139
|
__publicField$6(this, "formatterName", "Excel");
|
|
113
140
|
__publicField$6(this, "fileExtension", Extension.XLSX);
|
|
114
141
|
}
|
|
115
|
-
async format(products, categories, _,
|
|
142
|
+
async format(products, categories, _, __) {
|
|
116
143
|
const mappedCategories = {};
|
|
117
144
|
categories?.forEach(({ id, name }) => mappedCategories[id] = name);
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
145
|
+
const columns = /* @__PURE__ */ new Set([
|
|
146
|
+
"url",
|
|
147
|
+
"productId",
|
|
148
|
+
"parentId",
|
|
149
|
+
"variantId",
|
|
150
|
+
"title",
|
|
151
|
+
"description",
|
|
152
|
+
"vendor",
|
|
153
|
+
"vendorCode",
|
|
154
|
+
"category",
|
|
155
|
+
"images",
|
|
156
|
+
"videos",
|
|
157
|
+
"price",
|
|
158
|
+
"oldPrice",
|
|
159
|
+
"purchasePrice",
|
|
160
|
+
"currency",
|
|
161
|
+
"saleDate",
|
|
162
|
+
"countryOfOrigin",
|
|
163
|
+
"tags",
|
|
164
|
+
"codesTN",
|
|
165
|
+
"params",
|
|
166
|
+
"properties",
|
|
167
|
+
"sizes",
|
|
168
|
+
"keywords",
|
|
169
|
+
"relatedProducts"
|
|
170
|
+
]);
|
|
171
|
+
products.forEach((product) => {
|
|
172
|
+
Object.entries(product).forEach(([key, value]) => {
|
|
173
|
+
if (value)
|
|
174
|
+
columns.add(key);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
const workbook = new stream$2.xlsx.WorkbookWriter({});
|
|
178
|
+
const worksheet = workbook.addWorksheet("products");
|
|
179
|
+
worksheet.columns = Array.from(columns).map((column) => ({
|
|
180
|
+
key: column,
|
|
181
|
+
header: column
|
|
132
182
|
}));
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
183
|
+
products.forEach((product) => {
|
|
184
|
+
const row = {
|
|
185
|
+
...product,
|
|
186
|
+
category: mappedCategories[product.categoryId],
|
|
187
|
+
images: product.images?.join(","),
|
|
188
|
+
videos: product.videos?.join(","),
|
|
189
|
+
tags: product.tags?.join(","),
|
|
190
|
+
keywords: product.keywords?.join(","),
|
|
191
|
+
relatedProducts: product.relatedProducts?.join(","),
|
|
192
|
+
codesTN: product.codesTN?.join(", "),
|
|
193
|
+
params: product.params?.map(({ key, value }) => `${key}=${value}`).join(", "),
|
|
194
|
+
properties: product.properties?.map(({ key, value }) => `${key}=${value}`).join(", "),
|
|
195
|
+
sizes: product.sizes?.map(({ name, value }) => `${name}=${value}`).join(", ")
|
|
196
|
+
};
|
|
197
|
+
worksheet.addRow(row).commit();
|
|
198
|
+
});
|
|
199
|
+
worksheet.commit();
|
|
200
|
+
await workbook.commit();
|
|
201
|
+
return workbook.stream;
|
|
137
202
|
}
|
|
138
203
|
}
|
|
139
204
|
|
|
@@ -143,6 +208,7 @@ var __publicField$5 = (obj, key, value) => {
|
|
|
143
208
|
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
144
209
|
return value;
|
|
145
210
|
};
|
|
211
|
+
const { stream: stream$1 } = pkg;
|
|
146
212
|
class InsalesFormatter {
|
|
147
213
|
constructor() {
|
|
148
214
|
__publicField$5(this, "formatterName", "Insales");
|
|
@@ -187,41 +253,91 @@ class InsalesFormatter {
|
|
|
187
253
|
});
|
|
188
254
|
return categories2;
|
|
189
255
|
};
|
|
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
|
-
"\
|
|
256
|
+
const workbook = new stream$1.xlsx.WorkbookWriter({});
|
|
257
|
+
const worksheet = workbook.addWorksheet("products");
|
|
258
|
+
const columns = /* @__PURE__ */ new Set([
|
|
259
|
+
"\u0412\u043D\u0435\u0448\u043D\u0438\u0439 ID",
|
|
260
|
+
"\u0421\u0441\u044B\u043B\u043A\u0430 \u043D\u0430 \u0442\u043E\u0432\u0430\u0440",
|
|
261
|
+
"\u0410\u0440\u0442\u0438\u043A\u0443\u043B",
|
|
262
|
+
"\u041A\u043E\u0440\u043D\u0435\u0432\u0430\u044F",
|
|
263
|
+
"\u041F\u043E\u0434\u043A\u0430\u0442\u0435\u0433\u043E\u0440\u0438\u044F 1",
|
|
264
|
+
"\u041F\u043E\u0434\u043A\u0430\u0442\u0435\u0433\u043E\u0440\u0438\u044F 2",
|
|
265
|
+
"\u041D\u0430\u0437\u0432\u0430\u043D\u0438\u0435 \u0442\u043E\u0432\u0430\u0440\u0430 \u0438\u043B\u0438 \u0443\u0441\u043B\u0443\u0433\u0438",
|
|
266
|
+
"\u0421\u0442\u0430\u0440\u0430\u044F \u0446\u0435\u043D\u0430",
|
|
267
|
+
"\u0426\u0435\u043D\u0430 \u043F\u0440\u043E\u0434\u0430\u0436\u0438",
|
|
268
|
+
"C\u0435\u0431\u0435\u0441\u0442\u043E\u0438\u043C\u043E\u0441\u0442\u044C",
|
|
269
|
+
"\u041A\u0430\u0442\u0435\u0433\u043E\u0440\u0438\u0438",
|
|
270
|
+
"\u041E\u0441\u0442\u0430\u0442\u043E\u043A",
|
|
271
|
+
"\u0428\u0442\u0440\u0438\u0445-\u043A\u043E\u0434",
|
|
272
|
+
"\u041A\u0440\u0430\u0442\u043A\u043E\u0435 \u043E\u043F\u0438\u0441\u0430\u043D\u0438\u0435",
|
|
273
|
+
"\u041F\u043E\u043B\u043D\u043E\u0435 \u043E\u043F\u0438\u0441\u0430\u043D\u0438\u0435",
|
|
274
|
+
"\u0413\u0430\u0431\u0430\u0440\u0438\u0442\u044B \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u0430",
|
|
275
|
+
"\u0412\u0435\u0441",
|
|
276
|
+
"\u0420\u0430\u0437\u043C\u0435\u0449\u0435\u043D\u0438\u0435 \u043D\u0430 \u0441\u0430\u0439\u0442\u0435",
|
|
277
|
+
"\u041D\u0414\u0421",
|
|
278
|
+
"\u0412\u0430\u043B\u044E\u0442\u0430 \u0441\u043A\u043B\u0430\u0434\u0430",
|
|
279
|
+
"\u0418\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u0430",
|
|
280
|
+
"\u0418\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F",
|
|
281
|
+
"\u0421\u0441\u044B\u043B\u043A\u0430 \u043D\u0430 \u0432\u0438\u0434\u0435\u043E",
|
|
282
|
+
"\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B",
|
|
283
|
+
"\u0421\u0432\u043E\u0439\u0441\u0442\u0432\u0430",
|
|
284
|
+
"\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u0411\u0440\u0435\u043D\u0434",
|
|
285
|
+
"\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u041A\u043E\u043B\u043B\u0435\u043A\u0446\u0438\u044F",
|
|
286
|
+
"\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u041F\u043E\u043B",
|
|
287
|
+
"\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u0414\u0430\u0442\u0430 \u0432\u044B\u0445\u043E\u0434\u0430",
|
|
288
|
+
"\u0420\u0430\u0437\u043C\u0435\u0440\u043D\u0430\u044F \u0441\u0435\u0442\u043A\u0430",
|
|
289
|
+
"\u0421\u0432\u044F\u0437\u0430\u043D\u043D\u044B\u0435 \u0442\u043E\u0432\u0430\u0440\u044B",
|
|
290
|
+
"\u041A\u043B\u044E\u0447\u0435\u0432\u044B\u0435 \u0441\u043B\u043E\u0432\u0430"
|
|
291
|
+
]);
|
|
292
|
+
products.forEach((product) => {
|
|
293
|
+
Object.keys({
|
|
294
|
+
...getParams(product),
|
|
295
|
+
...getProperties(product)
|
|
296
|
+
}).forEach((key) => {
|
|
297
|
+
columns.add(key);
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
worksheet.columns = Array.from(columns).map((column) => ({
|
|
301
|
+
header: column,
|
|
302
|
+
key: column
|
|
220
303
|
}));
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
304
|
+
products.forEach((product) => {
|
|
305
|
+
const row = {
|
|
306
|
+
"\u0412\u043D\u0435\u0448\u043D\u0438\u0439 ID": product.productId,
|
|
307
|
+
"\u0421\u0441\u044B\u043B\u043A\u0430 \u043D\u0430 \u0442\u043E\u0432\u0430\u0440": product.url,
|
|
308
|
+
\u0410\u0440\u0442\u0438\u043A\u0443\u043B: product.vendorCode,
|
|
309
|
+
"\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,
|
|
310
|
+
"\u0421\u0442\u0430\u0440\u0430\u044F \u0446\u0435\u043D\u0430": product.oldPrice,
|
|
311
|
+
"\u0426\u0435\u043D\u0430 \u043F\u0440\u043E\u0434\u0430\u0436\u0438": product.price,
|
|
312
|
+
C\u0435\u0431\u0435\u0441\u0442\u043E\u0438\u043C\u043E\u0441\u0442\u044C: product.purchasePrice,
|
|
313
|
+
...getCategories(product),
|
|
314
|
+
\u041E\u0441\u0442\u0430\u0442\u043E\u043A: product.count,
|
|
315
|
+
"\u0428\u0442\u0440\u0438\u0445-\u043A\u043E\u0434": product.barcode,
|
|
316
|
+
"\u041A\u0440\u0430\u0442\u043A\u043E\u0435 \u043E\u043F\u0438\u0441\u0430\u043D\u0438\u0435": void 0,
|
|
317
|
+
"\u041F\u043E\u043B\u043D\u043E\u0435 \u043E\u043F\u0438\u0441\u0430\u043D\u0438\u0435": product.description,
|
|
318
|
+
"\u0413\u0430\u0431\u0430\u0440\u0438\u0442\u044B \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u0430": product.dimensions,
|
|
319
|
+
\u0412\u0435\u0441: product.weight,
|
|
320
|
+
"\u0420\u0430\u0437\u043C\u0435\u0449\u0435\u043D\u0438\u0435 \u043D\u0430 \u0441\u0430\u0439\u0442\u0435": product.available,
|
|
321
|
+
\u041D\u0414\u0421: product.vat.toString(),
|
|
322
|
+
"\u0412\u0430\u043B\u044E\u0442\u0430 \u0441\u043A\u043B\u0430\u0434\u0430": product.currency.toString(),
|
|
323
|
+
"\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,
|
|
324
|
+
\u0418\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F: product.parentId === void 0 ? void 0 : product.images?.join(" "),
|
|
325
|
+
"\u0421\u0441\u044B\u043B\u043A\u0430 \u043D\u0430 \u0432\u0438\u0434\u0435\u043E": product.videos ? product.videos[0] : void 0,
|
|
326
|
+
...getParams(product),
|
|
327
|
+
...getProperties(product),
|
|
328
|
+
"\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u0411\u0440\u0435\u043D\u0434": product.vendor,
|
|
329
|
+
"\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u041A\u043E\u043B\u043B\u0435\u043A\u0446\u0438\u044F": product.seriesName,
|
|
330
|
+
"\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u041F\u043E\u043B": product.gender,
|
|
331
|
+
"\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u0414\u0430\u0442\u0430 \u0432\u044B\u0445\u043E\u0434\u0430": product.saleDate,
|
|
332
|
+
"\u0420\u0430\u0437\u043C\u0435\u0440\u043D\u0430\u044F \u0441\u0435\u0442\u043A\u0430": JSON.stringify(product.sizes),
|
|
333
|
+
"\u0421\u0432\u044F\u0437\u0430\u043D\u043D\u044B\u0435 \u0442\u043E\u0432\u0430\u0440\u044B": product.relatedProducts?.join(","),
|
|
334
|
+
"\u041A\u043B\u044E\u0447\u0435\u0432\u044B\u0435 \u0441\u043B\u043E\u0432\u0430": product.keywords?.join(",")
|
|
335
|
+
};
|
|
336
|
+
worksheet.addRow(row).commit();
|
|
337
|
+
});
|
|
338
|
+
worksheet.commit();
|
|
339
|
+
await workbook.commit();
|
|
340
|
+
return workbook.stream;
|
|
225
341
|
}
|
|
226
342
|
}
|
|
227
343
|
|
|
@@ -237,12 +353,11 @@ class JSONFormatter {
|
|
|
237
353
|
__publicField$4(this, "fileExtension", Extension.JSON);
|
|
238
354
|
}
|
|
239
355
|
async format(products, categories, brands, _) {
|
|
240
|
-
|
|
356
|
+
return new jsonStreamStringify.JsonStreamStringify({
|
|
241
357
|
categories,
|
|
242
358
|
brands,
|
|
243
359
|
products
|
|
244
|
-
};
|
|
245
|
-
return JSON.stringify(result);
|
|
360
|
+
});
|
|
246
361
|
}
|
|
247
362
|
}
|
|
248
363
|
|
|
@@ -252,6 +367,7 @@ var __publicField$3 = (obj, key, value) => {
|
|
|
252
367
|
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
253
368
|
return value;
|
|
254
369
|
};
|
|
370
|
+
const { stream } = pkg;
|
|
255
371
|
class TgShopFormatter {
|
|
256
372
|
constructor() {
|
|
257
373
|
__publicField$3(this, "formatterName", "TgShop");
|
|
@@ -259,7 +375,7 @@ class TgShopFormatter {
|
|
|
259
375
|
}
|
|
260
376
|
async format(products, categories, _, __) {
|
|
261
377
|
const getParameter = (product, key) => product.params?.find((value) => value.key === key);
|
|
262
|
-
const
|
|
378
|
+
const convertProduct = (product) => ({
|
|
263
379
|
"category id": product.categoryId,
|
|
264
380
|
"group id": product.parentId,
|
|
265
381
|
"id product": product.variantId,
|
|
@@ -269,18 +385,59 @@ class TgShopFormatter {
|
|
|
269
385
|
vendorCode: product.vendorCode,
|
|
270
386
|
oldprice: product.oldPrice,
|
|
271
387
|
description: product.description,
|
|
272
|
-
shortDescription:
|
|
388
|
+
shortDescription: "",
|
|
273
389
|
quantityInStock: product.count,
|
|
274
390
|
color: getParameter(product, "color")?.value,
|
|
275
391
|
size: getParameter(product, "size")?.value,
|
|
276
392
|
priority: void 0
|
|
393
|
+
});
|
|
394
|
+
const workbook = new stream.xlsx.WorkbookWriter({});
|
|
395
|
+
const categoryWorksheet = workbook.addWorksheet("categories");
|
|
396
|
+
const productsWorksheet = workbook.addWorksheet("offers");
|
|
397
|
+
categoryWorksheet.columns = [
|
|
398
|
+
{
|
|
399
|
+
header: "id",
|
|
400
|
+
key: "id"
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
header: "parentId",
|
|
404
|
+
key: "parentId"
|
|
405
|
+
},
|
|
406
|
+
{
|
|
407
|
+
header: "name",
|
|
408
|
+
key: "name"
|
|
409
|
+
}
|
|
410
|
+
];
|
|
411
|
+
const columns = [
|
|
412
|
+
"category id",
|
|
413
|
+
"group id",
|
|
414
|
+
"id product",
|
|
415
|
+
"name product",
|
|
416
|
+
"price",
|
|
417
|
+
"picture",
|
|
418
|
+
"vendorCode",
|
|
419
|
+
"oldprice",
|
|
420
|
+
"description",
|
|
421
|
+
"shortDescription",
|
|
422
|
+
"quantityInStock",
|
|
423
|
+
"color",
|
|
424
|
+
"size",
|
|
425
|
+
"priority"
|
|
426
|
+
];
|
|
427
|
+
productsWorksheet.columns = columns.map((column) => ({
|
|
428
|
+
header: column,
|
|
429
|
+
key: column
|
|
277
430
|
}));
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
431
|
+
categories?.forEach((category) => {
|
|
432
|
+
categoryWorksheet.addRow(category).commit();
|
|
433
|
+
});
|
|
434
|
+
products.forEach((product) => {
|
|
435
|
+
productsWorksheet.addRow(convertProduct(product)).commit();
|
|
436
|
+
});
|
|
437
|
+
categoryWorksheet.commit();
|
|
438
|
+
productsWorksheet.commit();
|
|
439
|
+
await workbook.commit();
|
|
440
|
+
return workbook.stream;
|
|
284
441
|
}
|
|
285
442
|
}
|
|
286
443
|
|
|
@@ -298,21 +455,44 @@ class TildaFormatter {
|
|
|
298
455
|
async format(products, categories, _, __) {
|
|
299
456
|
const mappedCategories = {};
|
|
300
457
|
categories?.forEach(({ id, name }) => mappedCategories[id] = name);
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
"
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
"
|
|
313
|
-
"
|
|
314
|
-
|
|
315
|
-
|
|
458
|
+
const csvStream = new CSVStream({
|
|
459
|
+
delimiter: ";",
|
|
460
|
+
emptyFieldValue: "",
|
|
461
|
+
lineSeparator: "\n"
|
|
462
|
+
});
|
|
463
|
+
const columns = /* @__PURE__ */ new Set([
|
|
464
|
+
"SKU",
|
|
465
|
+
"Brand",
|
|
466
|
+
"Category",
|
|
467
|
+
"Title",
|
|
468
|
+
"Text",
|
|
469
|
+
"Photo",
|
|
470
|
+
"Price",
|
|
471
|
+
"Price Old",
|
|
472
|
+
"Quantity",
|
|
473
|
+
"Editions",
|
|
474
|
+
"External ID",
|
|
475
|
+
"Parent UID"
|
|
476
|
+
]);
|
|
477
|
+
csvStream.setColumns(columns);
|
|
478
|
+
products.forEach((product) => {
|
|
479
|
+
const row = {
|
|
480
|
+
SKU: product.vendorCode,
|
|
481
|
+
Brand: product.vendor,
|
|
482
|
+
Category: mappedCategories[product.categoryId],
|
|
483
|
+
Title: product.title,
|
|
484
|
+
Text: product.description,
|
|
485
|
+
Photo: product.images?.join(";"),
|
|
486
|
+
Price: product.price,
|
|
487
|
+
"Price Old": product.oldPrice,
|
|
488
|
+
Quantity: product.count,
|
|
489
|
+
Editions: product.params?.map(({ key, value }) => `${key}:${value}`).join(";"),
|
|
490
|
+
"External ID": product.variantId,
|
|
491
|
+
"Parent UID": product.parentId
|
|
492
|
+
};
|
|
493
|
+
csvStream.addRow(row);
|
|
494
|
+
});
|
|
495
|
+
return csvStream.getWritableStream();
|
|
316
496
|
}
|
|
317
497
|
}
|
|
318
498
|
|
|
@@ -326,51 +506,57 @@ class YMLFormatter {
|
|
|
326
506
|
constructor() {
|
|
327
507
|
__publicField$1(this, "formatterName", "YMl");
|
|
328
508
|
__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
509
|
}
|
|
336
510
|
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
|
-
}
|
|
511
|
+
const result = new stream$3.PassThrough();
|
|
512
|
+
const builder = new fastXmlParser.XMLBuilder({
|
|
513
|
+
ignoreAttributes: false,
|
|
514
|
+
cdataPropName: "__cdata"
|
|
515
|
+
});
|
|
516
|
+
const ymlCatalog = xml.element({
|
|
517
|
+
_attr: { date: (/* @__PURE__ */ new Date()).toISOString().replace(/.\d+Z/, "") }
|
|
518
|
+
});
|
|
519
|
+
const stream = xml(
|
|
520
|
+
{ yml_catalog: ymlCatalog },
|
|
521
|
+
{
|
|
522
|
+
stream: true,
|
|
523
|
+
declaration: { standalone: "yes", encoding: "UTF-8" }
|
|
353
524
|
}
|
|
354
|
-
|
|
355
|
-
|
|
525
|
+
);
|
|
526
|
+
const shop = xml.element();
|
|
527
|
+
const streamShop = xml({ shop }, { stream: true });
|
|
528
|
+
shop.push({ name: options?.shopName });
|
|
529
|
+
shop.push({ company: options?.companyName });
|
|
530
|
+
shop.push({ categories: this.getCategories(categories) });
|
|
531
|
+
shop.push({ brands: this.getBrands(brands) });
|
|
532
|
+
streamShop.pipe(result, { end: false });
|
|
533
|
+
const offers = xml.element();
|
|
534
|
+
const streamOffers = xml({ offers }, { stream: true });
|
|
535
|
+
streamOffers.pipe(result, { end: false });
|
|
536
|
+
products.forEach((product) => {
|
|
537
|
+
result.write(builder.build({ offer: this.getOffers(product) }));
|
|
538
|
+
});
|
|
539
|
+
stream.pipe(result, { end: false });
|
|
540
|
+
offers.close();
|
|
541
|
+
shop.close();
|
|
542
|
+
ymlCatalog.close();
|
|
543
|
+
return result;
|
|
356
544
|
}
|
|
357
545
|
getBrands(brands) {
|
|
358
|
-
return {
|
|
359
|
-
brand:
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
};
|
|
546
|
+
return brands?.map((brand) => ({
|
|
547
|
+
brand: [
|
|
548
|
+
{ _attr: { id: brand.id, url: brand.coverURL ?? "" } },
|
|
549
|
+
brand.name
|
|
550
|
+
]
|
|
551
|
+
}));
|
|
365
552
|
}
|
|
366
553
|
getCategories(categories) {
|
|
367
|
-
return {
|
|
368
|
-
category:
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
};
|
|
554
|
+
return categories?.map((cat) => ({
|
|
555
|
+
category: [
|
|
556
|
+
{ _attr: { id: cat.id, parentId: cat.parentId ?? "" } },
|
|
557
|
+
cat.name
|
|
558
|
+
]
|
|
559
|
+
}));
|
|
374
560
|
}
|
|
375
561
|
getOffers(product) {
|
|
376
562
|
const result = {
|
|
@@ -468,10 +654,10 @@ var __publicField = (obj, key, value) => {
|
|
|
468
654
|
class GoodsExporter {
|
|
469
655
|
constructor() {
|
|
470
656
|
__publicField(this, "formatter", new Formatters.YMLFormatter());
|
|
471
|
-
__publicField(this, "exporter", (
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
657
|
+
__publicField(this, "exporter", () => {
|
|
658
|
+
return fs.createWriteStream(
|
|
659
|
+
`${this.formatter.formatterName}.output.${this.formatter.fileExtension}`
|
|
660
|
+
);
|
|
475
661
|
});
|
|
476
662
|
__publicField(this, "transformers", new Array());
|
|
477
663
|
}
|
|
@@ -488,16 +674,13 @@ class GoodsExporter {
|
|
|
488
674
|
let transformedProducts = products;
|
|
489
675
|
for (const transformer of this.transformers)
|
|
490
676
|
transformedProducts = await transformer(transformedProducts);
|
|
491
|
-
const
|
|
677
|
+
const stream = await this.formatter.format(
|
|
492
678
|
transformedProducts,
|
|
493
679
|
categories,
|
|
494
680
|
brands,
|
|
495
681
|
option
|
|
496
682
|
);
|
|
497
|
-
|
|
498
|
-
return await this.exporter(Buffer.from(data, "utf-8"));
|
|
499
|
-
}
|
|
500
|
-
return await this.exporter(data);
|
|
683
|
+
stream.pipe(this.exporter());
|
|
501
684
|
}
|
|
502
685
|
}
|
|
503
686
|
|