@clarigen/cli 1.0.0-next.17 → 1.0.0-next.20
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/abi-types.ts.txt +119 -0
- package/dist/commands/index.js +741 -62
- package/dist/index.js +810 -61
- package/package.json +8 -6
- package/src/clarinet-config.ts +6 -0
- package/src/generate/declaration.ts +1 -1
- package/src/generate/single.ts +134 -0
- package/src/generate/vars.ts +82 -0
- package/src/utils.ts +43 -7
- package/src/writer.ts +39 -0
- package/dist/commands/index.d.ts +0 -16
- package/dist/commands/index.mjs +0 -78
- package/dist/index.d.ts +0 -63
- package/dist/index.mjs +0 -78
package/dist/index.mjs
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
var rt=Object.defineProperty,nt=Object.defineProperties;var et=Object.getOwnPropertyDescriptors;var w=Object.getOwnPropertySymbols;var k=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var j=(t,n,r)=>n in t?rt(t,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[n]=r,$=(t,n)=>{for(var r in n||(n={}))k.call(n,r)&&j(t,r,n[r]);if(w)for(var r of w(n))N.call(n,r)&&j(t,r,n[r]);return t},h=(t,n)=>nt(t,et(n));var ot=(t=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(t,{get:(n,r)=>(typeof require!="undefined"?require:n)[r]}):t)(function(t){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+t+'" is not supported')});var D=(t,n)=>{var r={};for(var e in t)k.call(t,e)&&n.indexOf(e)<0&&(r[e]=t[e]);if(t!=null&&w)for(var e of w(t))n.indexOf(e)<0&&N.call(t,e)&&(r[e]=t[e]);return r};import{run as Vr}from"@oclif/command";import{resolve as R,join as gt,relative as ut}from"path";import{readFile as mt,access as Ct}from"fs/promises";import{constants as dt}from"fs";import{parse as v}from"@ltd/j-toml";import{resolve as S}from"path";import{readFile as O}from"fs/promises";import{generateWallet as it,getStxAddressFromAccount as st}from"micro-stacks/wallet-sdk";import{array as ct}from"toposort";import{StacksNetworkVersion as at}from"micro-stacks/crypto";async function ft(t){let n=S(t,"settings","Devnet.toml"),r=await O(n,{encoding:"utf-8"});return v(r,1,`
|
|
2
|
-
`,!0,{longer:!0})}async function lt(t){let n=S(t,"Clarinet.toml"),r=await O(n,{encoding:"utf-8"});return v(r,1,`
|
|
3
|
-
`,!0)}async function _(t,n){let r=await lt(t),e=n.deployer.address;return pt(r.contracts).map(c=>({file:r.contracts[c].path.replace(/^contracts\//,""),address:e,name:c}))}function pt(t){let n=[],r=[];return Object.entries(t).forEach(([o,i])=>{r.push(o),i.depends_on.forEach(c=>n.push([o,c]))}),ct(r,n).reverse()}async function B(t){let n=await ft(t),r=await Promise.all(Object.entries(n.accounts).map(async([o,i])=>{let c=await it(i.mnemonic,"password"),[s]=c.accounts,a=st(s,at.testnetP2PKH);return[o,h($({},i),{address:a})]}));return Object.fromEntries(r)}var L={outputDir:"src/clarigen",clarinet:"."};function yt(t){return R(t,"clarigen.config.json")}async function $t(t){try{return await Ct(t,dt.R_OK),!0}catch{return!1}}async function xt(t){let n=yt(t);if(await $t(n)){let e=await mt(n,{encoding:"utf-8"}),o=JSON.parse(e);return $($({},L),o)}return L}async function b(t){let n=await xt(t),r=R(t,n.clarinet||"."),e=await B(r),o=await _(r,e),i=ut(process.cwd(),gt(n.clarinet,"contracts"));return h($({},n),{contracts:o,contractsDir:i,accounts:e,clarinet:n.clarinet||"."})}import{isClarityAbiBuffer as wt,isClarityAbiList as ht,isClarityAbiOptional as bt,isClarityAbiPrimitive as Ft,isClarityAbiResponse as J,isClarityAbiStringAscii as At,isClarityAbiStringUtf8 as Pt,isClarityAbiTuple as Tt}from"micro-stacks/transactions";import{toCamelCase as P}from"@clarigen/core";import{check as Et}from"reserved-words";var l=(t,n=!1)=>{if(Ft(t)){if(t==="uint128")return n?"number | bigint":"bigint";if(t==="int128")return n?"number | bigint":"bigint";if(t==="bool")return"boolean";if(t==="principal")return"string";if(t==="none")return"null";if(t==="trait_reference")return"string";throw new Error(`Unexpected Clarity ABI type primitive: ${JSON.stringify(t)}`)}else{if(wt(t))return"Uint8Array";if(J(t)){let r=l(t.response.ok),e=l(t.response.error);return`Response<${r}, ${e}>`}else{if(bt(t))return`${l(t.optional)} | null`;if(Tt(t)){let r=[];return t.tuple.forEach(({name:e,type:o})=>{let i=l(o);r.push(`"${e}": ${i}`)}),`{
|
|
4
|
-
${r.join(`;
|
|
5
|
-
`)}
|
|
6
|
-
}`}else{if(ht(t))return`${l(t.list.type)}[]`;if(At(t))return"string";if(Pt(t))return"string";if(t==="trait_reference")return"string";throw new Error(`Unexpected Clarity ABI type: ${JSON.stringify(t)}`)}}}};function It(t){let n=P(t);return`${Et(n,6)?"_":""}${n}`}var jt={public:"Public",read_only:"ReadOnly",private:"Private"};function M(t){let n="";return t.functions.forEach((r,e)=>{let o=`${P(r.name)}: `;if(o+=`(${r.args.map(s=>`${It(s.name)}: ${l(s.type,!0)}`).join(", ")}) => `,o+=`ContractCalls.${jt[r.access]}<`,r.access==="public"){let{type:s}=r.outputs;if(!J(s))throw new Error("Expected response type for public function");let a=l(s.response.ok),f=l(s.response.error);o+=`${a}, ${f}>;`}else o+=`${l(r.outputs.type)}>;`;n+=`${e===0?"":`
|
|
7
|
-
`} ${o}`}),t.maps.forEach(r=>{let e=`${P(r.name)}: `,o=l(r.key,!0),i=`key: ${o}`,c=l(r.value);e+=`(${i}) => ContractCalls.Map<${o}, ${c}>;`,n+=`
|
|
8
|
-
${e}`}),n}import{hasStdErr as kt}from"@clarigen/native-bin";import{toCamelCase as x}from"@clarigen/core";import{dirname as Nt,join as Dt}from"path";var U=async({provider:t,contractFile:n,contractAddress:r,contractName:e})=>{let o=await t.runCommand(["launch",`${r}.${e}`,n,t.dbFilePath,"--output_analysis","--costs","--assets"]);if(kt(o.stderr))throw new Error(`Error on ${n}:
|
|
9
|
-
${o.stderr}
|
|
10
|
-
`);let i=JSON.parse(o.stdout);if(i.error){let{initialization:s}=i.error;if(s!=null&&s.includes(`
|
|
11
|
-
Near:
|
|
12
|
-
`)){let[a,f]=s.split(`
|
|
13
|
-
Near:
|
|
14
|
-
`),p="",g=/start_line: (\d+),/.exec(f);throw g&&(p=g[1]),new Error(`Error on ${n}:
|
|
15
|
-
${a}
|
|
16
|
-
${p?`Near line ${p}`:""}
|
|
17
|
-
Raw trace:
|
|
18
|
-
${f}
|
|
19
|
-
`)}throw new Error(`Error on ${n}:
|
|
20
|
-
${JSON.stringify(i.error,null,2)}
|
|
21
|
-
`)}return i.analysis},W=({contractName:t,abi:n})=>{let r=x(t,!0),s=n,{clarity_version:e}=s,o=D(s,["clarity_version"]),i=JSON.stringify(o,null,2);return`import { ClarityAbi } from '@clarigen/core';
|
|
22
|
-
|
|
23
|
-
// prettier-ignore
|
|
24
|
-
export const ${r}Interface: ClarityAbi = ${i};
|
|
25
|
-
`},V=({contractFile:t,contractAddress:n,contractName:r})=>{let e=x(r,!0),o=x(r),i=`${e}Contract`,c=`${e}Interface`;return`import { pureProxy, Contract } from '@clarigen/core';
|
|
26
|
-
import type { ${i} } from './types';
|
|
27
|
-
import { ${c} } from './abi';
|
|
28
|
-
export type { ${i} } from './types';
|
|
29
|
-
|
|
30
|
-
export function ${o}Contract(contractAddress: string, contractName: string) {
|
|
31
|
-
return pureProxy<${i}>({
|
|
32
|
-
abi: ${c},
|
|
33
|
-
contractAddress,
|
|
34
|
-
contractName,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export const ${o}Info: Contract<${i}> = {
|
|
39
|
-
contract: ${o}Contract,
|
|
40
|
-
address: '${n}',
|
|
41
|
-
contractFile: '${t}',
|
|
42
|
-
name: '${r}',
|
|
43
|
-
abi: ${c},
|
|
44
|
-
};
|
|
45
|
-
`},K=(t,n)=>{let r=x(n,!0),e=M(t);return`import { Response, ContractCalls } from '@clarigen/core';
|
|
46
|
-
|
|
47
|
-
// prettier-ignore
|
|
48
|
-
export interface ${r}Contract {
|
|
49
|
-
${e}
|
|
50
|
-
}
|
|
51
|
-
`},q=t=>{let n=["import type { ContractInstances } from '@clarigen/core';"],r=[],e=[],o="";"accounts"in t&&(o=`
|
|
52
|
-
|
|
53
|
-
// prettier-ignore
|
|
54
|
-
export const accounts = {
|
|
55
|
-
${Object.keys(t.accounts).map(a=>{let f=t.accounts[a];return`"${a}": {
|
|
56
|
-
mnemonic: "${f.mnemonic}",
|
|
57
|
-
balance: ${f.balance.toString()}n,
|
|
58
|
-
address: "${f.address}",
|
|
59
|
-
},`}).join(`
|
|
60
|
-
`)}
|
|
61
|
-
};`),t.contracts.forEach(s=>{let a=s.name,f=x(a),p=`${f}Info`,y=`${x(a,!0)}Contract`,g=Nt(s.file),I=`'./${Dt(g||".",a)}'`,z=`import { ${p} } from ${I};`;n.push(z);let G=`export type { ${y} } from ${I};`;r.push(G);let tt=`${f}: ${p},`;e.push(tt)});let i=`
|
|
62
|
-
export type Contracts = ContractInstances<typeof contracts>;
|
|
63
|
-
`;return`${n.join(`
|
|
64
|
-
`)}
|
|
65
|
-
${r.join(`
|
|
66
|
-
`)}
|
|
67
|
-
${i}
|
|
68
|
-
export const contracts = {
|
|
69
|
-
${e.join(`
|
|
70
|
-
`)}
|
|
71
|
-
};${o}
|
|
72
|
-
`};import{Command as Wt,flags as Y}from"@oclif/command";import{createClarityBin as Lt}from"@clarigen/native-bin";import{resolve as u,relative as Rt,dirname as Jt}from"path";import{mkdir as Mt,writeFile as F}from"fs/promises";import{createContractDocInfo as vt,generateMarkdown as St}from"@clarigen/claridocs";import{mkdir as Ot,readFile as _t,writeFile as H}from"fs/promises";import{relative as Bt,resolve as T}from"path";async function Q({contractFile:t,contractName:n,docsPath:r,abi:e,dirName:o}){let i=await _t(t,{encoding:"utf-8"}),c=vt({contractSrc:i,abi:e}),s=T(process.cwd(),r,o||"."),a=T(s,`${n}.md`),f=St({contract:c,contractFile:Bt(s,t),contractName:n,abi:e});await Ot(s,{recursive:!0}),await H(a,f)}async function X(t){if(!t.docs)return;let r=`# Contracts
|
|
73
|
-
|
|
74
|
-
${t.contracts.map(o=>{let i=o.file.replace(".clar",".md");return`- [\`${o.name}\`](${i})`}).join(`
|
|
75
|
-
`)}
|
|
76
|
-
`,e=T(process.cwd(),t.docs,"README.md");await H(e,r)}var Ut=async({contractFile:t,outputFolder:n,provider:r,contractAddress:e,dirName:o,contractName:i,docsPath:c})=>{let s=u(process.cwd(),t),a=await U({contractFile:s,provider:r,contractAddress:e,contractName:i}),f=K(a,i),p=V({contractFile:Rt(process.cwd(),s),contractAddress:e,contractName:i}),y=W({contractName:i,abi:a});typeof c<"u"&&await Q({contractFile:s,contractName:i,abi:a,docsPath:c,dirName:o});let g=u(n,o||".",i);await Mt(g,{recursive:!0}),await F(u(g,"abi.ts"),y),await F(u(g,"index.ts"),p),await F(u(g,"types.ts"),f)},A=async t=>{let n=await b(t),{contractsDir:r,outputDir:e,contracts:o}=n,i=u(t,e),c=await Lt();for(let f of o){let p=u(t,r,f.file),y=Jt(f.file);await Ut({contractFile:p,outputFolder:i,provider:c,contractAddress:f.address,dirName:y,contractName:f.name,docsPath:n.docs})}let s=q(n);await X(n);let a=u(i,"index.ts");await F(a,s)};import{watch as Vt}from"chokidar";import{basename as Kt}from"path";import{red as qt,green as Z}from"chalk";var Ht=ot("ora"),E=class extends Wt{async run(){let{flags:n}=this.parse(E),r=process.cwd();if(n.watch){let e=Ht("Generating files").start(),{contractsDir:o}=await b(r),i=Vt([o],{cwd:r});try{await A(r),e.succeed("Finished generating files. Watching for changes.")}catch(c){e.fail(`Error generating files.
|
|
77
|
-
${c.message}`)}i.on("change",async c=>{let s=Kt(c);e.clear(),e.start(`Change detected for ${Z(s)}, generating.`);try{await A(r),e.succeed(`Finished generating files for ${Z(s)}. Watching for changes.`)}catch(a){let f=a.message;e.fail(`Error after saving ${qt(s)}.
|
|
78
|
-
${f}`)}}),process.on("SIGINT",async()=>{await i.close(),process.exit()})}else await A(r)}},d=E;d.description="Generate project files",d.strict=!0,d.hidden=!1,d.flags={help:Y.help({char:"h"}),watch:Y.boolean({char:"w",description:"Watch for changes to your contracts"})},d.args=[];export{d as Generate,$t as configFileExists,yt as configFilePath,L as defaultConfigFile,V as generateIndexFile,U as generateInterface,W as generateInterfaceFile,q as generateProjectIndexFile,K as generateTypesFile,xt as getConfigFile,b as getProjectConfig,l as jsTypeFromAbiType,M as makePureTypes,Vr as run};
|