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

Commit8740c1d

Browse files
committed
migrate to graphql-request on server
1 parent39af55d commit8740c1d

File tree

10 files changed

+414
-385
lines changed

10 files changed

+414
-385
lines changed

‎package-lock.json

Lines changed: 32 additions & 22 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@
2929
"watch":"tsc -watch -p ./"
3030
},
3131
"dependencies": {
32-
"axios":"^0.19.0",
3332
"dotenv":"^8.1.0",
3433
"graphql":"^14.4.2",
34+
"graphql-request":"^1.8.2",
35+
"graphql-tag":"^2.10.1",
3536
"vscode":"^1.1.36",
3637
"xstate":"^4.6.7"
3738
},

‎src/editor/commands/index.ts

Lines changed: 131 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,149 +1,154 @@
1-
import{join}from'path'
1+
import{join}from'path'
22
import*asCRfrom'typings'
3+
import*asGfrom'typings/graphql'
34
import*asvscodefrom'vscode'
45
importReactWebViewfrom'../ReactWebView'
5-
import{setStorage}from'../storage'
6-
import{isEmptyWorkspace}from'../workspace'
6+
import{setStorage}from'../storage'
7+
import{isEmptyWorkspace}from'../workspace'
78
importrunTestfrom'./runTest'
89

910
constCOMMANDS={
10-
START:'coderoad.start',
11-
TUTORIAL_LAUNCH:'coderoad.tutorial_launch',
12-
TUTORIAL_SETUP:'coderoad.tutorial_setup',
13-
OPEN_WEBVIEW:'coderoad.open_webview',
14-
SEND_STATE:'coderoad.send_state',
15-
SEND_DATA:'coderoad.send_data',
16-
RECEIVE_ACTION:'coderoad.receive_action',
17-
OPEN_FILE:'coderoad.open_file',
18-
RUN_TEST:'coderoad.run_test',
19-
TEST_PASS:'coderoad.test_pass',
20-
TEST_FAIL:'coderoad.test_fail',
11+
START:'coderoad.start',
12+
TUTORIAL_LAUNCH:'coderoad.tutorial_launch',
13+
TUTORIAL_SETUP:'coderoad.tutorial_setup',
14+
OPEN_WEBVIEW:'coderoad.open_webview',
15+
SEND_STATE:'coderoad.send_state',
16+
SEND_DATA:'coderoad.send_data',
17+
RECEIVE_ACTION:'coderoad.receive_action',
18+
OPEN_FILE:'coderoad.open_file',
19+
RUN_TEST:'coderoad.run_test',
20+
TEST_PASS:'coderoad.test_pass',
21+
TEST_FAIL:'coderoad.test_fail',
2122
}
2223

2324
interfaceCreateCommandProps{
24-
context:vscode.ExtensionContext
25-
machine:CR.StateMachine
26-
storage:any
27-
git:any
28-
position:any
25+
context:vscode.ExtensionContext
26+
machine:CR.StateMachine
27+
storage:any
28+
git:any
29+
position:any
2930
}
3031

3132
constresetLayout=()=>{
32-
vscode.commands.executeCommand('vscode.setEditorLayout',{
33-
orientation:0,
34-
groups:[{groups:[{}],size:0.6},{groups:[{}],size:0.4}],
35-
})
33+
vscode.commands.executeCommand('vscode.setEditorLayout',{
34+
orientation:0,
35+
groups:[{groups:[{}],size:0.6},{groups:[{}],size:0.4}],
36+
})
3637
}
3738

38-
exportconstcreateCommands=({context, machine, storage, git, position}:CreateCommandProps)=>{
39-
// React panel webview
40-
letwebview:any
39+
exportconstcreateCommands=({context, machine, storage, git, position}:CreateCommandProps)=>{
40+
// React panel webview
41+
letwebview:any
4142

42-
return{
43-
// initialize
44-
[COMMANDS.START]:()=>{
43+
return{
44+
// initialize
45+
[COMMANDS.START]:()=>{
4546

46-
letwebviewState:'INITIALIZING'|'RESTARTING'
47-
if(!webview){
48-
webviewState='INITIALIZING'
49-
}elseif(webview.loaded){
50-
// already loaded
51-
vscode.window.showInformationMessage('CodeRoad already open')
52-
return
53-
}else{
54-
webviewState='RESTARTING'
55-
}
47+
letwebviewState:'INITIALIZING'|'RESTARTING'
48+
if(!webview){
49+
webviewState='INITIALIZING'
50+
}elseif(webview.loaded){
51+
// already loaded
52+
vscode.window.showInformationMessage('CodeRoad already open')
53+
return
54+
}else{
55+
webviewState='RESTARTING'
56+
}
5657

57-
setStorage(context.workspaceState)
58+
setStorage(context.workspaceState)
5859

59-
// activate machine
60-
webview=newReactWebView(context.extensionPath)
61-
if(webviewState==='INITIALIZING'){
62-
machine.activate()
63-
}elseif(webviewState==='RESTARTING'){
64-
setTimeout(()=>{
65-
// timeout hack to make data update on new windows
66-
//@ts-ignore
67-
machine.refresh()
68-
},1000)
69-
}
70-
},
71-
// open React webview
72-
[COMMANDS.OPEN_WEBVIEW]:(column:number=vscode.ViewColumn.Two)=>{
73-
// setup 1x1 horizontal layout
74-
resetLayout()
75-
constcallback=()=>{
76-
machine.send('WEBVIEW_INITIALIZED')
77-
}
78-
webview.createOrShow(column,callback)
79-
},
80-
// launch a new tutorial
81-
// NOTE: may be better to move into action as logic is primarily non-vscode
82-
[COMMANDS.TUTORIAL_LAUNCH]:async({tutorial, dispatch}:any)=>{
83-
console.log('launch tutorial')
60+
// activate machine
61+
webview=newReactWebView(context.extensionPath)
62+
if(webviewState==='INITIALIZING'){
63+
machine.activate()
64+
}elseif(webviewState==='RESTARTING'){
65+
setTimeout(()=>{
66+
// timeout hack to make data update on new windows
67+
//@ts-ignore
68+
machine.refresh()
69+
},1000)
70+
}
71+
},
72+
// open React webview
73+
[COMMANDS.OPEN_WEBVIEW]:(column:number=vscode.ViewColumn.Two)=>{
74+
// setup 1x1 horizontal layout
75+
resetLayout()
76+
constcallback=()=>{
77+
machine.send('WEBVIEW_INITIALIZED')
78+
}
79+
webview.createOrShow(column,callback)
80+
},
81+
// launch a new tutorial
82+
// NOTE: may be better to move into action as logic is primarily non-vscode
83+
[COMMANDS.TUTORIAL_LAUNCH]:async(tutorial:G.Tutorial)=>{
84+
console.log('launch tutorial')
8485

85-
awaitisEmptyWorkspace()
86+
awaitisEmptyWorkspace()
8687

87-
awaitgit.gitInitIfNotExists()
88+
awaitgit.gitInitIfNotExists()
8889

89-
// TODO: use actual tutorial repo
90-
awaitPromise.all([git.gitSetupRemote(tutorial.meta.repo),storage.setTutorial(tutorial),storage.resetProgress()])
90+
if(!tutorial.repo||!tutorial.repo.uri){
91+
thrownewError('Tutorial repo uri not found')
92+
}
9193

92-
machine.send('TUTORIAL_LOADED')
93-
},
94-
[COMMANDS.TUTORIAL_SETUP]:async(tutorial:CR.Tutorial)=>{
95-
console.log('tutorial setup',tutorial)
96-
// setup onSave hook
97-
constlanguageIds=tutorial.meta.languages
98-
console.log(`languageIds:${languageIds.join(', ')}`)
99-
vscode.workspace.onDidSaveTextDocument((document:vscode.TextDocument)=>{
100-
console.log('save document',document)
101-
if(languageIds.includes(document.languageId)&&document.uri.scheme==='file'){
102-
// do work
103-
machine.send('TEST_RUN')
104-
}
105-
})
106-
},
107-
// open a file
108-
[COMMANDS.OPEN_FILE]:async(relativeFilePath:string)=>{
109-
console.log(`OPEN_FILE${JSON.stringify(relativeFilePath)}`)
110-
try{
111-
constworkspaceRoot=vscode.workspace.rootPath
112-
if(!workspaceRoot){
113-
thrownewError('No workspace root path')
114-
}
115-
constabsoluteFilePath=join(workspaceRoot,relativeFilePath)
116-
constdoc=awaitvscode.workspace.openTextDocument(absoluteFilePath)
117-
awaitvscode.window.showTextDocument(doc,vscode.ViewColumn.One)
118-
// there are times when intialization leave the panel behind any files opened
119-
// ensure the panel is redrawn on the right side first
120-
webview.createOrShow(vscode.ViewColumn.Two)
121-
}catch(error){
122-
console.log(`Failed to open file${relativeFilePath}`,error)
123-
}
124-
},
125-
// send messages to webview
126-
[COMMANDS.SEND_STATE]:(payload:{data:any;state:any})=>{
127-
webview.postMessage({type:'SET_STATE', payload})
128-
},
129-
[COMMANDS.SEND_DATA]:(payload:{data:any})=>{
130-
webview.postMessage({type:'SET_DATA', payload})
131-
},
132-
[COMMANDS.RECEIVE_ACTION]:(action:string|CR.Action)=>{
133-
// send received actions from web-app into state machine
134-
machine.send(action)
135-
},
136-
[COMMANDS.RUN_TEST]:()=>{
137-
runTest({
138-
onSuccess:()=>machine.send('TEST_PASS'),
139-
onFail:()=>machine.send('TEST_FAIL'),
140-
})
141-
},
142-
[COMMANDS.TEST_PASS]:()=>{
143-
vscode.window.showInformationMessage('PASS')
144-
},
145-
[COMMANDS.TEST_FAIL]:()=>{
146-
vscode.window.showWarningMessage('FAIL')
147-
},
148-
}
94+
// TODO: use actual tutorial repo
95+
awaitPromise.all([git.gitSetupRemote(tutorial.repo.uri),storage.setTutorial(tutorial),storage.resetProgress()])
96+
97+
machine.send('TUTORIAL_LOADED')
98+
},
99+
[COMMANDS.TUTORIAL_SETUP]:async(tutorial:CR.Tutorial)=>{
100+
console.log('tutorial setup',tutorial)
101+
// setup onSave hook
102+
constlanguageIds=tutorial.meta.languages
103+
console.log(`languageIds:${languageIds.join(', ')}`)
104+
vscode.workspace.onDidSaveTextDocument((document:vscode.TextDocument)=>{
105+
console.log('save document',document)
106+
if(languageIds.includes(document.languageId)&&document.uri.scheme==='file'){
107+
// do work
108+
machine.send('TEST_RUN')
109+
}
110+
})
111+
},
112+
// open a file
113+
[COMMANDS.OPEN_FILE]:async(relativeFilePath:string)=>{
114+
console.log(`OPEN_FILE${JSON.stringify(relativeFilePath)}`)
115+
try{
116+
constworkspaceRoot=vscode.workspace.rootPath
117+
if(!workspaceRoot){
118+
thrownewError('No workspace root path')
119+
}
120+
constabsoluteFilePath=join(workspaceRoot,relativeFilePath)
121+
constdoc=awaitvscode.workspace.openTextDocument(absoluteFilePath)
122+
awaitvscode.window.showTextDocument(doc,vscode.ViewColumn.One)
123+
// there are times when intialization leave the panel behind any files opened
124+
// ensure the panel is redrawn on the right side first
125+
webview.createOrShow(vscode.ViewColumn.Two)
126+
}catch(error){
127+
console.log(`Failed to open file${relativeFilePath}`,error)
128+
}
129+
},
130+
// send messages to webview
131+
[COMMANDS.SEND_STATE]:(payload:{data:any;state:any})=>{
132+
webview.postMessage({type:'SET_STATE', payload})
133+
},
134+
[COMMANDS.SEND_DATA]:(payload:{data:any})=>{
135+
webview.postMessage({type:'SET_DATA', payload})
136+
},
137+
[COMMANDS.RECEIVE_ACTION]:(action:string|CR.Action)=>{
138+
// send received actions from web-app into state machine
139+
machine.send(action)
140+
},
141+
[COMMANDS.RUN_TEST]:()=>{
142+
runTest({
143+
onSuccess:()=>machine.send('TEST_PASS'),
144+
onFail:()=>machine.send('TEST_FAIL'),
145+
})
146+
},
147+
[COMMANDS.TEST_PASS]:()=>{
148+
vscode.window.showInformationMessage('PASS')
149+
},
150+
[COMMANDS.TEST_FAIL]:()=>{
151+
vscode.window.showWarningMessage('FAIL')
152+
},
153+
}
149154
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp