Skip to content

Commit 67c0fc3

Browse files
committed
feat(project): generate project WIP
1 parent 5d9d836 commit 67c0fc3

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

scripts/generate-project.ts

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { writeFile } from "fs/promises";
2+
import { dirname, join, resolve } from "path";
3+
import { getContractNameFromPath } from "../shared/utils/contract-name-for-path";
4+
import { toCamelCase } from "../shared/utils/to-camel-case";
5+
import { CONTRACTS, GENERATION_FOLDER } from "./contracts";
6+
7+
export async function generateProjectIndexFile(contracts: CONTRACTS[]): Promise<void> {
8+
const imports: string[] = [];
9+
const exports: string[] = [];
10+
const contractMap: string[] = [];
11+
12+
// let accounts = '';
13+
// if ('accounts' in config) {
14+
// accounts = `\n\n// prettier-ignore
15+
// export const accounts = ${JSON.stringify(config.accounts, null, 2)};`;
16+
// }
17+
contracts.forEach((contract) => {
18+
const contractName = getContractNameFromPath(contract);
19+
const contractVar = toCamelCase(contractName);
20+
const contractInfo = `${contractVar}Info`;
21+
const contractInterface = `${toCamelCase(contractName, true)}Contract`;
22+
const dirName = dirname(contract);
23+
const importPath = `'./${join(dirName || '.', contractName)}'`;
24+
25+
const _import = `import { ${contractInfo} } from ${importPath};`;
26+
imports.push(_import);
27+
28+
const _export = `export type { ${contractInterface} } from ${importPath};`;
29+
exports.push(_export);
30+
31+
const map = `${contractVar}: ${contractInfo},`;
32+
contractMap.push(map);
33+
});
34+
35+
const file = `${imports.join('\n')}
36+
${exports.join('\n')}
37+
38+
export const contracts = {
39+
${contractMap.join('\n ')}
40+
};
41+
`;
42+
await writeFile(resolve(GENERATION_FOLDER, "index.ts"), file);
43+
}

0 commit comments

Comments
 (0)