-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (35 loc) · 1.35 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const inquirer = require('./lib/inquirer')
const formatters = require('./lib/formats/index')
const files = require('./lib/files')
const logger = require('./lib/logger')
const run = async () => {
const args = process.argv
.slice(2)
.map(arg => arg.split('='))
.reduce((args, [value, key]) => {
args[value] = key;
return args;
}, {});
logger.openingMessage()
const action = args.type || (await inquirer.requestAction()).action // export
const inputPath = args.input || (await inquirer.requestInputPath()).inputPath // js files
const outputPath = args.output || await inquirer.requestOutputPath().outputPath // csv
if (!files.directoryExists(inputPath)) {
logger.errorMessage('Error: input path inserted does not exist.')
return
}
if (!files.directoryExists(outputPath)) {
logger.errorMessage('Error: output path inserted does not exist.')
return
}
if (action === 'export') {
const output = formatters.jsFormatter.fromJs(inputPath)
const langs = formatters.jsFormatter.getLangs(inputPath)
formatters.csvFormatter.toCsv(output, outputPath, langs)
}
if (action === 'import') {
const output = formatters.csvFormatter.fromCsv(inputPath)
formatters.jsFormatter.toJs(output, outputPath)
}
}
run();