truffle compile child process

pull/2265/head
Aniket-Engg 3 years ago committed by yann300
parent d91701b136
commit 032b490fdc
  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)
}
async compileWithTruffle (fileName, compConfig) {
console.log('Inside compileWithTruffle in compile-api', compConfig)
return await this.call('truffle', 'compile', fileName, compConfig)
compileWithTruffle () {
return this.call('truffle', 'compile')
}
// async compileWithTruffle (fileName, CompConfig) {
// }
logToTerminal (content) {
return this.call('terminal', 'log', content)
}

@ -41,7 +41,7 @@ export interface ICompilerApi {
logToTerminal: (log: terminalLog) => void
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,
emit?: (key: string, ...payload: any) => void
}

@ -141,29 +141,11 @@ export class CompileTabLogic {
})
}
} else if (externalCompType === 'truffle') {
const fileName = this.api.currentFile
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.compileWithTruffle().then((result) => {
this.api.logToTerminal({ type: 'info', value: result })
}).catch((error) => {
this.api.logToTerminal({ type: 'error', value: error })
})
}
}
// TODO readd saving current file
this.api.saveCurrentFile()

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

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-webview": "^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",
"async": "^2.6.2",
"axios": ">=0.26.0",

Loading…
Cancel
Save