UNPKG

@patchworkdev/pdk

Version:

Patchwork Development Kit

57 lines (56 loc) 3.08 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateWWWEnv = generateWWWEnv; const path_1 = __importDefault(require("path")); const config_1 = require("../common/helpers/config"); const env_1 = require("../common/helpers/env"); const error_1 = require("../common/helpers/error"); const lockFile_1 = __importDefault(require("../common/helpers/lockFile")); const logger_1 = require("../common/helpers/logger"); const text_1 = require("../common/helpers/text"); async function generateWWWEnv(configPath) { // Resolve the full path of the config file const fullConfigPath = path_1.default.isAbsolute(configPath) ? configPath : path_1.default.resolve(process.cwd(), configPath); const configDir = path_1.default.dirname(fullConfigPath); // Define paths relative to the config file const wwwExamplePath = path_1.default.join(configDir, 'www', '.env.example'); const wwwEnvPath = path_1.default.join(configDir, 'www', '.env.local'); const projectConfig = await (0, config_1.importPatchworkConfig)(fullConfigPath); if (!projectConfig.networks) { logger_1.logger.error(`No networks found in the project config. Cannot build network configuration.`); throw new error_1.PDKError(error_1.ErrorCode.PROJECT_CONFIG_MISSING_NETWORKS, `No networks found in the project config at ${fullConfigPath}`); } const env = await (0, env_1.getEnvFile)(wwwEnvPath, true, wwwExamplePath); env['VITE_PUBLIC_PONDER_URL'] = 'http://localhost:42069'; Object.entries(projectConfig.networks).map(([networkName, network]) => { env[`${(0, text_1.envVarCase)(networkName)}_RPC`] = network.rpc; }); const lockFileManager = new lockFile_1.default(configPath); const selectedNetwork = lockFileManager.getCurrentNetwork(); env['VITE_NETWORK'] = selectedNetwork; /* * superfluous for now, commenting out * const bytecodeInfo = await processContracts(configPath, {}, false); for (const contractName in projectConfig.contracts) { const deploymentInfo = lockFileManager.getLatestDeploymentForContract(contractName, selectedNetwork); if (!deploymentInfo) { if (bytecodeInfo[contractName]) { env[`${envVarCase(contractName)}_BLOCK`] = '1'; env[`${envVarCase(contractName)}_ADDRESS`] = bytecodeInfo[contractName].deployedAddress; } else { logger.error(`No deployment found for ${contractName}`); throw new PDKError(ErrorCode.DEPLOYMENT_NOT_FOUND, `No deployment found for ${contractName}`); } } else { env[`${envVarCase(contractName)}_BLOCK`] = deploymentInfo.block.toString(); env[`${envVarCase(contractName)}_ADDRESS`] = deploymentInfo.address; } } */ (0, env_1.writeEnvFile)(env, wwwEnvPath); logger_1.logger.info(`WWW env generated successfully: ${wwwEnvPath}`); }