closer-cli 1.0.0 → 2.8.0
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/CHANGELOG.md +59 -0
- package/cmds/importData.js +1 -1
- package/cmds/importData_cmds/multiple.js +4 -3
- package/cmds/importData_cmds/single.js +4 -1
- package/cmds/importStock.js +3 -1
- package/helpers.js +54 -21
- package/package.json +1 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# [2.8.0](https://code.hfarm.dev/closer/closer/compare/v2.7.1...v2.8.0) (2022-04-27)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **#PJX-433:** [Import FTP] Cambiare il valore di default del separatore csv ([ef27bf1](https://code.hfarm.dev/closer/closer/commits/ef27bf17847f17b94ba5ec82846a9c94f521be22)), closes [#PJX-433](https://code.hfarm.dev/closer/closer/issues/PJX-433)
|
|
12
|
+
* **#PJX-437:** [Import] Archiviare anche il file csv sorgente ([9a729c5](https://code.hfarm.dev/closer/closer/commits/9a729c54982537e3bb6eca4bffc1f23c6bcc8aaf)), closes [#PJX-437](https://code.hfarm.dev/closer/closer/issues/PJX-437)
|
|
13
|
+
* **#PJX-439:** Anagrafiche con zero righe ([571ec16](https://code.hfarm.dev/closer/closer/commits/571ec169766cd784e6b7e905fa801f238da31fb6)), closes [#PJX-439](https://code.hfarm.dev/closer/closer/issues/PJX-439)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# [2.6.0](https://code.hfarm.dev/closer/closer/compare/v2.5.1...v2.6.0) (2022-04-19)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* **#PJX-415:** [Server] Import configuration ([a3fa87e](https://code.hfarm.dev/closer/closer/commits/a3fa87ea22c0a0d850afa025a0a04937bbd3b4dd)), closes [#PJX-415](https://code.hfarm.dev/closer/closer/issues/PJX-415)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# [2.5.0](https://code.hfarm.dev/closer/closer/compare/v2.4.0...v2.5.0) (2022-04-13)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Features
|
|
34
|
+
|
|
35
|
+
* **#PJX-388:** Aggiungere alla chat dell'ordine i cambi di stato ([544219c](https://code.hfarm.dev/closer/closer/commits/544219c76e9230db4541366ffc47dabb4c11fb42)), closes [#PJX-388](https://code.hfarm.dev/closer/closer/issues/PJX-388)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# [2.4.0](https://code.hfarm.dev/closer/closer/compare/v2.4.0-beta.1...v2.4.0) (2022-04-11)
|
|
42
|
+
|
|
43
|
+
**Note:** Version bump only for package closer-cli
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# [2.3.0](https://code.hfarm.dev/closer/closer/compare/v2.3.0-beta.0...v2.3.0) (2022-04-06)
|
|
50
|
+
|
|
51
|
+
**Note:** Version bump only for package closer-cli
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# [2.2.0](https://code.hfarm.dev/closer/closer/compare/v2.2.0-beta.1...v2.2.0) (2022-04-06)
|
|
58
|
+
|
|
59
|
+
**Note:** Version bump only for package closer-cli
|
package/cmds/importData.js
CHANGED
|
@@ -19,7 +19,8 @@ const {
|
|
|
19
19
|
callBeforeDataImportProcess,
|
|
20
20
|
callAfterDataImportProcess,
|
|
21
21
|
getExecutionTime,
|
|
22
|
-
getArchiveFolder
|
|
22
|
+
getArchiveFolder,
|
|
23
|
+
renameWithTimestamp
|
|
23
24
|
} = require('../../helpers')
|
|
24
25
|
|
|
25
26
|
exports.command = 'multiple [options]'
|
|
@@ -274,9 +275,9 @@ exports.handler = async argv => {
|
|
|
274
275
|
|
|
275
276
|
report.result = reportRows
|
|
276
277
|
|
|
277
|
-
// const message = getDataImportMessageReport(report)
|
|
278
|
-
|
|
279
278
|
await callAfterDataImportProcess(spinner, ws, report)
|
|
280
279
|
|
|
280
|
+
await renameWithTimestamp(argv.out)
|
|
281
|
+
|
|
281
282
|
process.exit()
|
|
282
283
|
}
|
|
@@ -14,7 +14,8 @@ const {
|
|
|
14
14
|
ALLOWED_CSV_FILES,
|
|
15
15
|
download,
|
|
16
16
|
validateCsvFromFile,
|
|
17
|
-
getArchiveFolder
|
|
17
|
+
getArchiveFolder,
|
|
18
|
+
renameWithTimestamp
|
|
18
19
|
} = require('../../helpers')
|
|
19
20
|
|
|
20
21
|
exports.command = 'single [options]'
|
|
@@ -213,5 +214,7 @@ exports.handler = async argv => {
|
|
|
213
214
|
|
|
214
215
|
await callAfterDataImportProcess(spinner, ws, report)
|
|
215
216
|
|
|
217
|
+
await renameWithTimestamp(argv.out)
|
|
218
|
+
|
|
216
219
|
process.exit()
|
|
217
220
|
}
|
package/cmds/importStock.js
CHANGED
|
@@ -167,7 +167,9 @@ exports.handler = async argv => {
|
|
|
167
167
|
|
|
168
168
|
let filepath = argv.fromFile
|
|
169
169
|
|
|
170
|
-
if (argv.
|
|
170
|
+
if (argv.fromDir) {
|
|
171
|
+
filepath = file.file
|
|
172
|
+
} else if (argv.fromUrl || argv.fromGoogleDocId) {
|
|
171
173
|
spinner.start('Downloading file...')
|
|
172
174
|
filepath = await download(file.url, argv.out, `${csvType}.csv`)
|
|
173
175
|
spinner.succeed('Downloaded file')
|
package/helpers.js
CHANGED
|
@@ -13,7 +13,7 @@ const { createWriteStream } = require('fs')
|
|
|
13
13
|
const slugify = require('slugify')
|
|
14
14
|
|
|
15
15
|
exports.createSocketConnection = (endpoint, adminSecret) => {
|
|
16
|
-
const protocol = endpoint.includes('localhost') ? 'ws' : 'wss'
|
|
16
|
+
const protocol = endpoint.includes('localhost') || endpoint.includes('127.0.0.1') ? 'ws' : 'wss'
|
|
17
17
|
const socket = new WebSocket(`${protocol}://${endpoint}/import`, {
|
|
18
18
|
headers: { 'x-closer-admin-secret': adminSecret }
|
|
19
19
|
})
|
|
@@ -32,16 +32,19 @@ exports.ALLOWED_CSV_FILES = {
|
|
|
32
32
|
filterPosition: 'filterPosition.csv',
|
|
33
33
|
fieldConfiguration: 'fieldConfigurations.csv',
|
|
34
34
|
stockAvailability: 'stockAvailability.csv',
|
|
35
|
+
configuration: 'configurations.csv',
|
|
35
36
|
userCustomer: 'userCustomers.csv'
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
const getCsvFilesFromDir = dir =>
|
|
39
40
|
fs.readdirSync(dir).filter(file => path.extname(file).toLowerCase() === '.csv')
|
|
40
41
|
|
|
42
|
+
exports.getCsvFilesFromDir = getCsvFilesFromDir
|
|
43
|
+
|
|
41
44
|
exports.getGoogleSheetCsvUrl = (docId, sheet) =>
|
|
42
45
|
`https://docs.google.com/spreadsheets/d/${docId}/gviz/tq?tqx=out:csv&sheet=${sheet}`
|
|
43
46
|
|
|
44
|
-
exports.importCsvFromFile = (file, csvType, outputDir, spinner, ws, delimiter = '
|
|
47
|
+
exports.importCsvFromFile = (file, csvType, outputDir, spinner, ws, delimiter = ';') =>
|
|
45
48
|
new Promise(resolve => {
|
|
46
49
|
const socket = this.createSocketConnection(ws.endpoint, ws.adminSecret)
|
|
47
50
|
|
|
@@ -53,6 +56,9 @@ exports.importCsvFromFile = (file, csvType, outputDir, spinner, ws, delimiter =
|
|
|
53
56
|
fs.mkdirSync(outputDir, { recursive: true })
|
|
54
57
|
}
|
|
55
58
|
|
|
59
|
+
const filename = path.basename(file)
|
|
60
|
+
fs.copyFileSync(file, path.resolve(outputDir, filename))
|
|
61
|
+
|
|
56
62
|
const errorCsvFile = path.resolve(outputDir, `${csvType}_errors.csv`)
|
|
57
63
|
const errorFileStream = fs.createWriteStream(errorCsvFile)
|
|
58
64
|
|
|
@@ -65,8 +71,6 @@ exports.importCsvFromFile = (file, csvType, outputDir, spinner, ws, delimiter =
|
|
|
65
71
|
let countFailed = 0
|
|
66
72
|
let countSkipped = 0
|
|
67
73
|
|
|
68
|
-
const filename = path.basename(file)
|
|
69
|
-
|
|
70
74
|
spinner.start('Loading...')
|
|
71
75
|
|
|
72
76
|
const importRowSuccess = () => {
|
|
@@ -220,7 +224,7 @@ exports.importCsvFromFile = (file, csvType, outputDir, spinner, ws, delimiter =
|
|
|
220
224
|
})
|
|
221
225
|
})
|
|
222
226
|
|
|
223
|
-
exports.validateCsvFromFile = (file, csvType, ws, delimiter = '
|
|
227
|
+
exports.validateCsvFromFile = (file, csvType, ws, delimiter = ';') =>
|
|
224
228
|
new Promise(resolve => {
|
|
225
229
|
const socket = this.createSocketConnection(ws.endpoint, ws.adminSecret)
|
|
226
230
|
|
|
@@ -246,20 +250,29 @@ exports.validateCsvFromFile = (file, csvType, ws, delimiter = ',') =>
|
|
|
246
250
|
}
|
|
247
251
|
|
|
248
252
|
if (lineNumber === 1) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
253
|
+
if (line === '') {
|
|
254
|
+
resolve({
|
|
255
|
+
csvType,
|
|
256
|
+
executionTime: this.getExecutionTime(hrstart),
|
|
257
|
+
inputFile: filename
|
|
258
|
+
})
|
|
259
|
+
} else {
|
|
260
|
+
const rows = parse(`${header}\n${line}`, {
|
|
261
|
+
columns: true,
|
|
262
|
+
skip_empty_lines: true,
|
|
263
|
+
skipLinesWithEmptyValues: true,
|
|
264
|
+
delimiter
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
const packet = {
|
|
268
|
+
csvColumns: Object.keys(rows[0]),
|
|
269
|
+
csvType,
|
|
270
|
+
type: 'validateCsvHeaderRequest'
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
socket.send(JSON.stringify(packet))
|
|
260
274
|
}
|
|
261
275
|
|
|
262
|
-
socket.send(JSON.stringify(packet))
|
|
263
276
|
readStream.destroy()
|
|
264
277
|
}
|
|
265
278
|
|
|
@@ -419,7 +432,6 @@ exports.refreshOrders = (spinner, ws) =>
|
|
|
419
432
|
const { type, payload } = JSON.parse(packet)
|
|
420
433
|
switch (type) {
|
|
421
434
|
case 'refreshDraftOrdersResponse': {
|
|
422
|
-
console.log(JSON.stringify({ type, payload }))
|
|
423
435
|
spinner.text = this.printRefreshedOrders({
|
|
424
436
|
...payload,
|
|
425
437
|
executionTime: this.getExecutionTime(hrstart)
|
|
@@ -709,11 +721,32 @@ exports.flushMedia = (spinner, ws) =>
|
|
|
709
721
|
})
|
|
710
722
|
|
|
711
723
|
exports.getArchiveFolder = instanceEndpoint => {
|
|
712
|
-
const date = new Date()
|
|
713
724
|
const prefix = 'closer'
|
|
714
725
|
const instance = slugify(instanceEndpoint.split('/')[0], { lower: true })
|
|
726
|
+
const ts = getTimestampForFilename()
|
|
727
|
+
return `${prefix}_${instance}/${ts}`
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
exports.renameWithTimestamp = dirPath => {
|
|
731
|
+
const ts = getTimestampForFilename()
|
|
732
|
+
|
|
733
|
+
const files = getCsvFilesFromDir(dirPath).map(filename => {
|
|
734
|
+
const oldPath = path.resolve(dirPath, filename)
|
|
735
|
+
const [name, ext] = oldPath.split('.')
|
|
736
|
+
const newPath = `${name}_${ts}.${ext}`
|
|
737
|
+
return {
|
|
738
|
+
oldPath,
|
|
739
|
+
newPath
|
|
740
|
+
}
|
|
741
|
+
})
|
|
742
|
+
|
|
743
|
+
files.forEach(file => fs.rename(file.oldPath, file.newPath, () => {}))
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
const getTimestampForFilename = () => {
|
|
747
|
+
const date = new Date()
|
|
715
748
|
const [isoDateString, isoTimeString] = date.toISOString().split('T')
|
|
716
749
|
const dateString = isoDateString.split('-').join('')
|
|
717
750
|
const timeString = isoTimeString.split(':').join('').split('.')[0]
|
|
718
|
-
return `${
|
|
751
|
+
return `${dateString}_${timeString}`.split(':').join('')
|
|
719
752
|
}
|