From 925441ca6e04e3ef93cca780b599604e01ace229 Mon Sep 17 00:00:00 2001 From: ezsh <ezsh.junk@gmail.com> Date: Tue, 21 Jan 2020 11:03:47 +0100 Subject: [PATCH] Collect JS files from the 'js' dir for the Tweego module This allows us to escape the SugarCube eval() environment and write normal JavaScript without assigning to the window object. --- Makefile | 8 ++++++-- compile.bat | 6 ++++-- compile.sh | 4 +++- devTools/concatFiles.bat | 22 ++++++++++++++++++++++ devTools/concatFiles.sh | 13 +++++++++++++ {src => js}/002-config/fc-js-init.js | 11 +++-------- 6 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 devTools/concatFiles.bat create mode 100755 devTools/concatFiles.sh rename {src => js}/002-config/fc-js-init.js (69%) diff --git a/Makefile b/Makefile index 28ec6b6baba..253475c26f9 100644 --- a/Makefile +++ b/Makefile @@ -33,8 +33,12 @@ bin/%.html: bin/tmp git checkout -- src/gui/mainMenu/AlphaDisclaimer.tw mv $< $@ -bin/tmp: bin/ src/gui/mainMenu/AlphaDisclaimer.tw - $(TWEEGO) src/ --head devTools/head.html > $@ +bin/fc.js: bin/ + devTools/concatFiles.sh js/ '*.js' $@ + +bin/tmp: bin/fc.js src/gui/mainMenu/AlphaDisclaimer.tw + $(TWEEGO) --module=bin/fc.js --head devTools/head.html src/ > $@ + rm -f bin/fc.js src/gui/mainMenu/AlphaDisclaimer.tw: sed -Ei "s/build .releaseID/\0 commit $(COMMIT)/" $@ diff --git a/compile.bat b/compile.bat index ad3570dfc45..2a06b08270c 100644 --- a/compile.bat +++ b/compile.bat @@ -4,12 +4,14 @@ :: Set working directory pushd %~dp0 if not exist "bin\resources" mkdir bin\resources +CALL devTools/concatFiles.bat js/ "*.js" bin/fc.js :: Run the appropriate compiler for the user's CPU architecture. if %PROCESSOR_ARCHITECTURE% == AMD64 ( - CALL "%~dp0devTools\tweeGo\tweego_win64.exe" -o "%~dp0bin/FC_pregmod.html" --head devTools/head.html "%~dp0src" + CALL "%~dp0devTools\tweeGo\tweego_win64.exe" -o "%~dp0bin/FC_pregmod.html" --module=bin/fc.js --head devTools/head.html "%~dp0src" ) else ( - CALL "%~dp0devTools\tweeGo\tweego_win86.exe" -o "%~dp0bin/FC_pregmod.html" --head devTools/head.html "%~dp0src" + CALL "%~dp0devTools\tweeGo\tweego_win86.exe" -o "%~dp0bin/FC_pregmod.html" --module=bin/fc.js --head devTools/head.html "%~dp0src" ) +DEL bin\fc.js popd ECHO Done diff --git a/compile.sh b/compile.sh index dc9140f965b..4946c57147f 100755 --- a/compile.sh +++ b/compile.sh @@ -76,7 +76,9 @@ function compile { file="bin/FC_pregmod.html" fi - $TWEEGO_EXE -o $file src/ --head devTools/head.html || build_failed="true" + devTools/concatFiles.sh js/ '*.js' bin/fc.js + $TWEEGO_EXE -o $file --module=bin/fc.js --head devTools/head.html src/ || build_failed="true" + rm -f bin/fc.js if [ "$build_failed" = "true" ] then echoError "Build failed." diff --git a/devTools/concatFiles.bat b/devTools/concatFiles.bat new file mode 100644 index 00000000000..2a07ad8205c --- /dev/null +++ b/devTools/concatFiles.bat @@ -0,0 +1,22 @@ +@echo off + +:: See if we can find a git installation +setlocal enabledelayedexpansion + +for %%k in (HKCU HKLM) do ( + for %%w in (\ \Wow6432Node\) do ( + for /f "skip=2 delims=: tokens=1*" %%a in ('reg query "%%k\SOFTWARE%%wMicrosoft\Windows\CurrentVersion\Uninstall\Git_is1" /v InstallLocation 2^> nul') do ( + for /f "tokens=3" %%z in ("%%a") do ( + set GIT=%%z:%%b + set GITFOUND=yes + goto FOUND + ) + ) + ) +) + +:FOUND +if %GITFOUND% == yes ( + set "PATH=%GIT%bin;%PATH%" + bash devTools/concatFiles.sh "%1" "%2" "%3" +) diff --git a/devTools/concatFiles.sh b/devTools/concatFiles.sh new file mode 100755 index 00000000000..a1a8fd85866 --- /dev/null +++ b/devTools/concatFiles.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# $1: source dir +# $2: name wildcard +# #3: destination file + +rm -f "$3" +files=$(find "$1" -name "$2" -print) +files=$(echo "$files" | sort) +for f in $files; do + echo -e "\n/* ${f#$1} */\n" >> "$3" + cat "$f" >> "$3" +done diff --git a/src/002-config/fc-js-init.js b/js/002-config/fc-js-init.js similarity index 69% rename from src/002-config/fc-js-init.js rename to js/002-config/fc-js-init.js index 3c923124687..f01b00419cd 100644 --- a/src/002-config/fc-js-init.js +++ b/js/002-config/fc-js-init.js @@ -1,13 +1,8 @@ /* eslint-disable no-var */ -/* -* SugarCube executes scripts via eval() inside a closure. Thus to make App global, -* we declare it as a property of the window object. I don't know why 'App = {}' -* does not work. -*/ // @ts-ignore -window.App = { }; -// the same declaration for code parsers that don't like the line above -var App = window.App || {}; /* eslint-disable-line no-var*/ +"use strict"; + +var App = { }; App.Art = {}; App.Data = {}; -- GitLab