UNPKG

@simbachain/web3-suites

Version:

common code for web3 suite plugins. Code in this repo can be used for truffle or hardhat, but is designed to be applicable to future web3 suite plugins as well.

61 lines 3.71 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildURL = exports.discoverAndSetWeb3Suite = exports.web3SuiteErrorMessage = void 0; const config_1 = require("./config"); const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const process_1 = require("process"); const chalk_1 = __importDefault(require("chalk")); exports.web3SuiteErrorMessage = `It looks like you do not have a hardhat or truffle config file present in your project root. You need to make sure that you are using either a hardhat project or a truffle project. If you are using a hardhat project, you will have a hardhat.config.ts/js file in your project root. If you are using a truffle project, you will have a truffle-config.js file in your project root. It may also be the case that you've accidentally place BOTH a truffle config AND a hardhat config file in your project root. Please make sure you are not mixing hardhat and truffle projects.`; function discoverAndSetWeb3Suite() { config_1.SimbaConfig.log.debug(":: ENTER :"); const hardhatTSPath = path_1.default.join((0, process_1.cwd)(), "hardhat.config.ts"); const hardhatJSPath = path_1.default.join((0, process_1.cwd)(), "hardhat.config.js"); const truffleJSPath = path_1.default.join((0, process_1.cwd)(), "truffle-config.js"); const web3SuiteFromSimbaConfig = config_1.SimbaConfig.ProjectConfigStore.get("web3Suite"); if (web3SuiteFromSimbaConfig) { return web3SuiteFromSimbaConfig.toLowerCase(); } if (fs_1.default.existsSync(truffleJSPath) && (fs_1.default.existsSync(hardhatJSPath) || fs_1.default.existsSync(hardhatTSPath))) { const message = `It looks like you have a truffle config file and a hardhat config file. Please make sure your project is EITHER a hardhat project OR a truffle project`; config_1.SimbaConfig.log.error(`${chalk_1.default.redBright(`${message}`)}`); throw new Error(message); } if (fs_1.default.existsSync(hardhatJSPath) || fs_1.default.existsSync(hardhatTSPath)) { const web3Suite = "hardhat"; config_1.SimbaConfig.ProjectConfigStore.set("web3Suite", web3Suite); return web3Suite; } if (fs_1.default.existsSync(truffleJSPath)) { const web3Suite = "truffle"; config_1.SimbaConfig.ProjectConfigStore.set("web3Suite", web3Suite); return web3Suite; } const message = `It looks like you do not have a hardhat or truffle config file present in your project root. You need to make sure that you are using either a hardhat project or a truffle project. If you are using a hardhat project, you will have a hardhat.config.ts/js file in your project root. If you are using a truffle project, you will have a truffle-config.js file in your project root.`; config_1.SimbaConfig.log.error(`${chalk_1.default.redBright(`${message}`)}`); throw new Error(message); } exports.discoverAndSetWeb3Suite = discoverAndSetWeb3Suite; function buildURL(baseURL, url) { const params = { baseURL, url, }; config_1.SimbaConfig.log.debug(`:: ENTER : ${JSON.stringify(params)}`); if (!url.startsWith("http")) { if (baseURL.endsWith("/") && url.startsWith("/")) { url = url.slice(1); } if (!baseURL.endsWith("/") && !url.startsWith("/")) { url = "/" + url; } url = baseURL + url; } config_1.SimbaConfig.log.debug(`:: EXIT : url : ${url}`); return url; } exports.buildURL = buildURL; //# sourceMappingURL=utils.js.map