pantry/scripts/sort.ts

47 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-08-05 04:19:01 +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
---*/
2022-09-01 20:49:14 +03:00
// sorts input for building
// does a full hydration, but only returns ordered, dry packages
2022-08-05 04:19:01 +03:00
import { parsePackageRequirement } from "types"
2022-09-01 20:49:14 +03:00
import hydrate from "prefab/hydrate.ts"
2022-08-17 15:22:22 +03:00
import useFlags from "hooks/useFlags.ts"
2022-09-01 20:49:14 +03:00
import usePantry from "../src/hooks/usePantry.ts"
2022-08-10 21:58:22 +03:00
2022-08-17 15:22:22 +03:00
const flags = useFlags()
2022-09-01 20:49:14 +03:00
const pantry = usePantry()
2022-08-05 04:19:01 +03:00
const dry = Deno.args.map(project => {
const match = project.match(/projects\/(.*)\/package.yml/)
return match ? match[1] : project
}).map(parsePackageRequirement)
2022-09-01 20:49:14 +03:00
const wet = await hydrate(dry, async (pkg, dry) => {
const deps = await pantry.getDeps(pkg)
return dry ? [...deps.build, ...deps.runtime] : deps.runtime
})
const gas = wet.dry.map(x => x.project)
2022-08-05 04:19:01 +03:00
2022-08-17 15:22:22 +03:00
if (Deno.env.get("GITHUB_ACTIONS")) {
2022-09-01 20:49:14 +03:00
const pre = wet.wet.map(x=>x.project)
2022-08-17 15:22:22 +03:00
console.log(`::set-output name=pkgs::${gas.join(" ")}`)
2022-09-01 20:49:14 +03:00
console.log(`::set-output name=pre-install::${pre.join(" ")}`)
2022-08-17 15:22:22 +03:00
} else if (flags.json) {
console.log(gas)
} else {
console.log(gas.join("\n"))
}