From 54020cf68b6dec0bd435d3eb9c8250167720c590 Mon Sep 17 00:00:00 2001 From: Grandschtroumpf Date: Thu, 30 May 2019 11:11:11 +0200 Subject: [PATCH 1/4] expose "compile" method to remix-plugin --- src/app/tabs/compile-tab.js | 5 +++ src/app/tabs/compileTab/compileTab.js | 44 ++++++++++++++++----------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/app/tabs/compile-tab.js b/src/app/tabs/compile-tab.js index 21409256d5..574f7e5df4 100644 --- a/src/app/tabs/compile-tab.js +++ b/src/app/tabs/compile-tab.js @@ -173,6 +173,11 @@ class CompileTab extends CompilerApi { return this.compileTabLogic.compiler.lastCompilationResult } + // This function is used by remix-plugin + compile (fileName) { + return this.compileTabLogic.compileFile(fileName) + } + /********* * SUB-COMPONENTS */ diff --git a/src/app/tabs/compileTab/compileTab.js b/src/app/tabs/compileTab/compileTab.js index 828a0e0d20..1c29029647 100644 --- a/src/app/tabs/compileTab/compileTab.js +++ b/src/app/tabs/compileTab/compileTab.js @@ -33,28 +33,38 @@ class CompileTab { this.compiler.setOptimize(this.optimize) } - runCompiler () { - this.fileManager.saveCurrentFile() - this.editor.clearAnnotations() - var currentFile = this.config.get('currentFile') - if (!currentFile) return - if (!/\.sol/.exec(currentFile)) return + /** + * Compile a specific file of the file manager + * @param {string} target the path to the file to compile + */ + compileFile (target) { + if (!target) throw new Error('No target provided for compiliation') + if (!/\.sol/.exec(target)) throw new Error(`${target} is not a solidity file. It cannot be compiled with solidity compiler`) // only compile *.sol file. - var target = currentFile - var sources = {} - var provider = this.fileManager.fileProviderOf(currentFile) - if (!provider) return console.log('cannot compile ' + currentFile + '. Does not belong to any explorer') - provider.get(target, (error, content) => { - if (error) return console.log(error) - sources[target] = { content } - this.event.emit('startingCompilation') - setTimeout(() => { + const provider = this.fileManager.fileProviderOf(target) + if (!provider) throw new Error(`cannot compile ${target}. Does not belong to any explorer`) + return new Promise((resolve, reject) => { + provider.get(target, (error, content) => { + if (error) return reject(error) + const sources = { [target]: { content } } + this.event.emit('startingCompilation') // setTimeout fix the animation on chrome... (animation triggered by 'staringCompilation') - this.compiler.compile(sources, target) - }, 100) + setTimeout(() => this.compiler.compile(sources, target), 100) + }) }) } + runCompiler () { + try { + this.fileManager.saveCurrentFile() + this.editor.clearAnnotations() + var currentFile = this.config.get('currentFile') + return this.compileFile(currentFile) + } catch (err) { + console.error(err) + } + } + importExternal (url, cb) { this.compilerImport.import(url, From 49b3a91e48d1def14d6f116a8718aa5c2e9356f2 Mon Sep 17 00:00:00 2001 From: Grandschtroumpf Date: Thu, 30 May 2019 11:47:01 +0200 Subject: [PATCH 2/4] use remix-plugin 0.0.2-alpha.10 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 58d3cfd85c..210e824a7a 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ }, "dependencies": { "http-server": "^0.11.1", - "remix-plugin": "0.0.2-alpha.9", + "remix-plugin": "0.0.2-alpha.10", "remixd": "0.1.8-alpha.6" }, "repository": { From ca94af80b0a2358109f5d1c6114731b1adf648e8 Mon Sep 17 00:00:00 2001 From: Grandschtroumpf Date: Mon, 3 Jun 2019 10:09:40 +0200 Subject: [PATCH 3/4] Compile tab display file name origin --- src/app/tabs/compile-tab.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/app/tabs/compile-tab.js b/src/app/tabs/compile-tab.js index 574f7e5df4..4b914f3a63 100644 --- a/src/app/tabs/compile-tab.js +++ b/src/app/tabs/compile-tab.js @@ -132,7 +132,7 @@ class CompileTab extends CompilerApi { // Update contract Selection let contractMap = {} if (success) this.compiler.visitContracts((contract) => { contractMap[contract.name] = contract }) - let contractSelection = this.contractSelection(Object.keys(contractMap) || [], source.target) + let contractSelection = this.contractSelection(contractMap) yo.update(this._view.contractSelection, contractSelection) if (data['error']) { @@ -186,13 +186,22 @@ class CompileTab extends CompilerApi { * Section to select the compiled contract * @param {string[]} contractList Names of the compiled contracts */ - contractSelection (contractList = [], sourceFile) { + contractSelection (contractMap) { + // Return the file name of a path: ex "browser/ballot.sol" -> "ballot.sol" + const getFileName = (path) => { + const part = path.split('/') + return part[part.length - 1] + } + const contractList = contractMap ? Object.keys(contractMap).map((key) => ({ + name: key, + file: getFileName(contractMap[key].file) + })) : [] let selectEl = yo` ` let result = contractList.length From 30c9126e8ad04625ea51d78f901e9a2f8919246a Mon Sep 17 00:00:00 2001 From: Grandschtroumpf Date: Mon, 3 Jun 2019 10:17:48 +0200 Subject: [PATCH 4/4] improve browser test --- test-browser/helpers/contracts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-browser/helpers/contracts.js b/test-browser/helpers/contracts.js index 758a17923a..417867e78f 100644 --- a/test-browser/helpers/contracts.js +++ b/test-browser/helpers/contracts.js @@ -42,7 +42,7 @@ function getCompiledContracts (browser, compiled, callback) { } else { var ret = [] for (var c = 0; c < contracts.length; c++) { - ret.push(contracts[c].innerHTML) + ret.push(contracts[c].value) } return ret }