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. 127
      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) {
if(isElectron()) {
if (isElectron()) {
await this.call('isogit', 'init', {
defaultBranch: (input && input.branch) || 'main'
})
@ -314,6 +314,11 @@ class DGitProvider extends Plugin {
}
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({
...await this.getGitConfig(),
...cmd
@ -339,10 +344,18 @@ class DGitProvider extends Plugin {
}
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 })
}
async delremote(input) {
if (isElectron()) {
await this.call('isogit', 'delremote', { remote: input.remote })
return
}
await git.deleteRemote({ ...await this.getGitConfig(), remote: input.remote })
}
@ -351,27 +364,45 @@ class DGitProvider extends Plugin {
}
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 (!workspaceExists) {
setTimeout(async () => {
await this.call('fileManager', 'refresh')
}, 1000)
if (isElectron()) {
const folder = await this.call('isogit', 'openFolder')
if (!folder) return false
console.log('folder', folder)
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) {
@ -384,17 +415,22 @@ class DGitProvider extends Plugin {
name: input.name,
email: input.email
},
...await this.parseInput(input),
input
}
if (isElectron()) {
return await this.call('isogit', 'push', cmd)
}
} else {
return await git.push({
...await this.getGitConfig(),
...cmd
})
cmd = {
...cmd,
...await this.parseInput(input),
}
return await git.push({
...await this.getGitConfig(),
...cmd
})
}
}
async pull(input) {
@ -406,14 +442,17 @@ class DGitProvider extends Plugin {
email: input.email
},
remote: input.remote,
...await this.parseInput(input),
input
}
let result
if (isElectron()) {
result = await this.call('isogit', 'pull', cmd)
}
else {
cmd = {
...cmd,
...await this.parseInput(input),
}
result = await git.pull({
...await this.getGitConfig(),
...cmd
@ -434,12 +473,16 @@ class DGitProvider extends Plugin {
email: input.email
},
remote: input.remote,
...await this.parseInput(input),
input
}
let result
if (isElectron()) {
result = await this.call('isogit', 'fetch', cmd)
} else {
cmd = {
...cmd,
...await this.parseInput(input),
}
result = await git.fetch({
...await this.getGitConfig(),
...cmd

@ -16,7 +16,7 @@ export class fsPlugin extends ElectronPlugin {
name: '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
// 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();
if(dir){
mainWindow.setTitle(dir)
}
// on close
mainWindow.on('close', (event) => {
console.log('close', event, mainWindow.webContents.id)
@ -106,125 +110,4 @@ EditMenu(commandKeys, execCommand),
WindowMenu(commandKeys, execCommand, [])
]
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)
})
*/
Menu.setApplicationMenu(Menu.buildFromTemplate(menu))

@ -72,7 +72,7 @@ const clientProfile: Profile = {
name: 'fs',
displayName: '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 {
@ -292,5 +292,9 @@ class FSPluginClient extends ElectronBasePluginClient {
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']
}
// TODO: implement all native OS git commands
class GitPluginClient extends ElectronBasePluginClient {
constructor(webContentsId: number, profile: Profile) {
@ -31,10 +32,5 @@ class GitPluginClient extends ElectronBasePluginClient {
console.log('GitPluginClient onload')
})
}
async log(cmd: any): Promise<any> {
}
}

@ -3,6 +3,8 @@ import { Profile } from "@remixproject/plugin-utils";
import { ElectronBasePlugin, ElectronBasePluginClient } from "@remixproject/plugin-electron"
import fs from 'fs/promises'
import git from 'isomorphic-git'
import { dialog } from "electron";
import http from 'isomorphic-git/http/web'
const profile: Profile = {
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 = {
name: 'isogit',
displayName: 'isogit',
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 {
@ -159,32 +176,79 @@ class IsoGitPluginClient extends ElectronBasePluginClient {
console.log('push')
const push = await git.push({
...await this.getGitConfig(),
...cmd
...cmd,
...parseInput(cmd.input)
})
console.log('PUSH', push)
return push
}
async pull (cmd: any) {
console.log('pull')
console.log('pull', cmd)
const pull = await git.pull({
...await this.getGitConfig(),
...cmd
...cmd,
...parseInput(cmd.input)
})
console.log('PULL', pull)
return pull
}
async fetch(cmd: any) {
console.log('fetch')
console.log('fetch', cmd)
const fetch = await git.fetch({
...await this.getGitConfig(),
...cmd
...cmd,
...parseInput(cmd.input)
})
console.log('FETCH', 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 () => {

@ -35,7 +35,7 @@ export const ElectronMenu = () => {
<div onClick={async()=>{await openFolderElectron(null)}} className='btn btn-primary'><FormattedMessage id="electron.openFolder" /></div>
{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" />
</label>
<ul>

Loading…
Cancel
Save