refactor(generation/embarkjs): generate embarkjs in artifacts dir

This commit is contained in:
Jonathan Rainville 2019-02-08 11:41:52 -05:00 committed by Iuri Matias
parent 40b9ac3c70
commit c91e145981
3 changed files with 17 additions and 14 deletions

View File

@ -88,6 +88,7 @@
"dir": "config", "dir": "config",
"blockchain": "blockchain.json", "blockchain": "blockchain.json",
"storage": "storage.json", "storage": "storage.json",
"communication": "communication.json" "communication": "communication.json",
"embarkjs": "embarkjs.js"
} }
} }

View File

@ -149,44 +149,47 @@ class CodeGenerator {
warnIfMetamask: this.blockchainConfig.isDev, warnIfMetamask: this.blockchainConfig.isDev,
blockchainClient: this.blockchainConfig.ethereumClientName blockchainClient: this.blockchainConfig.ethereumClientName
}; };
this.generateConfig(this.dappConfigs.blockchain, constants.dappConfig.blockchain); this.generateArtifact(this.dappConfigs.blockchain, constants.dappConfig.blockchain, constants.dappConfig.dir);
} }
generateStorageConfig(storageConfig) { generateStorageConfig(storageConfig) {
this.dappConfigs.storage = { this.dappConfigs.storage = {
dappConnection: storageConfig.dappConnection dappConnection: storageConfig.dappConnection
}; };
this.generateConfig(this.dappConfigs.storage, constants.dappConfig.storage); this.generateArtifact(this.dappConfigs.storage, constants.dappConfig.storage, constants.dappConfig.dir);
} }
generateCommunicationConfig(communicationConfig) { generateCommunicationConfig(communicationConfig) {
this.dappConfigs.communication = { this.dappConfigs.communication = {
connection: communicationConfig.connection connection: communicationConfig.connection
}; };
this.generateConfig(this.dappConfigs.communication, constants.dappConfig.communication); this.generateArtifact(this.dappConfigs.communication, constants.dappConfig.communication, constants.dappConfig.dir);
} }
generateConfig(configObj, filepathName) { generateArtifact(artifactInput, fileName, dirName, cb = () => {}) {
const dir = utils.joinPath(this.embarkConfig.generationDir, constants.dappConfig.dir); const dir = utils.joinPath(this.embarkConfig.generationDir, dirName);
const filePath = utils.joinPath(dir, filepathName); const filePath = utils.joinPath(dir, fileName);
const configString = JSON.stringify(configObj, null, 2); if (typeof artifactInput !== 'string') {
artifactInput = JSON.stringify(artifactInput, null, 2);
}
async.waterfall([ async.waterfall([
(next) => { (next) => {
fs.mkdirp(dir, next); fs.mkdirp(dir, next);
}, },
(_dir, next) => { (_dir, next) => {
this.checkIfNeedsUpdate(filePath, configString, next); this.checkIfNeedsUpdate(filePath, artifactInput, next);
}, },
(needsUpdate, next) => { (needsUpdate, next) => {
if (!needsUpdate) { if (!needsUpdate) {
return next(); return next();
} }
fs.writeFile(filePath, configString, next); fs.writeFile(filePath, artifactInput, next);
} }
], (err) => { ], (err) => {
if (err) { if (err) {
this.logger.error(err.message || err); this.logger.error(err.message || err);
} }
cb(err);
}); });
} }
@ -326,9 +329,7 @@ class CodeGenerator {
next(); next();
}, },
function writeFile(next) { function writeFile(next) {
fs.mkdirpSync(fs.dappPath(".embark")); self.generateArtifact(code, constants.dappConfig.embarkjs, '', next);
fs.writeFileSync(fs.dappPath(".embark", 'embark.js'), code);
next();
} }
], function(_err, _result) { ], function(_err, _result) {
cb(); cb();

View File

@ -14,6 +14,7 @@ class Pipeline {
this.buildDir = embark.config.buildDir; this.buildDir = embark.config.buildDir;
this.contractsFiles = embark.config.contractsFiles; this.contractsFiles = embark.config.contractsFiles;
this.assetFiles = embark.config.assetFiles; this.assetFiles = embark.config.assetFiles;
this.embarkConfig = embark.config.embarkConfig;
this.events = embark.events; this.events = embark.events;
this.logger = embark.config.logger; this.logger = embark.config.logger;
this.plugins = embark.config.plugins; this.plugins = embark.config.plugins;
@ -154,7 +155,7 @@ class Pipeline {
(next) => self.buildContracts(next), (next) => self.buildContracts(next),
(next) => self.buildWeb3JS(next), (next) => self.buildWeb3JS(next),
function createImportList(next) { function createImportList(next) {
importsList["Embark/EmbarkJS"] = fs.dappPath(".embark", 'embark.js'); importsList["Embark/EmbarkJS"] = fs.dappPath(self.embarkConfig.generationDir, constants.dappConfig.embarkjs);
importsList["Embark/web3"] = fs.dappPath(".embark", 'web3_instance.js'); importsList["Embark/web3"] = fs.dappPath(".embark", 'web3_instance.js');
importsList["Embark/contracts"] = fs.dappPath(".embark/contracts", ''); importsList["Embark/contracts"] = fs.dappPath(".embark/contracts", '');