UNPKG

@graphprotocol/graph-cli

Version:

CLI for building for and deploying to The Graph

46 lines (45 loc) 1.36 kB
import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import * as toolbox from 'gluegun'; import { normalizeNodeUrl } from './node.js'; const homedir = os.homedir(); const CONFIG_PATH = path.join(homedir, '/.graph-cli.json'); const getConfig = () => { let config; try { config = JSON.parse(fs.readFileSync(CONFIG_PATH).toString()); } catch { config = {}; } return config; }; export const identifyDeployKey = async (node, deployKey) => { // Determine the deploy key to use, if any: // - First try using --deploy-key, if provided // - Then see if we have a deploy key set for the Graph node if (deployKey !== undefined) { return deployKey; } try { node = normalizeNodeUrl(node); const config = getConfig(); return config[node]; } catch (e) { toolbox.print.warning(`Could not get deploy key: ${e.message}`); toolbox.print.info(`Continuing without a deploy key\n`); } }; export const saveDeployKey = async (node, deployKey) => { try { node = normalizeNodeUrl(node); const config = getConfig(); config[node] = deployKey; fs.writeFileSync(CONFIG_PATH, JSON.stringify(config)); } catch (e) { throw new Error(`Error storing deploy key: ${e.message}`); } };