Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf8c527e

Browse files
committed
cleanup start
1 parente88651e commitf8c527e

File tree

8 files changed

+182
-158
lines changed

8 files changed

+182
-158
lines changed

‎src/editor/commands/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import*asvscodefrom'vscode'
2+
importstartfrom'./start'
23

34
// import runTest from './runTest'
4-
importstartfrom'./start'
55
// import loadSolution from './loadSolution'
66
// import quit from './quit'
77

@@ -13,11 +13,11 @@ const COMMANDS = {
1313
// QUIT: 'coderoad.quit',
1414
}
1515

16+
1617
exportdefault(context:vscode.ExtensionContext):void=>{
1718
constcommands={
18-
[COMMANDS.START]():void{
19-
console.log('TUTORIAL_START')
20-
start(context)
19+
[COMMANDS.START]:asyncfunctionstartCommand():Promise<void>{
20+
returnstart(context)
2121
},
2222
// [COMMANDS.RUN_TEST]: runTest,
2323
// [COMMANDS.LOAD_SOLUTION]: loadSolution,

‎src/editor/commands/start-old.ts

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import*asvscodefrom'vscode'
2+
import*asCRfrom'typings'
3+
4+
importtutorialSetupfrom'../../services/tutorialSetup'
5+
import{isEmptyWorkspace,openReadme}from'../workspace'
6+
import{setWorkspaceRoot}from'../../services/node'
7+
import{setStorage}from'../../editor/storage'
8+
9+
/*
10+
new
11+
if current workspace is empty, use it
12+
if not, open a new folder then start
13+
*/
14+
15+
// async function continueTutorial() {
16+
// // TODO: verify that tutorial is loaded in workspace
17+
// // TODO: verify progress
18+
// // TODO: verify setup
19+
// await loadProgressPosition()
20+
// await openReadme()
21+
// }
22+
23+
asyncfunctionnewTutorial(tutorial:CR.Tutorial){
24+
// if workspace isn't empty, clear it out if given permission
25+
constisEmpty:boolean=awaitisEmptyWorkspace()
26+
if(!isEmpty){
27+
// eslint-disable-next-line
28+
constoptions=['Open a new folder','I\'ll clear the files and folders myself']
29+
constshouldOpenFolder=awaitvscode.window.showQuickPick(options)
30+
if(shouldOpenFolder===options[0]){
31+
awaitvscode.commands.executeCommand('vscode.openFolder')
32+
}
33+
}
34+
35+
awaittutorialSetup(tutorial)
36+
awaitopenReadme()
37+
}
38+
39+
40+
exportdefaultasyncfunctionstart(context:vscode.ExtensionContext):Promise<void>{
41+
console.log('start',context)
42+
43+
44+
return;
45+
46+
// const modes = ['New']
47+
48+
// const canContinue = await validateCanContinue()
49+
// if (canContinue) {
50+
// modes.push('Continue')
51+
// }
52+
53+
// const selectedMode: string | undefined = await vscode.window.showQuickPick(modes)
54+
55+
// if (!selectedMode) {
56+
// throw new Error('No mode selected')
57+
// return
58+
// }
59+
60+
// interface TutorialQuickPickItem extends vscode.QuickPickItem {
61+
// id: string
62+
// }
63+
64+
// // load tutorial summaries
65+
// const tutorialsData: { [id: string]: CR.TutorialSummary } = await api({
66+
// resource: 'getTutorialsSummary',
67+
// })
68+
// const selectableTutorials: TutorialQuickPickItem[] = Object.keys(tutorialsData).map(id => {
69+
// const tutorial = tutorialsData[id]
70+
// return {
71+
// label: tutorial.title,
72+
// description: tutorial.description,
73+
// // detail: '', // optional additional info
74+
// id,
75+
// }
76+
// })
77+
// const selectedTutorial: TutorialQuickPickItem | undefined = await vscode.window.showQuickPick(selectableTutorials)
78+
79+
// if (!selectedTutorial) {
80+
// throw new Error('No tutorial selected')
81+
// }
82+
83+
// // load specific tutorial
84+
// const tutorial: CR.Tutorial | undefined = await fetch({
85+
// resource: 'getTutorial',
86+
// params: { id: selectedTutorial.id },
87+
// })
88+
89+
// if (!tutorial) {
90+
// throw new Error('No tutorial found')
91+
// }
92+
93+
// switch (selectedMode) {
94+
// // new tutorial
95+
// case modes[0]:
96+
// await newTutorial(tutorial)
97+
// break
98+
// // continue
99+
// case modes[1]:
100+
// await continueTutorial()
101+
// break
102+
// }
103+
104+
// // setup hook to run tests on save
105+
106+
107+
// TODO: start
108+
}

‎src/editor/commands/start.ts

Lines changed: 38 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,45 @@
11
import*asvscodefrom'vscode'
2-
import*asCRfrom'typings'
3-
4-
importtutorialSetupfrom'../../services/tutorialSetup'
5-
import{isEmptyWorkspace,openReadme}from'../workspace'
62
import{setWorkspaceRoot}from'../../services/node'
73
import{setStorage}from'../../editor/storage'
8-
importcreateStateMachinefrom'../../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-
asyncfunctionnewTutorial(tutorial:CR.Tutorial){
25-
// if workspace isn't empty, clear it out if given permission
26-
constisEmpty:boolean=awaitisEmptyWorkspace()
27-
if(!isEmpty){
28-
// eslint-disable-next-line
29-
constoptions=['Open a new folder','I\'ll clear the files and folders myself']
30-
constshouldOpenFolder=awaitvscode.window.showQuickPick(options)
31-
if(shouldOpenFolder===options[0]){
32-
awaitvscode.commands.executeCommand('vscode.openFolder')
33-
}
34-
}
4+
import{activateasactivateMachine,defaultasmachine}from'../../state'
5+
import*asstoragefrom'../../services/storage'
6+
import*asgitfrom'../../services/git'
7+
import*asCRfrom'typings'
358

36-
awaittutorialSetup(tutorial)
37-
awaitopenReadme()
9+
letinitialTutorial:CR.Tutorial|undefined
10+
letinitialProgress:CR.Progress={
11+
levels:{},
12+
stages:{},
13+
steps:{},
14+
complete:false,
3815
}
3916

40-
4117
exportdefaultasyncfunctionstart(context:vscode.ExtensionContext):Promise<void>{
42-
console.log('start',context)
43-
44-
// setup connection to workspace
45-
awaitsetWorkspaceRoot()
46-
// set workspace context path
47-
awaitsetStorage(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+
awaitsetWorkspaceRoot()
22+
// set workspace context path
23+
awaitsetStorage(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]=awaitPromise.all([
33+
storage.getTutorial(),
34+
storage.getProgress(),
35+
git.gitVersion(),
36+
git.gitCheckRemoteExists(),
37+
])
38+
initialTutorial=tutorial
39+
initialProgress=progress
40+
constcanContinue=!!(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+
}

‎src/editor/init.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// Import the module and reference it with the alias vscode in your code below
33
import*asvscodefrom'vscode'
44

5+
import{deactivateasdeactivateMachine}from'../state'
56
importcreateCommandsfrom'./commands'
67
importcreateViewsfrom'./views'
7-
importcreateStateMachinefrom'../state'
88

99
// this method is called when your extension is activated
1010
// your extension is activated the very first time the command is executed
@@ -14,13 +14,11 @@ export function activate(context: vscode.ExtensionContext) {
1414
// commands
1515
createCommands(context)
1616

17-
// tasks
18-
// add tasks here
19-
2017
// views
2118
createViews(context)
2219

23-
20+
// tasks
21+
// add tasks here
2422
}
2523

2624
// this method is called when your extension is deactivated
@@ -30,4 +28,6 @@ export function deactivate(context: vscode.ExtensionContext): void {
3028
for(constdisposableofcontext.subscriptions){
3129
disposable.dispose()
3230
}
31+
// shut down state machine
32+
deactivateMachine()
3333
}

‎src/state/actions/index.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import{assign,send}from'xstate'
1+
import{assign}from'xstate'
22
import*asCRfrom'typings'
33
import*asstoragefrom'../../services/storage'
44
import*asgitfrom'../../services/git'
@@ -12,23 +12,6 @@ let initialProgress: CR.Progress = {
1212
}
1313

1414
exportdefault{
15-
start:async()=>{
16-
console.log('ACTION: start')
17-
// verify that the user has a tutorial & progress
18-
// verify git is setup with a coderoad remote
19-
const[tutorial,progress,hasGit,hasGitRemote]=awaitPromise.all([
20-
storage.getTutorial(),
21-
storage.getProgress(),
22-
git.gitVersion(),
23-
git.gitCheckRemoteExists(),
24-
])
25-
initialTutorial=tutorial
26-
initialProgress=progress
27-
constcanContinue=!!(tutorial&&progress&&hasGit&&hasGitRemote)
28-
// if a tutorial exists, "CONTINUE"
29-
// otherwise start from "NEW"
30-
send(canContinue ?'CONTINUE' :'NEW')
31-
},
3215
tutorialLoad:assign({
3316
// load initial data, progress & position
3417
data():CR.TutorialData{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp