Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: make scripts more lightweight #4

Merged
merged 1 commit into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions scripts/combine.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { walk } from "jsr:@std/fs";
import { parse } from "jsr:@std/yaml";

interface Stack {
Expand Down Expand Up @@ -31,27 +30,28 @@ async function parseYamlFile(filePath: string): Promise<unknown> {
return parse(fileContent);
}

async function collectData<T>(
async function collectData<T, D>(
dir: string,
transform: (data: all) => T,
transform: (data: D) => T,
): Promise<T[]> {
const items: T[] = [];

for await (
const entry of walk(dir, {
exts: [".yaml", ".yml"],
includeDirs: false,
})
) {
const data = await parseYamlFile(entry.path);
items.push(transform(data));
for await (const entry of Deno.readDir(dir)) {
// Only process files with .yaml or .yml extensions
if (
entry.isFile &&
(entry.name.endsWith(".yaml") || entry.name.endsWith(".yml"))
) {
const data = await parseYamlFile(`${dir}/${entry.name}`) as D;
items.push(transform(data));
}
}

return items;
}

function collectStacks(stacksDir: string): Promise<Stack[]> {
return collectData(stacksDir, (data) => ({
return collectData<Stack, Stack>(stacksDir, (data) => ({
name: data.name,
base: data.base,
packages: data.packages,
Expand All @@ -61,7 +61,7 @@ function collectStacks(stacksDir: string): Promise<Stack[]> {
}

function collectPkgManagers(pkgManagersDir: string): Promise<PkgManager[]> {
return collectData(pkgManagersDir, (data) => ({
return collectData<PkgManager, PkgManager>(pkgManagersDir, (data) => ({
name: data.name,
model: data.model,
needsudo: data.needsudo,
Expand Down
11 changes: 5 additions & 6 deletions scripts/feed.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Atom } from "jsr:@feed/feed";
import { dirname, join } from "jsr:@std/path";

interface Stack {
name: string;
Expand Down Expand Up @@ -31,10 +30,8 @@ interface UpdateData {
pkgManagers?: pkgManager[];
}

const __dirname = dirname(new URL(import.meta.url).pathname);

const data: UpdateData = JSON.parse(
await Deno.readTextFile(join(__dirname, "../_index.json")),
await Deno.readTextFile(new URL("../_index.json", import.meta.url).pathname),
);

const feed = new Atom({
Expand All @@ -44,7 +41,6 @@ const feed = new Atom({
id: "https://apx.vanillaos.org/",
link: "https://apx.vanillaos.org/",
language: "en",
updated: new Date(),
feedLinks: {
atom: "https://apx-community.vanillaos.org/feed.xml",
},
Expand Down Expand Up @@ -108,6 +104,9 @@ pkgManagers.forEach((pkgManager: pkgManager) => {
});
});

await Deno.writeTextFile(join(__dirname, "../feed.xml"), feed.build());
await Deno.writeTextFile(
new URL("../feed.xml", import.meta.url).pathname,
feed.build(),
);

console.log("Atom feed generated.");