closer-cli 2.6.0 → 2.9.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 +24 -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 +52 -20
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,30 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [2.9.0](https://code.hfarm.dev/closer/closer/compare/v2.8.0...v2.9.0) (2022-05-09)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **#PJX-442:** Import ad hoc disponibilità incrementale non bloccante ([aad991b](https://code.hfarm.dev/closer/closer/commits/aad991ba97e76977c6a6a2d73ef614026324b0d3)), closes [#PJX-442](https://code.hfarm.dev/closer/closer/issues/PJX-442)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [2.8.0](https://code.hfarm.dev/closer/closer/compare/v2.7.1...v2.8.0) (2022-04-27)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* **#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)
|
|
23
|
+
* **#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)
|
|
24
|
+
* **#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)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
6
30
|
# [2.6.0](https://code.hfarm.dev/closer/closer/compare/v2.5.1...v2.6.0) (2022-04-19)
|
|
7
31
|
|
|
8
32
|
|
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
|
@@ -36,13 +36,15 @@ exports.ALLOWED_CSV_FILES = {
|
|
|
36
36
|
userCustomer: 'userCustomers.csv'
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
const getCsvFilesFromDir = dir =>
|
|
40
40
|
fs.readdirSync(dir).filter(file => path.extname(file).toLowerCase() === '.csv')
|
|
41
41
|
|
|
42
|
+
exports.getCsvFilesFromDir = getCsvFilesFromDir
|
|
43
|
+
|
|
42
44
|
exports.getGoogleSheetCsvUrl = (docId, sheet) =>
|
|
43
45
|
`https://docs.google.com/spreadsheets/d/${docId}/gviz/tq?tqx=out:csv&sheet=${sheet}`
|
|
44
46
|
|
|
45
|
-
exports.importCsvFromFile = (file, csvType, outputDir, spinner, ws, delimiter = '
|
|
47
|
+
exports.importCsvFromFile = (file, csvType, outputDir, spinner, ws, delimiter = ';') =>
|
|
46
48
|
new Promise(resolve => {
|
|
47
49
|
const socket = this.createSocketConnection(ws.endpoint, ws.adminSecret)
|
|
48
50
|
|
|
@@ -54,6 +56,9 @@ exports.importCsvFromFile = (file, csvType, outputDir, spinner, ws, delimiter =
|
|
|
54
56
|
fs.mkdirSync(outputDir, { recursive: true })
|
|
55
57
|
}
|
|
56
58
|
|
|
59
|
+
const filename = path.basename(file)
|
|
60
|
+
fs.copyFileSync(file, path.resolve(outputDir, filename))
|
|
61
|
+
|
|
57
62
|
const errorCsvFile = path.resolve(outputDir, `${csvType}_errors.csv`)
|
|
58
63
|
const errorFileStream = fs.createWriteStream(errorCsvFile)
|
|
59
64
|
|
|
@@ -66,8 +71,6 @@ exports.importCsvFromFile = (file, csvType, outputDir, spinner, ws, delimiter =
|
|
|
66
71
|
let countFailed = 0
|
|
67
72
|
let countSkipped = 0
|
|
68
73
|
|
|
69
|
-
const filename = path.basename(file)
|
|
70
|
-
|
|
71
74
|
spinner.start('Loading...')
|
|
72
75
|
|
|
73
76
|
const importRowSuccess = () => {
|
|
@@ -221,7 +224,7 @@ exports.importCsvFromFile = (file, csvType, outputDir, spinner, ws, delimiter =
|
|
|
221
224
|
})
|
|
222
225
|
})
|
|
223
226
|
|
|
224
|
-
exports.validateCsvFromFile = (file, csvType, ws, delimiter = '
|
|
227
|
+
exports.validateCsvFromFile = (file, csvType, ws, delimiter = ';') =>
|
|
225
228
|
new Promise(resolve => {
|
|
226
229
|
const socket = this.createSocketConnection(ws.endpoint, ws.adminSecret)
|
|
227
230
|
|
|
@@ -247,20 +250,29 @@ exports.validateCsvFromFile = (file, csvType, ws, delimiter = ',') =>
|
|
|
247
250
|
}
|
|
248
251
|
|
|
249
252
|
if (lineNumber === 1) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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))
|
|
261
274
|
}
|
|
262
275
|
|
|
263
|
-
socket.send(JSON.stringify(packet))
|
|
264
276
|
readStream.destroy()
|
|
265
277
|
}
|
|
266
278
|
|
|
@@ -420,7 +432,6 @@ exports.refreshOrders = (spinner, ws) =>
|
|
|
420
432
|
const { type, payload } = JSON.parse(packet)
|
|
421
433
|
switch (type) {
|
|
422
434
|
case 'refreshDraftOrdersResponse': {
|
|
423
|
-
console.log(JSON.stringify({ type, payload }))
|
|
424
435
|
spinner.text = this.printRefreshedOrders({
|
|
425
436
|
...payload,
|
|
426
437
|
executionTime: this.getExecutionTime(hrstart)
|
|
@@ -710,11 +721,32 @@ exports.flushMedia = (spinner, ws) =>
|
|
|
710
721
|
})
|
|
711
722
|
|
|
712
723
|
exports.getArchiveFolder = instanceEndpoint => {
|
|
713
|
-
const date = new Date()
|
|
714
724
|
const prefix = 'closer'
|
|
715
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()
|
|
716
748
|
const [isoDateString, isoTimeString] = date.toISOString().split('T')
|
|
717
749
|
const dateString = isoDateString.split('-').join('')
|
|
718
750
|
const timeString = isoTimeString.split(':').join('').split('.')[0]
|
|
719
|
-
return `${
|
|
751
|
+
return `${dateString}_${timeString}`.split(':').join('')
|
|
720
752
|
}
|