@clarigen/cli 1.0.0-next.8 → 2.0.0
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/README.md +1 -31
- package/dist/index.cjs +1295 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +432 -0
- package/dist/index.js +1230 -17
- package/dist/index.js.map +1 -0
- package/dist/run-cli.cjs +1442 -0
- package/dist/run-cli.cjs.map +1 -0
- package/dist/run-cli.d.ts +1 -0
- package/dist/run-cli.js +1446 -0
- package/dist/run-cli.js.map +1 -0
- package/package.json +36 -51
- package/bin/run +0 -7
- package/dist/clarinet-config.js +0 -70
- package/dist/commands/index.js +0 -65
- package/dist/config.js +0 -54
- package/dist/generate/declaration.js +0 -120
- package/dist/generate/files.js +0 -147
- package/dist/start.js +0 -9
- package/dist/utils.js +0 -53
- package/src/clarinet-config.ts +0 -127
- package/src/commands/index.ts +0 -67
- package/src/config.ts +0 -78
- package/src/generate/declaration.ts +0 -116
- package/src/generate/files.ts +0 -181
- package/src/index.ts +0 -5
- package/src/start.ts +0 -5
- package/src/utils.ts +0 -78
package/src/generate/files.ts
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { NativeClarityBinProvider, hasStdErr } from '@clarigen/native-bin';
|
|
2
|
-
import { ClarityAbi, toCamelCase } from '@clarigen/core';
|
|
3
|
-
import { ConfigContract, ConfigFile } from '../config';
|
|
4
|
-
import { dirname, resolve, join } from 'path';
|
|
5
|
-
import { makePureTypes } from '..';
|
|
6
|
-
|
|
7
|
-
export const generateInterface = async ({
|
|
8
|
-
provider,
|
|
9
|
-
contractFile,
|
|
10
|
-
contractAddress,
|
|
11
|
-
contractName,
|
|
12
|
-
}: {
|
|
13
|
-
contractFile: string;
|
|
14
|
-
provider: NativeClarityBinProvider;
|
|
15
|
-
contractAddress: string;
|
|
16
|
-
contractName: string;
|
|
17
|
-
}): Promise<ClarityAbi> => {
|
|
18
|
-
const receipt = await provider.runCommand([
|
|
19
|
-
'launch',
|
|
20
|
-
`${contractAddress}.${contractName}`,
|
|
21
|
-
contractFile,
|
|
22
|
-
provider.dbFilePath,
|
|
23
|
-
'--output_analysis',
|
|
24
|
-
'--costs',
|
|
25
|
-
'--assets',
|
|
26
|
-
]);
|
|
27
|
-
if (hasStdErr(receipt.stderr)) {
|
|
28
|
-
throw new Error(`Error on ${contractFile}:
|
|
29
|
-
${receipt.stderr}
|
|
30
|
-
`);
|
|
31
|
-
}
|
|
32
|
-
const output = JSON.parse(receipt.stdout);
|
|
33
|
-
if (output.error) {
|
|
34
|
-
const { initialization } = output.error;
|
|
35
|
-
if (initialization?.includes('\nNear:\n')) {
|
|
36
|
-
const [error, trace] = initialization.split('\nNear:\n');
|
|
37
|
-
let startLine = '';
|
|
38
|
-
const matcher = /start_line: (\d+),/;
|
|
39
|
-
const matches = matcher.exec(trace);
|
|
40
|
-
if (matches) startLine = matches[1];
|
|
41
|
-
throw new Error(`Error on ${contractFile}:
|
|
42
|
-
${error}
|
|
43
|
-
${startLine ? `Near line ${startLine}` : ''}
|
|
44
|
-
Raw trace:
|
|
45
|
-
${trace}
|
|
46
|
-
`);
|
|
47
|
-
}
|
|
48
|
-
throw new Error(`Error on ${contractFile}:
|
|
49
|
-
${JSON.stringify(output.error, null, 2)}
|
|
50
|
-
`);
|
|
51
|
-
}
|
|
52
|
-
const abi = output.analysis;
|
|
53
|
-
return abi;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export const generateInterfaceFile = ({
|
|
57
|
-
contractName,
|
|
58
|
-
abi,
|
|
59
|
-
}: {
|
|
60
|
-
contractName: string;
|
|
61
|
-
abi: ClarityAbi;
|
|
62
|
-
}) => {
|
|
63
|
-
const variableName = toCamelCase(contractName, true);
|
|
64
|
-
const { clarity_version, ...rest } = abi;
|
|
65
|
-
const abiString = JSON.stringify(rest, null, 2);
|
|
66
|
-
|
|
67
|
-
const fileContents = `import { ClarityAbi } from '@clarigen/core';
|
|
68
|
-
|
|
69
|
-
// prettier-ignore
|
|
70
|
-
export const ${variableName}Interface: ClarityAbi = ${abiString};
|
|
71
|
-
`;
|
|
72
|
-
|
|
73
|
-
return fileContents;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export const generateIndexFile = ({
|
|
77
|
-
contractFile,
|
|
78
|
-
contractAddress,
|
|
79
|
-
contractName,
|
|
80
|
-
}: {
|
|
81
|
-
contractFile: string;
|
|
82
|
-
contractAddress: string;
|
|
83
|
-
contractName: string;
|
|
84
|
-
}) => {
|
|
85
|
-
const contractTitle = toCamelCase(contractName, true);
|
|
86
|
-
const varName = toCamelCase(contractName);
|
|
87
|
-
const contractType = `${contractTitle}Contract`;
|
|
88
|
-
const interfaceVar = `${contractTitle}Interface`;
|
|
89
|
-
|
|
90
|
-
const fileContents = `import { pureProxy, Contract } from '@clarigen/core';
|
|
91
|
-
import type { ${contractType} } from './types';
|
|
92
|
-
import { ${interfaceVar} } from './abi';
|
|
93
|
-
export type { ${contractType} } from './types';
|
|
94
|
-
|
|
95
|
-
export function ${varName}Contract(contractAddress: string, contractName: string) {
|
|
96
|
-
return pureProxy<${contractType}>({
|
|
97
|
-
abi: ${interfaceVar},
|
|
98
|
-
contractAddress,
|
|
99
|
-
contractName,
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export const ${varName}Info: Contract<${contractType}> = {
|
|
104
|
-
contract: ${varName}Contract,
|
|
105
|
-
address: '${contractAddress}',
|
|
106
|
-
contractFile: '${contractFile}',
|
|
107
|
-
name: '${contractName}',
|
|
108
|
-
abi: ${interfaceVar},
|
|
109
|
-
};
|
|
110
|
-
`;
|
|
111
|
-
|
|
112
|
-
return fileContents;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
export const generateTypesFile = (abi: ClarityAbi, contractName: string) => {
|
|
116
|
-
const name = toCamelCase(contractName, true);
|
|
117
|
-
const typings = makePureTypes(abi);
|
|
118
|
-
const fileContents = `import { ClarityTypes, ContractCalls } from '@clarigen/core';
|
|
119
|
-
|
|
120
|
-
// prettier-ignore
|
|
121
|
-
export interface ${name}Contract {
|
|
122
|
-
${typings}
|
|
123
|
-
}
|
|
124
|
-
`;
|
|
125
|
-
|
|
126
|
-
return fileContents;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
export const generateProjectIndexFile = (config: ConfigFile) => {
|
|
130
|
-
const imports: string[] = [
|
|
131
|
-
"import type { ContractInstances } from '@clarigen/core';",
|
|
132
|
-
];
|
|
133
|
-
const exports: string[] = [];
|
|
134
|
-
const contractMap: string[] = [];
|
|
135
|
-
|
|
136
|
-
let accounts = '';
|
|
137
|
-
if ('accounts' in config) {
|
|
138
|
-
const accountLines = Object.keys(config.accounts).map((key) => {
|
|
139
|
-
const account = config.accounts[key];
|
|
140
|
-
return `"${key}": {
|
|
141
|
-
mnemonic: "${account.mnemonic}",
|
|
142
|
-
balance: ${account.balance.toString()}n,
|
|
143
|
-
address: "${account.address}",
|
|
144
|
-
},`;
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
accounts = `\n\n// prettier-ignore
|
|
148
|
-
export const accounts = {
|
|
149
|
-
${accountLines.join('\n ')}
|
|
150
|
-
};`;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
config.contracts.forEach((contract) => {
|
|
154
|
-
const contractName = contract.name;
|
|
155
|
-
const contractVar = toCamelCase(contractName);
|
|
156
|
-
const contractInfo = `${contractVar}Info`;
|
|
157
|
-
const contractInterface = `${toCamelCase(contractName, true)}Contract`;
|
|
158
|
-
const dirName = dirname(contract.file);
|
|
159
|
-
const importPath = `'./${join(dirName || '.', contractName)}'`;
|
|
160
|
-
|
|
161
|
-
const _import = `import { ${contractInfo} } from ${importPath};`;
|
|
162
|
-
imports.push(_import);
|
|
163
|
-
|
|
164
|
-
const _export = `export type { ${contractInterface} } from ${importPath};`;
|
|
165
|
-
exports.push(_export);
|
|
166
|
-
|
|
167
|
-
const map = `${contractVar}: ${contractInfo},`;
|
|
168
|
-
contractMap.push(map);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
const contractsType = `\nexport type Contracts = ContractInstances<typeof contracts>;\n`;
|
|
172
|
-
|
|
173
|
-
const file = `${imports.join('\n')}
|
|
174
|
-
${exports.join('\n')}
|
|
175
|
-
${contractsType}
|
|
176
|
-
export const contracts = {
|
|
177
|
-
${contractMap.join('\n ')}
|
|
178
|
-
};${accounts}
|
|
179
|
-
`;
|
|
180
|
-
return file;
|
|
181
|
-
};
|
package/src/index.ts
DELETED
package/src/start.ts
DELETED
package/src/utils.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
generateIndexFile,
|
|
3
|
-
generateInterface,
|
|
4
|
-
generateInterfaceFile,
|
|
5
|
-
generateProjectIndexFile,
|
|
6
|
-
generateTypesFile,
|
|
7
|
-
} from './generate/files';
|
|
8
|
-
import {
|
|
9
|
-
NativeClarityBinProvider,
|
|
10
|
-
createClarityBin,
|
|
11
|
-
} from '@clarigen/native-bin';
|
|
12
|
-
import { resolve, relative, dirname } from 'path';
|
|
13
|
-
import { mkdir, writeFile } from 'fs/promises';
|
|
14
|
-
import { getProjectConfig } from './config';
|
|
15
|
-
|
|
16
|
-
export const generateFilesForContract = async ({
|
|
17
|
-
contractFile: _contractFile,
|
|
18
|
-
outputFolder,
|
|
19
|
-
provider,
|
|
20
|
-
contractAddress,
|
|
21
|
-
dirName,
|
|
22
|
-
contractName,
|
|
23
|
-
}: {
|
|
24
|
-
contractFile: string;
|
|
25
|
-
outputFolder: string;
|
|
26
|
-
provider: NativeClarityBinProvider;
|
|
27
|
-
contractAddress: string;
|
|
28
|
-
dirName?: string;
|
|
29
|
-
contractName: string;
|
|
30
|
-
}) => {
|
|
31
|
-
const contractFile = resolve(process.cwd(), _contractFile);
|
|
32
|
-
|
|
33
|
-
const abi = await generateInterface({
|
|
34
|
-
contractFile,
|
|
35
|
-
provider,
|
|
36
|
-
contractAddress,
|
|
37
|
-
contractName,
|
|
38
|
-
});
|
|
39
|
-
const typesFile = generateTypesFile(abi, contractName);
|
|
40
|
-
const indexFile = generateIndexFile({
|
|
41
|
-
contractFile: relative(process.cwd(), contractFile),
|
|
42
|
-
contractAddress: contractAddress,
|
|
43
|
-
contractName,
|
|
44
|
-
});
|
|
45
|
-
const abiFile = generateInterfaceFile({ contractName, abi });
|
|
46
|
-
|
|
47
|
-
const outputPath = resolve(outputFolder, dirName || '.', contractName);
|
|
48
|
-
await mkdir(outputPath, { recursive: true });
|
|
49
|
-
|
|
50
|
-
await writeFile(resolve(outputPath, 'abi.ts'), abiFile);
|
|
51
|
-
await writeFile(resolve(outputPath, 'index.ts'), indexFile);
|
|
52
|
-
await writeFile(resolve(outputPath, 'types.ts'), typesFile);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const generateProject = async (projectPath: string) => {
|
|
56
|
-
const configFile = await getProjectConfig(projectPath);
|
|
57
|
-
const { contractsDir, outputDir, contracts } = configFile;
|
|
58
|
-
const outputFolder = resolve(projectPath, outputDir);
|
|
59
|
-
const provider = await createClarityBin();
|
|
60
|
-
// this needs to be serial
|
|
61
|
-
for (const contract of contracts) {
|
|
62
|
-
const contractFile = resolve(projectPath, contractsDir, contract.file);
|
|
63
|
-
const dirName = dirname(contract.file);
|
|
64
|
-
await generateFilesForContract({
|
|
65
|
-
contractFile,
|
|
66
|
-
outputFolder: outputFolder,
|
|
67
|
-
provider,
|
|
68
|
-
contractAddress: contract.address,
|
|
69
|
-
dirName,
|
|
70
|
-
contractName: contract.name,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const indexFile = generateProjectIndexFile(configFile);
|
|
75
|
-
|
|
76
|
-
const indexPath = resolve(outputFolder, 'index.ts');
|
|
77
|
-
await writeFile(indexPath, indexFile);
|
|
78
|
-
};
|