2022-09-08 23:40:35 +03:00
|
|
|
|
#!/usr/bin/env -S tea -E
|
|
|
|
|
|
|
|
|
|
/*---
|
2022-11-30 23:18:05 +03:00
|
|
|
|
dependencies:
|
|
|
|
|
gnu.org/tar: 1
|
|
|
|
|
tukaani.org/xz: 5
|
|
|
|
|
sourceware.org/bzip2: 1
|
2022-09-08 23:40:35 +03:00
|
|
|
|
args:
|
|
|
|
|
- deno
|
|
|
|
|
- run
|
|
|
|
|
- --allow-net
|
|
|
|
|
- --allow-run
|
|
|
|
|
- --allow-read
|
|
|
|
|
- --allow-write={{ tea.prefix }}
|
|
|
|
|
- --allow-env
|
|
|
|
|
- --import-map={{ srcroot }}/import-map.json
|
|
|
|
|
---*/
|
|
|
|
|
|
2022-10-17 20:45:32 +03:00
|
|
|
|
//TODO verify the sha
|
2022-09-08 23:40:35 +03:00
|
|
|
|
|
2022-11-30 23:18:05 +03:00
|
|
|
|
import { usePantry, useCache, useDownload, useCellar, useSourceUnarchiver, useOffLicense, useFlags} from "hooks"
|
2023-01-03 18:58:49 +03:00
|
|
|
|
import { print } from "utils"
|
2022-10-17 20:45:32 +03:00
|
|
|
|
import { Stowage, Package } from "types"
|
|
|
|
|
import * as ARGV from "./utils/args.ts"
|
|
|
|
|
import Path from "path"
|
2022-09-08 23:40:35 +03:00
|
|
|
|
|
2022-11-30 23:18:05 +03:00
|
|
|
|
useFlags()
|
|
|
|
|
|
2022-09-08 23:40:35 +03:00
|
|
|
|
const pantry = usePantry()
|
2022-10-17 20:45:32 +03:00
|
|
|
|
const { download } = useDownload()
|
2022-09-08 23:40:35 +03:00
|
|
|
|
|
2022-10-17 20:45:32 +03:00
|
|
|
|
export async function fetch_src(pkg: Package): Promise<[Path, Path] | undefined> {
|
2022-10-17 22:20:42 +03:00
|
|
|
|
const dstdir = useCellar().shelf(pkg.project).join("src", `v${pkg.version}`)
|
2022-10-17 20:45:32 +03:00
|
|
|
|
const dist = await pantry.getDistributable(pkg)
|
|
|
|
|
if (!dist) return
|
|
|
|
|
const { url, stripComponents } = dist
|
|
|
|
|
const stowage: Stowage = { pkg, type: 'src', extname: url.path().extname() }
|
|
|
|
|
const dst = useCache().path(stowage)
|
|
|
|
|
const zipfile = await (async () => {
|
|
|
|
|
try {
|
|
|
|
|
// first try our mirror
|
|
|
|
|
const src = useOffLicense('s3').url(stowage)
|
|
|
|
|
return await download({ dst, src })
|
|
|
|
|
} catch {
|
|
|
|
|
// oh well, try original location then
|
|
|
|
|
return await download({ dst, src: url })
|
|
|
|
|
}
|
|
|
|
|
})()
|
|
|
|
|
await useSourceUnarchiver().unarchive({ dstdir, zipfile, stripComponents })
|
|
|
|
|
return [dstdir, zipfile]
|
|
|
|
|
}
|
2022-09-08 23:40:35 +03:00
|
|
|
|
|
2022-10-17 20:45:32 +03:00
|
|
|
|
if (import.meta.main) {
|
|
|
|
|
for await (let pkg of ARGV.pkgs()) {
|
|
|
|
|
pkg = await pantry.resolve(pkg)
|
2023-01-03 16:45:57 +03:00
|
|
|
|
const rv = await fetch_src(pkg)
|
|
|
|
|
if (rv) {
|
|
|
|
|
// a package doesn’t require a source tarball
|
|
|
|
|
//FIXME is this dumb tho? In theory a package could just be a build script that generates itself
|
|
|
|
|
// in practice this is rare and pkgs could just specify some dummy tarball
|
|
|
|
|
await print(rv.join("\n") + "\n")
|
|
|
|
|
}
|
2022-10-17 20:45:32 +03:00
|
|
|
|
}
|
|
|
|
|
}
|