@@ -2,11 +2,12 @@ import * as vscode from 'vscode'
2
2
import { join } from 'path'
3
3
import { setStorage } from '../storage'
4
4
import ReactWebView from '../ReactWebView'
5
+ import { isEmptyWorkspace } from '../workspace'
5
6
import * as CR from 'typings'
6
7
7
8
const COMMANDS = {
8
9
START : 'coderoad.start' ,
9
- NEW_OR_CONTINUE : 'coderoad.new_or_continue ' ,
10
+ TUTORIAL_LAUNCH : 'coderoad.tutorial_launch ' ,
10
11
OPEN_WEBVIEW : 'coderoad.open_webview' ,
11
12
SEND_STATE : 'coderoad.send_state' ,
12
13
SEND_DATA : 'coderoad.send_data' ,
@@ -20,12 +21,13 @@ interface CreateCommandProps {
20
21
machine : CR . StateMachine ,
21
22
storage : any ,
22
23
git : any
24
+ position : any
23
25
}
24
26
25
27
// React panel webview
26
28
let webview : any ;
27
29
28
- export const createCommands = ( { context, machine, storage, git } : CreateCommandProps ) => ( {
30
+ export const createCommands = ( { context, machine, storage, git, position } : CreateCommandProps ) => ( {
29
31
// initialize
30
32
[ COMMANDS . START ] : ( ) => {
31
33
// set local storage workspace
@@ -36,25 +38,30 @@ export const createCommands = ({ context, machine, storage, git }: CreateCommand
36
38
console . log ( 'webview' , webview . panel . webview . postMessage )
37
39
machine . activate ( )
38
40
} ,
39
- [ COMMANDS . NEW_OR_CONTINUE ] : async ( ) => {
40
- // verify that the user has a tutorial & progress
41
- // verify git is setup with a coderoad remote
42
- const [ tutorial , progress , hasGit , hasGitRemote ] = await Promise . all ( [
43
- storage . getTutorial ( ) ,
44
- storage . getProgress ( ) ,
45
- git . gitVersion ( ) ,
46
- git . gitCheckRemoteExists ( ) ,
47
- ] )
48
- const canContinue = ! ! ( tutorial && progress && hasGit && hasGitRemote )
49
- console . log ( 'canContinue' , canContinue )
50
- // if a tutorial exists, 'CONTINUE'
51
- // otherwise start from 'NEW'
52
- machine . send ( canContinue ? 'CONTINUE' : 'NEW' )
53
- } ,
54
41
// open React webview
55
42
[ COMMANDS . OPEN_WEBVIEW ] : ( column : number = vscode . ViewColumn . One ) => {
56
43
webview . createOrShow ( column ) ;
57
44
} ,
45
+ // launch a new tutorial
46
+ // NOTE: may be better to move into action as logic is primarily non-vscode
47
+ [ COMMANDS . TUTORIAL_LAUNCH ] : async ( tutorial : CR . Tutorial ) => {
48
+ console . log ( 'launch tutorial' )
49
+
50
+ await isEmptyWorkspace ( )
51
+
52
+ await git . gitInitIfNotExists ( )
53
+
54
+ // TODO: use actual tutorial repo
55
+ await Promise . all ( [ git . gitSetupRemote ( tutorial . meta . repo ) , storage . setTutorial ( tutorial ) , storage . resetProgress ( ) ] )
56
+
57
+ // TODO: refactor to allow client to call initialization
58
+ const pos : CR . Position = await position . getInitial ( tutorial )
59
+
60
+ // eslint-disable-next-line
61
+ const { steps } = tutorial . data
62
+ const { setup } = steps [ pos . stepId ] . actions
63
+ await git . gitLoadCommits ( setup )
64
+ } ,
58
65
// open a file
59
66
[ COMMANDS . OPEN_FILE ] : async ( relativeFilePath : string ) => {
60
67
console . log ( `OPEN_FILE ${ JSON . stringify ( relativeFilePath ) } ` )
@@ -79,6 +86,6 @@ export const createCommands = ({ context, machine, storage, git }: CreateCommand
79
86
} ,
80
87
[ COMMANDS . RECEIVE_ACTION ] : ( action : string | CR . Action ) => {
81
88
console . log ( 'onReceiveAction' , action )
82
- machine . onReceive ( action )
89
+ machine . send ( action )
83
90
}
84
91
} )
0 commit comments