11import * as vscode from 'vscode'
2- import * as CR from 'typings'
3-
4- import tutorialSetup from '../../services/tutorialSetup'
5- import { isEmptyWorkspace , openReadme } from '../workspace'
62import { setWorkspaceRoot } from '../../services/node'
73import { setStorage } from '../../editor/storage'
8- import createStateMachine from '../../state'
9-
10- /*
11- new
12- if current workspace is empty, use it
13- if not, open a new folder then start
14- */
15-
16- // async function continueTutorial() {
17- // // TODO: verify that tutorial is loaded in workspace
18- // // TODO: verify progress
19- // // TODO: verify setup
20- // await loadProgressPosition()
21- // await openReadme()
22- // }
23-
24- async function newTutorial ( tutorial : CR . Tutorial ) {
25- // if workspace isn't empty, clear it out if given permission
26- const isEmpty : boolean = await isEmptyWorkspace ( )
27- if ( ! isEmpty ) {
28- // eslint-disable-next-line
29- const options = [ 'Open a new folder' , 'I\'ll clear the files and folders myself' ]
30- const shouldOpenFolder = await vscode . window . showQuickPick ( options )
31- if ( shouldOpenFolder === options [ 0 ] ) {
32- await vscode . commands . executeCommand ( 'vscode.openFolder' )
33- }
34- }
4+ import { activate as activateMachine , default as machine } from '../../state'
5+ import * as storage from '../../services/storage'
6+ import * as git from '../../services/git'
7+ import * as CR from 'typings'
358
36- await tutorialSetup ( tutorial )
37- await openReadme ( )
9+ let initialTutorial : CR . Tutorial | undefined
10+ let initialProgress : CR . Progress = {
11+ levels : { } ,
12+ stages : { } ,
13+ steps : { } ,
14+ complete : false ,
3815}
3916
40-
4117export default async function start ( context : vscode . ExtensionContext ) : Promise < void > {
42- console . log ( 'start' , context )
43-
44- // setup connection to workspace
45- await setWorkspaceRoot ( )
46- // set workspace context path
47- await setStorage ( context . workspaceState )
48- // initiate the state machine
49- createStateMachine ( )
50- return ;
51-
52- // const modes = ['New']
53-
54- // const canContinue = await validateCanContinue()
55- // if (canContinue) {
56- // modes.push('Continue')
57- // }
58-
59- // const selectedMode: string | undefined = await vscode.window.showQuickPick(modes)
60-
61- // if (!selectedMode) {
62- // throw new Error('No mode selected')
63- // return
64- // }
65-
66- // interface TutorialQuickPickItem extends vscode.QuickPickItem {
67- // id: string
68- // }
69-
70- // // load tutorial summaries
71- // const tutorialsData: { [id: string]: CR.TutorialSummary } = await api({
72- // resource: 'getTutorialsSummary',
73- // })
74- // const selectableTutorials: TutorialQuickPickItem[] = Object.keys(tutorialsData).map(id => {
75- // const tutorial = tutorialsData[id]
76- // return {
77- // label: tutorial.title,
78- // description: tutorial.description,
79- // // detail: '', // optional additional info
80- // id,
81- // }
82- // })
83- // const selectedTutorial: TutorialQuickPickItem | undefined = await vscode.window.showQuickPick(selectableTutorials)
84-
85- // if (!selectedTutorial) {
86- // throw new Error('No tutorial selected')
87- // }
88-
89- // // load specific tutorial
90- // const tutorial: CR.Tutorial | undefined = await fetch({
91- // resource: 'getTutorial',
92- // params: { id: selectedTutorial.id },
93- // })
94-
95- // if (!tutorial) {
96- // throw new Error('No tutorial found')
97- // }
98-
99- // switch (selectedMode) {
100- // // new tutorial
101- // case modes[0]:
102- // await newTutorial(tutorial)
103- // break
104- // // continue
105- // case modes[1]:
106- // await continueTutorial()
107- // break
108- // }
109-
110- // // setup hook to run tests on save
111-
112-
113- // TODO: start
114- }
18+ console . log ( 'TUTORIAL_START' )
19+
20+ // setup connection to workspace
21+ await setWorkspaceRoot ( )
22+ // set workspace context path
23+ await setStorage ( context . workspaceState )
24+
25+ // initialize state machine
26+ activateMachine ( )
27+
28+ console . log ( 'ACTION: start' )
29+
30+ // verify that the user has a tutorial & progress
31+ // verify git is setup with a coderoad remote
32+ const [ tutorial , progress , hasGit , hasGitRemote ] = await Promise . all ( [
33+ storage . getTutorial ( ) ,
34+ storage . getProgress ( ) ,
35+ git . gitVersion ( ) ,
36+ git . gitCheckRemoteExists ( ) ,
37+ ] )
38+ initialTutorial = tutorial
39+ initialProgress = progress
40+ const canContinue = ! ! ( tutorial && progress && hasGit && hasGitRemote )
41+ console . log ( 'canContinue' , canContinue )
42+ // if a tutorial exists, "CONTINUE"
43+ // otherwise start from "NEW"
44+ machine . send ( canContinue ? 'CONTINUE' : 'NEW' )
45+ }
0 commit comments