-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlatest.ts
73 lines (62 loc) · 2.04 KB
/
latest.ts
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { execaCommand } from "execa";
import fs from "fs-extra";
import os from "node:os";
import path from "pathe";
import { fileURLToPath } from "url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
function getRemoveCommand(folders: string[]): string {
const platform = os.platform();
const folderList = folders.join(" ");
switch (platform) {
case "win32":
// PowerShell command
return `Remove-Item -Recurse -Force ${folders.map((f) => `"./${f}"`).join(", ")}`;
case "darwin":
case "linux":
// Unix-like systems
return `rm -rf ${folderList}`;
default:
// Fallback to basic command
return `Remove the following folders: ${folderList}`;
}
}
async function checkDistFolders(): Promise<boolean> {
const distFolders = ["dist-npm", "dist-jsr"];
const existingFolders: string[] = [];
for (const folder of distFolders) {
const folderPath = path.resolve(__dirname, folder);
if (await fs.pathExists(folderPath)) {
existingFolders.push(folder);
}
}
if (existingFolders.length > 0) {
console.error("\n❌ Cannot proceed with update!");
console.error(
"The following distribution folders exist and may cause unexpected behavior:",
);
existingFolders.forEach((folder) => console.error(` - ${folder}`));
console.error("\nPlease remove these folders first and try again:");
console.error(`${getRemoveCommand(existingFolders)}\n`);
return false;
}
return true;
}
async function updateDependencies() {
try {
// Check for dist folders first
if (!(await checkDistFolders())) {
process.exit(1);
}
console.log("🔄 Updating all dependencies to their latest versions...");
await execaCommand("bun update --latest", { stdio: "inherit" });
console.log("\n✅ All dependencies updated successfully!");
} catch (error) {
console.error(
"\n❌ Failed to update dependencies:",
error instanceof Error ? error.message : String(error),
);
process.exit(1);
}
}
// Run the update
await updateDependencies();