pantry/scripts/build.ts

78 lines
2.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
- --allow-read=/opt,/Library/Developer/CommandLineTools
- --allow-write=/opt
- --allow-env
- --import-map={{ srcroot }}/import-map.json
---*/
import useSourceUnarchiver from "hooks/useSourceUnarchiver.ts"
import useCellar from "hooks/useCellar.ts"
import usePantry from "hooks/usePantry.ts"
import useCache from "hooks/useCache.ts"
import { lvl1 as link } from "prefab/link.ts"
import build from "prefab/build.ts"
2022-09-01 20:49:14 +03:00
import { Package, parsePackageRequirement, semver } from "types"
2022-08-17 15:22:22 +03:00
import useFlags from "hooks/useFlags.ts"
2022-08-26 17:17:20 +03:00
import usePlatform from "hooks/usePlatform.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()
const cellar = useCellar()
const dry = Deno.args.map(project => {
const match = project.match(/projects\/(.*)\/package.yml/)
return match ? match[1] : project
}).map(parsePackageRequirement)
const rv: Package[] = []
2022-09-01 20:49:14 +03:00
for (const pkgrq of dry) {
const versions = await pantry.getVersions(pkgrq)
const version = semver.maxSatisfying(versions, pkgrq.constraint)
2022-08-01 22:43:40 +03:00
if (!version) throw "no-version-found"
2022-09-01 20:49:14 +03:00
const pkg = { project: pkgrq.project, version }
2022-08-01 22:43:40 +03:00
2022-09-01 20:49:14 +03:00
if (Deno.env.get("SKIP") && await cellar.isInstalled(pkg)) {
console.log({ skipping: pkg.project })
continue
}
2022-08-01 22:43:40 +03:00
2022-09-01 20:49:14 +03:00
console.log({ building: pkgrq.project })
2022-08-01 22:43:40 +03:00
// Get the source
const prebuild = async () => {
2022-09-01 20:49:14 +03:00
const dstdir = cellar.mkpath(pkg).join("src")
2022-08-01 22:43:40 +03:00
const { url, stripComponents } = await pantry.getDistributable(pkg)
const { download } = useCache()
const zip = await download({ pkg, url, type: 'src' })
await useSourceUnarchiver().unarchive({
dstdir,
zipfile: zip,
stripComponents
})
}
const deps = await pantry.getDeps(pkg)
2022-08-26 17:17:20 +03:00
const env = usePlatform().platform == 'darwin'
? {MACOSX_DEPLOYMENT_TARGET: ['11.0']}
: undefined
2022-08-01 22:43:40 +03:00
// Build and link
2022-08-26 17:17:20 +03:00
const path = await build({ pkg, deps, prebuild, env })
2022-08-01 22:43:40 +03:00
await link({ path, pkg })
2022-09-01 20:49:14 +03:00
rv.push(pkg)
2022-08-01 22:43:40 +03:00
}
2022-09-01 20:49:14 +03:00
const built_pkgs = rv.map(({ project, version }) => `${project}@${version}`).join(" ")
const txt = `::set-output name=pkgs::${built_pkgs}\n`
await Deno.stdout.write(new TextEncoder().encode(txt))