@wallabyjs/cli 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +2 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -51,7 +51,7 @@ tell application "System Events" to get value of property list item "CFBundleNam
|
|
|
51
51
|
`)}),i&&(s=i(s)||s),console.log(s.map(u=>u.title?`${u.title}:
|
|
52
52
|
${u.body}`:u.body).join(`
|
|
53
53
|
|
|
54
|
-
`))}outputVersion(){let{name:t}=this.cli,{versionNumber:r}=this.cli.globalCommand;r&&console.log(`${t}/${r} ${Nu}`)}checkRequiredArgs(){let t=this.args.filter(r=>r.required).length;if(this.cli.args.length<t)throw new st(`missing required args for command \`${this.rawName}\``)}checkUnknownOptions(){let{options:t,globalCommand:r}=this.cli;if(!this.config.allowUnknownOptions){for(let n of Object.keys(t))if(n!=="--"&&!this.hasOption(n)&&!r.hasOption(n))throw new st(`Unknown option \`${n.length>1?`--${n}`:`-${n}`}\``)}}checkOptionValue(){let{options:t,globalCommand:r}=this.cli,n=[...r.options,...this.options];for(let o of n){let i=t[o.name.split(".")[0]];if(o.required){let s=n.some(a=>a.negated&&a.names.includes(o.name));if(i===!0||i===!1&&!s)throw new st(`option \`${o.rawName}\` value is missing`)}}}},Ot=class extends Dt{constructor(t){super("@@global@@","",{},t)}},Nt=Object.assign,nr=class extends Ui.EventEmitter{constructor(t=""){super(),this.name=t,this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.globalCommand=new Ot(this),this.globalCommand.usage("<command> [options]")}usage(t){return this.globalCommand.usage(t),this}command(t,r,n){let o=new Dt(t,r||"",n,this);return o.globalCommand=this.globalCommand,this.commands.push(o),o}option(t,r,n){return this.globalCommand.option(t,r,n),this}help(t){return this.globalCommand.option("-h, --help","Display this message"),this.globalCommand.helpCallback=t,this.showHelpOnExit=!0,this}version(t,r="-v, --version"){return this.globalCommand.version(t,r),this.showVersionOnExit=!0,this}example(t){return this.globalCommand.example(t),this}outputHelp(){this.matchedCommand?this.matchedCommand.outputHelp():this.globalCommand.outputHelp()}outputVersion(){this.globalCommand.outputVersion()}setParsedInfo({args:t,options:r},n,o){return this.args=t,this.options=r,n&&(this.matchedCommand=n),o&&(this.matchedCommandName=o),this}unsetMatchedCommand(){this.matchedCommand=void 0,this.matchedCommandName=void 0}parse(t=bu,{run:r=!0}={}){this.rawArgs=t,this.name||(this.name=t[1]?Cu(t[1]):"cli");let n=!0;for(let i of this.commands){let s=this.mri(t.slice(2),i),a=s.args[0];if(i.isMatched(a)){n=!1;let c=Nt(Nt({},s),{args:s.args.slice(1)});this.setParsedInfo(c,i,a),this.emit(`command:${a}`,i)}}if(n){for(let i of this.commands)if(i.name===""){n=!1;let s=this.mri(t.slice(2),i);this.setParsedInfo(s,i),this.emit("command:!",i)}}if(n){let i=this.mri(t.slice(2));this.setParsedInfo(i)}this.options.help&&this.showHelpOnExit&&(this.outputHelp(),r=!1,this.unsetMatchedCommand()),this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null&&(this.outputVersion(),r=!1,this.unsetMatchedCommand());let o={args:this.args,options:this.options};return r&&this.runMatchedCommand(),!this.matchedCommand&&this.args[0]&&this.emit("command:*"),o}mri(t,r){let n=[...this.globalCommand.options,...r?r.options:[]],o=Eu(n),i=[],s=t.indexOf("--");s>-1&&(i=t.slice(s+1),t=t.slice(0,s));let a=gu(t,o);a=Object.keys(a).reduce((h,p)=>Nt(Nt({},h),{[$i(p)]:a[p]}),{_:[]});let c=a._,u={"--":i},l=r&&r.config.ignoreOptionDefaultValue?r.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,d=Object.create(null);for(let h of n){if(!l&&h.config.default!==void 0)for(let p of h.names)u[p]=h.config.default;Array.isArray(h.config.type)&&d[h.name]===void 0&&(d[h.name]=Object.create(null),d[h.name].shouldTransform=!0,d[h.name].transformFunction=h.config.type[0])}for(let h of Object.keys(a))if(h!=="_"){let p=h.split(".");xu(u,p,a[h]),vu(u,d)}return{args:c,options:u}}runMatchedCommand(){let{args:t,options:r,matchedCommand:n}=this;if(!n||!n.commandAction)return;n.checkUnknownOptions(),n.checkOptionValue(),n.checkRequiredArgs();let o=[];return n.args.forEach((i,s)=>{i.variadic?o.push(t.slice(s)):o.push(t[s])}),o.push(r),n.commandAction.apply(this,o)}},Mi=(e="")=>new nr(e);var _=X(Vi()),zs=X(Ao()),Zs=X(Bo())
|
|
54
|
+
`))}outputVersion(){let{name:t}=this.cli,{versionNumber:r}=this.cli.globalCommand;r&&console.log(`${t}/${r} ${Nu}`)}checkRequiredArgs(){let t=this.args.filter(r=>r.required).length;if(this.cli.args.length<t)throw new st(`missing required args for command \`${this.rawName}\``)}checkUnknownOptions(){let{options:t,globalCommand:r}=this.cli;if(!this.config.allowUnknownOptions){for(let n of Object.keys(t))if(n!=="--"&&!this.hasOption(n)&&!r.hasOption(n))throw new st(`Unknown option \`${n.length>1?`--${n}`:`-${n}`}\``)}}checkOptionValue(){let{options:t,globalCommand:r}=this.cli,n=[...r.options,...this.options];for(let o of n){let i=t[o.name.split(".")[0]];if(o.required){let s=n.some(a=>a.negated&&a.names.includes(o.name));if(i===!0||i===!1&&!s)throw new st(`option \`${o.rawName}\` value is missing`)}}}},Ot=class extends Dt{constructor(t){super("@@global@@","",{},t)}},Nt=Object.assign,nr=class extends Ui.EventEmitter{constructor(t=""){super(),this.name=t,this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.globalCommand=new Ot(this),this.globalCommand.usage("<command> [options]")}usage(t){return this.globalCommand.usage(t),this}command(t,r,n){let o=new Dt(t,r||"",n,this);return o.globalCommand=this.globalCommand,this.commands.push(o),o}option(t,r,n){return this.globalCommand.option(t,r,n),this}help(t){return this.globalCommand.option("-h, --help","Display this message"),this.globalCommand.helpCallback=t,this.showHelpOnExit=!0,this}version(t,r="-v, --version"){return this.globalCommand.version(t,r),this.showVersionOnExit=!0,this}example(t){return this.globalCommand.example(t),this}outputHelp(){this.matchedCommand?this.matchedCommand.outputHelp():this.globalCommand.outputHelp()}outputVersion(){this.globalCommand.outputVersion()}setParsedInfo({args:t,options:r},n,o){return this.args=t,this.options=r,n&&(this.matchedCommand=n),o&&(this.matchedCommandName=o),this}unsetMatchedCommand(){this.matchedCommand=void 0,this.matchedCommandName=void 0}parse(t=bu,{run:r=!0}={}){this.rawArgs=t,this.name||(this.name=t[1]?Cu(t[1]):"cli");let n=!0;for(let i of this.commands){let s=this.mri(t.slice(2),i),a=s.args[0];if(i.isMatched(a)){n=!1;let c=Nt(Nt({},s),{args:s.args.slice(1)});this.setParsedInfo(c,i,a),this.emit(`command:${a}`,i)}}if(n){for(let i of this.commands)if(i.name===""){n=!1;let s=this.mri(t.slice(2),i);this.setParsedInfo(s,i),this.emit("command:!",i)}}if(n){let i=this.mri(t.slice(2));this.setParsedInfo(i)}this.options.help&&this.showHelpOnExit&&(this.outputHelp(),r=!1,this.unsetMatchedCommand()),this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null&&(this.outputVersion(),r=!1,this.unsetMatchedCommand());let o={args:this.args,options:this.options};return r&&this.runMatchedCommand(),!this.matchedCommand&&this.args[0]&&this.emit("command:*"),o}mri(t,r){let n=[...this.globalCommand.options,...r?r.options:[]],o=Eu(n),i=[],s=t.indexOf("--");s>-1&&(i=t.slice(s+1),t=t.slice(0,s));let a=gu(t,o);a=Object.keys(a).reduce((h,p)=>Nt(Nt({},h),{[$i(p)]:a[p]}),{_:[]});let c=a._,u={"--":i},l=r&&r.config.ignoreOptionDefaultValue?r.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,d=Object.create(null);for(let h of n){if(!l&&h.config.default!==void 0)for(let p of h.names)u[p]=h.config.default;Array.isArray(h.config.type)&&d[h.name]===void 0&&(d[h.name]=Object.create(null),d[h.name].shouldTransform=!0,d[h.name].transformFunction=h.config.type[0])}for(let h of Object.keys(a))if(h!=="_"){let p=h.split(".");xu(u,p,a[h]),vu(u,d)}return{args:c,options:u}}runMatchedCommand(){let{args:t,options:r,matchedCommand:n}=this;if(!n||!n.commandAction)return;n.checkUnknownOptions(),n.checkOptionValue(),n.checkRequiredArgs();let o=[];return n.args.forEach((i,s)=>{i.variadic?o.push(t.slice(s)):o.push(t[s])}),o.push(r),n.commandAction.apply(this,o)}},Mi=(e="")=>new nr(e);var _=X(Vi()),zs=X(Ao()),Zs=X(Bo()),Nf=!1,Rt="https",js=!0,Xs=__dirname,Df=(0,G.join)(Xs,"bin"),Bt=Mi("wallaby"),Ks=require((0,G.join)(Xs,"package.json")).version,Br=(0,G.join)((0,Gs.homedir)(),".wallaby"),Te=(0,G.join)(Br,"cli"),Pr=(0,G.join)(Te,"downloads"),Js=(0,G.join)(Br,"key.lic"),Ys=(0,G.join)(Te,"wallaby.json"),qr=(0,G.join)(Te,"core.json"),Ms=()=>Rt+"://update.wallabyjs.com/",Of=10*60*1e3,Pt,Rr=0,ft,lt;Bt.command("[root]","start wallaby").option("--doNotOpen","do not open browser on startup").option("--smart","use smart (lazy) start to run tests of modified test files only: https://wallabyjs.com/docs/intro/smart-start.html").option("--config <path>","use config file: https://wallabyjs.com/docs/config/overview.html").option("--update","force Wallaby Core update to the latest version before starting").option("--useHttp","use http instead of https for downloading Wallaby dependencies").option("--useNonStrictSSL","do not use strict SSL for downloading Wallaby dependencies").option("--suppressExpirationNotifications","do not notify about license expiration").action(async(e,t)=>{kf(t),t.useHttp&&(Rt="http"),t.useNonStrictSSL&&(js=!1),Y.default.ensureDirSync(Br),Y.default.ensureDirSync(Te),await ta(t)});Bt.help();Bt.version(Ks);Bt.parse();function Qs(e){clearTimeout(Pt),Pt=setTimeout(async()=>{await ea(e)},Of)}async function ea(e){try{lt=await oa(e),lt?.updated&&(ft?.process.send({type:"coreUpdated",version:qt(lt.path)}),Rr=0)}catch{Rr++}finally{Rr<=3&&Qs(lt?.path||e)}}async function ta(e){clearTimeout(Pt),ft?.process.removeAllListeners(),ft?.process.kill();let{path:t,type:r}=lt||await Lf({forceUpdate:e.update});ft=If(t,e),r==="dist"&&Qs(ft.path)}function If(e,t){let r=["--cli=true","--lkp="+Js];t.smart&&r.push("--smartStart=true"),t.config&&r.push("--configPath="+(0,G.resolve)(t.config));let n=qt((0,G.dirname)(e)),[,,o]=n.split(".");parseInt(o,10)<1608&&(process.stdout.write(_.red(`${_.bold("Wallaby Core")} v${n} is not supported.
|
|
55
55
|
`)),process.stdout.write(_.red(`Run with ${_.bold("--update")} flag to get the latest version of Wallaby Core.
|
|
56
56
|
`)),process.exit(1));let i=(0,Ut.fork)(e,r,{env:process.env,silent:!0});return t.printLinks=!0,i.on("message",s=>{switch(s?.type){case"uiStarted":t.port=s.port,Af(t,n);break;case"notification":Tf(t,s.notification);break;case"restart":ta(t);break;case"licenseChanged":clearTimeout(Pt),ea(e);break;case"stopped":break;default:break}}),i.on("exit",()=>{process.stdout.write(_.gray(`
|
|
57
57
|
${_.bold("WALLABY CORE")} stopped
|
|
@@ -65,7 +65,7 @@ ${u.body}`:u.body).join(`
|
|
|
65
65
|
`)),e.doNotOpen||Rf(r)}function kf(e){for(let[t,r]of Object.entries(e))Array.isArray(r)&&(e[t]=r[r.length-1])}function Rf(e){let t=process.env.BROWSER||"";if(t.toLowerCase().endsWith(".js"))Pf(t,e);else if(t.toLowerCase()!=="none"){let r=process.env.BROWSER_ARGS?process.env.BROWSER_ARGS.split(" "):[];qf(t,r,e)}}function Pf(e,t){let r=process.argv.slice(2);(0,zs.default)(process.execPath,[e,...r,t],{stdio:"inherit"}).on("close",o=>{o!==0&&process.stdout.write(_.red(`
|
|
66
66
|
The script specified as BROWSER environment variable failed.
|
|
67
67
|
|
|
68
|
-
${_.cyan(e)} exited with code ${o}.`))})}var Hs=["Google Chrome Canary","Google Chrome Dev","Google Chrome Beta","Google Chrome","Microsoft Edge","Brave Browser","Vivaldi","Chromium"];async function qf(e,t,r){let n=e==="google chrome"?"Google Chrome":e;if(process.platform==="darwin"&&(!n||Hs.includes(n)))try{let i=await Ws("ps cax"),s=n&&i.includes(n)?n:Hs.find(a=>i.includes(a));if(s)return await Ws(`osascript openChrome.applescript "${encodeURI(r)}" "${s}"`,{cwd:Df}),!0}catch{}process.platform==="darwin"&&e==="open"&&(e=void 0);try{let i=e?{app:{name:e,arguments:t}}:{};return new Promise(async(s,a)=>{let c=(await eval?.("import('open')")).default
|
|
68
|
+
${_.cyan(e)} exited with code ${o}.`))})}var Hs=["Google Chrome Canary","Google Chrome Dev","Google Chrome Beta","Google Chrome","Microsoft Edge","Brave Browser","Vivaldi","Chromium"];async function qf(e,t,r){let n=e==="google chrome"?"Google Chrome":e;if(process.platform==="darwin"&&(!n||Hs.includes(n)))try{let i=await Ws("ps cax"),s=n&&i.includes(n)?n:Hs.find(a=>i.includes(a));if(s)return await Ws(`osascript openChrome.applescript "${encodeURI(r)}" "${s}"`,{cwd:Df}),!0}catch{}process.platform==="darwin"&&e==="open"&&(e=void 0);try{let i=e?{app:{name:e,arguments:t}}:{};return new Promise(async(s,a)=>{let c;try{c=(ys(),ha(ps)).default}catch{try{c=(await eval?.("import('open')")).default}catch{}}c&&c(r,i).then(u=>{u.on("error",a)}).catch(a)}).catch(s=>{process.stderr.write(s.stack||s.message)}),!0}catch{return!1}}function Ws(e,t){return new Promise((r,n)=>{(0,Ut.exec)(e,t,(o,i)=>{o?n(o):r(i.toString())})})}function ra(){try{let e=r=>r&&r.replace(/^\s+|\s+$/gm,""),t=Y.default.readFileSync(Js).toString();if(t){let r=t.split(":");r.length===2&&(t=e(r[1]))}return Buffer.from(t,"base64").toString().split(`
|
|
69
69
|
`)[2]}catch{}}function Uf(){try{let[e,t,r]=ra().split("/");return new Date(Date.UTC(parseInt(r,10),parseInt(t,10)-1,parseInt(e,10)))}catch{}}async function na(e,t){try{await Y.default.remove(e)}catch(r){if(t)throw r;await na(e,!0)}}function ia(e,t){let r;if(!e)try{e=JSON.parse(Y.default.readFileSync(qr).toString())}catch{}e||(e={});let n=Uf()?.getTime(),o=Object.keys(e).map(a=>({id:a,folder:(0,G.join)(Te,"wallaby"+a),...e[a]})).sort((a,c)=>c.releaseDate-a.releaseDate),i=new Date().getTime()-1e3*1440*5;o.forEach(a=>{if(!Y.default.existsSync(a.folder))t=!0,delete e[a.id];else if(a.invalidated&&Object.keys(a.expiry).length===0&&a.invalidated<i){t=!0,delete e[a.id];try{na(a.folder,!0)}catch{}}});let s=o.filter(a=>(!n||a.releaseDate<n)&&e[a.id]);if(s.length){if(n&&n<new Date().getTime()&&!e[s[0].id].expiry[n]){e[s[0].id].expiry[n]=!0;for(let c=1;c<s.length;c++)delete e[s[c].id].expiry[n];t=!0}let a=(s.find(c=>!c.invalidated)||s[0]).id;r=(0,G.join)(Te,"wallaby"+a)}return t&&Y.default.writeFileSync(qr,JSON.stringify(e)),r}async function oa(e,t){let r=!1,n=e,o=t?.forceLatestVersion,i=t?.useInstalledVersion,s=ra(),a=Ms(),c=h=>$f({name:"version",from:`${h}wallaby.json?${s?"expiry="+s.replace(/\//g,"-"):""}`,to:Ys}),u=o?!1:n&&Y.default.existsSync(n),l=(0,G.join)(Pr,"wallaby.zip");if(!u&&!o&&Y.default.existsSync(l))try{n=await aa(l),u=!!n&&Y.default.existsSync(n),r=!0}catch{}let d;if(i&&u)d={core:u&&qt(n)||"unknown"};else{let h=Ur("Downloading version file");try{try{await c(Ms())}catch{a=`${Rt}://s3.amazonaws.com/wallaby-downloads/`,await c("http://update.wallabyjs.com/")}}finally{h()}d=Bf()}if(!(u&&qt(n)===d.core))try{n=await Vs({name:"core",from:`${a}wallaby-v${d.core}.zip`}),r=!0}catch{n=await Vs({name:"core",from:`${Rt}://s3.amazonaws.com/wallaby-downloads/wallaby-v${d.core}.zip`}),r=!0}return{path:n,updated:r,type:"dist"}}function Bf(){let e=JSON.parse(Y.default.readFileSync(Ys).toString()),t;return e.latestServer.forEach(r=>{r.substring(0,r.lastIndexOf("."))===Ks.substring(0,r.lastIndexOf("."))&&(t=r)}),{core:t}}function qt(e){return JSON.parse(Y.default.readFileSync((0,G.join)(e,"package.json")).toString()).version}async function Vs(e){let t=Ur("Downloading core"),r=(0,G.join)(Pr,"wallaby.zip");try{Y.default.ensureDirSync(Pr),await sa(e.from,e.name,r,2e6)}finally{t()}let n=Ur("Extracting core");try{return await aa(r)}catch(o){throw new Error(`Error while unzipping wallaby.js ${e.name} file: ${o.message}`)}finally{n()}}async function $f(e){return await sa(e.from,e.name,e.to)}function sa(e,t,r,n){let o=!1,i=()=>!o&&(o=!0),s="This may occur when you are behind proxy.";return new Promise(async(a,c)=>{try{let u=global.fetch,l={headers:{"User-Agent":"node "+process.version},agent:void 0};if(e.startsWith("https:")){let h=require("https");js===!1&&(l.agent=new h.Agent({rejectUnauthorized:!1}))}let d=await u(e,l);if(!d.ok||d.status!==200)throw new Error(`Error while downloading wallaby.js ${t}, status code: ${d.status}. ${s}`);if(n&&d.headers.get("content-length")&&parseInt(d.headers.get("content-length"),10)<n)throw new Error(`Error while downloading wallaby.js ${t}, file is corrupt. ${s}`);{let h=await d.arrayBuffer();Y.default.writeFileSync(r,Buffer.from(h)),i()&&a(r)}}catch(u){i()&&c(u)}})}async function aa(e){let t=$s(),r=new t(e),n=new Date(r.getEntry("package.json").header.time);n.setMinutes(n.getMinutes()-n.getTimezoneOffset());let o=JSON.parse(r.readAsText("package.json")).version,[i,s,a]=o.split(".").map(h=>parseInt(h)),c=require("crypto");if(i>1||s>0||a>1091){let h=`-----BEGIN RSA PUBLIC KEY-----
|
|
70
70
|
MIIBCgKCAQEAngwMnSkF1zlHJggr7kXXO02ytYIlzMdvQxHu6hli+TFIeO72HNfK
|
|
71
71
|
P27g+f8EtlPRB0UwnpAHtkJHNCdwpo04eU8hS8g9vbmNf00luUJGuUHnf62Pp0EI
|