openkrew 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core-bootstrap.mjs +31 -118
- package/package.json +1 -1
package/core-bootstrap.mjs
CHANGED
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* OpenKrew .NET Core Bootstrapper
|
|
5
5
|
*
|
|
6
|
-
* Downloads
|
|
7
|
-
*
|
|
8
|
-
* GitHub Releases. Subsequent runs use the cached binary directly.
|
|
6
|
+
* Downloads the platform-specific self-contained binary from S3.
|
|
7
|
+
* Subsequent runs use the cached binary directly.
|
|
9
8
|
*
|
|
10
9
|
* This file is invoked by openkrew.mjs when the user runs `openkrew`.
|
|
11
10
|
*/
|
|
@@ -21,13 +20,13 @@ import {
|
|
|
21
20
|
rmSync,
|
|
22
21
|
} from "node:fs";
|
|
23
22
|
import { homedir, platform, arch } from "node:os";
|
|
24
|
-
import { join
|
|
23
|
+
import { join } from "node:path";
|
|
25
24
|
import { pipeline } from "node:stream/promises";
|
|
26
25
|
|
|
27
26
|
const OPENKREW_DIR = join(homedir(), ".openkrew");
|
|
28
27
|
const BIN_DIR = join(OPENKREW_DIR, "bin");
|
|
29
28
|
const VERSION_FILE = join(BIN_DIR, ".version");
|
|
30
|
-
const
|
|
29
|
+
const S3_BASE = "https://openkrew-releases.s3.amazonaws.com";
|
|
31
30
|
const PACKAGE_VERSION = (() => {
|
|
32
31
|
try {
|
|
33
32
|
const pkg = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8"));
|
|
@@ -38,34 +37,28 @@ const PACKAGE_VERSION = (() => {
|
|
|
38
37
|
})();
|
|
39
38
|
|
|
40
39
|
/**
|
|
41
|
-
* Resolves the platform-specific runtime identifier
|
|
40
|
+
* Resolves the platform-specific runtime identifier.
|
|
42
41
|
*/
|
|
43
42
|
function getRuntimeId() {
|
|
44
43
|
const p = platform();
|
|
45
44
|
const a = arch();
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
if (p === "win32" && a === "arm64") {
|
|
63
|
-
return "win-arm64";
|
|
46
|
+
const map = {
|
|
47
|
+
"darwin-arm64": "osx-arm64",
|
|
48
|
+
"darwin-x64": "osx-x64",
|
|
49
|
+
"linux-x64": "linux-x64",
|
|
50
|
+
"linux-arm64": "linux-arm64",
|
|
51
|
+
"win32-x64": "win-x64",
|
|
52
|
+
"win32-arm64": "win-arm64",
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const rid = map[`${p}-${a}`];
|
|
56
|
+
if (!rid) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
`Unsupported platform: ${p}-${a}. OpenKrew supports: macOS (arm64/x64), Linux (x64/arm64), Windows (x64/arm64).`,
|
|
59
|
+
);
|
|
64
60
|
}
|
|
65
|
-
|
|
66
|
-
throw new Error(
|
|
67
|
-
`Unsupported platform: ${p}-${a}. OpenKrew supports: macOS (arm64/x64), Linux (x64/arm64), Windows (x64/arm64).`,
|
|
68
|
-
);
|
|
61
|
+
return rid;
|
|
69
62
|
}
|
|
70
63
|
|
|
71
64
|
/**
|
|
@@ -80,9 +73,7 @@ function getBinaryName() {
|
|
|
80
73
|
*/
|
|
81
74
|
function isInstalled() {
|
|
82
75
|
const binaryPath = join(BIN_DIR, getBinaryName());
|
|
83
|
-
if (!existsSync(binaryPath))
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
76
|
+
if (!existsSync(binaryPath)) return false;
|
|
86
77
|
|
|
87
78
|
try {
|
|
88
79
|
const installedVersion = readFileSync(VERSION_FILE, "utf8").trim();
|
|
@@ -93,29 +84,23 @@ function isInstalled() {
|
|
|
93
84
|
}
|
|
94
85
|
|
|
95
86
|
/**
|
|
96
|
-
* Downloads the self-contained
|
|
87
|
+
* Downloads the self-contained binary from S3.
|
|
97
88
|
*/
|
|
98
89
|
async function downloadBinary() {
|
|
99
90
|
const rid = getRuntimeId();
|
|
100
|
-
const
|
|
101
|
-
const assetName = `openkrew-${rid}.tar.gz`;
|
|
102
|
-
const url = `https://github.com/${GITHUB_REPO}/releases/download/${tag}/${assetName}`;
|
|
91
|
+
const url = `${S3_BASE}/stable/${rid}/openkrew.tar.gz`;
|
|
103
92
|
|
|
104
|
-
process.stderr.write(`\x1b[36mOpenKrew\x1b[0m: downloading ${rid} binary (${
|
|
93
|
+
process.stderr.write(`\x1b[36mOpenKrew\x1b[0m: downloading ${rid} binary (v${PACKAGE_VERSION})...\n`);
|
|
105
94
|
|
|
106
95
|
mkdirSync(BIN_DIR, { recursive: true });
|
|
107
96
|
|
|
108
|
-
// Download and extract
|
|
109
97
|
const response = await fetch(url);
|
|
110
98
|
|
|
111
99
|
if (!response.ok) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return await buildFromSource();
|
|
117
|
-
}
|
|
118
|
-
throw new Error(`Failed to download binary: ${response.status} ${response.statusText}`);
|
|
100
|
+
process.stderr.write(`\x1b[31mError: Failed to download binary (HTTP ${response.status})\x1b[0m\n`);
|
|
101
|
+
process.stderr.write(`URL: ${url}\n`);
|
|
102
|
+
process.stderr.write("Try again later or check https://github.com/OpenKrew/openkrew/releases\n");
|
|
103
|
+
process.exit(1);
|
|
119
104
|
}
|
|
120
105
|
|
|
121
106
|
const tmpFile = join(OPENKREW_DIR, `download-${Date.now()}.tar.gz`);
|
|
@@ -124,7 +109,7 @@ async function downloadBinary() {
|
|
|
124
109
|
const fileStream = createWriteStream(tmpFile);
|
|
125
110
|
await pipeline(response.body, fileStream);
|
|
126
111
|
|
|
127
|
-
// Extract
|
|
112
|
+
// Extract
|
|
128
113
|
const tarProcess = spawn("tar", ["xzf", tmpFile, "-C", BIN_DIR], { stdio: "inherit" });
|
|
129
114
|
await new Promise((resolve, reject) => {
|
|
130
115
|
tarProcess.on("close", (code) =>
|
|
@@ -141,85 +126,13 @@ async function downloadBinary() {
|
|
|
141
126
|
}
|
|
142
127
|
}
|
|
143
128
|
|
|
144
|
-
// Write version marker
|
|
145
129
|
writeFileSync(VERSION_FILE, PACKAGE_VERSION);
|
|
146
|
-
|
|
147
|
-
process.stderr.write(`\x1b[32mInstalled OpenKrew ${PACKAGE_VERSION}\x1b[0m\n`);
|
|
130
|
+
process.stderr.write(`\x1b[32mInstalled OpenKrew v${PACKAGE_VERSION}\x1b[0m\n`);
|
|
148
131
|
} finally {
|
|
149
|
-
try {
|
|
150
|
-
rmSync(tmpFile);
|
|
151
|
-
} catch {}
|
|
132
|
+
try { rmSync(tmpFile); } catch {}
|
|
152
133
|
}
|
|
153
134
|
}
|
|
154
135
|
|
|
155
|
-
/**
|
|
156
|
-
* Fallback: build from source if binaries aren't available on GitHub Releases.
|
|
157
|
-
* Requires .NET 10 SDK to be installed.
|
|
158
|
-
*/
|
|
159
|
-
async function buildFromSource() {
|
|
160
|
-
// Check if dotnet is available
|
|
161
|
-
try {
|
|
162
|
-
const dotnetCheck = spawn("dotnet", ["--version"], { stdio: "pipe" });
|
|
163
|
-
const version = await new Promise((resolve, reject) => {
|
|
164
|
-
let output = "";
|
|
165
|
-
dotnetCheck.stdout.on("data", (d) => (output += d));
|
|
166
|
-
dotnetCheck.on("close", (code) => (code === 0 ? resolve(output.trim()) : reject()));
|
|
167
|
-
dotnetCheck.on("error", reject);
|
|
168
|
-
});
|
|
169
|
-
process.stderr.write(`Found .NET SDK ${String(version)}\n`);
|
|
170
|
-
} catch {
|
|
171
|
-
process.stderr.write("\x1b[31mError: .NET 10 SDK is required to build from source.\x1b[0m\n");
|
|
172
|
-
process.stderr.write("Install it from: https://dotnet.microsoft.com/download\n");
|
|
173
|
-
process.stderr.write(
|
|
174
|
-
"Or wait for a release build at: https://github.com/OpenKrew/openkrew/releases\n",
|
|
175
|
-
);
|
|
176
|
-
process.exit(1);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// Find the project root (relative to this script)
|
|
180
|
-
const scriptDir = dirname(new URL(import.meta.url).pathname);
|
|
181
|
-
|
|
182
|
-
if (!existsSync(join(scriptDir, "OpenKrew.slnx"))) {
|
|
183
|
-
process.stderr.write(
|
|
184
|
-
"\x1b[31mError: OpenKrew.slnx not found. Cannot build from source.\x1b[0m\n",
|
|
185
|
-
);
|
|
186
|
-
process.stderr.write("Install a release build: npm install -g openkrew@latest\n");
|
|
187
|
-
process.exit(1);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const rid = getRuntimeId();
|
|
191
|
-
process.stderr.write(`Building OpenKrew for ${rid}...\n`);
|
|
192
|
-
|
|
193
|
-
mkdirSync(BIN_DIR, { recursive: true });
|
|
194
|
-
|
|
195
|
-
const buildProcess = spawn(
|
|
196
|
-
"dotnet",
|
|
197
|
-
[
|
|
198
|
-
"publish",
|
|
199
|
-
join(scriptDir, "src", "OpenKrew.Hub", "OpenKrew.Hub.csproj"),
|
|
200
|
-
"-c",
|
|
201
|
-
"Release",
|
|
202
|
-
"-r",
|
|
203
|
-
rid,
|
|
204
|
-
"--self-contained",
|
|
205
|
-
"true",
|
|
206
|
-
"-o",
|
|
207
|
-
BIN_DIR,
|
|
208
|
-
],
|
|
209
|
-
{ stdio: "inherit" },
|
|
210
|
-
);
|
|
211
|
-
|
|
212
|
-
await new Promise((resolve, reject) => {
|
|
213
|
-
buildProcess.on("close", (code) =>
|
|
214
|
-
code === 0 ? resolve() : reject(new Error(`Build failed with code ${code}`)),
|
|
215
|
-
);
|
|
216
|
-
buildProcess.on("error", reject);
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
writeFileSync(VERSION_FILE, PACKAGE_VERSION);
|
|
220
|
-
process.stderr.write(`\x1b[32mBuilt OpenKrew ${PACKAGE_VERSION}\x1b[0m\n`);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
136
|
/**
|
|
224
137
|
* Runs the .NET Hub binary, passing through all CLI arguments.
|
|
225
138
|
*/
|