|
| 1 | +"use strict"; |
| 2 | +varpath=require('path'); |
| 3 | +varexists_1=require('./exists'); |
| 4 | +functionsetGlobals(config){ |
| 5 | +window.coderoad=Object.assign(window.coderoad,{ |
| 6 | +tutorial:config.name, |
| 7 | +suffix:config.config.testSuffix.substring(config.config.testSuffix.lastIndexOf('.')+1,config.config.testSuffix.length), |
| 8 | +tutorialDir:path.join(window.coderoad.dir,'node_modules',config.name,config.config.testDir), |
| 9 | +testRunner:config.config.testRunner, |
| 10 | +testRunnerOptions:config.config.testRunnerOptions||{} |
| 11 | +}); |
| 12 | +loadRepo(config); |
| 13 | +loadRunnerDep(config); |
| 14 | +} |
| 15 | +exports.setGlobals=setGlobals; |
| 16 | +functionloadRunnerDep(config){ |
| 17 | +varflatDep=path.join(window.coderoad.dir,'node_modules',config.config.testRunner,'package.json'); |
| 18 | +vartreeDep=path.join(window.coderoad.dir,'node_modules',config.name,'node_modules',config.config.testRunner,'package.json'); |
| 19 | +varrunnerMain; |
| 20 | +varrunnerRoot; |
| 21 | +if(exists_1.fileExists(flatDep)){ |
| 22 | +runnerMain=require(flatDep).main; |
| 23 | +runnerRoot=flatDep; |
| 24 | +} |
| 25 | +elseif(exists_1.fileExists(treeDep)){ |
| 26 | +runnerMain=require(treeDep).main; |
| 27 | +runnerRoot=treeDep; |
| 28 | +} |
| 29 | +else{ |
| 30 | +varmessage='Error loading test runner. Post an issue. https://github.com/coderoad/atom-coderoad/issues'; |
| 31 | +console.log(message); |
| 32 | +throwmessage; |
| 33 | +} |
| 34 | +varslash=window.coderoad.win ?'\\' :'/'; |
| 35 | +runnerMain=path.join.apply(null,runnerMain.split(slash)); |
| 36 | +runnerRoot=runnerRoot.substring(0,runnerRoot.lastIndexOf(slash)); |
| 37 | +varpathToMain=path.join(runnerRoot,runnerMain); |
| 38 | +if(!!require(pathToMain).default){ |
| 39 | +window.coderoad.runner=require(pathToMain).default; |
| 40 | +} |
| 41 | +else{ |
| 42 | +window.coderoad.runner=require(pathToMain); |
| 43 | +} |
| 44 | +} |
| 45 | +functionloadRepo(config){ |
| 46 | +if(config.bugs&&config.bugs.url){ |
| 47 | +window.coderoad.issuesPath=config.bugs.url; |
| 48 | +} |
| 49 | +if(config.repo&&config.repo.url){ |
| 50 | +varrepo=config.repo.url; |
| 51 | +if(!!repo.match(/\.git$/)){ |
| 52 | +repo=repo.slice(0,repo.length-4); |
| 53 | +} |
| 54 | +window.coderoad.repo=repo; |
| 55 | +} |
| 56 | +window.coderoad.edit=config.config.edit&&!!window.coderoad.repo||false; |
| 57 | +} |