-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
28 lines (23 loc) · 829 Bytes
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const fs = require('fs');
const path = require('path');
const cp = require('child_process');
if (fs.existsSync('./dist')) {
fs.rmSync('./dist', { recursive: true });
}
fs.mkdirSync('./dist');
fs.readdirSync('./public').forEach((publicFile) => {
fs.copyFileSync(path.join('public', publicFile), path.join('dist', publicFile));
});
const watFiles = [];
fs.readdirSync('./src').forEach((sourceFile) => {
if (sourceFile.endsWith('wat')) {
watFiles.push(sourceFile);
return;
}
fs.copyFileSync(path.join('src', sourceFile), path.join('dist', sourceFile));
});
watFiles.forEach((watFile) => {
const fullWatPath = path.join('src', watFile);
const fullWasmPath = path.join('dist', `${watFile.slice(0, watFile.length - 'wat'.length)}wasm`);
cp.execSync(`wat2wasm ${fullWatPath} --output ${fullWasmPath}`);
});