Skip to content

Commit

Permalink
Add support for assets
Browse files Browse the repository at this point in the history
  • Loading branch information
Exidex committed Mar 17, 2024
1 parent 57d0f7b commit f41715e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { rollup, RollupBuild } from "rollup";
import { parseManifest, readManifest, rollupInputOptions, rollupOutputOptions, writeDistManifest } from "./config";
import {
copyAssetData,
parseManifest,
readManifest,
rollupInputOptions,
rollupOutputOptions,
writeDistManifest
} from "./config";


export async function build(exit: boolean) {
Expand All @@ -15,6 +22,8 @@ export async function build(exit: boolean) {

await rollupBuild.write(rollupOutputOptions());

copyAssetData()

writeDistManifest(manifestText)
} catch (error) {
buildFailed = true;
Expand Down
14 changes: 13 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { InputOptions, OutputOptions } from "rollup";
import nodeResolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "@rollup/plugin-typescript";
import { readFileSync, writeFileSync } from "node:fs";
import { cpSync, readFileSync, writeFileSync } from "node:fs";

const preferences = z.discriminatedUnion("type", [
z.strictObject({
Expand Down Expand Up @@ -101,6 +101,18 @@ export function writeDistManifest(manifestText: string) {
writeFileSync("dist/gauntlet.toml", manifestText)
}

export function copyAssetData() {
try {
cpSync("assets", "dist/assets", { recursive: true });
} catch (err) {
if ((err as any).code === 'ENOENT') {
return;
} else {
throw err
}
}
}

export function parseManifest(manifestText: string) {
const manifest = Manifest.parse(parseToml(manifestText));

Expand Down
11 changes: 10 additions & 1 deletion src/dev.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { parseManifest, readManifest, rollupInputOptions, rollupOutputOptions, writeDistManifest } from "./config";
import {
copyAssetData,
parseManifest,
readManifest,
rollupInputOptions,
rollupOutputOptions,
writeDistManifest
} from "./config";
import { RollupError, watch } from "rollup";
import chalk from "chalk";
import { setupGrpc } from "./grpc";
Expand Down Expand Up @@ -33,6 +40,8 @@ export async function dev() {
const manifestText = readManifest();
parseManifest(manifestText); // TODO properly handle errors here

copyAssetData()

writeDistManifest(manifestText)

await event.result.close()
Expand Down

0 comments on commit f41715e

Please sign in to comment.