Skip to content

Commit

Permalink
feat(closes #178): add cli help and version
Browse files Browse the repository at this point in the history
BREAKING CHANGE: updated node version range will cause installation fail for Node versions less 12.20.0
  • Loading branch information
bhovhannes committed Aug 4, 2022
1 parent 29a6f77 commit 6ec6278
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 28 deletions.
55 changes: 35 additions & 20 deletions cli.js
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
})
21 changes: 17 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
"typings": "tsc index.js --declaration --allowJs --emitDeclarationOnly --outDir typings"
},
"dependencies": {
"fast-glob": "3.2.11",
"xmlbuilder2": "3.0.2"
"commander": "~9.4.0",
"fast-glob": "~3.2.11",
"xmlbuilder2": "~3.0.2"
},
"repository": {
"type": "git",
Expand All @@ -45,14 +46,14 @@
},
"homepage": "https://github.com/bhovhannes/junit-report-merger#readme",
"devDependencies": {
"@evilmartians/lefthook": "1.0.5",
"@bhovhannes/shared-config": "0.0.1",
"@evilmartians/lefthook": "1.0.5",
"@jest/globals": "28.1.3",
"jest": "28.1.3",
"prettier": "2.7.1",
"typescript": "4.7.4"
},
"engines": {
"node": ">=12"
"node": "^12.20.0 || >=14"
}
}

0 comments on commit 6ec6278

Please sign in to comment.