From 59500385791c23b9140e43504f8cc99cf8461345 Mon Sep 17 00:00:00 2001 From: Yan Chen <48968912+chenyan-dfinity@users.noreply.github.com> Date: Mon, 9 Sep 2024 13:23:59 -0700 Subject: [PATCH] upload works --- src/components/DeployModal.tsx | 6 +++++- src/node/uploadAsset.js | 21 ++++++++++----------- src/webcontainer.ts | 5 ++++- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/components/DeployModal.tsx b/src/components/DeployModal.tsx index 425d0e68..103ee365 100644 --- a/src/components/DeployModal.tsx +++ b/src/components/DeployModal.tsx @@ -344,7 +344,11 @@ export function DeployModal({ JSON.stringify(identity.toJSON()), ); logger.log(`Authorized asset canister with ${principal}`); - await container.run_cmd("node", ["uploadAsset.js", "dist"]); + await container.run_cmd("node", [ + "uploadAsset.js", + info!.id.toText(), + "dist", + ]); await isDeploy(false); setCompileResult({ wasm: undefined }); if (info) { diff --git a/src/node/uploadAsset.js b/src/node/uploadAsset.js index c6b7ae20..6f27ec85 100644 --- a/src/node/uploadAsset.js +++ b/src/node/uploadAsset.js @@ -15,19 +15,18 @@ const agent = HttpAgent.createSync({ identity, }); //agent.fetchRootKey(); -const assetManager = new AssetManager({ - canisterId: "m7sm4-2iaaa-aaaab-qabra-cai", - agent, -}); -async function upload(asset_dir) { +async function upload(canisterId, asset_dir) { + const assetManager = new AssetManager({ + canisterId, + agent, + }); const old = await assetManager.list(); console.log(old); const batch = assetManager.batch(); const files = await globPromise(`${asset_dir}/**/*`); for (const file of files) { - const relativePath = path.relative(asset_dir, file); - const fileName = `/${relativePath}`; + const fileName = path.relative(asset_dir, file); const contents = fs.readFileSync(file); console.log(fileName); await batch.store(contents, { fileName }); @@ -35,11 +34,11 @@ async function upload(asset_dir) { await batch.commit(); } -if (process.argv.length < 3) { - console.error("Usage: node uploadAsset.js "); +if (process.argv.length !== 4) { + console.error("Usage: node uploadAsset.js "); process.exit(1); } (async () => { - const [, , asset_dir] = process.argv; - await upload(asset_dir); + const [, , canister_id, asset_dir] = process.argv; + await upload(canister_id, asset_dir); })(); diff --git a/src/webcontainer.ts b/src/webcontainer.ts index 1c0c3304..888f215d 100644 --- a/src/webcontainer.ts +++ b/src/webcontainer.ts @@ -64,6 +64,9 @@ export class Container { }), ); const exitCode = await installProcess.exit; - this.terminal.writeln(`\r\nexited with code ${exitCode}`); + if (exitCode !== 0) { + this.terminal.writeln(`\r\nexited with code ${exitCode}`); + throw new Error(`Command failed with code ${exitCode}`); + } } }