Skip to content

Commit

Permalink
correct publish with build (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmikey authored Sep 1, 2022
1 parent 212167f commit aa4b744
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
16 changes: 10 additions & 6 deletions src/commands/function/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const publishFunction = async (
axios
.post(`${server}/api/submit`, formData, {
headers: {
"Authorization": `Bearer ${token}`,
Authorization: `Bearer ${token}`,
"Content-Type": "multipart/form-data",
},
})
Expand All @@ -48,7 +48,13 @@ const logResult = (data: any) => {
console.log(`function successfully published with id ${cid}`);
};
export const run = (options: any) => {
const { debug, name, path, publishCallback = logResult, rebuild } = options;
const {
debug,
name,
path = process.cwd(),
publishCallback = logResult,
rebuild,
} = options;
const buildDir = getBuildDir(path);
const wasmName = `${name}${debug ? "-debug" : ""}.wasm`;
const wasmArchive = `${name}.tar.gz`;
Expand All @@ -59,16 +65,14 @@ export const run = (options: any) => {
//TODO: this is absolutely monstrous and needssanity appplied
deploymentOptions.userFunctionId = userFunctionId;

if (rebuild) {
runBuild({ debug, name, path, rebuild });
}
runBuild({ debug, name, path, rebuild });

console.log(Chalk.yellow(`Creating tarball...`));
createWasmArchive(buildDir, wasmArchive, wasmName);

console.log(Chalk.yellow(`Deploying function located in ${buildDir}`));
publishFunction(
readFileSync(`${buildDir}/manifest.json}`),
readFileSync(`${buildDir}/manifest.json`),
readFileSync(`${buildDir}/${wasmArchive}`),
publishCallback
);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/function/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const createWasmArchive = (
wasmArchive: string,
wasmName: string
) => {
execSync(`tar zcf ${wasmArchive} ${wasmName}`, {
execSync(`tar zcf ${path}/${wasmArchive} ${path}/${wasmName}`, {
cwd: path,
stdio: "inherit",
});
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ args
}
const requiredOptions: RequiredOptions = {
init: ["name"],
deploy: ["name", "path"],
publish: ["name", "path"],
deploy: ["name"],
publish: ["name"],
};
const index: keyof RequiredOptions = "init";
didRun = true;
Expand Down

0 comments on commit aa4b744

Please sign in to comment.