hardhat-graph-protocol
Version:
A hardhat plugin that extends the runtime environment to inject additional functionality related to the usage of the Graph Protocol.
52 lines • 2.19 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAddressBookPath = getAddressBookPath;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const error_1 = require("./error");
const logger_1 = require("./logger");
function getAddressBookPath(deployment, hre, opts) {
const optsPath = getPath(opts.deployments?.[deployment]);
const networkPath = getPath(hre.network.config.deployments?.[deployment]);
const globalPath = getPath(hre.config.graph?.deployments?.[deployment]);
(0, logger_1.logDebug)(`Getting address book path...`);
(0, logger_1.logDebug)(`Graph base dir: ${hre.config.paths.graph}`);
(0, logger_1.logDebug)(`1) opts: ${optsPath}`);
(0, logger_1.logDebug)(`2) network: ${networkPath}`);
(0, logger_1.logDebug)(`3) global: ${globalPath}`);
const addressBookPath = optsPath ?? networkPath ?? globalPath;
if (addressBookPath === undefined) {
return undefined;
}
const normalizedAddressBookPath = normalizePath(addressBookPath, hre.config.paths.graph);
(0, logger_1.logDebug)(`Address book path: ${normalizedAddressBookPath}`);
if (!fs_1.default.existsSync(normalizedAddressBookPath)) {
if (opts.createAddressBook) {
(0, logger_1.logDebug)(`Creating address book: ${normalizedAddressBookPath}`);
fs_1.default.writeFileSync(normalizedAddressBookPath, '{}');
}
else {
throw new error_1.GraphPluginError(`Address book not found: ${normalizedAddressBookPath}`);
}
}
return normalizedAddressBookPath;
}
function normalizePath(_path, graphPath) {
if (!path_1.default.isAbsolute(_path) && graphPath !== undefined) {
_path = path_1.default.join(graphPath, _path);
}
return _path;
}
function getPath(value) {
if (typeof value === 'string') {
return value;
}
else if (value && typeof value == 'object') {
return value.addressBook;
}
return;
}
//# sourceMappingURL=config.js.map