@@ -2,11 +2,12 @@ import * as vscode from 'vscode'
22import { join } from 'path'
33import { setStorage } from '../storage'
44import ReactWebView from '../ReactWebView'
5+ import { isEmptyWorkspace } from '../workspace'
56import * as CR from 'typings'
67
78const COMMANDS = {
89START :'coderoad.start' ,
9- NEW_OR_CONTINUE :'coderoad.new_or_continue ' ,
10+ TUTORIAL_LAUNCH :'coderoad.tutorial_launch ' ,
1011OPEN_WEBVIEW :'coderoad.open_webview' ,
1112SEND_STATE :'coderoad.send_state' ,
1213SEND_DATA :'coderoad.send_data' ,
@@ -20,12 +21,13 @@ interface CreateCommandProps {
2021machine :CR . StateMachine ,
2122storage :any ,
2223git :any
24+ position :any
2325}
2426
2527// React panel webview
2628let webview :any ;
2729
28- export const createCommands = ( { context, machine, storage, git} :CreateCommandProps ) => ( {
30+ export const createCommands = ( { context, machine, storage, git, position } :CreateCommandProps ) => ( {
2931// initialize
3032[ COMMANDS . START ] :( ) => {
3133// set local storage workspace
@@ -36,25 +38,30 @@ export const createCommands = ({ context, machine, storage, git }: CreateCommand
3638console . log ( 'webview' , webview . panel . webview . postMessage )
3739machine . activate ( )
3840} ,
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- } ,
5441// open React webview
5542[ COMMANDS . OPEN_WEBVIEW ] :( column :number = vscode . ViewColumn . One ) => {
5643webview . createOrShow ( column ) ;
5744} ,
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+ } ,
5865// open a file
5966[ COMMANDS . OPEN_FILE ] :async ( relativeFilePath :string ) => {
6067console . log ( `OPEN_FILE${ JSON . stringify ( relativeFilePath ) } ` )
@@ -79,6 +86,6 @@ export const createCommands = ({ context, machine, storage, git }: CreateCommand
7986} ,
8087[ COMMANDS . RECEIVE_ACTION ] :( action :string | CR . Action ) => {
8188console . log ( 'onReceiveAction' , action )
82- machine . onReceive ( action )
89+ machine . send ( action )
8390}
8491} )