Moved build scripts into "scripts/", Updated readme
Update .gitignore, compile-clean.cmd, and 38 more files...
This commit is contained in:
26
scripts/compile-clean.cmd
Normal file
26
scripts/compile-clean.cmd
Normal file
@@ -0,0 +1,26 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
:: Going into the project's root directory
|
||||
cd /D "%~dp0\..\"
|
||||
|
||||
|
||||
:clean
|
||||
echo.
|
||||
echo Cleaning up the project
|
||||
echo -----------------------
|
||||
|
||||
:clean-php-minified
|
||||
echo Clearing old minified PHP files...
|
||||
pushd %CD%
|
||||
for /r "%CD%" %%F in (*.min.php) do (
|
||||
echo ^> Deleting "%%F"
|
||||
del "%%F"
|
||||
)
|
||||
echo ^> Done ^!
|
||||
popd
|
||||
|
||||
:clean-end
|
||||
|
||||
|
||||
:end
|
24
scripts/compile-content.cmd
Normal file
24
scripts/compile-content.cmd
Normal file
@@ -0,0 +1,24 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
:: Going into the script's directory
|
||||
cd /D "%~dp0"
|
||||
|
||||
|
||||
:content
|
||||
echo.
|
||||
echo Handling the raw content files
|
||||
echo ------------------------------
|
||||
|
||||
:content-compile-index
|
||||
echo Compiling index files...
|
||||
python content_index_maker.py ../content/raw_index/ ../content/index.json
|
||||
|
||||
:content-compile-items
|
||||
echo Compiling content item files...
|
||||
python content_item_converter.py ../content/raw_items/ ../content/items/
|
||||
|
||||
:content-end
|
||||
|
||||
|
||||
:end
|
44
scripts/compile-js-external.cmd
Normal file
44
scripts/compile-js-external.cmd
Normal file
@@ -0,0 +1,44 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
:: Going into the script's directory
|
||||
cd /D "%~dp0"
|
||||
|
||||
|
||||
:js-external
|
||||
echo.
|
||||
echo Handling external libraries
|
||||
echo ---------------------------
|
||||
|
||||
:js-external-decimaljs-minify
|
||||
echo Minifying Decimal.JS
|
||||
pushd %CD%
|
||||
cd %~dp0\..\resources\DecimalJs\10.4.3\
|
||||
echo ^> resources\DecimalJs\10.4.3\decimal.mjs
|
||||
call "%~dp0node_modules\.bin\terser" decimal.mjs -c -m --toplevel -o decimal.min.mjs
|
||||
cd %~dp0\..\resources\DecimalJsLight\2.5.1\
|
||||
echo ^> resources\DecimalJsLight\2.5.1\decimal.mjs
|
||||
call "%~dp0node_modules\.bin\terser" decimal.mjs -c -m --toplevel -o decimal.min.mjs
|
||||
popd
|
||||
|
||||
:js-external-highlightjs
|
||||
echo Handling HighlightJS
|
||||
pushd %CD%
|
||||
cd %~dp0\..\resources\HighlightJS\
|
||||
echo ^> Clearing old files
|
||||
del /Q /S /F highlight.js 2> nul 1> nul
|
||||
del /Q /S /F highlight.min.js 2> nul 1> nul
|
||||
echo ^> Installing dependencies
|
||||
call npm install > nul
|
||||
echo ^> Building for browsers
|
||||
node tools/build.js -t browser sql php c cpp vbnet java yaml css scss bash ini python shell dockerfile cmake purebasic csharp 1> nul
|
||||
echo ^> Moving final files
|
||||
robocopy %CD%\build %CD% highlight.js highlight.min.js 1> nul
|
||||
echo ^> Minifying used CSS files
|
||||
call "%~dp0node_modules\.bin\sass" src/styles/atom-one-dark.css:src/styles/atom-one-dark.min.css -q --style compressed
|
||||
popd
|
||||
|
||||
:js-external-end
|
||||
|
||||
|
||||
:end
|
32
scripts/compile-js-site.cmd
Normal file
32
scripts/compile-js-site.cmd
Normal file
@@ -0,0 +1,32 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
:: Going into the script's directory
|
||||
cd /D "%~dp0"
|
||||
|
||||
|
||||
:js-nibblepoker
|
||||
echo.
|
||||
echo Handling the website's libraries
|
||||
echo --------------------------------
|
||||
|
||||
:js-nibblepoker-minify
|
||||
echo Minifying nibblepoker.js
|
||||
pushd %CD%
|
||||
cd %~dp0\..\resources\NibblePoker\js\
|
||||
echo ^> resources\NibblePoker\js\nibblepoker.js
|
||||
call "%~dp0node_modules\.bin\terser" nibblepoker.js -c -m -o nibblepoker.min.js
|
||||
echo ^> resources\NibblePoker\js\nibblepoker-code.js
|
||||
call "%~dp0node_modules\.bin\terser" nibblepoker-code.js -c -m -o nibblepoker-code.min.js
|
||||
echo ^> resources\NibblePoker\js\nibblepoker-contributors.js
|
||||
call "%~dp0node_modules\.bin\terser" nibblepoker-contributors.js -c -m -o nibblepoker-contributors.min.js
|
||||
echo ^> resources\NibblePoker\js\nibblepoker-debug.js
|
||||
call "%~dp0node_modules\.bin\terser" nibblepoker-debug.js -c -m -o nibblepoker-debug.min.js
|
||||
echo ^> resources\NibblePoker\js\nibblepoker-splide.js
|
||||
call "%~dp0node_modules\.bin\terser" nibblepoker-splide.js -c -m -o nibblepoker-splide.min.js
|
||||
popd
|
||||
|
||||
:js-nibblepoker-end
|
||||
|
||||
|
||||
:end
|
28
scripts/compile-sass.cmd
Normal file
28
scripts/compile-sass.cmd
Normal file
@@ -0,0 +1,28 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
:: Going into the script's directory
|
||||
cd /D "%~dp0"
|
||||
|
||||
|
||||
:sass
|
||||
echo.
|
||||
echo Handling the SASS files
|
||||
echo -----------------------
|
||||
|
||||
:sass-compile
|
||||
echo Compiling SASS files...
|
||||
pushd %CD%
|
||||
cd %~dp0\..\resources\NibblePoker\scss\
|
||||
call "%~dp0node_modules\.bin\sass" nibblepoker.scss:../css/nibblepoker.css -q
|
||||
call "%~dp0node_modules\.bin\sass" nibblepoker.scss:../css/nibblepoker.min.css -q --style compressed
|
||||
call "%~dp0node_modules\.bin\sass" snowflakes.scss:../css/snowflakes.css -q
|
||||
call "%~dp0node_modules\.bin\sass" snowflakes.scss:../css/snowflakes.min.css -q --style compressed
|
||||
call "%~dp0node_modules\.bin\sass" debugger.scss:../css/debugger.css -q
|
||||
call "%~dp0node_modules\.bin\sass" debugger.scss:../css/debugger.min.css -q --style compressed
|
||||
popd
|
||||
|
||||
:sass-end
|
||||
|
||||
|
||||
:end
|
20
scripts/compile-strings.cmd
Normal file
20
scripts/compile-strings.cmd
Normal file
@@ -0,0 +1,20 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
:: Going into the script's directory
|
||||
cd /D "%~dp0"
|
||||
|
||||
|
||||
:lang
|
||||
echo.
|
||||
echo Handling the languages
|
||||
echo ----------------------
|
||||
|
||||
:lang-compile
|
||||
echo Compiling lang files...
|
||||
python compile_strings.py ../commons/strings/ ../commons/strings.json
|
||||
|
||||
:lang-end
|
||||
|
||||
|
||||
:end
|
15
scripts/compile.cmd
Normal file
15
scripts/compile.cmd
Normal file
@@ -0,0 +1,15 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
:: Going into the script's directory
|
||||
cd /D "%~dp0"
|
||||
|
||||
:: Running sub-scripts
|
||||
call "%~dp0compile-clean.cmd"
|
||||
call "%~dp0compile-strings.cmd"
|
||||
call "%~dp0compile-content.cmd"
|
||||
call "%~dp0compile-sass.cmd"
|
||||
call "%~dp0compile-js-site.cmd"
|
||||
call "%~dp0compile-js-external.cmd"
|
||||
|
||||
:end
|
84
scripts/compile_strings.py
Normal file
84
scripts/compile_strings.py
Normal file
@@ -0,0 +1,84 @@
|
||||
#!/bin/python
|
||||
|
||||
import argparse
|
||||
from datetime import datetime
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
# Including nicer-looking print function if possible.
|
||||
try:
|
||||
from rich import print
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
# Preparing and parsing launch arguments
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("input", help="Input folder where the strings are located.")
|
||||
parser.add_argument("output", help="Output file where the compiled strings will be saved.")
|
||||
|
||||
|
||||
# Fixing some issues with "argparse"
|
||||
def argparse_error(message):
|
||||
raise argparse.ArgumentError(None, message)
|
||||
|
||||
|
||||
# Parsing launch options
|
||||
parser.error = argparse_error
|
||||
try:
|
||||
args = parser.parse_args()
|
||||
except argparse.ArgumentError as err:
|
||||
print(f"\033[31m\033[1mError:\033[0m\033[31m {err.message.capitalize()}\033[39m")
|
||||
print("\033[36m\033[1mUsage:\033[0m\033[36m compile_strings.py <input_folder> <output_file>\033[39m")
|
||||
sys.exit(1)
|
||||
|
||||
# Checking the given options are valid
|
||||
if not (os.path.exists(args.input) and os.path.isdir(args.input)):
|
||||
print(f"\033[31m\033[1mError:\033[0m\033[31m The given input directory '{args.input}' doesn't exist or is a file !\033[39m")
|
||||
sys.exit(2)
|
||||
|
||||
if os.path.isdir(args.output):
|
||||
print(f"\033[31m\033[1mError:\033[0m\033[31m The given output '{args.output}' is a directory !\033[39m")
|
||||
sys.exit(3)
|
||||
|
||||
# Starting the process
|
||||
print(f"Compiling '{args.input}' to '{args.output}'...")
|
||||
input_folder = os.path.abspath(args.input)
|
||||
output_file = os.path.abspath(args.output)
|
||||
|
||||
lang_data = dict()
|
||||
lang_data["_compile_date"] = datetime.utcnow().isoformat() + "Z"
|
||||
|
||||
for main_dir_entry in os.listdir(input_folder):
|
||||
if main_dir_entry.startswith("_"):
|
||||
continue
|
||||
|
||||
print("> Processing '{}'".format(main_dir_entry))
|
||||
|
||||
if not os.path.isdir(os.path.join(input_folder, main_dir_entry)):
|
||||
continue
|
||||
|
||||
lang_data[main_dir_entry] = dict()
|
||||
|
||||
for sub_dir_entry in os.listdir(os.path.join(input_folder, main_dir_entry)):
|
||||
print("-> Checking '{}/{}'".format(main_dir_entry, sub_dir_entry))
|
||||
if not sub_dir_entry.endswith(".json"):
|
||||
continue
|
||||
|
||||
with open(os.path.join(input_folder, main_dir_entry, sub_dir_entry), "rb") as f:
|
||||
input_lang_data: dict = json.loads(f.read().decode("utf-8"))
|
||||
|
||||
for lang_record_key in input_lang_data.keys():
|
||||
lang_record_key: str
|
||||
if lang_record_key.startswith("_"):
|
||||
continue
|
||||
|
||||
lang_data[main_dir_entry][lang_record_key] = input_lang_data[lang_record_key]
|
||||
|
||||
try:
|
||||
os.remove(output_file)
|
||||
except IOError:
|
||||
pass
|
||||
|
||||
with open(output_file, "wb") as f:
|
||||
f.write(json.dumps(lang_data, separators=(',', ':')).encode("utf-8"))
|
87
scripts/compress.cmd
Normal file
87
scripts/compress.cmd
Normal file
@@ -0,0 +1,87 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
:compile
|
||||
call "%~dp0compile.cmd"
|
||||
|
||||
:compile-path-fix
|
||||
:: Going into the project's root directory
|
||||
cd /D "%~dp0\..\"
|
||||
|
||||
:compile-end
|
||||
|
||||
|
||||
:archive
|
||||
echo.
|
||||
echo Preparing a deployment archive
|
||||
echo ------------------------------
|
||||
|
||||
:archive-env-name
|
||||
echo Preparing name variable...
|
||||
set NP_ZIP_NAME=build_%date:~-4%-%date:~3,2%-%date:~0,2%.7z
|
||||
del /Q /S /F %NP_ZIP_NAME% 2> nul 1> nul
|
||||
echo ^> %NP_ZIP_NAME%
|
||||
|
||||
:archive-env-content
|
||||
echo Preparing environment variable...
|
||||
set NP_ZIP_CONTENT=
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "about/"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "commons/*.php"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "commons/strings.json"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "commons/DOM/"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "commons/content/"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "contact/"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "content/*.*"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "content/items/"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "contributors/"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "debug/"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "links/"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "privacy/"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/ExtGraphics/*.png"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/ExtGraphics/*.svg"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/ExtGraphics/*/*.png"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/ExtGraphics/*/*.svg"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/ExtGraphics/*/*/*.png"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/ExtGraphics/*/*/*.svg"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/ExtGraphics/*/*/*/*.png"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/ExtGraphics/*/*/*/*.svg"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/FontAwesomePro/5.15.3/"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/FontAwesomePro/6.5.1/"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/HighlightJS/highlight.min.js" "resources/HighlightJS/src/styles/atom-one-dark.min.css"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/NibblePoker/css/"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/NibblePoker/images/*.png"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/NibblePoker/images/*.jpg"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/NibblePoker/images/*.jpeg"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/NibblePoker/images/*.svg"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/NibblePoker/images/*.webp"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/NibblePoker/images/*/*.png"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/NibblePoker/images/*/*.jpg"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/NibblePoker/images/*/*.jpeg"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/NibblePoker/images/*/*.svg"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/NibblePoker/images/*/*.webp"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/NibblePoker/images/*/*/*.png"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/NibblePoker/images/*/*/*.jpg"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/NibblePoker/images/*/*/*.jpeg"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/NibblePoker/images/*/*/*.svg"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/NibblePoker/images/*/*/*.webp"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/NibblePoker/js/*.js"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/NibblePoker/sounds/"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/Quantum/"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "resources/SplideJs/dist/"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "tools/*"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "tools/items/*.json"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "tools/items/*/*"
|
||||
set NP_ZIP_CONTENT=%NP_ZIP_CONTENT% "./.htaccess" "./*.php" "./favicon.*" "./.env"
|
||||
::echo ^>%NP_ZIP_CONTENT%
|
||||
|
||||
:archive-7z
|
||||
echo Making '.7z' archive...
|
||||
7z a -mx9 "./%NP_ZIP_NAME%" %NP_ZIP_CONTENT% 1> nul
|
||||
echo ^> Done !
|
||||
|
||||
:archive-end
|
||||
|
||||
echo You can use the following command on the server:
|
||||
echo ^> 7z x %NP_ZIP_NAME% ^&^& chmod 755 -R ./ ^&^& rm %NP_ZIP_NAME%
|
||||
|
||||
:end
|
102
scripts/content_index_maker.py
Normal file
102
scripts/content_index_maker.py
Normal file
@@ -0,0 +1,102 @@
|
||||
#!/bin/python
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
# Importing YAML parser safely
|
||||
try:
|
||||
import yaml
|
||||
except ImportError:
|
||||
print("You need to install the 'PyYAML' module to continue !")
|
||||
sys.exit(10)
|
||||
|
||||
# Including nicer-looking print function if possible.
|
||||
try:
|
||||
from rich import print
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
# Preparing and parsing launch arguments
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("input", help="Input folder where the strings are located.")
|
||||
parser.add_argument("output", help="Output file where the compiled strings will be saved.")
|
||||
|
||||
|
||||
# Fixing some issues with "argparse"
|
||||
def argparse_error(message):
|
||||
raise argparse.ArgumentError(None, message)
|
||||
|
||||
|
||||
# Parsing launch options
|
||||
parser.error = argparse_error
|
||||
try:
|
||||
args = parser.parse_args()
|
||||
except argparse.ArgumentError as err:
|
||||
print(f"\033[31m\033[1mError:\033[0m\033[31m {err.message.capitalize()}\033[39m")
|
||||
print("\033[36m\033[1mUsage:\033[0m\033[36m content_index_maker.py <input_folder> <output_file>\033[39m")
|
||||
sys.exit(1)
|
||||
|
||||
# Checking the given options are valid
|
||||
if not (os.path.exists(args.input) and os.path.isdir(args.input)):
|
||||
print(f"\033[31m\033[1mError:\033[0m\033[31m The given input directory '{args.input}' doesn't exist or is a file !\033[39m")
|
||||
sys.exit(2)
|
||||
|
||||
if os.path.isdir(args.output):
|
||||
print(f"\033[31m\033[1mError:\033[0m\033[31m The given output '{args.output}' is a directory !\033[39m")
|
||||
sys.exit(3)
|
||||
|
||||
# Starting the process
|
||||
print(f"Compiling '{args.input}' to '{args.output}'...")
|
||||
input_folder = os.path.abspath(args.input)
|
||||
output_file = os.path.abspath(args.output)
|
||||
|
||||
index_data = list()
|
||||
|
||||
for index_entry_filename in os.listdir(input_folder):
|
||||
if index_entry_filename.startswith("_"):
|
||||
continue
|
||||
|
||||
print("> Processing '{}'".format(index_entry_filename))
|
||||
|
||||
# Loading the YAML data
|
||||
# See: https://github.com/yaml/pyyaml/issues/123#issuecomment-395431735
|
||||
with open(os.path.join(input_folder, index_entry_filename), 'rt', encoding='utf8') as f:
|
||||
index_entry_data = yaml.safe_load(f)
|
||||
|
||||
# Checking some stuff
|
||||
if type(index_entry_data) is not dict:
|
||||
raise ValueError(f"The data for '{index_entry_filename}' isn't a dict !")
|
||||
|
||||
if len(index_entry_data.keys()) < 1:
|
||||
raise ValueError(f"The '{index_entry_filename}' file is empty !")
|
||||
|
||||
# Fixing the ID
|
||||
_id_tmp = list(index_entry_data.keys())[0]
|
||||
index_entry_data[_id_tmp]["id"] = _id_tmp
|
||||
|
||||
# Un-nesting the data
|
||||
index_entry_data = index_entry_data[_id_tmp]
|
||||
|
||||
# Joining the preamble's lines
|
||||
if "preamble" not in index_entry_data.keys():
|
||||
raise ValueError(f"The 'preamble' field is missing from ''{index_entry_filename}' !")
|
||||
|
||||
if type(index_entry_data["preamble"]) is not dict:
|
||||
raise ValueError(f"The 'preamble' field for '{index_entry_filename}' isn't a dict !")
|
||||
|
||||
for preamble_lang_key in index_entry_data["preamble"].keys():
|
||||
if type(index_entry_data["preamble"][preamble_lang_key]) is list:
|
||||
index_entry_data["preamble"][preamble_lang_key] = "<br>".join(index_entry_data["preamble"][preamble_lang_key])
|
||||
|
||||
# Saving the data
|
||||
index_data.append(index_entry_data)
|
||||
|
||||
try:
|
||||
os.remove(output_file)
|
||||
except IOError:
|
||||
pass
|
||||
|
||||
with open(output_file, "wb") as f:
|
||||
f.write(json.dumps(index_data, separators=(',', ':'), ensure_ascii=False).encode("utf-8"))
|
84
scripts/content_item_converter.py
Normal file
84
scripts/content_item_converter.py
Normal file
@@ -0,0 +1,84 @@
|
||||
#!/bin/python
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
# Importing YAML parser safely
|
||||
try:
|
||||
import yaml
|
||||
except ImportError:
|
||||
print("You need to install the 'PyYAML' module to continue !")
|
||||
sys.exit(10)
|
||||
|
||||
# Including nicer-looking print function if possible.
|
||||
try:
|
||||
from rich import print
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
# Preparing and parsing launch arguments
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("input", help="Input folder where the strings are located.")
|
||||
parser.add_argument("output", help="Output folder where the converted files will be saved.")
|
||||
|
||||
|
||||
# Fixing some issues with "argparse"
|
||||
def argparse_error(message):
|
||||
raise argparse.ArgumentError(None, message)
|
||||
|
||||
|
||||
# Parsing launch options
|
||||
parser.error = argparse_error
|
||||
try:
|
||||
args = parser.parse_args()
|
||||
except argparse.ArgumentError as err:
|
||||
print(f"\033[31m\033[1mError:\033[0m\033[31m {err.message.capitalize()}\033[39m")
|
||||
print("\033[36m\033[1mUsage:\033[0m\033[36m content_index_maker.py <input_folder> <output_file>\033[39m")
|
||||
sys.exit(1)
|
||||
|
||||
# Checking the given options are valid
|
||||
if not (os.path.exists(args.input) and os.path.isdir(args.input)):
|
||||
print(f"\033[31m\033[1mError:\033[0m\033[31m The given input directory '{args.input}' doesn't exist or is a file !\033[39m")
|
||||
sys.exit(2)
|
||||
|
||||
if not (os.path.exists(args.output) and os.path.isdir(args.output)):
|
||||
print(f"\033[31m\033[1mError:\033[0m\033[31m The given output '{args.output}' is a directory !\033[39m")
|
||||
sys.exit(3)
|
||||
|
||||
|
||||
# Starting the process
|
||||
print(f"Compiling '{args.input}' to '{args.output}'...")
|
||||
input_folder = os.path.abspath(args.input)
|
||||
output_folder = os.path.abspath(args.output)
|
||||
|
||||
|
||||
for item_filename in os.listdir(input_folder):
|
||||
if item_filename.startswith("_") or not (item_filename.endswith(".yml") or item_filename.endswith(".yaml")):
|
||||
continue
|
||||
|
||||
print("> Processing '{}'".format(item_filename))
|
||||
|
||||
with open(os.path.join(input_folder, item_filename), 'r') as f:
|
||||
item_raw_data = yaml.safe_load(f)
|
||||
|
||||
# Grabbing the output ID
|
||||
output_id = list(item_raw_data.keys())[0]
|
||||
|
||||
# Un-nesting the data
|
||||
item_raw_data = item_raw_data[output_id]
|
||||
|
||||
# Converting content
|
||||
def process_content(content_element) -> dict:
|
||||
if type(content_element) is dict:
|
||||
pass
|
||||
return content_element
|
||||
|
||||
output_content = list()
|
||||
for content_item in item_raw_data["content"]:
|
||||
content_item = process_content(content_item)
|
||||
output_content.append(content_item)
|
||||
|
||||
item_raw_data["content"] = output_content
|
||||
print(item_raw_data)
|
27
scripts/legacy/compile-js-decimal.cmd
Normal file
27
scripts/legacy/compile-js-decimal.cmd
Normal file
@@ -0,0 +1,27 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
:: Going into the script's directory
|
||||
cd /D "%~dp0"
|
||||
|
||||
|
||||
:js-decimaljs
|
||||
echo.
|
||||
echo Handling DecimalJS library
|
||||
echo --------------------------
|
||||
|
||||
:js-decimaljs-minify
|
||||
echo Minifying Decimal.JS
|
||||
pushd %CD%
|
||||
cd %~dp0\resources\DecimalJs\10.4.3\
|
||||
echo ^> resources\DecimalJs\10.4.3\decimal.mjs
|
||||
call "%~dp0node_modules\.bin\terser" decimal.mjs -c -m --toplevel -o decimal.min.mjs
|
||||
cd %~dp0\resources\DecimalJsLight\2.5.1\
|
||||
echo ^> resources\DecimalJsLight\2.5.1\decimal.mjs
|
||||
call "%~dp0node_modules\.bin\terser" decimal.mjs -c -m --toplevel -o decimal.min.mjs
|
||||
popd
|
||||
|
||||
:js-decimaljs-end
|
||||
|
||||
|
||||
:end
|
20
scripts/legacy/compile-tools.cmd
Normal file
20
scripts/legacy/compile-tools.cmd
Normal file
@@ -0,0 +1,20 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
:: Going into the script's directory
|
||||
cd /D "%~dp0"
|
||||
|
||||
|
||||
:content
|
||||
echo.
|
||||
echo Handling the raw tools files
|
||||
echo -----------------------------
|
||||
|
||||
:content-compile-index
|
||||
echo Compiling index files...
|
||||
python content_index_maker.py ./tools/raw_index/ ./tools/index.json
|
||||
|
||||
:content-end
|
||||
|
||||
|
||||
:end
|
54
scripts/legacy/fix-import-path.js
Normal file
54
scripts/legacy/fix-import-path.js
Normal file
@@ -0,0 +1,54 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
|
||||
// Grabbing launch arguments
|
||||
if(process.argv.length !== 5) {
|
||||
console.error('!> Invalid syntax !');
|
||||
console.error('Use: node fix-import-path.js <input_file> <import_name> <replacement_file>');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const inputFile = process.argv[2];
|
||||
const inputImportName = process.argv[3];
|
||||
const inputReplacement = process.argv[4];
|
||||
|
||||
let filesToProcess = inputFile.split(";");
|
||||
|
||||
|
||||
// Fixing the files
|
||||
for(const fileToProcess of filesToProcess) {
|
||||
console.log("> Replacing '"+inputImportName+"' with '"+inputReplacement+"' in '"+fileToProcess+"' ...");
|
||||
|
||||
const inputFileLines = fs.readFileSync(fileToProcess).toString().split("\n");
|
||||
|
||||
if(inputFileLines == null) {
|
||||
console.error('!> Failed to read lines !');
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
const outputFileLines = [];
|
||||
|
||||
for(let inputLine of inputFileLines) {
|
||||
if(inputLine.startsWith("import") && inputLine.includes("from")) {
|
||||
inputLine = inputLine.split(/['"]+/);
|
||||
|
||||
// inputLine is now an array !
|
||||
//console.log(inputLine);
|
||||
|
||||
inputLine[inputLine.length - 2] = inputLine[inputLine.length - 2].replace(
|
||||
inputImportName, inputReplacement
|
||||
);
|
||||
|
||||
inputLine = inputLine.join("\"");
|
||||
}
|
||||
outputFileLines.push(inputLine);
|
||||
}
|
||||
|
||||
try {
|
||||
fs.unlinkSync(fileToProcess);
|
||||
fs.writeFileSync(fileToProcess, outputFileLines.join("\n"), "utf8");
|
||||
} catch(err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
46
scripts/legacy/minify-php.bat
Normal file
46
scripts/legacy/minify-php.bat
Normal file
@@ -0,0 +1,46 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
:: Going into the script's directory
|
||||
cd /D "%~dp0"
|
||||
|
||||
|
||||
:clean
|
||||
call "%~dp0clean.bat"
|
||||
:clean-end
|
||||
|
||||
|
||||
:php
|
||||
echo.
|
||||
echo Handling the PHP files
|
||||
echo -----------------------
|
||||
|
||||
:php-minify
|
||||
echo Minifying PHP files...
|
||||
pushd %CD%
|
||||
:: We minify the .php files to help with some weird spacing issues that cannot be fixed with CSS.
|
||||
:: This issue is usually handled by the reverse-proxy or a middleware, but since I need to export SPA(s), I can't rely on it
|
||||
for /r "%CD%" %%F in (*.php) do (
|
||||
set inputPath=%%F
|
||||
set outputPath=%%~dpnF.min.php
|
||||
|
||||
echo ^> "!inputPath!" =^> "!outputPath!"
|
||||
call "%~dp0node_modules\.bin\html-minifier-terser" --conservative-collapse --collapse-inline-tag-whitespace ^
|
||||
--collapse-whitespace --remove-comments --decode-entities --continue-on-parse-error -o "!outputPath!" "!inputPath!"
|
||||
)
|
||||
popd
|
||||
|
||||
:php-relink
|
||||
echo Linking minified PHP files together...
|
||||
pushd %CD%
|
||||
:: We change every .php extension to .min.php in all the minified file.
|
||||
:: I didn't use Python because it fails miserably with utf-8 symbols...
|
||||
for /r "%CD%" %%F in (*.min.php) do (
|
||||
node "%~dp0php-relinker.js" "%%F"
|
||||
)
|
||||
popd
|
||||
|
||||
:php-end
|
||||
|
||||
|
||||
:end
|
25
scripts/legacy/php-relinker.js
Normal file
25
scripts/legacy/php-relinker.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const fs = require('fs');
|
||||
|
||||
if (process.argv.length < 3) {
|
||||
console.log('Usage: node php-relinker.js <input_php_file>');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const inputFilePath = process.argv[2];
|
||||
console.log(">", inputFilePath);
|
||||
|
||||
function replaceExtension(match) {
|
||||
return match.replace('.php', '.min.php');
|
||||
}
|
||||
|
||||
try {
|
||||
const content = fs.readFileSync(inputFilePath, 'utf-8');
|
||||
const modifiedContent = content.replace(/include.*\.php/g, replaceExtension);
|
||||
fs.writeFileSync(inputFilePath, modifiedContent, 'utf-8');
|
||||
} catch (error) {
|
||||
if (error.code === 'ENOENT') {
|
||||
console.log('> Error: File not found.');
|
||||
} else {
|
||||
console.error('> Error: An error occurred =>', error.message);
|
||||
}
|
||||
}
|
23
scripts/nodejs-setup.cmd
Normal file
23
scripts/nodejs-setup.cmd
Normal file
@@ -0,0 +1,23 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
:: Going into the script's directory
|
||||
cd /D "%~dp0"
|
||||
|
||||
|
||||
:nodejs
|
||||
echo.
|
||||
echo Setting up NodeJS...
|
||||
echo --------------------
|
||||
|
||||
:nodejs-install
|
||||
echo Installing packages...
|
||||
pushd %CD%
|
||||
call npm install
|
||||
popd
|
||||
|
||||
|
||||
:nodejs-end
|
||||
|
||||
|
||||
:end
|
10
scripts/package.json
Normal file
10
scripts/package.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"devDependencies": {
|
||||
"minify": "^10.2.0",
|
||||
"rollup": "^3.27.2",
|
||||
"sass": "^1.63.6",
|
||||
"terser": "^5.19.0",
|
||||
"typescript": "^5.1.6",
|
||||
"html-minifier-terser": "^7.2.0"
|
||||
}
|
||||
}
|
22
scripts/python-setup.cmd
Normal file
22
scripts/python-setup.cmd
Normal file
@@ -0,0 +1,22 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
:: Going into the script's directory
|
||||
cd /D "%~dp0"
|
||||
|
||||
|
||||
:python
|
||||
echo.
|
||||
echo Setting up Python...
|
||||
echo --------------------
|
||||
|
||||
:python-install
|
||||
echo Installing packages...
|
||||
pushd %CD%
|
||||
call pip install -r requirements.txt
|
||||
popd
|
||||
|
||||
:python-end
|
||||
|
||||
|
||||
:end
|
1
scripts/requirements.txt
Normal file
1
scripts/requirements.txt
Normal file
@@ -0,0 +1 @@
|
||||
PyYAML>=6.0.1
|
Reference in New Issue
Block a user