-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
287 additions
and
34 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 |
---|---|---|
|
@@ -11,18 +11,25 @@ jobs: | |
name: Build pages | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
deno-version: [1.32.3] | ||
|
||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v4 | ||
- uses: oven-sh/setup-bun@v1 | ||
uses: actions/checkout@v3 | ||
- 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: | | ||
bun install | ||
bun bun.ts web | ||
run: deno run --unstable --allow-env --allow-run --allow-net --allow-read --allow-write deno.ts web | ||
- name: Pack 7z Package for nightly | ||
run: | | ||
cd nitrofiles | ||
|
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"deno.enable": false | ||
"deno.enable": true, | ||
"deno.unstable": true | ||
} |
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 |
---|---|---|
@@ -1,29 +1,27 @@ | ||
import { $, Subprocess } from "bun"; | ||
import { stat, exists, readdir, unlink } from "node:fs/promises"; | ||
|
||
import puppeteer, { Browser } from "puppeteer"; | ||
import {getAnyEdgeLatest} from "edge-paths" | ||
import puppeteer from "https://deno.land/x/[email protected]/mod.ts"; | ||
import {getAnyEdgeLatest} from "./edgePath.ts" | ||
import exists from "./exists.ts" | ||
|
||
const dedent = (string:string) => string.split('\n').map(line => line.trim()).join('\n') | ||
const needsUpdate = async (fileName: string, path:string) => | ||
!(await exists(fileName)) || ((await stat(fileName)).mtime || 0) < ((await stat(path)).mtime || 0) | ||
!(await exists(fileName)) || ((await Deno.stat(fileName)).mtime || 0) < ((await Deno.stat(path)).mtime || 0) | ||
|
||
const web = Bun.argv.includes("web"); | ||
let jekyll: Subprocess; | ||
const web = Deno.args.includes("web"); | ||
let jekyll; | ||
let accessURL:string; | ||
if (web) { | ||
accessURL = "https://" + await Bun.file("./CNAME").text(); | ||
console.log(`Generating images from ${accessURL}...`); | ||
accessURL = "https://" + await Deno.readTextFile("./CNAME"); | ||
console.log("Generating images from https://manual.ds-homebrew.com..."); | ||
} else { | ||
console.log("Generating images from local files..."); | ||
jekyll = Bun.spawn({ cmd: ["jekyll", "serve"] }) | ||
jekyll = new Deno.Command('bundle', { args: ['exec', 'jekyll', 'serve']}).spawn(); | ||
|
||
// Wait 5s for jekyll to be ready | ||
await new Promise(resolve => setTimeout(resolve, 5000)); | ||
accessURL = "http://127.0.0.1:4000/"; | ||
} | ||
|
||
let browser: Browser; | ||
let browser; | ||
try { | ||
browser = await puppeteer.launch({ product: 'chrome' }); | ||
} catch (error) { | ||
|
@@ -41,16 +39,18 @@ const tempFileNames = { | |
palette: "palette.png" | ||
} | ||
|
||
for (const folder of await readdir("pages", { withFileTypes: true })) { | ||
if (!folder.isDirectory()) | ||
for await (const folder of Deno.readDir("pages")) { | ||
if (!folder.isDirectory) | ||
continue; | ||
|
||
const dir = folder.name; | ||
if (dir == "_ic") | ||
continue; | ||
|
||
for (const subPageFolder of await readdir(`pages/${dir}`, { withFileTypes: true })) { | ||
if (subPageFolder.isDirectory()) | ||
await Deno.mkdir(`nitrofiles/pages/${dir.substring(1)}`, {recursive: true}); | ||
|
||
for await (const subPageFolder of Deno.readDir(`pages/${dir}`)) { | ||
if (subPageFolder.isDirectory) | ||
continue; | ||
|
||
const page = subPageFolder.name; | ||
|
@@ -77,8 +77,15 @@ for (const folder of await readdir("pages", { withFileTypes: true })) { | |
if (await needsUpdate(imagePath, `pages/${dir}/${page}`)) { | ||
await tab.screenshot({ path: tempFileNames.screenshot, clip: { x: 0, y: 0, width: 256, height: pageEval.height } }); | ||
|
||
$`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`; | ||
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(); | ||
} | ||
|
||
if (await needsUpdate(`nitrofiles/pages/${rootPath}.ini`, `pages/${dir}/${page}`)) { | ||
|
@@ -89,25 +96,24 @@ for (const folder of await readdir("pages", { withFileTypes: true })) { | |
BG_COLOR_2 = 0xA108 | ||
`) | ||
|
||
const iniLinks: string[] = []; | ||
const iniLinks = []; | ||
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 Bun.write(`nitrofiles/pages/${rootPath}.ini`, iniContent.trim()); | ||
await Deno.writeTextFile(`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 unlink(tempFile) | ||
await Deno.remove(tempFile) |
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,230 @@ | ||
import { join } from "https://deno.land/[email protected]/path/mod.ts" | ||
import exists from "./exists.ts" | ||
|
||
const platform = Deno.build.os | ||
|
||
// Caller will ensure that the platform is linux, otherwise null will be returned | ||
async function getEdgeLinux( | ||
name: | ||
| "microsoft-edge-dev" | ||
| "microsoft-edge-beta" | ||
| "microsoft-edge-stable", | ||
): Promise<string|null> { | ||
try { | ||
let path = await new Deno.Command('which', { args: [name] }).output() | ||
return new TextDecoder().decode(path.stdout); | ||
} catch (e) {} | ||
|
||
return null | ||
} | ||
|
||
|
||
// Caller will ensure that the platform is windows, otherwise null will be returned | ||
async function getEdgeWindows( | ||
edgeDirName: "Edge" | "Edge Dev" | "Edge Beta" | "Edge SxS", | ||
): Promise<string|null> { | ||
const paths = [] | ||
const suffix = `\\Microsoft\\${edgeDirName}\\Application\\msedge.exe` | ||
const prefixes = [ | ||
'LOCALAPPDATA', | ||
'PROGRAMFILES', | ||
"PROGRAMFILES(X86)", | ||
].map(string => Deno.env.get(string)).filter(Boolean) | ||
|
||
for (const prefix of prefixes) { | ||
const edgePath = join(prefix!, suffix) | ||
paths.push(edgePath) | ||
if (await exists(edgePath)) { | ||
return edgePath | ||
} | ||
} | ||
|
||
return null | ||
} | ||
|
||
// Caller will ensure that the platform is macos, otherwise null will be returned | ||
async function getEdgeDarwin(defaultPath: string): Promise<string|null> { | ||
if (await exists(defaultPath)) { | ||
return defaultPath | ||
} | ||
|
||
return null | ||
} | ||
|
||
const edgePaths = { | ||
edge: { | ||
linux: async () => await getEdgeLinux("microsoft-edge-stable"), | ||
darwin: async () => | ||
await getEdgeDarwin( | ||
"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge", | ||
), | ||
windows: async () => await getEdgeWindows("Edge"), | ||
}, | ||
dev: { | ||
linux: async () => await getEdgeLinux("microsoft-edge-dev"), | ||
darwin: async () => | ||
await getEdgeDarwin( | ||
"/Applications/Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Dev", | ||
), | ||
windows: async () => await getEdgeWindows("Edge Dev"), | ||
}, | ||
beta: { | ||
linux: async () => await getEdgeLinux("microsoft-edge-beta"), | ||
darwin: async () => | ||
await getEdgeDarwin( | ||
"/Applications/Microsoft Edge Beta.app/Contents/MacOS/Microsoft Edge Beta", | ||
), | ||
windows: async () => await getEdgeWindows("Edge Beta"), | ||
}, | ||
canary: { | ||
// linux: getEdgeLinux("microsoft-edge-beta"), | ||
darwin: async () => | ||
await getEdgeDarwin( | ||
"/Applications/Microsoft Edge Canary.app/Contents/MacOS/Microsoft Edge Canary", | ||
), | ||
windows: async () => await getEdgeWindows("Edge SxS"), | ||
}, | ||
} | ||
|
||
// returns edge path | ||
export async function getEdgePath(): Promise<string> { | ||
const edge = edgePaths.edge | ||
|
||
if (platform && platform in edgePaths.edge) { | ||
const pth = await edge[platform as keyof typeof edge]() | ||
if (pth) { | ||
return pth | ||
} | ||
} | ||
throwInvalidPlatformError("Edge Stable", edgePaths) | ||
} | ||
|
||
// Returns edge dev path | ||
export async function getEdgeDevPath(): Promise<string> { | ||
const edgeDev = edgePaths.dev | ||
|
||
if (platform && platform in edgeDev) { | ||
let pth = await edgeDev[platform as keyof typeof edgeDev]() | ||
if (pth) { | ||
return pth | ||
} | ||
} | ||
throwInvalidPlatformError("Edge Dev", edgePaths) | ||
} | ||
|
||
// Returns edge beta path if it is available | ||
export async function getEdgeBetaPath(): Promise<string> { | ||
const edgeBeta = edgePaths.beta | ||
|
||
if (platform && platform in edgeBeta) { | ||
const pth = await edgeBeta[platform as keyof typeof edgeBeta]() | ||
if (pth) { | ||
return pth | ||
} | ||
} | ||
throwInvalidPlatformError("Edge Beta", edgePaths) | ||
} | ||
|
||
// Returns edge canary paths. | ||
export async function getEdgeCanaryPath(): Promise<string> { | ||
const edgeCanary = edgePaths.canary | ||
|
||
if (platform && platform in edgeCanary) { | ||
const pth = await edgeCanary[platform as keyof typeof edgeCanary]() | ||
if (pth) { | ||
return pth | ||
} | ||
} | ||
throwInvalidPlatformError("Edge Canary", edgePaths) | ||
} | ||
|
||
// This will try to get any edge from bleeding edge to most stable version | ||
export async function getAnyEdgeLatest(): Promise<string> { | ||
try { | ||
return await getEdgeCanaryPath() | ||
} catch (e) { | ||
throwIfNotEdgePathIssue(e) | ||
} | ||
|
||
try { | ||
return await getEdgeDevPath() | ||
} catch (e) { | ||
throwIfNotEdgePathIssue(e) | ||
} | ||
|
||
try { | ||
return await getEdgeBetaPath() | ||
} catch (e) { | ||
throwIfNotEdgePathIssue(e) | ||
} | ||
|
||
try { | ||
return await getEdgePath() | ||
} catch (e) { | ||
throwIfNotEdgePathIssue(e) | ||
} | ||
|
||
throw { | ||
name: "edge-paths", | ||
message: `Unable to find any ms-edge-browser`, | ||
} | ||
} | ||
|
||
// This will try to get edge from stable version to bleeding version | ||
// Useful for playwright, puppeteer related stuff | ||
export async function getAnyEdgeStable(): Promise<string> { | ||
try { | ||
return await getEdgePath() | ||
} catch (e) { | ||
throwIfNotEdgePathIssue(e) | ||
} | ||
|
||
try { | ||
return await getEdgeBetaPath() | ||
} catch (e) { | ||
throwIfNotEdgePathIssue(e) | ||
} | ||
|
||
try { | ||
return await getEdgeDevPath() | ||
} catch (e) { | ||
throwIfNotEdgePathIssue(e) | ||
} | ||
|
||
try { | ||
return await getEdgeCanaryPath() | ||
} catch (e) { | ||
throwIfNotEdgePathIssue(e) | ||
} | ||
|
||
throw { | ||
name: "edge-paths", | ||
message: `Unable to find any ms-edge-browser.`, | ||
} | ||
} | ||
|
||
// Helpers | ||
function throwInvalidPlatformError( | ||
additionalInfo: string = "", | ||
otherDetails?: any, | ||
): never { | ||
throw { | ||
name: "edge-paths", | ||
message: `Couldn't find the edge browser. ${additionalInfo}`, | ||
additionalInfo, | ||
otherDetails, | ||
} | ||
} | ||
|
||
function throwIfNotEdgePathIssue(obj: any) { | ||
if ( | ||
Object.prototype.toString.call(obj) === "[object Object]" && | ||
obj && | ||
obj.name && | ||
obj.name === "edge-paths" | ||
) { | ||
return | ||
} | ||
|
||
throw obj | ||
} |
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 @@ | ||
export default async function exists (filename: string): Promise<boolean> { | ||
try { | ||
await Deno.lstat(filename); | ||
// successful, file or directory must exist | ||
return true; | ||
} catch (error) { | ||
if (error instanceof Deno.errors.NotFound) { | ||
// file or directory does not exist | ||
return false; | ||
} else { | ||
// unexpected error, maybe permissions, pass it along | ||
throw error; | ||
} | ||
} | ||
} |
Oops, something went wrong.