@@ -3,6 +3,8 @@ import * as path from 'path';
3
3
import * as fs from 'fs' ;
4
4
import { fileExists } from '../services/exists' ;
5
5
6
+ let tutorialError = 'This is an error with the tutorial itself' ;
7
+
6
8
export function packageJsonExists ( ) :boolean {
7
9
const pathToPackageJson = path . join ( window . coderoad . dir , 'package.json' ) ;
8
10
return fileExists ( pathToPackageJson ) ;
@@ -17,18 +19,34 @@ export function loadRootPackageJson(): PackageJson {
17
19
}
18
20
19
21
function _isTutorial ( name :string ) :boolean {
22
+ // has package.json
20
23
let pathToTutorialPackageJson = path . join ( window . coderoad . dir , 'node_modules' , name , 'package.json' ) ;
21
- if ( fileExists ( pathToTutorialPackageJson ) ) {
22
- // has package.json
23
- let packageJson = JSON . parse ( fs . readFileSync ( pathToTutorialPackageJson , 'utf8' ) ) ;
24
- // main path to coderoad.json
25
- if ( packageJson . main && packageJson . main . match ( / c o d e r o a d .j s o n $ / ) ) {
26
- let pathToCoderoadJson = path . join ( window . coderoad . dir , 'node_modules' , name , packageJson . main ) ;
27
- // coderoad.json file exists
28
- return fileExists ( pathToCoderoadJson ) ;
29
- }
24
+ if ( ! fileExists ( pathToTutorialPackageJson ) ) {
25
+ console . log ( `Error with${ name } : no package.json file found.${ tutorialError } ` ) ;
26
+ return false ;
27
+ }
28
+ // main path to coderoad.json
29
+ let packageJson = JSON . parse ( fs . readFileSync ( pathToTutorialPackageJson , 'utf8' ) ) ;
30
+ if ( ! packageJson . main && packageJson . main . match ( / c o d e r o a d .j s o n $ / ) ) {
31
+ console . log ( `Error with${ name } : main does not load a coderoad.json file.${ tutorialError } ` ) ;
32
+ return false ;
33
+ }
34
+ // coderoad.json file exists
35
+ let pathToCoderoadJson = path . join ( window . coderoad . dir , 'node_modules' , name , packageJson . main ) ;
36
+ if ( ! fileExists ( pathToCoderoadJson ) ) {
37
+ console . log ( `Error with${ name } : no coderoad.json file.${ tutorialError } ` ) ;
38
+ return false ;
39
+ } ;
40
+ if ( ! packageJson . config || ! packageJson . config . testRunner ) {
41
+ console . log ( `Error with${ name } : no test runner specified.${ tutorialError } ` ) ;
42
+ return false ;
43
+ }
44
+ let pathToTestRunner = path . join ( window . coderoad . dir , 'node_modules' , packageJson . config . testRunner ) ;
45
+ if ( ! fileExists ( pathToTestRunner ) ) {
46
+ console . log ( `Error with${ name } :${ packageJson . config . testRunner } test runner not installed` ) ;
47
+ return false ;
30
48
}
31
- return false ;
49
+ return true ;
32
50
}
33
51
34
52
export function searchForTutorials ( deps :Object ) :string [ ] {