-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpre_build.js
59 lines (50 loc) · 1.83 KB
/
pre_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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const path = require("path");
const fs = require("fs");
const distDir = path.join(__dirname, ".dist");
if(!fs.existsSync(distDir)){
fs.mkdirSync(distDir);
}
// clean and create output dir
const npmDir = path.join(__dirname, ".dist", "npm");
if(fs.existsSync(npmDir)){
fs.rmdirSync(npmDir, {recursive: true});
}
fs.mkdirSync(npmDir);
// Copy wasm file
const browserDir = path.join(npmDir, "browser");
if(fs.existsSync(browserDir)){
fs.rmdirSync(browserDir, {recursive: true});
}
fs.mkdirSync(browserDir);
const blsWasmSrcPath = path.join(__dirname, "node_modules", "clvm", "browser", "blsjs.wasm");
const blsWasmDestPath = path.join(browserDir, "blsjs.wasm");
if(!fs.existsSync(blsWasmSrcPath)){
console.error("blsjs.wasm not found at:");
console.error(blsWasmSrcPath);
console.error("Probably you haven't execute npm install yet");
return;
}
fs.copyFileSync(blsWasmSrcPath, blsWasmDestPath);
const clvmrsWasmSrcPath = require.resolve("clvm_rs/clvm_rs_bg.wasm");
const clvmrsWasmDestPath = path.join(browserDir, "clvm_rs_bg.wasm");
if(!fs.existsSync(clvmrsWasmSrcPath)){
console.error("clvm_rs_bg.wasm not found at:");
console.error(clvmrsWasmSrcPath);
console.error("Probably you haven't execute npm install yet");
return;
}
fs.copyFileSync(clvmrsWasmSrcPath, clvmrsWasmDestPath);
const browserDtsPath = path.join(browserDir, "index.d.ts");
fs.writeFileSync(browserDtsPath, 'export * from "..";\n');
const packageJson = require("./package.json");
fs.writeFileSync(path.join(npmDir, "package.json"), JSON.stringify(packageJson, null, 2));
function copyFileToPublish(fileName){
const srcPath = path.join(__dirname, fileName);
const distPath = path.join(npmDir, fileName);
if(fs.existsSync(srcPath)){
fs.copyFileSync(srcPath, distPath);
}
}
copyFileToPublish("CHANGELOG.md");
copyFileToPublish("LICENSE");
copyFileToPublish("README.md");