extra checks

pull/3285/head
filip mertens 2 years ago
parent 3c13087cb3
commit 21c1bcc752
  1. 36
      libs/remixd/src/services/foundryClient.ts
  2. 9
      libs/remixd/src/services/hardhatClient.ts
  3. 15
      libs/remixd/src/services/truffleClient.ts

@ -15,12 +15,12 @@ export class FoundryClient extends PluginClient {
buildPath: string
cachePath: string
constructor (private readOnly = false) {
constructor(private readOnly = false) {
super()
this.methods = ['compile', 'sync']
}
setWebSocket (websocket: WS): void {
setWebSocket(websocket: WS): void {
this.websocket = websocket
this.websocket.addEventListener('close', () => {
this.warnlog = false
@ -28,7 +28,7 @@ export class FoundryClient extends PluginClient {
})
}
sharedFolder (currentSharedFolder: string): void {
sharedFolder(currentSharedFolder: string): void {
this.currentSharedFolder = currentSharedFolder
this.buildPath = utils.absolutePath('out', this.currentSharedFolder)
this.cachePath = utils.absolutePath('cache', this.currentSharedFolder)
@ -55,7 +55,7 @@ export class FoundryClient extends PluginClient {
}
}
compile (configPath: string) {
compile(configPath: string) {
return new Promise((resolve, reject) => {
if (this.readOnly) {
const errMsg = '[Foundry Compilation]: Cannot compile in read-only mode'
@ -82,12 +82,12 @@ export class FoundryClient extends PluginClient {
})
}
private async processArtifact () {
private async processArtifact() {
const folderFiles = await fs.readdir(this.buildPath) // "out" folder
if (!fs.existsSync(join(this.cachePath, 'solidity-files-cache.json'))) return
try {
const cache = JSON.parse(await fs.readFile(join(this.cachePath, 'solidity-files-cache.json'), { encoding: 'utf-8' }))
// name of folders are file names
for (const file of folderFiles) {
const path = join(this.buildPath, file) // out/Counter.sol/
@ -113,7 +113,7 @@ export class FoundryClient extends PluginClient {
}
}
listenOnFoundryCompilation () {
listenOnFoundryCompilation() {
try {
this.watcher = chokidar.watch(this.cachePath, { depth: 0, ignorePermissionErrors: true, ignoreInitial: true })
@ -126,7 +126,7 @@ export class FoundryClient extends PluginClient {
}
}
async readContract (contractFolder, compilationResultPart, cache) {
async readContract(contractFolder, compilationResultPart, cache) {
const files = await fs.readdir(contractFolder)
for (const file of files) {
@ -136,7 +136,7 @@ export class FoundryClient extends PluginClient {
}
}
async feedContractArtifactFile (path, content, compilationResultPart, cache) {
async feedContractArtifactFile(path, content, compilationResultPart, cache) {
const contentJSON = JSON.parse(content)
const contractName = basename(path).replace('.json', '')
@ -188,10 +188,20 @@ export class FoundryClient extends PluginClient {
}
}
async sync () {
async sync() {
console.log('syncing from Foundry')
this.processArtifact()
// @ts-ignore
this.call('terminal', 'log', { type: 'log', value: 'synced with Foundry' })
if (fs.existsSync(this.buildPath) && fs.existsSync(this.cachePath)) {
if (!fs.existsSync(join(this.cachePath, 'solidity-files-cache.json'))) {
console.log('No compilation data found')
// @ts-ignore
this.call('terminal', 'log', { type: 'log', value: 'No compilation data found' })
} else{
this.processArtifact()
// @ts-ignore
this.call('terminal', 'log', { type: 'log', value: 'synced with Foundry' })
}
} else {
this.listenOFoundryFolder()
}
}
}

@ -151,7 +151,14 @@ export class HardhatClient extends PluginClient {
async sync() {
console.log('syncing from Hardhat')
this.processArtifact()
if(fs.existsSync(this.buildPath)) {
this.processArtifact()
}else{
console.log('No compilation result found')
this.listenOnHardHatFolder()
// ts-ignore
this.call('terminal', 'log', { type: 'log', value: 'No compilation result found' })
}
}
async feedContractArtifactFile(artifactContent, compilationResultPart) {

@ -157,9 +157,16 @@ export class TruffleClient extends PluginClient {
}
async sync () {
console.log('syncing from Truffle')
this.processArtifact()
// @ts-ignore
this.call('terminal', 'log', { type: 'log', value: 'synced with Truffle' })
if (fs.existsSync(this.buildPath)) {
console.log('syncing from Truffle')
this.processArtifact()
// @ts-ignore
this.call('terminal', 'log', { type: 'log', value: 'synced with Truffle' })
}else{
console.log('Truffle build folder doesn\'t exist... waiting for the first compilation.')
this.listenOnTruffleFolder()
// @ts-ignore
this.call('terminal', 'log', { type: 'log', value: 'Truffle build folder doesn\'t exist... waiting for the first compilation.' })
}
}
}

Loading…
Cancel
Save