From 9006f906a88562dabfe89d938a5aca7a1921494a Mon Sep 17 00:00:00 2001 From: bunsenstraat Date: Tue, 14 Nov 2023 08:19:42 +0300 Subject: [PATCH] compiler loader --- apps/remix-ide/src/app.js | 13 +-- .../plugins/electron/compilerLoaderPlugin.ts | 28 ++++-- apps/remix-ide/webpack.config.js | 5 +- .../src/plugins/compilerLoader.ts | 86 +++++++++++++++---- list.json | 0 5 files changed, 103 insertions(+), 29 deletions(-) create mode 100644 list.json diff --git a/apps/remix-ide/src/app.js b/apps/remix-ide/src/app.js index 75870cef25..cda3fc3ac7 100644 --- a/apps/remix-ide/src/app.js +++ b/apps/remix-ide/src/app.js @@ -55,7 +55,7 @@ import { electronConfig } from './app/plugins/electron/electronConfigPlugin' import { electronTemplates } from './app/plugins/electron/templatesPlugin' import { xtermPlugin } from './app/plugins/electron/xtermPlugin' import { ripgrepPlugin } from './app/plugins/electron/ripgrepPlugin' -import { compilerLoaderPlugin } from './app/plugins/electron/compilerLoaderPlugin' +import { compilerLoaderPlugin, compilerLoaderPluginDesktop } from './app/plugins/electron/compilerLoaderPlugin' import {OpenAIGpt} from './app/plugins/openaigpt' const isElectron = require('is-electron') @@ -366,10 +366,12 @@ class AppComponent { this.engine.register([xterm]) const ripgrep = new ripgrepPlugin() this.engine.register([ripgrep]) - const compilerloader = new compilerLoaderPlugin() - this.engine.register([compilerloader]) + } + const compilerloader = isElectron()? new compilerLoaderPluginDesktop(): new compilerLoaderPlugin() + this.engine.register([compilerloader]) + // LAYOUT & SYSTEM VIEWS const appPanel = new MainPanel() Registry.getInstance().put({api: this.mainview, name: 'mainview'}) @@ -479,7 +481,8 @@ class AppComponent { 'blockchain', 'fetchAndCompile', 'contentImport', - 'gistHandler' + 'gistHandler', + 'compilerloader' ]) await this.appManager.activatePlugin(['settings']) @@ -487,7 +490,7 @@ class AppComponent { await this.appManager.activatePlugin(['solidity-script', 'remix-templates']) if(isElectron()){ - await this.appManager.activatePlugin(['isogit', 'electronconfig', 'electronTemplates', 'xterm', 'ripgrep', 'compilerloader']) + await this.appManager.activatePlugin(['isogit', 'electronconfig', 'electronTemplates', 'xterm', 'ripgrep']) } this.appManager.on( diff --git a/apps/remix-ide/src/app/plugins/electron/compilerLoaderPlugin.ts b/apps/remix-ide/src/app/plugins/electron/compilerLoaderPlugin.ts index 3f53cb20f5..1a788100eb 100644 --- a/apps/remix-ide/src/app/plugins/electron/compilerLoaderPlugin.ts +++ b/apps/remix-ide/src/app/plugins/electron/compilerLoaderPlugin.ts @@ -1,12 +1,28 @@ import { ElectronPlugin } from '@remixproject/engine-electron'; +import { Plugin } from '@remixproject/engine'; -export class compilerLoaderPlugin extends ElectronPlugin { +const profile = { + displayName: 'compilerLoader', + name: 'compilerloader', + description: 'Loads the compiler for offline use', +} + +const methods = ['getBaseUrls'] + +export class compilerLoaderPlugin extends Plugin { constructor() { - super({ - displayName: 'compilerLoader', - name: 'compilerloader', - description: 'Loads the compiler for offline use', - }) + super(profile) + this.methods = methods + } + + async getBaseUrls() { + + } +} + +export class compilerLoaderPluginDesktop extends ElectronPlugin { + constructor() { + super(profile) this.methods = [] } diff --git a/apps/remix-ide/webpack.config.js b/apps/remix-ide/webpack.config.js index a7cade0f2a..fca57f5ce3 100644 --- a/apps/remix-ide/webpack.config.js +++ b/apps/remix-ide/webpack.config.js @@ -16,13 +16,14 @@ const versionData = { const loadLocalSolJson = async () => { //execute apps/remix-ide/ci/downloadsoljson.sh - const child = require('child_process').execSync('bash ' + __dirname + '/ci/downloadsoljson.sh', { encoding: 'utf8', cwd: process.cwd(), shell: true }) + //const child = require('child_process').execSync('bash ' + __dirname + '/ci/downloadsoljson.sh', { encoding: 'utf8', cwd: process.cwd(), shell: true }) // show output - console.log(child) + //console.log(child) } fs.writeFileSync(__dirname + '/src/assets/version.json', JSON.stringify(versionData)) + loadLocalSolJson() const project = fs.readFileSync(__dirname + '/project.json', 'utf8') diff --git a/apps/remixdesktop/src/plugins/compilerLoader.ts b/apps/remixdesktop/src/plugins/compilerLoader.ts index b3edc10b38..0dceed4b5d 100644 --- a/apps/remixdesktop/src/plugins/compilerLoader.ts +++ b/apps/remixdesktop/src/plugins/compilerLoader.ts @@ -1,10 +1,10 @@ -import {Profile} from '@remixproject/plugin-utils' -import {ElectronBasePlugin, ElectronBasePluginClient} from '@remixproject/plugin-electron' +import { Profile } from '@remixproject/plugin-utils' +import { ElectronBasePlugin, ElectronBasePluginClient } from '@remixproject/plugin-electron' import fs from 'fs/promises' import axios from 'axios' import express from 'express' -import {cacheDir} from '../utils/config' +import { cacheDir } from '../utils/config' export const baseURLBin = 'https://binaries.soliditylang.org/bin' export const baseURLWasm = 'https://binaries.soliditylang.org/wasm' @@ -27,7 +27,10 @@ export class CompilerLoaderPlugin extends ElectronBasePlugin { clients: CompilerLoaderPluginClient[] = [] constructor() { super(profile, clientProfile, CompilerLoaderPluginClient) - this.methods = [...super.methods, 'getPort'] + this.methods = [...super.methods, 'getPort']; + (async()=>{ + await getLists() + })() } async getPort(): Promise { @@ -39,7 +42,7 @@ const clientProfile: Profile = { name: 'compilerloader', displayName: 'compilerloader', description: 'Compiler Loader', - methods: ['getPort', 'downloadCompiler', 'listCompilers'], + methods: ['getPort', 'downloadCompiler', 'listCompilers', 'getBaseUrls', 'getLists'], } class CompilerLoaderPluginClient extends ElectronBasePluginClient { @@ -59,16 +62,17 @@ class CompilerLoaderPluginClient extends ElectronBasePluginClient { const fileName = url.split('/').pop() if (fileName) { const filePath = cacheDir + '/compilers/' + fileName - try{ - if (await fs.stat(filePath)) { - return - }} - catch(e){ + try { + if (await fs.stat(filePath)) { + return + } + } + catch (e) { // do nothing } } this.emit('downloadStarted', url) - this.call('terminal' as any, 'logHtml', 'Downloading compiler from ' + url) + this.call('terminal' as any, 'logHtml', 'Downloading compiler from ' + url) const res = await axios.get(url, { responseType: 'arraybuffer', onDownloadProgress(progressEvent) { @@ -82,7 +86,7 @@ class CompilerLoaderPluginClient extends ElectronBasePluginClient { }) const buffer = await res.data const file = Buffer.from(buffer) - + if (fileName) { const filePath = cacheDir + '/compilers/' + fileName await fs.writeFile(filePath, file) @@ -90,10 +94,10 @@ class CompilerLoaderPluginClient extends ElectronBasePluginClient { this.emit('downloadFinished', fileName, url) } } catch (e: any) { - plugin.call('terminal' as any, 'log', { - type: 'error', - value: `Failed to download ${url}: ${e.message}`, - }) + plugin.call('terminal' as any, 'log', { + type: 'error', + value: `Failed to download ${url}: ${e.message}`, + }) } } @@ -102,4 +106,54 @@ class CompilerLoaderPluginClient extends ElectronBasePluginClient { const compilers = await fs.readdir(compilersDir) return compilers } + + async getBaseUrls(){ + + } + + async getLists(){ + + } } + + +const getLists = async()=>{ + + let binData + let wasmData + + try{ + let binRes = await axios.get(baseURLBin + '/list.json') + await fs.writeFile(cacheDir + '/binlist.json', JSON.stringify(binRes.data, null, 2)) + binData = binRes.data + }catch(e) { + } + + try{ + let wasmRes = await axios.get(baseURLWasm + '/list.json') + await fs.writeFile(cacheDir + '/wasmlist.json', JSON.stringify(wasmRes.data, null, 2)) + wasmData = wasmRes.data + }catch(e) { + } + + if(!wasmData){ + try{ + wasmData = JSON.parse(await fs.readFile(cacheDir + '/wasmlist.json', 'utf8')); + }catch(e){ + wasmData = {} + } + } + + if(!binData){ + try{ + binData = JSON.parse(await fs.readFile(cacheDir + '/binlist.json', 'utf8')); + }catch(e){ + binData = {} + } + } + + return { + binData, wasmData + } + +} \ No newline at end of file diff --git a/list.json b/list.json new file mode 100644 index 0000000000..e69de29bb2