From 4291fbb31eb81abf90213a5a71ae6c53b9d92bcd Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Sat, 7 Dec 2024 18:00:00 +0100 Subject: [PATCH] Grathfully exit if vite.config.ts not present --- src/bin/updateTypes.ts | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/bin/updateTypes.ts b/src/bin/updateTypes.ts index 460666a..96792cf 100644 --- a/src/bin/updateTypes.ts +++ b/src/bin/updateTypes.ts @@ -1,12 +1,38 @@ import * as child_process from "child_process"; import { updateTypingScriptEnvName } from "../constants"; -export function updateTypes() { - child_process.execSync("npx vite", { - "env": { +export async function updateTypes(): Promise { + const child = child_process.spawn("npx", ["vite", "dev"], { + env: { ...process.env, [updateTypingScriptEnvName]: "" + }, + shell: true + }); + + child.stdout.on("data", data => { + const dataStr = data.toString("utf8"); + + if (dataStr.includes("VITE") && dataStr.includes("ready in")) { + console.log( + "vite-envs vite plugin not enabled, skipping update-types (Ok in Docker build stage)" + ); + process.exit(0); } + + process.stdout.write(data); }); + + child.stderr.on("data", data => process.stderr.write(data)); + + await new Promise(resolve => { + child.on("exit", code => { + if (code !== 0) { + process.exit(code ?? -1); + } + resolve(); + }); + }); + console.log(`src/vite-env.d.ts has been updated`); }