diff --git a/README.md b/README.md index a719269..0164291 100644 --- a/README.md +++ b/README.md @@ -41,29 +41,37 @@ This might be useful if you need a single report, but your chosen reporter gener To merge CTRF reports in a specified directory, use the following command: ```sh -npx ctrf-cli merge +npx ctrf-cli@0.0.3 merge ``` -Replace `directory` with the path to the directory containing the CTRF reports you want to merge. +Replace `directory` with the path to the directory containing the CTRF reports you want to merge. Your merged report will be saved as `ctrf-report.json` in the same directory by default. ### Options --o, --output `filename`: Output file name for the merged report. Default is ctrf-report.json. +-o, --output `path`: Output file path for the merged report. Can be a filename (saved in input directory), relative path from current working directory, or absolute path. Default is `ctrf-report.json`. ```sh -npx ctrf-cli merge --output my-merged-report.json -``` +# Save with custom filename in input directory +npx ctrf-cli@0.0.3 merge ./reports --output my-merged-report.json +# Merged report saved to: ./reports/my-merged-report.json --d, --output-dir `directory`: Output directory for the merged report. Default is the same directory as the input reports. +# Save with relative path from current directory +npx ctrf-cli@0.0.3 merge ./reports --output ./output/merged.json +# Merged report saved to: ./output/merged.json -```sh -npx ctrf-cli merge --output-dir /path/to/output +# Save to directory with default filename +npx ctrf-cli@0.0.3 merge ./reports --output ./output/ +# Merged report saved to: ./output/ctrf-report.json + +# Save to absolute path +npx ctrf-cli@0.0.3 merge ./reports --output /tmp/merged.json +# Merged report saved to: /tmp/merged.json ``` -k, --keep-reports: Keep existing reports after merging. By default, the original reports will be deleted after merging. ```sh -npx ctrf-cli merge --keep-reports +npx ctrf-cli@0.0.3 merge --keep-reports ``` ## Flaky @@ -74,7 +82,7 @@ Usage To output flaky tests, use the following command: ```sh -npx ctrf-cli flaky +npx ctrf-cli@0.0.3 flaky ``` Replace with the path to the CTRF report file you want to analyze. diff --git a/package-lock.json b/package-lock.json index 9468de3..60dbbe0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ctrf-cli", - "version": "0.0.2", + "version": "0.0.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "ctrf-cli", - "version": "0.0.2", + "version": "0.0.3", "license": "MIT", "dependencies": { "glob": "^11.0.1", @@ -121,9 +121,9 @@ } }, "node_modules/@types/yargs": { - "version": "17.0.32", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.32.tgz", - "integrity": "sha512-xQ67Yc/laOG5uMfX/093MRlGGCIBzZMarVa+gfNKJxWAIgykYpVGkBdbqEzGDDfCrVUj6Hiff4mTZ5BA6TmAog==", + "version": "17.0.34", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.34.tgz", + "integrity": "sha512-KExbHVa92aJpw9WDQvzBaGVE2/Pz+pLZQloT2hjL8IqsZnV62rlPOYvNnLmf/L2dyllfVUOVBj64M0z/46eR2A==", "dev": true, "dependencies": { "@types/yargs-parser": "*" @@ -223,9 +223,9 @@ "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" }, "node_modules/escalade": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.2.tgz", - "integrity": "sha512-ErCHMCae19vR8vQGe50xIsVomy19rg6gFu3+r3jkEO46suLMWBksvVyoGgQV+jOfl84ZSOSlmv6Gxa89PmTGmA==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz", + "integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==", "engines": { "node": ">=6" } @@ -617,9 +617,9 @@ } }, "@types/yargs": { - "version": "17.0.32", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.32.tgz", - "integrity": "sha512-xQ67Yc/laOG5uMfX/093MRlGGCIBzZMarVa+gfNKJxWAIgykYpVGkBdbqEzGDDfCrVUj6Hiff4mTZ5BA6TmAog==", + "version": "17.0.34", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.34.tgz", + "integrity": "sha512-KExbHVa92aJpw9WDQvzBaGVE2/Pz+pLZQloT2hjL8IqsZnV62rlPOYvNnLmf/L2dyllfVUOVBj64M0z/46eR2A==", "dev": true, "requires": { "@types/yargs-parser": "*" @@ -701,9 +701,9 @@ "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" }, "escalade": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.2.tgz", - "integrity": "sha512-ErCHMCae19vR8vQGe50xIsVomy19rg6gFu3+r3jkEO46suLMWBksvVyoGgQV+jOfl84ZSOSlmv6Gxa89PmTGmA==" + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz", + "integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==" }, "foreground-child": { "version": "3.3.0", diff --git a/package.json b/package.json index 50840cd..4b1e389 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ctrf-cli", - "version": "0.0.2", + "version": "0.0.3", "description": "Various CTRF utilities available from the command line", "main": "dist/index.js", "bin": { diff --git a/src/cli.ts b/src/cli.ts index 686de56..082f8e9 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -18,7 +18,7 @@ const argv = yargs(hideBin(process.argv)) }) .option('output', { alias: 'o', - describe: 'Output file name for merged report', + describe: 'Output file path (default: ctrf-report.json)', type: 'string', default: 'ctrf-report.json', }) @@ -26,6 +26,8 @@ const argv = yargs(hideBin(process.argv)) alias: 'd', describe: 'Output directory for merged report', type: 'string', + hidden: true, + deprecated: 'Use --output with a path instead', }) .option('keep-reports', { alias: 'k', @@ -35,7 +37,7 @@ const argv = yargs(hideBin(process.argv)) }); }, async (argv) => { - await mergeReports(argv.directory as string, argv.output as string, argv['output-dir'] as string, argv['keep-reports'] as boolean); + await mergeReports(argv.directory as string, argv.output as string, argv['keep-reports'] as boolean, argv['output-dir'] as string); } ) .command( diff --git a/src/merge.ts b/src/merge.ts index cad75d6..8492c60 100644 --- a/src/merge.ts +++ b/src/merge.ts @@ -1,12 +1,32 @@ import fs from 'fs'; import path from 'path'; -export async function mergeReports(directory: string, output: string, outputDir: string, keepReports: boolean) { +export async function mergeReports(directory: string, output: string, keepReports: boolean, outputDir?: string) { try { const directoryPath = path.resolve(directory); - const outputFileName = output; - const resolvedOutputDir = outputDir ? path.resolve(outputDir) : directoryPath; - const outputPath = path.join(resolvedOutputDir, outputFileName); + + let outputPath: string; + + if (outputDir) { + console.warn('Warning: --output-dir is deprecated. Use --output with a path instead.'); + const outputFileName = output; + const resolvedOutputDir = path.resolve(outputDir); + outputPath = path.join(resolvedOutputDir, outputFileName); + } else if (output.includes('/') || output.includes('\\')) { + const resolvedPath = path.resolve(output); + + const endsWithSeparator = output.endsWith('/') || output.endsWith('\\'); + const isExistingDirectory = fs.existsSync(resolvedPath) && fs.statSync(resolvedPath).isDirectory(); + const hasNoExtension = path.extname(output) === ''; + + if (endsWithSeparator || isExistingDirectory || hasNoExtension) { + outputPath = path.join(resolvedPath, 'ctrf-report.json'); + } else { + outputPath = resolvedPath; + } + } else { + outputPath = path.join(directoryPath, output); + } console.log("Merging CTRF reports..."); @@ -41,9 +61,10 @@ export async function mergeReports(directory: string, output: string, outputDir: return; } - if (!fs.existsSync(resolvedOutputDir)) { - fs.mkdirSync(resolvedOutputDir, { recursive: true }); - console.log(`Created output directory: ${resolvedOutputDir}`); + const outputDirPath = path.dirname(outputPath); + if (!fs.existsSync(outputDirPath)) { + fs.mkdirSync(outputDirPath, { recursive: true }); + console.log(`Created output directory: ${outputDirPath}`); } const mergedReport = ctrfReportFiles @@ -76,6 +97,7 @@ export async function mergeReports(directory: string, output: string, outputDir: fs.writeFileSync(outputPath, JSON.stringify(mergedReport, null, 2)); if (!keepReports) { + const outputFileName = path.basename(outputPath); ctrfReportFiles.forEach((file) => { const filePath = path.join(directoryPath, file); if (file !== outputFileName) {