Skip to content

Commit

Permalink
Allow .js config file (#56)
Browse files Browse the repository at this point in the history
* allow js as a config file
  • Loading branch information
marekkirejczyk committed Jan 15, 2019
1 parent d84ecc5 commit 768b4a0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
13 changes: 8 additions & 5 deletions lib/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,16 @@ export default class Compiler {
}
}

export function loadConfig(configPath: string) {
if (configPath) {
return require(path.join(process.cwd(), configPath));
}
return {};
}

export async function compile(configPath: string, options = {}) {
try {
let config = {};
if (configPath) {
const contents = fs.readFileSync(configPath, 'utf-8');
config = JSON.parse(contents);
}
const config = loadConfig(configPath);
const compiler = new Compiler(config, options);
await compiler.compile();
} catch (err) {
Expand Down
7 changes: 4 additions & 3 deletions test/compiler/e2e.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import fs from 'fs';
import fsx from 'fs-extra';
import path from 'path';
import {join, resolve} from 'path';
import {expect} from 'chai';
import {compile} from '../../lib/compiler';
import {compile, loadConfig} from '../../lib/compiler';
import {readFileContent, isFile, deepCopy} from '../../lib/utils';
import {deployContract, link, getWallets, createMockProvider} from '../../lib/waffle';

const configurations = [
'./test/projects/custom/config.json',
'./test/projects/custom/config.js',
'./test/projects/custom/config_native.json',
'./test/projects/custom/config_docker.json',
'./test/projects/custom_solidity_4/config_solcjs.json',
Expand Down Expand Up @@ -45,7 +46,7 @@ describe('E2E: Compiler integration', () => {
});

for (const configurationPath of configurations) {
const configuration = JSON.parse(readFileContent(configurationPath));
const configuration = loadConfig(configurationPath);
const {name, targetPath} = configuration;

/* eslint-disable no-loop-func */
Expand Down
6 changes: 6 additions & 0 deletions test/projects/custom/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
name: "solidity 5, solcjs",
sourcesPath: "./test/projects/custom/custom_contracts",
targetPath: "./test/projects/custom/custom_build",
npmPath: "./test/projects/custom/custom_node_modules"
};
6 changes: 0 additions & 6 deletions test/projects/custom/config.json

This file was deleted.

0 comments on commit 768b4a0

Please sign in to comment.