closer-cli 0.0.4 → 0.4.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/cmds/importData.js +42 -0
- package/cmds/importData_cmds/multiple.js +277 -0
- package/cmds/importData_cmds/single.js +213 -0
- package/cmds/importMedia.js +63 -0
- package/csv/customers.csv +6 -0
- package/csv/fieldConfigurations.csv +33 -0
- package/csv/groups.csv +3 -0
- package/csv/labels.csv +49 -0
- package/csv/lookups.csv +11 -0
- package/csv/prices.csv +319 -0
- package/csv/products.csv +319 -0
- package/csv/simple_customers.csv +6 -0
- package/csv/simple_userCustomer.csv +36 -0
- package/csv/simple_users.csv +8 -0
- package/csv/users.csv +8 -0
- package/helpers.js +706 -0
- package/index.js +10 -132
- package/package.json +7 -2
package/index.js
CHANGED
|
@@ -1,148 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/* eslint-disable no-unused-expressions */
|
|
2
4
|
/* eslint-disable no-console */
|
|
3
5
|
|
|
4
6
|
const chalk = require('chalk')
|
|
5
|
-
const Ora = require('ora')
|
|
6
|
-
const yargs = require('yargs')
|
|
7
|
-
const WebSocket = require('ws')
|
|
8
|
-
const CFonts = require('cfonts')
|
|
9
7
|
const packageJson = require('./package.json')
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
space: true,
|
|
13
|
-
gradient: ['red', '#f80']
|
|
14
|
-
})
|
|
9
|
+
console.log(chalk.bold(`\n 👜 Closer CLI (${packageJson.version})\n`))
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
.
|
|
18
|
-
.
|
|
19
|
-
|
|
20
|
-
.positional('docId', {
|
|
21
|
-
describe: 'google document id',
|
|
22
|
-
type: 'string'
|
|
23
|
-
})
|
|
24
|
-
.positional('sheet', {
|
|
25
|
-
describe: 'optional sheet name',
|
|
26
|
-
choices: [
|
|
27
|
-
'product',
|
|
28
|
-
'price',
|
|
29
|
-
'group',
|
|
30
|
-
'user',
|
|
31
|
-
'account',
|
|
32
|
-
'user_account',
|
|
33
|
-
'lookup',
|
|
34
|
-
'label',
|
|
35
|
-
'field_configuration'
|
|
36
|
-
]
|
|
37
|
-
})
|
|
38
|
-
.option('a', {
|
|
39
|
-
alias: 'assetType',
|
|
40
|
-
describe: 'Import products or media or both',
|
|
41
|
-
demandOption: true,
|
|
42
|
-
default: 'all',
|
|
43
|
-
choices: ['all', 'products', 'media']
|
|
44
|
-
})
|
|
45
|
-
.option('m', {
|
|
46
|
-
alias: 'mode',
|
|
47
|
-
describe: 'Import mode using "Group" (Normal) or "UserAccount" (Simplified)',
|
|
48
|
-
demandOption: true,
|
|
49
|
-
default: 'normal',
|
|
50
|
-
choices: ['normal', 'simplified']
|
|
51
|
-
})
|
|
52
|
-
})
|
|
11
|
+
require('yargs/yargs')(process.argv.slice(2))
|
|
12
|
+
.scriptName('closer')
|
|
13
|
+
.usage(`Usage: ${chalk.cyan('$0')} <command> [options]`)
|
|
14
|
+
.commandDir('cmds')
|
|
53
15
|
.option('e', {
|
|
54
16
|
alias: 'endpoint',
|
|
55
|
-
describe: 'Closer
|
|
17
|
+
describe: 'Closer URL',
|
|
56
18
|
demandOption: true
|
|
57
19
|
})
|
|
58
20
|
.option('s', {
|
|
59
21
|
alias: 'admin-secret',
|
|
60
|
-
describe: 'Admin Secret for Closer
|
|
22
|
+
describe: 'Admin Secret for Closer',
|
|
61
23
|
demandOption: true
|
|
62
24
|
})
|
|
63
25
|
.help()
|
|
64
|
-
.
|
|
65
|
-
.version()
|
|
66
|
-
|
|
67
|
-
// eslint-disable-next-line semi-style
|
|
68
|
-
;(async () => {
|
|
69
|
-
const spinner = new Ora()
|
|
70
|
-
|
|
71
|
-
const errorHandler = e => {
|
|
72
|
-
spinner.fail(e.message)
|
|
73
|
-
// console.log(chalk.red('Import failed'))
|
|
74
|
-
process.exit(1)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
spinner.start('Check code')
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
const hrstart = process.hrtime()
|
|
81
|
-
const protocol = argv.endpoint.includes('localhost') ? 'ws' : 'wss'
|
|
82
|
-
const ws = new WebSocket(`${protocol}://${argv.endpoint}/import`, {
|
|
83
|
-
headers: { 'x-closer-admin-secret': argv['admin-secret'] }
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
ws.on('open', () => {
|
|
87
|
-
ws.send(
|
|
88
|
-
JSON.stringify({
|
|
89
|
-
docId: argv.docId,
|
|
90
|
-
sheet: argv.sheet,
|
|
91
|
-
assetType: argv.assetType,
|
|
92
|
-
mode: argv.mode,
|
|
93
|
-
type: 'import'
|
|
94
|
-
})
|
|
95
|
-
)
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
ws.on('message', data => {
|
|
99
|
-
const parsed = JSON.parse(data)
|
|
100
|
-
|
|
101
|
-
switch (parsed.type) {
|
|
102
|
-
case 'download':
|
|
103
|
-
spinner.succeed()
|
|
104
|
-
spinner.start(`Download CSV ${chalk.gray(parsed.payload)}`)
|
|
105
|
-
break
|
|
106
|
-
case 'mediaStart':
|
|
107
|
-
spinner.succeed()
|
|
108
|
-
spinner.start(`Import ${chalk.cyan('Media')}`)
|
|
109
|
-
break
|
|
110
|
-
case 'mediaUpdate':
|
|
111
|
-
spinner.text = `Import ${chalk.cyan('Media')} [${parsed.payload.count}/${
|
|
112
|
-
parsed.payload.totalCount
|
|
113
|
-
}]`
|
|
114
|
-
break
|
|
115
|
-
case 'entityImportStart':
|
|
116
|
-
spinner.succeed()
|
|
117
|
-
spinner.start(`Import ${chalk.cyan(parsed.payload)}`)
|
|
118
|
-
break
|
|
119
|
-
case 'create':
|
|
120
|
-
case 'upsert':
|
|
121
|
-
spinner.text = `Import ${chalk.cyan(parsed.payload.entity)} [${parsed.payload.count}/${
|
|
122
|
-
parsed.payload.totalCount
|
|
123
|
-
}]`
|
|
124
|
-
break
|
|
125
|
-
case 'done':
|
|
126
|
-
{
|
|
127
|
-
if (parsed.error) {
|
|
128
|
-
spinner.fail()
|
|
129
|
-
console.log(`${chalk.red('Import Failed!')}`)
|
|
130
|
-
console.log(parsed.error)
|
|
131
|
-
process.exit(0)
|
|
132
|
-
}
|
|
133
|
-
const hrend = process.hrtime(hrstart)
|
|
134
|
-
const executionTime = ((hrend[0] * 1e9 + hrend[1]) / 1e9).toFixed(1)
|
|
135
|
-
spinner.succeed()
|
|
136
|
-
console.log(`${chalk.green('Done!')} ${chalk.gray(`[${executionTime}s]`)}`)
|
|
137
|
-
process.exit(0)
|
|
138
|
-
}
|
|
139
|
-
break
|
|
140
|
-
default:
|
|
141
|
-
}
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
ws.on('error', errorHandler)
|
|
145
|
-
} catch (e) {
|
|
146
|
-
errorHandler(e)
|
|
147
|
-
}
|
|
148
|
-
})()
|
|
26
|
+
.version().argv
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "closer-cli",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -11,9 +11,14 @@
|
|
|
11
11
|
"author": "Francesco Pasqua <cesconix@me.com>",
|
|
12
12
|
"license": "ISC",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"cfonts": "^2.9.3",
|
|
15
14
|
"chalk": "^4.1.2",
|
|
15
|
+
"csv-parse": "^4.16.3",
|
|
16
|
+
"csv-stringify": "^5.6.5",
|
|
17
|
+
"event-stream": "^4.0.1",
|
|
18
|
+
"got": "^11.8.2",
|
|
16
19
|
"ora": "^5.4.1",
|
|
20
|
+
"prompts": "^2.4.2",
|
|
21
|
+
"require-directory": "^2.1.1",
|
|
17
22
|
"ws": "^8.0.0",
|
|
18
23
|
"yargs": "^17.0.1"
|
|
19
24
|
}
|