From aeee96ad3388450f9d1b4d691dfcb390a978a502 Mon Sep 17 00:00:00 2001 From: Richard <0866playback@gmail.com> Date: Tue, 13 Jul 2021 17:27:39 -0700 Subject: [PATCH] Update tests --- bin/bundle-prod.sh | 4 --- bin/bundle-test-min.sh | 67 ++++++++++++++++++++++++++++++++++++++++++ bin/bundle-test.sh | 2 +- bin/test.lua | 1 - package.json | 3 +- 5 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 bin/bundle-test-min.sh diff --git a/bin/bundle-prod.sh b/bin/bundle-prod.sh index 3176d2e..3c6e57e 100644 --- a/bin/bundle-prod.sh +++ b/bin/bundle-prod.sh @@ -14,10 +14,6 @@ wrap_function_decl() { # Replace '_G' variable with 'TS._G' content=${content//_G\[script\]/"TS._G[script]"} - # Replace compound operators - # content=${content//([a-zA-Z_][a-zA-Z0-9_]*)\s*(\.\.|\+|\-|\*|\/|\%|\^)\s*\=/"I HATE COMPOUND OPERATORS"} - # | sed -e 's/([a-zA-Z_][a-zA-Z0-9_]*)\s*(\.\.|\+|\-|\*|\/|\%|\^)\s*\=/IHATECOMPOPS/g' - # Add tab to newlines content=${content//${nl}/$nl } diff --git a/bin/bundle-test-min.sh b/bin/bundle-test-min.sh new file mode 100644 index 0000000..a25c4e9 --- /dev/null +++ b/bin/bundle-test-min.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash + +# Save newline as a tab +printf -v nl '\n' + +# Wrap the given file in a function declaration. +wrap_function_decl() { + local name="$1" + local file="$2" + + # Get file source + local content=$(cat $file) + + # Replace '_G' variable with 'TS._G' + content=${content//_G\[script\]/"TS._G[script]"} + + # Add tab to newlines + content=${content//${nl}/$nl } + + echo "${nl}TS.register(\"$file\", \"$name\", function() + local script = TS.get(\"$file\") + ${content} +end)" +} + +bundle=$(cat 'bin/runtime.lua') + +traverse() { + local dir="$1" + + # Do files first + for file in "$dir"/*; do + if [ -f "$file" ]; then + filename=$(basename -- "$file") + extension="${filename##*.}" + filename="${filename%%.*}" + if [ "$extension" = 'lua' ]; then + bundle+=$(wrap_function_decl "$filename" "$file") + fi + fi + done + + # Do folders last + for file in "$dir"/*; do + if [ -d "$file" ]; then + traverse "$file" + fi + done +} + +# Load all Lua files +traverse 'out' + +# End by returning the main module +bundle+="${nl}return TS.initialize(\"init\")" + +# Generate an output by removing all compound assignments and minifying the source +output=$(echo "${bundle}" | sed -E 's/(([A-z0-9_]+\.)*[A-z_][A-z0-9_]*)\s*(\.\.|\+|\-|\*|\/|\%|\^)\=/\1 = \1 \3/g' | npx luamin -c) + +# Finalize the test code +output="local Rostruct = (function() ${output} end)()${nl}${nl}" +output+="$nl$(cat 'bin/test.lua' | sed 's/local Rostruct = TS.initialize("init")//g')" + +# Clear any existing Rostruct.lua file +>Rostruct.lua + +echo "$output" >>Rostruct.lua diff --git a/bin/bundle-test.sh b/bin/bundle-test.sh index f170e4f..496648b 100644 --- a/bin/bundle-test.sh +++ b/bin/bundle-test.sh @@ -59,7 +59,7 @@ traverse() { traverse 'out' -bundle+="$nl$(cat 'bin/test.lua')" +bundle+="$nl$nl$(cat 'bin/test.lua')" >Rostruct.lua echo "${bundle}" >>Rostruct.lua diff --git a/bin/test.lua b/bin/test.lua index 642023c..b8b4e23 100644 --- a/bin/test.lua +++ b/bin/test.lua @@ -1,4 +1,3 @@ - local Rostruct = TS.initialize("init") local function assertTypes(name, t, types) diff --git a/package.json b/package.json index 6bee1c0..745b90e 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "prepublishOnly": "rbxtsc", "build:luau": "cross-env NODE_ENV=production TYPE=Luau rbxtsc --verbose --type=package", "build:prod": "chmod +x \"./bin/bundle-prod.sh\" && bash ./bin/bundle-prod.sh", - "build:test": "chmod +x \"./bin/bundle-test.sh\" && bash ./bin/bundle-test.sh" + "build:test": "chmod +x \"./bin/bundle-test.sh\" && bash ./bin/bundle-test.sh", + "build:test:min": "chmod +x \"./bin/bundle-test-min.sh\" && bash ./bin/bundle-test-min.sh" }, "keywords": [], "author": "",