commit
10af8f5c11
@ -0,0 +1,18 @@ |
||||
import { WebsocketPlugin } from '@remixproject/engine-web' |
||||
import * as packageJson from '../../../../../package.json' |
||||
|
||||
const profile = { |
||||
name: 'truffle', |
||||
displayName: 'truffle', |
||||
url: 'ws://127.0.0.1:65524', |
||||
methods: ['compile'], |
||||
description: 'Using Remixd daemon, allow to access truffle API', |
||||
kind: 'other', |
||||
version: packageJson.version |
||||
} |
||||
|
||||
export class TruffleHandle extends WebsocketPlugin { |
||||
constructor () { |
||||
super(profile) |
||||
} |
||||
} |
@ -1,4 +1,5 @@ |
||||
export { RemixdClient as Sharedfolder } from './services/remixdClient' |
||||
export { GitClient } from './services/gitClient' |
||||
export { HardhatClient } from './services/hardhatClient' |
||||
export { TruffleClient } from './services/truffleClient' |
||||
export { SlitherClient } from './services/slitherClient' |
||||
|
@ -0,0 +1,50 @@ |
||||
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 () { |
||||
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) |
||||
}) |
||||
}) |
||||
} |
||||
} |
Loading…
Reference in new issue