forked from kavinsood/yaos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-server-release.mjs
More file actions
113 lines (100 loc) · 3.45 KB
/
build-server-release.mjs
File metadata and controls
113 lines (100 loc) · 3.45 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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { execFileSync } from "node:child_process";
import { cpSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
const rootDir = resolve(".");
const outputDir = resolve(rootDir, "dist/release-assets");
const tempDir = mkdtempSync(join(tmpdir(), "yaos-server-release-"));
const serverTempDir = join(tempDir, "server");
const rootPackage = JSON.parse(readFileSync(resolve(rootDir, "package.json"), "utf8"));
const pluginManifest = JSON.parse(readFileSync(resolve(rootDir, "manifest.json"), "utf8"));
const serverPackage = JSON.parse(readFileSync(resolve(rootDir, "server/package.json"), "utf8"));
const serverVersionSource = readFileSync(resolve(rootDir, "server/src/version.ts"), "utf8");
function readStringConst(source, name) {
const match = source.match(new RegExp(`export const ${name} = "([^"]*)";`));
if (!match) {
throw new Error(`Unable to read string constant ${name} from server/src/version.ts`);
}
return match[1];
}
function readBooleanConst(source, name) {
const match = source.match(new RegExp(`export const ${name} = (true|false);`));
if (!match) {
throw new Error(`Unable to read boolean constant ${name} from server/src/version.ts`);
}
return match[1] === "true";
}
const serverVersion = readStringConst(serverVersionSource, "SERVER_VERSION");
const minCompatibleServerVersionForPlugin = readStringConst(
serverVersionSource,
"SERVER_MIN_COMPATIBLE_SERVER_VERSION_FOR_PLUGIN",
);
const minCompatiblePluginVersionForServer = readStringConst(
serverVersionSource,
"SERVER_MIN_COMPATIBLE_PLUGIN_VERSION_FOR_SERVER",
);
const migrationRequired = readBooleanConst(
serverVersionSource,
"SERVER_MIGRATION_REQUIRED",
);
if (serverPackage.version !== serverVersion) {
throw new Error(
`server/package.json version (${serverPackage.version}) does not match SERVER_VERSION (${serverVersion})`,
);
}
const updateManifest = {
latestServerVersion: serverVersion,
latestPluginVersion: pluginManifest.version,
releaseType: migrationRequired ? "migration-required" : "compatible",
migrationRequired,
autoUpdateEligible: false,
minCompatibleServerVersionForPlugin,
minCompatiblePluginVersionForServer,
upgradeOrder: "either",
releaseNotesUrl: `https://github.com/kavinsood/yaos/releases/tag/${rootPackage.version}`,
upgradeGuideUrl: "https://github.com/kavinsood/yaos#updating-your-server",
};
const serverZipManifest = {
serverVersion,
pluginVersion: pluginManifest.version,
protectedFiles: ["wrangler.toml"],
updateOwnedPaths: [
".gitlab-ci.yml",
"package.json",
"package-lock.json",
"scripts",
"tsconfig.json",
"src",
],
migrationRequired,
};
mkdirSync(outputDir, { recursive: true });
mkdirSync(serverTempDir, { recursive: true });
for (const relativePath of [
"package.json",
"package-lock.json",
".gitlab-ci.yml",
"scripts",
"tsconfig.json",
"wrangler.toml",
"src",
]) {
cpSync(resolve(rootDir, "server", relativePath), join(serverTempDir, relativePath), {
recursive: true,
});
}
writeFileSync(
join(serverTempDir, "yaos-server-manifest.json"),
`${JSON.stringify(serverZipManifest, null, 2)}\n`,
);
writeFileSync(
resolve(outputDir, "update-manifest.json"),
`${JSON.stringify(updateManifest, null, 2)}\n`,
);
const zipPath = resolve(outputDir, "yaos-server.zip");
rmSync(zipPath, { force: true });
execFileSync("zip", ["-qr", zipPath, "."], {
cwd: serverTempDir,
stdio: "inherit",
});
rmSync(tempDir, { recursive: true, force: true });