-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate-env.js
More file actions
29 lines (22 loc) · 849 Bytes
/
Copy pathgenerate-env.js
File metadata and controls
29 lines (22 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env node
const fs = require("fs");
const path = require("path");
const canisterIdsPath = path.join(__dirname, ".dfx/local/canister_ids.json");
const envPath = path.join(__dirname, "src/frontend/.env");
try {
const canisterIds = JSON.parse(fs.readFileSync(canisterIdsPath, "utf8"));
let envContent = "# Canister IDs for local development\n";
for (const [name, ids] of Object.entries(canisterIds)) {
if (ids.local && !name.startsWith("__")) {
const envName = name.toUpperCase();
envContent += `VITE_CANISTER_ID_${envName}=${ids.local}\n`;
}
}
envContent += "VITE_DFX_NETWORK=local\n";
fs.writeFileSync(envPath, envContent);
console.log("Generated .env file with canister IDs");
console.log(envContent);
} catch (error) {
console.error("Error generating .env file:", error);
process.exit(1);
}