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

Commit5363655

Browse files
committed
fix new tutorial process
1 parent295a61a commit5363655

File tree

9 files changed

+74
-63
lines changed

9 files changed

+74
-63
lines changed

‎src/editor/channel.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

‎src/editor/commands/index.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ import { setStorage } from '../storage'
44
importReactWebViewfrom'../ReactWebView'
55
import{isEmptyWorkspace}from'../workspace'
66
import*asCRfrom'typings'
7+
importrunTestfrom'./runTest'
78

89
constCOMMANDS={
910
START:'coderoad.start',
1011
TUTORIAL_LAUNCH:'coderoad.tutorial_launch',
12+
TUTORIAL_SETUP:'coderoad.tutorial_setup',
1113
OPEN_WEBVIEW:'coderoad.open_webview',
1214
SEND_STATE:'coderoad.send_state',
1315
SEND_DATA:'coderoad.send_data',
1416
RECEIVE_ACTION:'coderoad.receive_action',
1517
OPEN_FILE:'coderoad.open_file',
16-
RUN_TEST:'coderoad.test_run',
18+
RUN_TEST:'coderoad.run_test',
1719
}
1820

1921
interfaceCreateCommandProps{
@@ -62,6 +64,19 @@ export const createCommands = ({ context, machine, storage, git, position }: Cre
6264
const{ setup}=steps[pos.stepId].actions
6365
awaitgit.gitLoadCommits(setup)
6466
},
67+
[COMMANDS.TUTORIAL_SETUP]:async(tutorial:CR.Tutorial)=>{
68+
console.log('tutorial setup',tutorial)
69+
// setup onSave hook
70+
constlanguageIds=tutorial.meta.languages
71+
console.log(`languageIds:${languageIds.join(', ')}`)
72+
vscode.workspace.onDidSaveTextDocument((document:vscode.TextDocument)=>{
73+
console.log('save document',document)
74+
if(languageIds.includes(document.languageId)&&document.uri.scheme==='file'){
75+
// do work
76+
vscode.commands.executeCommand('coderoad.run_test')
77+
}
78+
})
79+
},
6580
// open a file
6681
[COMMANDS.OPEN_FILE]:async(relativeFilePath:string)=>{
6782
console.log(`OPEN_FILE${JSON.stringify(relativeFilePath)}`)
@@ -85,6 +100,10 @@ export const createCommands = ({ context, machine, storage, git, position }: Cre
85100
webview.postMessage({type:'SET_DATA', payload})
86101
},
87102
[COMMANDS.RECEIVE_ACTION]:(action:string|CR.Action)=>{
103+
// send received actions from web-app into state machine
88104
machine.send(action)
105+
},
106+
[COMMANDS.RUN_TEST]:()=>{
107+
runTest()
89108
}
90109
})

‎src/editor/commands/runTest.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import{getOutputChannel}from'../channel'
1+
import*asvscodefrom'vscode'
22
import{exec}from'../../services/node'
33
import*asstoragefrom'../../services/storage'
44
import*astestResultfrom'../../services/testResult'
@@ -12,6 +12,15 @@ const shouldExitEarly = (processId: number): boolean => {
1212
returncurrentId!==processId
1313
}
1414

15+
let_channel:vscode.OutputChannel
16+
17+
constgetOutputChannel=(name:string):vscode.OutputChannel=>{
18+
if(!_channel){
19+
_channel=vscode.window.createOutputChannel(name)
20+
}
21+
return_channel
22+
}
23+
1524
exportdefaultasyncfunctionrunTest():Promise<void>{
1625
// increment process id
1726
letprocessId=++currentId

‎src/editor/save.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

‎src/editor/workspace.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,33 @@ export async function isEmptyWorkspace(): Promise<boolean> {
1111
return!stdout.length
1212
}
1313

14-
// TODO: workspace change listener
15-
exportasyncfunctionopenReadme():Promise<void>{
16-
const{ stderr}=awaitexec('ls')
17-
if(stderr){
18-
thrownewError('Error looking for initial file')
19-
}
14+
////TODO: workspace change listener
15+
//export async function openReadme(): Promise<void> {
16+
// const { stderr } = await exec('ls')
17+
// if (stderr) {
18+
// throw new Error('Error looking for initial file')
19+
// }
2020

21-
constfile='README.md'
22-
constfilePath=path.join(vscode.workspace.rootPath||'',file)
23-
console.log('filePath',filePath)
24-
consthasReadme=awaitexists(file)
21+
// const file = 'README.md'
22+
// const filePath = path.join(vscode.workspace.rootPath || '', file)
23+
// console.log('filePath', filePath)
24+
// const hasReadme = await exists(file)
2525

26-
if(!hasReadme){
27-
// add readme if none exists
28-
try{
29-
constcontent='# Welcome to CodeRoad!'
30-
fs.writeFileSync(filePath,content,'utf8')
31-
}catch(error){
32-
thrownewError('Error writing READM.md')
33-
}
34-
}
26+
// if (!hasReadme) {
27+
// // add readme if none exists
28+
// try {
29+
// const content = '# Welcome to CodeRoad!'
30+
// fs.writeFileSync(filePath, content, 'utf8')
31+
// } catch (error) {
32+
// throw new Error('Error writing READM.md')
33+
// }
34+
// }
3535

36-
try{
37-
constopenPath=vscode.Uri.parse(filePath)
38-
constdoc=awaitvscode.workspace.openTextDocument(openPath)
39-
awaitvscode.window.showTextDocument(doc)
40-
}catch(error){
41-
thrownewError('Error opening README doc')
42-
}
43-
}
36+
// try {
37+
// const openPath = vscode.Uri.parse(filePath)
38+
// const doc = await vscode.workspace.openTextDocument(openPath)
39+
// await vscode.window.showTextDocument(doc)
40+
// } catch (error) {
41+
// throw new Error('Error opening README doc')
42+
// }
43+
//}

‎src/services/api/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface Options {
99
}
1010

1111
consttutorialsData:{[key:string]:CR.Tutorial}={
12-
tutorialId:basicTutorial,
12+
[basicTutorial.id]:basicTutorial,
1313
}
1414

1515
// TODO: replace with fetch resource

‎src/state/actions/index.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import * as vscode from 'vscode'
77
import*asstoragefrom'../../services/storage'
88
import*asgitfrom'../../services/git'
99

10-
letinitialTutorial:CR.Tutorial|undefined
11-
letinitialProgress:CR.Progress={
10+
letcurrentTutorial:CR.Tutorial|undefined
11+
letcurrentProgress:CR.Progress={
1212
levels:{},
1313
stages:{},
1414
steps:{},
@@ -32,37 +32,42 @@ export default {
3232
constcanContinue=!!(tutorial&&progress&&hasGit&&hasGitRemote)
3333

3434
if(canContinue){
35-
initialTutorial=tutorial
36-
initialProgress=progress
35+
currentTutorial=tutorial
36+
currentProgress=progress
3737
}
3838

3939
machine.send(canContinue ?'CONTINUE' :'NEW')
4040
},
4141
asynctutorialLaunch(){
4242
// TODO: add selection of tutorial id
4343
consttutorial:CR.Tutorial=awaitapi({resource:'getTutorial',params:{id:'1'}})
44+
console.log('api')
45+
console.log(tutorial)
4446
vscode.commands.executeCommand('coderoad.tutorial_launch',tutorial)
4547
},
48+
tutorialSetup(){
49+
vscode.commands.executeCommand('coderoad.tutorial_setup',currentTutorial)
50+
},
4651
tutorialContinue:assign({
4752
// load initial data, progress & position
4853
data():CR.TutorialData{
4954
console.log('ACTION: tutorialLoad.data')
50-
if(!initialTutorial){
55+
if(!currentTutorial){
5156
thrownewError('No Tutorial loaded')
5257
}
53-
returninitialTutorial.data
58+
returncurrentTutorial.data
5459

5560
},
5661
progress():CR.Progress{
5762
console.log('ACTION: tutorialLoad.progress')
58-
returninitialProgress
63+
returncurrentProgress
5964
},
6065
position(){
6166
console.log('ACTION: tutorialLoad.position')
62-
if(!initialTutorial){
67+
if(!currentTutorial){
6368
thrownewError('No Tutorial loaded')
6469
}
65-
const{ data}=initialTutorial
70+
const{ data}=currentTutorial
6671

6772
constlevelId=data.summary.levelList[0]
6873
conststageId=data.levels[levelId].stageList[0]

‎src/state/machine.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export const machine = Machine<
5858
Tutorial:{
5959
id:'tutorial',
6060
initial:'Summary',
61+
onEntry:['tutorialSetup'],
6162
states:{
6263
LoadNext:{
6364
id:'tutorial-load-next',

‎src/tutorials/basic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import*asCRfrom'typings'
22

33
constbasic:CR.Tutorial={
4-
id:'tutorialId',
4+
id:'1',
55
meta:{
66
version:'0.1.0',
77
repo:'https://github.com/ShMcK/coderoad-tutorial-basic.git',

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp