-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.mjs
58 lines (55 loc) · 1.54 KB
/
index.mjs
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
47
48
49
50
51
52
53
54
55
56
57
58
/**
* Main Module
*
* This is where the CLI tool is configured that calls all of the
* subordinate functions.
*
* @module
*/
import { generate, generateCsv } from './src/generators.mjs'
import {
howManyRowsShouldBeInSource,
howManyRowsShouldTargetBeRelativeToSource,
shouldColumnOrderBeAltered,
shouldOptionalColumnsBeIncluded,
whichColumnsShouldHaveDatesAltered,
whichColumnsShouldHaveDifferentNames,
whichColumnsShouldHaveFloatsAltered,
whichColumnsShouldHaveLatLonAltered
} from './src/questions.mjs'
import colspec from './colspec.mjs'
import fs from 'fs'
import inquirer from 'inquirer'
/**
* This function starts the CLI tool's Q&A process and then
* processes and writes the results to the `output/` directory.
*/
inquirer
.prompt([
shouldOptionalColumnsBeIncluded,
howManyRowsShouldBeInSource,
howManyRowsShouldTargetBeRelativeToSource,
shouldColumnOrderBeAltered,
whichColumnsShouldHaveDifferentNames,
whichColumnsShouldHaveFloatsAltered,
whichColumnsShouldHaveDatesAltered,
whichColumnsShouldHaveLatLonAltered,
])
.then((answers) => {
const output = generate(answers, colspec)
const csvs = generateCsv(output)
try {
fs.writeFileSync(csvs.source.path, csvs.source.content)
fs.writeFileSync(csvs.target.path, csvs.target.content)
} catch (e) {
console.log(e)
}
})
.catch(error => {
if (error.isTtyError) {
// prompt could not be rendered in current environment
} else {
// something else went wrong
}
console.log(error)
})