diff --git a/lib/i18n/locales/en.json b/lib/i18n/locales/en.json index 81f2aa879..d1b17561d 100644 --- a/lib/i18n/locales/en.json +++ b/lib/i18n/locales/en.json @@ -101,8 +101,17 @@ "downloading {{packageName}} {{version}}....": "downloading {{packageName}} {{version}}....", "Swarm node is offline...": "Swarm node is offline...", "Swarm node detected...": "Swarm node detected...", + "Cannot find file %s Please ensure you are running this command inside the Dapp folder": "Cannot find file %s Please ensure you are running this command inside the Dapp folder", + "finished building": "finished building", + "compiling Vyper contracts": "compiling Vyper contracts", + "Vyper exited with error code ": "Vyper exited with error code ", + "attempted to deploy %s without specifying parameters": "attempted to deploy %s without specifying parameters", + "adding %s to ipfs": "adding %s to ipfs", + "DApp available at": "DApp available at", + "successfully uploaded to ipfs": "successfully uploaded to ipfs", "Ethereum node (version unknown)": "Ethereum node (version unknown)", "No Blockchain node found": "No Blockchain node found", "Couldn't connect to an Ethereum node are you sure it's on?": "Couldn't connect to an Ethereum node are you sure it's on?", - "make sure you have an Ethereum node or simulator running. e.g '%s'": "make sure you have an Ethereum node or simulator running. e.g '%s'" + "make sure you have an Ethereum node or simulator running. e.g '%s'": "make sure you have an Ethereum node or simulator running. e.g '%s'", + "finished building DApp and deploying to": "finished building DApp and deploying to" } \ No newline at end of file diff --git a/lib/pipeline/pipeline.js b/lib/pipeline/pipeline.js index 5bcea392c..ea09afba3 100644 --- a/lib/pipeline/pipeline.js +++ b/lib/pipeline/pipeline.js @@ -36,6 +36,7 @@ class Pipeline { function createImportList(next) { importsList["Embark/EmbarkJS"] = fs.dappPath(".embark", 'embark.js'); importsList["Embark/web3"] = fs.dappPath(".embark", 'web3_instance.js'); + importsList["Embark/contracts"] = fs.dappPath(".embark/contracts", ''); self.plugins.getPluginsProperty('imports', 'imports').forEach(function (importObject) { let [importName, importLocation] = importObject; @@ -44,15 +45,34 @@ class Pipeline { next(); }, - function writeContracts(next) { + function writeContracts(next) { self.events.request('contracts:list', (contracts) => { - async.each(contracts, (contract, eachCb) => { - self.events.request('code-generator:contract', contract.className, (contractCode) => { - let filePath = fs.dappPath(".embark", contract.className + '.js'); - importsList["Embark/contracts/" + contract.className] = filePath; - fs.writeFile(filePath, contractCode, eachCb); + // ensure the .embark/contracts directory exists (create if not exists) + fs.mkdirp(fs.dappPath(".embark/contracts", ''), (err) => { + if(err) return next(err); + + // Create a file .embark/contracts/index.js that requires all contract files + // Used to enable alternate import syntax: + // e.g. import {Token} from 'Embark/contracts' + // e.g. import * as Contracts from 'Embark/contracts' + let importsHelperFile = fs.createWriteStream(fs.dappPath(".embark/contracts", 'index.js')); + importsHelperFile.write('module.exports = {\n'); + + async.eachOf(contracts, (contract, idx, eachCb) => { + self.events.request('code-generator:contract', contract.className, (contractCode) => { + let filePath = fs.dappPath(".embark/contracts", contract.className + '.js'); + importsList["Embark/contracts/" + contract.className] = filePath; + fs.writeFile(filePath, contractCode, eachCb); + + // add the contract to the exports list to support alternate import syntax + importsHelperFile.write(`"${contract.className}": require('./${contract.className}').default`); + if(idx < contracts.length - 1) importsHelperFile.write(',\n'); // add a comma if we have more contracts to add + }); + }, function(){ + importsHelperFile.write('\n}'); // close the module.exports = {} + importsHelperFile.close(next); // close the write stream }); - }, next); + }); }); }, function assetFileWrite(next) {