@begit/cli
Advanced tools
Comparing version
@@ -6,2 +6,3 @@ #! /usr/bin/env node | ||
import { downloadRepo } from '@begit/core'; | ||
import { fetchLatestCommit, getMostRecentCachedCommit } from '@begit/core/utils'; | ||
@@ -12,3 +13,3 @@ createRequire(import.meta.url); | ||
var name = "@begit/cli"; | ||
var version = "0.0.17"; | ||
var version = "0.1.0"; | ||
var main = async () => { | ||
@@ -42,8 +43,22 @@ updater({ name, version, ttl: 864e5 }); | ||
const parts = url.split("/"); | ||
const repo = parts.pop(); | ||
const repoName = parts.pop(); | ||
const owner = parts.pop(); | ||
const branch = url.split("#")[1]; | ||
if (!repo || !owner) throw new Error("Invalid URL"); | ||
if (!repoName || !owner) throw new Error("Invalid URL"); | ||
let hash; | ||
try { | ||
hash = await fetchLatestCommit(owner, repoName); | ||
} catch (_) { | ||
const cached = await getMostRecentCachedCommit(owner, repoName); | ||
if (!cached) { | ||
throw new Error("Unable to fetch repository or retrieve from cache"); | ||
} | ||
const x = new Date(cached.timestamp); | ||
console.log("Can't fetch repository from the internet"); | ||
console.log(`Using cached repository from ${x.toUTCString()}`); | ||
hash = cached.hash; | ||
} | ||
if (!hash) throw new Error("Unable to retrieve a valid commit hash"); | ||
await downloadRepo({ | ||
repo: { owner, name: repo, branch, subdir }, | ||
repo: { owner, name: repoName, branch, subdir, hash }, | ||
dest, | ||
@@ -50,0 +65,0 @@ opts: { cache: !no_cache } |
{ | ||
"name": "@begit/cli", | ||
"version": "0.0.17", | ||
"version": "0.1.0", | ||
"description": "A CLI for using begit", | ||
@@ -27,14 +27,14 @@ "author": "Thomas Beer", | ||
"devDependencies": { | ||
"@types/node": "^20.14.11", | ||
"@types/node": "^22.10.7", | ||
"changesets": "^1.0.2", | ||
"jiti": "^1.21.6", | ||
"tsup": "^8.1.2", | ||
"typescript": "^5.5.3", | ||
"vitest": "^2.0.3" | ||
"jiti": "^2.4.2", | ||
"tsup": "^8.3.5", | ||
"typescript": "^5.7.3", | ||
"vitest": "^3.0.2" | ||
}, | ||
"dependencies": { | ||
"@clack/prompts": "^0.7.0", | ||
"@clack/prompts": "^0.9.1", | ||
"cmd-ts": "^0.13.0", | ||
"tiny-updater": "^3.5.2", | ||
"@begit/core": "0.0.19" | ||
"tiny-updater": "^3.5.3", | ||
"@begit/core": "0.1.0" | ||
}, | ||
@@ -41,0 +41,0 @@ "publishConfig": { |
Sorry, the diff of this file is not supported yet
10997
22.08%70
27.27%+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
Updated
Updated
Updated