Skip to content

Feature/workspace empty #150

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 3 commits into from
Mar 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add empty workspace check
  • Loading branch information
ShMcK committed Mar 21, 2020
commit 5858c933e96778dd943e1476c0d5a514038cd9c5
10 changes: 10 additions & 0 deletions src/channel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import tutorialConfig from '../actions/tutorialConfig'
import { COMMANDS } from '../editor/commands'
import logger from '../services/logger'
import Context from './context'
import { openWorkspace, checkWorkspaceEmpty } from '../services/workspace'

interface Channel {
receive(action: T.Action): Promise<void>
Expand Down Expand Up @@ -108,6 +109,15 @@ class Channel implements Channel {
// update the current stepId on startup
vscode.commands.executeCommand(COMMANDS.SET_CURRENT_STEP, action.payload)
return
case 'EDITOR_CHECK_WORKSPACE':
const isEmptyWorkspace = await checkWorkspaceEmpty(this.workspaceRoot.uri.path)
if (isEmptyWorkspace) {
this.send({ type: 'IS_EMPTY_WORKSPACE' })
} else {
openWorkspace()
this.send({ type: 'REQUEST_WORKSPACE' })
}
return
// load step actions (git commits, commands, open files)
case 'SETUP_ACTIONS':
await vscode.commands.executeCommand(COMMANDS.SET_CURRENT_STEP, action.payload)
Expand Down
4 changes: 2 additions & 2 deletions src/services/testRunner/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import node from '../../services/node'
import logger from '../../services/logger'
import node from '../node'
import logger from '../logger'
import parser from './parser'
import { debounce, throttle } from './throttle'
import onError from '../sentry/onError'
Expand Down
16 changes: 16 additions & 0 deletions src/services/workspace/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as vscode from 'vscode'
import * as fs from 'fs'

export const openWorkspace = () => {
vscode.commands.executeCommand('vscode.openFolder')
}

export const checkWorkspaceEmpty = async (dirname: string) => {
let files
try {
files = await fs.promises.readdir(dirname)
} catch (error) {
throw new Error('Failed to check workspace')
}
return files.length === 0
}
2 changes: 2 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export interface MachineStateSchema {
Error: {}
LoadStoredTutorial: {}
Start: {}
CheckEmptyWorkspace: {}
RequestEmptyWorkspace: {}
SelectTutorial: {}
LoadTutorialSummary: {}
Summary: {}
Expand Down
10 changes: 9 additions & 1 deletion web-app/src/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ const Routes = () => {
<Workspace>
<Router>
{/* Setup */}
<Route path={['Setup.Startup', 'Setup.Authenticate', 'Setup.LoadStoredTutorial']}>
<Route
path={[
'Setup.Startup',
'Setup.Authenticate',
'Setup.LoadStoredTutorial',
'Setup.CheckEmptyWorkspace',
'Setup.RequestEmptyWorkspace',
]}
>
<LoadingPage text="Launching..." context={context} />
</Route>
<Route path="Setup.Start">
Expand Down
9 changes: 9 additions & 0 deletions web-app/src/services/state/actions/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,13 @@ export default (editorSend: any) => ({
clearStorage(): void {
editorSend({ type: 'TUTORIAL_CLEAR' })
},
checkEmptyWorkspace() {
editorSend({
type: 'EDITOR_CHECK_WORKSPACE',
})
},
requestEmptyWorkspace() {
// TODO
console.log('request empty workspace')
},
})
15 changes: 14 additions & 1 deletion web-app/src/services/state/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,26 @@ export const createMachine = (options: any) => {
},
Start: {
on: {
NEW_TUTORIAL: 'SelectTutorial',
NEW_TUTORIAL: 'CheckEmptyWorkspace',
CONTINUE_TUTORIAL: {
target: '#tutorial-level',
actions: ['continueConfig'],
},
},
},
CheckEmptyWorkspace: {
onEntry: ['checkEmptyWorkspace'],
on: {
REQUEST_WORKSPACE: 'RequestEmptyWorkspace',
IS_EMPTY_WORKSPACE: 'SelectTutorial',
},
},
RequestEmptyWorkspace: {
onEntry: ['requestWorkspaceSelection'],
on: {
WORKSPACE_LOADED: 'CheckEmptyWorkspace',
},
},
SelectTutorial: {
onEntry: ['clearStorage'],
id: 'select-new-tutorial',
Expand Down