try to add and use shrinko8
This commit is contained in:
parent
d606a8002f
commit
c003955c3d
27
Dockerfile
27
Dockerfile
@ -1,30 +1,13 @@
|
|||||||
# Installs Node image
|
# Installs Node image
|
||||||
FROM node:18-alpine as base
|
FROM node:18-buster as base
|
||||||
|
|
||||||
# sets the working directory for any RUN, CMD, COPY command
|
# sets the working directory for any RUN, CMD, COPY command
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# ENV PORT=3000
|
# Install Python and pip
|
||||||
# ENV DB_HOST=postgres
|
RUN apk add --update python3 py3-pip
|
||||||
# ENV DB_USER=postgres
|
RUN python3 -m ensurepip
|
||||||
# ENV DB_NAME=db_name
|
RUN pip3 install --no-cache --upgrade pip setuptools
|
||||||
# ENV DB_PASSWORD=password
|
|
||||||
# ENV DB_PORT=5432
|
|
||||||
# ENV DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}
|
|
||||||
|
|
||||||
# intentionally here only for temporary cache-busting test
|
|
||||||
# COPY ./client ./client
|
|
||||||
|
|
||||||
# RUN apt update
|
|
||||||
# RUN apt -y install python3
|
|
||||||
|
|
||||||
# RUN apt-get update
|
|
||||||
# RUN apt-get -y install libsdl2-dev
|
|
||||||
# RUN apt-get -y install xorg-dev
|
|
||||||
|
|
||||||
# COPY ./pico8 ./pico8
|
|
||||||
# RUN echo "chmoding pico8"
|
|
||||||
# RUN chmod +x ./usr/bin/pico8
|
|
||||||
|
|
||||||
# Copies stuff to cache for install
|
# Copies stuff to cache for install
|
||||||
COPY ./package.json ./package-lock.json tsconfig.json ./
|
COPY ./package.json ./package-lock.json tsconfig.json ./
|
||||||
|
2
TODO.md
2
TODO.md
@ -1,10 +1,10 @@
|
|||||||
# TODO
|
# TODO
|
||||||
|
|
||||||
## MVP
|
## MVP
|
||||||
- [ ] Update GH Workflow to be by push
|
|
||||||
- [ ] Add version prop to picobook.json
|
- [ ] Add version prop to picobook.json
|
||||||
- [ ] "Compile" carts in server and save them to db
|
- [ ] "Compile" carts in server and save them to db
|
||||||
- [ ] Load cart by URL in React
|
- [ ] Load cart by URL in React
|
||||||
|
- [ ] Update GH Workflow to be by push
|
||||||
|
|
||||||
## Later
|
## Later
|
||||||
- [ ] Update pico console handle
|
- [ ] Update pico console handle
|
||||||
|
@ -8,6 +8,7 @@ const App = (props: {}) => {
|
|||||||
<div className={css`
|
<div className={css`
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
`}>
|
`}>
|
||||||
|
<h1>Picobook</h1>
|
||||||
<Pico8Console carts={testcarts.carts} />
|
<Pico8Console carts={testcarts.carts} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -1,71 +1,37 @@
|
|||||||
import { Type } from "@sinclair/typebox";
|
import { Type } from "@sinclair/typebox";
|
||||||
import { FirRouteInput, FirRouteOptions } from "../util/routewrap.js";
|
import { FirRouteInput, FirRouteOptions } from "../util/routewrap";
|
||||||
import fs from "fs";
|
import {git} from "../util/git.ts";
|
||||||
|
import { randomUUID } from "crypto";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import git from "isomorphic-git";
|
|
||||||
import http from "isomorphic-git/http/node";
|
|
||||||
import {fileURLToPath} from 'url';
|
import {fileURLToPath} from 'url';
|
||||||
import { pico8 } from "../util/pico8.js";
|
import { getCarts } from "../util/carts.ts";
|
||||||
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
||||||
|
const reposPath = path.resolve(__dirname, "..", "..", "..", "repos");
|
||||||
|
|
||||||
const method = "POST";
|
const method = "POST";
|
||||||
const url = "/api/release";
|
const url = "/api/release";
|
||||||
|
|
||||||
// const payloadT = Type.Object({
|
|
||||||
// png: Type.String(),
|
|
||||||
// });
|
|
||||||
|
|
||||||
const payloadT = Type.Any();
|
const payloadT = Type.Any();
|
||||||
|
|
||||||
const repoPath = path.resolve(__dirname, "..", "..", "..", "repo");
|
|
||||||
|
|
||||||
// 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]);
|
|
||||||
// console.log(stdout);
|
|
||||||
|
|
||||||
// const {stdout: stdout2, } = await execa(picoBinPath, ["-x"]);
|
|
||||||
// console.log(stdout2);
|
|
||||||
|
|
||||||
const handler = async ({payload}: FirRouteInput<typeof payloadT>) => {
|
const handler = async ({payload}: FirRouteInput<typeof payloadT>) => {
|
||||||
const {manifest, token} = payload;
|
const {manifest, token} = payload;
|
||||||
if (!fs.existsSync(repoPath)) {
|
|
||||||
fs.mkdirSync(repoPath, {recursive: true})
|
const uuid = randomUUID();
|
||||||
}
|
const repoPath = path.join(reposPath, uuid);
|
||||||
console.log(manifest);
|
|
||||||
console.log("cloning...");
|
|
||||||
await git.clone({
|
await git.clone({
|
||||||
fs,
|
from: manifest.repo,
|
||||||
http,
|
to: repoPath,
|
||||||
// headers: {
|
auth: token,
|
||||||
// "Authorization": `Bearer ${token}`,
|
|
||||||
// },
|
|
||||||
onAuth() {
|
|
||||||
return {
|
|
||||||
username: 'x-access-token',
|
|
||||||
password: token,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
dir: repoPath,
|
|
||||||
url: manifest.repo,
|
|
||||||
});
|
});
|
||||||
console.log("cloned");
|
|
||||||
console.log("read local manifest");
|
const carts = await getCarts(manifest.carts);
|
||||||
console.log("manifest exists: ", fs.existsSync(path.join(repoPath, "picobook.json")));
|
|
||||||
console.log("main exists: ", fs.existsSync(path.join(repoPath, manifest.main)));
|
|
||||||
// const {stdout} = await execa("ls", ["-la", picoDirPath], {shell: true});
|
|
||||||
// console.log(stdout);
|
|
||||||
const exported=await pico8.export(path.join(repoPath, manifest.main), path.join(repoPath, "result.js"));
|
|
||||||
console.log((exported as any).stdout);
|
|
||||||
// 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")]);
|
|
||||||
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");
|
|
||||||
fs.promises.rm(repoPath, {recursive: true, force: true});
|
|
||||||
console.log({
|
console.log({
|
||||||
manifest,
|
manifest,
|
||||||
js,
|
carts,
|
||||||
// png,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,8 +3,15 @@ import Fastify from 'fastify'
|
|||||||
import fastifyStatic from '@fastify/static'
|
import fastifyStatic from '@fastify/static'
|
||||||
import { routeList } from "./routelist.ts";
|
import { routeList } from "./routelist.ts";
|
||||||
import { route } from "./util/routewrap.ts";
|
import { route } from "./util/routewrap.ts";
|
||||||
|
import { git } from './util/git.ts';
|
||||||
|
import path from "path";
|
||||||
|
import {fileURLToPath} from 'url';
|
||||||
|
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
||||||
|
|
||||||
console.log(process.env["DATABASE_URL"]);
|
await git.clone({
|
||||||
|
from: "https://github.com/thisismypassport/shrinko8/tree/v1.1.2",
|
||||||
|
to: path.resolve(__dirname, "shrinko8"),
|
||||||
|
});
|
||||||
|
|
||||||
const server = Fastify({
|
const server = Fastify({
|
||||||
logger: true
|
logger: true
|
||||||
|
40
src/server/util/carts.ts
Normal file
40
src/server/util/carts.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
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);
|
||||||
|
const outputFile = path.join(dir, inputFile+".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*(\[.*\])/);
|
||||||
|
if (!match) {
|
||||||
|
throw Error("Could not properly parse js file to find _cartdat");
|
||||||
|
}
|
||||||
|
|
||||||
|
return JSON.parse(match[1]) as number[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const getCart = async (inputFile: string) => {
|
||||||
|
return {
|
||||||
|
name: inputFile,
|
||||||
|
rom: await getRom(inputFile),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getCarts = async (inputFiles: string[]) => {
|
||||||
|
return await Promise.all(inputFiles.map(getCart));
|
||||||
|
}
|
27
src/server/util/git.ts
Normal file
27
src/server/util/git.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
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,
|
||||||
|
}
|
18
src/server/util/shrinko8.ts
Normal file
18
src/server/util/shrinko8.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { execa } from "execa";
|
||||||
|
import path from "path";
|
||||||
|
import {fileURLToPath} from 'url';
|
||||||
|
|
||||||
|
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
||||||
|
|
||||||
|
const shrinko8Path = path.resolve(__dirname, "../shrinko8");
|
||||||
|
const pico8DatPath = path.resolve(__dirname, "../../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])
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user