compiler loader

desktopoffline
bunsenstraat 1 year ago
parent 4e9a8c0c03
commit 9006f906a8
  1. 13
      apps/remix-ide/src/app.js
  2. 28
      apps/remix-ide/src/app/plugins/electron/compilerLoaderPlugin.ts
  3. 5
      apps/remix-ide/webpack.config.js
  4. 86
      apps/remixdesktop/src/plugins/compilerLoader.ts
  5. 0
      list.json

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

@ -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 = []
}

@ -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')

@ -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<number> {
@ -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
}
}
Loading…
Cancel
Save