Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit09a0c59

Browse files
committed
improved error handling & messages
1 parent1dfee83 commit09a0c59

File tree

9 files changed

+45
-59
lines changed

9 files changed

+45
-59
lines changed

‎.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ src
22
tsconfig.json
33
tsd.json
44
tslint.json
5+
.gitattributes

‎lib/reducers/task-tests/concat-tests.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@ function concatTests(targetFile, files) {
44
if(fs.existsSync(targetFile)){
55
fs.unlink(targetFile);
66
}
7-
files.forEach(function(tests){
8-
if(typeoftests==='string'){
9-
readAppend(targetFile,tests);
10-
}
11-
elseif(Object.prototype.toString.call(tests)==='[object Array]'){
12-
tests.forEach(function(test){
13-
readAppend(targetFile,test);
14-
});
7+
files.forEach(function(test){
8+
if(typeoftest==='string'){
9+
readAppend(targetFile,test);
1510
}
1611
});
1712
returntargetFile;

‎lib/services/package.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var PackageService = (function () {
4646
if(task.tests){
4747
task.tests=task.tests.map(function(tests){
4848
if(_.isString(tests)){
49-
return[].concat(configTestString(config,_this.packageName,tests));
49+
returnconfigTestString(config,_this.packageName,tests);
5050
}
5151
else{
5252
console.error('Invalid task test',tests);

‎lib/services/setGlobals.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ function loadRunnerDep(config) {
3030
console.log(message);
3131
throwmessage;
3232
}
33+
varslash=navigator.appVersion.indexOf('Win')!==-1 ?'\\' :'/';
34+
runnerMain=path.join.apply(null,runnerMain.split(slash));
3335
runnerRoot=runnerRoot.substring(0,runnerRoot.lastIndexOf('/'));
3436
varpathToMain=path.join(runnerRoot,runnerMain);
3537
if(!!require(pathToMain).default){

‎src/reducers/alert/alert.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,30 @@ export default function alertReducer(alert = defaultAlert, action: CR.Action): C
2626
if(result.pass&&result.change>0){
2727
// Pass
2828
statusBarAlert.style.color='#73C990';
29-
current={
29+
return{
3030
message:result.msg,
3131
open:true,
3232
action:'pass',
3333
duration:result.duration||1500
3434
};
35-
returncurrent;
3635
}elseif(result.pass===false&&result.change<1){
3736
// Fail
3837
statusBarAlert.style.color='#FF4081';
39-
current={
38+
return{
4039
message:result.msg,
4140
open:true,
4241
action:'fail',
4342
duration:result.duration||2500
4443
};
45-
returncurrent;
4644
}
4745
// Alert
4846
statusBarAlert.style.color='#9DA5B4';
49-
current={
47+
return{
5048
message:result.msg,
5149
open:true,
5250
action:'note',
5351
duration:result.duration||2500
5452
};
55-
returncurrent;
5653
caseType.PAGE_COMPLETE:
5754
return{
5855
message:`Page${action.payload.position.page+1} Complete`,

‎src/reducers/task-tests/concat-tests.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,15 @@ export function concatTests(targetFile: string, files: any): string {
77
}
88

99
// load tests in order
10-
files.forEach(function(tests){
11-
// path to file
12-
if(typeoftests==='string'){
13-
readAppend(targetFile,tests);
14-
15-
// array of paths to file
16-
}elseif(Object.prototype.toString.call(tests)==='[object Array]'){
17-
tests.forEach(function(test){
18-
readAppend(targetFile,test);
19-
});
20-
}
21-
});
10+
files.forEach((test:string)=>readAppend(targetFile,test));
2211
returntargetFile;
2312
}
2413

2514
functionreadAppend(targetFile:string,file:string):void{
2615
try{
2716
letdata=fs.readFileSync(file,'utf8');
2817
fs.appendFileSync(targetFile,data,'utf8');
18+
return;
2919
}catch(e){
3020
console.log('Error reading test file',e);
3121
}

‎src/services/package.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ class PackageService {
4545
letconfig=this.config.config;
4646
return!tasks ?[] :tasks.map((task:CR.Task)=>{
4747
if(task.tests){
48-
task.tests=task.tests.map((tests:string)=>{
49-
if(_.isString(tests)){
50-
return[].concat(configTestString(config,this.packageName,tests));
48+
task.tests=task.tests.map((test:string)=>{
49+
// add unique string to tests
50+
if(_.isString(test)&&task.tests.indexOf(test)===-1){
51+
returnconfigTestString(config,this.packageName,test);
5152
}else{
52-
console.error('Invalid task test',tests);
53+
console.error('Invalid task test',test);
5354
}
5455
});
5556
}

‎src/services/setup-checks.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export function verifySetupComplete() {
99
hasDirectory()
1010
.then(hasPackageJson)
1111
.then(hasTutorialDep)
12-
.then(hasTestRunner)
1312
.then(()=>{
1413
store.dispatch(Action.setupWarning(null));
1514
store.dispatch(Action.loadTutorials());
@@ -73,23 +72,6 @@ function hasTutorialDep(): Promise<CR.SetupWarning> {
7372
});
7473
}
7574

76-
// 4
77-
functionhasTestRunner():Promise<CR.SetupWarning>{
78-
returnnewPromise((resolve,reject)=>{
79-
consthasTestRunner=true;
80-
if(!hasTestRunner){
81-
reject({
82-
key:'noTestRunner',
83-
title:'Error with Tutorial',
84-
click:null,
85-
text:'no test runner found'
86-
});
87-
}
88-
resolve();
89-
});
90-
}
91-
92-
9375
function_hasKeys(obj:Object):boolean{
9476
returnObject.keys(obj).length>0;
9577
}

‎src/services/tutorials.ts

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import * as path from 'path';
33
import*asfsfrom'fs';
44
import{fileExists}from'../services/exists';
55

6+
lettutorialError='This is an error with the tutorial itself';
7+
68
exportfunctionpackageJsonExists():boolean{
79
constpathToPackageJson=path.join(window.coderoad.dir,'package.json');
810
returnfileExists(pathToPackageJson);
@@ -17,18 +19,34 @@ export function loadRootPackageJson(): PackageJson {
1719
}
1820

1921
function_isTutorial(name:string):boolean{
22+
// has package.json
2023
letpathToTutorialPackageJson=path.join(window.coderoad.dir,'node_modules',name,'package.json');
21-
if(fileExists(pathToTutorialPackageJson)){
22-
// has package.json
23-
letpackageJson=JSON.parse(fs.readFileSync(pathToTutorialPackageJson,'utf8'));
24-
// main path to coderoad.json
25-
if(packageJson.main&&packageJson.main.match(/coderoad.json$/)){
26-
letpathToCoderoadJson=path.join(window.coderoad.dir,'node_modules',name,packageJson.main);
27-
// coderoad.json file exists
28-
returnfileExists(pathToCoderoadJson);
29-
}
24+
if(!fileExists(pathToTutorialPackageJson)){
25+
console.log(`Error with${name}: no package.json file found.${tutorialError}`);
26+
returnfalse;
27+
}
28+
// main path to coderoad.json
29+
letpackageJson=JSON.parse(fs.readFileSync(pathToTutorialPackageJson,'utf8'));
30+
if(!packageJson.main&&packageJson.main.match(/coderoad.json$/)){
31+
console.log(`Error with${name}: main does not load a coderoad.json file.${tutorialError}`);
32+
returnfalse;
33+
}
34+
// coderoad.json file exists
35+
letpathToCoderoadJson=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+
returnfalse;
39+
};
40+
if(!packageJson.config||!packageJson.config.testRunner){
41+
console.log(`Error with${name}: no test runner specified.${tutorialError}`);
42+
returnfalse;
43+
}
44+
letpathToTestRunner=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+
returnfalse;
3048
}
31-
returnfalse;
49+
returntrue;
3250
}
3351

3452
exportfunctionsearchForTutorials(deps:Object):string[]{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp