pantry/scripts/fetch.ts

35 lines
931 B
TypeScript
Raw Normal View History

#!/usr/bin/env -S tea -E
/*---
args:
- deno
- run
- --allow-net
- --allow-run
- --allow-read
- --allow-write={{ tea.prefix }}
- --allow-env
- --import-map={{ srcroot }}/import-map.json
---*/
2022-09-20 14:53:40 +03:00
import { usePantry, useCache, useCellar, useSourceUnarchiver } from "hooks"
import { Command } from "cliffy/command/mod.ts"
2022-09-21 10:46:24 +03:00
import { print, pkg as pkgutils } from "utils"
const { args } = await new Command()
.name("tea-fetch-src")
.arguments("<pkgspec:string>")
.parse(Deno.args)
const pantry = usePantry()
2022-09-21 10:46:24 +03:00
const req = pkgutils.parse(args[0])
const pkg = await pantry.resolve(req); console.debug(pkg)
2022-09-21 10:46:24 +03:00
const dstdir = useCellar().keg(pkg).join("src")
const { url, stripComponents } = await pantry.getDistributable(pkg)
const { download } = useCache()
2022-09-21 10:46:24 +03:00
const zipfile = await download({ pkg, url, type: 'src' })
await useSourceUnarchiver().unarchive({ dstdir, zipfile, stripComponents })
await print(`${dstdir}\n`)