2023-03-23 16:01:27 +00:00
|
|
|
import fastglob from 'fast-glob';
|
|
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
import * as fs from 'node:fs';
|
|
|
|
|
|
|
|
const result = await fastglob(fileURLToPath(new URL('./src/**/*.wasm', import.meta.url)));
|
|
|
|
|
2023-03-23 16:03:49 +00:00
|
|
|
for (const filepath of result) {
|
2023-03-23 16:01:27 +00:00
|
|
|
const buffer = await fs.promises.readFile(filepath);
|
|
|
|
const base64 = buffer.toString('base64');
|
|
|
|
const source = `export default Buffer.from(${JSON.stringify(base64)}, 'base64');`;
|
|
|
|
const outpath = filepath + '.ts';
|
|
|
|
await fs.promises.writeFile(outpath, source, 'utf-8');
|
|
|
|
}
|