|
|
|
@ -41,9 +41,9 @@ export const addInputField = async (type: 'file' | 'folder', path: string, cb?: |
|
|
|
|
return promise |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const createWorkspace = async (workspaceName: string, isEmpty = false, cb?: (err: Error, result?: string | number | boolean | Record<string, any>) => void) => { |
|
|
|
|
export const createWorkspace = async (workspaceName: string, workspaceTemplateName, isEmpty = false, cb?: (err: Error, result?: string | number | boolean | Record<string, any>) => void) => { |
|
|
|
|
await plugin.fileManager.closeAllFiles() |
|
|
|
|
const promise = createWorkspaceTemplate(workspaceName, 'default-template') |
|
|
|
|
const promise = createWorkspaceTemplate(workspaceName, workspaceTemplateName) |
|
|
|
|
|
|
|
|
|
dispatch(createWorkspaceRequest(promise)) |
|
|
|
|
promise.then(async () => { |
|
|
|
@ -51,7 +51,7 @@ export const createWorkspace = async (workspaceName: string, isEmpty = false, cb |
|
|
|
|
await plugin.setWorkspace({ name: workspaceName, isLocalhost: false }) |
|
|
|
|
await plugin.setWorkspaces(await getWorkspaces()) |
|
|
|
|
await plugin.workspaceCreated(workspaceName) |
|
|
|
|
if (!isEmpty) await loadWorkspacePreset('default-template') |
|
|
|
|
if (!isEmpty) await loadWorkspacePreset(workspaceTemplateName) |
|
|
|
|
cb && cb(null, workspaceName) |
|
|
|
|
}).catch((error) => { |
|
|
|
|
dispatch(createWorkspaceError({ error })) |
|
|
|
@ -60,10 +60,10 @@ export const createWorkspace = async (workspaceName: string, isEmpty = false, cb |
|
|
|
|
return promise |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const createWorkspaceTemplate = async (workspaceName: string, template: 'gist-template' | 'code-template' | 'default-template' = 'default-template') => { |
|
|
|
|
export const createWorkspaceTemplate = async (workspaceName: string, template: 'gist-template' | 'code-template' | 'remixDefault' = 'remixDefault') => { |
|
|
|
|
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) && template === 'default-template') throw new Error('workspace already exists') |
|
|
|
|
if (await workspaceExists(workspaceName) && template === 'remixDefault') throw new Error('workspace already exists') |
|
|
|
|
else { |
|
|
|
|
const workspaceProvider = plugin.fileProviders.workspace |
|
|
|
|
|
|
|
|
@ -77,7 +77,7 @@ export type UrlParametersType = { |
|
|
|
|
url: string |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const loadWorkspacePreset = async (template: 'gist-template' | 'code-template' | 'default-template' = 'default-template') => { |
|
|
|
|
export const loadWorkspacePreset = async (template: 'gist-template' | 'code-template' | 'remixDefault' = 'remixDefault') => { |
|
|
|
|
const workspaceProvider = plugin.fileProviders.workspace |
|
|
|
|
const params = queryParams.get() as UrlParametersType |
|
|
|
|
|
|
|
|
@ -150,7 +150,7 @@ export const loadWorkspacePreset = async (template: 'gist-template' | 'code-temp |
|
|
|
|
} |
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
case 'default-template': |
|
|
|
|
case 'remixDefault': |
|
|
|
|
// creates a new workspace and populates it with default project template.
|
|
|
|
|
// insert example contracts
|
|
|
|
|
for (const file in examples) { |
|
|
|
|