pantry/scripts/build.ts

50 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-08-01 22:43:40 +03:00
#!/usr/bin/env -S tea -E
/*---
dependencies:
gnu.org/tar: 1
tukaani.org/xz: 5
sourceware.org/bzip2: 1
2022-08-01 22:43:40 +03:00
args:
- deno
- run
- --allow-net
- --allow-run
2022-09-08 23:40:35 +03:00
- --allow-read
2022-09-09 16:37:26 +03:00
- --allow-write={{tea.prefix}}
2022-08-01 22:43:40 +03:00
- --allow-env
2022-11-07 19:43:48 +03:00
- --unstable
2022-08-01 22:43:40 +03:00
- --import-map={{ srcroot }}/import-map.json
---*/
2022-11-11 03:53:26 +03:00
import { usePantry, useFlags, useCellar, useInventory } from "hooks"
2022-11-07 19:43:48 +03:00
import { hydrate, install, link } from "prefab"
2022-11-09 19:22:30 +03:00
import { str as pkgstr } from "utils/pkg.ts"
2022-09-30 16:03:03 +03:00
import * as ARGV from "./utils/args.ts"
2022-11-07 19:43:48 +03:00
import { panic } from "utils/error.ts"
2022-11-11 03:53:26 +03:00
import build from "./build/build.ts"
2022-08-10 21:58:22 +03:00
2022-08-17 15:22:22 +03:00
useFlags()
2022-08-01 22:43:40 +03:00
const pantry = usePantry()
2022-11-07 19:43:48 +03:00
const cellar = useCellar()
const inventory = useInventory()
const raw = await ARGV.toArray(ARGV.pkgs())
for (const rq of raw) {
const dry = await pantry.getDeps(rq)
const wet = await hydrate([...dry.runtime, ...dry.build])
for (const pkg of wet.pkgs) {
if (!await cellar.has(pkg)) {
const version = await inventory.select(pkg) ?? panic(`${pkgstr(pkg)} not found`)
const installation = await install({ project: pkg.project, version })
await link(installation)
}
2022-09-08 23:40:35 +03:00
}
2022-09-01 20:49:14 +03:00
2022-11-07 19:43:48 +03:00
const pkg = await pantry.resolve(rq)
2022-11-11 03:53:26 +03:00
await build(pkg)
2022-11-07 19:43:48 +03:00
await link(pkg)
}