From 212167f9edad35efbc0d37e17d006120097ecc21 Mon Sep 17 00:00:00 2001 From: Derek Anderson Date: Thu, 1 Sep 2022 09:16:39 -0500 Subject: [PATCH] corrects function invoke against main (#34) --- src/commands/function/build.ts | 13 ++++++++++--- src/commands/function/invoke.ts | 12 ++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/commands/function/build.ts b/src/commands/function/build.ts index 971bc69..8045493 100644 --- a/src/commands/function/build.ts +++ b/src/commands/function/build.ts @@ -32,26 +32,33 @@ export const run = (options: { }) => { const { debug, name, path, rebuild } = options; // check for and store unmodified wasm file name to change later + const defaultWasm = debug ? "debug.wasm" : "release.wasm"; const buildDir = `${path}/build`; const wasmName = `${name}${debug ? "-debug" : ""}.wasm`; const wasmArchive = `${name}.tar.gz`; const wasmManifest = createManifest(buildDir, wasmName, wasmArchive); + const renameWasm = (path: string, oldName: string, newName: string) => { + execSync(`mv ${oldName} ${newName}`, { cwd: path, stdio: "inherit" }); + }; + const build = () => { console.log(Chalk.green(`Building function ${name} in ${buildDir}...`)); execSync(`npm run build:${debug ? "debug" : "release"};`, { cwd: path, stdio: "inherit", }); + + if (existsSync(`${buildDir}/${defaultWasm}`)) { + renameWasm(buildDir, defaultWasm, wasmName); + } }; try { - if (!fs.existsSync(`${buildDir}/${wasmName}`)) build(); + if (!fs.existsSync(`${buildDir}/${wasmName}`) || rebuild) build(); } catch (err) { build(); } - if (rebuild) build(); - writeFileSync(`${buildDir}/manifest.json`, JSON.stringify(wasmManifest)); }; diff --git a/src/commands/function/invoke.ts b/src/commands/function/invoke.ts index 6285fe5..9e86cf6 100644 --- a/src/commands/function/invoke.ts +++ b/src/commands/function/invoke.ts @@ -8,6 +8,7 @@ export const run = (options: any) => { systemPath = `${store.system.homedir}/.bls/`, cwd: path = process.cwd(), name, + rebuild = true, } = options; const runtimePath = `${systemPath}runtime/blockless-cli`; @@ -17,9 +18,16 @@ export const run = (options: any) => { path, name, debug: true, - rebuild: false, + rebuild, }); - execSync(`${runtimePath} build/manifest.json`, { + // the runtime requires absolute paths + let manifestData = fs.readFileSync(`${path}/build/manifest.json`, "utf8"); + let manifest = JSON.parse(manifestData); + manifest.entry = `${path}/build/${manifest.entry}`; + fs.writeFileSync(`${path}/build/manifest.json`, JSON.stringify(manifest)); + + // pass in stdin to the runtime + execSync(`echo "" | ${runtimePath} build/manifest.json`, { cwd: path, stdio: "inherit", });