Skip to content

Commit 917a1b9

Browse files
committed
Prepare-publish script
1 parent 5b66e8a commit 917a1b9

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

scripts/ci/prepare-publish.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import fs from "fs";
2+
import path from "path";
3+
import { execSync } from "child_process";
4+
5+
const root = process.cwd();
6+
7+
const readJson = (relativePath) =>
8+
JSON.parse(fs.readFileSync(path.join(root, relativePath), "utf8"));
9+
10+
const writeJson = (relativePath, data) => {
11+
fs.writeFileSync(
12+
path.join(root, relativePath),
13+
JSON.stringify(data, null, 2) + "\n"
14+
);
15+
};
16+
17+
const publishList = (process.env.PUBLISH_PACKAGES || "all")
18+
.split(",")
19+
.map((value) => value.trim())
20+
.filter(Boolean);
21+
22+
const shouldUpdate = (pkgName) =>
23+
publishList.includes("all") || publishList.includes(pkgName);
24+
25+
const localVersions = {
26+
"appwrite-utils": readJson("packages/appwrite-utils/package.json").version,
27+
"appwrite-utils-helpers": readJson("packages/appwrite-utils-helpers/package.json").version,
28+
};
29+
30+
const getRemoteVersion = (packageName) => {
31+
try {
32+
const output = execSync(`npm view ${packageName} version`, {
33+
encoding: "utf8",
34+
stdio: ["ignore", "pipe", "ignore"],
35+
});
36+
return output.trim();
37+
} catch {
38+
return null;
39+
}
40+
};
41+
42+
const resolveDepVersion = (depName) => {
43+
if (shouldUpdate(depName)) {
44+
return localVersions[depName];
45+
}
46+
return getRemoteVersion(depName) || localVersions[depName];
47+
};
48+
49+
const setDepVersion = (pkg, depName, version) => {
50+
if (pkg.dependencies && depName in pkg.dependencies && version) {
51+
pkg.dependencies[depName] = `^${version}`;
52+
}
53+
};
54+
55+
const packagesToUpdate = [
56+
{ name: "appwrite-utils-helpers", path: "packages/appwrite-utils-helpers/package.json" },
57+
{ name: "appwrite-utils-cli", path: "packages/appwrite-utils-cli/package.json" },
58+
{ name: "appwrite-utils-mcp", path: "packages/appwrite-utils-mcp/package.json" },
59+
];
60+
61+
for (const pkgInfo of packagesToUpdate) {
62+
const pkg = readJson(pkgInfo.path);
63+
if (shouldUpdate(pkgInfo.name)) {
64+
const utilsVersion = resolveDepVersion("appwrite-utils");
65+
const helpersVersion = resolveDepVersion("appwrite-utils-helpers");
66+
setDepVersion(pkg, "appwrite-utils", utilsVersion);
67+
setDepVersion(pkg, "appwrite-utils-helpers", helpersVersion);
68+
writeJson(pkgInfo.path, pkg);
69+
}
70+
}

0 commit comments

Comments
 (0)