pantry/scripts/deps.ts

50 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-09-07 03:33:51 +03:00
#!/usr/bin/env -S tea -E
/*---
args:
- deno
- run
- --allow-read
- --allow-env
- --import-map={{ srcroot }}/import-map.json
env:
TEA_PANTRY_PATH: "{{srcroot}}"
2022-09-07 03:33:51 +03:00
---*/
2022-09-20 14:53:40 +03:00
import { PackageRequirement } from "types"
import { usePantry, useFlags } from "hooks"
import { hydrate } from "prefab"
2022-09-21 10:46:24 +03:00
import { pkg } from "utils"
2022-09-07 03:33:51 +03:00
const pantry = usePantry()
useFlags()
const mode: 'build' | 'install' = Deno.args.includes("-b") ? 'build' : 'install'
const get_deps = async (pkg: PackageRequirement) => {
const deps = await pantry.getDeps(pkg)
switch (mode) {
case 'build':
return [...deps.build, ...deps.runtime]
case 'install':
return deps.runtime
}
}
2022-09-21 10:46:24 +03:00
const dry = Deno.args.compact(arg => !arg.startsWith('-') && pkg.parse(arg))
2022-09-07 03:33:51 +03:00
const explicit = new Set(dry.map(x=>x.project))
const wet = await hydrate(dry, get_deps)
2022-09-21 10:46:24 +03:00
const gas = wet.pkgs.compact(({project}) => {
2022-09-07 03:33:51 +03:00
if (Deno.args.includes('-i')) {
return project
2022-09-08 23:40:35 +03:00
} else if (!explicit.has(project)){
return project
2022-09-07 03:33:51 +03:00
}
})
if (Deno.env.get("GITHUB_ACTIONS")) {
console.log(`::set-output name=pkgs::${gas.join(" ")}\n`)
} else {
console.log(gas.join("\n"))
}