Skip to content

Commit

Permalink
Add a quick-n-dirty way to generate the boilerplate for the official …
Browse files Browse the repository at this point in the history
…plugin list
  • Loading branch information
Phault committed Mar 9, 2024
1 parent f7de66d commit 86278e2
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 0 deletions.
1 change: 1 addition & 0 deletions .prototools
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ caddy = "2.7.6"
cmake = "3.28.3"
cosign = "2.2.3"
dagger = "0.10.0"
deno = "1.41.2"
dprint = "0.45.0"
fly = "0.2.13"
flyctl = "0.2.13"
Expand Down
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["denoland.vscode-deno"]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"deno.enable": true
}
104 changes: 104 additions & 0 deletions _scripts/build-for-proto-docs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { parse } from "@std/toml";
import { join, dirname } from "@std/path";

/**
* Quick and very dirty script to generate most of the JS needed to submit plugins for https://moonrepo.dev/docs/proto/tools#third-party
*/

interface ProtoToolDoc {
name: string;
description: string;
homepageUrl?: string;
repoUrl: string;
noIcon?: boolean; // If no SVG
pluginLocator?: string;
pluginType: "toml" | "wasm";
usageId?: string;
author: string;
bins?: string[];
globalsDirs?: string[];
detectionSources?: {
file: string;
label?: string;
url?: string;
}[];
}

type Prototools = {
plugins: Record<string, string>;
};

type PluginToml = {
name: string;
resolve: {
"git-url": string;
};
};

const currentPrototoolsTsx = await fetch(
"https://raw.githubusercontent.com/moonrepo/moon/master/website/src/data/proto-tools.tsx",
).then((r) => r.text());

const [_, currentToolsObjectJs] =
currentPrototoolsTsx.match(
/export const THIRD_PARTY_TOOLS[^=]+=\s+([^;]+)/,
) ?? [];

if (!currentToolsObjectJs)
throw new Error("Failed to find THIRD_PARTY_TOOLS object");

const existingTools = eval?.(`(${currentToolsObjectJs})`) as Record<
string,
ProtoToolDoc
>;

const root = join(import.meta.dirname!, "..");

const prototools = parse(
await Deno.readTextFile(join(root, ".prototools")),
) as Prototools;

const markdownLinkRegex = /\[[^\]]+\]\(([^)]+)\)/;

const blacklist = [
// registered as flyctl
"fly",
];

const newTools = Object.entries(prototools.plugins)
.filter(([id]) => !existingTools[id])
.filter(([id]) => !blacklist.includes(id))
.map(([id, source]) => {
const relativePluginPath = source.split(":").at(-1)!;

const pluginTomlRaw = Deno.readTextFileSync(join(root, relativePluginPath));
const pluginToml = parse(pluginTomlRaw) as PluginToml;

const readme = Deno.readTextFileSync(
join(root, dirname(relativePluginPath), "README.md"),
);
const [_, homepageUrl] = markdownLinkRegex.exec(readme) ?? [];

return [
id,
{
author: "Phault",
bins: [id],
description: "",
homepageUrl,
name: pluginToml.name,
noIcon: true,
pluginLocator: `source:https://raw.githubusercontent.com/Phault/proto-toml-plugins/main/${relativePluginPath}`,
pluginType: "toml",
repoUrl: "https://github.com/Phault/proto-toml-plugins",
},
] satisfies [string, ProtoToolDoc];
});

const combinedTools = Object.fromEntries(
Object.entries(existingTools)
.concat(newTools)
.toSorted(([a], [b]) => a.localeCompare(b)),
);

console.log(JSON.stringify(combinedTools, undefined, 2));
6 changes: 6 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"imports": {
"@std/path": "jsr:@std/path@^0.219.1",
"@std/toml": "jsr:@std/toml@^0.219.1"
}
}
38 changes: 38 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 86278e2

Please sign in to comment.