/
files.ts
44 lines (36 loc) · 1.01 KB
/
files.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
const fs = require('fs-extra')
const path = require('path')
export const listFiles = async (folderName: string) => {
const folderPath = path.resolve('src', folderName)
if (!(await fs.pathExists(folderPath)))
throw new Error(`path not found: ${folderPath}`)
let files
try {
files = await fs.readdir(folderPath)
} catch (err) {
console.log(err)
}
return files
}
export const parseExports = async (folderName: string) => {
const files = await listFiles(folderName)
const exportsList = files
.filter((f: string) => f.includes('.json'))
.map((f: string) => `./${folderName}/${f}`)
// make sure all paths exists
await Promise.all(
exportsList.map((f: string) => fs.pathExists(path.resolve(f)))
)
return exportsList
}
export const getAbiPaths = async () => {
const folders = [
'abis/PublicLock',
'abis/Unlock',
'abis/UnlockDiscountToken',
'abis/Governor',
'abis/utils',
]
const paths = await Promise.all(folders.map((f) => parseExports(f)))
return paths
}