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

Commit00e306b

Browse files
authored
Merge pull requestcoderoad#24 from ShMcK/feature/commit-consistency
Feature/commit consistency
2 parentsb8cd7c4 +59ec0d2 commit00e306b

File tree

11 files changed

+4067
-3886
lines changed

11 files changed

+4067
-3886
lines changed

‎package-lock.json

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

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
},
5454
"devDependencies": {
5555
"@types/mocha":"^5.2.7",
56-
"@types/node":"^12.6.2",
56+
"@types/node":"^12.6.8",
5757
"concurrently":"^4.1.1",
5858
"prettier":"^1.18.2",
5959
"tslint":"^5.18.0",

‎src/editor/commands/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,6 @@ export const createCommands = ({ context, machine, storage, git, position }: Cre
8989
// TODO: use actual tutorial repo
9090
awaitPromise.all([git.gitSetupRemote(tutorial.meta.repo),storage.setTutorial(tutorial),storage.resetProgress()])
9191

92-
// TODO: refactor to allow client to call initialization
93-
constpos:CR.Position=awaitposition.getInitial(tutorial)
94-
95-
// eslint-disable-next-line
96-
const{ steps}=tutorial.data
97-
const{ setup}=steps[pos.stepId].actions
98-
awaitgit.gitLoadCommits(setup,dispatch)
9992
machine.send('TUTORIAL_LOADED')
10093
},
10194
[COMMANDS.TUTORIAL_SETUP]:async(tutorial:CR.Tutorial)=>{

‎src/services/git/index.ts

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,51 @@ import { exec, exists } from '../node'
33

44
constgitOrigin='coderoad'
55

6+
conststashAllFiles=async()=>{
7+
console.log('stashAllFiles')
8+
// stash files including untracked (eg. newly created file)
9+
const{ stdout, stderr}=awaitexec(`git stash --include-untracked`)
10+
if(stderr){
11+
console.error(stderr)
12+
thrownewError('Error stashing files')
13+
}
14+
}
15+
16+
constcherryPickCommit=async(commit:string,count=0):Promise<void>=>{
17+
if(count>1){
18+
console.warn('cherry-pick failed')
19+
return
20+
}
21+
try{
22+
const{ stdout}=awaitexec(`git cherry-pick${commit}`)
23+
if(!stdout){
24+
thrownewError('No cherry-pick output')
25+
}
26+
}catch(error){
27+
console.log('cherry-pick-commit failed')
28+
// stash all files if cherry-pick fails
29+
awaitstashAllFiles()
30+
returncherryPickCommit(commit,++count)
31+
}
32+
}
33+
34+
consterrorMessages={
35+
js:{
36+
'node-gyp':'Error running npm setup command'
37+
}
38+
}
39+
640
/*
741
SINGLE git cherry-pick %COMMIT%
8-
MULTIPLE git cherry-pick %COMMIT_START%..%COMMIT_END%
9-
if shell, run shell
42+
if fails, will stash all and retry
1043
*/
1144
exportasyncfunctiongitLoadCommits(actions:CR.TutorialAction,dispatch:CR.EditorDispatch):Promise<void>{
1245
const{ commits, commands, files}=actions
1346

1447
for(constcommitofcommits){
15-
const{ stdout, stderr}=awaitexec(`git cherry-pick${commit}`)
16-
if(stderr){
17-
console.error(stderr)
18-
thrownewError('Error loading commit')
19-
}
48+
// pull a commit from tutorial repo
49+
console.log(`try cherry-pick${commit}`)
50+
awaitcherryPickCommit(commit)
2051
}
2152

2253
if(commands){
@@ -25,10 +56,12 @@ export async function gitLoadCommits(actions: CR.TutorialAction, dispatch: CR.Ed
2556
const{ stdout, stderr}=awaitexec(command)
2657
if(stderr){
2758
console.error(stderr)
28-
29-
if(stderr.match(/node-gyp/)){
30-
// ignored error
31-
thrownewError('Error running setup command')
59+
// langauge specific error messages from running commands
60+
for(constmessageofObject.keys(errorMessages.js)){
61+
if(stderr.match(message)){
62+
// ignored error
63+
thrownewError('Error running setup command')
64+
}
3265
}
3366
}
3467
console.log(`run command:${command}`,stdout)

‎src/state/actions/index.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ export default (dispatch: CR.EditorDispatch) => ({
107107
testStart(){
108108
dispatch('coderoad.run_test')
109109
},
110-
testPass(){
110+
testPass(context:CR.MachineContext):void{
111111
dispatch('coderoad.test_pass')
112+
git.gitSaveCommit(context.position)
112113
},
113114
testFail(){
114115
dispatch('coderoad.test_fail')
@@ -157,18 +158,34 @@ export default (dispatch: CR.EditorDispatch) => ({
157158
returnnextPosition
158159
},
159160
}),
160-
loadLevel(){
161+
loadLevel(context:CR.MachineContext):void{
162+
const{ data, position}=context
161163
console.log('loadLevel')
164+
console.log(position)
165+
const{ levels}=data
166+
constlevel=levels[position.levelId]
167+
168+
// run level setup if it exists
169+
if(level&&level.actions&&level.actions.setup){
170+
git.gitLoadCommits(level.actions.setup,dispatch)
171+
}
162172
},
163173
stageLoadNext(context:CR.MachineContext){
164174
console.log('stageLoadNext')
165175
const{ position}=context
166176
console.log(position)
167177
},
168178
loadStage(context:CR.MachineContext):void{
179+
const{ data, position}=context
169180
console.log('loadStage')
170-
const{ position}=context
171181
console.log(position)
182+
const{ stages}=data
183+
conststage=stages[position.levelId]
184+
185+
// run level setup if it exists
186+
if(stage&&stage.actions&&stage.actions.setup){
187+
git.gitLoadCommits(stage.actions.setup,dispatch)
188+
}
172189
},
173190
//@ts-ignore
174191
updatePosition:assign({

‎src/tutorials/basic.ts

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,29 @@ const basic: CR.Tutorial = {
1717
summary:{
1818
title:'Basic Test',
1919
description:'A basic coding skills example',
20-
levelList:['level1Id'],
20+
levelList:['level1Id','level2Id'],
2121
},
2222
levels:{
2323
level1Id:{
2424
stageList:['stage1Id','stage2Id'],
2525
content:{
26-
title:'Sum Level',
26+
title:'Operators',
2727
text:'A description of this stage',
2828
},
29+
actions:{
30+
setup:{
31+
commits:['aab5f3d'],
32+
commands:['npm install'],
33+
}
34+
}
2935
},
36+
level2Id:{
37+
stageList:['a'],
38+
content:{
39+
title:'Logic',
40+
text:'Some basic logic in level 2'
41+
}
42+
}
3043
},
3144
stages:{
3245
stage1Id:{
@@ -42,7 +55,14 @@ const basic: CR.Tutorial = {
4255
title:'Second Stage',
4356
text:'Going into round 2'
4457
}
45-
}
58+
},
59+
a:{
60+
stepList:['a1','a2'],
61+
content:{
62+
title:'Part 1',
63+
text:'Going into round 1'
64+
}
65+
},
4666
},
4767
steps:{
4868
step1Id:{
@@ -52,12 +72,11 @@ const basic: CR.Tutorial = {
5272
},
5373
actions:{
5474
setup:{
55-
commits:['430500f','8383061'],
56-
commands:['npm install'],
75+
commits:['8fa5ad5'],
5776
files:['src/sum.js'],
5877
},
5978
solution:{
60-
commits:['abbe136'],
79+
commits:['abe3123'],
6180
},
6281
},
6382
hints:[],
@@ -69,11 +88,11 @@ const basic: CR.Tutorial = {
6988
},
7089
actions:{
7190
setup:{
72-
commits:['9cbb518'],
91+
commits:['0e01df8'],
7392
files:['src/multiply.js'],
7493
},
7594
solution:{
76-
commits:['5ae011f'],
95+
commits:['1b9a520'],
7796
},
7897
},
7998
hints:[],
@@ -85,11 +104,11 @@ const basic: CR.Tutorial = {
85104
},
86105
actions:{
87106
setup:{
88-
commits:['70c774c'],
107+
commits:['40802cf'],
89108
files:['src/divide.js'],
90109
},
91110
solution:{
92-
commits:['3180bed'],
111+
commits:['b321a3d'],
93112
},
94113
},
95114
hints:[],
@@ -101,11 +120,11 @@ const basic: CR.Tutorial = {
101120
},
102121
actions:{
103122
setup:{
104-
commits:['16d9699'],
123+
commits:['4db40b4'],
105124
files:['src/modulo.js'],
106125
},
107126
solution:{
108-
commits:['bbf8aa5']
127+
commits:['3580c9d']
109128
}
110129
}
111130
},
@@ -116,11 +135,41 @@ const basic: CR.Tutorial = {
116135
},
117136
actions:{
118137
setup:{
119-
commits:['683c8db'],
138+
commits:['abc1e2d'],
120139
files:['src/power.js'],
121140
},
122141
solution:{
123-
commits:['deaf3a8']
142+
commits:['5d28c25']
143+
}
144+
}
145+
},
146+
a1:{
147+
content:{
148+
title:'Hello',
149+
text:'Return the word "hello"'
150+
},
151+
actions:{
152+
setup:{
153+
commits:['d2c5827'],
154+
files:['src/hello.js'],
155+
},
156+
solution:{
157+
commits:['f668bf7']
158+
}
159+
}
160+
},
161+
a2:{
162+
content:{
163+
title:'Bye',
164+
text:'Return the word "bye"'
165+
},
166+
actions:{
167+
setup:{
168+
commits:['3aa0ccd'],
169+
files:['src/hello.js'],
170+
},
171+
solution:{
172+
commits:['9897785']
124173
}
125174
}
126175
},

‎tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"emitDecoratorMetadata":true,
2121
"paths": {
2222
"typings": ["../typings/index.d.ts"]
23-
}
23+
},
24+
"allowJs":true
2425
},
2526
"exclude": ["node_modules",".vscode-test","build","resources","web-app"]
2627
}

‎typings/index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ export interface TutorialLevel {
66
title:string
77
text:string
88
}
9+
actions?:{
10+
setup:TutorialAction
11+
}
912
}
1013

1114
exportinterfaceTutorialStage{
@@ -14,6 +17,9 @@ export interface TutorialStage {
1417
title:string
1518
text:string
1619
}
20+
actions?:{
21+
setup:TutorialAction
22+
}
1723
}
1824

1925
exportinterfaceTutorialHint{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp