aboutsummaryrefslogtreecommitdiffstats
path: root/packages/deployer
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-04-01 14:54:56 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-04-02 01:45:25 +0800
commit20fec2943bebc50059b1a9a0646f263b07aba88b (patch)
tree431c578baba8be739f243f786bd035e207beffa0 /packages/deployer
parent1bac5019e84a11843fed3100c36c9b3c47abe430 (diff)
downloaddexon-sol-tools-20fec2943bebc50059b1a9a0646f263b07aba88b.tar.gz
dexon-sol-tools-20fec2943bebc50059b1a9a0646f263b07aba88b.tar.zst
dexon-sol-tools-20fec2943bebc50059b1a9a0646f263b07aba88b.zip
Create solc_bin dir if does not exist before attempting to compile
Diffstat (limited to 'packages/deployer')
-rw-r--r--packages/deployer/src/compiler.ts8
-rw-r--r--packages/deployer/src/utils/compiler.ts12
-rw-r--r--packages/deployer/test/compiler_utils_test.ts6
3 files changed, 14 insertions, 12 deletions
diff --git a/packages/deployer/src/compiler.ts b/packages/deployer/src/compiler.ts
index 4741a9086..219a55c32 100644
--- a/packages/deployer/src/compiler.ts
+++ b/packages/deployer/src/compiler.ts
@@ -11,7 +11,7 @@ import solc = require('solc');
import { binPaths } from './solc/bin_paths';
import {
- createArtifactsDirIfDoesNotExistAsync,
+ createDirIfDoesNotExistAsync,
findImportIfExist,
getContractArtifactIfExistsAsync,
getNormalizedErrMsg,
@@ -32,6 +32,7 @@ import {
import { utils } from './utils/utils';
const ALL_CONTRACTS_IDENTIFIER = '*';
+const SOLC_BIN_DIR = path.join(__dirname, '..', '..', 'solc_bin');
/**
* The Compiler facilitates compiling Solidity smart contracts and saves the results
@@ -103,7 +104,8 @@ export class Compiler {
* Compiles selected Solidity files found in `contractsDir` and writes JSON artifacts to `artifactsDir`.
*/
public async compileAsync(): Promise<void> {
- await createArtifactsDirIfDoesNotExistAsync(this._artifactsDir);
+ await createDirIfDoesNotExistAsync(this._artifactsDir);
+ await createDirIfDoesNotExistAsync(SOLC_BIN_DIR);
this._contractSources = await Compiler._getContractSourcesAsync(this._contractsDir);
_.forIn(this._contractSources, this._setContractSpecificSourceData.bind(this));
const fileNames = this._specifiedContracts.has(ALL_CONTRACTS_IDENTIFIER)
@@ -147,7 +149,7 @@ export class Compiler {
contractSpecificSourceData.solcVersionRange,
);
const fullSolcVersion = binPaths[solcVersion];
- const compilerBinFilename = path.join(__dirname, '../../solc_bin', fullSolcVersion);
+ const compilerBinFilename = path.join(SOLC_BIN_DIR, fullSolcVersion);
let solcjs: string;
const isCompilerAvailableLocally = fs.existsSync(compilerBinFilename);
if (isCompilerAvailableLocally) {
diff --git a/packages/deployer/src/utils/compiler.ts b/packages/deployer/src/utils/compiler.ts
index 9c8fef26d..d5137d394 100644
--- a/packages/deployer/src/utils/compiler.ts
+++ b/packages/deployer/src/utils/compiler.ts
@@ -34,13 +34,13 @@ export async function getContractArtifactIfExistsAsync(
}
/**
- * Creates the artifacts directory if it does not already exist.
- * @param artifactsDir Path to the artifacts directory.
+ * Creates a directory if it does not already exist.
+ * @param artifactsDir Path to the directory.
*/
-export async function createArtifactsDirIfDoesNotExistAsync(artifactsDir: string): Promise<void> {
- if (!fsWrapper.doesPathExistSync(artifactsDir)) {
- logUtils.log('Creating artifacts directory...');
- await fsWrapper.mkdirAsync(artifactsDir);
+export async function createDirIfDoesNotExistAsync(dirPath: string): Promise<void> {
+ if (!fsWrapper.doesPathExistSync(dirPath)) {
+ logUtils.log(`Creating directory at ${dirPath}...`);
+ await fsWrapper.mkdirAsync(dirPath);
}
}
diff --git a/packages/deployer/test/compiler_utils_test.ts b/packages/deployer/test/compiler_utils_test.ts
index 1867177dc..246304858 100644
--- a/packages/deployer/test/compiler_utils_test.ts
+++ b/packages/deployer/test/compiler_utils_test.ts
@@ -3,7 +3,7 @@ import * as dirtyChai from 'dirty-chai';
import 'mocha';
import {
- createArtifactsDirIfDoesNotExistAsync,
+ createDirIfDoesNotExistAsync,
getNormalizedErrMsg,
parseDependencies,
parseSolidityVersionRange,
@@ -21,11 +21,11 @@ describe('Compiler utils', () => {
expect(normalizedErrMsg).to.be.equal('Token.sol:6:46: Warning: Unused local variable');
});
});
- describe('#createArtifactsDirIfDoesNotExistAsync', () => {
+ describe('#createDirIfDoesNotExistAsync', () => {
it('creates artifacts dir', async () => {
const artifactsDir = `${__dirname}/artifacts`;
expect(fsWrapper.doesPathExistSync(artifactsDir)).to.be.false();
- await createArtifactsDirIfDoesNotExistAsync(artifactsDir);
+ await createDirIfDoesNotExistAsync(artifactsDir);
expect(fsWrapper.doesPathExistSync(artifactsDir)).to.be.true();
fsWrapper.rmdirSync(artifactsDir);
expect(fsWrapper.doesPathExistSync(artifactsDir)).to.be.false();