Chaning to a provider system for desktop and web variants
This commit is contained in:
parent
d69737050a
commit
ec05b76078
7 changed files with 43 additions and 7 deletions
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
|
@ -6,6 +6,7 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
|
"build:desktop": "VITE_DESKTOP=1 vite build --outDir out-desktop/",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||||
|
@ -30,6 +31,7 @@
|
||||||
"svelte-check": "^4.0.0",
|
"svelte-check": "^4.0.0",
|
||||||
"tailwindcss": "^4.0.0-beta.9",
|
"tailwindcss": "^4.0.0-beta.9",
|
||||||
"typescript": "^5.0.0",
|
"typescript": "^5.0.0",
|
||||||
"vite": "^5.4.11"
|
"vite": "^5.4.11",
|
||||||
|
"vite-plugin-wasm": "^3.4.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
import {} from 'sprig/web';
|
import {} from 'sprig/web';
|
||||||
import { constrainedEditor } from 'constrained-editor-plugin';
|
import { constrainedEditor } from 'constrained-editor-plugin';
|
||||||
import { parse } from '@babel/parser';
|
import { parse } from '@babel/parser';
|
||||||
import { buildProject } from './build';
|
import { buildProject } from './build/esbuild';
|
||||||
|
|
||||||
let editorContainer: HTMLDivElement;
|
let editorContainer: HTMLDivElement;
|
||||||
let editor: import('monaco-editor').editor.IStandaloneCodeEditor;
|
let editor: import('monaco-editor').editor.IStandaloneCodeEditor;
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
import { transform, initialize } from 'esbuild-wasm';
|
import { transform, initialize } from 'esbuild-wasm';
|
||||||
|
|
||||||
await initialize({
|
await initialize({
|
||||||
wasmURL: (await import('esbuild-wasm/esbuild.wasm')).default
|
wasmURL: (await import('esbuild-wasm/esbuild.wasm?url')).default
|
||||||
});
|
});
|
||||||
|
|
||||||
export async function buildProject(code: string, vanilla: boolean) {
|
export async function buildProject(code: string, vanilla: boolean) {
|
||||||
let template = '';
|
let template = '';
|
||||||
if (vanilla) {
|
if (vanilla) {
|
||||||
template += `function game(api) {
|
template += `async function game(api) {
|
||||||
${code}
|
${code}
|
||||||
}
|
}
|
||||||
console.log("Made with Sprigsy")
|
console.log("Made with Sprigsy")
|
||||||
|
@ -18,6 +18,6 @@ game({ addSprite, addText, afterInput, bitmap, clearInterval, clearText, clearTi
|
||||||
}
|
}
|
||||||
|
|
||||||
return await transform(template, {
|
return await transform(template, {
|
||||||
loader: 'ts'
|
loader: 'ts',
|
||||||
});
|
});
|
||||||
}
|
}
|
30
src/lib/provider/Provider.ts
Normal file
30
src/lib/provider/Provider.ts
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import { buildProject } from "$lib/build/esbuild"
|
||||||
|
|
||||||
|
enum Capability {
|
||||||
|
BuildToVite,
|
||||||
|
ProjectDB
|
||||||
|
}
|
||||||
|
|
||||||
|
export default abstract class Provider {
|
||||||
|
constructor(
|
||||||
|
|
||||||
|
) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract capabilities(): Capability[]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds HTML project
|
||||||
|
*/
|
||||||
|
async buildHTML(input: string): Promise<string> {
|
||||||
|
throw new TypeError("BuildToVite capability is not available")
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build JS
|
||||||
|
*/
|
||||||
|
async buildJS(input: string): Promise<string> {
|
||||||
|
return (await buildProject(input, true)).code
|
||||||
|
}
|
||||||
|
}
|
|
@ -1 +1,2 @@
|
||||||
export const csr = true;
|
export const csr = true;
|
||||||
|
export const prerender = true;
|
|
@ -2,5 +2,8 @@ import { sveltekit } from '@sveltejs/kit/vite';
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [sveltekit()]
|
plugins: [sveltekit()],
|
||||||
|
build: {
|
||||||
|
target: ['es2022']
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue