Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions build-scripts/print-all-examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#################
### IMPORTANT ###
#################
#
# This script must be run inside the `examples` directory
# of the main Flix repository.
#
# It simply prints all the paths in the `examples` directory
# and prints them as json objects that can be inserted into `sampleFiles.mjs`
# file in this repository.
#
# Use as `python3 print-all-examples.py > out.json`
#

import os

def json_kv(key: str, val: str) -> str:
result = key
result += ': '
result += "'"
result += val
result += "',\n"
return result

def to_json(str: str) -> str:
result = ' {\n'
result += ' '
result += json_kv('name', str)
result += ' '
result += json_kv('file', str)
result += ' },'
return result

paths = []
for dirpath, _, files in os.walk('.'):
for file_name in files:
path = os.path.join(dirpath, file_name)
if path.endswith('.flix'):
paths.append(path.removeprefix('./'))

json_objects = []
for path in sorted(paths):
json_objects.append(to_json(path))

result = ',\n'.join(json_objects)
print(result)
Loading