-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(closes #178): add cli help and version
BREAKING CHANGE: updated node version range will cause installation fail for Node versions less 12.20.0
- Loading branch information
1 parent
29a6f77
commit 6ec6278
Showing
3 changed files
with
57 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,40 @@ | ||
#!/usr/bin/env node | ||
|
||
const { mergeFiles } = require("./src/mergeFiles.js"); | ||
const { Command } = require('commander') | ||
const pkg = require('./package.json') | ||
const { mergeFiles } = require('./src/mergeFiles.js') | ||
|
||
const [, , destFilePath, ...srcFilePathsOrGlobPatterns] = process.argv; | ||
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 | ||
} | ||
|
||
(async () => { | ||
try { | ||
let processedFileCount = 0; | ||
await mergeFiles(destFilePath, srcFilePathsOrGlobPatterns, { | ||
onFileMatched: () => { | ||
++processedFileCount; | ||
}, | ||
}); | ||
console.log(`Done. ${processedFileCount} files processed.`); | ||
if (processedFileCount === 0) { | ||
console.log( | ||
"Provided input file patterns did not matched any file." | ||
); | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
process.exitCode = 1; | ||
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 | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters