Skip to content
Snippets Groups Projects
Verified Commit e4b90599 authored by Zandor Smith's avatar Zandor Smith :computer:
Browse files

Set host in script 8.

parent 8a3085ca
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,29 @@ async function step08CreateViteConfig() {
fileContent = fileContent.replace("<PROXY_SOURCE>", proxySource);
fileContent = fileContent.replace("<PROXY_TARGET>", proxyTarget);
const packageJsonPath = "./package.json";
const packageJsonContent = fs.readFileSync(packageJsonPath, "utf8");
const packageJson = JSON.parse(packageJsonContent);
if(packageJson.scripts?.start?.includes("HOST=")) {
const startScript = packageJson.scripts.start;
const startScriptParts = startScript.split(" ");
const hostIndex = startScriptParts.findIndex(part => part.includes("HOST="));
if(hostIndex === -1) {
throw new Error("HOST= not found in start script");
}
const host = startScriptParts[hostIndex].replace("HOST=", "");
fileContent = fileContent.replace("<HOST>", host);
} else {
// Remove line in vite config with host: "<HOST>"
const viteConfigLines = fileContent.split("\n");
const hostLineIndex = viteConfigLines.findIndex(line => line.includes("host:"));
if(hostLineIndex === -1) {
throw new Error("host: not found in vite config");
}
viteConfigLines.splice(hostLineIndex, 1);
fileContent = viteConfigLines.join("\n");
}
fs.writeFileSync(targetPath, fileContent);
console.log("vite.config.ts created");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment