try to add and use shrinko8

This commit is contained in:
dylan
2024-03-31 13:49:09 -07:00
parent d606a8002f
commit c003955c3d
9 changed files with 117 additions and 75 deletions
+40
View File
@@ -0,0 +1,40 @@
import { randomUUID } from "crypto";
import { shrinko8 } from "./shrinko8";
import path from "path";
import fs from "fs";
import { fileURLToPath } from "url";
const __dirname = fileURLToPath(new URL('.', import.meta.url));
const outputDirPath = path.resolve(__dirname, "..", "..", "..", "output");
const getRom = async (inputFile: string) => {
const uuid = randomUUID();
const dir = path.join(outputDirPath, uuid);
const outputFile = path.join(dir, inputFile+".js");
await shrinko8({
inputFile,
outputFile,
});
const js = await fs.promises.readFile(outputFile, "utf8");
await fs.promises.rm(dir, {recursive: true, force: true});
const match = js.match(/\b_cartdat\s*=\s*(\[.*\])/);
if (!match) {
throw Error("Could not properly parse js file to find _cartdat");
}
return JSON.parse(match[1]) as number[]
}
const getCart = async (inputFile: string) => {
return {
name: inputFile,
rom: await getRom(inputFile),
}
}
export const getCarts = async (inputFiles: string[]) => {
return await Promise.all(inputFiles.map(getCart));
}
+27
View File
@@ -0,0 +1,27 @@
import fs from "fs";
import isogit from "isomorphic-git";
import http from "isomorphic-git/http/node";
const clone = async (options: {
from: string;
to: string;
auth?: string;
}) => {
fs.mkdirSync(options.to, {recursive: true});
await isogit.clone({
fs,
http,
onAuth() {
return {
username: 'x-access-token',
password: options.auth,
}
},
dir: options.to,
url: options.from,
});
}
export const git = {
clone,
}
+18
View File
@@ -0,0 +1,18 @@
import { execa } from "execa";
import path from "path";
import {fileURLToPath} from 'url';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
const shrinko8Path = path.resolve(__dirname, "../shrinko8");
const pico8DatPath = path.resolve(__dirname, "../../pico8.dat");
export const shrinko8 = async (props: {
inputFile: string;
outputFile: string;
options?: string[];
}) => {
const {inputFile, outputFile, options = []} = props;
return await execa("python3", [shrinko8Path, inputFile, outputFile, "--pico8-dat", pico8DatPath, ...options])
}