Skip to content

Commit

Permalink
Handle platform specific provides yml
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Jan 17, 2024
1 parent 9a20fd7 commit 4b65dd6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
11 changes: 5 additions & 6 deletions .github/scripts/gen-algolia-data.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env -S pkgx deno run --allow-read=. --allow-net

import * as yaml from "https://deno.land/[email protected]/yaml/mod.ts";
import { isArray, isString } from "https://deno.land/x/[email protected]/src/index.ts";
import get_pkg_name from "./utils/get-name.ts"
import get_provides from "./utils/get-provides.ts"
import { basename } from "path";

interface Package {
project: string
Expand All @@ -24,7 +25,8 @@ export async function getKettleRemoteMetadata() {
}

function get_name(yml: any, project: string) {
return get_pkg_name({ project, display_name: yml['display-name'], provides: yml['provides'] })
const provides = get_provides(yml)
return get_pkg_name({ project, display_name: yml['display-name'], provides })
}


Expand All @@ -37,11 +39,8 @@ for (const obj of rv as Package[]) {
const txt = await Deno.readTextFileSync(yaml_path)
const yml = await yaml.parse(txt) as Record<string, any>

const node = yml['provides']
const provides: string[] = isArray(node) ? node : isString(node) ? [node] : []

obj.displayName = get_name(yaml_path, obj.project)
obj.programs = provides.map(x => x.slice(4))
obj.programs = get_provides(yml).map(x => basename(x))
} catch (err) {
console.warn(`::warning::${err.message}`)
}
Expand Down
4 changes: 3 additions & 1 deletion .github/scripts/gen-pkgs-index.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ console.log(JSON.stringify(pkgs, null, 2));

//////////////////////////////////////////////////////
import { parse } from "https://deno.land/[email protected]/yaml/mod.ts";
import get_provides from "./utils/get-provides.ts";
import get_pkg_name from "./utils/get-name.ts";

async function get_name(path: string, project: string): Promise<string | undefined> {
const txt = await Deno.readTextFileSync(path)
const yml = await parse(txt) as Record<string, any>
return get_pkg_name({ project, display_name: yml['display-name'], provides: yml['provides'] })
const provides = get_provides(yml)
return get_pkg_name({ project, display_name: yml['display-name'], provides })
}

import { parse_pkgs_node } from "https://deno.land/x/[email protected]/src/hooks/usePantry.ts"
Expand Down
16 changes: 16 additions & 0 deletions .github/scripts/utils/get-provides.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { isString, isPlainObject } from "https://deno.land/x/[email protected]/src/index.ts";

export default function get_provides(yml: any): string[] {
let provides = yml['provides']
if (isString(provides)) {
return [provides]
}
if (isPlainObject(provides)) {
const { darwin, linux, windows } = provides
provides = []
for (const x of [darwin, linux, windows]) {
if (x) provides.push(...x)
}
}
return provides
}

0 comments on commit 4b65dd6

Please sign in to comment.