-
Notifications
You must be signed in to change notification settings - Fork 1
/
release.js
77 lines (65 loc) · 1.83 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import pkg from './package.json' assert {type: 'json'};
import fs from 'node:fs';
import {exec} from 'child_process';
import release from "release-it";
const isAlpha = true;
const allowedArgs = ['major', 'minor', 'patch'];
const args = process.argv.slice(2);
const options = args.reduce((acc, arg) => {
if (allowedArgs.includes(arg)) {
acc[arg] = true;
}
return acc;
}, {});
allowedArgs.forEach(arg => {
if (options[arg] === undefined) {
options[arg] = false;
}
});
const version = pkg.version;
const versionParts = version.split('.').map(part => parseInt(part, 10));
if (options.major) {
versionParts[0] += 1;
versionParts[1] = 0;
versionParts[2] = 0;
} else if (options.minor) {
versionParts[1] += 1;
versionParts[2] = 0;
} else if (options.patch) {
versionParts[2] += 1;
}
function upTauriVersion(newVersion) {
const tauriConf = "./src-tauri/tauri.conf.json";
const data = fs.readFileSync(tauriConf, "utf8");
const jsonData = JSON.parse(data);
jsonData.package.version = newVersion;
const newJson = JSON.stringify(jsonData, null, 2);
fs.writeFileSync(tauriConf, newJson, "utf8");
}
const newVersion = versionParts.join('.');
upTauriVersion(newVersion);
function tauriBuild() {
exec("pnpm tauri build", (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
}
});
}
tauriBuild();
const releaseName = isAlpha ? `Alpha ${versionParts[2]}` : `Version ${versionParts[0]}.${versionParts[1]}`;
const opts = {
increment: newVersion, releaseName: releaseName,
}
if (isAlpha) {
opts.preRelease = releaseName;
}
release({
...opts,
ci: true,
}).then(output => {
console.log(`🚀 Release : ${newVersion}`);
});