compile.js :
const path = require('path');
const solc = require('solc');
const fs = require('fs-extra');
const buildPath = path.resolve(__dirname, 'build');
fs.removeSync(buildPath);
const campaignPath = path.resolve(__dirname, 'contracts', 'Campaign.sol');
const source = fs.readFileSync(campaignPath, 'utf8');
var input = {
language: 'Solidity',
sources: {
'Campaign.sol': {
content: source
}
},
settings: {
outputSelection: {
'*': {
'*': [ '*' ]
}
}
}
}
const output = solc.compile(input, 1).contracts;
fs.ensureDirSync(buildPath);
for(let contract in output){
fs.outputJSONSync(
path.resolve(buildPath, contract+'.json')
);
}
Campaign.sol :
pragma solidity ^0.5.3;
contract FactoryCampaign {
. . .
}
contract Campaign {
. . .
}
The Solidity works perfectly in remix editor and the solc version is 0.5.3
The solc version 0.4 allowed me to call solc.compile on the 'source' directly but the later versions throw this error
AssertionError [ERR_ASSERTION]: Invalid callback specified.