diff --git a/um_wasm_loader/build.js b/um_wasm_loader/build.js index df4efda..605c6d1 100644 --- a/um_wasm_loader/build.js +++ b/um_wasm_loader/build.js @@ -56,13 +56,30 @@ async function replaceFileByRegex(filepath, ...replacementRules) { await writeFile(filepath, content, 'utf-8'); } +/** + * @param {string | undefined} value + * @param [defaultValue=false] + * @return {boolean} + */ +function parseBoolean(value, defaultValue = false) { + if (value === undefined || value === null) { + return defaultValue; + } + + if (Number.isFinite(+value)) { + return Boolean(value); + } + + return value.toLowerCase() === 'true'; +} + async function main() { const wasmSourceDir = path.join(__dirname, '..', 'um_wasm'); const wasmOutDir = path.resolve(__dirname, 'pkg'); const wasmDistDir = path.resolve(__dirname, 'dist'); await rm(wasmOutDir, { recursive: true, force: true }); const wasmRelOutDir = path.relative(wasmSourceDir, wasmOutDir); - const profileFlag = process.env.BUILD_RELEASE ? '--release' : '--dev'; + const profileFlag = parseBoolean(process.env.BUILD_RELEASE, true) ? '--release' : '--dev'; await run(['wasm-pack', 'build', profileFlag, '--target', 'web', '--out-dir', wasmRelOutDir], { cwd: path.resolve(__dirname, '..', 'um_wasm'), });