truffle compilation with custom config

pull/2333/head
Aniket-Engg 3 years ago committed by Aniket
parent a518ca611b
commit d2f6aa5803
  1. 4
      apps/solidity-compiler/src/app/compiler-api.ts
  2. 2
      libs/remix-lib/src/types/ICompilerApi.ts
  3. 22
      libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts
  4. 4
      libs/remixd/src/services/truffleClient.ts

@ -105,8 +105,8 @@ export const CompilerApiMixin = (Base) => class extends Base {
return this.call('hardhat', 'compile', configFile)
}
compileWithTruffle () {
return this.call('truffle', 'compile')
compileWithTruffle (configFile) {
return this.call('truffle', 'compile', configFile)
}
logToTerminal (content) {

@ -42,7 +42,7 @@ export interface ICompilerApi {
logToTerminal: (log: terminalLog) => void
compileWithHardhat: (configPath: string) => Promise<string>
compileWithTruffle: () => Promise<string>
compileWithTruffle: (configPath: string) => Promise<string>
statusChanged: (data: { key: string, title?: string, type?: string }) => void,
emit?: (key: string, ...payload: any) => void
}

@ -141,11 +141,31 @@ export class CompileTabLogic {
})
}
} else if (externalCompType === 'truffle') {
this.api.compileWithTruffle().then((result) => {
const { currentVersion, optimize, runs, evmVersion } = this.compiler.state
if (currentVersion) {
const fileContent = `module.exports = {
compilers: {
solc: {
version: '${currentVersion.substring(0, currentVersion.indexOf('+commit'))}',
settings: {
optimizer: {
enabled: ${optimize},
runs: ${runs},
},
evmVersion: ${evmVersion}
}
}
}
}`
const configFilePath = 'remix-compiler.config.js'
this.api.writeFile(configFilePath, fileContent)
_paq.push(['trackEvent', 'compiler', 'compileWithTruffle'])
this.api.compileWithTruffle(configFilePath).then((result) => {
this.api.logToTerminal({ type: 'info', value: result })
}).catch((error) => {
this.api.logToTerminal({ type: 'error', value: error })
})
}
}
}
// TODO readd saving current file

@ -20,13 +20,13 @@ export class TruffleClient extends PluginClient {
this.currentSharedFolder = currentSharedFolder
}
compile () {
compile (configPath: string) {
return new Promise((resolve, reject) => {
if (this.readOnly) {
const errMsg = '[Truffle Compilation]: Cannot compile in read-only mode'
return reject(new Error(errMsg))
}
const cmd = `truffle compile`
const cmd = `truffle compile --config ${configPath}`
const options = { cwd: this.currentSharedFolder, shell: true }
const child = spawn(cmd, options)
let result = ''

Loading…
Cancel
Save