File tree Expand file tree Collapse file tree 7 files changed +62
-4
lines changed Expand file tree Collapse file tree 7 files changed +62
-4
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import tutorialConfig from '../actions/tutorialConfig'
8
8
import { COMMANDS } from '../editor/commands'
9
9
import logger from '../services/logger'
10
10
import Context from './context'
11
+ import { openWorkspace, checkWorkspaceEmpty } from '../services/workspace'
11
12
12
13
interface Channel {
13
14
receive(action: T.Action): Promise<void>
@@ -108,6 +109,15 @@ class Channel implements Channel {
108
109
// update the current stepId on startup
109
110
vscode.commands.executeCommand(COMMANDS.SET_CURRENT_STEP, action.payload)
110
111
return
112
+ case 'EDITOR_CHECK_WORKSPACE':
113
+ const isEmptyWorkspace = await checkWorkspaceEmpty(this.workspaceRoot.uri.path)
114
+ if (isEmptyWorkspace) {
115
+ this.send({ type: 'IS_EMPTY_WORKSPACE' })
116
+ } else {
117
+ openWorkspace()
118
+ this.send({ type: 'REQUEST_WORKSPACE' })
119
+ }
120
+ return
111
121
// load step actions (git commits, commands, open files)
112
122
case 'SETUP_ACTIONS':
113
123
await vscode.commands.executeCommand(COMMANDS.SET_CURRENT_STEP, action.payload)
Original file line number Diff line number Diff line change 1
- import node from '../../services/ node'
2
- import logger from '../../services/ logger'
1
+ import node from '../node'
2
+ import logger from '../logger'
3
3
import parser from './parser'
4
4
import { debounce, throttle } from './throttle'
5
5
import onError from '../sentry/onError'
Original file line number Diff line number Diff line change
1
+ import * as vscode from 'vscode'
2
+ import * as fs from 'fs'
3
+
4
+ export const openWorkspace = () => {
5
+ vscode.commands.executeCommand('vscode.openFolder')
6
+ }
7
+
8
+ export const checkWorkspaceEmpty = async (dirname: string) => {
9
+ let files
10
+ try {
11
+ files = await fs.promises.readdir(dirname)
12
+ } catch (error) {
13
+ throw new Error('Failed to check workspace')
14
+ }
15
+ return files.length === 0
16
+ }
Original file line number Diff line number Diff line change @@ -73,6 +73,8 @@ export interface MachineStateSchema {
73
73
Error: {}
74
74
LoadStoredTutorial: {}
75
75
Start: {}
76
+ CheckEmptyWorkspace: {}
77
+ RequestEmptyWorkspace: {}
76
78
SelectTutorial: {}
77
79
LoadTutorialSummary: {}
78
80
Summary: {}
Original file line number Diff line number Diff line change @@ -14,7 +14,15 @@ const Routes = () => {
14
14
<Workspace>
15
15
<Router>
16
16
{/* Setup */}
17
- <Route path={['Setup.Startup', 'Setup.Authenticate', 'Setup.LoadStoredTutorial']}>
17
+ <Route
18
+ path={[
19
+ 'Setup.Startup',
20
+ 'Setup.Authenticate',
21
+ 'Setup.LoadStoredTutorial',
22
+ 'Setup.CheckEmptyWorkspace',
23
+ 'Setup.RequestEmptyWorkspace',
24
+ ]}
25
+ >
18
26
<LoadingPage text="Launching..." context={context} />
19
27
</Route>
20
28
<Route path="Setup.Start">
Original file line number Diff line number Diff line change @@ -70,4 +70,13 @@ export default (editorSend: any) => ({
70
70
clearStorage(): void {
71
71
editorSend({ type: 'TUTORIAL_CLEAR' })
72
72
},
73
+ checkEmptyWorkspace() {
74
+ editorSend({
75
+ type: 'EDITOR_CHECK_WORKSPACE',
76
+ })
77
+ },
78
+ requestEmptyWorkspace() {
79
+ // TODO
80
+ console.log('request empty workspace')
81
+ },
73
82
})
Original file line number Diff line number Diff line change @@ -68,13 +68,26 @@ export const createMachine = (options: any) => {
68
68
},
69
69
Start: {
70
70
on: {
71
- NEW_TUTORIAL: 'SelectTutorial ',
71
+ NEW_TUTORIAL: 'CheckEmptyWorkspace ',
72
72
CONTINUE_TUTORIAL: {
73
73
target: '#tutorial-level',
74
74
actions: ['continueConfig'],
75
75
},
76
76
},
77
77
},
78
+ CheckEmptyWorkspace: {
79
+ onEntry: ['checkEmptyWorkspace'],
80
+ on: {
81
+ REQUEST_WORKSPACE: 'RequestEmptyWorkspace',
82
+ IS_EMPTY_WORKSPACE: 'SelectTutorial',
83
+ },
84
+ },
85
+ RequestEmptyWorkspace: {
86
+ onEntry: ['requestWorkspaceSelection'],
87
+ on: {
88
+ WORKSPACE_LOADED: 'CheckEmptyWorkspace',
89
+ },
90
+ },
78
91
SelectTutorial: {
79
92
onEntry: ['clearStorage'],
80
93
id: 'select-new-tutorial',
You can’t perform that action at this time.
0 commit comments