|
| 1 | +"use strict"; |
| 2 | +varpath_1=require('path'); |
| 3 | +varactions_1=require('../actions/actions'); |
| 4 | +varstore_1=require('../store/store'); |
| 5 | +functionconfigTestString(config,name,test){ |
| 6 | +if(window.coderoad.win){ |
| 7 | +test=test.split('/').join('\\'); |
| 8 | +} |
| 9 | +if(config.testDir){ |
| 10 | +test=path_1.join(window.coderoad.dir,'node_modules',name,config.testDir,test); |
| 11 | +} |
| 12 | +else{ |
| 13 | +test=path_1.join(window.coderoad.dir,'node_modules',name,test); |
| 14 | +} |
| 15 | +if(config.testSuffix){ |
| 16 | +test+=config.testSuffix; |
| 17 | +} |
| 18 | +returntest; |
| 19 | +} |
| 20 | +varTutorialPackageService=(function(){ |
| 21 | +functionTutorialPackageService(){ |
| 22 | +this.name=''; |
| 23 | +this.data={ |
| 24 | +project:{}, |
| 25 | +chapters:[] |
| 26 | +}; |
| 27 | +this.packageJson=null; |
| 28 | +} |
| 29 | +TutorialPackageService.prototype.selectPackage=function(name){ |
| 30 | +varpackagePath=path_1.join(window.coderoad.dir,'node_modules',name); |
| 31 | +this.packageJson=require(path_1.join(packagePath,'package.json')); |
| 32 | +store_1.store.dispatch(actions_1.setGlobals(this.packageJson)); |
| 33 | +this.data=require(path_1.join(packagePath,this.packageJson.main)); |
| 34 | +this.name=name; |
| 35 | +}; |
| 36 | +TutorialPackageService.prototype.page=function(_a){ |
| 37 | +varchapter=_a.chapter,page=_a.page; |
| 38 | +returnthis.data.chapters[chapter].pages[page]; |
| 39 | +}; |
| 40 | +TutorialPackageService.prototype.getPackage=function(){ |
| 41 | +returnthis.packageJson; |
| 42 | +}; |
| 43 | +TutorialPackageService.prototype.configTaskTests=function(tasks){ |
| 44 | +var_this=this; |
| 45 | +varconfig=this.packageJson.config; |
| 46 | +return!tasks ?[] :tasks.map(function(task){ |
| 47 | +if(task.tests){ |
| 48 | +task.tests=task.tests.map(function(test){ |
| 49 | +if(typeoftest==='string'){ |
| 50 | +returnconfigTestString(config,_this.name,test); |
| 51 | +} |
| 52 | +else{ |
| 53 | +console.error('Invalid task test',test); |
| 54 | +} |
| 55 | +}); |
| 56 | +} |
| 57 | +returntask; |
| 58 | +}); |
| 59 | +}; |
| 60 | +TutorialPackageService.prototype.getTasks=function(position){ |
| 61 | +vartasks=this.page(position).tasks||[]; |
| 62 | +tasks=this.configTaskTests(tasks); |
| 63 | +returntasks; |
| 64 | +}; |
| 65 | +TutorialPackageService.prototype.getPage=function(position){ |
| 66 | +var_a=this.page(position),title=_a.title,description=_a.description,onPageComplete=_a.onPageComplete,completed=_a.completed; |
| 67 | +return{ |
| 68 | +title:title,description:description,onPageComplete:onPageComplete,completed:completed||false |
| 69 | +}; |
| 70 | +}; |
| 71 | +TutorialPackageService.prototype.getSavedPosition=function(){ |
| 72 | +return{chapter:0,page:0}; |
| 73 | +}; |
| 74 | +TutorialPackageService.prototype.getSavedRoute=function(){ |
| 75 | +return'progress'; |
| 76 | +}; |
| 77 | +TutorialPackageService.prototype.getNextPosition=function(_a){ |
| 78 | +varchapter=_a.chapter,page=_a.page; |
| 79 | +varchapters=this.data.chapters; |
| 80 | +if(page<chapters[chapter].pages.length-1){ |
| 81 | +return{chapter:chapter,page:page+1}; |
| 82 | +} |
| 83 | +elseif(chapter<chapters.length-1){ |
| 84 | +return{chapter:chapter+1,page:0}; |
| 85 | +} |
| 86 | +else{ |
| 87 | +store_1.store.dispatch(actions_1.projectComplete()); |
| 88 | +return{chapter:chapter,page:page,completed:true}; |
| 89 | +} |
| 90 | +}; |
| 91 | +TutorialPackageService.prototype.getProject=function(){ |
| 92 | +returnthis.data.project; |
| 93 | +}; |
| 94 | +TutorialPackageService.prototype.getProgress=function(){ |
| 95 | +varchapters=this.data.chapters; |
| 96 | +return{ |
| 97 | +completed:false, |
| 98 | +chapters:!chapters ?[] :chapters.map(function(_a){ |
| 99 | +vartitle=_a.title,description=_a.description,completed=_a.completed,pages=_a.pages; |
| 100 | +return{ |
| 101 | +title:title,description:description,completed:completed||false, |
| 102 | +pages:!pages ?[] :pages.map(function(page){ |
| 103 | +return{ |
| 104 | +title:page.title, |
| 105 | +description:page.description, |
| 106 | +completed:page.completed||false |
| 107 | +}; |
| 108 | +}) |
| 109 | +}; |
| 110 | +}) |
| 111 | +}; |
| 112 | +}; |
| 113 | +returnTutorialPackageService; |
| 114 | +}()); |
| 115 | +Object.defineProperty(exports,"__esModule",{value:true}); |
| 116 | +exports.default=newTutorialPackageService(); |