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

Commitbc4dd2c

Browse files
committed
add skeleton validation
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent429cdf8 commitbc4dd2c

File tree

3 files changed

+53
-41
lines changed

3 files changed

+53
-41
lines changed

‎src/build.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as util from "util";
55
import{parse}from"./utils/parse";
66
import{getArg}from"./utils/args";
77
import{getCommits,CommitLogObject}from"./utils/commits";
8+
importskeletonSchemafrom"./schema/skeleton";
89
importtutorialSchemafrom"./schema/tutorial";
910
import{validateSchema}from"./utils/validateSchema";
1011
import*asTfrom"../typings/tutorial";
@@ -71,25 +72,36 @@ async function build(args: string[]) {
7172
return;
7273
}
7374

74-
// parse yaml config
75-
letconfig;
75+
// parse yamlskeletonconfig
76+
letskeleton;
7677
try{
77-
config=yamlParser.load(_yaml);
78-
// TODO: validate yaml
79-
if(!config||!config.length){
78+
skeleton=yamlParser.load(_yaml);
79+
if(!skeleton||!skeleton.length){
8080
thrownewError("Invalid yaml file contents");
8181
}
8282
}catch(e){
8383
console.error("Error parsing yaml");
8484
console.error(e.message);
8585
}
8686

87+
// validate skeleton based on skeleton json schema
88+
try{
89+
constvalid=validateSchema(skeletonSchema,skeleton);
90+
if(!valid){
91+
console.error("Tutorial validation failed. See above to see what to fix");
92+
return;
93+
}
94+
}catch(e){
95+
console.error("Error validating tutorial schema:");
96+
console.error(e.message);
97+
}
98+
8799
// load git commits to use in parse step
88100
letcommits:CommitLogObject;
89101
try{
90102
commits=awaitgetCommits({
91103
localDir:localPath,
92-
codeBranch:config.config.repo.branch,
104+
codeBranch:skeleton.config.repo.branch,
93105
});
94106
}catch(e){
95107
console.error("Error loading commits:");
@@ -102,7 +114,7 @@ async function build(args: string[]) {
102114
try{
103115
tutorial=awaitparse({
104116
text:_markdown,
105-
config,
117+
skeleton,
106118
commits,
107119
});
108120
}catch(e){
@@ -111,7 +123,7 @@ async function build(args: string[]) {
111123
return;
112124
}
113125

114-
// validate tutorial based on json schema
126+
// validate tutorial based ontutorialjson schema
115127
try{
116128
constvalid=validateSchema(tutorialSchema,tutorial);
117129
if(!valid){

‎src/utils/parse.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,17 @@ export function parseMdContent(md: string): TutorialFrame | never {
9090

9191
typeParseParams={
9292
text:string;
93-
config:Partial<T.Tutorial|any>;
93+
skeleton:Partial<T.Tutorial|any>;
9494
commits:CommitLogObject;
9595
};
9696

9797
exportfunctionparse(params:ParseParams):any{
9898
constmdContent:TutorialFrame=parseMdContent(params.text);
9999

100100
constparsed:Partial<T.Tutorial>={
101-
version:params.config.version,
101+
version:params.skeleton.version,
102102
summary:mdContent.summary,
103-
config:params.config.config||{},
103+
config:params.skeleton.config||{},
104104
levels:[],
105105
};
106106

@@ -114,8 +114,8 @@ export function parse(params: ParseParams): any {
114114
}
115115

116116
// merge content and tutorial
117-
if(params.config.levels&&params.config.levels.length){
118-
parsed.levels=params.config.levels
117+
if(params.skeleton.levels&&params.skeleton.levels.length){
118+
parsed.levels=params.skeleton.levels
119119
.map((level:T.Level,levelIndex:number)=>{
120120
constlevelContent=mdContent.levels[level.id];
121121

‎tests/parse.test.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ Short description to be shown as a tutorial's subtitle.
99
1010
`;
1111

12-
constconfig={version:"0.1.0"};
12+
constskeleton={version:"0.1.0"};
1313
constresult=parse({
1414
text:md,
15-
config,
15+
skeleton,
1616
commits:{},
1717
});
1818
constexpected={
@@ -37,13 +37,13 @@ Description.
3737
Some text
3838
`;
3939

40-
constconfig={
40+
constskeleton={
4141
levels:[{id:"L1"}],
4242
};
4343

4444
constresult=parse({
4545
text:md,
46-
config,
46+
skeleton,
4747
commits:{},
4848
});
4949
constexpected={
@@ -73,7 +73,7 @@ Description.
7373
Some text
7474
`;
7575

76-
constconfig={
76+
constskeleton={
7777
levels:[
7878
{
7979
id:"L1",
@@ -85,7 +85,7 @@ Some text
8585
};
8686
constresult=parse({
8787
text:md,
88-
config,
88+
skeleton,
8989
commits:{},
9090
});
9191
constexpected={
@@ -115,10 +115,10 @@ Description.
115115
Some text that becomes the summary
116116
`;
117117

118-
constconfig={levels:[{id:"L1"}]};
118+
constskeleton={levels:[{id:"L1"}]};
119119
constresult=parse({
120120
text:md,
121-
config,
121+
skeleton,
122122
commits:{},
123123
});
124124
constexpected={
@@ -145,10 +145,10 @@ Description.
145145
Some text that becomes the summary and goes beyond the maximum length of 80 so that it gets truncated at the end
146146
`;
147147

148-
constconfig={levels:[{id:"L1"}]};
148+
constskeleton={levels:[{id:"L1"}]};
149149
constresult=parse({
150150
text:md,
151-
config,
151+
skeleton,
152152
commits:{},
153153
});
154154
constexpected={
@@ -180,10 +180,10 @@ Second line
180180
Third line
181181
`;
182182

183-
constconfig={levels:[{id:"L1"}]};
183+
constskeleton={levels:[{id:"L1"}]};
184184
constresult=parse({
185185
text:md,
186-
config,
186+
skeleton,
187187
commits:{},
188188
});
189189
constexpected={
@@ -215,7 +215,7 @@ First line
215215
216216
The first step
217217
`;
218-
constconfig={
218+
constskeleton={
219219
levels:[
220220
{
221221
id:"L1",
@@ -229,7 +229,7 @@ The first step
229229
};
230230
constresult=parse({
231231
text:md,
232-
config,
232+
skeleton,
233233
commits:{
234234
L1S1Q:["abcdefg1"],
235235
},
@@ -271,7 +271,7 @@ First line
271271
272272
The first step
273273
`;
274-
constconfig={
274+
constskeleton={
275275
levels:[
276276
{
277277
id:"L1",
@@ -285,7 +285,7 @@ The first step
285285
};
286286
constresult=parse({
287287
text:md,
288-
config,
288+
skeleton,
289289
commits:{
290290
L1S1Q:["abcdefg1","123456789"],
291291
},
@@ -327,7 +327,7 @@ First line
327327
328328
The first step
329329
`;
330-
constconfig={
330+
constskeleton={
331331
levels:[
332332
{
333333
id:"L1",
@@ -336,7 +336,7 @@ The first step
336336
};
337337
constresult=parse({
338338
text:md,
339-
config,
339+
skeleton,
340340
commits:{
341341
L1:["abcdefg1"],
342342
},
@@ -372,7 +372,7 @@ First line
372372
373373
The first step
374374
`;
375-
constconfig={
375+
constskeleton={
376376
levels:[
377377
{
378378
id:"L1",
@@ -397,7 +397,7 @@ The first step
397397
};
398398
constresult=parse({
399399
text:md,
400-
config,
400+
skeleton,
401401
commits:{
402402
L1S1Q:["abcdefg1","123456789"],
403403
L1S1A:["1gfedcba","987654321"],
@@ -462,7 +462,7 @@ Second level content.
462462
463463
The third step
464464
`;
465-
constconfig={
465+
constskeleton={
466466
levels:[
467467
{
468468
id:"L1",
@@ -522,7 +522,7 @@ The third step
522522
};
523523
constresult=parse({
524524
text:md,
525-
config,
525+
skeleton,
526526
commits:{
527527
L1S1Q:["abcdef1","123456789"],
528528
L1S1A:["1fedcba","987654321"],
@@ -623,7 +623,7 @@ First level content.
623623
The first step
624624
625625
`;
626-
constconfig={
626+
constskeleton={
627627
levels:[
628628
{
629629
id:"L1",
@@ -637,7 +637,7 @@ The first step
637637
};
638638
constresult=parse({
639639
text:md,
640-
config,
640+
skeleton,
641641
commits:{
642642
L1S1Q:["abcdef1","123456789"],
643643
},
@@ -674,7 +674,7 @@ The first step
674674
Description.
675675
`;
676676

677-
constconfig={
677+
constskeleton={
678678
config:{
679679
testRunner:{
680680
command:"./node_modules/.bin/mocha",
@@ -704,7 +704,7 @@ Description.
704704
};
705705
constresult=parse({
706706
text:md,
707-
config,
707+
skeleton,
708708
commits:{},
709709
});
710710
constexpected={
@@ -747,7 +747,7 @@ Description.
747747
Description.
748748
`;
749749

750-
constconfig={
750+
constskeleton={
751751
config:{
752752
testRunner:{
753753
command:"./node_modules/.bin/mocha",
@@ -774,7 +774,7 @@ Description.
774774
};
775775
constresult=parse({
776776
text:md,
777-
config,
777+
skeleton,
778778
commits:{
779779
INIT:["abcdef1","123456789"],
780780
},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp