New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dfx-translate

Package Overview
Dependencies
Maintainers
2
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dfx-translate - npm Package Compare versions

Comparing version 1.6.0 to 1.6.1

6

CHANGELOG.md

@@ -5,2 +5,8 @@ # Changelog

## [1.6.1](https://github.com/Dafnik/dfts-common/compare/dfx-translate-1.6.0...dfx-translate-1.6.1) (2023-01-18)
### Bug Fixes
- **dfx-translate:** cli requiring commander to be installed ([8f829d4](https://github.com/Dafnik/dfts-common/commit/8f829d41652a6de3f38d7d3e662b1360acae8486))
# 1.6.0 (2023-01-18)

@@ -7,0 +13,0 @@

2

cli/index.js

@@ -1,1 +0,1 @@

(()=>{"use strict";var e={499:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return o(t,e),t},s=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,a){function s(e){try{i(r.next(e))}catch(t){a(t)}}function c(e){try{i(r.throw(e))}catch(t){a(t)}}function i(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}i((r=r.apply(e,t||[])).next())}))},c=this&&this.__generator||function(e,t){var n,r,o,a,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function c(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(c){a=[6,c],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.translateIntoLanguage=t.getTypeStringFromArray=t.convertToObject=t.convertToArray=t.writeToFile=t.getJSON=t.createDir=t.exists=t.getDefaultLanguage=void 0;var i=a(n(147));t.getDefaultLanguage=function(e){return s(void 0,void 0,Promise,(function(){var t,n,r,o,a,s,l,u,f;return c(this,(function(c){switch(c.label){case 0:n="./src/app/app.module.ts",r="./src/app/app.component.ts",c.label=1;case 1:return c.trys.push([1,4,,10]),[4,i.promises.access(n)];case 2:return c.sent(),a=(o=/DfxTranslateModule\.setup\((.+)\)\s*,/).exec,[4,i.promises.readFile(n,"utf-8")];case 3:return t=a.apply(o,[c.sent()]),[3,10];case 4:c.sent(),e&&console.log("dfx-translate >> getDefaultLanguage: app.module.ts not found - trying app.component.ts"),c.label=5;case 5:return c.trys.push([5,8,,9]),[4,i.promises.access(r)];case 6:return c.sent(),l=(s=/provideDfxTranslate\((.+)\)\s*,/).exec,[4,i.promises.readFile(r,"utf-8")];case 7:return t=l.apply(s,[c.sent()]),[3,9];case 8:throw c.sent(),console.log("dfx-translate >> getDefaultLanguage: Neither app.module.ts or app.component.ts found - cancelling"),Error("Neither app.module.ts or app.component.ts found");case 9:return[3,10];case 10:if(!t)throw console.log("dfx-translate >> getDefaultLanguage: Unable to extract default language out of json"),new Error("Unable to extract JSON string from file");if(u=t[1].replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g,'"$2": ').replace(/'/g,'"'),!(f=JSON.parse(u).defaultLanguage))throw console.log("dfx-translate >> getDefaultLanguage: Unable to extract default language out of json"),new Error("Unable to extract JSON string from file");return[2,f]}}))}))};t.exists=function(e){return i.existsSync(e)};t.createDir=function(e){return i.mkdirSync(e,{recursive:!0})};t.getJSON=function(e){return s(void 0,void 0,Promise,(function(){var t,n;return c(this,(function(r){switch(r.label){case 0:return n=(t=JSON).parse,[4,i.promises.readFile(e,"utf-8")];case 1:return[2,n.apply(t,[r.sent()])]}}))}))};t.writeToFile=function(e,t){return s(void 0,void 0,Promise,(function(){return c(this,(function(n){return[2,i.promises.writeFile(e,t)]}))}))};t.convertToArray=function(e){return Object.keys(e).map((function(t){return{key:t,value:e[t]}}))};t.convertToObject=function(e){return e.reduce((function(e,t){return e[t.key]=t.value,e}),{})};t.getTypeStringFromArray=function(e){return"export type translationKeys = string | undefined | null | ".concat(e.map((function(e){return"'".concat(e.key,"'")})).join(" | "),";")};t.translateIntoLanguage=function(e,n,r,o,a,u,f){return s(void 0,void 0,Promise,(function(){var s,d,p,g,h,v,y,m,b,x,w,T,_,O,S,j;return c(this,(function(c){switch(c.label){case 0:return s="".concat(a).concat(r,".json"),(0,t.exists)(s)?[4,(0,t.getJSON)(s)]:[3,2];case 1:return p=c.sent(),[3,3];case 2:p=void 0,c.label=3;case 3:if(d=p,f&&console.log('dfx-translate >> manual translation lookup path: "'.concat(s,'"')),void 0===d)console.log('dfx-translate >> no manual translation found for: "'.concat(r,'"'));else for(g=0,h=o;g<h.length;g++)v=h[g],null!=d[v.key]&&(f&&console.log('dfx-translate >> found manual translation for "'.concat(v.key,'"')),o.splice(o.indexOf(v),1));return y="./node_modules/dfx-translate/translation/translation_cache_"+r+".json",(0,t.exists)(y)&&u?[4,(0,t.getJSON)(y)]:[3,5];case 4:return b=c.sent(),[3,6];case 5:b=void 0,c.label=6;case 6:m=b,f&&console.log('dfx-translate >> cache lookup path: "'.concat(y,'"')),void 0===m&&console.log('dfx-translate >> no local cache found for "'.concat(r,'"')),x=[],w=0,T=o,c.label=7;case 7:return w<T.length?(_=T[w],(O=m?m[_.value]:void 0)?(console.log('Translating "'.concat(_.value,'" from cache to ').concat(r,': "').concat(O,'"')),x.push({key:_.key,value:O}),[3,11]):[3,8]):[3,12];case 8:return c.trys.push([8,10,,11]),[4,l(e,n,r,_)];case 9:return S=c.sent(),m&&(m[_.value]=S.value),x.push(S),[3,11];case 10:return j=c.sent(),console.log(j),console.log('dfx-translate >> error during fetch for "'.concat(_.value,'" to ').concat(r)),[3,11];case 11:return w++,[3,7];case 12:return m&&i.promises.writeFile(y,JSON.stringify(m)).then((function(){console.log('dfx-translate >> cache saved in "'.concat(y,'"'))})),[2,x]}}))}))};var l=function(e,t,n,r){return s(void 0,void 0,Promise,(function(){var o,a,s,i;return c(this,(function(c){switch(c.label){case 0:return o=JSON.stringify({format:"text",q:r.value,target:n,source:t}),a=new AbortController,setTimeout((function(){return a.abort()}),5e3),[4,fetch("".concat(e,"/translate"),{signal:a.signal,method:"POST",headers:{"Content-Type":"application/json; charset=utf-8"},body:o})];case 1:if(!(s=c.sent()).ok)throw new Error("Fetch failed with status code ".concat(s.status));return[4,s.json()];case 2:return i=c.sent(),console.log('Translating "'.concat(r.value,'" to ').concat(n,': "').concat(i.translatedText,'"')),[2,{key:r.key,value:i.translatedText}]}}))}))}},526:function(e,t,n){var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,a){function s(e){try{i(r.next(e))}catch(t){a(t)}}function c(e){try{i(r.throw(e))}catch(t){a(t)}}function i(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}i((r=r.apply(e,t||[])).next())}))},o=this&&this.__generator||function(e,t){var n,r,o,a,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function c(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(c){a=[6,c],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};Object.defineProperty(t,"__esModule",{value:!0});var a=n(499),s=n(304),c="./node_modules/dfx-translate/lib/translationKeys.d.ts",i="./src/assets/i18n/";s.program.name("translate-cli").description("dfx-translate development tools and helper scripts").version("0.0.2"),s.program.command("generateTypes").description("Generates type-definitions for your default language").argument("[sourceLanguagePath]","Path to source language file").option("--log","Log more information").option("--dir <path>","Path to language files folder",i).action((function(e,t){return r(void 0,void 0,void 0,(function(){var n,r;return o(this,(function(o){switch(o.label){case 0:return null==e?[3,1]:(n=e,[3,3]);case 1:return r=t.dir,[4,(0,a.getDefaultLanguage)(t.log)];case 2:n=r+o.sent()+".json",o.label=3;case 3:return e=n,t.log&&console.log('dfx-translate >> source path: "'.concat(e,'"')),(0,a.getJSON)(e).then((function(e){return(0,a.convertToArray)(e)})).then((function(e){return(0,a.getTypeStringFromArray)(e)})).then((function(e){return t.log&&console.log('dfx-translate >> new types: "'.concat(e,'"')),(0,a.writeToFile)(c,e)})).then((function(){return console.log("dfx-translate >> Successfully saved translation types")})).catch((function(e){return console.error("Error",e)})),[2]}}))}))})),s.program.command("resetTypes").description("Resets type-definitions").action((function(){return r(void 0,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,(0,a.writeToFile)(c,"export type translationKeys = string | undefined | null;")];case 1:return e.sent(),console.log("dfx-translate >> Types resetted."),[2]}}))}))})),s.program.command("createDir").description("Creates the default directory for all language files").option("--log","Log more information").action((function(e){(0,a.exists)(i)?e.log&&console.log("dfx-translate >> Language directory already exists"):((0,a.createDir)(i),console.log("dfx-translate >> Created default language assets directory."))})),s.program.command("autoTranslate").description("Translates a file into another language").argument("<url>","LibreTranslate Instance URL").argument("<targetLanguageCode>","Wanted language").option("--log","Log more information").option("--disable-cache","Disables cache",!1).option("--source <path>","Path to source language file").option("--dir <path>","Path to language files folder",i).action((function(e,t,n){return r(void 0,void 0,void 0,(function(){var r,s,c,i,l,u;return o(this,(function(o){switch(o.label){case 0:return null===(l=n.source)||void 0===l?[3,1]:(s=l,[3,3]);case 1:return c=n.dir,[4,(0,a.getDefaultLanguage)(n.log)];case 2:s=c+o.sent()+".json",o.label=3;case 3:return(i=null===(u=(r=s).split("/").pop())||void 0===u?void 0:u.split(".").at(0))?((0,a.getJSON)(r).then((function(e){return(0,a.convertToArray)(e)})).then((function(r){return(0,a.translateIntoLanguage)(e,i,t,r,n.dir,n.disableCache,n.log)})).then((function(e){return(0,a.convertToObject)(e)})).then((function(e){return(0,a.writeToFile)("".concat(n.dir).concat(t,"_auto.json"),JSON.stringify(e))})).then((function(){return console.log("dfx-translate >> translation successfully saved")})).catch((function(e){return console.error("Error",e)})),[2]):(console.log("dfx-translate >> ERROR: Could not extract source language"),n.log&&console.log('dfx-translate >> path: "'.concat(r,'"')),[2])}}))}))})),s.program.parse()},304:e=>{e.exports=require("commander")},147:e=>{e.exports=require("fs")}},t={};var n=function n(r){var o=t[r];if(void 0!==o)return o.exports;var a=t[r]={exports:{}};return e[r].call(a.exports,a,a.exports,n),a.exports}(526),r=exports;for(var o in n)r[o]=n[o];n.__esModule&&Object.defineProperty(r,"__esModule",{value:!0})})();
(()=>{var t={504:(t,e,n)=>{const{Argument:i}=n(644),{Command:r}=n(593),{CommanderError:o,InvalidArgumentError:s}=n(884),{Help:a}=n(538),{Option:l}=n(267);(e=t.exports=new r).program=e,e.Argument=i,e.Command=r,e.CommanderError=o,e.Help=a,e.InvalidArgumentError=s,e.InvalidOptionArgumentError=s,e.Option=l},644:(t,e,n)=>{const{InvalidArgumentError:i}=n(884);e.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 i(`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}},e.humanReadableArgName=function(t){const e=t.name()+(!0===t.variadic?"...":"");return t.required?"<"+e+">":"["+e+"]"}},593:(t,e,n)=>{const i=n(361).EventEmitter,r=n(81),o=n(17),s=n(147),a=n(282),{Argument:l,humanReadableArgName:c}=n(644),{CommanderError:h}=n(884),{Help:u}=n(538),{Option:p,splitOptionFlags:d,DualOptions:m}=n(267),{suggestSimilar:g}=n(359);class f extends i{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=>a.stdout.write(t),writeErr:t=>a.stderr.write(t),getOutHelpWidth:()=>a.stdout.isTTY?a.stdout.columns:void 0,getErrHelpWidth:()=>a.stderr.isTTY?a.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,n){let i=e,r=n;"object"==typeof i&&null!==i&&(r=i,i=null),r=r||{};const[,o,s]=t.match(/([^ ]+) *(.*)/),a=this.createCommand(o);return i&&(a.description(i),a._executableHandler=!0),r.isDefault&&(this._defaultCommandName=a._name),a._hidden=!(!r.noHelp&&!r.hidden),a._executableFile=r.executableFile||null,s&&a.arguments(s),this.commands.push(a),a.parent=this,a.copyInheritedSettings(this),i?this:a}createCommand(t){return new f(t)}createHelp(){return Object.assign(new u,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 l(t,e)}argument(t,e,n,i){const r=this.createArgument(t,e);return"function"==typeof n?r.default(i).argParser(n):r.default(n),this.addArgument(r),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 n=["preSubcommand","preAction","postAction"];if(!n.includes(t))throw new Error(`Unexpected value for event passed to hook : '${t}'.\nExpecting one of '${n.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,n){this._exitCallback&&this._exitCallback(new h(t,e,n)),a.exit(t)}action(t){return this._actionHandler=e=>{const n=this._args.length,i=e.slice(0,n);return this._storeOptionsAsProperties?i[n]=this:i[n]=this.opts(),i.push(this),t.apply(this,i)},this}createOption(t,e){return new p(t,e)}addOption(t){const e=t.name(),n=t.attributeName();if(t.negate){const e=t.long.replace(/^--no-/,"--");this._findOption(e)||this.setOptionValueWithSource(n,void 0===t.defaultValue||t.defaultValue,"default")}else void 0!==t.defaultValue&&this.setOptionValueWithSource(n,t.defaultValue,"default");this.options.push(t);const i=(e,i,r)=>{null==e&&void 0!==t.presetArg&&(e=t.presetArg);const o=this.getOptionValue(n);if(null!==e&&t.parseArg)try{e=t.parseArg(e,o)}catch(t){if("commander.invalidArgument"===t.code){const e=`${i} ${t.message}`;this.error(e,{exitCode:t.exitCode,code:t.code})}throw t}else null!==e&&t.variadic&&(e=t._concatValue(e,o));null==e&&(e=!t.negate&&(!(!t.isBoolean()&&!t.optional)||"")),this.setOptionValueWithSource(n,e,r)};return this.on("option:"+e,(e=>{const n=`error: option '${t.flags}' argument '${e}' is invalid.`;i(e,n,"cli")})),t.envVar&&this.on("optionEnv:"+e,(e=>{const n=`error: option '${t.flags}' value '${e}' from env '${t.envVar}' is invalid.`;i(e,n,"env")})),this}_optionEx(t,e,n,i,r){if("object"==typeof e&&e instanceof p)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");const o=this.createOption(e,n);if(o.makeOptionMandatory(!!t.mandatory),"function"==typeof i)o.default(r).argParser(i);else if(i instanceof RegExp){const t=i;i=(e,n)=>{const i=t.exec(e);return i?i[0]:n},o.default(r).argParser(i)}else o.default(i);return this.addOption(o)}option(t,e,n,i){return this._optionEx({},t,e,n,i)}requiredOption(t,e,n,i){return this._optionEx({mandatory:!0},t,e,n,i)}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.setOptionValueWithSource(t,e,void 0)}setOptionValueWithSource(t,e,n){return this._storeOptionsAsProperties?this[t]=e:this._optionValues[t]=e,this._optionValueSources[t]=n,this}getOptionValueSource(t){return this._optionValueSources[t]}getOptionValueSourceWithGlobals(t){let e;return b(this).forEach((n=>{void 0!==n.getOptionValueSource(t)&&(e=n.getOptionValueSource(t))})),e}_prepareUserArgs(t,e){if(void 0!==t&&!Array.isArray(t))throw new Error("first parameter to parse must be array or undefined");let n;switch(e=e||{},void 0===t&&(t=a.argv,a.versions&&a.versions.electron&&(e.from="electron")),this.rawArgs=t.slice(),e.from){case void 0:case"node":this._scriptPath=t[1],n=t.slice(2);break;case"electron":a.defaultApp?(this._scriptPath=t[1],n=t.slice(2)):n=t.slice(1);break;case"user":n=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",n}parse(t,e){const n=this._prepareUserArgs(t,e);return this._parseCommand([],n),this}async parseAsync(t,e){const n=this._prepareUserArgs(t,e);return await this._parseCommand([],n),this}_executeSubCommand(t,e){e=e.slice();let n=!1;const i=[".js",".ts",".tsx",".mjs",".cjs"];function l(t,e){const n=o.resolve(t,e);if(s.existsSync(n))return n;if(i.includes(o.extname(e)))return;const r=i.find((t=>s.existsSync(`${n}${t}`)));return r?`${n}${r}`:void 0}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let c,u=t._executableFile||`${this._name}-${t._name}`,p=this._executableDir||"";if(this._scriptPath){let t;try{t=s.realpathSync(this._scriptPath)}catch(e){t=this._scriptPath}p=o.resolve(o.dirname(t),p)}if(p){let e=l(p,u);if(!e&&!t._executableFile&&this._scriptPath){const n=o.basename(this._scriptPath,o.extname(this._scriptPath));n!==this._name&&(e=l(p,`${n}-${t._name}`))}u=e||u}if(n=i.includes(o.extname(u)),"win32"!==a.platform?n?(e.unshift(u),e=v(a.execArgv).concat(e),c=r.spawn(a.argv[0],e,{stdio:"inherit"})):c=r.spawn(u,e,{stdio:"inherit"}):(e.unshift(u),e=v(a.execArgv).concat(e),c=r.spawn(a.execPath,e,{stdio:"inherit"})),!c.killed){["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach((t=>{a.on(t,(()=>{!1===c.killed&&null===c.exitCode&&c.kill(t)}))}))}const d=this._exitCallback;d?c.on("close",(()=>{d(new h(a.exitCode||0,"commander.executeSubCommandAsync","(close)"))})):c.on("close",a.exit.bind(a)),c.on("error",(e=>{if("ENOENT"===e.code){const e=p?`searched for local subcommand relative to directory '${p}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",n=`'${u}' 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(n)}if("EACCES"===e.code)throw new Error(`'${u}' not executable`);if(d){const t=new h(1,"commander.executeSubCommandAsync","(error)");t.nestedError=e,d(t)}else a.exit(1)})),this.runningCommand=c}_dispatchSubcommand(t,e,n){const i=this._findCommand(t);let r;return i||this.help({error:!0}),r=this._chainOrCallSubCommandHook(r,i,"preSubcommand"),r=this._chainOrCall(r,(()=>{if(!i._executableHandler)return i._parseCommand(e,n);this._executeSubCommand(i,e.concat(n))})),r}_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,n)=>{let i=e;if(null!==e&&t.parseArg)try{i=t.parseArg(e,n)}catch(n){if("commander.invalidArgument"===n.code){const i=`error: command-argument value '${e}' is invalid for argument '${t.name()}'. ${n.message}`;this.error(i,{exitCode:n.exitCode,code:n.code})}throw n}return i};this._checkNumberOfArguments();const e=[];this._args.forEach(((n,i)=>{let r=n.defaultValue;n.variadic?i<this.args.length?(r=this.args.slice(i),n.parseArg&&(r=r.reduce(((e,i)=>t(n,i,e)),n.defaultValue))):void 0===r&&(r=[]):i<this.args.length&&(r=this.args[i],n.parseArg&&(r=t(n,r,n.defaultValue))),e[i]=r})),this.processedArgs=e}_chainOrCall(t,e){return t&&t.then&&"function"==typeof t.then?t.then((()=>e())):e()}_chainOrCallHooks(t,e){let n=t;const i=[];return b(this).reverse().filter((t=>void 0!==t._lifeCycleHooks[e])).forEach((t=>{t._lifeCycleHooks[e].forEach((e=>{i.push({hookedCommand:t,callback:e})}))})),"postAction"===e&&i.reverse(),i.forEach((t=>{n=this._chainOrCall(n,(()=>t.callback(t.hookedCommand,this)))})),n}_chainOrCallSubCommandHook(t,e,n){let i=t;return void 0!==this._lifeCycleHooks[n]&&this._lifeCycleHooks[n].forEach((t=>{i=this._chainOrCall(i,(()=>t(this,e)))})),i}_parseCommand(t,e){const n=this.parseOptions(e);if(this._parseOptionsEnv(),this._parseOptionsImplied(),t=t.concat(n.operands),e=n.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 _(this,e),this._dispatchSubcommand(this._defaultCommandName,t,e);!this.commands.length||0!==this.args.length||this._actionHandler||this._defaultCommandName||this.help({error:!0}),_(this,n.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();const i=()=>{n.unknown.length>0&&this.unknownOption(n.unknown[0])},r=`command:${this.name()}`;if(this._actionHandler){let n;return i(),this._processArguments(),n=this._chainOrCallHooks(n,"preAction"),n=this._chainOrCall(n,(()=>this._actionHandler(this.processedArgs))),this.parent&&(n=this._chainOrCall(n,(()=>{this.parent.emit(r,t,e)}))),n=this._chainOrCallHooks(n,"postAction"),n}if(this.parent&&this.parent.listenerCount(r))i(),this._processArguments(),this.parent.emit(r,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():(i(),this._processArguments())}else this.commands.length?(i(),this.help({error:!0})):(i(),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)}));t.filter((t=>t.conflictsWith.length>0)).forEach((e=>{const n=t.find((t=>e.conflictsWith.includes(t.attributeName())));n&&this._conflictingOption(e,n)}))}_checkForConflictingOptions(){for(let t=this;t;t=t.parent)t._checkForConflictingLocalOptions()}parseOptions(t){const e=[],n=[];let i=e;const r=t.slice();function o(t){return t.length>1&&"-"===t[0]}let s=null;for(;r.length;){const t=r.shift();if("--"===t){i===n&&i.push(t),i.push(...r);break}if(!s||o(t)){if(s=null,o(t)){const e=this._findOption(t);if(e){if(e.required){const t=r.shift();void 0===t&&this.optionMissingArgument(e),this.emit(`option:${e.name()}`,t)}else if(e.optional){let t=null;r.length>0&&!o(r[0])&&(t=r.shift()),this.emit(`option:${e.name()}`,t)}else this.emit(`option:${e.name()}`);s=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()}`),r.unshift(`-${t.slice(2)}`));continue}}if(/^--[^=]+=/.test(t)){const e=t.indexOf("="),n=this._findOption(t.slice(0,e));if(n&&(n.required||n.optional)){this.emit(`option:${n.name()}`,t.slice(e+1));continue}}if(o(t)&&(i=n),(this._enablePositionalOptions||this._passThroughOptions)&&0===e.length&&0===n.length){if(this._findCommand(t)){e.push(t),r.length>0&&n.push(...r);break}if(t===this._helpCommandName&&this._hasImplicitHelpCommand()){e.push(t),r.length>0&&e.push(...r);break}if(this._defaultCommandName){n.push(t),r.length>0&&n.push(...r);break}}if(this._passThroughOptions){i.push(t),r.length>0&&i.push(...r);break}i.push(t)}else this.emit(`option:${s.name()}`,t)}return{operands:e,unknown:n}}opts(){if(this._storeOptionsAsProperties){const t={},e=this.options.length;for(let n=0;n<e;n++){const e=this.options[n].attributeName();t[e]=e===this._versionOptionName?this._version:this[e]}return t}return this._optionValues}optsWithGlobals(){return b(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 n=e||{},i=n.exitCode||1,r=n.code||"commander.error";this._exit(i,r,t)}_parseOptionsEnv(){this.options.forEach((t=>{if(t.envVar&&t.envVar in a.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()}`,a.env[t.envVar]):this.emit(`optionEnv:${t.name()}`))}}))}_parseOptionsImplied(){const t=new m(this.options),e=t=>void 0!==this.getOptionValue(t)&&!["default","implied"].includes(this.getOptionValueSource(t));this.options.filter((n=>void 0!==n.implied&&e(n.attributeName())&&t.valueFromOption(this.getOptionValue(n.attributeName()),n))).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 n=t=>{const e=t.attributeName(),n=this.getOptionValue(e),i=this.options.find((t=>t.negate&&e===t.attributeName())),r=this.options.find((t=>!t.negate&&e===t.attributeName()));return i&&(void 0===i.presetArg&&!1===n||void 0!==i.presetArg&&n===i.presetArg)?i:r||t},i=t=>{const e=n(t),i=e.attributeName();return"env"===this.getOptionValueSource(i)?`environment variable '${e.envVar}'`:`option '${e.flags}'`},r=`error: ${i(t)} cannot be used with ${i(e)}`;this.error(r,{code:"commander.conflictingOption"})}unknownOption(t){if(this._allowUnknownOption)return;let e="";if(t.startsWith("--")&&this._showSuggestionAfterError){let n=[],i=this;do{const t=i.createHelp().visibleOptions(i).filter((t=>t.long)).map((t=>t.long));n=n.concat(t),i=i.parent}while(i&&!i._enablePositionalOptions);e=g(t,n)}const n=`error: unknown option '${t}'${e}`;this.error(n,{code:"commander.unknownOption"})}_excessArguments(t){if(this._allowExcessArguments)return;const e=this._args.length,n=1===e?"":"s",i=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${e} argument${n} but got ${t.length}.`;this.error(i,{code:"commander.excessArguments"})}unknownCommand(){const t=this.args[0];let e="";if(this._showSuggestionAfterError){const n=[];this.createHelp().visibleCommands(this).forEach((t=>{n.push(t.name()),t.alias()&&n.push(t.alias())})),e=g(t,n)}const n=`error: unknown command '${t}'${e}`;this.error(n,{code:"commander.unknownCommand"})}version(t,e,n){if(void 0===t)return this._version;this._version=t,e=e||"-V, --version",n=n||"output the version number";const i=this.createOption(e,n);return this._versionOptionName=i.attributeName(),this.options.push(i),this.on("option:"+i.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=>c(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=o.basename(t,o.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 n;return n=e.error?t=>this._outputConfiguration.writeErr(t):t=>this._outputConfiguration.writeOut(t),e.write=t.write||n,e.command=this,e}outputHelp(t){let e;"function"==typeof t&&(e=t,t=void 0);const n=this._getHelpContext(t);b(this).reverse().forEach((t=>t.emit("beforeAllHelp",n))),this.emit("beforeHelp",n);let i=this.helpInformation(n);if(e&&(i=e(i),"string"!=typeof i&&!Buffer.isBuffer(i)))throw new Error("outputHelp callback must return a string or a Buffer");n.write(i),this.emit(this._helpLongFlag),this.emit("afterHelp",n),b(this).forEach((t=>t.emit("afterAllHelp",n)))}helpOption(t,e){if("boolean"==typeof t)return this._hasHelpOption=t,this;this._helpFlags=t||this._helpFlags,this._helpDescription=e||this._helpDescription;const n=d(this._helpFlags);return this._helpShortFlag=n.shortFlag,this._helpLongFlag=n.longFlag,this}help(t){this.outputHelp(t);let e=a.exitCode||0;0===e&&t&&"function"!=typeof t&&t.error&&(e=1),this._exit(e,"commander.help","(outputHelp)")}addHelpText(t,e){const n=["beforeAll","before","after","afterAll"];if(!n.includes(t))throw new Error(`Unexpected value for position to addHelpText.\nExpecting one of '${n.join("', '")}'`);const i=`${t}Help`;return this.on(i,(t=>{let n;n="function"==typeof e?e({error:t.error,command:t.command}):e,n&&t.write(`${n}\n`)})),this}}function _(t,e){t._hasHelpOption&&e.find((e=>e===t._helpLongFlag||e===t._helpShortFlag))&&(t.outputHelp(),t._exit(0,"commander.helpDisplayed","(outputHelp)"))}function v(t){return t.map((t=>{if(!t.startsWith("--inspect"))return t;let e,n,i="127.0.0.1",r="9229";return null!==(n=t.match(/^(--inspect(-brk)?)$/))?e=n[1]:null!==(n=t.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))?(e=n[1],/^\d+$/.test(n[3])?r=n[3]:i=n[3]):null!==(n=t.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))&&(e=n[1],i=n[3],r=n[4]),e&&"0"!==r?`${e}=${i}:${parseInt(r)+1}`:t}))}function b(t){const e=[];for(let n=t;n;n=n.parent)e.push(n);return e}e.Command=f},884:(t,e)=>{class n extends Error{constructor(t,e,n){super(n),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=e,this.exitCode=t,this.nestedError=void 0}}e.CommanderError=n,e.InvalidArgumentError=class extends n{constructor(t){super(1,"commander.invalidArgument",t),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}}},538:(t,e,n)=>{const{humanReadableArgName:i}=n(644);e.Help=class{constructor(){this.helpWidth=void 0,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}visibleCommands(t){const e=t.commands.filter((t=>!t._hidden));if(t._hasImplicitHelpCommand()){const[,n,i]=t._helpCommandnameAndArgs.match(/([^ ]+) *(.*)/),r=t.createCommand(n).helpOption(!1);r.description(t._helpCommandDescription),i&&r.arguments(i),e.push(r)}return this.sortSubcommands&&e.sort(((t,e)=>t.name().localeCompare(e.name()))),e}compareOptions(t,e){const n=t=>t.short?t.short.replace(/^-/,""):t.long.replace(/^--/,"");return n(t).localeCompare(n(e))}visibleOptions(t){const e=t.options.filter((t=>!t.hidden)),n=t._hasHelpOption&&t._helpShortFlag&&!t._findOption(t._helpShortFlag),i=t._hasHelpOption&&!t._findOption(t._helpLongFlag);if(n||i){let r;r=n?i?t.createOption(t._helpFlags,t._helpDescription):t.createOption(t._helpShortFlag,t._helpDescription):t.createOption(t._helpLongFlag,t._helpDescription),e.push(r)}return this.sortOptions&&e.sort(this.compareOptions),e}visibleGlobalOptions(t){if(!this.showGlobalOptions)return[];const e=[];for(let n=t.parent;n;n=n.parent){const t=n.options.filter((t=>!t.hidden));e.push(...t)}return this.sortOptions&&e.sort(this.compareOptions),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=>i(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,n)=>Math.max(t,e.subcommandTerm(n).length)),0)}longestOptionTermLength(t,e){return e.visibleOptions(t).reduce(((t,n)=>Math.max(t,e.optionTerm(n).length)),0)}longestGlobalOptionTermLength(t,e){return e.visibleGlobalOptions(t).reduce(((t,n)=>Math.max(t,e.optionTerm(n).length)),0)}longestArgumentTermLength(t,e){return e.visibleArguments(t).reduce(((t,n)=>Math.max(t,e.argumentTerm(n).length)),0)}commandUsage(t){let e=t._name;t._aliases[0]&&(e=e+"|"+t._aliases[0]);let n="";for(let e=t.parent;e;e=e.parent)n=e.name()+" "+n;return n+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 n=`(${e.join(", ")})`;return t.description?`${t.description} ${n}`:n}return t.description}formatHelp(t,e){const n=e.padWidth(t,e),i=e.helpWidth||80;function r(t,r){if(r){const o=`${t.padEnd(n+2)}${r}`;return e.wrap(o,i-2,n+2)}return t}function o(t){return t.join("\n").replace(/^/gm," ".repeat(2))}let s=[`Usage: ${e.commandUsage(t)}`,""];const a=e.commandDescription(t);a.length>0&&(s=s.concat([e.wrap(a,i,0),""]));const l=e.visibleArguments(t).map((t=>r(e.argumentTerm(t),e.argumentDescription(t))));l.length>0&&(s=s.concat(["Arguments:",o(l),""]));const c=e.visibleOptions(t).map((t=>r(e.optionTerm(t),e.optionDescription(t))));if(c.length>0&&(s=s.concat(["Options:",o(c),""])),this.showGlobalOptions){const n=e.visibleGlobalOptions(t).map((t=>r(e.optionTerm(t),e.optionDescription(t))));n.length>0&&(s=s.concat(["Global Options:",o(n),""]))}const h=e.visibleCommands(t).map((t=>r(e.subcommandTerm(t),e.subcommandDescription(t))));return h.length>0&&(s=s.concat(["Commands:",o(h),""])),s.join("\n")}padWidth(t,e){return Math.max(e.longestOptionTermLength(t,e),e.longestGlobalOptionTermLength(t,e),e.longestSubcommandTermLength(t,e),e.longestArgumentTermLength(t,e))}wrap(t,e,n,i=40){const r=new RegExp("[\\n][ \\f\\t\\v   -    \ufeff]+");if(t.match(r))return t;const o=e-n;if(o<i)return t;const s=t.slice(0,n),a=t.slice(n).replace("\r\n","\n"),l=" ".repeat(n),c="\\s​",h=new RegExp(`\n|.{1,${o-1}}([${c}]|$)|[^${c}]+?([${c}]|$)`,"g");return s+(a.match(h)||[]).map(((t,e)=>"\n"===t?"":(e>0?l:"")+t.trimEnd())).join("\n")}}},267:(t,e,n)=>{const{InvalidArgumentError:i}=n(884);function r(t){let e,n;const i=t.split(/[ |,]+/);return i.length>1&&!/^[[<]/.test(i[1])&&(e=i.shift()),n=i.shift(),!e&&/^-[^-]$/.test(n)&&(e=n,n=void 0),{shortFlag:e,longFlag:n}}e.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 n=r(t);this.short=n.shortFlag,this.long=n.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 i(`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}},e.splitOptionFlags=r,e.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 n=e.attributeName();if(!this.dualOptions.has(n))return!0;const i=this.negativeOptions.get(n).presetArg,r=void 0!==i&&i;return e.negate===(r===t)}}},359:(t,e)=>{e.suggestSimilar=function(t,e){if(!e||0===e.length)return"";e=Array.from(new Set(e));const n=t.startsWith("--");n&&(t=t.slice(2),e=e.map((t=>t.slice(2))));let i=[],r=3;return e.forEach((e=>{if(e.length<=1)return;const n=function(t,e){if(Math.abs(t.length-e.length)>3)return Math.max(t.length,e.length);const n=[];for(let e=0;e<=t.length;e++)n[e]=[e];for(let t=0;t<=e.length;t++)n[0][t]=t;for(let i=1;i<=e.length;i++)for(let r=1;r<=t.length;r++){let o=1;o=t[r-1]===e[i-1]?0:1,n[r][i]=Math.min(n[r-1][i]+1,n[r][i-1]+1,n[r-1][i-1]+o),r>1&&i>1&&t[r-1]===e[i-2]&&t[r-2]===e[i-1]&&(n[r][i]=Math.min(n[r][i],n[r-2][i-2]+1))}return n[t.length][e.length]}(t,e),o=Math.max(t.length,e.length);(o-n)/o>.4&&(n<r?(r=n,i=[e]):n===r&&i.push(e))})),i.sort(((t,e)=>t.localeCompare(e))),n&&(i=i.map((t=>`--${t}`))),i.length>1?`\n(Did you mean one of ${i.join(", ")}?)`:1===i.length?`\n(Did you mean ${i[0]}?)`:""}},499:function(t,e,n){"use strict";var i=this&&this.__createBinding||(Object.create?function(t,e,n,i){void 0===i&&(i=n);var r=Object.getOwnPropertyDescriptor(e,n);r&&!("get"in r?!e.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,i,r)}:function(t,e,n,i){void 0===i&&(i=n),t[i]=e[n]}),r=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),o=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)"default"!==n&&Object.prototype.hasOwnProperty.call(t,n)&&i(e,t,n);return r(e,t),e},s=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))((function(r,o){function s(t){try{l(i.next(t))}catch(t){o(t)}}function a(t){try{l(i.throw(t))}catch(t){o(t)}}function l(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}l((i=i.apply(t,e||[])).next())}))},a=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],i=0}finally{n=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.translateIntoLanguage=e.getTypeStringFromArray=e.convertToObject=e.convertToArray=e.writeToFile=e.getJSON=e.createDir=e.exists=e.getDefaultLanguage=void 0;var l=o(n(147));e.getDefaultLanguage=function(t){return s(void 0,void 0,Promise,(function(){var e,n,i,r,o,s,c,h,u;return a(this,(function(a){switch(a.label){case 0:n="./src/app/app.module.ts",i="./src/app/app.component.ts",a.label=1;case 1:return a.trys.push([1,4,,10]),[4,l.promises.access(n)];case 2:return a.sent(),o=(r=/DfxTranslateModule\.setup\((.+)\)\s*,/).exec,[4,l.promises.readFile(n,"utf-8")];case 3:return e=o.apply(r,[a.sent()]),[3,10];case 4:a.sent(),t&&console.log("dfx-translate >> getDefaultLanguage: app.module.ts not found - trying app.component.ts"),a.label=5;case 5:return a.trys.push([5,8,,9]),[4,l.promises.access(i)];case 6:return a.sent(),c=(s=/provideDfxTranslate\((.+)\)\s*,/).exec,[4,l.promises.readFile(i,"utf-8")];case 7:return e=c.apply(s,[a.sent()]),[3,9];case 8:throw a.sent(),console.log("dfx-translate >> getDefaultLanguage: Neither app.module.ts or app.component.ts found - cancelling"),Error("Neither app.module.ts or app.component.ts found");case 9:return[3,10];case 10:if(!e)throw console.log("dfx-translate >> getDefaultLanguage: Unable to extract default language out of json"),new Error("Unable to extract JSON string from file");if(h=e[1].replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g,'"$2": ').replace(/'/g,'"'),!(u=JSON.parse(h).defaultLanguage))throw console.log("dfx-translate >> getDefaultLanguage: Unable to extract default language out of json"),new Error("Unable to extract JSON string from file");return[2,u]}}))}))};e.exists=function(t){return l.existsSync(t)};e.createDir=function(t){return l.mkdirSync(t,{recursive:!0})};e.getJSON=function(t){return s(void 0,void 0,Promise,(function(){var e,n;return a(this,(function(i){switch(i.label){case 0:return n=(e=JSON).parse,[4,l.promises.readFile(t,"utf-8")];case 1:return[2,n.apply(e,[i.sent()])]}}))}))};e.writeToFile=function(t,e){return s(void 0,void 0,Promise,(function(){return a(this,(function(n){return[2,l.promises.writeFile(t,e)]}))}))};e.convertToArray=function(t){return Object.keys(t).map((function(e){return{key:e,value:t[e]}}))};e.convertToObject=function(t){return t.reduce((function(t,e){return t[e.key]=e.value,t}),{})};e.getTypeStringFromArray=function(t){return"export type translationKeys = string | undefined | null | ".concat(t.map((function(t){return"'".concat(t.key,"'")})).join(" | "),";")};e.translateIntoLanguage=function(t,n,i,r,o,h,u){return s(void 0,void 0,Promise,(function(){var s,p,d,m,g,f,_,v,b,O,w,y,C,x,A,E;return a(this,(function(a){switch(a.label){case 0:return s="".concat(o).concat(i,".json"),(0,e.exists)(s)?[4,(0,e.getJSON)(s)]:[3,2];case 1:return d=a.sent(),[3,3];case 2:d=void 0,a.label=3;case 3:if(p=d,u&&console.log('dfx-translate >> manual translation lookup path: "'.concat(s,'"')),void 0===p)console.log('dfx-translate >> no manual translation found for: "'.concat(i,'"'));else for(m=0,g=r;m<g.length;m++)f=g[m],null!=p[f.key]&&(u&&console.log('dfx-translate >> found manual translation for "'.concat(f.key,'"')),r.splice(r.indexOf(f),1));return _="./node_modules/dfx-translate/translation/translation_cache_"+i+".json",(0,e.exists)(_)&&h?[4,(0,e.getJSON)(_)]:[3,5];case 4:return b=a.sent(),[3,6];case 5:b=void 0,a.label=6;case 6:v=b,u&&console.log('dfx-translate >> cache lookup path: "'.concat(_,'"')),void 0===v&&console.log('dfx-translate >> no local cache found for "'.concat(i,'"')),O=[],w=0,y=r,a.label=7;case 7:return w<y.length?(C=y[w],(x=v?v[C.value]:void 0)?(console.log('Translating "'.concat(C.value,'" from cache to ').concat(i,': "').concat(x,'"')),O.push({key:C.key,value:x}),[3,11]):[3,8]):[3,12];case 8:return a.trys.push([8,10,,11]),[4,c(t,n,i,C)];case 9:return A=a.sent(),v&&(v[C.value]=A.value),O.push(A),[3,11];case 10:return E=a.sent(),console.log(E),console.log('dfx-translate >> error during fetch for "'.concat(C.value,'" to ').concat(i)),[3,11];case 11:return w++,[3,7];case 12:return v&&l.promises.writeFile(_,JSON.stringify(v)).then((function(){console.log('dfx-translate >> cache saved in "'.concat(_,'"'))})),[2,O]}}))}))};var c=function(t,e,n,i){return s(void 0,void 0,Promise,(function(){var r,o,s,l;return a(this,(function(a){switch(a.label){case 0:return r=JSON.stringify({format:"text",q:i.value,target:n,source:e}),o=new AbortController,setTimeout((function(){return o.abort()}),5e3),[4,fetch("".concat(t,"/translate"),{signal:o.signal,method:"POST",headers:{"Content-Type":"application/json; charset=utf-8"},body:r})];case 1:if(!(s=a.sent()).ok)throw new Error("Fetch failed with status code ".concat(s.status));return[4,s.json()];case 2:return l=a.sent(),console.log('Translating "'.concat(i.value,'" to ').concat(n,': "').concat(l.translatedText,'"')),[2,{key:i.key,value:l.translatedText}]}}))}))}},526:function(t,e,n){"use strict";var i=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))((function(r,o){function s(t){try{l(i.next(t))}catch(t){o(t)}}function a(t){try{l(i.throw(t))}catch(t){o(t)}}function l(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}l((i=i.apply(t,e||[])).next())}))},r=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],i=0}finally{n=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}};Object.defineProperty(e,"__esModule",{value:!0});var o=n(499),s=n(504),a="./node_modules/dfx-translate/lib/translationKeys.d.ts",l="./src/assets/i18n/";s.program.name("translate-cli").description("dfx-translate development tools and helper scripts").version("0.0.2"),s.program.command("generateTypes").description("Generates type-definitions for your default language").argument("[sourceLanguagePath]","Path to source language file").option("--log","Log more information").option("--dir <path>","Path to language files folder",l).action((function(t,e){return i(void 0,void 0,void 0,(function(){var n,i;return r(this,(function(r){switch(r.label){case 0:return null==t?[3,1]:(n=t,[3,3]);case 1:return i=e.dir,[4,(0,o.getDefaultLanguage)(e.log)];case 2:n=i+r.sent()+".json",r.label=3;case 3:return t=n,e.log&&console.log('dfx-translate >> source path: "'.concat(t,'"')),(0,o.getJSON)(t).then((function(t){return(0,o.convertToArray)(t)})).then((function(t){return(0,o.getTypeStringFromArray)(t)})).then((function(t){return e.log&&console.log('dfx-translate >> new types: "'.concat(t,'"')),(0,o.writeToFile)(a,t)})).then((function(){return console.log("dfx-translate >> Successfully saved translation types")})).catch((function(t){return console.error("Error",t)})),[2]}}))}))})),s.program.command("resetTypes").description("Resets type-definitions").action((function(){return i(void 0,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,(0,o.writeToFile)(a,"export type translationKeys = string | undefined | null;")];case 1:return t.sent(),console.log("dfx-translate >> Types resetted."),[2]}}))}))})),s.program.command("createDir").description("Creates the default directory for all language files").option("--log","Log more information").action((function(t){(0,o.exists)(l)?t.log&&console.log("dfx-translate >> Language directory already exists"):((0,o.createDir)(l),console.log("dfx-translate >> Created default language assets directory."))})),s.program.command("autoTranslate").description("Translates a file into another language").argument("<url>","LibreTranslate Instance URL").argument("<targetLanguageCode>","Wanted language").option("--log","Log more information").option("--disable-cache","Disables cache",!1).option("--source <path>","Path to source language file").option("--dir <path>","Path to language files folder",l).action((function(t,e,n){return i(void 0,void 0,void 0,(function(){var i,s,a,l,c,h;return r(this,(function(r){switch(r.label){case 0:return null===(c=n.source)||void 0===c?[3,1]:(s=c,[3,3]);case 1:return a=n.dir,[4,(0,o.getDefaultLanguage)(n.log)];case 2:s=a+r.sent()+".json",r.label=3;case 3:return(l=null===(h=(i=s).split("/").pop())||void 0===h?void 0:h.split(".").at(0))?((0,o.getJSON)(i).then((function(t){return(0,o.convertToArray)(t)})).then((function(i){return(0,o.translateIntoLanguage)(t,l,e,i,n.dir,n.disableCache,n.log)})).then((function(t){return(0,o.convertToObject)(t)})).then((function(t){return(0,o.writeToFile)("".concat(n.dir).concat(e,"_auto.json"),JSON.stringify(t))})).then((function(){return console.log("dfx-translate >> translation successfully saved")})).catch((function(t){return console.error("Error",t)})),[2]):(console.log("dfx-translate >> ERROR: Could not extract source language"),n.log&&console.log('dfx-translate >> path: "'.concat(i,'"')),[2])}}))}))})),s.program.parse()},81:t=>{"use strict";t.exports=require("child_process")},361:t=>{"use strict";t.exports=require("events")},147:t=>{"use strict";t.exports=require("fs")},17:t=>{"use strict";t.exports=require("path")},282:t=>{"use strict";t.exports=require("process")}},e={};(function n(i){var r=e[i];if(void 0!==r)return r.exports;var o=e[i]={exports:{}};return t[i].call(o.exports,o,o.exports,n),o.exports})(526)})();
{
"name": "dfx-translate",
"version": "1.6.0",
"version": "1.6.1",
"private": false,

@@ -5,0 +5,0 @@ "license": "MIT",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc