@vantaloom/cli 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/package.json +1 -1
- package/src/cli.mjs +67 -45
package/package.json
CHANGED
package/src/cli.mjs
CHANGED
|
@@ -19,7 +19,7 @@ import { fileURLToPath } from "node:url"
|
|
|
19
19
|
const cliRoot = path.resolve(fileURLToPath(import.meta.url), "..", "..")
|
|
20
20
|
const repoCandidate = path.resolve(cliRoot, "..", "..")
|
|
21
21
|
const installedConfigPath = path.join(cliRoot, "config.json")
|
|
22
|
-
const
|
|
22
|
+
const defaultReleaseTag = "runtime-latest"
|
|
23
23
|
const defaultRepo = "Timefiles404/Vantaloom-next"
|
|
24
24
|
|
|
25
25
|
const runtimePackages = [
|
|
@@ -44,7 +44,7 @@ export async function main(argv) {
|
|
|
44
44
|
if (options.package) {
|
|
45
45
|
await installFromPackage({ ...options, update: false })
|
|
46
46
|
} else if (shouldUseDistSync(options)) {
|
|
47
|
-
await
|
|
47
|
+
await syncFromRelease(options, "install")
|
|
48
48
|
} else {
|
|
49
49
|
await installFromSource(options)
|
|
50
50
|
}
|
|
@@ -53,7 +53,7 @@ export async function main(argv) {
|
|
|
53
53
|
if (options.package) {
|
|
54
54
|
await installFromPackage({ ...options, update: true })
|
|
55
55
|
} else if (shouldUseDistSync(options)) {
|
|
56
|
-
await
|
|
56
|
+
await syncFromRelease(options, "update")
|
|
57
57
|
} else {
|
|
58
58
|
await installFromSource({ ...options, update: true })
|
|
59
59
|
}
|
|
@@ -219,35 +219,29 @@ async function applyPackage(packageRoot, prefix, options) {
|
|
|
219
219
|
return version
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
-
async function
|
|
222
|
+
async function syncFromRelease(options, action) {
|
|
223
223
|
const prefix = safeDirectory(options.prefix ?? defaultPrefix())
|
|
224
224
|
const installedConfig = readInstalledConfig(prefix)
|
|
225
225
|
const sourceRoot = installedConfig.sourceRoot
|
|
226
226
|
? tryAssertSourceRoot(installedConfig.sourceRoot)
|
|
227
227
|
: tryFindSourceRoot()
|
|
228
228
|
const sourceRemote = sourceRoot ? gitRemoteUrl(sourceRoot) : ""
|
|
229
|
-
const
|
|
230
|
-
const
|
|
231
|
-
const distBranch = options.distBranch ?? installedConfig.distBranch ?? defaultDistBranch
|
|
232
|
-
const cloneUrl = remote || sshRemoteFromRepo(repo)
|
|
229
|
+
const repo = options.repo || installedConfig.repo || inferGitHubRepo(options.remote ?? installedConfig.remote ?? sourceRemote) || defaultRepo
|
|
230
|
+
const releaseTag = options.releaseTag || installedConfig.releaseTag || defaultReleaseTag
|
|
233
231
|
const tempRoot = mkdtempSync(path.join(os.tmpdir(), "vantaloom-update-"))
|
|
234
232
|
|
|
235
233
|
try {
|
|
236
|
-
const distRoot = path.join(tempRoot, "dist")
|
|
237
234
|
const extractRoot = path.join(tempRoot, "extract")
|
|
235
|
+
const archive = path.join(tempRoot, `vantaloom-${platformId()}.tar.gz`)
|
|
238
236
|
mkdirSync(extractRoot, { recursive: true })
|
|
239
237
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
distRoot,
|
|
248
|
-
])
|
|
249
|
-
|
|
250
|
-
const archive = findPackageArchive(distRoot, platformId())
|
|
238
|
+
await downloadReleaseAsset({
|
|
239
|
+
repo,
|
|
240
|
+
releaseTag,
|
|
241
|
+
assetName: `vantaloom-${platformId()}.tar.gz`,
|
|
242
|
+
target: archive,
|
|
243
|
+
token: options.githubToken,
|
|
244
|
+
})
|
|
251
245
|
run("tar", ["-xzf", archive, "-C", extractRoot])
|
|
252
246
|
|
|
253
247
|
const packageRoot = findExtractedPackage(extractRoot, platformId())
|
|
@@ -259,13 +253,57 @@ async function syncFromDist(options, action) {
|
|
|
259
253
|
|
|
260
254
|
console.log(`${action === "update" ? "updated" : "installed"} Vantaloom: ${prefix}`)
|
|
261
255
|
console.log(`version: ${version}`)
|
|
262
|
-
console.log(`source: ${repo}
|
|
256
|
+
console.log(`source: ${repo}@${releaseTag}`)
|
|
263
257
|
console.log(`run: ${displayCommand(prefix)} status`)
|
|
264
258
|
} finally {
|
|
265
259
|
removeKnownPath(tempRoot, os.tmpdir())
|
|
266
260
|
}
|
|
267
261
|
}
|
|
268
262
|
|
|
263
|
+
async function downloadReleaseAsset({ repo, releaseTag, assetName, target, token }) {
|
|
264
|
+
const releaseUrl = `https://api.github.com/repos/${repo}/releases/tags/${releaseTag}`
|
|
265
|
+
const headers = {
|
|
266
|
+
"User-Agent": "vantaloom-cli",
|
|
267
|
+
}
|
|
268
|
+
const githubToken = token || process.env.VANTALOOM_GITHUB_TOKEN || process.env.GITHUB_TOKEN
|
|
269
|
+
if (githubToken) {
|
|
270
|
+
headers.Authorization = `Bearer ${githubToken}`
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const releaseResponse = await fetch(releaseUrl, { headers })
|
|
274
|
+
if (!releaseResponse.ok) {
|
|
275
|
+
const detail = await releaseResponse.text().catch(() => "")
|
|
276
|
+
const authHint = releaseResponse.status === 404 || releaseResponse.status === 403
|
|
277
|
+
? " If the repository is private, set VANTALOOM_GITHUB_TOKEN to a GitHub token that can read releases."
|
|
278
|
+
: ""
|
|
279
|
+
throw new Error(`failed to inspect ${repo}@${releaseTag}: HTTP ${releaseResponse.status}.${authHint}${detail ? ` ${detail.slice(0, 200)}` : ""}`)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const release = await releaseResponse.json()
|
|
283
|
+
const asset = release.assets?.find((asset) => asset.name === assetName)
|
|
284
|
+
if (!asset) {
|
|
285
|
+
const names = release.assets?.map((asset) => asset.name).join(", ") || "none"
|
|
286
|
+
throw new Error(`missing release asset ${assetName} in ${repo}@${releaseTag}; available assets: ${names}`)
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const response = await fetch(asset.url, {
|
|
290
|
+
headers: {
|
|
291
|
+
...headers,
|
|
292
|
+
Accept: "application/octet-stream",
|
|
293
|
+
},
|
|
294
|
+
})
|
|
295
|
+
if (!response.ok) {
|
|
296
|
+
const detail = await response.text().catch(() => "")
|
|
297
|
+
const authHint = response.status === 404 || response.status === 403
|
|
298
|
+
? " If the repository is private, set VANTALOOM_GITHUB_TOKEN to a GitHub token that can read releases."
|
|
299
|
+
: ""
|
|
300
|
+
throw new Error(`failed to download ${assetName} from ${repo}@${releaseTag}: HTTP ${response.status}.${authHint}${detail ? ` ${detail.slice(0, 200)}` : ""}`)
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const buffer = Buffer.from(await response.arrayBuffer())
|
|
304
|
+
await writeFile(target, buffer)
|
|
305
|
+
}
|
|
306
|
+
|
|
269
307
|
function shouldUseDistSync(options) {
|
|
270
308
|
return !options.local && !options.source && !options.buildWeb
|
|
271
309
|
}
|
|
@@ -300,7 +338,7 @@ function readJSONIfExists(filePath) {
|
|
|
300
338
|
|
|
301
339
|
function mergeRuntimeConfig(packageConfig, existingConfig, overrides) {
|
|
302
340
|
const merged = { ...packageConfig }
|
|
303
|
-
for (const key of ["sourceRoot", "remote", "repo", "
|
|
341
|
+
for (const key of ["sourceRoot", "remote", "repo", "releaseTag"]) {
|
|
304
342
|
if (!merged[key] && existingConfig[key]) {
|
|
305
343
|
merged[key] = existingConfig[key]
|
|
306
344
|
}
|
|
@@ -311,8 +349,8 @@ function mergeRuntimeConfig(packageConfig, existingConfig, overrides) {
|
|
|
311
349
|
if (!merged.repo) {
|
|
312
350
|
merged.repo = defaultRepo
|
|
313
351
|
}
|
|
314
|
-
if (!merged.
|
|
315
|
-
merged.
|
|
352
|
+
if (!merged.releaseTag) {
|
|
353
|
+
merged.releaseTag = defaultReleaseTag
|
|
316
354
|
}
|
|
317
355
|
return merged
|
|
318
356
|
}
|
|
@@ -324,21 +362,8 @@ function runtimeConfigFromSource(sourceRoot) {
|
|
|
324
362
|
...(process.env.GITHUB_ACTIONS ? {} : { sourceRoot }),
|
|
325
363
|
...(remote ? { remote } : {}),
|
|
326
364
|
repo,
|
|
327
|
-
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
function findPackageArchive(distRoot, platform) {
|
|
332
|
-
const candidates = [
|
|
333
|
-
path.join(distRoot, "packages", `vantaloom-${platform}.tar.gz`),
|
|
334
|
-
path.join(distRoot, `vantaloom-${platform}.tar.gz`),
|
|
335
|
-
]
|
|
336
|
-
for (const candidate of candidates) {
|
|
337
|
-
if (existsSync(candidate)) {
|
|
338
|
-
return candidate
|
|
339
|
-
}
|
|
365
|
+
releaseTag: defaultReleaseTag,
|
|
340
366
|
}
|
|
341
|
-
throw new Error(`missing CI package for ${platform} in ${distRoot}`)
|
|
342
367
|
}
|
|
343
368
|
|
|
344
369
|
function findExtractedPackage(extractRoot, platform) {
|
|
@@ -397,10 +422,6 @@ function inferGitHubRepo(remote) {
|
|
|
397
422
|
return sshMatch?.[1] ?? ""
|
|
398
423
|
}
|
|
399
424
|
|
|
400
|
-
function sshRemoteFromRepo(repo) {
|
|
401
|
-
return `git@github.com:${repo}.git`
|
|
402
|
-
}
|
|
403
|
-
|
|
404
425
|
async function copyStandaloneWeb(sourceRoot, buildWeb) {
|
|
405
426
|
const standalone = path.join(sourceRoot, "apps", "vantaloom", ".next", "standalone")
|
|
406
427
|
const staticSource = path.join(sourceRoot, "apps", "vantaloom", ".next", "static")
|
|
@@ -639,7 +660,8 @@ function parseOptions(args) {
|
|
|
639
660
|
case "output":
|
|
640
661
|
case "repo":
|
|
641
662
|
case "remote":
|
|
642
|
-
case "
|
|
663
|
+
case "release-tag":
|
|
664
|
+
case "github-token":
|
|
643
665
|
options[toCamel(key)] = inlineValue ?? args[++index]
|
|
644
666
|
if (!options[toCamel(key)]) {
|
|
645
667
|
throw new Error(`missing value for --${key}`)
|
|
@@ -746,9 +768,9 @@ function printHelp() {
|
|
|
746
768
|
console.log(`Vantaloom CLI
|
|
747
769
|
|
|
748
770
|
Usage:
|
|
749
|
-
vantaloom install [--prefix <dir>] [--repo <owner/name>] [--
|
|
771
|
+
vantaloom install [--prefix <dir>] [--repo <owner/name>] [--release-tag <tag>] [--github-token <token>] [--package <dir>] [--no-start]
|
|
750
772
|
vantaloom install --local [--prefix <dir>] [--source <repo>] [--build-web] [--no-start]
|
|
751
|
-
vantaloom update [--prefix <dir>] [--repo <owner/name>] [--
|
|
773
|
+
vantaloom update [--prefix <dir>] [--repo <owner/name>] [--release-tag <tag>] [--github-token <token>] [--no-start]
|
|
752
774
|
vantaloom update --local [--prefix <dir>] [--source <repo>] [--build-web] [--no-start]
|
|
753
775
|
vantaloom package [--source <repo>] [--output <dir>] [--build-web] [--archive]
|
|
754
776
|
vantaloom start [--prefix <dir>] [--component all|api|agent|web]
|