-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
66 lines (56 loc) · 1.68 KB
/
Copy pathbuild.js
File metadata and controls
66 lines (56 loc) · 1.68 KB
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
59
60
61
62
63
64
65
66
#!/usr/bin/env node
// internal libs
const WPXMLReader = require("./wp-xml-reader")
const WPXMLBuilder = require("./wp-xml-builder")
const ARGV = require("./argv")()
// external libs
const chalk = require("chalk")
const path = require("path")
// 1. Reader
let configuration = null
if (ARGV.postType) {
try {
configuration = require(`./post-types/${ARGV.postType}`)
} catch (err) {
console.log(
chalk.red(
`Post Type "${
ARGV.postType
}" configuration file doesn't exists in post-type directory`
),
"\n"
)
}
}
if (!configuration) {
console.log(chalk.red(`Argument post-type is missing in cli command`), "\n")
process.exit(0)
}
let reader = new WPXMLReader(configuration.input_path)
// 2. Queries
reader.query(configuration.builder_query_options).then(response => {
console.log(chalk.grey(`*********`))
console.log(chalk.grey("Query Options:"))
console.log(chalk.grey(`*********`), "\n")
console.log(
chalk.grey(JSON.stringify(configuration.builder_query_options, null, 2)),
"\n"
)
console.log(chalk.green(`*********`))
console.log(chalk.green(`Response: (${response.length} items)`))
console.log(chalk.green(`*********`), "\n")
// 3 Builder
let builder = new WPXMLBuilder()
// set contents to builder
builder.set_contents(reader.mutable_contents)
// before build hook
if (typeof configuration.before_build === "function") {
builder = configuration.before_build(builder)
}
// build result orignal contents in a xml file following default import structure
builder
.build({ output_filename: configuration.output_filename })
.then(response => {
console.log("XML file saved")
})
})