pantry/scripts/build.ts

58 lines
1.7 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
---*/
import { usePantry, useFlags, useCellar, useInventory, usePrefix } 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"
import build, { BuildResult } from "./build/build.ts"
import { set_output } from "./utils/gha.ts"
import { pkg as pkgutils } from "utils"
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())
const rv: BuildResult[] = []
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)
rv.push(await build(pkg))
2022-11-07 19:43:48 +03:00
await link(pkg)
}
if (Deno.env.get("GITHUB_ACTIONS")) {
const to = usePrefix()
await set_output("pkgs", rv.map(x => pkgutils.str(x.installation.pkg)))
await set_output("paths", rv.map(x => x.installation.path), '%0A')
await set_output("relative-paths", rv.map(x => x.installation.path.relative({ to })))
await set_output("srcs", rv.map(x => x.src?.relative({ to }) ?? "~"))
await set_output("srcs-relative-paths", rv.compact(x => x.src?.relative({ to })))
}