pull/3654/head
yann300 1 year ago
parent 41ecde7fd7
commit 7329db73c3
  1. 106
      libs/remix-ui/workspace/src/lib/actions/workspace.ts

@ -121,62 +121,62 @@ export const createWorkspace = async (
const promise = createWorkspaceTemplate(workspaceName, workspaceTemplateName) const promise = createWorkspaceTemplate(workspaceName, workspaceTemplateName)
dispatch(createWorkspaceRequest()) dispatch(createWorkspaceRequest())
promise.then(async () => { promise.then(async () => {
dispatch(createWorkspaceSuccess({ name: workspaceName, isGitRepo })) dispatch(createWorkspaceSuccess({ name: workspaceName, isGitRepo }))
await plugin.setWorkspace({ name: workspaceName, isLocalhost: false }) await plugin.setWorkspace({ name: workspaceName, isLocalhost: false })
await plugin.workspaceCreated(workspaceName) await plugin.workspaceCreated(workspaceName)
if (isGitRepo && createCommit) { if (isGitRepo && createCommit) {
const name = await plugin.call('settings', 'get', 'settings/github-user-name') const name = await plugin.call('settings', 'get', 'settings/github-user-name')
const email = await plugin.call('settings', 'get', 'settings/github-email') const email = await plugin.call('settings', 'get', 'settings/github-email')
const currentBranch = await plugin.call('dGitProvider', 'currentbranch') const currentBranch = await plugin.call('dGitProvider', 'currentbranch')
if (!currentBranch) { if (!currentBranch) {
if (!name || !email) { if (!name || !email) {
await plugin.call('notification', 'toast', 'To use Git features, add username and email to the Github section of the Settings panel.') await plugin.call('notification', 'toast', 'To use Git features, add username and email to the Github section of the Settings panel.')
} else { } else {
// commit the template as first commit // commit the template as first commit
plugin.call('notification', 'toast', 'Creating initial git commit ...') plugin.call('notification', 'toast', 'Creating initial git commit ...')
await plugin.call('dGitProvider', 'init') await plugin.call('dGitProvider', 'init')
if (!isEmpty) await loadWorkspacePreset(workspaceTemplateName, opts) if (!isEmpty) await loadWorkspacePreset(workspaceTemplateName, opts)
const status = await plugin.call('dGitProvider', 'status', { ref: 'HEAD' }) const status = await plugin.call('dGitProvider', 'status', { ref: 'HEAD' })
Promise.all( Promise.all(
status.map(([filepath, , worktreeStatus]) => status.map(([filepath, , worktreeStatus]) =>
worktreeStatus worktreeStatus
? plugin.call('dGitProvider', 'add', { ? plugin.call('dGitProvider', 'add', {
filepath: removeSlash(filepath), filepath: removeSlash(filepath),
}) })
: plugin.call('dGitProvider', 'rm', { : plugin.call('dGitProvider', 'rm', {
filepath: removeSlash(filepath), filepath: removeSlash(filepath),
}) })
) )
).then(async () => { ).then(async () => {
await plugin.call('dGitProvider', 'commit', { await plugin.call('dGitProvider', 'commit', {
author: { author: {
name, name,
email, email,
}, },
message: `Initial commit: remix template ${workspaceTemplateName}`, message: `Initial commit: remix template ${workspaceTemplateName}`,
})
}) })
} })
} }
} }
if (!isEmpty && !(isGitRepo && createCommit)) await loadWorkspacePreset(workspaceTemplateName, opts) }
cb && cb(null, workspaceName) if (!isEmpty && !(isGitRepo && createCommit)) await loadWorkspacePreset(workspaceTemplateName, opts)
if (isGitRepo) { cb && cb(null, workspaceName)
await checkGit() if (isGitRepo) {
const isActive = await plugin.call('manager', 'isActive', 'dgit') await checkGit()
if (!isActive) await plugin.call('manager', 'activatePlugin', 'dgit') const isActive = await plugin.call('manager', 'isActive', 'dgit')
} if (!isActive) await plugin.call('manager', 'activatePlugin', 'dgit')
// this call needs to be here after the callback because it calls dGitProvider which also calls this function and that would cause an infinite loop }
await plugin.setWorkspaces(await getWorkspaces()) // this call needs to be here after the callback because it calls dGitProvider which also calls this function and that would cause an infinite loop
}) await plugin.setWorkspaces(await getWorkspaces())
.catch((error) => { })
dispatch(createWorkspaceError(error.message)) .catch((error) => {
cb && cb(error) dispatch(createWorkspaceError(error.message))
}) cb && cb(error)
})
return promise return promise
} }

Loading…
Cancel
Save