-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
assemblePredicates.ts
52 lines (41 loc) · 1.4 KB
/
assemblePredicates.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { join } from 'path';
import type { Abi } from '../abi/Abi';
import type { IFile } from '../index';
import { renderCommonTemplate } from '../templates/common/common';
import { renderIndexTemplate } from '../templates/common/index';
import { renderFactoryTemplate } from '../templates/predicate/factory';
/**
* Render all Predicate-related templates and returns
* an array of `IFile` with them all. For here on,
* the only thing missing is to write them to disk.
*/
export function assemblePredicates(params: { abis: Abi[]; outputDir: string }) {
const { abis, outputDir } = params;
const files: IFile[] = [];
const usesCommonTypes = abis.find((a) => a.commonTypesInUse.length > 0);
abis.forEach((abi) => {
const { name } = abi;
const factoryFilepath = `${outputDir}/factories/${name}__factory.ts`;
const factory: IFile = {
path: factoryFilepath,
contents: renderFactoryTemplate({ abi }),
};
files.push(factory);
});
// Includes index file
const indexFile: IFile = {
path: `${outputDir}/index.ts`,
contents: renderIndexTemplate({ abis }),
};
files.push(indexFile);
// Conditionally includes `common.d.ts` file if needed
if (usesCommonTypes) {
const commonsFilepath = join(outputDir, 'common.d.ts');
const file: IFile = {
path: commonsFilepath,
contents: renderCommonTemplate(),
};
files.push(file);
}
return files;
}