@0xobelisk/sui-cli 1.2.0-pre.112 → 1.2.0-pre.113
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/dist/dubhe.js +1 -1
- package/dist/dubhe.js.map +1 -1
- package/package.json +3 -3
package/dist/dubhe.js
CHANGED
|
@@ -105,7 +105,7 @@ Watch stopped.`),f()})}},jt=kn;import Ut from"wait-on";import ce from"ora";impor
|
|
|
105
105
|
- Sui localnode on port 9000
|
|
106
106
|
- Sui faucet on port 9123
|
|
107
107
|
- PostgreSQL database on port 5432
|
|
108
|
-
- Dubhe GraphQL server on port 4000`):t["local-database"]?(s="Timeout waiting for local database",r="Please make sure PostgreSQL is running on port 5432"):t["local-node"]?(s="Timeout waiting for local Sui node",r="Please make sure Sui localnode is running on port 9123"):t["local-indexer"]&&(s="Timeout waiting for local indexer",r="Please make sure indexer is running and health endpoint is available at http://127.0.0.1:8080/health"),n.fail(Z.red(s)),console.error(Z.yellow(r)),f(1)}}},Wt=Fn;var On={command:"switch-env",describe:"Switch environment",builder(e){return e.option("network",{type:"string",choices:["mainnet","testnet","devnet","localnet"],default:"localnet",desc:"Switch to node network (mainnet/testnet/devnet/localnet)"})},async handler(e){await q(e.network),f()}},zt=On;import Mn from"dotenv";import ee from"chalk";Mn.config();var Rn={command:"info",describe:"Get information about the current Sui node",builder(e){return e.options({network:{type:"string",choices:["mainnet","testnet","devnet","localnet","default"],default:"default",desc:"Node network (mainnet/testnet/devnet/localnet)"}})},handler:async({network:e})=>{try{e=="default"&&(e=await N(),console.log(ee.yellow(`Use default network: [${e}]`)));let t=W({network:e}),o=t.getSigner();console.log(ee.blue("Account Information:")),console.log(` Network: ${ee.green(e)}`),console.log(` Address: ${ee.green(o.toSuiAddress())}`);try{let n=await t.getBalance("0x2::sui::SUI"),s=(Number(n.totalBalance)/10**9).toFixed(4);console.log(` Balance: ${ee.green(s)} SUI`)}catch{console.log(` Balance: ${ee.red("Failed to fetch balance")} ${ee.gray("(Network error)")}`)}f()}catch(t){V(t),f(1)}}},Bt=Rn;import{loadConfig as jn}from"@0xobelisk/sui-common";async function qt(e,t,o){if(o)await ge(e.name,t,o);else{let n=`${process.cwd()}/src/${e.name}`,s=await ue(n,t);await ge(e.name,t,s)}}import Un from"chalk";var Hn={command:"load-metadata",describe:"Load metadata for a package",builder(e){return e.options({network:{type:"string",choices:["mainnet","testnet","devnet","localnet","default"],default:"default",desc:"Node network (mainnet/testnet/devnet/localnet)"},"config-path":{type:"string",desc:"Configuration file path",default:"dubhe.config.ts"},"package-id":{type:"string",desc:"Package ID to load metadata for",optional:!0}})},async handler({network:e,"config-path":t,"package-id":o}){try{e=="default"&&(e=await N(),console.log(Un.yellow(`Use default network: [${e}]`)));let n=await jn(t);await qt(n,e,o)}catch(n){V(n),f(1)}f()}},Gt=Hn;import i from"chalk";import{spawn as zn}from"child_process";import Xt from"cli-table3";import Fe from"inquirer";import*as E from"fs";import*as F from"path";import*as oe from"os";import*as Zt from"net";import Bn from"axios";var te={name:"@0xobelisk/sui-cli",version:"1.2.0-pre.112",description:"Tookit for interacting with move eps framework",keywords:["sui","obelisk labs","move","blockchain"],homepage:"https://github.com/0xobelisk/dubhe/tree/main/packages/sui-cli#readme",bugs:"https://github.com/0xobelisk/dubhe/issues",repository:{type:"git",url:"https://github.com/0xobelisk/dubhe.git"},license:"Apache-2.0",author:"team@obelisk.build",type:"module",exports:{".":"./dist/index.js"},types:"src/index.ts",bin:{dubhe:"./dist/dubhe.js"},scripts:{build:"pnpm run type-check && pnpm run build:js","build:js":"tsup && chmod +x ./dist/dubhe.js",clean:"pnpm run clean:js","clean:js":"rimraf dist",dev:"tsup --watch",format:"prettier --write .","format:check":"prettier --check .",lint:"eslint . --ext .ts",test:"vitest run","test:all":"pnpm test && pnpm test:integration","test:coverage":"vitest run --coverage","test:integration":"vitest run --config vitest.integration.config.ts","test:localnet":"vitest run --config vitest.integration.config.ts tests/integration/localnet.test.ts","test:testnet":"vitest run --config vitest.integration.config.ts tests/integration/testnet.test.ts","test:watch":"vitest","type-check":"tsc --noEmit",validate:"pnpm format:check && pnpm type-check"},dependencies:{"@0xobelisk/sui-client":"workspace:*","@0xobelisk/sui-common":"workspace:*","@mysten/sui":"1.35.0","@types/wait-on":"^5.3.4",axios:"^1.12.0",chalk:"^5.0.1",child_process:"^1.0.2",chokidar:"^3.5.3","cli-progress":"^3.12.0","cli-table3":"^0.6.5",dotenv:"^16.0.3",ejs:"^3.1.8",execa:"^7.0.0",glob:"^8.0.3","http-proxy-agent":"^7.0.2","https-proxy-agent":"^7.0.6",inquirer:"^9.2.15",ora:"^5.4.1",path:"^0.12.7",typescript:"^5.8.3","wait-on":"^7.0.1",yargs:"^17.7.1",zod:"^3.22.3","zod-validation-error":"^1.3.0"},devDependencies:{"@types/cli-progress":"^3.11.5","@types/ejs":"^3.1.1","@types/glob":"^7.2.0","@types/inquirer":"^9.0.7","@types/node":"^22.16.0","@types/yargs":"^17.0.10",eslint:"^9.0.0","eslint-config-prettier":"^9.1.0",prettier:"3.3.3","ts-node":"^10.9.1",tsup:"^6.7.0",tsx:"^3.12.6",vitest:"0.31.4"},engines:{node:">=22.0.0"},publishConfig:{access:"public"}};import Ne from"chalk";import*as Kt from"cli-progress";import*as Yt from"fs";import Vn from"axios";async function Jt(e,t){try{let o=await Vn.get(e,{responseType:"stream",timeout:3e4,headers:{"User-Agent":"dubhe-cli"},maxRedirects:5,validateStatus:n=>n<400});await Wn(o,t),console.log(Ne.green(" \u2713 Successfully downloaded"))}catch(o){if(o.code==="ENOTFOUND")throw new Error(`DNS resolution failed: ${o.message}. Please check your internet connection.`);if(o.code==="ECONNRESET")throw new Error(`Connection reset: ${o.message}. Please check your network connection.`);if(o.code==="ETIMEDOUT")throw new Error(`Connection timeout: ${o.message}. Please check your network connection.`);if(o.message.includes("protocol mismatch"))throw new Error(`Protocol mismatch: ${o.message}. Please check your network configuration.`);if(o.response)throw new Error(`HTTP ${o.response.status}: ${o.response.statusText}`);{let n=o instanceof Error?o.message:String(o);throw new Error(`Download failed: ${n}`)}}}async function Wn(e,t){let o=parseInt(e.headers["content-length"]||"0"),n=new Kt.SingleBar({format:Ne.cyan("Download Progress")+" |{bar}| {percentage}% | {value}/{total} MB | Speed: {speed} MB/s | ETA: {eta}s",barCompleteChar:"\u2588",barIncompleteChar:"\u2591",hideCursor:!0,barsize:30,forceRedraw:!0});o>0?n.start(Math.round(o/1024/1024*100)/100,0,{speed:"0.00"}):console.log(Ne.blue("\u{1F4E5} Downloading... (unable to get file size)"));let s=Yt.createWriteStream(t),r=0,a=Date.now();return new Promise((c,d)=>{e.data.on("data",l=>{if(r+=l.length,o>0){let m=Math.round(r/1024/1024*100)/100,u=(Date.now()-a)/1e3,y=u>0?Math.round(m/u*100)/100:0;n.update(m,{speed:y.toFixed(2)})}}),e.data.pipe(s),s.on("finish",()=>{o>0&&n.stop();let l=Math.round(r/1024/1024*100)/100,m=(Date.now()-a)/1e3,u=m>0?Math.round(l/m*100)/100:0;console.log(Ne.green(`\u2713 Download completed! ${l} MB, average speed: ${u} MB/s`)),c()}),s.on("error",l=>{o>0&&n.stop(),d(l)})})}function Je(){let e=process.platform,t=process.arch,o,n;switch(e){case"darwin":o="macos";break;case"win32":o="windows";break;case"linux":o="ubuntu";break;default:o=e}switch(t){case"x64":n="x86_64";break;case"arm64":n="aarch64";break;default:n=t}return{platform:e,arch:t,platformForAsset:o,archForAsset:n}}var H={sui:{name:"sui",repo:"MystenLabs/sui",binaryName:"sui",installDir:F.join(oe.homedir(),".dubhe","bin")},"dubhe-indexer":{name:"dubhe-indexer",repo:"0xobelisk/dubhe",binaryName:"dubhe-indexer",installDir:F.join(oe.homedir(),".dubhe","bin")}};async function z(e,t=[]){return new Promise(o=>{let n=zn(e,t,{shell:!0}),s="",r="";n.stdout?.on("data",a=>{s+=a.toString()}),n.stderr?.on("data",a=>{r+=a.toString()}),n.on("close",a=>{o({code:a||0,stdout:s,stderr:r})}),n.on("error",()=>{o({code:-1,stdout:s,stderr:r})})})}async function eo(e,t={}){try{let o={timeout:3e4,maxRedirects:5,validateStatus:s=>s<500,...t},n=await Bn(e,o);return{ok:n.status>=200&&n.status<300,status:n.status,statusText:n.statusText,json:async()=>n.data,headers:n.headers}}catch(o){let n=o.response?.status||0,s=o.response?.statusText||o.message;return o.code==="ENOTFOUND"?s="DNS resolution failed - please check your internet connection":o.code==="ECONNRESET"?s="Connection reset - please check your network connection":o.code==="ETIMEDOUT"?s="Connection timeout - please check your network connection":o.message.includes("protocol mismatch")&&(s="Protocol mismatch - please check your network configuration"),{ok:!1,status:n,statusText:s,json:async()=>o.response?.data||{},headers:o.response?.headers||{}}}}async function Xe(e,t=10,o=3){let n=`https://api.github.com/repos/${e}/releases?per_page=${t}`;for(let s=1;s<=o;s++)try{s>1&&console.log(i.gray(` Retry ${s}/${o}...`));let r=await eo(n,{headers:{"User-Agent":"dubhe-cli",Accept:"application/vnd.github.v3+json"}});if(!r.ok)throw r.status===403?new Error(`GitHub API rate limit: ${r.status}. Please retry later or set GITHUB_TOKEN environment variable`):new Error(`GitHub API request failed: ${r.status} ${r.statusText}`);return await r.json()}catch(r){if(s>1&&console.log(i.yellow(` \u26A0\uFE0F Attempt ${s} failed: ${r instanceof Error?r.message:String(r)}`)),s===o)return console.error(i.red(` \u274C Failed to fetch releases after ${o} attempts`)),[];await new Promise(a=>setTimeout(a,1e3*s))}return[]}function we(e,t){return e.assets.filter(n=>{let s=n.name.toLowerCase(),r=[t.platformForAsset.toLowerCase(),...t.platformForAsset==="macos"?["darwin","apple"]:[],...t.platformForAsset==="windows"?["win","win32","windows"]:[],...t.platformForAsset==="ubuntu"?["linux","gnu"]:[]],a=[t.archForAsset.toLowerCase(),...t.archForAsset==="x86_64"?["amd64","x64"]:[],...t.archForAsset==="aarch64"?["arm64"]:[]],c=r.some(m=>s.includes(m)),d=a.some(m=>s.includes(m)),l=s.endsWith(".tar.gz")||s.endsWith(".zip")||s.endsWith(".tgz")||s.endsWith(".tar.bz2")||s.endsWith(".tar.xz");return c&&d&&l}).map(n=>n.name)}async function qn(e,t){let o=H[e];return o?(await Xe(o.repo,10)).map(s=>({version:s.tag_name,hasCompatibleAsset:we(s,t).length>0})):[]}async function Gn(e){try{let t=ve();if(!t){console.log(i.gray(`Please add to PATH: export PATH="$PATH:${e}"`));return}let{shellName:o,configFile:n}=t,s=o==="fish"?`set -gx PATH $PATH ${e}`:`export PATH="$PATH:${e}"`;if(E.existsSync(n)&&E.readFileSync(n,"utf8").includes(e)){console.log(i.green(` \u2713 PATH already configured in ${n}`));return}let a=`# Added by dubhe doctor
|
|
108
|
+
- Dubhe GraphQL server on port 4000`):t["local-database"]?(s="Timeout waiting for local database",r="Please make sure PostgreSQL is running on port 5432"):t["local-node"]?(s="Timeout waiting for local Sui node",r="Please make sure Sui localnode is running on port 9123"):t["local-indexer"]&&(s="Timeout waiting for local indexer",r="Please make sure indexer is running and health endpoint is available at http://127.0.0.1:8080/health"),n.fail(Z.red(s)),console.error(Z.yellow(r)),f(1)}}},Wt=Fn;var On={command:"switch-env",describe:"Switch environment",builder(e){return e.option("network",{type:"string",choices:["mainnet","testnet","devnet","localnet"],default:"localnet",desc:"Switch to node network (mainnet/testnet/devnet/localnet)"})},async handler(e){await q(e.network),f()}},zt=On;import Mn from"dotenv";import ee from"chalk";Mn.config();var Rn={command:"info",describe:"Get information about the current Sui node",builder(e){return e.options({network:{type:"string",choices:["mainnet","testnet","devnet","localnet","default"],default:"default",desc:"Node network (mainnet/testnet/devnet/localnet)"}})},handler:async({network:e})=>{try{e=="default"&&(e=await N(),console.log(ee.yellow(`Use default network: [${e}]`)));let t=W({network:e}),o=t.getSigner();console.log(ee.blue("Account Information:")),console.log(` Network: ${ee.green(e)}`),console.log(` Address: ${ee.green(o.toSuiAddress())}`);try{let n=await t.getBalance("0x2::sui::SUI"),s=(Number(n.totalBalance)/10**9).toFixed(4);console.log(` Balance: ${ee.green(s)} SUI`)}catch{console.log(` Balance: ${ee.red("Failed to fetch balance")} ${ee.gray("(Network error)")}`)}f()}catch(t){V(t),f(1)}}},Bt=Rn;import{loadConfig as jn}from"@0xobelisk/sui-common";async function qt(e,t,o){if(o)await ge(e.name,t,o);else{let n=`${process.cwd()}/src/${e.name}`,s=await ue(n,t);await ge(e.name,t,s)}}import Un from"chalk";var Hn={command:"load-metadata",describe:"Load metadata for a package",builder(e){return e.options({network:{type:"string",choices:["mainnet","testnet","devnet","localnet","default"],default:"default",desc:"Node network (mainnet/testnet/devnet/localnet)"},"config-path":{type:"string",desc:"Configuration file path",default:"dubhe.config.ts"},"package-id":{type:"string",desc:"Package ID to load metadata for",optional:!0}})},async handler({network:e,"config-path":t,"package-id":o}){try{e=="default"&&(e=await N(),console.log(Un.yellow(`Use default network: [${e}]`)));let n=await jn(t);await qt(n,e,o)}catch(n){V(n),f(1)}f()}},Gt=Hn;import i from"chalk";import{spawn as zn}from"child_process";import Xt from"cli-table3";import Fe from"inquirer";import*as E from"fs";import*as F from"path";import*as oe from"os";import*as Zt from"net";import Bn from"axios";var te={name:"@0xobelisk/sui-cli",version:"1.2.0-pre.113",description:"Tookit for interacting with move eps framework",keywords:["sui","obelisk labs","move","blockchain"],homepage:"https://github.com/0xobelisk/dubhe/tree/main/packages/sui-cli#readme",bugs:"https://github.com/0xobelisk/dubhe/issues",repository:{type:"git",url:"https://github.com/0xobelisk/dubhe.git"},license:"Apache-2.0",author:"team@obelisk.build",type:"module",exports:{".":"./dist/index.js"},types:"src/index.ts",bin:{dubhe:"./dist/dubhe.js"},scripts:{build:"pnpm run type-check && pnpm run build:js","build:js":"tsup && chmod +x ./dist/dubhe.js",clean:"pnpm run clean:js","clean:js":"rimraf dist",dev:"tsup --watch",format:"prettier --write .","format:check":"prettier --check .",lint:"eslint . --ext .ts",test:"vitest run","test:all":"pnpm test && pnpm test:integration","test:coverage":"vitest run --coverage","test:integration":"vitest run --config vitest.integration.config.ts","test:localnet":"vitest run --config vitest.integration.config.ts tests/integration/localnet.test.ts","test:testnet":"vitest run --config vitest.integration.config.ts tests/integration/testnet.test.ts","test:watch":"vitest","type-check":"tsc --noEmit",validate:"pnpm format:check && pnpm type-check"},dependencies:{"@0xobelisk/sui-client":"workspace:*","@0xobelisk/sui-common":"workspace:*","@mysten/sui":"1.35.0","@types/wait-on":"^5.3.4",axios:"^1.12.0",chalk:"^5.0.1",child_process:"^1.0.2",chokidar:"^3.5.3","cli-progress":"^3.12.0","cli-table3":"^0.6.5",dotenv:"^16.0.3",ejs:"^3.1.8",execa:"^7.0.0",glob:"^8.0.3","http-proxy-agent":"^7.0.2","https-proxy-agent":"^7.0.6",inquirer:"^9.2.15",ora:"^5.4.1",path:"^0.12.7",typescript:"^5.8.3","wait-on":"^7.0.1",yargs:"^17.7.1",zod:"^3.22.3","zod-validation-error":"^1.3.0"},devDependencies:{"@types/cli-progress":"^3.11.5","@types/ejs":"^3.1.1","@types/glob":"^7.2.0","@types/inquirer":"^9.0.7","@types/node":"^22.16.0","@types/yargs":"^17.0.10",eslint:"^9.0.0","eslint-config-prettier":"^9.1.0",prettier:"3.3.3","ts-node":"^10.9.1",tsup:"^6.7.0",tsx:"^3.12.6",vitest:"0.31.4"},engines:{node:">=22.0.0"},publishConfig:{access:"public"}};import Ne from"chalk";import*as Kt from"cli-progress";import*as Yt from"fs";import Vn from"axios";async function Jt(e,t){try{let o=await Vn.get(e,{responseType:"stream",timeout:3e4,headers:{"User-Agent":"dubhe-cli"},maxRedirects:5,validateStatus:n=>n<400});await Wn(o,t),console.log(Ne.green(" \u2713 Successfully downloaded"))}catch(o){if(o.code==="ENOTFOUND")throw new Error(`DNS resolution failed: ${o.message}. Please check your internet connection.`);if(o.code==="ECONNRESET")throw new Error(`Connection reset: ${o.message}. Please check your network connection.`);if(o.code==="ETIMEDOUT")throw new Error(`Connection timeout: ${o.message}. Please check your network connection.`);if(o.message.includes("protocol mismatch"))throw new Error(`Protocol mismatch: ${o.message}. Please check your network configuration.`);if(o.response)throw new Error(`HTTP ${o.response.status}: ${o.response.statusText}`);{let n=o instanceof Error?o.message:String(o);throw new Error(`Download failed: ${n}`)}}}async function Wn(e,t){let o=parseInt(e.headers["content-length"]||"0"),n=new Kt.SingleBar({format:Ne.cyan("Download Progress")+" |{bar}| {percentage}% | {value}/{total} MB | Speed: {speed} MB/s | ETA: {eta}s",barCompleteChar:"\u2588",barIncompleteChar:"\u2591",hideCursor:!0,barsize:30,forceRedraw:!0});o>0?n.start(Math.round(o/1024/1024*100)/100,0,{speed:"0.00"}):console.log(Ne.blue("\u{1F4E5} Downloading... (unable to get file size)"));let s=Yt.createWriteStream(t),r=0,a=Date.now();return new Promise((c,d)=>{e.data.on("data",l=>{if(r+=l.length,o>0){let m=Math.round(r/1024/1024*100)/100,u=(Date.now()-a)/1e3,y=u>0?Math.round(m/u*100)/100:0;n.update(m,{speed:y.toFixed(2)})}}),e.data.pipe(s),s.on("finish",()=>{o>0&&n.stop();let l=Math.round(r/1024/1024*100)/100,m=(Date.now()-a)/1e3,u=m>0?Math.round(l/m*100)/100:0;console.log(Ne.green(`\u2713 Download completed! ${l} MB, average speed: ${u} MB/s`)),c()}),s.on("error",l=>{o>0&&n.stop(),d(l)})})}function Je(){let e=process.platform,t=process.arch,o,n;switch(e){case"darwin":o="macos";break;case"win32":o="windows";break;case"linux":o="ubuntu";break;default:o=e}switch(t){case"x64":n="x86_64";break;case"arm64":n="aarch64";break;default:n=t}return{platform:e,arch:t,platformForAsset:o,archForAsset:n}}var H={sui:{name:"sui",repo:"MystenLabs/sui",binaryName:"sui",installDir:F.join(oe.homedir(),".dubhe","bin")},"dubhe-indexer":{name:"dubhe-indexer",repo:"0xobelisk/dubhe",binaryName:"dubhe-indexer",installDir:F.join(oe.homedir(),".dubhe","bin")}};async function z(e,t=[]){return new Promise(o=>{let n=zn(e,t,{shell:!0}),s="",r="";n.stdout?.on("data",a=>{s+=a.toString()}),n.stderr?.on("data",a=>{r+=a.toString()}),n.on("close",a=>{o({code:a||0,stdout:s,stderr:r})}),n.on("error",()=>{o({code:-1,stdout:s,stderr:r})})})}async function eo(e,t={}){try{let o={timeout:3e4,maxRedirects:5,validateStatus:s=>s<500,...t},n=await Bn(e,o);return{ok:n.status>=200&&n.status<300,status:n.status,statusText:n.statusText,json:async()=>n.data,headers:n.headers}}catch(o){let n=o.response?.status||0,s=o.response?.statusText||o.message;return o.code==="ENOTFOUND"?s="DNS resolution failed - please check your internet connection":o.code==="ECONNRESET"?s="Connection reset - please check your network connection":o.code==="ETIMEDOUT"?s="Connection timeout - please check your network connection":o.message.includes("protocol mismatch")&&(s="Protocol mismatch - please check your network configuration"),{ok:!1,status:n,statusText:s,json:async()=>o.response?.data||{},headers:o.response?.headers||{}}}}async function Xe(e,t=10,o=3){let n=`https://api.github.com/repos/${e}/releases?per_page=${t}`;for(let s=1;s<=o;s++)try{s>1&&console.log(i.gray(` Retry ${s}/${o}...`));let r=await eo(n,{headers:{"User-Agent":"dubhe-cli",Accept:"application/vnd.github.v3+json"}});if(!r.ok)throw r.status===403?new Error(`GitHub API rate limit: ${r.status}. Please retry later or set GITHUB_TOKEN environment variable`):new Error(`GitHub API request failed: ${r.status} ${r.statusText}`);return await r.json()}catch(r){if(s>1&&console.log(i.yellow(` \u26A0\uFE0F Attempt ${s} failed: ${r instanceof Error?r.message:String(r)}`)),s===o)return console.error(i.red(` \u274C Failed to fetch releases after ${o} attempts`)),[];await new Promise(a=>setTimeout(a,1e3*s))}return[]}function we(e,t){return e.assets.filter(n=>{let s=n.name.toLowerCase(),r=[t.platformForAsset.toLowerCase(),...t.platformForAsset==="macos"?["darwin","apple"]:[],...t.platformForAsset==="windows"?["win","win32","windows"]:[],...t.platformForAsset==="ubuntu"?["linux","gnu"]:[]],a=[t.archForAsset.toLowerCase(),...t.archForAsset==="x86_64"?["amd64","x64"]:[],...t.archForAsset==="aarch64"?["arm64"]:[]],c=r.some(m=>s.includes(m)),d=a.some(m=>s.includes(m)),l=s.endsWith(".tar.gz")||s.endsWith(".zip")||s.endsWith(".tgz")||s.endsWith(".tar.bz2")||s.endsWith(".tar.xz");return c&&d&&l}).map(n=>n.name)}async function qn(e,t){let o=H[e];return o?(await Xe(o.repo,10)).map(s=>({version:s.tag_name,hasCompatibleAsset:we(s,t).length>0})):[]}async function Gn(e){try{let t=ve();if(!t){console.log(i.gray(`Please add to PATH: export PATH="$PATH:${e}"`));return}let{shellName:o,configFile:n}=t,s=o==="fish"?`set -gx PATH $PATH ${e}`:`export PATH="$PATH:${e}"`;if(E.existsSync(n)&&E.readFileSync(n,"utf8").includes(e)){console.log(i.green(` \u2713 PATH already configured in ${n}`));return}let a=`# Added by dubhe doctor
|
|
109
109
|
${s}`;E.appendFileSync(n,`
|
|
110
110
|
${a}
|
|
111
111
|
`),console.log(i.green(` \u2713 Automatically added to PATH in ${n}`)),console.log(i.blue(` \u{1F4DD} To apply changes: source ${n} or restart terminal`))}catch(t){console.log(i.yellow(` \u26A0\uFE0F Could not auto-configure PATH: ${t instanceof Error?t.message:String(t)}`)),console.log(i.gray(` Please manually add to PATH: export PATH="$PATH:${e}"`))}}function ve(){let e=oe.homedir(),t=process.env.SHELL;if(t){if(t.includes("zsh"))return{shellName:"zsh",configFile:F.join(e,".zshrc")};if(t.includes("bash")){let n=F.join(e,".bash_profile"),s=F.join(e,".bashrc");return{shellName:"bash",configFile:process.platform==="darwin"&&E.existsSync(n)?n:s}}else if(t.includes("fish")){let n=F.join(e,".config","fish");return E.existsSync(n)||E.mkdirSync(n,{recursive:!0}),{shellName:"fish",configFile:F.join(n,"config.fish")}}}let o=[{name:"zsh",file:F.join(e,".zshrc")},{name:"bash",file:process.platform==="darwin"?F.join(e,".bash_profile"):F.join(e,".bashrc")},{name:"bash",file:F.join(e,".bashrc")}];for(let n of o)if(E.existsSync(n.file))return{shellName:n.name,configFile:n.file};return process.env.ZSH||E.existsSync("/bin/zsh")?{shellName:"zsh",configFile:F.join(e,".zshrc")}:null}async function Ye(e,t){let o=H[e];if(!o)return console.error(`Unknown tool: ${e}`),!1;let n=Je();console.log(i.gray(` System: ${n.platform}/${n.arch}`));try{console.log(i.gray(" Fetching release information..."));let s=await Xe(o.repo,10);if(s.length===0)return console.error(i.red(` \u274C Unable to fetch releases for ${o.name}`)),!1;let r=null;if(t){if(t.startsWith("v")||(t=`v${t}`),r=s.find(p=>p.tag_name===t)||null,!r)return console.error(`Version ${t} not found`),!1}else for(let p of s)if(we(p,n).length>0){r=p;break}if(!r)return console.error("No compatible version found"),!1;let a=we(r,n);if(a.length===0)return console.error(`Version ${r.tag_name} has no compatible binaries`),!1;let c=a[0],d=r.assets.find(p=>p.name===c);if(!d)return console.error(`Asset file not found: ${c}`),!1;console.log(i.green(` \u2713 Found compatible version: ${r.tag_name}`)),console.log(i.gray(` Download file: ${d.name}`));try{let p=await eo(d.browser_download_url,{method:"HEAD",headers:{"User-Agent":"dubhe-cli"}});if(!p.ok)console.log(i.yellow(` \u26A0\uFE0F Warning: Unable to access download file (${p.status})`));else{let w=p.headers["content-length"];w&&console.log(i.gray(` File size: ${Math.round(parseInt(w)/1024/1024*100)/100} MB`))}}catch{console.log(i.yellow(" \u26A0\uFE0F Warning: Unable to verify download file"))}E.existsSync(o.installDir)||(E.mkdirSync(o.installDir,{recursive:!0}),console.log(i.gray(` Created install directory: ${o.installDir}`))),console.log(i.blue(" \u{1F4E5} Downloading..."));let l=F.join(oe.tmpdir(),d.name),m=3;for(let p=1;p<=m;p++)try{p>1&&console.log(i.gray(` Attempt ${p} to download...`)),await Jt(d.browser_download_url,l);break}catch(w){let g=w instanceof Error?w.message:String(w);if(console.log(i.yellow(` \u26A0\uFE0F Download failed (attempt ${p}): ${g}`)),p===m)throw new Error(`Download failed after ${m} attempts: ${g}`);console.log(i.gray(` Waiting ${p*2} seconds before retry...`)),await new Promise(h=>setTimeout(h,p*2e3))}console.log(i.blue(" \u{1F4E6} Extracting and installing..."));let u=F.join(oe.tmpdir(),`extract_${Date.now()}`);if(E.mkdirSync(u,{recursive:!0}),d.name.endsWith(".tar.gz")||d.name.endsWith(".tgz")){let p=await z("tar",["-xzf",l,"-C",u]);if(p.code!==0)throw new Error(`Extraction failed: ${p.stderr}`)}else if(d.name.endsWith(".tar.bz2")){let p=await z("tar",["-xjf",l,"-C",u]);if(p.code!==0)throw new Error(`Extraction failed: ${p.stderr}`)}else if(d.name.endsWith(".tar.xz")){let p=await z("tar",["-xJf",l,"-C",u]);if(p.code!==0)throw new Error(`Extraction failed: ${p.stderr}`)}else if(d.name.endsWith(".zip")){let p=await z("unzip",["-q",l,"-d",u]);if(p.code!==0)throw new Error(`Extraction failed: ${p.stderr}`)}else throw new Error(`Unsupported compression format: ${d.name}`);let y=p=>{let w=E.readdirSync(p,{withFileTypes:!0});for(let g of w){let h=F.join(p,g.name);if(g.isDirectory()){let v=y(h);if(v)return v}else if(g.name===o.binaryName||g.name===`${o.binaryName}.exe`)return h}return null},$=y(u);if(!$)throw new Error(`Cannot find ${o.binaryName} binary in extracted files`);let T=F.join(o.installDir,o.binaryName+(process.platform==="win32"?".exe":""));return E.copyFileSync($,T),process.platform!=="win32"&&E.chmodSync(T,493),E.rmSync(l,{force:!0}),E.rmSync(u,{recursive:!0,force:!0}),console.log(i.green(" \u2705 Installation completed!")),console.log(i.gray(` Location: ${T}`)),console.log(i.gray(` Version: ${r.tag_name}`)),(process.env.PATH||"").includes(o.installDir)||(console.log(i.yellow(" \u26A0\uFE0F Warning: Install directory is not in PATH environment variable")),process.platform==="win32"?console.log(i.gray(` Please add to PATH: set PATH=%PATH%;${o.installDir}`)):await Gn(o.installDir)),!0}catch(s){return console.error(i.red(`\u274C Installation failed: ${s}`)),!1}}async function Kn(e){let t=Je(),o=await qn(e,t);if(o.length===0)return console.log(i.red(`Unable to get version information for ${e}`)),null;let n=o.filter(r=>r.hasCompatibleAsset).slice(0,5);if(n.length===0)return console.log(i.red("No compatible versions found for current system")),null;console.log(i.blue(`
|