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

Commita92d52f

Browse files
committed
heavy refactoring
1 parent57675e5 commita92d52f

File tree

12 files changed

+333
-432
lines changed

12 files changed

+333
-432
lines changed

‎src/editor/commands/loadSolution.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import*asCRfrom'typings'
22
import*asGfrom'typings/graphql'
3+
import{TutorialModel}from'../../services/tutorial'
34
import*asstoragefrom'../../services/storage'
45
import{gitLoadCommits,gitClear}from'../../services/git'
56

6-
exportdefaultasyncfunctionloadSolution(dispatch:CR.EditorDispatch):Promise<void>{
7+
exportdefaultasyncfunctionloadSolution(dispatch:CR.EditorDispatch,tutorialModel:TutorialModel):Promise<void>{
78
const[position,tutorial]:[CR.Position,G.Tutorial|undefined]=awaitPromise.all([
89
storage.getPosition(),
910
storage.getTutorial(),
@@ -16,17 +17,10 @@ export default async function loadSolution(dispatch: CR.EditorDispatch): Promise
1617
}
1718
// eslint-disable-next-line
1819

19-
try{
20-
constsolution=tutorial.version
21-
.levels.find((l:G.Level)=>l.id===position.levelId)
22-
.stages.find((s:G.Stage)=>s.id===position.stageId)
23-
.steps.find((s:G.Step)=>s.id===position.stepId)
24-
.solution
20+
conststep=tutorialModel.step()
21+
constsolution=step.solution
2522

26-
awaitgitClear()
27-
awaitgitLoadCommits(solution,dispatch)
28-
}catch(error){
29-
thrownewError(error)
30-
}
23+
awaitgitClear()
24+
awaitgitLoadCommits(solution,dispatch)
3125

3226
}

‎src/editor/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import*asvscodefrom'vscode'
22
import*asCRfrom'typings'
33
import{createCommands}from'./commands'
4-
import*asstoragefrom'../services/storage'
54
import*asgitfrom'../services/git'
6-
import*aspositionfrom'../services/position'
75

86
interfaceProps{
97
machine:CR.StateMachine

‎src/services/git/index.ts

Lines changed: 125 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
1+
import*asGfrom'typings/graphql'
12
import*asCRfrom'typings'
2-
import{exec,exists}from'../node'
3+
import{exec,exists}from'../node'
34
importerrorMessagesfrom'./errorMessages'
45

56
constgitOrigin='coderoad'
67

78
conststashAllFiles=async()=>{
8-
console.log('stashAllFiles')
9-
// stash files including untracked (eg. newly created file)
10-
const{stdout, stderr}=awaitexec(`git stash --include-untracked`)
11-
if(stderr){
12-
console.error(stderr)
13-
thrownewError('Error stashing files')
14-
}
9+
console.log('stashAllFiles')
10+
// stash files including untracked (eg. newly created file)
11+
const{stdout, stderr}=awaitexec(`git stash --include-untracked`)
12+
if(stderr){
13+
console.error(stderr)
14+
thrownewError('Error stashing files')
15+
}
1516
}
1617

1718
constcherryPickCommit=async(commit:string,count=0):Promise<void>=>{
18-
if(count>1){
19-
console.warn('cherry-pick failed')
20-
return
21-
}
22-
try{
23-
const{stdout}=awaitexec(`git cherry-pick${commit}`)
24-
if(!stdout){
25-
thrownewError('No cherry-pick output')
26-
}
27-
}catch(error){
28-
console.log('cherry-pick-commit failed')
29-
// stash all files if cherry-pick fails
30-
awaitstashAllFiles()
31-
returncherryPickCommit(commit,++count)
32-
}
19+
if(count>1){
20+
console.warn('cherry-pick failed')
21+
return
22+
}
23+
try{
24+
const{stdout}=awaitexec(`git cherry-pick${commit}`)
25+
if(!stdout){
26+
thrownewError('No cherry-pick output')
27+
}
28+
}catch(error){
29+
console.log('cherry-pick-commit failed')
30+
// stash all files if cherry-pick fails
31+
awaitstashAllFiles()
32+
returncherryPickCommit(commit,++count)
33+
}
3334
}
3435

3536

@@ -38,38 +39,38 @@ const cherryPickCommit = async (commit: string, count = 0): Promise<void> => {
3839
SINGLE git cherry-pick %COMMIT%
3940
if fails, will stash all and retry
4041
*/
41-
exportasyncfunctiongitLoadCommits(actions:CR.TutorialAction,dispatch:CR.EditorDispatch):Promise<void>{
42-
const{commits, commands, files}=actions
43-
44-
for(constcommitofcommits){
45-
// pull a commit from tutorial repo
46-
console.log(`try cherry-pick${commit}`)
47-
awaitcherryPickCommit(commit)
48-
}
49-
50-
if(commands){
51-
// TODO: run shell as task
52-
for(constcommandofcommands){
53-
const{stdout, stderr}=awaitexec(command)
54-
if(stderr){
55-
console.error(stderr)
56-
// langauge specific error messages from running commands
57-
for(constmessageofObject.keys(errorMessages.js)){
58-
if(stderr.match(message)){
59-
// ignored error
60-
thrownewError('Error running setup command')
61-
}
62-
}
63-
}
64-
console.log(`run command:${command}`,stdout)
65-
}
66-
}
67-
68-
if(files){
69-
for(constfilePathoffiles){
70-
dispatch('coderoad.open_file',filePath)
71-
}
72-
}
42+
exportasyncfunctiongitLoadCommits(actions:G.StepActions,editorDispatch:CR.EditorDispatch):Promise<void>{
43+
const{commits, commands, files}=actions
44+
45+
for(constcommitofcommits){
46+
// pull a commit from tutorial repo
47+
console.log(`try cherry-pick${commit}`)
48+
awaitcherryPickCommit(commit)
49+
}
50+
51+
if(commands){
52+
// TODO: run shell as task
53+
for(constcommandofcommands){
54+
const{stdout, stderr}=awaitexec(command)
55+
if(stderr){
56+
console.error(stderr)
57+
// langauge specific error messages from running commands
58+
for(constmessageofObject.keys(errorMessages.js)){
59+
if(stderr.match(message)){
60+
// ignored error
61+
thrownewError('Error running setup command')
62+
}
63+
}
64+
}
65+
console.log(`run command:${command}`,stdout)
66+
}
67+
}
68+
69+
if(files){
70+
for(constfilePathoffiles){
71+
editorDispatch('coderoad.open_file',filePath)
72+
}
73+
}
7374
}
7475

7576
/*
@@ -78,96 +79,96 @@ export async function gitLoadCommits(actions: CR.TutorialAction, dispatch: CR.Ed
7879
*/
7980

8081
exportasyncfunctiongitSaveCommit(position:CR.Position):Promise<void>{
81-
const{levelId, stageId, stepId}=position
82-
const{stdout, stderr}=awaitexec(`git commit -am 'completed${levelId}/${stageId}/${stepId}'`)
83-
if(stderr){
84-
console.error(stderr)
85-
thrownewError('Error saving progress to Git')
86-
}
87-
console.log('save with commit & continue stdout',stdout)
82+
const{levelId, stageId, stepId}=position
83+
const{stdout, stderr}=awaitexec(`git commit -am 'completed${levelId}/${stageId}/${stepId}'`)
84+
if(stderr){
85+
console.error(stderr)
86+
thrownewError('Error saving progress to Git')
87+
}
88+
console.log('save with commit & continue stdout',stdout)
8889
}
8990

9091
exportasyncfunctiongitClear():Promise<void>{
91-
try{
92-
// commit progress to git
93-
const{stderr}=awaitexec('git reset HEAD --hard && git clean -fd')
94-
if(!stderr){
95-
return
96-
}
97-
console.error(stderr)
98-
}catch(error){
99-
console.error(error)
100-
}
101-
thrownewError('Error cleaning up current unsaved work')
92+
try{
93+
// commit progress to git
94+
const{stderr}=awaitexec('git reset HEAD --hard && git clean -fd')
95+
if(!stderr){
96+
return
97+
}
98+
console.error(stderr)
99+
}catch(error){
100+
console.error(error)
101+
}
102+
thrownewError('Error cleaning up current unsaved work')
102103
}
103104

104105
exportasyncfunctiongitVersion():Promise<string|boolean>{
105-
const{stdout, stderr}=awaitexec('git --version')
106-
if(!stderr){
107-
constmatch=stdout.match(/^gitversion(\d+\.)?(\d+\.)?(\*|\d+)/)
108-
if(match){
109-
// eslint-disable-next-line
110-
const[_,major,minor,patch]=match
111-
return`${major}${minor}${patch}`
112-
}
113-
}
114-
thrownewError('Git not installed. Please install Git')
106+
const{stdout, stderr}=awaitexec('git --version')
107+
if(!stderr){
108+
constmatch=stdout.match(/^gitversion(\d+\.)?(\d+\.)?(\*|\d+)/)
109+
if(match){
110+
// eslint-disable-next-line
111+
const[_,major,minor,patch]=match
112+
return`${major}${minor}${patch}`
113+
}
114+
}
115+
thrownewError('Git not installed. Please install Git')
115116
}
116117

117118
asyncfunctiongitInit():Promise<void>{
118-
const{stderr}=awaitexec('git init')
119-
if(stderr){
120-
thrownewError('Error initializing Gits')
121-
}
119+
const{stderr}=awaitexec('git init')
120+
if(stderr){
121+
thrownewError('Error initializing Gits')
122+
}
122123
}
123124

124125
exportasyncfunctiongitInitIfNotExists():Promise<void>{
125-
consthasGit=awaitgitVersion()
126+
consthasGit=awaitgitVersion()
126127

127-
if(!hasGit){
128-
thrownewError('Git must be installed')
129-
}
128+
if(!hasGit){
129+
thrownewError('Git must be installed')
130+
}
130131

131-
consthasGitInit=exists('.git')
132-
if(!hasGitInit){
133-
awaitgitInit()
134-
}
132+
consthasGitInit=exists('.git')
133+
if(!hasGitInit){
134+
awaitgitInit()
135+
}
135136
}
136137

137138
exportasyncfunctiongitAddRemote(repo:string):Promise<void>{
138-
const{stderr}=awaitexec(`git remote add${gitOrigin}${repo} && git fetch${gitOrigin}`)
139-
if(stderr){
140-
constalreadyExists=stderr.match(`${gitOrigin} already exists.`)
141-
constsuccessfulNewBranch=stderr.match('new branch')
142-
143-
// validate the response is acceptable
144-
if(!alreadyExists&&!successfulNewBranch){
145-
console.error(stderr)
146-
thrownewError('Error adding git remote')
147-
}
148-
}
139+
const{stderr}=awaitexec(`git remote add${gitOrigin}${repo} && git fetch${gitOrigin}`)
140+
if(stderr){
141+
constalreadyExists=stderr.match(`${gitOrigin} already exists.`)
142+
constsuccessfulNewBranch=stderr.match('new branch')
143+
144+
// validate the response is acceptable
145+
if(!alreadyExists&&!successfulNewBranch){
146+
console.error(stderr)
147+
thrownewError('Error adding git remote')
148+
}
149+
}
149150
}
150151

151152
exportasyncfunctiongitCheckRemoteExists():Promise<boolean>{
152-
try{
153-
const{stdout, stderr}=awaitexec('git remote -v')
154-
if(stderr){
155-
returnfalse
156-
}
157-
// string match on remote output
158-
// TODO: improve the specificity of this regex
159-
return!!stdout.match(gitOrigin)
160-
}catch(error){
161-
returnfalse
162-
}
153+
try{
154+
const{stdout, stderr}=awaitexec('git remote -v')
155+
if(stderr){
156+
returnfalse
157+
}
158+
// string match on remote output
159+
// TODO: improve the specificity of this regex
160+
return!!stdout.match(gitOrigin)
161+
}catch(error){
162+
returnfalse
163+
}
163164
}
164165

165166
exportasyncfunctiongitSetupRemote(repo:string):Promise<void>{
166-
// check coderoad remote not taken
167-
consthasRemote=awaitgitCheckRemoteExists()
168-
// git remote add coderoad tutorial
169-
// git fetch coderoad
170-
if(!hasRemote){
171-
awaitgitAddRemote(repo)
172-
}
167+
// check coderoad remote not taken
168+
consthasRemote=awaitgitCheckRemoteExists()
169+
// git remote add coderoad tutorial
170+
// git fetch coderoad
171+
if(!hasRemote){
172+
awaitgitAddRemote(repo)
173+
}
173174
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp