truffle compile child process

pull/5370/head
Aniket-Engg 3 years ago committed by yann300
parent e7cc1fd285
commit be606d043f
  1. 9
      apps/solidity-compiler/src/app/compiler-api.ts
  2. 2
      libs/remix-lib/src/types/ICompilerApi.ts
  3. 20
      libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts
  4. 63
      libs/remixd/src/services/truffleClient.ts
  5. 1231
      package-lock.json
  6. 2
      package.json

@ -101,15 +101,10 @@ export const CompilerApiMixin = (Base) => class extends Base {
return this.call('hardhat', 'compile', configFile) return this.call('hardhat', 'compile', configFile)
} }
async compileWithTruffle (fileName, compConfig) { compileWithTruffle () {
console.log('Inside compileWithTruffle in compile-api', compConfig) return this.call('truffle', 'compile')
return await this.call('truffle', 'compile', fileName, compConfig)
} }
// async compileWithTruffle (fileName, CompConfig) {
// }
logToTerminal (content) { logToTerminal (content) {
return this.call('terminal', 'log', content) return this.call('terminal', 'log', content)
} }

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

@ -141,29 +141,11 @@ export class CompileTabLogic {
}) })
} }
} else if (externalCompType === 'truffle') { } else if (externalCompType === 'truffle') {
const fileName = this.api.currentFile this.api.compileWithTruffle().then((result) => {
const { currentVersion, optimize, runs, evmVersion} = this.compiler.state
if (currentVersion) {
const compConfig = {
compilers: {
solc: {
version: `${currentVersion.substring(0, currentVersion.indexOf('+commit'))}`,
settings: {
optimizer: {
enabled: optimize,
runs: runs
},
evmVersion: evmVersion
}
}
}
}
this.api.compileWithTruffle(fileName, compConfig).then((result) => {
this.api.logToTerminal({ type: 'info', value: result }) this.api.logToTerminal({ type: 'info', value: result })
}).catch((error) => { }).catch((error) => {
this.api.logToTerminal({ type: 'error', value: error }) this.api.logToTerminal({ type: 'error', value: error })
}) })
}
} }
// TODO readd saving current file // TODO readd saving current file
this.api.saveCurrentFile() this.api.saveCurrentFile()

@ -1,10 +1,6 @@
import * as WS from 'ws' // eslint-disable-line import * as WS from 'ws' // eslint-disable-line
import { PluginClient } from '@remixproject/plugin' import { PluginClient } from '@remixproject/plugin'
import Schema from "@truffle/contract-schema" const { spawn } = require('child_process') // eslint-disable-line
// import Config from '@truffle/config'
const Config = require("@truffle/config")
import { Compile } from "@truffle/compile-solidity"
import { Shims } from "@truffle/compile-common"
export class TruffleClient extends PluginClient { export class TruffleClient extends PluginClient {
methods: Array<string> methods: Array<string>
@ -24,36 +20,31 @@ export class TruffleClient extends PluginClient {
this.currentSharedFolder = currentSharedFolder this.currentSharedFolder = currentSharedFolder
} }
async compile (fileName: string, CompConfig) { compile () {
if (this.readOnly) { return new Promise((resolve, reject) => {
const errMsg = '[Truffle Compilation]: Cannot compile in read-only mode' if (this.readOnly) {
return new Error(errMsg) const errMsg = '[Truffle Compilation]: Cannot compile in read-only mode'
} return reject(new Error(errMsg))
console.log('fileName-in compileWithTruffle-->', fileName) }
console.log('config-in compileWithTruffle-->', CompConfig) const cmd = `truffle compile`
const options = { cwd: this.currentSharedFolder, shell: true }
const sources = { const child = spawn(cmd, options)
Example: await this.call('fileManager', 'getFile', fileName) let result = ''
} let error = ''
let config = Config.default().with(CompConfig) child.stdout.on('data', (data) => {
console.log('config---->', config) console.log('data in truffle-->', data)
console.log('sources---->', sources) const msg = `[Truffle Compilation]: ${data.toString()}`
// Compile first console.log('\x1b[32m%s\x1b[0m', msg)
const { compilations } = await Compile.sources({ result += msg + '\n'
sources, })
options: config child.stderr.on('data', (err) => {
}); error += `[Truffle Compilation]: ${err.toString()} \n`
console.log('compilations----->', compilations) })
const { contracts } = compilations[0]; child.on('close', () => {
// use forEach if (error && result) resolve(error + result)
const exampleContract = contracts.find( else if (error) reject(error)
contract => contract.contractName === "Owner" else resolve(result)
); })
const compiled = Schema.normalize( })
Shims.NewToLegacy.forContract(exampleContract)
);
if(!compiled.updatedAt) compiled.updatedAt = new Date().toISOString()
console.log('compiled----->', compiled)
return "done"
} }
} }

1231
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -159,8 +159,6 @@
"@remixproject/plugin-utils": "^0.3.28", "@remixproject/plugin-utils": "^0.3.28",
"@remixproject/plugin-webview": "^0.3.28", "@remixproject/plugin-webview": "^0.3.28",
"@remixproject/plugin-ws": "^0.3.28", "@remixproject/plugin-ws": "^0.3.28",
"@truffle/compile-solidity": "^6.0.17",
"@truffle/contract-schema": "^3.4.6",
"ansi-gray": "^0.1.1", "ansi-gray": "^0.1.1",
"async": "^2.6.2", "async": "^2.6.2",
"axios": ">=0.26.0", "axios": ">=0.26.0",

Loading…
Cancel
Save