-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck-exports.py
32 lines (26 loc) · 987 Bytes
/
check-exports.py
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
from os import listdir
from re import match
with open('src/index.ts') as f:
exports = [x.strip() for x in f.readlines()]
# verify exports structure (and create the export names)
exportNames = set()
for e in exports:
m = match("^export { default as (.*) } from '(.*)';$", e)
if not m:
# allow export * for modules that have multiple exports
if match("^export \* from '(.*)';$", e): continue
print(f'Line "{e}" is not a valid export!')
exit(1)
g = m.groups()
if len(g) != 2 or f'./{g[0]}' != g[1]:
print(f'Export "{e}" doesn\'t match the library folder name!')
exit(1)
exportNames.add(g[0])
# verify that all helpers are exported (except the ignored ones)
ignored = set(['common', 'go', 'index.ts', 'tsconfig.json'])
srcFolders = set(listdir('src'))
diff = srcFolders.difference(ignored.union(exportNames))
if len(diff) != 0:
print(f'Found non-exported folder names {diff}!')
exit(1)
print('All helpers are correctly exported by "index.ts"!')