History

Replace repository contents with v4 snapshot

Rhys Sullivan committed 7 months ago

Commit 4fcdba41 parent be4bbf5865 files · +36247 −404676Browse files

Showing the changes to scripts (1 of 865 files). Show all

Unified · Split

scripts/release/sync-versions.mjs+85−0
@@ -0,0 +1,85 @@
1+import { readFile, readdir, writeFile } from "node:fs/promises";
2+import { existsSync } from "node:fs";
3+import { dirname, join, resolve } from "node:path";
4+import { fileURLToPath } from "node:url";
5+
6+const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), "../..");
7+const sourcePackagePath = join(repoRoot, "apps/cli/package.json");
8+const skippedPackageNames = new Set([
9+ "@executor/runtime-deno-subprocess",
10+]);
11+
12+const readJson = async (path) => JSON.parse(await readFile(path, "utf8"));
13+
14+const writeJson = async (path, value) => {
15+ await writeFile(path, `${JSON.stringify(value, null, 2)}\n`);
16+};
17+
18+const collectPackageJsonPaths = async () => {
19+ const paths = [join(repoRoot, "package.json")];
20+
21+ for (const entry of await readdir(join(repoRoot, "apps"), { withFileTypes: true })) {
22+ if (!entry.isDirectory()) continue;
23+ const candidate = join(repoRoot, "apps", entry.name, "package.json");
24+ if (existsSync(candidate)) {
25+ paths.push(candidate);
26+ }
27+ }
28+
29+ const packagesUi = join(repoRoot, "packages/ui/package.json");
30+ if (existsSync(packagesUi)) {
31+ paths.push(packagesUi);
32+ }
33+
34+ for (const group of await readdir(join(repoRoot, "packages"), { withFileTypes: true })) {
35+ if (!group.isDirectory() || group.name === "ui") continue;
36+ const groupDir = join(repoRoot, "packages", group.name);
37+
38+ for (const entry of await readdir(groupDir, { withFileTypes: true })) {
39+ if (!entry.isDirectory()) continue;
40+ const candidate = join(groupDir, entry.name, "package.json");
41+ if (existsSync(candidate)) {
42+ paths.push(candidate);
43+ }
44+ }
45+ }
46+
47+ return paths;
48+};
49+
50+const main = async () => {
51+ const sourcePackage = await readJson(sourcePackagePath);
52+ const version = sourcePackage.version;
53+
54+ if (typeof version !== "string" || version.length === 0) {
55+ throw new Error(`Missing version in ${sourcePackagePath}`);
56+ }
57+
58+ const packageJsonPaths = await collectPackageJsonPaths();
59+ const updated = [];
60+
61+ for (const path of packageJsonPaths) {
62+ if (path === sourcePackagePath) continue;
63+
64+ const pkg = await readJson(path);
65+ if (typeof pkg.version !== "string") continue;
66+ if (skippedPackageNames.has(pkg.name)) continue;
67+ if (pkg.version === version) continue;
68+
69+ pkg.version = version;
70+ await writeJson(path, pkg);
71+ updated.push(path);
72+ }
73+
74+ if (updated.length === 0) {
75+ console.log(`All package versions already match ${version}.`);
76+ return;
77+ }
78+
79+ console.log(`Synced ${updated.length} package version(s) to ${version}:`);
80+ for (const path of updated) {
81+ console.log(`- ${path.replace(`${repoRoot}/`, "")}`);
82+ }
83+};
84+
85+await main();