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'
88import { COMMANDS } from '../editor/commands'
99import logger from '../services/logger'
1010import Context from './context'
11+ import { openWorkspace , checkWorkspaceEmpty } from '../services/workspace'
1112
1213interface Channel {
1314 receive ( action : T . Action ) : Promise < void >
@@ -108,6 +109,15 @@ class Channel implements Channel {
108109 // update the current stepId on startup
109110 vscode . commands . executeCommand ( COMMANDS . SET_CURRENT_STEP , action . payload )
110111 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
111121 // load step actions (git commits, commands, open files)
112122 case 'SETUP_ACTIONS' :
113123 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'
33import parser from './parser'
44import { debounce , throttle } from './throttle'
55import 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 {
7373 Error : { }
7474 LoadStoredTutorial : { }
7575 Start : { }
76+ CheckEmptyWorkspace : { }
77+ RequestEmptyWorkspace : { }
7678 SelectTutorial : { }
7779 LoadTutorialSummary : { }
7880 Summary : { }
Original file line number Diff line number Diff line change @@ -14,7 +14,15 @@ const Routes = () => {
1414 < Workspace >
1515 < Router >
1616 { /* 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+ >
1826 < LoadingPage text = "Launching..." context = { context } />
1927 </ Route >
2028 < Route path = "Setup.Start" >
Original file line number Diff line number Diff line change @@ -70,4 +70,13 @@ export default (editorSend: any) => ({
7070 clearStorage ( ) : void {
7171 editorSend ( { type : 'TUTORIAL_CLEAR' } )
7272 } ,
73+ checkEmptyWorkspace ( ) {
74+ editorSend ( {
75+ type : 'EDITOR_CHECK_WORKSPACE' ,
76+ } )
77+ } ,
78+ requestEmptyWorkspace ( ) {
79+ // TODO
80+ console . log ( 'request empty workspace' )
81+ } ,
7382} )
Original file line number Diff line number Diff line change @@ -68,13 +68,26 @@ export const createMachine = (options: any) => {
6868 } ,
6969 Start : {
7070 on : {
71- NEW_TUTORIAL : 'SelectTutorial ' ,
71+ NEW_TUTORIAL : 'CheckEmptyWorkspace ' ,
7272 CONTINUE_TUTORIAL : {
7373 target : '#tutorial-level' ,
7474 actions : [ 'continueConfig' ] ,
7575 } ,
7676 } ,
7777 } ,
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+ } ,
7891 SelectTutorial : {
7992 onEntry : [ 'clearStorage' ] ,
8093 id : 'select-new-tutorial' ,
You can’t perform that action at this time.
0 commit comments