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");
|
2024-03-27 21:09:47 -07:00
|
|
|
const picoBinPath = path.resolve(picoDirPath, "pico8_dyn");
|
2024-03-27 19:17:12 -07:00
|
|
|
|
2024-03-27 19:41:23 -07:00
|
|
|
const cmd = (cmd: string, args: string[], options = {}) => {
|
2024-03-27 19:17:12 -07:00
|
|
|
return new Promise((resolve, reject) => {
|
2024-03-27 19:41:23 -07:00
|
|
|
execFile(cmd, args, options, (error, stdout, stderr) => {
|
2024-03-27 19:17:12 -07:00
|
|
|
if (error) {
|
|
|
|
|
reject({error, stderr});
|
|
|
|
|
} else {
|
|
|
|
|
resolve({stdout});
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-27 19:41:23 -07:00
|
|
|
const execPico = async (args: string[]) => {
|
|
|
|
|
return await cmd(picoBinPath, args);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-27 19:17:12 -07:00
|
|
|
export const pico8 = {
|
2024-03-29 02:02:40 -07:00
|
|
|
async export(filesIn: string[], fileOut: string) {
|
2024-03-27 19:22:08 -07:00
|
|
|
try {
|
2024-03-27 21:04:24 -07:00
|
|
|
// console.log((await cmd("ls", ["-la", "/app/pico8"]) as any).stdout)
|
2024-03-29 02:02:40 -07:00
|
|
|
return await execPico([...filesIn, "-export", fileOut]);
|
2024-03-27 19:22:08 -07:00
|
|
|
} catch (err) {
|
|
|
|
|
console.log("CAUGHT ERROR", err);
|
|
|
|
|
}
|
2024-03-27 19:17:12 -07:00
|
|
|
}
|
2024-03-27 19:22:08 -07:00
|
|
|
}
|
|
|
|
|
|
2024-03-29 02:02:40 -07:00
|
|
|
// 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");
|
2024-03-27 19:22:08 -07:00
|
|
|
// console.log(result);
|