Skip to content

Commit

Permalink
Check all exports are exported by index.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Siegrift committed Jan 26, 2020
1 parent 42d26cd commit f26ec11
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
30 changes: 30 additions & 0 deletions check_exports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from os import listdir
from re import match

with open('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:
print(f'Line "{e}" is not a valid export!')
exit(1)

g = m.groups()
if len(g) != 2 or f'./src/{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(['test', 'common'])
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"!')
3 changes: 3 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ export { default as map } from './src/map'
export { default as omit } from './src/omit'
export { default as pick } from './src/pick'
export { default as set } from './src/set'
export { default as update } from './src/update'
export { default as unset } from './src/unset'
export { default as fpSet } from './src/fpSet'
export { default as fpUnset } from './src/fpUnset'
export { default as fpUpdate } from './src/fpUpdate'
export { default as pipe } from './src/pipe'
export { default as compose } from './src/compose'
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
},
"husky": {
"hooks": {
"pre-commit": "yarn test && yarn clean && yarn docs && git add docs/*",
"pre-push": "yarn test"
"pre-commit": "python3 check_exports.py && yarn test && yarn clean && yarn docs && git add docs/*",
"pre-push": "python3 check_exports.py && yarn test"
}
},
"description": "Tsfunct is a **T**ype**S**cript **funct**ional library made directly for TS with its static typesystem in mind.",
Expand Down

0 comments on commit f26ec11

Please sign in to comment.