From a98b9c33d2b5b89a091b153a87171bae7d23e2a5 Mon Sep 17 00:00:00 2001 From: Surma Date: Sat, 23 Sep 2023 22:08:04 +0100 Subject: [PATCH] Introduce Vite (#19) * Dev mode with vite * Fix prod build * Use locked dep install in build script * remove serve-site script * ci: add vite build step --------- Co-authored-by: Antonio Vivace --- .github/workflows/build.yml | 7 + .gitignore | 2 + README.md | 10 +- build-binjgb.sh | 17 +- build-rgbds.sh | 6 +- build.sh | 3 +- codegen.sh | 9 - {www/css => css}/style.css | 0 www/index.html => index.html | 46 +- {www/js => js}/ace/ace.js | 0 {www/js => js}/ace/complete-gbz80.js | 4 +- {www/js => js}/ace/ext-language_tools.js | 0 {www/js => js}/ace/ext-searchbox.js | 0 {www/js => js}/ace/gbz80tooltip.js | 4 +- {www/js => js}/ace/mode-gbz80.js | 2 + {www/js => js}/ace/theme-tomorrow.js | 0 {www/js => js}/compiler.js | 8 +- {www/js => js}/download.js | 0 {www/js => js}/editors.js | 4 +- {www/js => js}/emulator.js | 6 +- {www/js => js}/gbz80.js | 6 +- {www/js => js}/gfxEditor.js | 4 +- {www/js => js}/jszip.min.js | 0 {www/js => js}/lz-string.min.js | 0 {www/js => js}/storage.js | 12 +- {www/js => js}/textEditor.js | 6 +- package-lock.json | 551 ++++++++++++++++++ package.json | 24 + serve-site.sh | 4 - .../hardware.inc | 0 .../main.asm | 0 {www/tracker => tracker}/index.html | 0 {www/tracker => tracker}/js/assemblyExport.js | 0 {www/tracker => tracker}/js/player.js | 0 {www/tracker => tracker}/js/sdccExport.js | 0 {www/tracker => tracker}/js/song.js | 0 {www/tracker => tracker}/js/ugeLoader.js | 0 {www/tracker => tracker}/js/ugeSaver.js | 0 {www/tracker => tracker}/js/ui/instruments.js | 0 {www/tracker => tracker}/js/ui/sequence.js | 0 {www/tracker => tracker}/js/ui/tracker.js | 0 {www/tracker => tracker}/style.css | 0 vite.config.js | 12 + 43 files changed, 667 insertions(+), 80 deletions(-) create mode 100644 .gitignore delete mode 100755 codegen.sh rename {www/css => css}/style.css (100%) rename www/index.html => index.html (97%) rename {www/js => js}/ace/ace.js (100%) rename {www/js => js}/ace/complete-gbz80.js (95%) rename {www/js => js}/ace/ext-language_tools.js (100%) rename {www/js => js}/ace/ext-searchbox.js (100%) rename {www/js => js}/ace/gbz80tooltip.js (97%) rename {www/js => js}/ace/mode-gbz80.js (99%) rename {www/js => js}/ace/theme-tomorrow.js (100%) rename {www/js => js}/compiler.js (95%) rename {www/js => js}/download.js (100%) rename {www/js => js}/editors.js (96%) rename {www/js => js}/emulator.js (96%) rename {www/js => js}/gbz80.js (99%) rename {www/js => js}/gfxEditor.js (96%) rename {www/js => js}/jszip.min.js (100%) rename {www/js => js}/lz-string.min.js (100%) rename {www/js => js}/storage.js (91%) rename {www/js => js}/textEditor.js (94%) create mode 100644 package-lock.json create mode 100644 package.json delete mode 100755 serve-site.sh rename {www/starting_project => starting_project}/hardware.inc (100%) rename {www/starting_project => starting_project}/main.asm (100%) rename {www/tracker => tracker}/index.html (100%) rename {www/tracker => tracker}/js/assemblyExport.js (100%) rename {www/tracker => tracker}/js/player.js (100%) rename {www/tracker => tracker}/js/sdccExport.js (100%) rename {www/tracker => tracker}/js/song.js (100%) rename {www/tracker => tracker}/js/ugeLoader.js (100%) rename {www/tracker => tracker}/js/ugeSaver.js (100%) rename {www/tracker => tracker}/js/ui/instruments.js (100%) rename {www/tracker => tracker}/js/ui/sequence.js (100%) rename {www/tracker => tracker}/js/ui/tracker.js (100%) rename {www/tracker => tracker}/style.css (100%) create mode 100644 vite.config.js diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d07b3fb..4dd4f56 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,6 +25,13 @@ jobs: - name: Build binjgb run: ./build-binjgb.sh shell: bash + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: '20.x' + run: | + npm ci + npm run build - name: Deploy to GitHub Pages uses: peaceiris/actions-gh-pages@v3 with: diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ded68f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +www +node_modules diff --git a/README.md b/README.md index 5595dc8..eab3a29 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,17 @@ System requirements: - bison, cmake - [emscripten](https://emscripten.org/docs/getting_started/downloads.html) -To build RGBDS live and run it locally: +Make sure you initialize submodules to be able to build the WebAssembly modules: ```bash # Pull RGBDS-live, rgbds and binjgb sources git clone https://github.com/gbdev/rgbds-live --recursive -# Generate WASM builds and put them in the main source folder +# Do a full build ./build.sh ``` -Final build will be in `www/`. You can run the provided `serve-site.sh` to serve that folder locally over port 8080. +To start hacking, use the development server: +```bash +# Development server with live refresh: +npm run dev +``` diff --git a/build-binjgb.sh b/build-binjgb.sh index 021a64c..be5b812 100755 --- a/build-binjgb.sh +++ b/build-binjgb.sh @@ -10,13 +10,12 @@ fi cd binjgb ! mkdir out cd out -cmake \ - -DCMAKE_TOOLCHAIN_FILE=${EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake \ - -DCMAKE_BUILD_TYPE=Release \ - -DWERROR=ON \ - -DWASM=true \ - -DRGBDS_LIVE=ON \ - ../ +cmake -E env LDFLAGS='-s EXPORT_ES6=1' \ + cmake \ + -DCMAKE_TOOLCHAIN_FILE=${EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DWERROR=ON \ + -DWASM=true \ + -DRGBDS_LIVE=ON \ + ../ make -mkdir -p ../../www/wasm -cp binjgb.* ../../www/wasm/ diff --git a/build-rgbds.sh b/build-rgbds.sh index ddb775a..714bfdf 100755 --- a/build-rgbds.sh +++ b/build-rgbds.sh @@ -13,11 +13,7 @@ patch -p1 < ../rgbds.patch MAKE_ARGS="Q= PNGCFLAGS= PNGLDFLAGS= PNGLDLIBS=" -CFLAGS="-O3 -s MODULARIZE=1 -s EXPORTED_RUNTIME_METHODS=['FS'] -s USE_LIBPNG" +CFLAGS="-O3 -s EXPORT_ES6=1 -s ENVIRONMENT=web -s MODULARIZE=1 -s EXPORTED_RUNTIME_METHODS=['FS'] -s USE_LIBPNG" emmake make ${MAKE_ARGS} CFLAGS="${CFLAGS} -s 'EXPORT_NAME=createRgbAsm'" rgbasm emmake make ${MAKE_ARGS} CFLAGS="${CFLAGS} -s 'EXPORT_NAME=createRgbLink'" rgblink emmake make ${MAKE_ARGS} CFLAGS="${CFLAGS} -s 'EXPORT_NAME=createRgbFix'" rgbfix -mkdir -p ../www/wasm/ -cp rgbasm* ../www/wasm/ -cp rgblink* ../www/wasm/ -cp rgbfix* ../www/wasm/ diff --git a/build.sh b/build.sh index 5d7c294..79e5daf 100755 --- a/build.sh +++ b/build.sh @@ -4,5 +4,6 @@ set -eu test -d binjgb/out || ./build-binjgb.sh test -f rgbds/rgbasm.wasm || ./build-rgbds.sh -./codegen.sh +npm ci +npm run build diff --git a/codegen.sh b/codegen.sh deleted file mode 100755 index 2726f9f..0000000 --- a/codegen.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -set -eu - -cd www -# Generate hardware.inc.js -echo "var hardware_inc = String.raw\`" > js/hardware.inc.js -cat starting_project/hardware.inc | sed -r "s/\`/\$\{\'\`\'}/g" >> js/hardware.inc.js -echo "\`;" >> js/hardware.inc.js diff --git a/www/css/style.css b/css/style.css similarity index 100% rename from www/css/style.css rename to css/style.css diff --git a/www/index.html b/index.html similarity index 97% rename from www/index.html rename to index.html index 5e51f48..9de6b84 100644 --- a/www/index.html +++ b/index.html @@ -4,32 +4,26 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + +