Skip to content

Commit

Permalink
Switch to bun
Browse files Browse the repository at this point in the history
Experiment to see if it'll be quicker
  • Loading branch information
NightScript370 committed Apr 4, 2024
1 parent 05ed310 commit 056c44d
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 287 deletions.
17 changes: 5 additions & 12 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,18 @@ jobs:
name: Build pages

runs-on: ubuntu-latest
strategy:
matrix:
deno-version: [1.32.3]

steps:
- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- name: Install tools
run: |
sudo apt-get update
sudo apt-get install ffmpeg jq p7zip-full -y
- name: Use Deno Version ${{ matrix.deno-version }}
uses: denoland/setup-deno@v1
with:
deno-version: ${{ matrix.deno-version }}
- name: Install Dependencies
run: PUPPETEER_PRODUCT=chrome deno run --unstable --allow-env --allow-net --allow-write --allow-read https://deno.land/x/[email protected]/install.ts
- name: Run Application
run: deno run --unstable --allow-env --allow-run --allow-net --allow-read --allow-write deno.ts web
run: |
bun install
bun bun.ts web
- name: Pack 7z Package for nightly
run: |
cd nitrofiles
Expand Down
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"deno.enable": true,
"deno.unstable": true
"deno.enable": false
}
Binary file added bun.lockb
Binary file not shown.
50 changes: 22 additions & 28 deletions deno.ts → bun.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import puppeteer from "https://deno.land/x/[email protected]/mod.ts";
import {getAnyEdgeLatest} from "./edgePath.ts"
import exists from "./exists.ts"
import { $, Subprocess } from "bun";
import { stat, exists, readdir, unlink } from "node:fs/promises";

import puppeteer, { Browser } from "puppeteer";
import {getAnyEdgeLatest} from "edge-paths"

const dedent = (string:string) => string.split('\n').map(line => line.trim()).join('\n')
const needsUpdate = async (fileName: string, path:string) =>
!(await exists(fileName)) || ((await Deno.stat(fileName)).mtime || 0) < ((await Deno.stat(path)).mtime || 0)
!(await exists(fileName)) || ((await stat(fileName)).mtime || 0) < ((await stat(path)).mtime || 0)

const web = Deno.args.includes("web");
let jekyll;
const web = Bun.argv.includes("web");
let jekyll: Subprocess;
let accessURL:string;
if (web) {
accessURL = "https://" + await Deno.readTextFile("./CNAME");
console.log("Generating images from https://manual.ds-homebrew.com...");
accessURL = "https://" + await Bun.file("./CNAME").text();
console.log(`Generating images from ${accessURL}...`);
} else {
console.log("Generating images from local files...");
jekyll = new Deno.Command('bundle', { args: ['exec', 'jekyll', 'serve']}).spawn();
jekyll = Bun.spawn({ cmd: ["jekyll", "serve"] })

// Wait 5s for jekyll to be ready
await new Promise(resolve => setTimeout(resolve, 5000));
accessURL = "http://127.0.0.1:4000/";
}

let browser;
let browser: Browser;
try {
browser = await puppeteer.launch({ product: 'chrome' });
} catch (error) {
Expand All @@ -39,18 +41,16 @@ const tempFileNames = {
palette: "palette.png"
}

for await (const folder of Deno.readDir("pages")) {
if (!folder.isDirectory)
for (const folder of await readdir("pages", { withFileTypes: true })) {
if (!folder.isDirectory())
continue;

const dir = folder.name;
if (dir == "_ic")
continue;

await Deno.mkdir(`nitrofiles/pages/${dir.substring(1)}`, {recursive: true});

for await (const subPageFolder of Deno.readDir(`pages/${dir}`)) {
if (subPageFolder.isDirectory)
for (const subPageFolder of await readdir(`pages/${dir}`, { withFileTypes: true })) {
if (subPageFolder.isDirectory())
continue;

const page = subPageFolder.name;
Expand All @@ -77,15 +77,8 @@ for await (const folder of Deno.readDir("pages")) {
if (await needsUpdate(imagePath, `pages/${dir}/${page}`)) {
await tab.screenshot({ path: tempFileNames.screenshot, clip: { x: 0, y: 0, width: 256, height: pageEval.height } });

const paletteProcess = new Deno.Command('ffmpeg', {
args: ["-i", tempFileNames.screenshot, "-vf", "palettegen=max_colors=246", tempFileNames.palette, "-y", "-loglevel", "error"]
});
await paletteProcess.output();

const conversionProcess = new Deno.Command('ffmpeg', {
args: ["-i", tempFileNames.screenshot, "-i", tempFileNames.palette, "-filter_complex", "paletteuse", imagePath, "-y", "-loglevel", "error"]
})
await conversionProcess.output();
$`ffmpeg -i ${tempFileNames.screenshot} -vf palettegen=max_colors=246 ${tempFileNames.palette} -y -loglevel error`;
$`ffmpeg -i ${tempFileNames.screenshot} -i ${tempFileNames.palette} -filter_complex paletteuse ${imagePath} -y -loglevel error`;
}

if (await needsUpdate(`nitrofiles/pages/${rootPath}.ini`, `pages/${dir}/${page}`)) {
Expand All @@ -96,24 +89,25 @@ for await (const folder of Deno.readDir("pages")) {
BG_COLOR_2 = 0xA108
`)

const iniLinks = [];
const iniLinks: string[] = [];
for (const index in pageEval.links) {
iniLinks.push(`[LINK${index}]\n` + Object.entries(pageEval.links[index])
.map(([key, value]) => `${key} = ${value}`)
.join('\n'))
}

iniContent += iniLinks.join('\n\n')
await Deno.writeTextFile(`nitrofiles/pages/${rootPath}.ini`, iniContent.trim());
await Bun.write(`nitrofiles/pages/${rootPath}.ini`, iniContent.trim());
}
}
}

await browser.close();

// @ts-ignore
if (jekyll)
jekyll.kill();

for (const tempFile of Object.values(tempFileNames))
if (await exists(tempFile))
await Deno.remove(tempFile)
await unlink(tempFile)
230 changes: 0 additions & 230 deletions edgePath.ts

This file was deleted.

15 changes: 0 additions & 15 deletions exists.ts

This file was deleted.

Loading

0 comments on commit 056c44d

Please sign in to comment.