feat: install moo and use in toy example (#2)

I failed to find a satisfactory way to compile and import moo.js with
  fixed specifiers, so finally I just gave up and patched the distributed
  moo code to be an es6 module. Very ugly but it works.

Resolves #1.

Reviewed-on: #2
Co-authored-by: Glen Whitney <glen@studioinfinity.org>
Co-committed-by: Glen Whitney <glen@studioinfinity.org>
This commit is contained in:
Glen Whitney 2023-09-01 21:32:25 +00:00 committed by Glen Whitney
parent 67a07e2000
commit e0861ea157
11 changed files with 88 additions and 25 deletions

10
etc/streamToString.js Normal file
View file

@ -0,0 +1,10 @@
export async function streamToString(stream) {
// lets have a ReadableStream as a stream variable
const chunks = [];
for await (const chunk of stream) {
chunks.push(Buffer.from(chunk));
}
return Buffer.concat(chunks).toString("utf-8");
}

View file

@ -5,8 +5,8 @@
<title>vrml1to97 test</title>
<script>
(async () => {
const vrml1to97 = await import('../dist/index.js')
console.log(vrml1to97.convert('test'))
const vrml1to97 = await import('../dist/vrml1to97/index.js')
console.log(vrml1to97.convert('if (moo) cows // hurray'))
})()
</script>
</head>

View file

@ -1,18 +1,8 @@
#!/usr/bin/env node
import {convert} from './index.js'
import {convert} from './vrml1to97/index.js'
import {stdin, argv} from 'node:process'
async function streamToString(stream) {
// lets have a ReadableStream as a stream variable
const chunks = [];
for await (const chunk of stream) {
chunks.push(Buffer.from(chunk));
}
return Buffer.concat(chunks).toString("utf-8");
}
import {streamToString} from './streamToString.js'
if (argv.length > 2) {
console.log('Usage: vrml1to97 < old.wrl > shinynew.wrl')