Skip to content

Commit

Permalink
corrects function invoke against main (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmikey authored Sep 1, 2022
1 parent 07d23a1 commit 212167f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/commands/function/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};
12 changes: 10 additions & 2 deletions src/commands/function/invoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;

Expand All @@ -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",
});
Expand Down

0 comments on commit 212167f

Please sign in to comment.