normalize path on builder
Some checks failed
Build and Release / build-and-release (push) Failing after 30s
Some checks failed
Build and Release / build-and-release (push) Failing after 30s
This commit is contained in:
16
builder.js
16
builder.js
@@ -6,11 +6,7 @@ import path from "node:path";
|
||||
const DEV = process.argv.includes("--dev");
|
||||
|
||||
const escape = (str) =>
|
||||
str
|
||||
.replace(/\s+/g, " ")
|
||||
.trim()
|
||||
.replace(/"/g, '\\"')
|
||||
.replace(/\$/g, "\\$");
|
||||
str.replace(/\s+/g, " ").trim().replace(/"/g, '\\"').replace(/\$/g, "\\$");
|
||||
|
||||
function build() {
|
||||
const data = fs.readFileSync("./script.php", "utf8");
|
||||
@@ -18,7 +14,7 @@ function build() {
|
||||
const mountedFiles = new Set();
|
||||
|
||||
const result = data.replace(mountRegex, (_match, file) => {
|
||||
let fileContent = fs.readFileSync(file, "utf8");
|
||||
let fileContent = fs.readFileSync(path.normalize(file), "utf8");
|
||||
mountedFiles.add(path.resolve(file));
|
||||
|
||||
const inlinePhpVarRegex = /"<<BUILDER_PHP_VAR\((?<varName>.*?)\)>>"/g;
|
||||
@@ -36,7 +32,7 @@ function build() {
|
||||
for (const { escapedPlaceholder, varName } of vars) {
|
||||
fileContent = fileContent.replace(
|
||||
escapedPlaceholder,
|
||||
`" . ${varName} . "`
|
||||
`" . ${varName} . "`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -58,7 +54,9 @@ if (DEV) {
|
||||
function watchFile(file) {
|
||||
if (watchers.has(file)) return;
|
||||
const watcher = fs.watch(file, () => {
|
||||
console.log(`[${new Date().toLocaleTimeString()}] Changed: ${path.relative(".", file)}`);
|
||||
console.log(
|
||||
`[${new Date().toLocaleTimeString()}] Changed: ${path.relative(".", file)}`,
|
||||
);
|
||||
rebuild();
|
||||
});
|
||||
watchers.set(file, watcher);
|
||||
@@ -91,4 +89,4 @@ if (DEV) {
|
||||
syncWatchers(watchedFiles);
|
||||
|
||||
console.log("Watching for changes… (Ctrl+C to stop)");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user