Files
picobook/src/server/util/pico8.ts
T

34 lines
946 B
TypeScript
Raw Normal View History

2024-03-27 19:17:12 -07:00
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");
const execPico = (args: string[]) => {
return new Promise((resolve, reject) => {
const options = {};
execFile(picoBinPath, args, options, (error, stdout, stderr) => {
if (error) {
reject({error, stderr});
} else {
resolve({stdout});
}
})
});
}
export const pico8 = {
async export(fileIn: string, fileOut: string) {
2024-03-27 19:22:08 -07:00
try {
return await execPico([fileIn, "-export", fileOut]);
} catch (err) {
console.log("CAUGHT ERROR", err);
}
2024-03-27 19:17:12 -07:00
}
2024-03-27 19:22:08 -07:00
}
// const result = await pico8.export("/home/dylan/.lexaloffle/pico-8/carts/candles/candles.p8", "/home/dylan/repos/picobook/sample.js");
// console.log(result);