Add contracts to compiler options
This commit is contained in:
@@ -14,6 +14,7 @@ const DEFAULT_ARTIFACTS_DIR = path.resolve('artifacts');
|
||||
const DEFAULT_NETWORK_ID = 50;
|
||||
const DEFAULT_JSONRPC_PORT = 8545;
|
||||
const DEFAULT_GAS_PRICE = (10 ** 9 * 2).toString();
|
||||
const DEFAULT_COMPILE_CONTRACTS = '*';
|
||||
|
||||
/**
|
||||
* Compiles all contracts with options passed in through CLI.
|
||||
@@ -25,6 +26,7 @@ async function onCompileCommand(argv: CliOptions): Promise<void> {
|
||||
networkId: argv.networkId,
|
||||
optimizerEnabled: argv.shouldOptimize ? 1 : 0,
|
||||
artifactsDir: argv.artifactsDir,
|
||||
contractsToCompile: generateContractsToCompileSet(argv.contracts),
|
||||
};
|
||||
await commands.compileAsync(opts);
|
||||
}
|
||||
@@ -43,6 +45,7 @@ async function onMigrateCommand(argv: CliOptions): Promise<void> {
|
||||
networkId,
|
||||
optimizerEnabled: argv.shouldOptimize ? 1 : 0,
|
||||
artifactsDir: argv.artifactsDir,
|
||||
contractsToCompile: generateContractsToCompileSet(argv.contracts),
|
||||
};
|
||||
await commands.compileAsync(compilerOpts);
|
||||
|
||||
@@ -72,6 +75,7 @@ async function onDeployCommand(argv: CliOptions): Promise<void> {
|
||||
networkId,
|
||||
optimizerEnabled: argv.shouldOptimize ? 1 : 0,
|
||||
artifactsDir: argv.artifactsDir,
|
||||
contractsToCompile: generateContractsToCompileSet(argv.contracts),
|
||||
};
|
||||
await commands.compileAsync(compilerOpts);
|
||||
|
||||
@@ -89,6 +93,18 @@ async function onDeployCommand(argv: CliOptions): Promise<void> {
|
||||
const deployerArgs = deployerArgsString.split(',');
|
||||
await commands.deployAsync(argv.contract, deployerArgs, deployerOpts);
|
||||
}
|
||||
/**
|
||||
* Creates a set of contracts to compile.
|
||||
* @param contracts Comma separated list of contracts to compile
|
||||
*/
|
||||
function generateContractsToCompileSet(contracts: string): Set<string> {
|
||||
const contractsToCompile = new Set();
|
||||
const contractsArray = contracts.split(',');
|
||||
_.forEach(contracts, contractName => {
|
||||
contractsToCompile.add(contractName);
|
||||
});
|
||||
return contractsToCompile;
|
||||
}
|
||||
/**
|
||||
* Provides extra required options for deploy command.
|
||||
* @param yargsInstance yargs instance provided in builder function callback.
|
||||
@@ -144,6 +160,11 @@ function deployCommandBuilder(yargsInstance: any) {
|
||||
type: 'string',
|
||||
description: 'account to use for deploying contracts',
|
||||
})
|
||||
.option('contracts', {
|
||||
type: 'string',
|
||||
default: DEFAULT_COMPILE_CONTRACTS,
|
||||
description: 'comma separated list of contracts to compile',
|
||||
})
|
||||
.command('compile', 'compile contracts', identityCommandBuilder, onCompileCommand)
|
||||
.command(
|
||||
'migrate',
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
import { utils } from './utils/utils';
|
||||
|
||||
const SOLIDITY_FILE_EXTENSION = '.sol';
|
||||
const ALL_CONTRACTS_IDENTIFIER = '*';
|
||||
|
||||
export class Compiler {
|
||||
private _contractsDir: string;
|
||||
@@ -25,6 +26,7 @@ export class Compiler {
|
||||
private _artifactsDir: string;
|
||||
private _contractSourcesIfExists?: ContractSources;
|
||||
private _solcErrors: Set<string>;
|
||||
private _contractsToCompile: Set<string>;
|
||||
/**
|
||||
* Recursively retrieves Solidity source code from directory.
|
||||
* @param dirPath Directory to search.
|
||||
@@ -106,6 +108,7 @@ export class Compiler {
|
||||
this._optimizerEnabled = opts.optimizerEnabled;
|
||||
this._artifactsDir = opts.artifactsDir;
|
||||
this._solcErrors = new Set();
|
||||
this._contractsToCompile = opts.contractsToCompile;
|
||||
}
|
||||
/**
|
||||
* Compiles all Solidity files found in contractsDir and writes JSON artifacts to artifactsDir.
|
||||
@@ -150,9 +153,10 @@ export class Compiler {
|
||||
oldNetworks = currentArtifact.networks;
|
||||
const oldNetwork: ContractData = oldNetworks[this._networkId];
|
||||
shouldCompile =
|
||||
_.isUndefined(oldNetwork) ||
|
||||
(_.isUndefined(oldNetwork) ||
|
||||
oldNetwork.keccak256 !== sourceHash ||
|
||||
oldNetwork.optimizer_enabled !== this._optimizerEnabled;
|
||||
oldNetwork.optimizer_enabled !== this._optimizerEnabled) &&
|
||||
(this._contractsToCompile.has(ALL_CONTRACTS_IDENTIFIER) || this._contractsToCompile.has(contractName));
|
||||
} catch (err) {
|
||||
shouldCompile = true;
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ export interface CompilerOptions {
|
||||
networkId: number;
|
||||
optimizerEnabled: number;
|
||||
artifactsDir: string;
|
||||
contractsToCompile: Set<string>;
|
||||
}
|
||||
|
||||
export interface DeployerOptions {
|
||||
|
||||
Reference in New Issue
Block a user