forked from konsalex/gatsby-wordpress-migrate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·50 lines (46 loc) · 1.3 KB
/
cli.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
47
48
49
50
#!/usr/bin/env node
// FS-Extra in order to enable promises
const fs = require('fs');
const path = require('path');
const args = process.argv;
const parser = require('xml2js');
const inquirer = require('inquirer');
// Custom Styling for Command Line printing
const log = console.log;
const chalk = require('chalk');
const error = chalk.bold.red;
const success = chalk.bold.green.inverse;
const helperFunctions = require('./functions');
(async () => {
const args = process.argv;
let infos = null;
if (args.length < 4) {
infos = await inquirer.prompt([
{
type: 'input',
name: 'xml',
message: 'Wordpress XML file:',
},
{
type: 'input',
name: 'dest',
message: 'Destination for your new MarkDown folder:',
},
]);
}
const inputFilePath = infos ? infos.xml : args[2];
const outputDir = infos ? infos.dest : args[3];
// Read the XML file and call DataWrangle after we parse it
return fs.readFile(inputFilePath, (err, data) => {
if (err) {
return log(error(err));
}
return parser.parseString(data, (parseError, result) => {
if (parseError) {
return log(error(parseError));
}
log(success('Successfully loaded file.'));
return helperFunctions.dataWrangle(result, outputDir);
});
});
})();