UNPKG

deployment-tool

Version:

Tool to deploy and upgrade contracts on Ethereum Mainnet

139 lines 4.78 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.pushToGit = exports.pullFromGit = exports.commitChanges = exports.getLastCommit = exports.addToCommit = exports.etherscanVerifyContract = exports.compileContract = exports.runCommand = void 0; const child_process_1 = require("child_process"); const fs_1 = __importDefault(require("fs")); const sleep = async (ms) => { return new Promise((resolve) => setTimeout(resolve, ms)); }; const runCommand = async (command) => { try { let finishedRunning = false; const runPush = await (0, child_process_1.spawn)(command, { stdio: 'inherit', shell: true }); runPush.on('exit', (code) => { // exit() finishedRunning = true; }); // Keep waiting until the compiling is finished while (!finishedRunning) { await sleep(500); } return true; } catch (err) { console.log('\x1b[33m%s\x1b[0m', `Error running command`, err); return false; } }; exports.runCommand = runCommand; const compileContract = async (env) => { try { await env.run('compile'); console.log('\x1b[32m%s\x1b[0m', `Contracts have been compiled`); return true; } catch (err) { console.log('\x1b[33m%s\x1b[0m', `Error compiling contract`, err); return false; } }; exports.compileContract = compileContract; const etherscanVerifyContract = async (env, contractAddress) => { try { await env.run('verify:verify', { address: contractAddress, constructorArguments: [] }); console.log('\x1b[32m%s\x1b[0m', `Contract: ${contractAddress} has been verify on etherscan.io`); return true; } catch (err) { console.log('\x1b[33m%s\x1b[0m', `Error verifying contract on etherscan.io`, err); return false; } }; exports.etherscanVerifyContract = etherscanVerifyContract; const addToCommit = async (filesToCommit) => { try { await (0, exports.runCommand)('git add ' + filesToCommit); console.log('\x1b[32m%s\x1b[0m', `Files: ${filesToCommit} has been added to the next commit`); return true; } catch (err) { console.log('\x1b[33m%s\x1b[0m', `Error git add`, err); return false; } }; exports.addToCommit = addToCommit; const getLastCommit = async () => { const TEMP_FILE = 'lastGitCommit.txt'; let commitId = ''; try { await (0, exports.runCommand)('git log -n 1 > ' + TEMP_FILE); if (fs_1.default.existsSync('./' + TEMP_FILE)) { const lastGitCommitData = fs_1.default.readFileSync('./' + TEMP_FILE, 'utf8'); // Separate the commit id from the rest of the commit message commitId = lastGitCommitData.split(' ')[1].substring(0, 8); // Delete the temporary file fs_1.default.unlinkSync('./' + TEMP_FILE); } else console.log('\x1b[31m%s\x1b[0m', `Could not find ${TEMP_FILE}`); return { success: true, commitId }; } catch (err) { console.log('\x1b[33m%s\x1b[0m', `Error git log last commit id`, err); return { success: false, commitId }; } }; exports.getLastCommit = getLastCommit; const commitChanges = async (commitComment, commitDescription, filesToCommit) => { try { // Commit the new storage layout await (0, exports.runCommand)(`git commit -a -m "deployment-tool: ${commitComment}" -m "${commitDescription}"`); console.log('\x1b[32m%s\x1b[0m', `Files ${filesToCommit} are Committed in the repo`); return true; } catch (err) { console.log('\x1b[33m%s\x1b[0m', `Error git commit`, err); return false; } }; exports.commitChanges = commitChanges; const pullFromGit = async () => { try { await (0, exports.runCommand)('git pull'); console.log('\x1b[32m%s\x1b[0m', `Git Pull is done`); return true; } catch (err) { console.log('\x1b[33m%s\x1b[0m', `Error git pull`, err); return false; } }; exports.pullFromGit = pullFromGit; const pushToGit = async (filesToCommit) => { try { await (0, exports.runCommand)('git push'); console.log('\x1b[32m%s\x1b[0m', `Files ${filesToCommit} are Push in the repo`); return true; } catch (err) { console.log('\x1b[33m%s\x1b[0m', `Error git push`, err); return false; } }; exports.pushToGit = pushToGit; //# sourceMappingURL=utils.js.map