Skip to content

Commit

Permalink
upload works
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyan-dfinity committed Sep 9, 2024
1 parent 62d93ea commit 5950038
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
6 changes: 5 additions & 1 deletion src/components/DeployModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 10 additions & 11 deletions src/node/uploadAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,30 @@ 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 });
}
await batch.commit();
}

if (process.argv.length < 3) {
console.error("Usage: node uploadAsset.js <asset_dir>");
if (process.argv.length !== 4) {
console.error("Usage: node uploadAsset.js <canister_id> <asset_dir>");
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);
})();
5 changes: 4 additions & 1 deletion src/webcontainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
}
}

0 comments on commit 5950038

Please sign in to comment.