|
| 1 | +"use strict"; |
| 2 | +var path = require('path'); |
| 3 | +var exists_1 = require('./exists'); |
| 4 | +function setGlobals(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 | +function loadRunnerDep(config) { |
| 17 | + var flatDep = path.join(window.coderoad.dir, 'node_modules', config.config.testRunner, 'package.json'); |
| 18 | + var treeDep = path.join(window.coderoad.dir, 'node_modules', config.name, 'node_modules', config.config.testRunner, 'package.json'); |
| 19 | + var runnerMain; |
| 20 | + var runnerRoot; |
| 21 | + if (exists_1.fileExists(flatDep)) { |
| 22 | + runnerMain = require(flatDep).main; |
| 23 | + runnerRoot = flatDep; |
| 24 | + } |
| 25 | + else if (exists_1.fileExists(treeDep)) { |
| 26 | + runnerMain = require(treeDep).main; |
| 27 | + runnerRoot = treeDep; |
| 28 | + } |
| 29 | + else { |
| 30 | + var message = 'Error loading test runner. Post an issue. https://github.com/coderoad/atom-coderoad/issues'; |
| 31 | + console.log(message); |
| 32 | + throw message; |
| 33 | + } |
| 34 | + var slash = window.coderoad.win ? '\\' : '/'; |
| 35 | + runnerMain = path.join.apply(null, runnerMain.split(slash)); |
| 36 | + runnerRoot = runnerRoot.substring(0, runnerRoot.lastIndexOf(slash)); |
| 37 | + var pathToMain = 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 | +function loadRepo(config) { |
| 46 | + if (config.bugs && config.bugs.url) { |
| 47 | + window.coderoad.issuesPath = config.bugs.url; |
| 48 | + } |
| 49 | + if (config.repo && config.repo.url) { |
| 50 | + var repo = 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 | +} |
0 commit comments