-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathinstall-viteplus.ts
More file actions
55 lines (46 loc) · 1.7 KB
/
install-viteplus.ts
File metadata and controls
55 lines (46 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { info, addPath } from "@actions/core";
import { exec } from "@actions/exec";
import { join } from "node:path";
import type { Inputs } from "./types.js";
import { DISPLAY_NAME } from "./types.js";
import { resolveVersion, restoreVpCache } from "./cache-vp.js";
import { getVitePlusHome } from "./utils.js";
const INSTALL_URL_SH = "https://viteplus.dev/install.sh";
const INSTALL_URL_PS1 = "https://viteplus.dev/install.ps1";
export async function installVitePlus(inputs: Inputs, nodeVersion: string): Promise<void> {
const { version } = inputs;
// Try to resolve version and restore from cache
const resolvedVersion = await resolveVersion(version);
if (resolvedVersion) {
const cacheHit = await restoreVpCache(resolvedVersion, nodeVersion);
if (cacheHit) {
ensureVitePlusBinInPath();
info(`${DISPLAY_NAME} restored from cache`);
return;
}
}
// Cache miss or resolution failed — install fresh
const installVersion = resolvedVersion || version;
info(`Installing ${DISPLAY_NAME}@${installVersion}...`);
const env = { ...process.env, VITE_PLUS_VERSION: installVersion };
let exitCode: number;
if (process.platform === "win32") {
exitCode = await exec(
"pwsh",
["-Command", `& ([scriptblock]::Create((irm ${INSTALL_URL_PS1})))`],
{ env },
);
} else {
exitCode = await exec("bash", ["-c", `curl -fsSL ${INSTALL_URL_SH} | bash`], { env });
}
if (exitCode !== 0) {
throw new Error(`Failed to install ${DISPLAY_NAME}. Exit code: ${exitCode}`);
}
ensureVitePlusBinInPath();
}
function ensureVitePlusBinInPath(): void {
const binDir = join(getVitePlusHome(), "bin");
if (!process.env.PATH?.includes(binDir)) {
addPath(binDir);
}
}