From ee5e6f757c53791807f70d607c5cd7ee402c4c2d Mon Sep 17 00:00:00 2001 From: Jakob Schneider <60233376+jaschdoc@users.noreply.github.com> Date: Tue, 29 Apr 2025 19:19:57 +0200 Subject: [PATCH 1/2] feat: add script for examples --- build-scripts/print-all-examples.py | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 build-scripts/print-all-examples.py diff --git a/build-scripts/print-all-examples.py b/build-scripts/print-all-examples.py new file mode 100644 index 0000000..4e26cb0 --- /dev/null +++ b/build-scripts/print-all-examples.py @@ -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) From c64791a456d6d831cbb21d47b8761ada70928499 Mon Sep 17 00:00:00 2001 From: Jakob Schneider <60233376+jaschdoc@users.noreply.github.com> Date: Tue, 29 Apr 2025 19:20:13 +0200 Subject: [PATCH 2/2] Update print-all-examples.py --- build-scripts/print-all-examples.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-scripts/print-all-examples.py b/build-scripts/print-all-examples.py index 4e26cb0..7aa5a47 100644 --- a/build-scripts/print-all-examples.py +++ b/build-scripts/print-all-examples.py @@ -3,7 +3,7 @@ ################# # # This script must be run inside the `examples` directory -# of the main `flix` repository. +# 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`