|
|
|
@ -2,12 +2,18 @@ import React from 'react' |
|
|
|
|
import { bufferToHex, keccakFromString } from 'ethereumjs-util' |
|
|
|
|
import axios, { AxiosResponse } from 'axios' |
|
|
|
|
import { addInputFieldSuccess, cloneRepositoryFailed, cloneRepositoryRequest, cloneRepositorySuccess, createWorkspaceError, createWorkspaceRequest, createWorkspaceSuccess, displayNotification, displayPopUp, fetchWorkspaceDirectoryError, fetchWorkspaceDirectoryRequest, fetchWorkspaceDirectorySuccess, hideNotification, setCurrentWorkspace, setDeleteWorkspace, setMode, setReadOnlyMode, setRenameWorkspace } from './payload' |
|
|
|
|
import { checkSlash, checkSpecialChars } from '@remix-ui/helper' |
|
|
|
|
import { addSlash, checkSlash, checkSpecialChars } from '@remix-ui/helper' |
|
|
|
|
|
|
|
|
|
import { JSONStandardInput, WorkspaceTemplate } from '../types' |
|
|
|
|
import { QueryParams } from '@remix-project/remix-lib' |
|
|
|
|
import * as templateWithContent from '@remix-project/remix-ws-templates' |
|
|
|
|
import { ROOT_PATH } from '../utils/constants' |
|
|
|
|
// eslint-disable-next-line @nrwl/nx/enforce-module-boundaries
|
|
|
|
|
import { IndexedDBStorage } from '../../../../../../apps/remix-ide/src/app/files/filesystems/indexedDB' |
|
|
|
|
|
|
|
|
|
declare global { |
|
|
|
|
interface Window { remixFileSystemCallback: IndexedDBStorage; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const LOCALHOST = ' - connect to localhost - ' |
|
|
|
@ -48,6 +54,25 @@ export const createWorkspace = async (workspaceName: string, workspaceTemplateNa |
|
|
|
|
const promise = createWorkspaceTemplate(workspaceName, workspaceTemplateName) |
|
|
|
|
dispatch(createWorkspaceRequest(promise)) |
|
|
|
|
promise.then(async () => { |
|
|
|
|
if (isGitRepo) { |
|
|
|
|
let branches = [] |
|
|
|
|
let currentBranch = null |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
branches = await getGitRepoBranches(`${plugin.fileProviders.workspace.workspacesPath}/${workspaceName}`) |
|
|
|
|
} catch (e) { |
|
|
|
|
console.error(e) |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
currentBranch = await getGitRepoCurrentBranch(`${plugin.fileProviders.workspace.workspacesPath}/${workspaceName}`) |
|
|
|
|
} catch (e) { |
|
|
|
|
console.error(e) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dispatch(createWorkspaceSuccess({ name: workspaceName, isGitRepo, branches, currentBranch })) |
|
|
|
|
} else { |
|
|
|
|
dispatch(createWorkspaceSuccess({ name: workspaceName, isGitRepo })) |
|
|
|
|
} |
|
|
|
|
dispatch(createWorkspaceSuccess({ name: workspaceName, isGitRepo })) |
|
|
|
|
await plugin.setWorkspace({ name: workspaceName, isLocalhost: false }) |
|
|
|
|
await plugin.setWorkspaces(await getWorkspaces()) |
|
|
|
@ -263,7 +288,7 @@ export const switchToWorkspace = async (name: string) => { |
|
|
|
|
if (isActive) await plugin.call('manager', 'deactivatePlugin', 'remixd') |
|
|
|
|
await plugin.fileProviders.workspace.setWorkspace(name) |
|
|
|
|
await plugin.setWorkspace({ name, isLocalhost: false }) |
|
|
|
|
const isGitRepo = await plugin.fileManager.isGitRepo() |
|
|
|
|
const isGitRepo = await plugin.fileManager.isGitRepo(name) |
|
|
|
|
|
|
|
|
|
dispatch(setMode('browser')) |
|
|
|
|
dispatch(setCurrentWorkspace({ name, isGitRepo })) |
|
|
|
@ -325,10 +350,37 @@ export const getWorkspaces = async (): Promise<{name: string, isGitRepo: boolean |
|
|
|
|
Promise.all(Object.keys(items) |
|
|
|
|
.filter((item) => items[item].isDirectory) |
|
|
|
|
.map(async (folder) => { |
|
|
|
|
console.log('folder: ', folder) |
|
|
|
|
const isGitRepo: boolean = await plugin.fileProviders.browser.exists('/' + folder + '/.git') |
|
|
|
|
return { |
|
|
|
|
name: folder.replace(workspacesPath + '/', ''), |
|
|
|
|
isGitRepo |
|
|
|
|
|
|
|
|
|
if (isGitRepo) { |
|
|
|
|
let branches = [] |
|
|
|
|
let currentBranch = null |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
branches = await getGitRepoBranches(folder) |
|
|
|
|
} catch (e) { |
|
|
|
|
console.error(e) |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
currentBranch = await getGitRepoCurrentBranch(folder) |
|
|
|
|
} catch (e) { |
|
|
|
|
console.error(e) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
console.log('branches: ', branches) |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
name: folder.replace(workspacesPath + '/', ''), |
|
|
|
|
isGitRepo, |
|
|
|
|
branches, |
|
|
|
|
currentBranch |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
return { |
|
|
|
|
name: folder.replace(workspacesPath + '/', ''), |
|
|
|
|
isGitRepo |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
})).then(workspacesList => resolve(workspacesList)) |
|
|
|
|
}) |
|
|
|
@ -397,3 +449,23 @@ export const getRepositoryTitle = async (url: string) => { |
|
|
|
|
|
|
|
|
|
return name + counter |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const getGitRepoBranches = async (workspacePath: string) => { |
|
|
|
|
const gitConfig: { fs: IndexedDBStorage, dir: string } = { |
|
|
|
|
fs: window.remixFileSystemCallback, |
|
|
|
|
dir: addSlash(workspacePath) |
|
|
|
|
} |
|
|
|
|
const branches: { remote: any; name: string; }[] = await plugin.call('dGitProvider', 'branches', gitConfig) |
|
|
|
|
|
|
|
|
|
return branches |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const getGitRepoCurrentBranch = async (workspaceName: string) => { |
|
|
|
|
const gitConfig: { fs: IndexedDBStorage, dir: string } = { |
|
|
|
|
fs: window.remixFileSystemCallback, |
|
|
|
|
dir: addSlash(workspaceName) |
|
|
|
|
} |
|
|
|
|
const currentBranch: string = await plugin.call('dGitProvider', 'currentbranch', gitConfig) |
|
|
|
|
|
|
|
|
|
return currentBranch |
|
|
|
|
} |
|
|
|
|