Skip to content

Commit 9250363

Browse files
restructure
1 parent 29e9dbd commit 9250363

File tree

2 files changed

+54
-40
lines changed

2 files changed

+54
-40
lines changed

packages/@pglt/pglt/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pglt",
3-
"version": "0.1.0",
3+
"version": "<placeholder>",
44
"bin": {
55
"pglt": "bin/pglt"
66
},
@@ -30,11 +30,11 @@
3030
"node": ">=20"
3131
},
3232
"optionalDependencies": {
33-
"@pglt/cli-aarch64-apple-darwin": "0.1.0",
34-
"@pglt/cli-aarch64-windows-msvc": "0.1.0",
35-
"@pglt/cli-aarch64-linux-gnu": "0.1.0",
36-
"@pglt/cli-x86_64-apple-darwin": "0.1.0",
37-
"@pglt/cli-x86_64-windows-msvc": "0.1.0",
38-
"@pglt/cli-x86_64-linux-gnu": "0.1.0"
33+
"@pglt/cli-aarch64-apple-darwin": "<placeholder>",
34+
"@pglt/cli-aarch64-windows-msvc": "<placeholder>",
35+
"@pglt/cli-aarch64-linux-gnu": "<placeholder>",
36+
"@pglt/cli-x86_64-apple-darwin": "<placeholder>",
37+
"@pglt/cli-x86_64-windows-msvc": "<placeholder>",
38+
"@pglt/cli-x86_64-linux-gnu": "<placeholder>"
3939
}
4040
}

packages/@pglt/pglt/scripts/generate-packages.mjs

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@ import * as fs from "node:fs";
33
import { pipeline } from "node:stream";
44
import { resolve } from "node:path";
55
import { fileURLToPath } from "node:url";
6-
import { format, promisify } from "node:util";
6+
import { promisify } from "node:util";
7+
const streamPipeline = promisify(pipeline);
78

89
const CLI_ROOT = resolve(fileURLToPath(import.meta.url), "../..");
910
const PACKAGES_PGLT_ROOT = resolve(CLI_ROOT, "..");
1011
const PGLT_ROOT = resolve(PACKAGES_PGLT_ROOT, "../..");
1112
const MANIFEST_PATH = resolve(CLI_ROOT, "package.json");
12-
13-
const streamPipeline = promisify(pipeline);
13+
const SUPPORTED_PLATFORMS = [
14+
"pc-windows-msvc",
15+
"apple-darwin",
16+
"unknown-linux-gnu",
17+
];
18+
const SUPPORTED_ARCHITECTURES = ["x86_64", "aarch64"];
1419

1520
async function downloadSchema(releaseTag, githubToken) {
1621
const assetUrl = `https://github.com/supabase-community/postgres_lsp/releases/download/${releaseTag}/schema.json`;
@@ -34,7 +39,7 @@ async function downloadSchema(releaseTag, githubToken) {
3439
console.log(`Downloaded schema for ${releaseTag}`);
3540
}
3641

37-
async function downloadAsset(platform, arch, os, releaseTag, githubToken) {
42+
async function downloadBinary(platform, arch, os, releaseTag, githubToken) {
3843
const buildName = getBuildName(platform, arch);
3944

4045
const assetUrl = `https://github.com/supabase-community/postgres_lsp/releases/download/${releaseTag}/${buildName}`;
@@ -59,31 +64,15 @@ async function downloadAsset(platform, arch, os, releaseTag, githubToken) {
5964
console.log(`Downloaded asset for ${buildName} (v${releaseTag})`);
6065
}
6166

62-
const rootManifest = JSON.parse(
63-
fs.readFileSync(MANIFEST_PATH).toString("utf-8")
64-
);
65-
66-
function getBinaryExt(os) {
67-
return os === "windows" ? ".exe" : "";
68-
}
67+
async function overwriteManifestVersions(releaseTag) {
68+
const manifestClone = structuredClone(rootManifest);
6969

70-
function getBinarySource(platform, arch, os) {
71-
const ext = getBinaryExt(os);
72-
return resolve(PGLT_ROOT, `${getBuildName(platform, arch)}${ext}`);
73-
}
74-
75-
function getBuildName(platform, arch) {
76-
return `pglt_${arch}-${platform}`;
77-
}
78-
79-
function getPackageName(platform, arch) {
80-
// trim the "unknown" from linux
81-
const name = platform.split("-").slice(-2).join("-");
82-
return `@pglt/cli-${arch}-${name}`;
83-
}
70+
manifestClone.version = releaseTag;
71+
for (const key in manifestClone.optionalDependencies) {
72+
manifestClone.optionalDependencies[key] = releaseTag;
73+
}
8474

85-
function getOs(platform) {
86-
return platform.split("-").find((_, idx) => idx === 1);
75+
fs.writeFileSync(MANIFEST_PATH, JSON.stringify(manifestClone, null, 2));
8776
}
8877

8978
function copyBinaryToNativePackage(platform, arch, os) {
@@ -158,6 +147,33 @@ function copySchemaToNativePackage(platform, arch) {
158147
fs.chmodSync(schemaTarget, 0o666);
159148
}
160149

150+
const rootManifest = JSON.parse(
151+
fs.readFileSync(MANIFEST_PATH).toString("utf-8")
152+
);
153+
154+
function getBinaryExt(os) {
155+
return os === "windows" ? ".exe" : "";
156+
}
157+
158+
function getBinarySource(platform, arch, os) {
159+
const ext = getBinaryExt(os);
160+
return resolve(PGLT_ROOT, `${getBuildName(platform, arch)}${ext}`);
161+
}
162+
163+
function getBuildName(platform, arch) {
164+
return `pglt_${arch}-${platform}`;
165+
}
166+
167+
function getPackageName(platform, arch) {
168+
// trim the "unknown" from linux and the "pc" from windows
169+
const name = platform.split("-").slice(-2).join("-");
170+
return `@pglt/cli-${arch}-${name}`;
171+
}
172+
173+
function getOs(platform) {
174+
return platform.split("-").find((_, idx) => idx === 1);
175+
}
176+
161177
(async function main() {
162178
const githubToken = process.env.GITHUB_TOKEN;
163179
const releaseTag = process.env.RELEASE_TAG;
@@ -166,15 +182,13 @@ function copySchemaToNativePackage(platform, arch) {
166182
assert(releaseTag, "RELEASE_TAG not defined!");
167183

168184
await downloadSchema(releaseTag, githubToken);
185+
overwriteManifestVersions(releaseTag);
169186

170-
const PLATFORMS = ["pc-windows-msvc", "apple-darwin", "unknown-linux-gnu"];
171-
const ARCHITECTURES = ["x86_64", "aarch64"];
172-
173-
for (const platform of PLATFORMS) {
187+
for (const platform of SUPPORTED_PLATFORMS) {
174188
const os = getOs(platform);
175189

176-
for (const arch of ARCHITECTURES) {
177-
await downloadAsset(platform, arch, os, releaseTag, githubToken);
190+
for (const arch of SUPPORTED_ARCHITECTURES) {
191+
await downloadBinary(platform, arch, os, releaseTag, githubToken);
178192
copyBinaryToNativePackage(platform, arch, os);
179193
copySchemaToNativePackage(platform, arch);
180194
}

0 commit comments

Comments
 (0)