new format wip

This commit is contained in:
Dylan Pizzo
2026-06-10 21:47:30 -04:00
parent 07595c31ef
commit 876404d8f5
45 changed files with 10893 additions and 144129 deletions
-44
View File
@@ -1,44 +0,0 @@
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);
fs.mkdirSync(dir, {recursive: true});
const outputFile = path.join(dir, "output.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*(\[.*?\])/s);
if (!match) {
console.log("BEGIN js contents --------------------------------------------");
console.log(js);
console.log("END js contents ----------------------------------------------");
throw Error("Could not properly parse js file to find _cartdat");
}
return JSON.parse(match[1]) as number[]
}
const getCart = async (baseDir: string, inputFile: string) => {
return {
name: inputFile,
rom: await getRom(path.join(baseDir, inputFile)),
}
}
export const getCarts = async (baseDir: string, inputFiles: string[]) => {
return await Promise.all(inputFiles.map(inputFile => getCart(baseDir, inputFile)));
}
+51
View File
@@ -0,0 +1,51 @@
import crypto from "node:crypto";
// Key derivation from password
const algorithm = "aes-256-gcm";
// TODO: make salt vary by use case;
const salt = "saltysalt";
export const encrypt = (props: { password: string; text: string }) => {
const { password, text } = props;
const key = new Uint8Array(crypto.scryptSync(password, salt, 32)); // 32 bytes key
const iv = new Uint8Array(crypto.randomBytes(16)); // Initialization Vector
// Encryption
const cipher = crypto.createCipheriv(algorithm, key, iv);
let encrypted = cipher.update(text, "utf8", "hex");
encrypted += cipher.final("hex");
const authTag = cipher.getAuthTag().toString("hex");
const fullEncrypted =
authTag + "+" + Buffer.from(iv).toString("hex") + ":" + encrypted; // Store IV with encrypted data
// console.log({ iv, authTag });
return fullEncrypted;
};
export const decrypt = (props: { password: string; cyphertext: string }) => {
const { password, cyphertext } = props;
const key = new Uint8Array(crypto.scryptSync(password, salt, 32)); // 32 bytes key
// Decryption
const [pre, encryptedHex] = cyphertext.split(":");
const [authTag, ivHex] = pre.split("+");
const ivFromStorage = new Uint8Array(Buffer.from(ivHex, "hex"));
// console.log({ ivFromStorage, authTag });
const decipher = crypto.createDecipheriv(algorithm, key, ivFromStorage);
decipher.setAuthTag(new Uint8Array(Buffer.from(authTag, "hex")));
let decrypted = decipher.update(encryptedHex, "hex", "utf8");
decrypted += decipher.final("utf8");
return decrypted;
};
// console.log(process.env.ENCRYPTION_PASSWORD);
// const x = encrypt({
// password: process.env.ENCRYPTION_PASSWORD!,
// text: "",
// });
// const y = decrypt({
// password: process.env.ENCRYPTION_PASSWORD!,
// cyphertext: "",
// });
// console.log(x);
// console.log(y);
-27
View File
@@ -1,27 +0,0 @@
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,
}
-38
View File
@@ -1,38 +0,0 @@
import fs from "fs";
import path from "path";
import {fileURLToPath} from 'url';
import {execFile} from "child_process";
const __dirname = fileURLToPath(new URL('.', import.meta.url));
const picoDirPath = path.resolve(__dirname, "..", "..", "..", "pico8");
const picoBinPath = path.resolve(picoDirPath, "pico8_dyn");
const cmd = (cmd: string, args: string[], options = {}) => {
return new Promise((resolve, reject) => {
execFile(cmd, args, options, (error, stdout, stderr) => {
if (error) {
reject({error, stderr});
} else {
resolve({stdout});
}
})
});
}
const execPico = async (args: string[]) => {
return await cmd(picoBinPath, args);
}
export const pico8 = {
async export(filesIn: string[], fileOut: string) {
try {
// console.log((await cmd("ls", ["-la", "/app/pico8"]) as any).stdout)
return await execPico([...filesIn, "-export", fileOut]);
} catch (err) {
console.log("CAUGHT ERROR", err);
}
}
}
// const result = await pico8.export(["/home/dylan/.lexaloffle/pico-8/carts/my-pico-project/mygame.p8","/home/dylan/.lexaloffle/pico-8/carts/my-pico-project/secondcart.p8"], "/home/dylan/repos/picobook/sample2.js");
// console.log(result);
-19
View File
@@ -1,19 +0,0 @@
import { execa } from "execa";
import path from "path";
import {fileURLToPath} from 'url';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
const shrinko8DirPath = path.resolve(__dirname, "../shrinko8");
const shrinko8Path = path.resolve(shrinko8DirPath, "shrinko8.py");
const pico8DatPath = path.resolve(__dirname, "../../../data/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])
}