expose "compile" method to remix-plugin

pull/3094/head
Grandschtroumpf 6 years ago
parent 0da46ec468
commit 4afaa3d679
  1. 5
      src/app/tabs/compile-tab.js
  2. 40
      src/app/tabs/compileTab/compileTab.js

@ -173,6 +173,11 @@ class CompileTab extends CompilerApi {
return this.compileTabLogic.compiler.lastCompilationResult return this.compileTabLogic.compiler.lastCompilationResult
} }
// This function is used by remix-plugin
compile (fileName) {
return this.compileTabLogic.compileFile(fileName)
}
/********* /*********
* SUB-COMPONENTS * SUB-COMPONENTS
*/ */

@ -33,28 +33,38 @@ class CompileTab {
this.compiler.setOptimize(this.optimize) this.compiler.setOptimize(this.optimize)
} }
runCompiler () { /**
this.fileManager.saveCurrentFile() * Compile a specific file of the file manager
this.editor.clearAnnotations() * @param {string} target the path to the file to compile
var currentFile = this.config.get('currentFile') */
if (!currentFile) return compileFile (target) {
if (!/\.sol/.exec(currentFile)) return 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. // only compile *.sol file.
var target = currentFile const provider = this.fileManager.fileProviderOf(target)
var sources = {} if (!provider) throw new Error(`cannot compile ${target}. Does not belong to any explorer`)
var provider = this.fileManager.fileProviderOf(currentFile) return new Promise((resolve, reject) => {
if (!provider) return console.log('cannot compile ' + currentFile + '. Does not belong to any explorer')
provider.get(target, (error, content) => { provider.get(target, (error, content) => {
if (error) return console.log(error) if (error) return reject(error)
sources[target] = { content } const sources = { [target]: { content } }
this.event.emit('startingCompilation') this.event.emit('startingCompilation')
setTimeout(() => {
// setTimeout fix the animation on chrome... (animation triggered by 'staringCompilation') // setTimeout fix the animation on chrome... (animation triggered by 'staringCompilation')
this.compiler.compile(sources, target) setTimeout(() => this.compiler.compile(sources, target), 100)
}, 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) { importExternal (url, cb) {
this.compilerImport.import(url, this.compilerImport.import(url,

Loading…
Cancel
Save