pantry/scripts/build.ts

45 lines
1 KiB
TypeScript
Raw Normal View History

2022-08-01 22:43:40 +03:00
#!/usr/bin/env -S tea -E
/*---
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-07 19:43:48 +03:00
import { usePantry, useFlags, useCellar, useInventory } from "hooks"
import { hydrate, install, link } from "prefab"
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"
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()
2022-09-30 16:03:03 +03:00
const dry = await ARGV.toArray(ARGV.pkgs())
2022-11-07 19:43:48 +03:00
const wet = await hydrate(dry, async (pkg, dry) => {
const deps = await pantry.getDeps(pkg)
return dry ? [...deps.build, ...deps.runtime] : deps.runtime
})
for (const pkg of wet.wet) {
if (!await cellar.has(pkg)) {
const version = await inventory.select(pkg) ?? panic()
await install({ project: pkg.project, version })
2022-09-08 23:40:35 +03:00
}
2022-08-01 22:43:40 +03:00
}
2022-09-01 20:49:14 +03:00
2022-11-07 19:43:48 +03:00
for (const rq of dry) {
const pkg = await pantry.resolve(rq)
await build(pkg)
await link(pkg)
}