try execFile
This commit is contained in:
		| @@ -1,12 +1,11 @@ | |||||||
| import { Type } from "@sinclair/typebox"; | import { Type } from "@sinclair/typebox"; | ||||||
| import { FirRouteInput, FirRouteOptions } from "../util/routewrap.js"; | import { FirRouteInput, FirRouteOptions } from "../util/routewrap.js"; | ||||||
| import {execa} from 'execa'; |  | ||||||
| import fs from "fs"; | import fs from "fs"; | ||||||
| import path from "path"; | import path from "path"; | ||||||
| import git from "isomorphic-git"; | import git from "isomorphic-git"; | ||||||
| import http from "isomorphic-git/http/node"; | import http from "isomorphic-git/http/node"; | ||||||
| import {fileURLToPath} from 'url'; | import {fileURLToPath} from 'url'; | ||||||
| const __filename = fileURLToPath(import.meta.url); | import { pico8 } from "../util/pico8.js"; | ||||||
| const __dirname = fileURLToPath(new URL('.', import.meta.url)); | const __dirname = fileURLToPath(new URL('.', import.meta.url)); | ||||||
|  |  | ||||||
| const method = "POST"; | const method = "POST"; | ||||||
| @@ -19,8 +18,6 @@ const url = "/api/release"; | |||||||
| const payloadT = Type.Any(); | const payloadT = Type.Any(); | ||||||
|  |  | ||||||
| const repoPath = path.resolve(__dirname, "..", "..", "..", "repo"); | const repoPath = path.resolve(__dirname, "..", "..", "..", "repo"); | ||||||
| const picoDirPath = path.resolve(__dirname, "..", "..", "..", "pico8"); |  | ||||||
| const picoBinPath = path.resolve(picoDirPath, "pico8"); |  | ||||||
|  |  | ||||||
| // const {stdout, } = await execa(picoBinPath, ["/home/dylan/.lexaloffle/pico-8/carts/candles/candles.p8", "-export", path.join(__dirname, "result.js")]); | // const {stdout, } = await execa(picoBinPath, ["/home/dylan/.lexaloffle/pico-8/carts/candles/candles.p8", "-export", path.join(__dirname, "result.js")]); | ||||||
| // const {stdout, } = await execa("ls", ["-la", picoDirPath]); | // const {stdout, } = await execa("ls", ["-la", picoDirPath]); | ||||||
| @@ -53,12 +50,12 @@ const handler = async ({payload}: FirRouteInput<typeof payloadT>) => { | |||||||
| 	}); | 	}); | ||||||
| 	console.log("cloned"); | 	console.log("cloned"); | ||||||
| 	console.log("read local manifest"); | 	console.log("read local manifest"); | ||||||
| 	console.log("pico exists: ", fs.existsSync(picoBinPath)); |  | ||||||
| 	console.log("manifest exists: ", fs.existsSync(path.join(repoPath, "picobook.json"))); | 	console.log("manifest exists: ", fs.existsSync(path.join(repoPath, "picobook.json"))); | ||||||
| 	console.log("main exists: ", fs.existsSync(path.join(repoPath, manifest.main))); | 	console.log("main exists: ", fs.existsSync(path.join(repoPath, manifest.main))); | ||||||
| 	// const {stdout} = await execa("ls", ["-la", picoDirPath], {shell: true}); | 	// const {stdout} = await execa("ls", ["-la", picoDirPath], {shell: true}); | ||||||
| 	// console.log(stdout); | 	// console.log(stdout); | ||||||
| 	await execa(picoBinPath, [path.join(repoPath, manifest.main), "-export", path.join(repoPath, "result.js")]); | 	await pico8.export(path.join(repoPath, manifest.main), path.join(repoPath, "result.js")); | ||||||
|  | 	// await execa(picoBinPath, [path.join(repoPath, manifest.main), "-export", path.join(repoPath, "result.js")]); | ||||||
| 	// await execa(picoBinPath, [path.join(repoPath, manifest.main), "-export", path.join(repoPath, "result.png")]); | 	// await execa(picoBinPath, [path.join(repoPath, manifest.main), "-export", path.join(repoPath, "result.png")]); | ||||||
| 	const js = await fs.promises.readFile(path.join(repoPath, "result.js"), "utf8"); | 	const js = await fs.promises.readFile(path.join(repoPath, "result.js"), "utf8"); | ||||||
| 	// const png = Buffer.from(await fs.promises.readFile(path.join(repoPath, "result.png"))).toString("base64"); | 	// const png = Buffer.from(await fs.promises.readFile(path.join(repoPath, "result.png"))).toString("base64"); | ||||||
|   | |||||||
							
								
								
									
										27
									
								
								src/server/util/pico8.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								src/server/util/pico8.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | |||||||
|  | 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]); | ||||||
|  | 	} | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user
	 dylan
					dylan