Skip to content

Commit

Permalink
Move usePantry().ls() out into bottle-all.ts.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhheider committed Jul 13, 2022
1 parent 71d171d commit ce92f69
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 26 deletions.
18 changes: 15 additions & 3 deletions scripts/bottle-all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import usePantry from "hooks/usePantry.ts"
import { bottle } from "./bottle.ts";
import { semver } from "types";
import useCellar from "hooks/useCellar.ts";
import { join } from "deno/path/mod.ts";

const pantry = usePantry();

const projects = await pantry.ls()

for await (const project of projects) {
for await (const project of lsPantry()) {
console.log({project})
const versions = await pantry.getVersions({ project, constraint: new semver.Range('*') })
const reqs = new Set(versions.map(v => `${v.major}.${v.minor}`))
for (const req of reqs) {
Expand All @@ -34,3 +34,15 @@ for await (const project of projects) {
}
}
}

export async function* lsPantry(path = ""): AsyncGenerator<string, void, void> {
for await (const p of Deno.readDir(`/opt/tea.xyz/var/pantry/projects/${path}`)) {
if (p.name === "package.yml") {
yield path
} else if (p.isDirectory) {
for await (const p1 of lsPantry(join(path, p.name))) {
if (p1) { yield p1 }
}
}
}
}
8 changes: 4 additions & 4 deletions scripts/build-all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ args:
- --allow-run
- --allow-read=/opt
- --allow-write=/opt
- --allow-env=AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,S3_BUCKET,GITHUB_TOKEN,VERBOSE,DEBUG,MAGIC,PATH,MANPATH,PKG_CONFIG_PATH,LIBRARY_PATH,CPATH,XDG_DATA_DIRS
- --allow-env=AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,S3_BUCKET,GITHUB_TOKEN,VERBOSE,DEBUG,MAGIC,PATH,MANPATH,PKG_CONFIG_PATH,LIBRARY_PATH,CPATH,XDG_DATA_DIRS,CMAKE_PREFIX_PATH
- --import-map={{ srcroot }}/import-map.json
---*/

Expand All @@ -22,9 +22,9 @@ import useCache from "hooks/useCache.ts"
import useCellar from "hooks/useCellar.ts"
import useSourceUnarchiver from "hooks/useSourceUnarchiver.ts"
import { S3 } from "s3";
import { lsPantry } from "./bottle-all.ts";

const pantry = usePantry();
const projects = await pantry.ls()

const s3 = new S3({
accessKeyID: Deno.env.get("AWS_ACCESS_KEY_ID")!,
Expand All @@ -39,7 +39,7 @@ const results: { built: string[], failed: string[] } = {
failed: []
}

for await (const project of projects) {
for await (const project of lsPantry()) {
try {
const req = { project, constraint: new semver.Range('*') }
await buildIfNeeded({ project: req, install: false })
Expand Down Expand Up @@ -132,4 +132,4 @@ async function prepare(pkg: Package) {
zipfile: zip,
stripComponents
})
}
}
2 changes: 1 addition & 1 deletion scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ args:
- --allow-run
- --allow-read=/opt
- --allow-write=/opt
- --allow-env=VERBOSE,DEBUG,MAGIC,PATH,MANPATH,PKG_CONFIG_PATH,GITHUB_TOKEN,CPATH,LIBRARY_PATH,XDG_DATA_DIRS
- --allow-env=VERBOSE,DEBUG,MAGIC,PATH,MANPATH,PKG_CONFIG_PATH,GITHUB_TOKEN,CPATH,LIBRARY_PATH,XDG_DATA_DIRS,CMAKE_PREFIX_PATH
- --import-map={{ srcroot }}/import-map.json
---*/

Expand Down
19 changes: 1 addition & 18 deletions src/hooks/usePantry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import useGitHubAPI from "hooks/useGitHubAPI.ts"
import { run, flatMap, isNumber, isPlainObject, isString, isArray, undent } from "utils"
import useCellar from "hooks/useCellar.ts"
import usePlatform from "hooks/usePlatform.ts"
import { join } from "deno/path/mod.ts";


interface GetDepsOptions {
Expand All @@ -19,8 +18,6 @@ interface Response {
getBuildScript(pkg: Package): Promise<string>
update(): Promise<void>
getProvides(rq: PackageRequirement | Package): Promise<string[]>
/// list all packages in the pantry
ls(): Promise<string[]>
}

interface Entry {
Expand Down Expand Up @@ -172,21 +169,7 @@ export default function usePantry(): Response {
})
}

const ls = async (path = "") => {
let rv: string[] = []
for await (const p of Deno.readDir(`${prefix}/${path}`)) {
const name = join(path, p.name)
try {
await entry({ project: name, constraint: new semver.Range('*') }).yml();
rv.push(name)
} catch {
rv = rv.concat(await ls(name))
}
}
return rv.sort();
}

return { getVersions, getDeps, getDistributable, getBuildScript, update, getProvides, ls }
return { getVersions, getDeps, getDistributable, getBuildScript, update, getProvides }
}


Expand Down

0 comments on commit ce92f69

Please sign in to comment.