|
|
@ -1,7 +1,7 @@ |
|
|
|
import React from 'react' |
|
|
|
import React from 'react' |
|
|
|
import { bufferToHex } from '@ethereumjs/util' |
|
|
|
import { bufferToHex } from '@ethereumjs/util' |
|
|
|
import { hash } from '@remix-project/remix-lib' |
|
|
|
import { hash } from '@remix-project/remix-lib' |
|
|
|
import { TEMPLATE_METADATA, TEMPLATE_NAMES } from '../utils/constants' |
|
|
|
import { TEMPLATE_METADATA, TEMPLATE_NAMES, TemplateType } from '../utils/constants' |
|
|
|
import axios, { AxiosResponse } from 'axios' |
|
|
|
import axios, { AxiosResponse } from 'axios' |
|
|
|
import { |
|
|
|
import { |
|
|
|
addInputFieldSuccess, |
|
|
|
addInputFieldSuccess, |
|
|
@ -125,7 +125,8 @@ export const createWorkspace = async ( |
|
|
|
createCommit: boolean = true |
|
|
|
createCommit: boolean = true |
|
|
|
) => { |
|
|
|
) => { |
|
|
|
await plugin.fileManager.closeAllFiles() |
|
|
|
await plugin.fileManager.closeAllFiles() |
|
|
|
const promise = createWorkspaceTemplate(workspaceName, workspaceTemplateName) |
|
|
|
const metadata = TEMPLATE_METADATA[workspaceTemplateName] |
|
|
|
|
|
|
|
const promise = createWorkspaceTemplate(workspaceName, workspaceTemplateName, metadata) |
|
|
|
dispatch(createWorkspaceRequest()) |
|
|
|
dispatch(createWorkspaceRequest()) |
|
|
|
promise.then(async () => { |
|
|
|
promise.then(async () => { |
|
|
|
dispatch(createWorkspaceSuccess({ name: workspaceName, isGitRepo })) |
|
|
|
dispatch(createWorkspaceSuccess({ name: workspaceName, isGitRepo })) |
|
|
@ -170,7 +171,18 @@ export const createWorkspace = async ( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (!isEmpty && !(isGitRepo && createCommit)) await loadWorkspacePreset(workspaceTemplateName, opts) |
|
|
|
if (metadata && metadata.type === 'plugin') {
|
|
|
|
|
|
|
|
plugin.call('notification', 'toast', 'Please wait while the workspace is being populated with the template.') |
|
|
|
|
|
|
|
dispatch(cloneRepositoryRequest()) |
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
|
|
plugin.call(metadata.name, metadata.endpoint, ...metadata.params).then(() => { |
|
|
|
|
|
|
|
dispatch(cloneRepositorySuccess()) |
|
|
|
|
|
|
|
}).catch((e) => { |
|
|
|
|
|
|
|
dispatch(cloneRepositorySuccess()) |
|
|
|
|
|
|
|
plugin.call('notification', 'toast', 'error adding template ' + e.message || e) |
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}, 5000)
|
|
|
|
|
|
|
|
} else if (!isEmpty && !(isGitRepo && createCommit)) await loadWorkspacePreset(workspaceTemplateName, opts) |
|
|
|
cb && cb(null, workspaceName) |
|
|
|
cb && cb(null, workspaceName) |
|
|
|
if (isGitRepo) { |
|
|
|
if (isGitRepo) { |
|
|
|
await checkGit() |
|
|
|
await checkGit() |
|
|
@ -190,12 +202,11 @@ export const createWorkspace = async ( |
|
|
|
return promise |
|
|
|
return promise |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const createWorkspaceTemplate = async (workspaceName: string, template: WorkspaceTemplate = 'remixDefault') => { |
|
|
|
export const createWorkspaceTemplate = async (workspaceName: string, template: WorkspaceTemplate = 'remixDefault', metadata?: TemplateType) => { |
|
|
|
const metadata = TEMPLATE_METADATA[template] |
|
|
|
|
|
|
|
if (!workspaceName) throw new Error('workspace name cannot be empty') |
|
|
|
if (!workspaceName) throw new Error('workspace name cannot be empty') |
|
|
|
if (checkSpecialChars(workspaceName) || checkSlash(workspaceName)) throw new Error('special characters are not allowed') |
|
|
|
if (checkSpecialChars(workspaceName) || checkSlash(workspaceName)) throw new Error('special characters are not allowed') |
|
|
|
if ((await workspaceExists(workspaceName)) && template === 'remixDefault') throw new Error('workspace already exists') |
|
|
|
if ((await workspaceExists(workspaceName)) && template === 'remixDefault') throw new Error('workspace already exists') |
|
|
|
else if (metadata) { |
|
|
|
else if (metadata && metadata.type === 'git') { |
|
|
|
await plugin.call('dGitProvider', 'clone', {url: metadata.url, branch: metadata.branch}, workspaceName) |
|
|
|
await plugin.call('dGitProvider', 'clone', {url: metadata.url, branch: metadata.branch}, workspaceName) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
const workspaceProvider = plugin.fileProviders.workspace |
|
|
|
const workspaceProvider = plugin.fileProviders.workspace |
|
|
|