various fixes (#80)

This commit is contained in:
Max Howell 2022-08-17 08:22:22 -04:00 committed by GitHub
parent cfb4e7e1f2
commit e4509ef409
7 changed files with 97 additions and 14 deletions

View file

@ -50,3 +50,9 @@ knowledge. Please keep it tidy.
|-------------|---------|
| deno.land | ^1.18 |
| tea.xyz | ^0 |
## Build All
```sh
scripts/ls.ts | xargs scripts/sort.ts | xargs scripts/build.ts
```

View file

@ -6,6 +6,7 @@ args:
- run
- --allow-net
- --allow-run
- --allow-env
- --allow-read=/opt/
- --allow-write=/opt/
- --import-map={{ srcroot }}/import-map.json
@ -16,6 +17,9 @@ import { Path } from "types"
import useCellar from "hooks/useCellar.ts"
import { run } from "utils"
import useCache from "hooks/useCache.ts"
import useFlags from "hooks/useFlags.ts"
useFlags()
const cellar = useCellar()
const filesListName = 'files.txt'

View file

@ -24,11 +24,9 @@ import { parsePackageRequirement } from "types"
import hydrate from "prefab/hydrate.ts"
import resolve from "prefab/resolve.ts"
import { get_build_deps } from "./_lib.ts"
import useFlags from "hooks/useFlags.ts"
//<FIXME>
import { print } from "utils"
print("this because otherwise console.verbose is not defined lol")
//</FIXME>
useFlags()
const pantry = usePantry()
const cellar = useCellar()

64
scripts/ls.ts Executable file
View file

@ -0,0 +1,64 @@
#!/usr/bin/env -S tea -E
// returns all pantry entries as `[{ name, path }]`
/*---
args:
- deno
- run
- --allow-env
- --allow-read=/opt/tea.xyz/var/pantry
- --import-map={{ srcroot }}/import-map.json
---*/
import { Path } from "types"
import useFlags from "hooks/useFlags.ts"
const flags = useFlags()
const prefix = new Path('/opt/tea.xyz/var/pantry/projects')
//FIXME unfortunately importing executes the script below
export async function* ls(): AsyncGenerator<Entry> {
for await (const path of _ls_pantry(prefix)) {
yield {
name: path.parent().relative({ to: prefix }),
path: path.string
}
}
}
async function* _ls_pantry(dir: Path): AsyncGenerator<Path> {
if (!dir.isDirectory()) throw new Error()
for await (const [path, { name, isDirectory }] of dir.ls()) {
if (isDirectory) {
for await (const x of _ls_pantry(path)) {
yield x
}
} else if (name === "package.yml") {
yield path
}
}
}
interface Entry {
name: string
path: string
}
const rv: Entry[] = []
for await (const item of ls()) {
rv.push(item)
}
if (Deno.env.get("GITHUB_ACTIONS")) {
const projects = rv.map(x => x.name).join(":")
console.log(`::set-output name=projects::${projects}`)
} else if (flags.json) {
const output = JSON.stringify(rv, null, 2)
console.log(output)
} else {
console.log(rv.map(x => x.name).join("\n"))
}

View file

@ -15,11 +15,9 @@ args:
import { parsePackageRequirement } from "types"
import hydrate from "prefab/hydrate.ts"
import { get_build_deps } from "./_lib.ts"
import useFlags from "hooks/useFlags.ts"
//<FIXME>
import { print } from "utils"
print("this because otherwise console.verbose is not defined lol")
//</FIXME>
const flags = useFlags()
const dry = Deno.args.map(project => {
const match = project.match(/projects\/(.*)\/package.yml/)
@ -31,4 +29,10 @@ const wet = await hydrate(dry, get_build_deps(set))
const gas = wet.map(x => x.project)
.filter(x => set.has(x)) // we're only sorting `dry` so reject the rest
console.log(`::set-output name=pkgs::${gas.join(" ")}`)
if (Deno.env.get("GITHUB_ACTIONS")) {
console.log(`::set-output name=pkgs::${gas.join(" ")}`)
} else if (flags.json) {
console.log(gas)
} else {
console.log(gas.join("\n"))
}

View file

@ -17,6 +17,9 @@ import usePantry from "hooks/usePantry.ts"
import useShellEnv, { expand } from "hooks/useShellEnv.ts"
import { run, undent, isPlainObject } from "utils"
import { validatePackageRequirement } from "utils/lvl2.ts"
import useFlags from "hooks/useFlags.ts"
useFlags()
//TODO install any other deps
@ -69,10 +72,11 @@ function get_deps() {
return rv
function attempt(obj: PlainObject) {
if (isPlainObject(obj))
for (const [project, constraint] of Object.entries(obj)) {
const pkg = validatePackageRequirement({ project, constraint })
if (pkg) rv.push(pkg)
if (isPlainObject(obj)) {
for (const [project, constraint] of Object.entries(obj)) {
const pkg = validatePackageRequirement({ project, constraint })
if (pkg) rv.push(pkg)
}
}
}
}

View file

@ -6,7 +6,7 @@ args:
- run
- --allow-net
- --allow-read=/opt
- --allow-env=AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,AWS_S3
- --allow-env
- --import-map={{ srcroot }}/import-map.json
---*/
@ -16,6 +16,9 @@ import useCache from "hooks/useCache.ts"
import useCellar from "hooks/useCellar.ts"
import { encodeToString } from "encodeToString"
import { Package, parsePackageRequirement, SemVer, semver } from "types"
import useFlags from "hooks/useFlags.ts"
useFlags()
if (Deno.args.length === 0) throw new Error("no args supplied")