Skip to content

Commit 9a71404

Browse files
authored
Use iframes (#369)
* Use iframes This PR removes react and next. It allows a sample to be pure JavaScript (though there are none at the moment). It allows samples to be standalone so that they run separate from the sample selection menu.
1 parent bcba0c6 commit 9a71404

File tree

224 files changed

+12551
-12331
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

224 files changed

+12551
-12331
lines changed

.eslintrc.cjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
extends: [
4+
'plugin:@typescript-eslint/recommended',
5+
'plugin:prettier/recommended',
6+
],
7+
plugins: ['@typescript-eslint', 'eslint-plugin-html', 'prettier'],
8+
rules: {
9+
'@typescript-eslint/no-unused-vars': [
10+
'error',
11+
{ vars: 'all', args: 'after-used', ignoreRestSiblings: true },
12+
],
13+
},
14+
};

.eslintrc.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

.github/workflows/build-and-deploy.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ jobs:
2929
npm ci
3030
npm run-script lint
3131
npm run-script build
32-
npm run-script export
3332
touch out/.nojekyll
3433
3534
- name: Deploy 🚀

.github/workflows/build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,3 @@ jobs:
3232
npm ci
3333
npm run-script lint
3434
npm run-script build
35-
npm run-script export
File renamed without changes.

build/lib/copyAndWatch.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import chokidar from 'chokidar';
2+
import fs from 'fs';
3+
import path from 'path';
4+
5+
const debug = console.log; //() => {};
6+
const removeLeadingSlash = (s) => s.replace(/^\//, '');
7+
8+
/**
9+
* Recursively copies files and watches for changes.
10+
*
11+
* Example:
12+
*
13+
* copyAndWatch([
14+
* {src: "src\/**\/*.js", srcPrefix: "src", dst: "out"}, // would copy src/bar/moo.js -> out/bar/moo.js
15+
* {src: "index.html", dst: "out"}, // copies index.html -> out/index.html
16+
* ]);
17+
*
18+
* @param {*} paths [{src: glob, srcPrefix: string, dst: string }]
19+
* @param {*} options { watch: true/false } // watch: false = just copy and exit.
20+
*/
21+
export function copyAndWatch(paths, { watch } = { watch: true }) {
22+
for (const { src, srcPrefix, dst } of paths) {
23+
const watcher = chokidar.watch(src, {
24+
ignored: /(^|[\/\\])\../, // ignore dot files
25+
persistent: watch,
26+
});
27+
28+
const makeDstPath = (path, dst) =>
29+
`${dst}/${removeLeadingSlash(
30+
path.startsWith(srcPrefix) ? path.substring(srcPrefix.length) : path
31+
)}`;
32+
33+
watcher
34+
.on('addDir', (srcPath) => {
35+
const dstPath = makeDstPath(srcPath, dst);
36+
debug('addDir:', srcPath, dstPath);
37+
fs.mkdirSync(dstPath, { recursive: true });
38+
})
39+
.on('add', (srcPath) => {
40+
const dstPath = makeDstPath(srcPath, dst);
41+
const dir = path.dirname(dstPath);
42+
fs.mkdirSync(dir, { recursive: true });
43+
debug('add:', srcPath, dstPath);
44+
fs.copyFileSync(srcPath, dstPath);
45+
})
46+
.on('change', (srcPath) => {
47+
const dstPath = makeDstPath(srcPath, dst);
48+
debug('change:', srcPath, dstPath);
49+
fs.copyFileSync(srcPath, dstPath);
50+
})
51+
.on('unlink', (srcPath) => {
52+
const dstPath = makeDstPath(srcPath, dst);
53+
debug('unlink:', srcPath, dstPath);
54+
fs.unlinkSync(dstPath);
55+
})
56+
.on('ready', () => {
57+
if (!watch) {
58+
watcher.close();
59+
}
60+
});
61+
}
62+
}

build/lib/readdir.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
4+
// not needed in node v20+
5+
export function readDirSyncRecursive(dir) {
6+
const basename = path.basename(dir);
7+
const entries = fs.readdirSync(dir, { withFileTypes: true });
8+
return entries
9+
.map((entry) =>
10+
entry.isDirectory()
11+
? readDirSyncRecursive(`${dir}/${entry.name}`)
12+
: entry.name
13+
)
14+
.flat()
15+
.map((name) => `${basename}/${name}`);
16+
}

build/tools/build.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { spawn } from 'child_process';
2+
import { mkdirSync } from 'fs';
3+
4+
mkdirSync('out', { recursive: true });
5+
6+
spawn('node', ['build/tools/copy.js'], {
7+
shell: true,
8+
stdio: 'inherit',
9+
});
10+
11+
spawn('./node_modules/.bin/rollup', ['-c'], {
12+
shell: true,
13+
stdio: 'inherit',
14+
});

build/tools/copy.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { copyAndWatch } from '../lib/copyAndWatch.js';
2+
3+
const watch = !!process.argv[2];
4+
5+
copyAndWatch(
6+
[
7+
{ src: 'public/**/*', srcPrefix: 'public', dst: 'out' },
8+
{ src: 'meshes/**/*', dst: 'out' },
9+
{ src: 'sample/**/*', dst: 'out' },
10+
{ src: 'shaders/**/*', dst: 'out' },
11+
{ src: 'index.html', dst: 'out' },
12+
],
13+
{ watch }
14+
);

build/tools/serve.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { spawn } from 'child_process';
2+
import { mkdirSync } from 'fs';
3+
4+
mkdirSync('out', { recursive: true });
5+
6+
spawn('npm', ['run', 'watch'], {
7+
shell: true,
8+
stdio: 'inherit',
9+
});
10+
11+
spawn('node', ['build/tools/copy.js', '1'], {
12+
shell: true,
13+
stdio: 'inherit',
14+
});
15+
16+
spawn('./node_modules/.bin/servez', ['out'], {
17+
shell: true,
18+
stdio: 'inherit',
19+
});

0 commit comments

Comments
 (0)