All files / src/reporter cli.ts

0% Statements 0/17
0% Branches 0/5
0% Functions 0/7
0% Lines 0/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 67 68 69 70 71 72 73                                                                                                                                                 
#!/usr/bin/env node
 
import fs from "fs";
import { join } from "path";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { immediatePush } from "./coverage";
 
async function main() {
  await yargs(hideBin(process.argv))
    .option("coverageDirectory", {
      description:
        "Path to the folder of the coverage files. Should be $pwd/coverage where $pwd is the directory where autorest.testserver was run from.",
      default: join(process.cwd(), "coverage"),
      type: "string",
    })
    .version(false)
    .option("version", { description: "Version", type: "string" })
    .command(
      "publish",
      "Publish testserver coverage",
      (cmd) => {
        return cmd
          .option("repo", { type: "string", description: "Name of the Github Repo", demandOption: true })
          .option("ref", { type: "string", description: "Ref to the branch/pr.", demandOption: true })
          .option("githubToken", { type: "string", description: "Github token for authentication" })
          .option("azStorageAccount", {
            type: "string",
            description: "Azure storager account name",
            demandOption: true,
          })
          .option("azStorageAccessKey", {
            type: "string",
            description: "Authentication key for storage account",
            demandOption: true,
          });
      },
      (args) => {
        const pr = Number(args.ref.split("/")[2]);
        return immediatePush(
          args.repo,
          pr.toString(),
          args.githubToken ?? "",
          args.azStorageAccount,
          args.azStorageAccessKey,
          args.version,
          args.coverageDirectory,
        );
      },
    )
    .command(
      "clear",
      "Clear the code coverage directory",
      () => null,
      async (args) => {
        await fs.promises.rm(args.coverageDirectory, { recursive: true });
      },
    )
    .fail(function (msg, err) {
      Iif (err) {
        throw err;
      }
      // eslint-disable-next-line no-console
      console.log(msg);
      process.exit(1);
    }).argv;
}
 
main().catch((e) => {
  // eslint-disable-next-line no-console
  console.error(e);
});