From badcb35525a4ccd5c80b7ad79288b267b961faef Mon Sep 17 00:00:00 2001 From: "F. Eugene Aumson" Date: Wed, 15 Aug 2018 16:14:36 -0700 Subject: extract method _shouldCompile() --- packages/sol-compiler/src/compiler.ts | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'packages') diff --git a/packages/sol-compiler/src/compiler.ts b/packages/sol-compiler/src/compiler.ts index f0cb2ded3..390c2412a 100644 --- a/packages/sol-compiler/src/compiler.ts +++ b/packages/sol-compiler/src/compiler.ts @@ -172,19 +172,7 @@ export class Compiler { path.join(this._contractsDir, contractSource.path), ).toString('hex')}`, }; - let shouldCompile = false; - if (_.isUndefined(contractPathToData[contractSource.path].currentArtifactIfExists)) { - shouldCompile = true; - } else { - const currentArtifact = contractPathToData[contractSource.path] - .currentArtifactIfExists as ContractArtifact; - const isUserOnLatestVersion = currentArtifact.schemaVersion === constants.LATEST_ARTIFACT_VERSION; - const didCompilerSettingsChange = !_.isEqual(currentArtifact.compiler.settings, this._compilerSettings); - const didSourceChange = - currentArtifact.sourceTreeHashHex !== contractPathToData[contractSource.path].sourceTreeHashHex; - shouldCompile = !isUserOnLatestVersion || didCompilerSettingsChange || didSourceChange; - } - if (!shouldCompile) { + if (!this._shouldCompile(contractPathToData[contractSource.path])) { continue; } const solcVersion = _.isUndefined(this._solcVersionIfExists) @@ -231,6 +219,17 @@ export class Compiler { } } } + private _shouldCompile(contractData: ContractData): boolean { + if (_.isUndefined(contractData.currentArtifactIfExists)) { + return true; + } else { + const currentArtifact = contractData.currentArtifactIfExists as ContractArtifact; + const isUserOnLatestVersion = currentArtifact.schemaVersion === constants.LATEST_ARTIFACT_VERSION; + const didCompilerSettingsChange = !_.isEqual(currentArtifact.compiler.settings, this._compilerSettings); + const didSourceChange = currentArtifact.sourceTreeHashHex !== contractData.sourceTreeHashHex; + return !isUserOnLatestVersion || didCompilerSettingsChange || didSourceChange; + } + } private async _verifyAndPersistCompiledContractAsync( contractPath: string, contractMetadata: ContractData, -- cgit v1.2.3