some git functions

rdesktop^2
filip mertens 1 year ago
parent 7dac9f1731
commit cdf0ca95c2
  1. 103
      apps/remix-ide/src/app/files/dgitProvider.js
  2. 2
      apps/remix-ide/src/app/plugins/fsPlugin.ts
  3. 125
      apps/remixdesktop/src/main.ts
  4. 6
      apps/remixdesktop/src/plugins/fsPlugin.ts
  5. 6
      apps/remixdesktop/src/plugins/gitPlugin.ts
  6. 76
      apps/remixdesktop/src/plugins/isoGitPlugin.ts
  7. 2
      libs/remix-ui/workspace/src/lib/components/electron-menu.tsx

@ -85,7 +85,7 @@ class DGitProvider extends Plugin {
} }
async init(input) { async init(input) {
if(isElectron()) { if (isElectron()) {
await this.call('isogit', 'init', { await this.call('isogit', 'init', {
defaultBranch: (input && input.branch) || 'main' defaultBranch: (input && input.branch) || 'main'
}) })
@ -314,6 +314,11 @@ class DGitProvider extends Plugin {
} }
async readblob(cmd) { async readblob(cmd) {
console.log('readblob', cmd)
if (isElectron()) {
const readBlobResult = await this.call('isogit', 'readblob', cmd)
console.log('readblob', readBlobResult)
}
const readBlobResult = await git.readBlob({ const readBlobResult = await git.readBlob({
...await this.getGitConfig(), ...await this.getGitConfig(),
...cmd ...cmd
@ -339,10 +344,18 @@ class DGitProvider extends Plugin {
} }
async addremote(input) { async addremote(input) {
if (isElectron()) {
await this.call('isogit', 'addremote', { url: input.url, remote: input.remote })
return
}
await git.addRemote({ ...await this.getGitConfig(), url: input.url, remote: input.remote }) await git.addRemote({ ...await this.getGitConfig(), url: input.url, remote: input.remote })
} }
async delremote(input) { async delremote(input) {
if (isElectron()) {
await this.call('isogit', 'delremote', { remote: input.remote })
return
}
await git.deleteRemote({ ...await this.getGitConfig(), remote: input.remote }) await git.deleteRemote({ ...await this.getGitConfig(), remote: input.remote })
} }
@ -351,27 +364,45 @@ class DGitProvider extends Plugin {
} }
async clone(input, workspaceName, workspaceExists = false) { async clone(input, workspaceName, workspaceExists = false) {
const permission = await this.askUserPermission('clone', 'Import multiple files into your workspaces.')
if (!permission) return false
if (this.calculateLocalStorage() > 10000) throw new Error('The local storage of the browser is full.')
if (!workspaceExists) await this.call('filePanel', 'createWorkspace', workspaceName || `workspace_${Date.now()}`, true)
const cmd = {
url: input.url,
singleBranch: input.singleBranch,
ref: input.branch,
depth: input.depth || 10,
...await this.parseInput(input),
...await this.getGitConfig()
}
const result = await git.clone(cmd) if (isElectron()) {
if (!workspaceExists) { const folder = await this.call('isogit', 'openFolder')
setTimeout(async () => { if (!folder) return false
await this.call('fileManager', 'refresh') console.log('folder', folder)
}, 1000) const cmd = {
url: input.url,
singleBranch: input.singleBranch,
ref: input.branch,
depth: input.depth || 10,
dir: folder,
input
}
const result = await this.call('isogit', 'clone', cmd)
await this.call('fs', 'openWindow', folder)
} else {
const permission = await this.askUserPermission('clone', 'Import multiple files into your workspaces.')
if (!permission) return false
if (this.calculateLocalStorage() > 10000) throw new Error('The local storage of the browser is full.')
if (!workspaceExists) await this.call('filePanel', 'createWorkspace', workspaceName || `workspace_${Date.now()}`, true)
const cmd = {
url: input.url,
singleBranch: input.singleBranch,
ref: input.branch,
depth: input.depth || 10,
...await this.parseInput(input),
...await this.getGitConfig()
}
const result = await git.clone(cmd)
if (!workspaceExists) {
setTimeout(async () => {
await this.call('fileManager', 'refresh')
}, 1000)
}
this.emit('clone')
return result
} }
this.emit('clone')
return result
} }
async push(input) { async push(input) {
@ -384,17 +415,22 @@ class DGitProvider extends Plugin {
name: input.name, name: input.name,
email: input.email email: input.email
}, },
...await this.parseInput(input), input
} }
if (isElectron()) { if (isElectron()) {
return await this.call('isogit', 'push', cmd) return await this.call('isogit', 'push', cmd)
} } else {
return await git.push({ cmd = {
...await this.getGitConfig(), ...cmd,
...cmd ...await this.parseInput(input),
}) }
return await git.push({
...await this.getGitConfig(),
...cmd
})
}
} }
async pull(input) { async pull(input) {
@ -406,14 +442,17 @@ class DGitProvider extends Plugin {
email: input.email email: input.email
}, },
remote: input.remote, remote: input.remote,
...await this.parseInput(input), input
} }
let result let result
if (isElectron()) { if (isElectron()) {
result = await this.call('isogit', 'pull', cmd) result = await this.call('isogit', 'pull', cmd)
} }
else { else {
cmd = {
...cmd,
...await this.parseInput(input),
}
result = await git.pull({ result = await git.pull({
...await this.getGitConfig(), ...await this.getGitConfig(),
...cmd ...cmd
@ -434,12 +473,16 @@ class DGitProvider extends Plugin {
email: input.email email: input.email
}, },
remote: input.remote, remote: input.remote,
...await this.parseInput(input), input
} }
let result let result
if (isElectron()) { if (isElectron()) {
result = await this.call('isogit', 'fetch', cmd) result = await this.call('isogit', 'fetch', cmd)
} else { } else {
cmd = {
...cmd,
...await this.parseInput(input),
}
result = await git.fetch({ result = await git.fetch({
...await this.getGitConfig(), ...await this.getGitConfig(),
...cmd ...cmd

@ -16,7 +16,7 @@ export class fsPlugin extends ElectronPlugin {
name: 'fs', name: 'fs',
description: 'fs', description: 'fs',
}) })
this.methods = ['readdir', 'readFile', 'writeFile', 'mkdir', 'rmdir', 'unlink', 'rename', 'stat', 'lstat', 'exists', 'setWorkingDir', 'getRecentFolders', 'glob'] this.methods = ['readdir', 'readFile', 'writeFile', 'mkdir', 'rmdir', 'unlink', 'rename', 'stat', 'lstat', 'exists', 'setWorkingDir', 'getRecentFolders', 'glob', 'openWindow']
// List of commands all filesystems are expected to provide. `rm` is not // List of commands all filesystems are expected to provide. `rm` is not
// included since it may not exist and must be handled as a special case // included since it may not exist and must be handled as a special case

@ -35,6 +35,10 @@ export const createWindow = async (dir?: string): Promise<void> => {
mainWindow.maximize(); mainWindow.maximize();
if(dir){
mainWindow.setTitle(dir)
}
// on close // on close
mainWindow.on('close', (event) => { mainWindow.on('close', (event) => {
console.log('close', event, mainWindow.webContents.id) console.log('close', event, mainWindow.webContents.id)
@ -107,124 +111,3 @@ WindowMenu(commandKeys, execCommand, [])
] ]
Menu.setApplicationMenu(Menu.buildFromTemplate(menu)) Menu.setApplicationMenu(Menu.buildFromTemplate(menu))
import { glob, globSync, globStream, globStreamSync, Glob, GlobOptions } from 'glob'
import { PathScurry, Path } from 'path-scurry'
async function getDirectory(path: string, options?: GlobOptions): Promise<string[] | Path[]> {
return await glob(path + '/**/*.sol', {
withFileTypes: true,
...options
})
}
function doGlobTest() {
let startglob = new Date().getTime()
console.log('start', startglob)
getDirectory('/Volumes/bunsen/code/rmproject2/remix-project/apps/remix-ide/contracts').then((files) => {
const result: any[] = []
for (const file of files) {
result.push({
path: (file as Path).path,
name: (file as Path).name,
isDirectory: (file as Path).isDirectory(),
})
}
console.log(result)
const end = new Date().getTime()
console.log('end glob', end - startglob)
})
}
import fs, { Dirent } from 'fs'
async function readdir(path: string): Promise<Dirent[]> {
// call node fs.readdir
//console.log('readdir', path)
if (!path) return []
const files = fs.readdirSync(path, {
withFileTypes: true
})
return files
}
function doReadDirTest() {
let startreaddir = new Date().getTime()
console.log('start', startreaddir)
readdir('/Volumes/bunsen/code/rmproject2/remix-project/node_modules/').then((files) => {
const result: any[] = []
for (const file of files) {
try {
result.push({
path: file.name,
isDirectory: file.isDirectory(),
})
} catch (e) {
console.log('error', e)
}
}
console.log(result)
const end = new Date().getTime()
console.log('end readdir', end - startreaddir)
})
}
function getFileList(dirName: string) {
let files: any[] = [];
const items = fs.readdirSync(dirName, { withFileTypes: true });
for (const item of items) {
if (item.isDirectory()) {
files = [...files, ...getFileList(`${dirName}/${item.name}`)];
} else {
files.push(`${dirName}/${item.name}`);
}
}
return files;
};
function doFileListTest() {
let startgetfilelist = new Date().getTime()
console.log('start', startgetfilelist)
const r = getFileList('/Volumes/bunsen/code/rmproject2/remix-project/node_modules/')
console.log(r.length)
const end = new Date().getTime()
console.log('end getfilelist', end - startgetfilelist)
}
//doFileListTest()
doGlobTest()
//doReadDirTest()
/*
async function testScury() {
const result: any[] = []
const pw = new PathScurry('/Volumes/bunsen/code/rmproject2/remix-project/node_modules')
for await (const entry of pw) {
result.push({
path: entry.path,
isDirectory: entry.isDirectory(),
})
}
return result
}
// log time
let startscurry = new Date().getTime()
console.log('start', startscurry)
testScury().then((res) => {
console.log(res.length)
const end = new Date().getTime()
console.log('end scurry', end - startscurry)
})
*/

@ -72,7 +72,7 @@ const clientProfile: Profile = {
name: 'fs', name: 'fs',
displayName: 'fs', displayName: 'fs',
description: 'fs', description: 'fs',
methods: ['readdir', 'readFile', 'writeFile', 'mkdir', 'rmdir', 'unlink', 'rename', 'stat', 'lstat', 'exists', 'currentPath', 'watch', 'closeWatch', 'setWorkingDir', 'openFolder', 'getRecentFolders', 'glob'] methods: ['readdir', 'readFile', 'writeFile', 'mkdir', 'rmdir', 'unlink', 'rename', 'stat', 'lstat', 'exists', 'currentPath', 'watch', 'closeWatch', 'setWorkingDir', 'openFolder', 'getRecentFolders', 'glob', 'openWindow']
} }
class FSPluginClient extends ElectronBasePluginClient { class FSPluginClient extends ElectronBasePluginClient {
@ -292,5 +292,9 @@ class FSPluginClient extends ElectronBasePluginClient {
return path return path
} }
openWindow(path: string): void {
createWindow(path)
}
} }

@ -23,6 +23,7 @@ const clientProfile: Profile = {
methods: ['log', 'status', 'add', 'commit', 'push', 'pull', 'clone', 'checkout', 'branch', 'merge', 'reset', 'revert', 'diff', 'stash', 'apply', 'cherryPick', 'rebase', 'tag', 'fetch', 'remote', 'config', 'show', 'init', 'help', 'version'] methods: ['log', 'status', 'add', 'commit', 'push', 'pull', 'clone', 'checkout', 'branch', 'merge', 'reset', 'revert', 'diff', 'stash', 'apply', 'cherryPick', 'rebase', 'tag', 'fetch', 'remote', 'config', 'show', 'init', 'help', 'version']
} }
// TODO: implement all native OS git commands
class GitPluginClient extends ElectronBasePluginClient { class GitPluginClient extends ElectronBasePluginClient {
constructor(webContentsId: number, profile: Profile) { constructor(webContentsId: number, profile: Profile) {
@ -32,9 +33,4 @@ class GitPluginClient extends ElectronBasePluginClient {
}) })
} }
async log(cmd: any): Promise<any> {
}
} }

@ -3,6 +3,8 @@ import { Profile } from "@remixproject/plugin-utils";
import { ElectronBasePlugin, ElectronBasePluginClient } from "@remixproject/plugin-electron" import { ElectronBasePlugin, ElectronBasePluginClient } from "@remixproject/plugin-electron"
import fs from 'fs/promises' import fs from 'fs/promises'
import git from 'isomorphic-git' import git from 'isomorphic-git'
import { dialog } from "electron";
import http from 'isomorphic-git/http/web'
const profile: Profile = { const profile: Profile = {
name: 'isogit', name: 'isogit',
@ -17,11 +19,26 @@ export class IsoGitPlugin extends ElectronBasePlugin {
} }
} }
const parseInput = (input: any)=> {
return {
corsProxy: 'https://corsproxy.remixproject.org/',
http,
onAuth: (url: any) => {
url
const auth = {
username: input.token,
password: ''
}
return auth
}
}
}
const clientProfile: Profile = { const clientProfile: Profile = {
name: 'isogit', name: 'isogit',
displayName: 'isogit', displayName: 'isogit',
description: 'isogit plugin', description: 'isogit plugin',
methods: ['init', 'localStorageUsed', 'addremote', 'delremote', 'remotes', 'fetch', 'clone', 'export', 'import', 'status', 'log', 'commit', 'add', 'remove', 'rm', 'lsfiles', 'readblob', 'resolveref', 'branches', 'branch', 'checkout', 'currentbranch', 'push', 'pin', 'pull', 'pinList', 'unPin', 'setIpfsConfig', 'zip', 'setItem', 'getItem'] methods: ['init', 'localStorageUsed', 'addremote', 'delremote', 'remotes', 'fetch', 'clone', 'export', 'import', 'status', 'log', 'commit', 'add', 'remove', 'rm', 'lsfiles', 'readblob', 'resolveref', 'branches', 'branch', 'checkout', 'currentbranch', 'push', 'pin', 'pull', 'pinList', 'unPin', 'setIpfsConfig', 'zip', 'setItem', 'getItem', 'openFolder']
} }
class IsoGitPluginClient extends ElectronBasePluginClient { class IsoGitPluginClient extends ElectronBasePluginClient {
@ -159,32 +176,79 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
console.log('push') console.log('push')
const push = await git.push({ const push = await git.push({
...await this.getGitConfig(), ...await this.getGitConfig(),
...cmd ...cmd,
...parseInput(cmd.input)
}) })
console.log('PUSH', push) console.log('PUSH', push)
return push return push
} }
async pull (cmd: any) { async pull (cmd: any) {
console.log('pull') console.log('pull', cmd)
const pull = await git.pull({ const pull = await git.pull({
...await this.getGitConfig(), ...await this.getGitConfig(),
...cmd ...cmd,
...parseInput(cmd.input)
}) })
console.log('PULL', pull) console.log('PULL', pull)
return pull return pull
} }
async fetch(cmd: any) { async fetch(cmd: any) {
console.log('fetch') console.log('fetch', cmd)
const fetch = await git.fetch({ const fetch = await git.fetch({
...await this.getGitConfig(), ...await this.getGitConfig(),
...cmd ...cmd,
...parseInput(cmd.input)
}) })
console.log('FETCH', fetch) console.log('FETCH', fetch)
return fetch return fetch
} }
async clone(cmd: any) {
console.log('clone')
const clone = await git.clone({
...await this.getGitConfig(),
...cmd,
...parseInput(cmd.input),
dir: cmd.dir || this.workingDir
})
console.log('CLONE', clone)
return clone
}
async openFolder(path?: string): Promise<string> {
let dirs: string[] | undefined
if (!path) {
dirs = dialog.showOpenDialogSync(this.window, {
properties: ['openDirectory', 'createDirectory', "showHiddenFiles"]
})
}
path = dirs && dirs.length && dirs[0] ? dirs[0] : path
if (!path) return ''
return path
}
async addremote(cmd: any) {
console.log('addremote')
const addremote = await git.addRemote({
...await this.getGitConfig(),
...cmd
})
console.log('ADDREMOTE', addremote)
return addremote
}
async delremote(cmd: any) {
console.log('delremote')
const delremote = await git.deleteRemote({
...await this.getGitConfig(),
...cmd
})
console.log('DELREMOTE', delremote)
return delremote
}
remotes = async () => { remotes = async () => {

@ -35,7 +35,7 @@ export const ElectronMenu = () => {
<div onClick={async()=>{await openFolderElectron(null)}} className='btn btn-primary'><FormattedMessage id="electron.openFolder" /></div> <div onClick={async()=>{await openFolderElectron(null)}} className='btn btn-primary'><FormattedMessage id="electron.openFolder" /></div>
{global.fs.browser.recentFolders.length > 0 ? {global.fs.browser.recentFolders.length > 0 ?
<> <>
<label className="py-2 pt-3 align-self-center m-0" style={{ fontSize: "1.2rem" }}> <label className="py-2 pt-3 align-self-center m-0">
<FormattedMessage id="electron.recentFolders" /> <FormattedMessage id="electron.recentFolders" />
</label> </label>
<ul> <ul>

Loading…
Cancel
Save