fix(rewrite): setup.mjs should work on both Unix-like and Windows, fixed message function

This commit is contained in:
tecc 2023-09-15 15:04:22 +02:00
parent 1d3bfe52db
commit c1d6551301
No known key found for this signature in database
GPG Key ID: 622EEC5BAE5EBD3A

View File

@ -7,14 +7,20 @@ console.log("Setting up project");
let currentlySettingUp = "";
const url = new URL(import.meta.url);
const projectDir = path.dirname(
path.resolve(
url.pathname
.split("/")
.filter((v) => v && v.length > 0)
.join(path.sep)
)
let projectDir = path.resolve(
url.pathname
.split("/")
.filter((v) => v && v.length > 0)
.join(path.sep)
);
// This is a cheap but probably check to see if we're *not* on Windows.
if (path.sep !== "\\") {
// You could inline `path.sep` as "\" but why not go that extra mile
// We're already using it so
projectDir = path.sep + projectDir;
}
projectDir = path.dirname(projectDir);
const legacyDir = path.resolve(projectDir, "..");
function message(str) {
@ -22,7 +28,7 @@ function message(str) {
if (!!currentlySettingUp && currentlySettingUp.trim().length >= 0) {
prefix = `[${currentlySettingUp}]`;
}
console.log(" " + str);
console.log(" " + prefix + str);
}
console.log(`
@ -59,7 +65,7 @@ async function symlink(to, from) {
message(`Missing .env file for backend, creating from example.env`);
await fsp.cp(exampleEnvFile, envFile);
} else {
message(`[backend] Environment file already exists, continuing`);
message(`Environment file already exists, continuing`);
}
}