truffle integration

pull/2265/head
aniket-engg 3 years ago committed by yann300
parent ffd6ac95a0
commit 099b4a0053
  1. 9
      libs/remixd/src/bin/remixd.ts
  2. 2
      libs/remixd/src/index.ts
  3. 1
      libs/remixd/src/serviceList.ts
  4. 31
      libs/remixd/src/services/truffleClient.ts
  5. 3
      libs/remixd/src/websocket.ts

@ -25,6 +25,7 @@ async function warnLatestVersion () {
const services = { const services = {
git: (readOnly: boolean) => new servicesList.GitClient(readOnly), git: (readOnly: boolean) => new servicesList.GitClient(readOnly),
hardhat: (readOnly: boolean) => new servicesList.HardhatClient(readOnly), hardhat: (readOnly: boolean) => new servicesList.HardhatClient(readOnly),
truffle: (readOnly: boolean) => new servicesList.TruffleClient(readOnly),
slither: (readOnly: boolean) => new servicesList.SlitherClient(readOnly), slither: (readOnly: boolean) => new servicesList.SlitherClient(readOnly),
folder: (readOnly: boolean) => new servicesList.Sharedfolder(readOnly) folder: (readOnly: boolean) => new servicesList.Sharedfolder(readOnly)
} }
@ -34,11 +35,12 @@ const ports = {
git: 65521, git: 65521,
hardhat: 65522, hardhat: 65522,
slither: 65523, slither: 65523,
truffle: 65524,
folder: 65520 folder: 65520
} }
const killCallBack: Array<any> = [] // any is function const killCallBack: Array<any> = [] // any is function
function startService<S extends 'git' | 'hardhat' | 'slither' | 'folder'> (service: S, callback: (ws: WS, sharedFolderClient: servicesList.Sharedfolder, error?:Error) => void) { function startService<S extends 'git' | 'hardhat' | 'truffle' | 'slither' | 'folder'> (service: S, callback: (ws: WS, sharedFolderClient: servicesList.Sharedfolder, error?:Error) => void) {
const socket = new WebSocket(ports[service], { remixIdeUrl: program.remixIde }, () => services[service](program.readOnly || false)) const socket = new WebSocket(ports[service], { remixIdeUrl: program.remixIde }, () => services[service](program.readOnly || false))
socket.start(callback) socket.start(callback)
killCallBack.push(socket.close.bind(socket)) killCallBack.push(socket.close.bind(socket))
@ -100,6 +102,11 @@ function errorHandler (error: any, service: string) {
sharedFolderClient.setWebSocket(ws) sharedFolderClient.setWebSocket(ws)
sharedFolderClient.sharedFolder(program.sharedFolder) sharedFolderClient.sharedFolder(program.sharedFolder)
}) })
startService('truffle', (ws: WS, sharedFolderClient: servicesList.Sharedfolder) => {
sharedFolderClient.setWebSocket(ws)
sharedFolderClient.sharedFolder(program.sharedFolder)
})
// Run hardhat service if a hardhat project is shared as folder // Run hardhat service if a hardhat project is shared as folder
const hardhatConfigFilePath = absolutePath('./', program.sharedFolder) const hardhatConfigFilePath = absolutePath('./', program.sharedFolder)
const isHardhatProject = existsSync(hardhatConfigFilePath + '/hardhat.config.js') || existsSync(hardhatConfigFilePath + '/hardhat.config.ts') const isHardhatProject = existsSync(hardhatConfigFilePath + '/hardhat.config.js') || existsSync(hardhatConfigFilePath + '/hardhat.config.ts')

@ -2,6 +2,7 @@
import { RemixdClient as sharedFolder } from './services/remixdClient' import { RemixdClient as sharedFolder } from './services/remixdClient'
import { GitClient } from './services/gitClient' import { GitClient } from './services/gitClient'
import { HardhatClient } from './services/hardhatClient' import { HardhatClient } from './services/hardhatClient'
import { TruffleClient } from './services/truffleClient'
import { SlitherClient } from './services/slitherClient' import { SlitherClient } from './services/slitherClient'
import Websocket from './websocket' import Websocket from './websocket'
import * as utils from './utils' import * as utils from './utils'
@ -13,6 +14,7 @@ module.exports = {
sharedFolder, sharedFolder,
GitClient, GitClient,
HardhatClient, HardhatClient,
TruffleClient,
SlitherClient SlitherClient
} }
} }

@ -1,4 +1,5 @@
export { RemixdClient as Sharedfolder } from './services/remixdClient' export { RemixdClient as Sharedfolder } from './services/remixdClient'
export { GitClient } from './services/gitClient' export { GitClient } from './services/gitClient'
export { HardhatClient } from './services/hardhatClient' export { HardhatClient } from './services/hardhatClient'
export { TruffleClient } from './services/truffleClient'
export { SlitherClient } from './services/slitherClient' export { SlitherClient } from './services/slitherClient'

@ -0,0 +1,31 @@
import * as WS from 'ws' // eslint-disable-line
import { PluginClient } from '@remixproject/plugin'
const { spawn } = require('child_process') // eslint-disable-line
export class TruffleClient extends PluginClient {
methods: Array<string>
websocket: WS
currentSharedFolder: string
constructor (private readOnly = false) {
super()
this.methods = ['compile']
}
setWebSocket (websocket: WS): void {
this.websocket = websocket
}
sharedFolder (currentSharedFolder: string): void {
this.currentSharedFolder = currentSharedFolder
}
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))
}
})
}
}

@ -20,7 +20,8 @@ export default class WebSocket {
65520: 'remixd', 65520: 'remixd',
65521: 'git', 65521: 'git',
65522: 'hardhat', 65522: 'hardhat',
65523: 'slither' 65523: 'slither',
65524: 'truffle'
} }
this.server.on('error', (error: Error) => { this.server.on('error', (error: Error) => {

Loading…
Cancel
Save