closer-cli 2.9.0 → 2.16.6

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 CHANGED
@@ -3,6 +3,28 @@
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.16.4](https://code.hfarm.dev/closer/closer/compare/v2.16.3...v2.16.4) (2022-06-28)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * hide retail price row if not exists ([883784e](https://code.hfarm.dev/closer/closer/commits/883784e97c64df77631ca569a0622ac8407c0cc4))
12
+
13
+
14
+
15
+
16
+
17
+ # [2.11.0](https://code.hfarm.dev/closer/closer/compare/v2.10.0...v2.11.0) (2022-05-18)
18
+
19
+
20
+ ### Features
21
+
22
+ * **#PJX-445:** Multilingua ([f24f066](https://code.hfarm.dev/closer/closer/commits/f24f0668b7c0c8338c8d91db68afc871efb534ed)), closes [#PJX-445](https://code.hfarm.dev/closer/closer/issues/PJX-445)
23
+
24
+
25
+
26
+
27
+
6
28
  # [2.9.0](https://code.hfarm.dev/closer/closer/compare/v2.8.0...v2.9.0) (2022-05-09)
7
29
 
8
30
 
@@ -0,0 +1,84 @@
1
+ /* eslint-disable no-console */
2
+ /* eslint-disable no-await-in-loop */
3
+ /* eslint-disable no-restricted-syntax */
4
+
5
+ const chalk = require('chalk')
6
+ const Ora = require('ora')
7
+ const prompts = require('prompts')
8
+ const { ALLOWED_CSV_FILES, exportCsv } = require('../helpers')
9
+
10
+ exports.command = 'export:data'
11
+ exports.desc = 'Export data from Closer'
12
+
13
+ exports.builder = yargs => {
14
+ yargs.usage(`Usage: ${chalk.cyan('$0 export:data')} [options]`)
15
+ }
16
+
17
+ exports.handler = async argv => {
18
+ const interactive = !argv.nonInteractive
19
+
20
+ const csvChoices = Object.keys(ALLOWED_CSV_FILES).map(csvType => ({
21
+ title: csvType,
22
+ csvType,
23
+ value: csvType
24
+ }))
25
+
26
+ let csvTypes
27
+ if (interactive && !argv.type) {
28
+ const answers = await prompts(
29
+ [
30
+ {
31
+ instructions: false,
32
+ name: 'csvTypes',
33
+ type: 'multiselect',
34
+ message: 'Select CSV type',
35
+ choices: csvChoices,
36
+ min: 1
37
+ }
38
+ ],
39
+ { onCancel: () => process.exit() }
40
+ )
41
+
42
+ csvTypes = answers.csvTypes
43
+ } else {
44
+ csvTypes = argv.type.map(type => {
45
+ const choice = csvChoices.find(csvChoice => csvChoice.csvType === type)
46
+ return choice.value
47
+ })
48
+ }
49
+
50
+ const spinner = new Ora()
51
+ // const hrstart = process.hrtime()
52
+
53
+ const ws = {
54
+ endpoint: argv.endpoint,
55
+ adminSecret: argv['admin-secret']
56
+ }
57
+
58
+ if (interactive) {
59
+ console.log('')
60
+ const { confirmed } = await prompts(
61
+ [
62
+ {
63
+ type: 'confirm',
64
+ name: 'confirmed',
65
+ message: 'Continue?',
66
+ initial: false
67
+ }
68
+ ],
69
+ { onCancel: () => process.exit() }
70
+ )
71
+
72
+ if (!confirmed) {
73
+ process.exit()
74
+ }
75
+ }
76
+
77
+ console.log('')
78
+
79
+ for (const csvType of csvTypes) {
80
+ await exportCsv(csvType, argv.out, spinner, ws, argv.csvDelimiter)
81
+ }
82
+
83
+ process.exit()
84
+ }
package/helpers.js CHANGED
@@ -23,6 +23,9 @@ exports.createSocketConnection = (endpoint, adminSecret) => {
23
23
 
24
24
  exports.ALLOWED_CSV_FILES = {
25
25
  product: 'products.csv',
26
+ localizedProduct: 'localizedProducts.csv',
27
+ localizedFilter: 'localizedFilters.csv',
28
+ localizedVariant: 'localizedVariants.csv',
26
29
  price: 'prices.csv',
27
30
  group: 'groups.csv',
28
31
  lookup: 'lookups.csv',
@@ -722,7 +725,7 @@ exports.flushMedia = (spinner, ws) =>
722
725
 
723
726
  exports.getArchiveFolder = instanceEndpoint => {
724
727
  const prefix = 'closer'
725
- const instance = slugify(instanceEndpoint.split('/')[0], { lower: true })
728
+ const instance = slugify(instanceEndpoint.split('/')[0].split('.').join('-'), { lower: true })
726
729
  const ts = getTimestampForFilename()
727
730
  return `${prefix}_${instance}/${ts}`
728
731
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "closer-cli",
3
- "version": "2.9.0",
3
+ "version": "2.16.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -1,215 +0,0 @@
1
- /* eslint-disable no-await-in-loop */
2
- /* eslint-disable no-restricted-syntax */
3
- /* eslint-disable no-console */
4
- const fs = require('fs')
5
- const chalk = require('chalk')
6
- const path = require('path')
7
-
8
- const Ora = require('ora')
9
- const prompts = require('prompts')
10
- const {
11
- importCsvFromFile,
12
- getExecutionTime,
13
- callAfterDataImportProcess,
14
- ALLOWED_CSV_FILES,
15
- download,
16
- validateCsvFromFile,
17
- getArchiveFolder,
18
- getGoogleSheetCsvUrl
19
- } = require('../helpers')
20
-
21
- exports.command = 'import:stock'
22
-
23
- exports.desc = 'Import Stock Availability from CSV file'
24
-
25
- exports.builder = yargs => {
26
- yargs
27
- .usage(`Usage: ${chalk.cyan('$0 import:stock')} [options]`)
28
- .option('fromFile', {
29
- alias: 'f',
30
- describe: 'File to import',
31
- type: 'string'
32
- })
33
- .option('fromUrl', {
34
- alias: 'u',
35
- describe: 'Remote URL file to import',
36
- type: 'string'
37
- })
38
- .option('fromDir', {
39
- alias: 'd',
40
- describe: 'Directory path that contains file to import',
41
- type: 'string'
42
- })
43
- .option('fromGoogleDocId', {
44
- alias: 'g',
45
- describe: 'Google Doc ID that contains sheet to import',
46
- type: 'string'
47
- })
48
- // .conflicts('fromFile', 'fromUrl', 'fromDir', 'fromGoogleDocId')
49
- .check(argv => {
50
- if (!argv.fromFile && !argv.fromUrl && !argv.fromDir && !argv.fromGoogleDocId) {
51
- throw new Error(
52
- 'Missing required argument: fromFile OR fromUrl OR fromDir OR fromGoogleDocId'
53
- )
54
- }
55
-
56
- if (argv.fromFile) {
57
- fs.accessSync(argv.fromFile, fs.constants.F_OK)
58
- }
59
-
60
- if (argv.fromDir) {
61
- fs.accessSync(argv.fromDir, fs.constants.F_OK)
62
- }
63
-
64
- return true
65
- })
66
- }
67
-
68
- exports.handler = async argv => {
69
- // eslint-disable-next-line no-param-reassign
70
- argv.out = argv.out || getArchiveFolder(argv.endpoint)
71
-
72
- const spinner = new Ora()
73
- const hrstart = process.hrtime()
74
-
75
- const report = {
76
- start: new Date(),
77
- end: null,
78
- time: null,
79
- endpoint: argv.endpoint,
80
- mode: null,
81
- type: [],
82
- result: []
83
- }
84
-
85
- const ws = {
86
- endpoint: argv.endpoint,
87
- adminSecret: argv['admin-secret']
88
- }
89
-
90
- const interactive = !argv.nonInteractive
91
-
92
- const csvType = 'stockAvailability'
93
-
94
- let file
95
- if (argv.fromDir) {
96
- file = {
97
- file: path.resolve(argv.fromDir, ALLOWED_CSV_FILES.stockAvailability),
98
- csvType
99
- }
100
- } else if (argv.fromGoogleDocId) {
101
- file = {
102
- url: getGoogleSheetCsvUrl(argv.fromGoogleDocId, csvType),
103
- csvType
104
- }
105
- } else if (argv.fromFile) {
106
- file = {
107
- file: argv.fromFile,
108
- csvType
109
- }
110
- } else if (argv.fromUrl) {
111
- file = {
112
- url: argv.fromUrl,
113
- csvType
114
- }
115
- }
116
-
117
- let mode
118
- if (interactive && !argv.mode) {
119
- const answers = await prompts(
120
- [
121
- {
122
- type: 'select',
123
- name: 'mode',
124
- message: 'Import Mode',
125
- choices: [
126
- {
127
- title: 'Incremental',
128
- value: 'incremental'
129
- },
130
- {
131
- title: 'Full',
132
- description: 'Before starting, all database records will be logically deleted',
133
- value: 'full'
134
- }
135
- ],
136
- hint: ' '
137
- }
138
- ],
139
- { onCancel: () => process.exit() }
140
- )
141
-
142
- mode = answers.mode
143
- } else {
144
- mode = argv.mode
145
- }
146
-
147
- if (interactive) {
148
- console.log('')
149
- const { confirmed } = await prompts(
150
- [
151
- {
152
- type: 'confirm',
153
- name: 'confirmed',
154
- message: 'Continue?',
155
- initial: false
156
- }
157
- ],
158
- { onCancel: () => process.exit() }
159
- )
160
-
161
- if (!confirmed) {
162
- process.exit()
163
- }
164
-
165
- console.log('')
166
- }
167
-
168
- let filepath = argv.fromFile
169
-
170
- if (argv.fromDir) {
171
- filepath = file.file
172
- } else if (argv.fromUrl || argv.fromGoogleDocId) {
173
- spinner.start('Downloading file...')
174
- filepath = await download(file.url, argv.out, `${csvType}.csv`)
175
- spinner.succeed('Downloaded file')
176
- }
177
-
178
- const validation = await validateCsvFromFile(filepath, csvType, ws, argv.csvDelimiter)
179
-
180
- if (validation.error) {
181
- console.log(`ERROR => [${chalk.red(validation.inputFile)}] ${validation.error}`)
182
- process.exit()
183
- }
184
-
185
- const csvReport = await importCsvFromFile(
186
- filepath,
187
- csvType,
188
- argv.out,
189
- spinner,
190
- ws,
191
- argv.csvDelimiter
192
- )
193
-
194
- //
195
- // Report
196
- //
197
-
198
- report.end = new Date()
199
- report.time = getExecutionTime(hrstart)
200
- report.mode = mode
201
- report.type = [csvType]
202
-
203
- const reportRows = []
204
-
205
- reportRows.push({
206
- type: 'import.csv',
207
- payload: csvReport
208
- })
209
-
210
- report.result = reportRows
211
-
212
- await callAfterDataImportProcess(spinner, ws, report)
213
-
214
- process.exit()
215
- }