goods-exporter 0.5.3 → 0.5.5
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 +85 -86
package/LICENSE
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright © 2023 German Bagdasaryan
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
-
a copy of this software and associated documentation files (the
|
|
7
|
-
“Software”), to deal in the Software without restriction, including
|
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
-
the following conditions:
|
|
12
|
-
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
|
14
|
-
included in all copies or substantial portions of the Software.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
18
|
-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright © 2023 German Bagdasaryan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
“Software”), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
18
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
22
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,102 +1,103 @@
|
|
|
1
|
-
# goods-exporter
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/goods-exporter)
|
|
4
|
-

|
|
5
|
-

|
|
6
|
-
[](https://github.com/Bagi4-source/goods-converter/blob/main/LICENSE)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
A versatile JavaScript library for exporting goods data to various formats such as YML, CSV, and Excel. Simplify data
|
|
10
|
-
export tasks with ease.
|
|
11
|
-
|
|
12
|
-
[](https://t.me/+gGHmBC8VZ4BjYjZi)
|
|
13
|
-
|
|
14
|
-
## Features
|
|
15
|
-
|
|
16
|
-
- Export goods data to JSON, YML, CSV, and Excel formats.
|
|
17
|
-
- Easily integrate into your JavaScript projects.
|
|
18
|
-
- Compatible with Node.js version 16 and above.
|
|
19
|
-
- Comprehensive TypeScript type definitions included.
|
|
20
|
-
- Supports streams.
|
|
21
|
-
|
|
22
|
-
## Supported formats
|
|
23
|
-
|
|
24
|
-
- YML (Yandex Market Language)
|
|
25
|
-
- JSON
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
import {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
exporter.
|
|
58
|
-
exporter.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
exporter
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
[
|
|
1
|
+
# goods-exporter
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/goods-exporter)
|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
[](https://github.com/Bagi4-source/goods-converter/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
A versatile JavaScript library for exporting goods data to various formats such as YML, CSV, and Excel. Simplify data
|
|
10
|
+
export tasks with ease.
|
|
11
|
+
|
|
12
|
+
[](https://t.me/+gGHmBC8VZ4BjYjZi)
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- Export goods data to JSON, YML, CSV, and Excel formats.
|
|
17
|
+
- Easily integrate into your JavaScript projects.
|
|
18
|
+
- Compatible with Node.js version 16 and above.
|
|
19
|
+
- Comprehensive TypeScript type definitions included.
|
|
20
|
+
- Supports streams.
|
|
21
|
+
|
|
22
|
+
## Supported formats
|
|
23
|
+
|
|
24
|
+
- YML (Yandex Market Language)
|
|
25
|
+
- JSON
|
|
26
|
+
- SimpleJSON (grouped)
|
|
27
|
+
- CSV
|
|
28
|
+
- Excel
|
|
29
|
+
- TgShop
|
|
30
|
+
- Insales
|
|
31
|
+
- Tilda
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
To use `goods-exporter` in your project, simply add it to your dependencies using npm or yarn:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm install goods-exporter --save
|
|
39
|
+
# or
|
|
40
|
+
yarn add goods-exporter
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Quick start
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { GoodsExporter, Product, Category, Formatters } from '../src';
|
|
47
|
+
import { PassThrough } from "stream";
|
|
48
|
+
|
|
49
|
+
// Create an instance of the GoodsExporter class.
|
|
50
|
+
const exporter = new GoodsExporter()
|
|
51
|
+
|
|
52
|
+
const products: Product[] = [] // Put your products;
|
|
53
|
+
const categories: Category[] = [{ id: 1, name: 'Обувь' }]
|
|
54
|
+
|
|
55
|
+
// Call the data export method.
|
|
56
|
+
const stream = new PassThrough();
|
|
57
|
+
exporter.setExporter(() => stream);
|
|
58
|
+
exporter.setFormatter(new Formatters.YMLFormatter());
|
|
59
|
+
exporter.setTransformers([
|
|
60
|
+
(products) => {
|
|
61
|
+
return products.map((product) => ({
|
|
62
|
+
...product,
|
|
63
|
+
price: product.price + 10000,
|
|
64
|
+
images: product.images?.map((image) => image.replace("image", "pic")),
|
|
65
|
+
}));
|
|
66
|
+
},
|
|
67
|
+
]);
|
|
68
|
+
await exporter.export(products, categories);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Example
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import fs from "fs"; // Import the 'fs' module for file writing.
|
|
75
|
+
|
|
76
|
+
// Create an instance of the GoodsExporter class.
|
|
77
|
+
const exporter = new GoodsExporter()
|
|
78
|
+
|
|
79
|
+
// Define an object 'transformers' that contains data transformation functions.
|
|
80
|
+
const transformers: Transformer[] = [
|
|
81
|
+
(products) => products.map(product => ({
|
|
82
|
+
...product,
|
|
83
|
+
price: product.price + 10000
|
|
84
|
+
})),
|
|
85
|
+
(products) => products.map(product => ({
|
|
86
|
+
...product,
|
|
87
|
+
images: product.images?.map(image => image.replace("image", "pic"))
|
|
88
|
+
}))
|
|
89
|
+
]
|
|
90
|
+
|
|
91
|
+
// Set the formatter for exporting data to YML.
|
|
92
|
+
exporter.setFormatter(new Formatters.YMLFormatter()) // or your own Formatter;
|
|
93
|
+
|
|
94
|
+
// Set transformers based on the specified keys.
|
|
95
|
+
exporter.setTransformers(transformers);
|
|
96
|
+
|
|
97
|
+
// Set an exporter that saves the data to the "output.yml" file.
|
|
98
|
+
exporter.setExporter(fs.createWriteStream("output.yml"));
|
|
99
|
+
await exporter.export(products, categories);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
# Supported by [PoizonAPI](https://t.me/PoizonAPI)
|
|
103
|
+
[](https://t.me/PoizonAPI)
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -4,15 +4,11 @@ var stream$3 = require('stream');
|
|
|
4
4
|
var pkg = require('exceljs');
|
|
5
5
|
var jsonStreamStringify = require('json-stream-stringify');
|
|
6
6
|
var fastXmlParser = require('fast-xml-parser');
|
|
7
|
-
var xml = require('xml');
|
|
8
7
|
var fs = require('fs');
|
|
9
8
|
|
|
10
9
|
var __defProp$9 = Object.defineProperty;
|
|
11
10
|
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
-
var __publicField$9 = (obj, key, value) =>
|
|
13
|
-
__defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
14
|
-
return value;
|
|
15
|
-
};
|
|
11
|
+
var __publicField$9 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
16
12
|
class CSVStream {
|
|
17
13
|
constructor({ delimiter, lineSeparator, emptyFieldValue }) {
|
|
18
14
|
__publicField$9(this, "stream", new stream$3.PassThrough());
|
|
@@ -20,12 +16,9 @@ class CSVStream {
|
|
|
20
16
|
__publicField$9(this, "lineSeparator", "\n");
|
|
21
17
|
__publicField$9(this, "emptyFieldValue", "");
|
|
22
18
|
__publicField$9(this, "columns", /* @__PURE__ */ new Set());
|
|
23
|
-
if (delimiter !== void 0)
|
|
24
|
-
|
|
25
|
-
if (
|
|
26
|
-
this.lineSeparator = lineSeparator;
|
|
27
|
-
if (emptyFieldValue !== void 0)
|
|
28
|
-
this.emptyFieldValue = emptyFieldValue;
|
|
19
|
+
if (delimiter !== void 0) this.delimiter = delimiter;
|
|
20
|
+
if (lineSeparator !== void 0) this.lineSeparator = lineSeparator;
|
|
21
|
+
if (emptyFieldValue !== void 0) this.emptyFieldValue = emptyFieldValue;
|
|
29
22
|
}
|
|
30
23
|
getWritableStream() {
|
|
31
24
|
return this.stream;
|
|
@@ -57,10 +50,7 @@ var Extension = /* @__PURE__ */ ((Extension2) => {
|
|
|
57
50
|
|
|
58
51
|
var __defProp$8 = Object.defineProperty;
|
|
59
52
|
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
60
|
-
var __publicField$8 = (obj, key, value) =>
|
|
61
|
-
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
62
|
-
return value;
|
|
63
|
-
};
|
|
53
|
+
var __publicField$8 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
64
54
|
class CSVFormatter {
|
|
65
55
|
constructor() {
|
|
66
56
|
__publicField$8(this, "formatterName", "CSV");
|
|
@@ -102,8 +92,7 @@ class CSVFormatter {
|
|
|
102
92
|
]);
|
|
103
93
|
products.forEach((product) => {
|
|
104
94
|
Object.entries(product).forEach(([key, value]) => {
|
|
105
|
-
if (value)
|
|
106
|
-
columns.add(key);
|
|
95
|
+
if (value) columns.add(key);
|
|
107
96
|
});
|
|
108
97
|
});
|
|
109
98
|
csvStream.setColumns(columns);
|
|
@@ -123,16 +112,14 @@ class CSVFormatter {
|
|
|
123
112
|
};
|
|
124
113
|
csvStream.addRow(row);
|
|
125
114
|
});
|
|
115
|
+
csvStream.getWritableStream().end();
|
|
126
116
|
return csvStream.getWritableStream();
|
|
127
117
|
}
|
|
128
118
|
}
|
|
129
119
|
|
|
130
120
|
var __defProp$7 = Object.defineProperty;
|
|
131
121
|
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
132
|
-
var __publicField$7 = (obj, key, value) =>
|
|
133
|
-
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
134
|
-
return value;
|
|
135
|
-
};
|
|
122
|
+
var __publicField$7 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
136
123
|
const { stream: stream$2 } = pkg;
|
|
137
124
|
class ExcelFormatter {
|
|
138
125
|
constructor() {
|
|
@@ -170,11 +157,13 @@ class ExcelFormatter {
|
|
|
170
157
|
]);
|
|
171
158
|
products.forEach((product) => {
|
|
172
159
|
Object.entries(product).forEach(([key, value]) => {
|
|
173
|
-
if (value)
|
|
174
|
-
columns.add(key);
|
|
160
|
+
if (value) columns.add(key);
|
|
175
161
|
});
|
|
176
162
|
});
|
|
177
|
-
const
|
|
163
|
+
const passThroughStream = new stream$3.PassThrough();
|
|
164
|
+
const workbook = new stream$2.xlsx.WorkbookWriter({
|
|
165
|
+
stream: passThroughStream
|
|
166
|
+
});
|
|
178
167
|
const worksheet = workbook.addWorksheet("products");
|
|
179
168
|
worksheet.columns = Array.from(columns).map((column) => ({
|
|
180
169
|
key: column,
|
|
@@ -198,16 +187,14 @@ class ExcelFormatter {
|
|
|
198
187
|
});
|
|
199
188
|
worksheet.commit();
|
|
200
189
|
await workbook.commit();
|
|
201
|
-
|
|
190
|
+
passThroughStream.end();
|
|
191
|
+
return passThroughStream;
|
|
202
192
|
}
|
|
203
193
|
}
|
|
204
194
|
|
|
205
195
|
var __defProp$6 = Object.defineProperty;
|
|
206
196
|
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
207
|
-
var __publicField$6 = (obj, key, value) =>
|
|
208
|
-
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
209
|
-
return value;
|
|
210
|
-
};
|
|
197
|
+
var __publicField$6 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
211
198
|
const { stream: stream$1 } = pkg;
|
|
212
199
|
class InsalesFormatter {
|
|
213
200
|
constructor() {
|
|
@@ -237,8 +224,7 @@ class InsalesFormatter {
|
|
|
237
224
|
const categories2 = {};
|
|
238
225
|
const categoryList = new Array();
|
|
239
226
|
function addCategory(categoryId) {
|
|
240
|
-
if (categoryId === void 0)
|
|
241
|
-
return;
|
|
227
|
+
if (categoryId === void 0) return;
|
|
242
228
|
const category = mappedCategories[categoryId];
|
|
243
229
|
if (category) {
|
|
244
230
|
categoryList.push(category.name);
|
|
@@ -253,7 +239,10 @@ class InsalesFormatter {
|
|
|
253
239
|
});
|
|
254
240
|
return categories2;
|
|
255
241
|
};
|
|
256
|
-
const
|
|
242
|
+
const passThroughStream = new stream$3.PassThrough();
|
|
243
|
+
const workbook = new stream$1.xlsx.WorkbookWriter({
|
|
244
|
+
stream: passThroughStream
|
|
245
|
+
});
|
|
257
246
|
const worksheet = workbook.addWorksheet("products");
|
|
258
247
|
const columns = /* @__PURE__ */ new Set([
|
|
259
248
|
"\u0412\u043D\u0435\u0448\u043D\u0438\u0439 ID",
|
|
@@ -337,16 +326,14 @@ class InsalesFormatter {
|
|
|
337
326
|
});
|
|
338
327
|
worksheet.commit();
|
|
339
328
|
await workbook.commit();
|
|
340
|
-
|
|
329
|
+
passThroughStream.end();
|
|
330
|
+
return passThroughStream;
|
|
341
331
|
}
|
|
342
332
|
}
|
|
343
333
|
|
|
344
334
|
var __defProp$5 = Object.defineProperty;
|
|
345
335
|
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
346
|
-
var __publicField$5 = (obj, key, value) =>
|
|
347
|
-
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
348
|
-
return value;
|
|
349
|
-
};
|
|
336
|
+
var __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
350
337
|
class JSONFormatter {
|
|
351
338
|
constructor() {
|
|
352
339
|
__publicField$5(this, "formatterName", "JSON");
|
|
@@ -363,10 +350,7 @@ class JSONFormatter {
|
|
|
363
350
|
|
|
364
351
|
var __defProp$4 = Object.defineProperty;
|
|
365
352
|
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
366
|
-
var __publicField$4 = (obj, key, value) =>
|
|
367
|
-
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
368
|
-
return value;
|
|
369
|
-
};
|
|
353
|
+
var __publicField$4 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
370
354
|
class SimpleJSONFormatter {
|
|
371
355
|
constructor() {
|
|
372
356
|
__publicField$4(this, "formatterName", "JSON");
|
|
@@ -375,19 +359,16 @@ class SimpleJSONFormatter {
|
|
|
375
359
|
async format(products, categories, brands, _) {
|
|
376
360
|
const groupedProduct = /* @__PURE__ */ new Map();
|
|
377
361
|
products.forEach((product) => {
|
|
378
|
-
if (product.parentId !== void 0)
|
|
379
|
-
return;
|
|
362
|
+
if (product.parentId !== void 0) return;
|
|
380
363
|
groupedProduct.set(product.variantId, {
|
|
381
364
|
...product,
|
|
382
365
|
children: []
|
|
383
366
|
});
|
|
384
367
|
});
|
|
385
368
|
products.forEach((product) => {
|
|
386
|
-
if (product.parentId === void 0)
|
|
387
|
-
return;
|
|
369
|
+
if (product.parentId === void 0) return;
|
|
388
370
|
const parent = groupedProduct.get(product.parentId);
|
|
389
|
-
if (!parent)
|
|
390
|
-
return;
|
|
371
|
+
if (!parent) return;
|
|
391
372
|
parent.children.push(product);
|
|
392
373
|
});
|
|
393
374
|
return new jsonStreamStringify.JsonStreamStringify({
|
|
@@ -400,10 +381,7 @@ class SimpleJSONFormatter {
|
|
|
400
381
|
|
|
401
382
|
var __defProp$3 = Object.defineProperty;
|
|
402
383
|
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
403
|
-
var __publicField$3 = (obj, key, value) =>
|
|
404
|
-
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
405
|
-
return value;
|
|
406
|
-
};
|
|
384
|
+
var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
407
385
|
const { stream } = pkg;
|
|
408
386
|
class TgShopFormatter {
|
|
409
387
|
constructor() {
|
|
@@ -428,7 +406,10 @@ class TgShopFormatter {
|
|
|
428
406
|
size: getParameter(product, "size")?.value,
|
|
429
407
|
priority: void 0
|
|
430
408
|
});
|
|
431
|
-
const
|
|
409
|
+
const passThroughStream = new stream$3.PassThrough();
|
|
410
|
+
const workbook = new stream.xlsx.WorkbookWriter({
|
|
411
|
+
stream: passThroughStream
|
|
412
|
+
});
|
|
432
413
|
const categoryWorksheet = workbook.addWorksheet("categories");
|
|
433
414
|
const productsWorksheet = workbook.addWorksheet("offers");
|
|
434
415
|
categoryWorksheet.columns = [
|
|
@@ -474,16 +455,13 @@ class TgShopFormatter {
|
|
|
474
455
|
categoryWorksheet.commit();
|
|
475
456
|
productsWorksheet.commit();
|
|
476
457
|
await workbook.commit();
|
|
477
|
-
return
|
|
458
|
+
return passThroughStream;
|
|
478
459
|
}
|
|
479
460
|
}
|
|
480
461
|
|
|
481
462
|
var __defProp$2 = Object.defineProperty;
|
|
482
463
|
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
483
|
-
var __publicField$2 = (obj, key, value) =>
|
|
484
|
-
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
485
|
-
return value;
|
|
486
|
-
};
|
|
464
|
+
var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
487
465
|
class TildaFormatter {
|
|
488
466
|
constructor() {
|
|
489
467
|
__publicField$2(this, "formatterName", "Tilda");
|
|
@@ -529,16 +507,14 @@ class TildaFormatter {
|
|
|
529
507
|
};
|
|
530
508
|
csvStream.addRow(row);
|
|
531
509
|
});
|
|
510
|
+
csvStream.getWritableStream().end();
|
|
532
511
|
return csvStream.getWritableStream();
|
|
533
512
|
}
|
|
534
513
|
}
|
|
535
514
|
|
|
536
515
|
var __defProp$1 = Object.defineProperty;
|
|
537
516
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
538
|
-
var __publicField$1 = (obj, key, value) =>
|
|
539
|
-
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
540
|
-
return value;
|
|
541
|
-
};
|
|
517
|
+
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
542
518
|
class YMLFormatter {
|
|
543
519
|
constructor() {
|
|
544
520
|
__publicField$1(this, "formatterName", "YMl");
|
|
@@ -548,53 +524,67 @@ class YMLFormatter {
|
|
|
548
524
|
const result = new stream$3.PassThrough();
|
|
549
525
|
const builder = new fastXmlParser.XMLBuilder({
|
|
550
526
|
ignoreAttributes: false,
|
|
551
|
-
cdataPropName: "__cdata"
|
|
527
|
+
cdataPropName: "__cdata",
|
|
528
|
+
format: true,
|
|
529
|
+
indentBy: " "
|
|
552
530
|
});
|
|
553
|
-
const
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
{
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
531
|
+
const date = (/* @__PURE__ */ new Date()).toISOString().replace(/.\d+Z/, "");
|
|
532
|
+
result.write('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n');
|
|
533
|
+
result.write('<yml_catalog date="' + date + '">\n');
|
|
534
|
+
result.write("<shop>\n");
|
|
535
|
+
if (options?.shopName) {
|
|
536
|
+
result.write(builder.build({ name: options.shopName }));
|
|
537
|
+
result.write("\n");
|
|
538
|
+
}
|
|
539
|
+
if (options?.companyName) {
|
|
540
|
+
result.write(builder.build({ company: options.companyName }));
|
|
541
|
+
result.write("\n");
|
|
542
|
+
}
|
|
543
|
+
if (categories) {
|
|
544
|
+
result.write(
|
|
545
|
+
builder.build({
|
|
546
|
+
// tagname: "categories",
|
|
547
|
+
categories: { category: this.getCategories(categories) }
|
|
548
|
+
})
|
|
549
|
+
);
|
|
550
|
+
result.write("\n");
|
|
551
|
+
}
|
|
552
|
+
if (brands) {
|
|
553
|
+
result.write(
|
|
554
|
+
builder.build({ brands: { brand: this.getBrands(brands) } })
|
|
555
|
+
);
|
|
556
|
+
result.write("\n");
|
|
557
|
+
}
|
|
558
|
+
result.write("<offers>\n");
|
|
559
|
+
const offerStream = new stream$3.PassThrough();
|
|
560
|
+
offerStream.pipe(result, { end: false });
|
|
575
561
|
products.forEach((product) => {
|
|
576
|
-
|
|
562
|
+
const offer = builder.build({ offer: this.getOffer(product) });
|
|
563
|
+
offerStream.write(offer + "\n");
|
|
564
|
+
});
|
|
565
|
+
offerStream.end();
|
|
566
|
+
offerStream.on("end", () => {
|
|
567
|
+
result.write("</offers>\n");
|
|
568
|
+
result.write("</shop>\n");
|
|
569
|
+
result.write("</yml_catalog>\n");
|
|
570
|
+
result.end();
|
|
577
571
|
});
|
|
578
|
-
streamOffers.pipe(result, { end: false });
|
|
579
|
-
offers.close();
|
|
580
|
-
shop.close();
|
|
581
|
-
ymlCatalog.close();
|
|
582
572
|
return result;
|
|
583
573
|
}
|
|
584
574
|
getBrands(brands) {
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
575
|
+
if (!brands) return [];
|
|
576
|
+
return brands.map((brand) => ({
|
|
577
|
+
"@_id": brand.id,
|
|
578
|
+
"@_url": brand.coverURL ?? "",
|
|
579
|
+
"#text": brand.name
|
|
590
580
|
}));
|
|
591
581
|
}
|
|
592
582
|
getCategories(categories) {
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
583
|
+
if (!categories) return [];
|
|
584
|
+
return categories.map((cat) => ({
|
|
585
|
+
"@_id": cat.id,
|
|
586
|
+
"@_parentId": cat.parentId ?? "",
|
|
587
|
+
"#text": cat.name
|
|
598
588
|
}));
|
|
599
589
|
}
|
|
600
590
|
getOffer(product) {
|
|
@@ -688,10 +678,7 @@ const Formatters = {
|
|
|
688
678
|
|
|
689
679
|
var __defProp = Object.defineProperty;
|
|
690
680
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
691
|
-
var __publicField = (obj, key, value) =>
|
|
692
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
693
|
-
return value;
|
|
694
|
-
};
|
|
681
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
695
682
|
class GoodsExporter {
|
|
696
683
|
constructor() {
|
|
697
684
|
__publicField(this, "formatter", new Formatters.YMLFormatter());
|