@@ -3,6 +3,8 @@ import * as path from 'path';
33import * as fs from 'fs' ;
44import { fileExists } from '../services/exists' ;
55
6+ let tutorialError = 'This is an error with the tutorial itself' ;
7+
68export function packageJsonExists ( ) : boolean {
79 const pathToPackageJson = path . join ( window . coderoad . dir , 'package.json' ) ;
810 return fileExists ( pathToPackageJson ) ;
@@ -17,18 +19,34 @@ export function loadRootPackageJson(): PackageJson {
1719}
1820
1921function _isTutorial ( name : string ) : boolean {
22+ // has package.json
2023 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 ;
3048 }
31- return false ;
49+ return true ;
3250}
3351
3452export function searchForTutorials ( deps : Object ) : string [ ] {
0 commit comments