-
Notifications
You must be signed in to change notification settings - Fork 13
/
cli.js
executable file
·40 lines (36 loc) · 1.19 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
#!/usr/bin/env node
const { Command } = require('commander')
const pkg = require('./package.json')
const { mergeFiles } = require('./src/mergeFiles.js')
function getProgram() {
const program = new Command()
program.version(pkg.version)
program.description(
pkg.description +
'\n\n' +
'Example (combines a.xml and b.xml into target.xml):\n jrm target.xml a.xml b.xml' +
'\n\n' +
'Example (glob patterns to match input files):\n jrm ./results/combined.xml "./results/units/*.xml" "./results/e2e/*.xml"'
)
program.arguments('<destination> <sources...>')
return program
}
const program = getProgram()
program.action(async function (destination, sources) {
const destFilePath = destination
const srcFilePathsOrGlobPatterns = sources
let processedFileCount = 0
await mergeFiles(destFilePath, srcFilePathsOrGlobPatterns, {
onFileMatched: () => {
++processedFileCount
}
})
process.stdout.write(`Done. ${processedFileCount} files processed.\n`)
if (processedFileCount === 0) {
process.stdout.write(`Provided input file patterns did not matched any file.\n`)
}
})
program.parseAsync().catch((e) => {
console.error(e)
process.exitCode = 1
})