-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.js
56 lines (49 loc) · 1.88 KB
/
release.js
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
#!/usr/bin/env node
const fs = require("fs");
const { execSync } = require("child_process");
// Get version from command-line arguments
const version = process.argv[2].replace(/^v/, "");
if (!version) {
console.error("Usage: yarn release <version>");
process.exit(1);
}
// Check if tag already exists in Git
try {
const existingTags = execSync("git tag", { encoding: "utf8" }).split("\n");
if (existingTags.includes(version)) {
console.error(`Tag ${version} already exists in Git.`);
process.exit(1);
}
} catch (error) {
console.error("Error checking Git tags:", error.message);
process.exit(1);
}
const packageJsonPathWebsite = "./server/package.json";
const packageJsonPathBackend = "./client/package.json";
const updatePackageJson = (packageJsonPath) => {
// Update package.json version
try {
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
packageJson.version = version;
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 4) + "\n");
execSync(`git add ${packageJsonPath}`);
console.log(`Updated package.json version to ${version}`);
} catch (error) {
console.error("Error updating package.json:", error.message);
process.exit(1);
}
};
updatePackageJson(packageJsonPathWebsite);
updatePackageJson(packageJsonPathBackend);
// Create Git commit and tag
try {
execSync("git push origin", { stdio: "inherit" });
execSync(`git commit -m "Release v${version}"`, { stdio: "inherit" });
execSync("git push origin", { stdio: "inherit" });
execSync(`git tag -a v${version} -m "Version v${version}"`, { stdio: "inherit" });
execSync(`git push origin v${version}`, { stdio: "inherit" });
console.log(`Created Git tag v${version}`);
} catch (error) {
console.error("Error creating Git commit or tag:", error.message);
process.exit(1);
}