diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 33dd0d1..21e6df7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,11 +1,35 @@ -name: Github Pages -on: [push] +# Simple workflow for deploying static content to GitHub Pages +name: Deploy static content to Pages + +on: + # Runs on pushes targeting the default branch + push: + branches: ["main"] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow one concurrent deployment +concurrency: + group: "pages" + cancel-in-progress: true + jobs: - build-and-deploy: + # Single deploy job since we're just deploying + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@master + uses: actions/checkout@v3 - name: Setup Ruby uses: ruby/setup-ruby@v1 @@ -16,17 +40,23 @@ jobs: - name: Setup node uses: actions/setup-node@v2 with: - node-version: 14.x + node-version: 18.x cache: yarn + - name: Setup Pages + uses: actions/configure-pages@v3 + - name: Package application run: | bundle exec rake yarn install --frozen-lockfile yarn build - - name: Deploy - uses: peaceiris/actions-gh-pages@v3 + - name: Upload artifact + uses: actions/upload-pages-artifact@v1 with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./docs + path: './docs' + + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v1 diff --git a/bin/build b/bin/build deleted file mode 100755 index 818f84b..0000000 --- a/bin/build +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env node - -const esbuild = require("esbuild"); -const path = require("path"); - -const wasmPlugin = require("./wasmPlugin"); - -esbuild.build({ - bundle: true, - entryPoints: [path.join(__dirname, "../src/index.ts")], - format: "esm", - metafile: true, - minify: true, - outdir: path.join(__dirname, "../docs"), - plugins: [wasmPlugin], - sourcemap: true, - splitting: true, - target: "es6" -}).then((result) => esbuild.analyzeMetafile(result.metafile)).then((analysis) => { - console.log(analysis); -}); diff --git a/bin/build.js b/bin/build.js new file mode 100644 index 0000000..ffcf388 --- /dev/null +++ b/bin/build.js @@ -0,0 +1,22 @@ +import esbuild from "esbuild"; +import url from "url"; +import wasmPlugin from "./wasmPlugin.js"; + +const entryPoint = url.fileURLToPath(new URL("../src/index", import.meta.url)); +const outdir = url.fileURLToPath(new URL("../docs", import.meta.url)); + +const { metafile } = await esbuild.build({ + bundle: true, + entryPoints: [entryPoint], + format: "esm", + metafile: true, + minify: true, + outdir, + plugins: [wasmPlugin], + sourcemap: true, + splitting: true, + target: "es6" +}); + +const analysis = await esbuild.analyzeMetafile(metafile); +console.log(analysis); diff --git a/bin/serve b/bin/serve deleted file mode 100755 index b2568da..0000000 --- a/bin/serve +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env node - -const esbuild = require("esbuild"); -const path = require("path"); - -const wasmPlugin = require("./wasmPlugin"); - -const serveOptions = { - servedir: path.join(__dirname, "../docs") -}; - -const buildOptions = { - bundle: true, - entryPoints: [path.join(__dirname, "../src/index.ts")], - format: "esm", - outdir: path.join(__dirname, "../docs"), - plugins: [wasmPlugin], - sourcemap: true, - splitting: true, - target: "esnext" -}; - -esbuild.serve(serveOptions, buildOptions).then((result) => { - console.log(`Listening at ${result.host}:${result.port}`); -}); diff --git a/bin/serve.js b/bin/serve.js new file mode 100644 index 0000000..39a72e7 --- /dev/null +++ b/bin/serve.js @@ -0,0 +1,20 @@ +import esbuild from "esbuild"; +import url from "url"; +import wasmPlugin from "./wasmPlugin.js"; + +const entryPoint = url.fileURLToPath(new URL("../src/index", import.meta.url)); +const outdir = url.fileURLToPath(new URL("../docs", import.meta.url)); + +const ctx = await esbuild.context({ + bundle: true, + entryPoints: [entryPoint], + format: "esm", + outdir, + plugins: [wasmPlugin], + sourcemap: true, + splitting: true, + target: "esnext" +}); + +const { host, port } = await ctx.serve({ servedir: outdir }); +console.log(`Listening at ${host}:${port}`); diff --git a/bin/wasmPlugin.js b/bin/wasmPlugin.js index 7c2f5f4..64c817a 100644 --- a/bin/wasmPlugin.js +++ b/bin/wasmPlugin.js @@ -1,9 +1,9 @@ -module.exports = { +import path from 'node:path'; +import fs from 'node:fs'; + +export default { name: 'wasm', setup(build) { - let path = require('path') - let fs = require('fs') - // Resolve ".wasm" files to a path with a namespace build.onResolve({ filter: /\.wasm$/ }, args => { // If this is the import inside the stub module, import the @@ -37,7 +37,7 @@ module.exports = { // binary itself is imported from a second virtual module. build.onLoad({ filter: /.*/, namespace: 'wasm-stub' }, async (args) => ({ contents: `import wasm from ${JSON.stringify(args.path)} - export default (imports) => WebAssembly.instantiate(wasm, imports).then((result) => result.instance)`, + export default () => WebAssembly.compile(wasm)`, })) // Virtual modules in the "wasm-binary" namespace contain the @@ -50,3 +50,4 @@ module.exports = { })) }, } + diff --git a/docs/index.html b/docs/index.html index 1ca2640..4802bcc 100644 --- a/docs/index.html +++ b/docs/index.html @@ -23,9 +23,12 @@