-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kicak start some search with algolia (#13)
- Loading branch information
Showing
9 changed files
with
563 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/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" | ||
|
||
interface Package { | ||
project: string | ||
description: string | ||
brief: string | ||
displayName: string | ||
programs: string[] | ||
} | ||
|
||
export async function getKettleRemoteMetadata() { | ||
const headers = { Authorization: 'public' } | ||
const rsp = await fetch(`https://app.pkgx.dev/v1/packages/`, {headers}) | ||
const data = await rsp.json() as (Package & { short_description: string })[] | ||
/// just pick out the fields we want | ||
return data.map(({ project, description, short_description }) => ({ project, description, brief: short_description })) | ||
} | ||
|
||
function get_name(yml: any, project: string) { | ||
return get_pkg_name({ project, display_name: yml['display_name'], provides: yml['provides'] }) | ||
} | ||
|
||
|
||
const rv = await getKettleRemoteMetadata() | ||
|
||
for (const obj of rv as Package[]) { | ||
const yaml_path = `./projects/${obj.project}/package.yml` | ||
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)) | ||
} | ||
|
||
console.log(JSON.stringify(rv, null, 2)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ export async function getKettleRemoteMetadata() { | |
const headers = { Authorization: 'public' } | ||
const rsp = await fetch(`https://app.pkgx.dev/v1/packages/`, {headers}) | ||
const foo = await rsp.json() as {project: string, short_description: string}[] | ||
return foo.reduce((acc, {project, short_description}) => { | ||
return foo.reduce((acc, {project, short_description, description}) => { | ||
acc[project] = short_description | ||
return acc | ||
}, {} as Record<string, string>) | ||
|
@@ -75,18 +75,12 @@ console.log(JSON.stringify(pkgs, null, 2)); | |
////////////////////////////////////////////////////// | ||
import { parse } from "https://deno.land/[email protected]/yaml/mod.ts"; | ||
import { isArray } from "https://deno.land/x/[email protected]/src/index.ts"; | ||
import get_pkg_name from "../../src/utils/pkg-name.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> | ||
if (yml['display-name']) { | ||
return yml['display-name'] | ||
} else if (isArray(yml.provides) && yml.provides.length == 1) { | ||
return yml.provides[0].slice(4) | ||
} else { | ||
return get_pkg_name(project) | ||
} | ||
return get_pkg_name({ project, display_name: yml['display_name'], provides: yml['provides'] }) | ||
} | ||
|
||
import { parse_pkgs_node } from "https://deno.land/x/[email protected]/src/hooks/usePantry.ts" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import get_name_base from '../../../src/utils/pkg-name.ts' | ||
import { isArray, isString } from "https://deno.land/x/[email protected]/src/index.ts"; | ||
|
||
export default function get_name(opts: {display_name?: string, provides?: (string[] | string), project: string}): string { | ||
const { display_name, provides, project } = opts | ||
if (display_name) { | ||
return display_name | ||
} else if (isArray(provides) && provides?.length == 1) { | ||
return provides[0].slice(4) | ||
} else if (isString(provides)) { | ||
return (provides as string)!.slice(4) | ||
} else { | ||
return get_name_base(project) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.