27 lines
716 B
TypeScript
27 lines
716 B
TypeScript
|
|
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) {
|
||
|
|
return await execPico([fileIn, "-export", fileOut]);
|
||
|
|
}
|
||
|
|
}
|