@lcov-viewer/cli
Version:
LCOV viewer CLI to convert coverage to grouped HTML report. Generates code coverage report grouped by directory.
3 lines (2 loc) • 34.6 kB
JavaScript
#! /usr/bin/env node
"use strict";var t=require("events"),e=require("child_process"),i=require("path"),n=require("fs"),s=require("process");function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var o=r(t),a=r(e),h=r(i),l=r(n),c=r(s),u={exports:{}},p={},m={};class d extends Error{constructor(t,e,i){super(i),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=e,this.exitCode=t,this.nestedError=void 0}}m.CommanderError=d,m.InvalidArgumentError=class extends d{constructor(t){super(1,"commander.invalidArgument",t),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};const{InvalidArgumentError:g}=m;p.Argument=class{constructor(t,e){switch(this.description=e||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,t[0]){case"<":this.required=!0,this._name=t.slice(1,-1);break;case"[":this.required=!1,this._name=t.slice(1,-1);break;default:this.required=!0,this._name=t}this._name.length>3&&"..."===this._name.slice(-3)&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_concatValue(t,e){return e!==this.defaultValue&&Array.isArray(e)?e.concat(t):[t]}default(t,e){return this.defaultValue=t,this.defaultValueDescription=e,this}argParser(t){return this.parseArg=t,this}choices(t){return this.argChoices=t.slice(),this.parseArg=(t,e)=>{if(!this.argChoices.includes(t))throw new g(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(t,e):t},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}},p.humanReadableArgName=function(t){const e=t.name()+(!0===t.variadic?"...":"");return t.required?"<"+e+">":"["+e+"]"};var f={},_={};const{humanReadableArgName:v}=p;_.Help=class{constructor(){this.helpWidth=void 0,this.sortSubcommands=!1,this.sortOptions=!1}visibleCommands(t){const e=t.commands.filter((t=>!t._hidden));if(t._hasImplicitHelpCommand()){const[,i,n]=t._helpCommandnameAndArgs.match(/([^ ]+) *(.*)/),s=t.createCommand(i).helpOption(!1);s.description(t._helpCommandDescription),n&&s.arguments(n),e.push(s)}return this.sortSubcommands&&e.sort(((t,e)=>t.name().localeCompare(e.name()))),e}visibleOptions(t){const e=t.options.filter((t=>!t.hidden)),i=t._hasHelpOption&&t._helpShortFlag&&!t._findOption(t._helpShortFlag),n=t._hasHelpOption&&!t._findOption(t._helpLongFlag);if(i||n){let s;s=i?n?t.createOption(t._helpFlags,t._helpDescription):t.createOption(t._helpShortFlag,t._helpDescription):t.createOption(t._helpLongFlag,t._helpDescription),e.push(s)}if(this.sortOptions){const t=t=>t.short?t.short.replace(/^-/,""):t.long.replace(/^--/,"");e.sort(((e,i)=>t(e).localeCompare(t(i))))}return e}visibleArguments(t){return t._argsDescription&&t._args.forEach((e=>{e.description=e.description||t._argsDescription[e.name()]||""})),t._args.find((t=>t.description))?t._args:[]}subcommandTerm(t){const e=t._args.map((t=>v(t))).join(" ");return t._name+(t._aliases[0]?"|"+t._aliases[0]:"")+(t.options.length?" [options]":"")+(e?" "+e:"")}optionTerm(t){return t.flags}argumentTerm(t){return t.name()}longestSubcommandTermLength(t,e){return e.visibleCommands(t).reduce(((t,i)=>Math.max(t,e.subcommandTerm(i).length)),0)}longestOptionTermLength(t,e){return e.visibleOptions(t).reduce(((t,i)=>Math.max(t,e.optionTerm(i).length)),0)}longestArgumentTermLength(t,e){return e.visibleArguments(t).reduce(((t,i)=>Math.max(t,e.argumentTerm(i).length)),0)}commandUsage(t){let e=t._name;t._aliases[0]&&(e=e+"|"+t._aliases[0]);let i="";for(let e=t.parent;e;e=e.parent)i=e.name()+" "+i;return i+e+" "+t.usage()}commandDescription(t){return t.description()}subcommandDescription(t){return t.summary()||t.description()}optionDescription(t){const e=[];if(t.argChoices&&e.push(`choices: ${t.argChoices.map((t=>JSON.stringify(t))).join(", ")}`),void 0!==t.defaultValue){(t.required||t.optional||t.isBoolean()&&"boolean"==typeof t.defaultValue)&&e.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`)}return void 0!==t.presetArg&&t.optional&&e.push(`preset: ${JSON.stringify(t.presetArg)}`),void 0!==t.envVar&&e.push(`env: ${t.envVar}`),e.length>0?`${t.description} (${e.join(", ")})`:t.description}argumentDescription(t){const e=[];if(t.argChoices&&e.push(`choices: ${t.argChoices.map((t=>JSON.stringify(t))).join(", ")}`),void 0!==t.defaultValue&&e.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`),e.length>0){const i=`(${e.join(", ")})`;return t.description?`${t.description} ${i}`:i}return t.description}formatHelp(t,e){const i=e.padWidth(t,e),n=e.helpWidth||80;function s(t,s){if(s){const r=`${t.padEnd(i+2)}${s}`;return e.wrap(r,n-2,i+2)}return t}function r(t){return t.join("\n").replace(/^/gm," ".repeat(2))}let o=[`Usage: ${e.commandUsage(t)}`,""];const a=e.commandDescription(t);a.length>0&&(o=o.concat([a,""]));const h=e.visibleArguments(t).map((t=>s(e.argumentTerm(t),e.argumentDescription(t))));h.length>0&&(o=o.concat(["Arguments:",r(h),""]));const l=e.visibleOptions(t).map((t=>s(e.optionTerm(t),e.optionDescription(t))));l.length>0&&(o=o.concat(["Options:",r(l),""]));const c=e.visibleCommands(t).map((t=>s(e.subcommandTerm(t),e.subcommandDescription(t))));return c.length>0&&(o=o.concat(["Commands:",r(c),""])),o.join("\n")}padWidth(t,e){return Math.max(e.longestOptionTermLength(t,e),e.longestSubcommandTermLength(t,e),e.longestArgumentTermLength(t,e))}wrap(t,e,i,n=40){if(t.match(/[\n]\s+/))return t;const s=e-i;if(s<n)return t;const r=t.slice(0,i),o=t.slice(i),a=" ".repeat(i),h=new RegExp(".{1,"+(s-1)+"}([\\s]|$)|[^\\s]+?([\\s]|$)","g");return r+(o.match(h)||[]).map(((t,e)=>("\n"===t.slice(-1)&&(t=t.slice(0,t.length-1)),(e>0?a:"")+t.trimRight()))).join("\n")}};var O={};const{InvalidArgumentError:b}=m;function C(t){let e,i;const n=t.split(/[ |,]+/);return n.length>1&&!/^[[<]/.test(n[1])&&(e=n.shift()),i=n.shift(),!e&&/^-[^-]$/.test(i)&&(e=i,i=void 0),{shortFlag:e,longFlag:i}}O.Option=class{constructor(t,e){this.flags=t,this.description=e||"",this.required=t.includes("<"),this.optional=t.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(t),this.mandatory=!1;const i=C(t);this.short=i.shortFlag,this.long=i.longFlag,this.negate=!1,this.long&&(this.negate=this.long.startsWith("--no-")),this.defaultValue=void 0,this.defaultValueDescription=void 0,this.presetArg=void 0,this.envVar=void 0,this.parseArg=void 0,this.hidden=!1,this.argChoices=void 0,this.conflictsWith=[],this.implied=void 0}default(t,e){return this.defaultValue=t,this.defaultValueDescription=e,this}preset(t){return this.presetArg=t,this}conflicts(t){return this.conflictsWith=this.conflictsWith.concat(t),this}implies(t){return this.implied=Object.assign(this.implied||{},t),this}env(t){return this.envVar=t,this}argParser(t){return this.parseArg=t,this}makeOptionMandatory(t=!0){return this.mandatory=!!t,this}hideHelp(t=!0){return this.hidden=!!t,this}_concatValue(t,e){return e!==this.defaultValue&&Array.isArray(e)?e.concat(t):[t]}choices(t){return this.argChoices=t.slice(),this.parseArg=(t,e)=>{if(!this.argChoices.includes(t))throw new b(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(t,e):t},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return this.name().replace(/^no-/,"").split("-").reduce(((t,e)=>t+e[0].toUpperCase()+e.slice(1)))}is(t){return this.short===t||this.long===t}isBoolean(){return!this.required&&!this.optional&&!this.negate}},O.splitOptionFlags=C,O.DualOptions=class{constructor(t){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,t.forEach((t=>{t.negate?this.negativeOptions.set(t.attributeName(),t):this.positiveOptions.set(t.attributeName(),t)})),this.negativeOptions.forEach(((t,e)=>{this.positiveOptions.has(e)&&this.dualOptions.add(e)}))}valueFromOption(t,e){const i=e.attributeName();if(!this.dualOptions.has(i))return!0;const n=this.negativeOptions.get(i).presetArg,s=void 0!==n&&n;return e.negate===(s===t)}};var A={};A.suggestSimilar=function(t,e){if(!e||0===e.length)return"";e=Array.from(new Set(e));const i=t.startsWith("--");i&&(t=t.slice(2),e=e.map((t=>t.slice(2))));let n=[],s=3;return e.forEach((e=>{if(e.length<=1)return;const i=function(t,e){if(Math.abs(t.length-e.length)>3)return Math.max(t.length,e.length);const i=[];for(let e=0;e<=t.length;e++)i[e]=[e];for(let t=0;t<=e.length;t++)i[0][t]=t;for(let n=1;n<=e.length;n++)for(let s=1;s<=t.length;s++){let r=1;r=t[s-1]===e[n-1]?0:1,i[s][n]=Math.min(i[s-1][n]+1,i[s][n-1]+1,i[s-1][n-1]+r),s>1&&n>1&&t[s-1]===e[n-2]&&t[s-2]===e[n-1]&&(i[s][n]=Math.min(i[s][n],i[s-2][n-2]+1))}return i[t.length][e.length]}(t,e),r=Math.max(t.length,e.length);(r-i)/r>.4&&(i<s?(s=i,n=[e]):i===s&&n.push(e))})),n.sort(((t,e)=>t.localeCompare(e))),i&&(n=n.map((t=>`--${t}`))),n.length>1?`\n(Did you mean one of ${n.join(", ")}?)`:1===n.length?`\n(Did you mean ${n[0]}?)`:""};const w=o.default.EventEmitter,E=a.default,x=h.default,$=l.default,H=c.default,{Argument:k,humanReadableArgName:y}=p,{CommanderError:V}=m,{Help:F}=_,{Option:S,splitOptionFlags:N,DualOptions:D}=O,{suggestSimilar:P}=A;class T extends w{constructor(t){super(),this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!0,this._args=[],this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=t||"",this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description="",this._summary="",this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._outputConfiguration={writeOut:t=>H.stdout.write(t),writeErr:t=>H.stderr.write(t),getOutHelpWidth:()=>H.stdout.isTTY?H.stdout.columns:void 0,getErrHelpWidth:()=>H.stderr.isTTY?H.stderr.columns:void 0,outputError:(t,e)=>e(t)},this._hidden=!1,this._hasHelpOption=!0,this._helpFlags="-h, --help",this._helpDescription="display help for command",this._helpShortFlag="-h",this._helpLongFlag="--help",this._addImplicitHelpCommand=void 0,this._helpCommandName="help",this._helpCommandnameAndArgs="help [command]",this._helpCommandDescription="display help for command",this._helpConfiguration={}}copyInheritedSettings(t){return this._outputConfiguration=t._outputConfiguration,this._hasHelpOption=t._hasHelpOption,this._helpFlags=t._helpFlags,this._helpDescription=t._helpDescription,this._helpShortFlag=t._helpShortFlag,this._helpLongFlag=t._helpLongFlag,this._helpCommandName=t._helpCommandName,this._helpCommandnameAndArgs=t._helpCommandnameAndArgs,this._helpCommandDescription=t._helpCommandDescription,this._helpConfiguration=t._helpConfiguration,this._exitCallback=t._exitCallback,this._storeOptionsAsProperties=t._storeOptionsAsProperties,this._combineFlagAndOptionalValue=t._combineFlagAndOptionalValue,this._allowExcessArguments=t._allowExcessArguments,this._enablePositionalOptions=t._enablePositionalOptions,this._showHelpAfterError=t._showHelpAfterError,this._showSuggestionAfterError=t._showSuggestionAfterError,this}command(t,e,i){let n=e,s=i;"object"==typeof n&&null!==n&&(s=n,n=null),s=s||{};const[,r,o]=t.match(/([^ ]+) *(.*)/),a=this.createCommand(r);return n&&(a.description(n),a._executableHandler=!0),s.isDefault&&(this._defaultCommandName=a._name),a._hidden=!(!s.noHelp&&!s.hidden),a._executableFile=s.executableFile||null,o&&a.arguments(o),this.commands.push(a),a.parent=this,a.copyInheritedSettings(this),n?this:a}createCommand(t){return new T(t)}createHelp(){return Object.assign(new F,this.configureHelp())}configureHelp(t){return void 0===t?this._helpConfiguration:(this._helpConfiguration=t,this)}configureOutput(t){return void 0===t?this._outputConfiguration:(Object.assign(this._outputConfiguration,t),this)}showHelpAfterError(t=!0){return"string"!=typeof t&&(t=!!t),this._showHelpAfterError=t,this}showSuggestionAfterError(t=!0){return this._showSuggestionAfterError=!!t,this}addCommand(t,e){if(!t._name)throw new Error("Command passed to .addCommand() must have a name\n- specify the name in Command constructor or using .name()");return(e=e||{}).isDefault&&(this._defaultCommandName=t._name),(e.noHelp||e.hidden)&&(t._hidden=!0),this.commands.push(t),t.parent=this,this}createArgument(t,e){return new k(t,e)}argument(t,e,i,n){const s=this.createArgument(t,e);return"function"==typeof i?s.default(n).argParser(i):s.default(i),this.addArgument(s),this}arguments(t){return t.split(/ +/).forEach((t=>{this.argument(t)})),this}addArgument(t){const e=this._args.slice(-1)[0];if(e&&e.variadic)throw new Error(`only the last argument can be variadic '${e.name()}'`);if(t.required&&void 0!==t.defaultValue&&void 0===t.parseArg)throw new Error(`a default value for a required argument is never used: '${t.name()}'`);return this._args.push(t),this}addHelpCommand(t,e){return!1===t?this._addImplicitHelpCommand=!1:(this._addImplicitHelpCommand=!0,"string"==typeof t&&(this._helpCommandName=t.split(" ")[0],this._helpCommandnameAndArgs=t),this._helpCommandDescription=e||this._helpCommandDescription),this}_hasImplicitHelpCommand(){return void 0===this._addImplicitHelpCommand?this.commands.length&&!this._actionHandler&&!this._findCommand("help"):this._addImplicitHelpCommand}hook(t,e){const i=["preAction","postAction"];if(!i.includes(t))throw new Error(`Unexpected value for event passed to hook : '${t}'.\nExpecting one of '${i.join("', '")}'`);return this._lifeCycleHooks[t]?this._lifeCycleHooks[t].push(e):this._lifeCycleHooks[t]=[e],this}exitOverride(t){return this._exitCallback=t||(t=>{if("commander.executeSubCommandAsync"!==t.code)throw t}),this}_exit(t,e,i){this._exitCallback&&this._exitCallback(new V(t,e,i)),H.exit(t)}action(t){return this._actionHandler=e=>{const i=this._args.length,n=e.slice(0,i);return this._storeOptionsAsProperties?n[i]=this:n[i]=this.opts(),n.push(this),t.apply(this,n)},this}createOption(t,e){return new S(t,e)}addOption(t){const e=t.name(),i=t.attributeName();if(t.negate){const e=t.long.replace(/^--no-/,"--");this._findOption(e)||this.setOptionValueWithSource(i,void 0===t.defaultValue||t.defaultValue,"default")}else void 0!==t.defaultValue&&this.setOptionValueWithSource(i,t.defaultValue,"default");this.options.push(t);const n=(e,n,s)=>{null==e&&void 0!==t.presetArg&&(e=t.presetArg);const r=this.getOptionValue(i);if(null!==e&&t.parseArg)try{e=t.parseArg(e,r)}catch(t){if("commander.invalidArgument"===t.code){const e=`${n} ${t.message}`;this.error(e,{exitCode:t.exitCode,code:t.code})}throw t}else null!==e&&t.variadic&&(e=t._concatValue(e,r));null==e&&(e=!t.negate&&(!(!t.isBoolean()&&!t.optional)||"")),this.setOptionValueWithSource(i,e,s)};return this.on("option:"+e,(e=>{const i=`error: option '${t.flags}' argument '${e}' is invalid.`;n(e,i,"cli")})),t.envVar&&this.on("optionEnv:"+e,(e=>{const i=`error: option '${t.flags}' value '${e}' from env '${t.envVar}' is invalid.`;n(e,i,"env")})),this}_optionEx(t,e,i,n,s){if("object"==typeof e&&e instanceof S)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");const r=this.createOption(e,i);if(r.makeOptionMandatory(!!t.mandatory),"function"==typeof n)r.default(s).argParser(n);else if(n instanceof RegExp){const t=n;n=(e,i)=>{const n=t.exec(e);return n?n[0]:i},r.default(s).argParser(n)}else r.default(n);return this.addOption(r)}option(t,e,i,n){return this._optionEx({},t,e,i,n)}requiredOption(t,e,i,n){return this._optionEx({mandatory:!0},t,e,i,n)}combineFlagAndOptionalValue(t=!0){return this._combineFlagAndOptionalValue=!!t,this}allowUnknownOption(t=!0){return this._allowUnknownOption=!!t,this}allowExcessArguments(t=!0){return this._allowExcessArguments=!!t,this}enablePositionalOptions(t=!0){return this._enablePositionalOptions=!!t,this}passThroughOptions(t=!0){if(this._passThroughOptions=!!t,this.parent&&t&&!this.parent._enablePositionalOptions)throw new Error("passThroughOptions can not be used without turning on enablePositionalOptions for parent command(s)");return this}storeOptionsAsProperties(t=!0){if(this._storeOptionsAsProperties=!!t,this.options.length)throw new Error("call .storeOptionsAsProperties() before adding options");return this}getOptionValue(t){return this._storeOptionsAsProperties?this[t]:this._optionValues[t]}setOptionValue(t,e){return this._storeOptionsAsProperties?this[t]=e:this._optionValues[t]=e,this}setOptionValueWithSource(t,e,i){return this.setOptionValue(t,e),this._optionValueSources[t]=i,this}getOptionValueSource(t){return this._optionValueSources[t]}_prepareUserArgs(t,e){if(void 0!==t&&!Array.isArray(t))throw new Error("first parameter to parse must be array or undefined");let i;switch(e=e||{},void 0===t&&(t=H.argv,H.versions&&H.versions.electron&&(e.from="electron")),this.rawArgs=t.slice(),e.from){case void 0:case"node":this._scriptPath=t[1],i=t.slice(2);break;case"electron":H.defaultApp?(this._scriptPath=t[1],i=t.slice(2)):i=t.slice(1);break;case"user":i=t.slice(0);break;default:throw new Error(`unexpected parse option { from: '${e.from}' }`)}return!this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||"program",i}parse(t,e){const i=this._prepareUserArgs(t,e);return this._parseCommand([],i),this}async parseAsync(t,e){const i=this._prepareUserArgs(t,e);return await this._parseCommand([],i),this}_executeSubCommand(t,e){e=e.slice();let i=!1;const n=[".js",".ts",".tsx",".mjs",".cjs"];function s(t,e){const i=x.resolve(t,e);if($.existsSync(i))return i;if(n.includes(x.extname(e)))return;const s=n.find((t=>$.existsSync(`${i}${t}`)));return s?`${i}${s}`:void 0}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let r,o=t._executableFile||`${this._name}-${t._name}`,a=this._executableDir||"";if(this._scriptPath){let t;try{t=$.realpathSync(this._scriptPath)}catch(e){t=this._scriptPath}a=x.resolve(x.dirname(t),a)}if(a){let e=s(a,o);if(!e&&!t._executableFile&&this._scriptPath){const i=x.basename(this._scriptPath,x.extname(this._scriptPath));i!==this._name&&(e=s(a,`${i}-${t._name}`))}o=e||o}if(i=n.includes(x.extname(o)),"win32"!==H.platform?i?(e.unshift(o),e=I(H.execArgv).concat(e),r=E.spawn(H.argv[0],e,{stdio:"inherit"})):r=E.spawn(o,e,{stdio:"inherit"}):(e.unshift(o),e=I(H.execArgv).concat(e),r=E.spawn(H.execPath,e,{stdio:"inherit"})),!r.killed){["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach((t=>{H.on(t,(()=>{!1===r.killed&&null===r.exitCode&&r.kill(t)}))}))}const h=this._exitCallback;h?r.on("close",(()=>{h(new V(H.exitCode||0,"commander.executeSubCommandAsync","(close)"))})):r.on("close",H.exit.bind(H)),r.on("error",(e=>{if("ENOENT"===e.code){const e=a?`searched for local subcommand relative to directory '${a}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",i=`'${o}' does not exist\n - if '${t._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead\n - if the default executable name is not suitable, use the executableFile option to supply a custom name or path\n - ${e}`;throw new Error(i)}if("EACCES"===e.code)throw new Error(`'${o}' not executable`);if(h){const t=new V(1,"commander.executeSubCommandAsync","(error)");t.nestedError=e,h(t)}else H.exit(1)})),this.runningCommand=r}_dispatchSubcommand(t,e,i){const n=this._findCommand(t);if(n||this.help({error:!0}),!n._executableHandler)return n._parseCommand(e,i);this._executeSubCommand(n,e.concat(i))}_checkNumberOfArguments(){this._args.forEach(((t,e)=>{t.required&&null==this.args[e]&&this.missingArgument(t.name())})),this._args.length>0&&this._args[this._args.length-1].variadic||this.args.length>this._args.length&&this._excessArguments(this.args)}_processArguments(){const t=(t,e,i)=>{let n=e;if(null!==e&&t.parseArg)try{n=t.parseArg(e,i)}catch(i){if("commander.invalidArgument"===i.code){const n=`error: command-argument value '${e}' is invalid for argument '${t.name()}'. ${i.message}`;this.error(n,{exitCode:i.exitCode,code:i.code})}throw i}return n};this._checkNumberOfArguments();const e=[];this._args.forEach(((i,n)=>{let s=i.defaultValue;i.variadic?n<this.args.length?(s=this.args.slice(n),i.parseArg&&(s=s.reduce(((e,n)=>t(i,n,e)),i.defaultValue))):void 0===s&&(s=[]):n<this.args.length&&(s=this.args[n],i.parseArg&&(s=t(i,s,i.defaultValue))),e[n]=s})),this.processedArgs=e}_chainOrCall(t,e){return t&&t.then&&"function"==typeof t.then?t.then((()=>e())):e()}_chainOrCallHooks(t,e){let i=t;const n=[];return M(this).reverse().filter((t=>void 0!==t._lifeCycleHooks[e])).forEach((t=>{t._lifeCycleHooks[e].forEach((e=>{n.push({hookedCommand:t,callback:e})}))})),"postAction"===e&&n.reverse(),n.forEach((t=>{i=this._chainOrCall(i,(()=>t.callback(t.hookedCommand,this)))})),i}_parseCommand(t,e){const i=this.parseOptions(e);if(this._parseOptionsEnv(),this._parseOptionsImplied(),t=t.concat(i.operands),e=i.unknown,this.args=t.concat(e),t&&this._findCommand(t[0]))return this._dispatchSubcommand(t[0],t.slice(1),e);if(this._hasImplicitHelpCommand()&&t[0]===this._helpCommandName)return 1===t.length&&this.help(),this._dispatchSubcommand(t[1],[],[this._helpLongFlag]);if(this._defaultCommandName)return j(this,e),this._dispatchSubcommand(this._defaultCommandName,t,e);!this.commands.length||0!==this.args.length||this._actionHandler||this._defaultCommandName||this.help({error:!0}),j(this,i.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();const n=()=>{i.unknown.length>0&&this.unknownOption(i.unknown[0])},s=`command:${this.name()}`;if(this._actionHandler){let i;return n(),this._processArguments(),i=this._chainOrCallHooks(i,"preAction"),i=this._chainOrCall(i,(()=>this._actionHandler(this.processedArgs))),this.parent&&(i=this._chainOrCall(i,(()=>{this.parent.emit(s,t,e)}))),i=this._chainOrCallHooks(i,"postAction"),i}if(this.parent&&this.parent.listenerCount(s))n(),this._processArguments(),this.parent.emit(s,t,e);else if(t.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",t,e);this.listenerCount("command:*")?this.emit("command:*",t,e):this.commands.length?this.unknownCommand():(n(),this._processArguments())}else this.commands.length?(n(),this.help({error:!0})):(n(),this._processArguments())}_findCommand(t){if(t)return this.commands.find((e=>e._name===t||e._aliases.includes(t)))}_findOption(t){return this.options.find((e=>e.is(t)))}_checkForMissingMandatoryOptions(){for(let t=this;t;t=t.parent)t.options.forEach((e=>{e.mandatory&&void 0===t.getOptionValue(e.attributeName())&&t.missingMandatoryOptionValue(e)}))}_checkForConflictingLocalOptions(){const t=this.options.filter((t=>{const e=t.attributeName();return void 0!==this.getOptionValue(e)&&"default"!==this.getOptionValueSource(e)})),e=t.filter((t=>t.conflictsWith.length>0));e.forEach((e=>{const i=t.find((t=>e.conflictsWith.includes(t.attributeName())));i&&this._conflictingOption(e,i)}))}_checkForConflictingOptions(){for(let t=this;t;t=t.parent)t._checkForConflictingLocalOptions()}parseOptions(t){const e=[],i=[];let n=e;const s=t.slice();function r(t){return t.length>1&&"-"===t[0]}let o=null;for(;s.length;){const t=s.shift();if("--"===t){n===i&&n.push(t),n.push(...s);break}if(!o||r(t)){if(o=null,r(t)){const e=this._findOption(t);if(e){if(e.required){const t=s.shift();void 0===t&&this.optionMissingArgument(e),this.emit(`option:${e.name()}`,t)}else if(e.optional){let t=null;s.length>0&&!r(s[0])&&(t=s.shift()),this.emit(`option:${e.name()}`,t)}else this.emit(`option:${e.name()}`);o=e.variadic?e:null;continue}}if(t.length>2&&"-"===t[0]&&"-"!==t[1]){const e=this._findOption(`-${t[1]}`);if(e){e.required||e.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${e.name()}`,t.slice(2)):(this.emit(`option:${e.name()}`),s.unshift(`-${t.slice(2)}`));continue}}if(/^--[^=]+=/.test(t)){const e=t.indexOf("="),i=this._findOption(t.slice(0,e));if(i&&(i.required||i.optional)){this.emit(`option:${i.name()}`,t.slice(e+1));continue}}if(r(t)&&(n=i),(this._enablePositionalOptions||this._passThroughOptions)&&0===e.length&&0===i.length){if(this._findCommand(t)){e.push(t),s.length>0&&i.push(...s);break}if(t===this._helpCommandName&&this._hasImplicitHelpCommand()){e.push(t),s.length>0&&e.push(...s);break}if(this._defaultCommandName){i.push(t),s.length>0&&i.push(...s);break}}if(this._passThroughOptions){n.push(t),s.length>0&&n.push(...s);break}n.push(t)}else this.emit(`option:${o.name()}`,t)}return{operands:e,unknown:i}}opts(){if(this._storeOptionsAsProperties){const t={},e=this.options.length;for(let i=0;i<e;i++){const e=this.options[i].attributeName();t[e]=e===this._versionOptionName?this._version:this[e]}return t}return this._optionValues}optsWithGlobals(){return M(this).reduce(((t,e)=>Object.assign(t,e.opts())),{})}error(t,e){this._outputConfiguration.outputError(`${t}\n`,this._outputConfiguration.writeErr),"string"==typeof this._showHelpAfterError?this._outputConfiguration.writeErr(`${this._showHelpAfterError}\n`):this._showHelpAfterError&&(this._outputConfiguration.writeErr("\n"),this.outputHelp({error:!0}));const i=e||{},n=i.exitCode||1,s=i.code||"commander.error";this._exit(n,s,t)}_parseOptionsEnv(){this.options.forEach((t=>{if(t.envVar&&t.envVar in H.env){const e=t.attributeName();(void 0===this.getOptionValue(e)||["default","config","env"].includes(this.getOptionValueSource(e)))&&(t.required||t.optional?this.emit(`optionEnv:${t.name()}`,H.env[t.envVar]):this.emit(`optionEnv:${t.name()}`))}}))}_parseOptionsImplied(){const t=new D(this.options),e=t=>void 0!==this.getOptionValue(t)&&!["default","implied"].includes(this.getOptionValueSource(t));this.options.filter((i=>void 0!==i.implied&&e(i.attributeName())&&t.valueFromOption(this.getOptionValue(i.attributeName()),i))).forEach((t=>{Object.keys(t.implied).filter((t=>!e(t))).forEach((e=>{this.setOptionValueWithSource(e,t.implied[e],"implied")}))}))}missingArgument(t){const e=`error: missing required argument '${t}'`;this.error(e,{code:"commander.missingArgument"})}optionMissingArgument(t){const e=`error: option '${t.flags}' argument missing`;this.error(e,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(t){const e=`error: required option '${t.flags}' not specified`;this.error(e,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(t,e){const i=t=>{const e=t.attributeName(),i=this.getOptionValue(e),n=this.options.find((t=>t.negate&&e===t.attributeName())),s=this.options.find((t=>!t.negate&&e===t.attributeName()));return n&&(void 0===n.presetArg&&!1===i||void 0!==n.presetArg&&i===n.presetArg)?n:s||t},n=t=>{const e=i(t),n=e.attributeName();return"env"===this.getOptionValueSource(n)?`environment variable '${e.envVar}'`:`option '${e.flags}'`},s=`error: ${n(t)} cannot be used with ${n(e)}`;this.error(s,{code:"commander.conflictingOption"})}unknownOption(t){if(this._allowUnknownOption)return;let e="";if(t.startsWith("--")&&this._showSuggestionAfterError){let i=[],n=this;do{const t=n.createHelp().visibleOptions(n).filter((t=>t.long)).map((t=>t.long));i=i.concat(t),n=n.parent}while(n&&!n._enablePositionalOptions);e=P(t,i)}const i=`error: unknown option '${t}'${e}`;this.error(i,{code:"commander.unknownOption"})}_excessArguments(t){if(this._allowExcessArguments)return;const e=this._args.length,i=1===e?"":"s",n=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${e} argument${i} but got ${t.length}.`;this.error(n,{code:"commander.excessArguments"})}unknownCommand(){const t=this.args[0];let e="";if(this._showSuggestionAfterError){const i=[];this.createHelp().visibleCommands(this).forEach((t=>{i.push(t.name()),t.alias()&&i.push(t.alias())})),e=P(t,i)}const i=`error: unknown command '${t}'${e}`;this.error(i,{code:"commander.unknownCommand"})}version(t,e,i){if(void 0===t)return this._version;this._version=t,e=e||"-V, --version",i=i||"output the version number";const n=this.createOption(e,i);return this._versionOptionName=n.attributeName(),this.options.push(n),this.on("option:"+n.name(),(()=>{this._outputConfiguration.writeOut(`${t}\n`),this._exit(0,"commander.version",t)})),this}description(t,e){return void 0===t&&void 0===e?this._description:(this._description=t,e&&(this._argsDescription=e),this)}summary(t){return void 0===t?this._summary:(this._summary=t,this)}alias(t){if(void 0===t)return this._aliases[0];let e=this;if(0!==this.commands.length&&this.commands[this.commands.length-1]._executableHandler&&(e=this.commands[this.commands.length-1]),t===e._name)throw new Error("Command alias can't be the same as its name");return e._aliases.push(t),this}aliases(t){return void 0===t?this._aliases:(t.forEach((t=>this.alias(t))),this)}usage(t){if(void 0===t){if(this._usage)return this._usage;const t=this._args.map((t=>y(t)));return[].concat(this.options.length||this._hasHelpOption?"[options]":[],this.commands.length?"[command]":[],this._args.length?t:[]).join(" ")}return this._usage=t,this}name(t){return void 0===t?this._name:(this._name=t,this)}nameFromFilename(t){return this._name=x.basename(t,x.extname(t)),this}executableDir(t){return void 0===t?this._executableDir:(this._executableDir=t,this)}helpInformation(t){const e=this.createHelp();return void 0===e.helpWidth&&(e.helpWidth=t&&t.error?this._outputConfiguration.getErrHelpWidth():this._outputConfiguration.getOutHelpWidth()),e.formatHelp(this,e)}_getHelpContext(t){const e={error:!!(t=t||{}).error};let i;return i=e.error?t=>this._outputConfiguration.writeErr(t):t=>this._outputConfiguration.writeOut(t),e.write=t.write||i,e.command=this,e}outputHelp(t){let e;"function"==typeof t&&(e=t,t=void 0);const i=this._getHelpContext(t);M(this).reverse().forEach((t=>t.emit("beforeAllHelp",i))),this.emit("beforeHelp",i);let n=this.helpInformation(i);if(e&&(n=e(n),"string"!=typeof n&&!Buffer.isBuffer(n)))throw new Error("outputHelp callback must return a string or a Buffer");i.write(n),this.emit(this._helpLongFlag),this.emit("afterHelp",i),M(this).forEach((t=>t.emit("afterAllHelp",i)))}helpOption(t,e){if("boolean"==typeof t)return this._hasHelpOption=t,this;this._helpFlags=t||this._helpFlags,this._helpDescription=e||this._helpDescription;const i=N(this._helpFlags);return this._helpShortFlag=i.shortFlag,this._helpLongFlag=i.longFlag,this}help(t){this.outputHelp(t);let e=H.exitCode||0;0===e&&t&&"function"!=typeof t&&t.error&&(e=1),this._exit(e,"commander.help","(outputHelp)")}addHelpText(t,e){const i=["beforeAll","before","after","afterAll"];if(!i.includes(t))throw new Error(`Unexpected value for position to addHelpText.\nExpecting one of '${i.join("', '")}'`);const n=`${t}Help`;return this.on(n,(t=>{let i;i="function"==typeof e?e({error:t.error,command:t.command}):e,i&&t.write(`${i}\n`)})),this}}function j(t,e){t._hasHelpOption&&e.find((e=>e===t._helpLongFlag||e===t._helpShortFlag))&&(t.outputHelp(),t._exit(0,"commander.helpDisplayed","(outputHelp)"))}function I(t){return t.map((t=>{if(!t.startsWith("--inspect"))return t;let e,i,n="127.0.0.1",s="9229";return null!==(i=t.match(/^(--inspect(-brk)?)$/))?e=i[1]:null!==(i=t.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))?(e=i[1],/^\d+$/.test(i[3])?s=i[3]:n=i[3]):null!==(i=t.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))&&(e=i[1],n=i[3],s=i[4]),e&&"0"!==s?`${e}=${n}:${parseInt(s)+1}`:t}))}function M(t){const e=[];for(let i=t;i;i=i.parent)e.push(i);return e}f.Command=T,function(t,e){const{Argument:i}=p,{Command:n}=f,{CommanderError:s,InvalidArgumentError:r}=m,{Help:o}=_,{Option:a}=O;(e=t.exports=new n).program=e,e.Argument=i,e.Command=n,e.CommanderError=s,e.Help=o,e.InvalidArgumentError=r,e.InvalidOptionArgumentError=r,e.Option=a}(u,u.exports);var q=u.exports;const{program:W,createCommand:L,createArgument:U,createOption:R,CommanderError:B,InvalidArgumentError:G,Command:J,Argument:Y,Option:z,Help:K}=q;var Q={exports:{}},X=l.default,Z=h.default,tt=X.exists||Z.exists,et=function(t,e){var i,n=[];["end_of_record"].concat(t.split("\n")).forEach((function(t){var e,s,r=(t=t.trim()).split(":"),o=[r.shift(),r.join(":")];switch(o[0].toUpperCase()){case"TN":i.title=o[1].trim();break;case"SF":i.file=o.slice(1).join(":").trim();break;case"FNF":i.functions.found=Number(o[1].trim());break;case"FNH":i.functions.hit=Number(o[1].trim());break;case"LF":i.lines.found=Number(o[1].trim());break;case"LH":i.lines.hit=Number(o[1].trim());break;case"DA":e=o[1].split(","),i.lines.details.push({line:Number(e[0]),hit:Number(e[1])});break;case"FN":s=o[1].split(","),i.functions.details.push({name:s[1],line:Number(s[0])});break;case"FNDA":s=o[1].split(","),i.functions.details.some((function(t,e){if(t.name===s[1]&&void 0===t.hit)return i.functions.details[e].hit=Number(s[0]),!0}));break;case"BRDA":s=o[1].split(","),i.branches.details.push({line:Number(s[0]),block:Number(s[1]),branch:Number(s[2]),taken:"-"===s[3]?0:Number(s[3])});break;case"BRF":i.branches.found=Number(o[1]);break;case"BRH":i.branches.hit=Number(o[1])}t.indexOf("end_of_record")>-1&&(n.push(i),i={lines:{found:0,hit:0,details:[]},functions:{hit:0,found:0,details:[]},branches:{hit:0,found:0,details:[]}})})),n.shift(),n.length?e(null,n):e("Failed to parse string")};Q.exports=function(t,e){tt(t,(function(i){if(!i)return et(t,e);X.readFile(t,"utf8",(function(t,i){et(i,e)}))}))};var it=Q.exports.source=et;W.name("lcov-viewer").command("lcov <src>").description("Converts lcov.info file into an LCOV viewer HTML report.").option("-o, --output <output>","The output directory.","./lcov-viewer").action((async function(t,{output:e}){const[i,s]=await Promise.all([n.promises.stat(t),n.promises.readFile(t,{encoding:"utf8"})]),r=i.mtime.toString(),o=await(a=s,new Promise(((t,e)=>{it(a,((i,n)=>{i?e(i):t(n)}))})));var a;const l=o.reduce(((t,e)=>{const i=e.file.replace(/\\/g,"/").replace(/^(.):/,"/$1").replace(/^\//,"");return t[i]={metrics:{lines:{total:e.lines.found,covered:e.lines.hit},functions:{total:e.functions.found,covered:e.functions.hit},branches:{total:e.branches.found,covered:e.branches.hit}},path:i,filename:i.split("/").pop()},t}),{}),c=h.default.resolve(__dirname,"assets");await n.promises.mkdir(e,{recursive:!0}),(await n.promises.readdir(c)).map((t=>{const i=h.default.resolve(e,t);return n.promises.copyFile(h.default.resolve(c,t),i)})),await n.promises.writeFile(h.default.resolve(e,"report-data.js"),`window.REPORT_DATE = '${r.toString()}';window.COVERAGE_DATA = ${JSON.stringify(l)};`,{encoding:"utf8"})})),W.parse();