Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
richie0866 committed Jul 14, 2021
1 parent 417ec79 commit aeee96a
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 7 deletions.
4 changes: 0 additions & 4 deletions bin/bundle-prod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
67 changes: 67 additions & 0 deletions bin/bundle-test-min.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion bin/bundle-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion bin/test.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

local Rostruct = TS.initialize("init")

local function assertTypes(name, t, types)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down

0 comments on commit aeee96a

Please sign in to comment.