try to add and use shrinko8
This commit is contained in:
@@ -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));
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
@@ -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])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user