From c1d6551301982a18578394debf0ca07394866457 Mon Sep 17 00:00:00 2001 From: tecc Date: Fri, 15 Sep 2023 15:04:22 +0200 Subject: [PATCH] fix(rewrite): `setup.mjs` should work on both Unix-like and Windows, fixed `message` function --- new/setup.mjs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/new/setup.mjs b/new/setup.mjs index d36fe9382..78cac6f0b 100644 --- a/new/setup.mjs +++ b/new/setup.mjs @@ -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`); } }