Moved build scripts into "scripts/", Updated readme

Update .gitignore, compile-clean.cmd, and 38 more files...
This commit is contained in:
2024-04-18 18:00:28 +02:00
parent e544271ffa
commit c8bf68fa2d
22 changed files with 73 additions and 25 deletions

View 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

View 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

View 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);
}
}

View 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

View 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);
}
}