11"use strict" ;
22var chalk = require ( 'chalk' ) ;
33var validKeys = {
4- project : [ 'title' , 'description' ] ,
4+ info : [ 'title' , 'description' ] ,
55 chapter : [ 'title' , 'description' , 'pages' ] ,
66 page : [ 'title' , 'description' , 'onPageComplete' , 'tasks' , 'video' , 'link' ] ,
77 task : [ 'description' , 'tests' , 'actions' , 'hints' ]
88} ;
99function lintOutput ( json ) {
1010 var invalidKeys = [ ] ;
1111 var warningKeys = [ ] ;
12- var prKeys = Object . keys ( json . project ) ;
12+ var prKeys = Object . keys ( json . info ) ;
1313 prKeys . forEach ( function ( key ) {
14- if ( validKeys . project . indexOf ( key ) < 0 ) {
15- invalidKeys . push ( { error : "Invalid Project key \"" + key + "\"" , location : 'Project' } ) ;
14+ if ( validKeys . info . indexOf ( key ) < 0 ) {
15+ invalidKeys . push ( {
16+ error : "Invalid Project key \"" + key + "\"" ,
17+ location : 'Project'
18+ } ) ;
1619 }
1720 } ) ;
1821 json . chapters . forEach ( function ( chapter , cIndex ) {
1922 var chKeys = Object . keys ( chapter ) ;
2023 chKeys . forEach ( function ( key ) {
2124 if ( validKeys . chapter . indexOf ( key ) < 0 ) {
22- invalidKeys . push ( { error : "Invalid Chapter key \"" + key + "\"" , location : "ch: " + ( cIndex + 1 ) } ) ;
25+ invalidKeys . push ( {
26+ error : "Invalid Chapter key \"" + key + "\"" ,
27+ location : "ch: " + ( cIndex + 1 )
28+ } ) ;
2329 }
2430 } ) ;
2531 if ( chapter . pages && chapter . pages . length > 0 ) {
2632 chapter . pages . forEach ( function ( page , pIndex ) {
2733 var pKeys = Object . keys ( page ) ;
2834 pKeys . forEach ( function ( key ) {
2935 if ( validKeys . page . indexOf ( key ) < 0 ) {
30- invalidKeys . push ( { error : "Invalid Page key \"" + key + "\"" , location : "ch: " + ( cIndex + 1 ) + ", page: " + ( pIndex + 1 ) } ) ;
36+ invalidKeys . push ( {
37+ error : "Invalid Page key \"" + key + "\"" ,
38+ location : "ch: " + ( cIndex + 1 ) + ", page: " + ( pIndex + 1 )
39+ } ) ;
3140 }
3241 } ) ;
3342 if ( page . tasks && page . tasks . length > 0 ) {
3443 page . tasks . forEach ( function ( task , tIndex ) {
3544 var tKeys = Object . keys ( task ) ;
3645 tKeys . forEach ( function ( key ) {
3746 if ( validKeys . task . indexOf ( key ) < 0 ) {
38- invalidKeys . push ( { error : "Invalid Task key \"" + key + "\"" , location : "ch: " + ( cIndex + 1 ) + ", page: " + ( pIndex + 1 ) + ", task: " + ( tIndex + 1 ) } ) ;
47+ invalidKeys . push ( {
48+ error : "Invalid Task key \"" + key + "\"" ,
49+ location : "ch: " + ( cIndex + 1 ) + ", page: " + ( pIndex + 1 ) + ", task: " + ( tIndex + 1 )
50+ } ) ;
3951 }
4052 } ) ;
4153 if ( ! task . tests || task . tests . length < 1 ) {
42- invalidKeys . push ( { error : 'Missing Task Test' , location : "ch: " + ( cIndex + 1 ) + ", page: " + ( pIndex + 1 ) + ", task: " + ( tIndex + 1 ) } ) ;
54+ invalidKeys . push ( {
55+ error : 'Missing Task Test' ,
56+ location : "ch: " + ( cIndex + 1 ) + ", page: " + ( pIndex + 1 ) + ", task: " + ( tIndex + 1 )
57+ } ) ;
4358 }
4459 } ) ;
4560 }
4661 else {
47- warningKeys . push ( { warning : 'Missing page tasks' , location : "ch: " + ( cIndex + 1 ) + ", page: " + ( pIndex + 1 ) } ) ;
62+ warningKeys . push ( {
63+ warning : 'Missing page tasks' ,
64+ location : "ch: " + ( cIndex + 1 ) + ", page: " + ( pIndex + 1 )
65+ } ) ;
4866 }
4967 } ) ;
5068 }
5169 else {
52- warningKeys . push ( { warning : 'Missing pages' , location : "ch: " + ( cIndex + 1 ) } ) ;
70+ warningKeys . push ( {
71+ warning : 'Missing pages' ,
72+ location : "ch: " + ( cIndex + 1 )
73+ } ) ;
5374 }
5475 } ) ;
5576 if ( warningKeys . length > 0 ) {
@@ -74,14 +95,14 @@ function isValidJSON(text) {
7495 }
7596}
7697exports . isValidJSON = isValidJSON ;
77- function hasProjectInfo ( json ) {
78- var validTitle = json . project . title . length > 0 , validDescription = json . project . description . length > 0 ;
98+ function hasTutorialInfo ( json ) {
99+ var validTitle = json . info . title . length > 0 , validDescription = json . info . description . length > 0 ;
79100 if ( ! ( validTitle && validDescription ) ) {
80101 console . log ( chalk . red ( "\n Your tutorial is missing basic project information. Check the project title & description.\n " ) ) ;
81102 process . exit ( 1 ) ;
82103 }
83104}
84- exports . hasProjectInfo = hasProjectInfo ;
105+ exports . hasTutorialInfo = hasTutorialInfo ;
85106function hasPage ( json ) {
86107 if ( ! ( json . chapters [ 0 ] . pages . length > 0 && ! ! json . chapters [ 0 ] . pages [ 0 ] . title ) ) {
87108 console . log ( chalk . red ( "\n Your tutorial requires at least one page.\n " ) ) ;
0 commit comments