UNPKG

@aptos-labs/ts-sdk

Version:
2 lines 1.59 kB
import{spawn as n}from"child_process";import{platform as p}from"os";var i=class{async init(e){let{network:t,profile:s}=e,r=["aptos","init",`--network=${t??"local"}`,`--profile=${s??"default"}`];return this.runCommand(r)}async compile(e){let{packageDirectoryPath:t,namedAddresses:s}=e,r=["aptos","move","compile","--package-dir",t,"--skip-fetch-latest-git-deps"],o=this.parseNamedAddresses(s);return r.push(...this.prepareNamedAddresses(o)),this.runCommand(r)}async test(e){let{packageDirectoryPath:t,namedAddresses:s}=e,r=["aptos","move","test","--package-dir",t,"--skip-fetch-latest-git-deps"],o=this.parseNamedAddresses(s);return r.push(...this.prepareNamedAddresses(o)),this.runCommand(r)}async publish(e){let{packageDirectoryPath:t,namedAddresses:s,profile:r}=e,o=["aptos","move","publish","--package-dir",t,"--skip-fetch-latest-git-deps",`--profile=${r??"default"}`],a=this.parseNamedAddresses(s);return o.push(...this.prepareNamedAddresses(a)),this.runCommand(o)}async runCommand(e){return new Promise((t,s)=>{let r=p(),o;r==="win32"?o=n("npx",e,{shell:!0}):o=n("npx",e),o.stdout.pipe(process.stdout),o.stderr.pipe(process.stderr),process.stdin.pipe(o.stdin),o.on("close",a=>{a===0?t(!0):s(new Error(`Child process exited with code ${a}`))})})}prepareNamedAddresses(e){let t=e.size,s=[];if(t===0)return s;s.push("--named-addresses");let r=0;return e.forEach((o,a)=>{r+=1;let d=`${a}=${o.toString()}`;r<t-1&&(d+=","),s.push(d)}),s}parseNamedAddresses(e){let t=new Map;return Object.keys(e).forEach(s=>{let r=e[s];t.set(s,r)}),t}};export{i as a}; //# sourceMappingURL=chunk-7UBKXR37.mjs.map