From 810c3be9fcf4e212d84a9db6565f8216d30cc27d Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 11 Jul 2019 15:41:58 -0400 Subject: [PATCH] fix(@embark/pipeline): streamline contract index file creation --- packages/embark-pipeline/src/index.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/embark-pipeline/src/index.js b/packages/embark-pipeline/src/index.js index a8bcc9088..82de4eaa7 100644 --- a/packages/embark-pipeline/src/index.js +++ b/packages/embark-pipeline/src/index.js @@ -356,8 +356,14 @@ class Pipeline { // Used to enable alternate import syntax: // e.g. import {Token} from 'Embark/contracts' // e.g. import * as Contracts from 'Embark/contracts' - let importsHelperFile = self.fs.createWriteStream(joinPath(contractsDir, 'index.js')); - importsHelperFile.write('module.exports = {\n'); + let importHelperFileCode = 'module.exports = {\n'; + Object.values(contracts).forEach(contract => { + importHelperFileCode += `"${contract.className}": require('./${contract.className}').default,\n`; + }); + importHelperFileCode += '};'; + self.fs.writeFile(joinPath(contractsDir, 'index.js'), importHelperFileCode, (err) => { + if (err) self.logger.error(__('Error writing contract index file: %s', err.message)); + }); async.eachOf(contracts, (contract, idx, eachCb) => { self.events.request('code-generator:contract', contract.className, (err, contractPath) => { @@ -366,14 +372,9 @@ class Pipeline { } importsList["Embark/contracts/" + contract.className] = dappPath(contractPath); - // add the contract to the exports list to support alternate import syntax - importsHelperFile.write(`"${contract.className}": require('./${contract.className}').default,\n`); eachCb(); }); - }, () => { - importsHelperFile.write('\n};'); // close the module.exports = {} - importsHelperFile.close(next); // close the write stream - }); + }, next); }); } ], cb);