This repository was archived by the owner on Sep 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathversion.ts
91 lines (75 loc) · 2.69 KB
/
version.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import main from "../package.json";
import cli from "../packages/cli/package.json";
import core from "../packages/core/package.json";
import cpp from "../packages/llama-cpp/package.json";
import rwkv from "../packages/rwkv-cpp/package.json";
import example from "../example/package.json";
import semver from "semver";
import path from "path";
import fs from "fs";
import { fileURLToPath } from "url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const newVersion = process.argv[2];
if (!newVersion) {
console.error("No version specified");
process.exit(1);
}
if (!semver.valid(newVersion)) {
console.error("Invalid version specified");
process.exit(1);
}
const newVersionIsGreaterThanAll = [main, cli, example, core, cpp, rwkv].every(
(pkg) => semver.gte(newVersion, pkg.version)
);
if (!newVersionIsGreaterThanAll) {
console.error("New version must be greater than all existing versions");
process.exit(1);
}
const backendPackages = { core, "llama-cpp": cpp, "rwkv-cpp": rwkv };
const updateVersionForBackend = (
backend: "core" | "llama-cpp" | "rwkv-cpp"
) => {
backendPackages[backend].version = newVersion;
// write backend package.json
fs.writeFileSync(
path.join(__dirname, `../packages/${backend}/package.json`),
JSON.stringify(backendPackages[backend], null, 2)
);
main.devDependencies[`@llama-node/${backend}`] = newVersion;
main.optionalDependencies[`@llama-node/${backend}`] = newVersion;
main.peerDependencies[`@llama-node/${backend}`] = newVersion;
example.dependencies[`@llama-node/${backend}`] = newVersion;
};
console.log("Current versions: ");
console.log(`main: ${main.version}`);
console.log(`cli: ${cli.version}`);
console.log(`example: ${example.version}`);
console.log(`New version: ${newVersion}`);
console.log("Updating versions...");
main.version = newVersion;
cli.version = newVersion;
example.version = newVersion;
main.dependencies["@llama-node/cli"] = newVersion;
main.devDependencies["@llama-node/cli"] = newVersion;
main.peerDependencies["@llama-node/cli"] = newVersion;
cli.dependencies["@llama-node/core"] = newVersion;
example.dependencies["llama-node"] = newVersion;
updateVersionForBackend("core");
updateVersionForBackend("llama-cpp");
updateVersionForBackend("rwkv-cpp");
// write main package.json
fs.writeFileSync(
path.join(__dirname, "../package.json"),
JSON.stringify(main, null, 2)
);
// write cli package.json
fs.writeFileSync(
path.join(__dirname, "../packages/cli/package.json"),
JSON.stringify(cli, null, 2)
);
// write example package.json
fs.writeFileSync(
path.join(__dirname, "../example/package.json"),
JSON.stringify(example, null, 2)
);
console.log("Done!");