Skip to content

Refactor editor #396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor onValidateSetup
Signed-off-by: shmck <[email protected]>
  • Loading branch information
ShMcK committed Jul 20, 2020
commit 72ef62ca979a8f387a8358ff81eacb68666ce49e
1 change: 1 addition & 0 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { default as onStartup } from './onStartup'
export { default as onTutorialConfig } from './onTutorialConfig'
export { default as onTutorialContinueConfig } from './onTutorialContinueConfig'
export { default as onValidateSetup } from './onValidateSetup'
export { default as onErrorPage } from './onErrorPage'
export { default as onTestPass } from './onTestPass'
54 changes: 54 additions & 0 deletions src/actions/onValidateSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import * as E from 'typings/error'
import { version } from '../services/dependencies'
import { checkWorkspaceEmpty } from '../services/workspace'

const onValidateSetup = async (send: any) => {
try {
// check workspace is selected
const isEmptyWorkspace = await checkWorkspaceEmpty()
if (!isEmptyWorkspace) {
const error: E.ErrorMessage = {
type: 'WorkspaceNotEmpty',
message: '',
actions: [
{
label: 'Open Workspace',
transition: 'REQUEST_WORKSPACE',
},
{
label: 'Check Again',
transition: 'RETRY',
},
],
}
send({ type: 'VALIDATE_SETUP_FAILED', payload: { error } })
return
}
// check Git is installed.
// Should wait for workspace before running otherwise requires access to root folder
const isGitInstalled = await version('git')
if (!isGitInstalled) {
const error: E.ErrorMessage = {
type: 'GitNotFound',
message: '',
actions: [
{
label: 'Check Again',
transition: 'RETRY',
},
],
}
send({ type: 'VALIDATE_SETUP_FAILED', payload: { error } })
return
}
send({ type: 'SETUP_VALIDATED' })
} catch (e) {
const error = {
type: 'UknownError',
message: e.message,
}
send({ type: 'VALIDATE_SETUP_FAILED', payload: { error } })
}
}

export default onValidateSetup
52 changes: 2 additions & 50 deletions src/channel.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import * as T from 'typings'
import * as TT from 'typings/tutorial'
import * as E from 'typings/error'
import * as vscode from 'vscode'
import { setupActions, solutionActions } from './actions/setupActions'
import { COMMANDS } from './commands'
import Context from './services/context/context'
import logger from './services/logger'
import { version } from './services/dependencies'
import { openWorkspace, checkWorkspaceEmpty } from './services/workspace'
import { openWorkspace } from './services/workspace'
import { showOutput } from './services/testRunner/output'
import { exec } from './services/node'
import reset from './services/reset'
Expand Down Expand Up @@ -48,7 +46,6 @@ class Channel implements Channel {
case 'EDITOR_STARTUP':
actions.onStartup(this.context, this.workspaceState, this.send)
return

// clear tutorial local storage
case 'TUTORIAL_CLEAR':
// clear current progress/position/tutorial
Expand All @@ -62,52 +59,7 @@ class Channel implements Channel {
actions.onTutorialContinueConfig(action, this.context, this.send)
return
case 'EDITOR_VALIDATE_SETUP':
try {
// check workspace is selected
const isEmptyWorkspace = await checkWorkspaceEmpty()
if (!isEmptyWorkspace) {
const error: E.ErrorMessage = {
type: 'WorkspaceNotEmpty',
message: '',
actions: [
{
label: 'Open Workspace',
transition: 'REQUEST_WORKSPACE',
},
{
label: 'Check Again',
transition: 'RETRY',
},
],
}
this.send({ type: 'VALIDATE_SETUP_FAILED', payload: { error } })
return
}
// check Git is installed.
// Should wait for workspace before running otherwise requires access to root folder
const isGitInstalled = await version('git')
if (!isGitInstalled) {
const error: E.ErrorMessage = {
type: 'GitNotFound',
message: '',
actions: [
{
label: 'Check Again',
transition: 'RETRY',
},
],
}
this.send({ type: 'VALIDATE_SETUP_FAILED', payload: { error } })
return
}
this.send({ type: 'SETUP_VALIDATED' })
} catch (e) {
const error = {
type: 'UknownError',
message: e.message,
}
this.send({ type: 'VALIDATE_SETUP_FAILED', payload: { error } })
}
actions.onValidateSetup(this.send)
return
case 'EDITOR_REQUEST_WORKSPACE':
openWorkspace()
Expand Down