Skip to content

Instantly share code, notes, and snippets.

@vncsna
Created November 25, 2021 15:09
Show Gist options
  • Save vncsna/18fdb859a0503d1747072b96fbbc039a to your computer and use it in GitHub Desktop.
Save vncsna/18fdb859a0503d1747072b96fbbc039a to your computer and use it in GitHub Desktop.
Create a `index.ts`
# Usage `python create_ts_index.py <folder-name>`
# TODO: Convert to bash script
import sys
from pathlib import Path
def create_index(rootpath):
rootpath = Path(rootpath)
indexpath = rootpath / "index.ts"
indexpath.unlink(True)
with indexpath.open("w") as file:
for filename in sorted(rootpath.glob("*")):
if filename.name[:-3] != 'index':
file.write(f"export * from './{filename.name[:-3]}';\n")
if __name__ == "__main__":
rootpath = sys.argv[1]
create_index(rootpath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment