generated from garronej/ts-ci
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Grathfully exit if vite.config.ts not present
- Loading branch information
Showing
1 changed file
with
29 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<void> { | ||
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<void>(resolve => { | ||
child.on("exit", code => { | ||
if (code !== 0) { | ||
process.exit(code ?? -1); | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
|
||
console.log(`src/vite-env.d.ts has been updated`); | ||
} |