closer-cli 2.48.2 ā 2.49.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 +11 -0
- package/cmds/exportData.js +115 -0
- package/cmds/importData.js +10 -9
- package/cmds/importMedia.js +3 -1
- package/index.js +2 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
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.49.0](https://code.hfarm.dev/closer/closer/compare/v2.48.2...v2.49.0) (2023-03-06)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **PJX-483:** Export CSV in formato compatibile per l'import ([e6e88d3](https://code.hfarm.dev/closer/closer/commits/e6e88d39f2b24677cc4f728c4012ba054a5672e3))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [2.48.2](https://code.hfarm.dev/closer/closer/compare/v2.48.1...v2.48.2) (2023-03-03)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package closer-cli
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/* eslint-disable no-await-in-loop */
|
|
2
|
+
/* eslint-disable no-restricted-syntax */
|
|
3
|
+
/* eslint-disable no-console */
|
|
4
|
+
import chalk from 'chalk'
|
|
5
|
+
import prompts from 'prompts'
|
|
6
|
+
import axios from 'axios'
|
|
7
|
+
import { getHumanTimestamp, CsvType } from '../helpers.js'
|
|
8
|
+
|
|
9
|
+
export const command = 'export:data'
|
|
10
|
+
export const desc = 'Export data from Closer'
|
|
11
|
+
|
|
12
|
+
export function builder(yargs) {
|
|
13
|
+
yargs
|
|
14
|
+
.usage(`Usage: ${chalk.cyan('$0 export:data')} [options]`)
|
|
15
|
+
.option('name', {
|
|
16
|
+
alias: 'n',
|
|
17
|
+
describe: 'Define export process name',
|
|
18
|
+
type: 'string',
|
|
19
|
+
default: getHumanTimestamp(new Date())
|
|
20
|
+
})
|
|
21
|
+
.option('csvType', {
|
|
22
|
+
alias: 'c',
|
|
23
|
+
describe: 'CSV type to consider during import',
|
|
24
|
+
choices: CsvType,
|
|
25
|
+
array: true
|
|
26
|
+
})
|
|
27
|
+
.option('csvDelimiter', {
|
|
28
|
+
alias: 's',
|
|
29
|
+
describe: 'CSV Delimiter',
|
|
30
|
+
type: 'string',
|
|
31
|
+
default: ';'
|
|
32
|
+
})
|
|
33
|
+
.option('non-interactive', {
|
|
34
|
+
describe: '',
|
|
35
|
+
type: 'bool'
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function handler(argv) {
|
|
40
|
+
const interactive = !argv.nonInteractive
|
|
41
|
+
|
|
42
|
+
let csvType
|
|
43
|
+
if (interactive && !argv.csvType) {
|
|
44
|
+
const answers = await prompts(
|
|
45
|
+
[
|
|
46
|
+
{
|
|
47
|
+
instructions: false,
|
|
48
|
+
name: 'csvType',
|
|
49
|
+
type: 'multiselect',
|
|
50
|
+
message: 'Select',
|
|
51
|
+
choices: CsvType.map(type => ({ title: type, value: type })),
|
|
52
|
+
min: 1
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
{ onCancel: () => process.exit() }
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
csvType = answers.csvType
|
|
59
|
+
} else {
|
|
60
|
+
csvType = argv.csvType
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (interactive) {
|
|
64
|
+
const { confirmed } = await prompts(
|
|
65
|
+
[
|
|
66
|
+
{
|
|
67
|
+
type: 'confirm',
|
|
68
|
+
name: 'confirmed',
|
|
69
|
+
message: 'Continue?',
|
|
70
|
+
initial: false
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
{ onCancel: () => process.exit() }
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
if (!confirmed) {
|
|
77
|
+
process.exit()
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const data = {
|
|
82
|
+
name: argv.name,
|
|
83
|
+
delimiter: argv.csvDelimiter,
|
|
84
|
+
csvType
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const protocol =
|
|
88
|
+
argv.endpoint.includes('localhost') || argv.endpoint.includes('127.0.0.1') ? 'http' : 'https'
|
|
89
|
+
|
|
90
|
+
const url = `${protocol}://${argv.endpoint}/export/data`
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
const response = await axios.post(url, data, {
|
|
94
|
+
headers: { 'x-closer-secret': argv.secretKey }
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
if (response.data.error) {
|
|
98
|
+
console.error(response.data.message)
|
|
99
|
+
process.exit(1)
|
|
100
|
+
}
|
|
101
|
+
} catch (error) {
|
|
102
|
+
if (error.response?.data?.message) {
|
|
103
|
+
console.error(error.response.data.message)
|
|
104
|
+
}
|
|
105
|
+
console.error(error.message)
|
|
106
|
+
process.exit(1)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
console.log('')
|
|
110
|
+
console.log('ā
Thank you for initiating the data export process!')
|
|
111
|
+
console.log('š« You will receive an email notification once the export is completed.')
|
|
112
|
+
console.log('')
|
|
113
|
+
|
|
114
|
+
process.exit()
|
|
115
|
+
}
|
package/cmds/importData.js
CHANGED
|
@@ -25,7 +25,7 @@ export const desc = 'Import data to Closer'
|
|
|
25
25
|
|
|
26
26
|
export function builder(yargs) {
|
|
27
27
|
yargs
|
|
28
|
-
.usage(`Usage: ${chalk.cyan('$0 import
|
|
28
|
+
.usage(`Usage: ${chalk.cyan('$0 import:data')} [options]`)
|
|
29
29
|
.option('name', {
|
|
30
30
|
alias: 'n',
|
|
31
31
|
describe: 'Define import process name',
|
|
@@ -244,6 +244,13 @@ export async function handler(argv) {
|
|
|
244
244
|
headers: { ...formData.getHeaders(), 'x-closer-secret': argv.secretKey }
|
|
245
245
|
})
|
|
246
246
|
|
|
247
|
+
if (!argv.keepFiles) {
|
|
248
|
+
await deleteAsync(
|
|
249
|
+
data.files.map(file => file.file),
|
|
250
|
+
{ force: true }
|
|
251
|
+
)
|
|
252
|
+
}
|
|
253
|
+
|
|
247
254
|
if (response.data.error) {
|
|
248
255
|
console.error(response.data.message)
|
|
249
256
|
process.exit(1)
|
|
@@ -256,16 +263,10 @@ export async function handler(argv) {
|
|
|
256
263
|
process.exit(1)
|
|
257
264
|
}
|
|
258
265
|
|
|
259
|
-
|
|
260
|
-
await deleteAsync(
|
|
261
|
-
data.files.map(file => file.file),
|
|
262
|
-
{ force: true }
|
|
263
|
-
)
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
console.log('\n')
|
|
266
|
+
console.log('')
|
|
267
267
|
console.log('ā
Thank you for initiating the data import process!')
|
|
268
268
|
console.log('š« You will receive an email notification once the import is completed.')
|
|
269
|
+
console.log('')
|
|
269
270
|
|
|
270
271
|
process.exit()
|
|
271
272
|
}
|
package/cmds/importMedia.js
CHANGED
|
@@ -8,7 +8,7 @@ export const desc = 'Import media to Closer'
|
|
|
8
8
|
|
|
9
9
|
export function builder(yargs) {
|
|
10
10
|
yargs
|
|
11
|
-
.usage(`Usage: ${chalk.cyan('$0 import
|
|
11
|
+
.usage(`Usage: ${chalk.cyan('$0 import:media')} [options]`)
|
|
12
12
|
.option('flush', {
|
|
13
13
|
describe: 'Truncate tables (ProductAssets, Assets) and delete files from disk',
|
|
14
14
|
type: 'bool'
|
|
@@ -54,8 +54,10 @@ export async function handler(argv) {
|
|
|
54
54
|
process.exit(1)
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
console.log('')
|
|
57
58
|
console.log('ā
Thank you for initiating the media import process!')
|
|
58
59
|
console.log('š« You will receive an email notification once the import is completed.')
|
|
60
|
+
console.log('')
|
|
59
61
|
|
|
60
62
|
process.exit()
|
|
61
63
|
}
|
package/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import yargs from 'yargs'
|
|
|
6
6
|
|
|
7
7
|
import * as ImportData from './cmds/importData.js'
|
|
8
8
|
import * as ImportMedia from './cmds/importMedia.js'
|
|
9
|
+
import * as ExportData from './cmds/exportData.js'
|
|
9
10
|
|
|
10
11
|
console.log(chalk.bold(`\nš Closer CLI (${pkg.version})\n`))
|
|
11
12
|
|
|
@@ -24,5 +25,6 @@ yargs(process.argv.slice(2))
|
|
|
24
25
|
})
|
|
25
26
|
.command(ImportData.command, ImportData.desc, ImportData.builder, ImportData.handler)
|
|
26
27
|
.command(ImportMedia.command, ImportMedia.desc, ImportMedia.builder, ImportMedia.handler)
|
|
28
|
+
.command(ExportData.command, ExportData.desc, ExportData.builder, ExportData.handler)
|
|
27
29
|
.help()
|
|
28
30
|
.version().argv
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "closer-cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.49.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"exports": "./index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"ws": "^8.0.0",
|
|
25
25
|
"yargs": "^17.0.1"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "7ebcc493afa8a574eb67808612cdc3e87dbcf91c"
|
|
28
28
|
}
|