@vantaloom/cli 0.1.1 → 0.1.2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/cli.mjs +46 -45
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vantaloom/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Vantaloom local runtime manager.",
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 defaultDistBranch = "vantaloom-dist"
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 syncFromDist(options, "install")
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 syncFromDist(options, "update")
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 syncFromDist(options, action) {
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 remote = options.remote ?? installedConfig.remote ?? sourceRemote
230
- const repo = options.repo || installedConfig.repo || inferGitHubRepo(remote) || defaultRepo
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
- run("git", [
241
- "clone",
242
- "--depth",
243
- "1",
244
- "--branch",
245
- distBranch,
246
- cloneUrl,
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,36 @@ 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}#${distBranch}`)
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 url = `https://github.com/${repo}/releases/download/${releaseTag}/${assetName}`
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 response = await fetch(url, { headers })
274
+ if (!response.ok) {
275
+ const detail = await response.text().catch(() => "")
276
+ const authHint = response.status === 404 || response.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 download ${assetName} from ${repo}@${releaseTag}: HTTP ${response.status}.${authHint}${detail ? ` ${detail.slice(0, 200)}` : ""}`)
280
+ }
281
+
282
+ const buffer = Buffer.from(await response.arrayBuffer())
283
+ await writeFile(target, buffer)
284
+ }
285
+
269
286
  function shouldUseDistSync(options) {
270
287
  return !options.local && !options.source && !options.buildWeb
271
288
  }
@@ -300,7 +317,7 @@ function readJSONIfExists(filePath) {
300
317
 
301
318
  function mergeRuntimeConfig(packageConfig, existingConfig, overrides) {
302
319
  const merged = { ...packageConfig }
303
- for (const key of ["sourceRoot", "remote", "repo", "distBranch"]) {
320
+ for (const key of ["sourceRoot", "remote", "repo", "releaseTag"]) {
304
321
  if (!merged[key] && existingConfig[key]) {
305
322
  merged[key] = existingConfig[key]
306
323
  }
@@ -311,8 +328,8 @@ function mergeRuntimeConfig(packageConfig, existingConfig, overrides) {
311
328
  if (!merged.repo) {
312
329
  merged.repo = defaultRepo
313
330
  }
314
- if (!merged.distBranch) {
315
- merged.distBranch = defaultDistBranch
331
+ if (!merged.releaseTag) {
332
+ merged.releaseTag = defaultReleaseTag
316
333
  }
317
334
  return merged
318
335
  }
@@ -324,21 +341,8 @@ function runtimeConfigFromSource(sourceRoot) {
324
341
  ...(process.env.GITHUB_ACTIONS ? {} : { sourceRoot }),
325
342
  ...(remote ? { remote } : {}),
326
343
  repo,
327
- distBranch: defaultDistBranch,
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
- }
344
+ releaseTag: defaultReleaseTag,
340
345
  }
341
- throw new Error(`missing CI package for ${platform} in ${distRoot}`)
342
346
  }
343
347
 
344
348
  function findExtractedPackage(extractRoot, platform) {
@@ -397,10 +401,6 @@ function inferGitHubRepo(remote) {
397
401
  return sshMatch?.[1] ?? ""
398
402
  }
399
403
 
400
- function sshRemoteFromRepo(repo) {
401
- return `git@github.com:${repo}.git`
402
- }
403
-
404
404
  async function copyStandaloneWeb(sourceRoot, buildWeb) {
405
405
  const standalone = path.join(sourceRoot, "apps", "vantaloom", ".next", "standalone")
406
406
  const staticSource = path.join(sourceRoot, "apps", "vantaloom", ".next", "static")
@@ -639,7 +639,8 @@ function parseOptions(args) {
639
639
  case "output":
640
640
  case "repo":
641
641
  case "remote":
642
- case "dist-branch":
642
+ case "release-tag":
643
+ case "github-token":
643
644
  options[toCamel(key)] = inlineValue ?? args[++index]
644
645
  if (!options[toCamel(key)]) {
645
646
  throw new Error(`missing value for --${key}`)
@@ -746,9 +747,9 @@ function printHelp() {
746
747
  console.log(`Vantaloom CLI
747
748
 
748
749
  Usage:
749
- vantaloom install [--prefix <dir>] [--repo <owner/name>] [--remote <git-url>] [--dist-branch <branch>] [--package <dir>] [--no-start]
750
+ vantaloom install [--prefix <dir>] [--repo <owner/name>] [--release-tag <tag>] [--github-token <token>] [--package <dir>] [--no-start]
750
751
  vantaloom install --local [--prefix <dir>] [--source <repo>] [--build-web] [--no-start]
751
- vantaloom update [--prefix <dir>] [--repo <owner/name>] [--remote <git-url>] [--dist-branch <branch>] [--no-start]
752
+ vantaloom update [--prefix <dir>] [--repo <owner/name>] [--release-tag <tag>] [--github-token <token>] [--no-start]
752
753
  vantaloom update --local [--prefix <dir>] [--source <repo>] [--build-web] [--no-start]
753
754
  vantaloom package [--source <repo>] [--output <dir>] [--build-web] [--archive]
754
755
  vantaloom start [--prefix <dir>] [--component all|api|agent|web]