|
|
|
@ -6,13 +6,55 @@ const QueryParams = require('../../../../../../apps/remix-ide/src/lib/query-para |
|
|
|
|
const examples = require('../../../../../../apps/remix-ide/src/app/editor/examples') |
|
|
|
|
let plugin |
|
|
|
|
|
|
|
|
|
export const setCurrentWorkspace = (workspace: string) => { |
|
|
|
|
const setCurrentWorkspace = (workspace: string) => { |
|
|
|
|
return { |
|
|
|
|
type: 'SET_CURRENT_WORKSPACE', |
|
|
|
|
payload: workspace |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const processCreateWorkspace = async (name: string) => { |
|
|
|
|
const workspaceProvider = plugin.fileProviders.workspace |
|
|
|
|
const browserProvider = plugin.fileProviders.browser |
|
|
|
|
const workspacePath = 'browser/' + workspaceProvider.workspacesPath + '/' + name |
|
|
|
|
const workspaceRootPath = 'browser/' + workspaceProvider.workspacesPath |
|
|
|
|
const workspaceRootPathExists = await browserProvider.exists(workspaceRootPath) |
|
|
|
|
const workspacePathExists = await browserProvider.exists(workspacePath) |
|
|
|
|
|
|
|
|
|
if (!workspaceRootPathExists) browserProvider.createDir(workspaceRootPath) |
|
|
|
|
if (!workspacePathExists) browserProvider.createDir(workspacePath) |
|
|
|
|
workspaceProvider.setWorkspace(name) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const createWorkspace = async (workspaceName: string, setDefaults = true) => { |
|
|
|
|
if (!workspaceName) throw new Error('workspace name cannot be empty') |
|
|
|
|
if (checkSpecialChars(workspaceName) || checkSlash(workspaceName)) throw new Error('special characters are not allowed') |
|
|
|
|
if (await workspaceExists(workspaceName)) throw new Error('workspace already exists') |
|
|
|
|
else { |
|
|
|
|
const workspaceProvider = plugin.fileProviders.workspace |
|
|
|
|
|
|
|
|
|
await processCreateWorkspace(workspaceName) |
|
|
|
|
if (setDefaults) { |
|
|
|
|
// insert example contracts if there are no files to show
|
|
|
|
|
for (const file in examples) { |
|
|
|
|
try { |
|
|
|
|
await workspaceProvider.set(examples[file].name, examples[file].content) |
|
|
|
|
} catch (error) { |
|
|
|
|
console.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const workspaceExists = async (name: string) => { |
|
|
|
|
const workspaceProvider = plugin.fileProviders.workspace |
|
|
|
|
const browserProvider = plugin.fileProviders.browser |
|
|
|
|
const workspacePath = 'browser/' + workspaceProvider.workspacesPath + '/' + name |
|
|
|
|
|
|
|
|
|
return browserProvider.exists(workspacePath) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const initWorkspace = (filePanelPlugin) => async (dispatch: React.Dispatch<any>) => { |
|
|
|
|
plugin = filePanelPlugin |
|
|
|
|
const queryParams = new QueryParams() |
|
|
|
@ -66,49 +108,24 @@ export const initWorkspace = (filePanelPlugin) => async (dispatch: React.Dispatc |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
return dispatch(setCurrentWorkspace(initialWorkspace)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const processCreateWorkspace = async (name: string) => { |
|
|
|
|
const workspaceProvider = plugin.fileProviders.workspace |
|
|
|
|
const browserProvider = plugin.fileProviders.browser |
|
|
|
|
const workspacePath = 'browser/' + workspaceProvider.workspacesPath + '/' + name |
|
|
|
|
const workspaceRootPath = 'browser/' + workspaceProvider.workspacesPath |
|
|
|
|
const workspaceRootPathExists = await browserProvider.exists(workspaceRootPath) |
|
|
|
|
const workspacePathExists = await browserProvider.exists(workspacePath) |
|
|
|
|
// plugin.fileProviders.localhost.event.off('disconnected', localhostDisconnect)
|
|
|
|
|
// plugin.fileProviders.localhost.event.on('disconnected', localhostDisconnect)
|
|
|
|
|
// plugin.fileProviders.localhost.event.on('connected', () => {
|
|
|
|
|
// remixdExplorer.show()
|
|
|
|
|
// setWorkspace(LOCALHOST)
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
if (!workspaceRootPathExists) browserProvider.createDir(workspaceRootPath) |
|
|
|
|
if (!workspacePathExists) browserProvider.createDir(workspacePath) |
|
|
|
|
plugin.fileProviders.workspace.setWorkspace(name) |
|
|
|
|
} |
|
|
|
|
// plugin.fileProviders.localhost.event.on('disconnected', () => {
|
|
|
|
|
// remixdExplorer.hide()
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
const createWorkspace = async (workspaceName, setDefaults = true) => { |
|
|
|
|
if (!workspaceName) throw new Error('name cannot be empty') |
|
|
|
|
if (checkSpecialChars(workspaceName) || checkSlash(workspaceName)) throw new Error('special characters are not allowed') |
|
|
|
|
if (await workspaceExists(workspaceName)) throw new Error('workspace already exists') |
|
|
|
|
else { |
|
|
|
|
const workspaceProvider = plugin.fileProviders.workspace |
|
|
|
|
// plugin.fileProviders.localhost.event.on('loading', () => {
|
|
|
|
|
// remixdExplorer.loading()
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
await processCreateWorkspace(workspaceName) |
|
|
|
|
workspaceProvider.setWorkspace(workspaceName) |
|
|
|
|
plugin.workspaceName = workspaceName |
|
|
|
|
if (setDefaults) { |
|
|
|
|
// insert example contracts if there are no files to show
|
|
|
|
|
for (const file in examples) { |
|
|
|
|
try { |
|
|
|
|
await workspaceProvider.set(examples[file].name, examples[file].content) |
|
|
|
|
} catch (error) { |
|
|
|
|
console.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const workspaceExists = async (name) => { |
|
|
|
|
const workspaceProvider = plugin.fileProviders.workspace |
|
|
|
|
const browserProvider = plugin.fileProviders.browser |
|
|
|
|
const workspacePath = 'browser/' + workspaceProvider.workspacesPath + '/' + name |
|
|
|
|
|
|
|
|
|
return browserProvider.exists(workspacePath) |
|
|
|
|
// plugin.fileProviders.workspace.event.on('createWorkspace', (name) => {
|
|
|
|
|
// createNewWorkspace(name)
|
|
|
|
|
// })
|
|
|
|
|
return dispatch(setCurrentWorkspace(initialWorkspace)) |
|
|
|
|
} |
|
|
|
|