Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions scripts/hardhat-tasks-functions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-undef */ // This is to disable warning for hre undefined in file
const fs = require('fs-extra');
const { exec } = require('child_process');
const { exec, execFile } = require('child_process');
const axios = require('axios');
const ethers = require('ethers');
const path = require('path');
Expand Down Expand Up @@ -167,13 +167,15 @@ function getInput(text) {
});
}

function execShellCommand(cmd) {
function execShellCommand(cmd, args = []) {
Comment thread
Dargon789 marked this conversation as resolved.
return new Promise((resolve) => {
exec(cmd, (error, stdout, stderr) => {
execFile(cmd, args, (error, stdout, stderr) => {
if (error) {
console.warn(error);
}
console.log(stderr);
if (stderr) {
console.log(stderr);
Comment thread
Dargon789 marked this conversation as resolved.
}
resolve(stdout || stderr);
});
});
Expand Down Expand Up @@ -453,8 +455,8 @@ async function flatten(filePath) {
console.error(err);
}
// Flatten file, delete unneeded licenses and pragmas
await execShellCommand(`npx hardhat flatten ${filePath} > contracts/flattened/${fileName}`);
let data = (await fs.readFileSync(`contracts/flattened/${fileName}`)).toString();
const flattenedSource = await execShellCommand('npx', ['hardhat', 'flatten', filePath]);
let data = flattenedSource.toString();
data = data.replace(pragmaRegex, '');
data = data.replace(topLvlCommentsRegex, '');
const flags = { flag: 'a+' };
Expand Down
7 changes: 5 additions & 2 deletions scripts/hardhat-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@ task('deployOnFork', 'Deploys contracts on an existing fork')
)
.setAction(async (args) => {
const contractNames = args.contractNames.join(' ');
const cmd = `CONTRACTS="${contractNames}" npx hardhat run ./scripts/utils/deploy-on-fork.js --network fork`;
try {
execSync(cmd, { stdio: 'inherit', shell: true });
execSync('npx', ['hardhat', 'run', './scripts/utils/deploy-on-fork.js', '--network', 'fork'], {
stdio: 'inherit',
shell: true,
env: { ...process.env, CONTRACTS: contractNames },
});
Comment thread
Dargon789 marked this conversation as resolved.
} catch (error) {
console.error(`Command failed: ${error}`);
process.exit(1);
Expand Down
Loading