|
|
|
@ -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() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|