UNPKG

753 BPlain TextView Raw
1import { ClassDeclaration } from 'ts-simple-ast';
2
3import * as utils from './utils';
4import { getLibs } from './symbols';
5
6export interface Contracts {
7 [file: string]: string[];
8}
9
10export const scan = async (dir: string): Promise<Contracts> => {
11 const ast = await utils.getAst(dir);
12 const libs = getLibs(ast);
13 const smartContract = libs.SmartContract.getDeclarations()[0] as ClassDeclaration;
14 return smartContract.getDerivedClasses().reduce(
15 (acc, derived) => {
16 if (!derived.isAbstract()) {
17 const file = derived.getSourceFile().getFilePath();
18 if (acc[file] == null) {
19 acc[file] = [];
20 }
21 acc[file].push(derived.getNameOrThrow());
22 }
23
24 return acc;
25 },
26 {} as Contracts,
27 );
28};