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

Commit1355b82

Browse files
committed
load files above tests
1 parent2a99028 commit1355b82

File tree

10 files changed

+120
-72
lines changed

10 files changed

+120
-72
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"use strict";
2+
varpath=require('path');
3+
varfs=require('fs');
4+
varsupportedFileTypes=['js','jsx','ts','py'];
5+
varjs=/^\/\/\s?load\(['"`](.+)['"`]\)$/;
6+
varloaderMatch={
7+
js:js,
8+
ts:js,
9+
jsx:js,
10+
py:/\#\s?load\(['"`](.+)['"`]\)$/
11+
};
12+
functionparseLoaders(data,fileType){
13+
if(supportedFileTypes.indexOf(fileType)<0){
14+
console.log("File type \""+fileType+"\" not supported.");
15+
return'';
16+
}
17+
varimports='';
18+
vari=0;
19+
varlines=data.split('\n');
20+
while(i<lines.length-1){
21+
i+=1;
22+
varloader=lines[i].match(loaderMatch[fileType]);
23+
if(loader){
24+
varfileToLoad=loader[1];
25+
varpathToFile=path.normalize(path.join(window.coderoad.dir,fileToLoad));
26+
varfile=fs.readFileSync(pathToFile,'utf8');
27+
imports+=file;
28+
}
29+
}
30+
varoutput=null;
31+
if(imports.length>0){
32+
output=imports+'\n'.concat(data);
33+
}
34+
else{
35+
output=data;
36+
}
37+
returnoutput;
38+
}
39+
Object.defineProperty(exports,"__esModule",{value:true});
40+
exports.default=parseLoaders;

‎lib/reducers/run-tests/run.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
"use strict";
22
vartest_result_1=require('./test-result');
33
var_base_1=require('../../_base');
4+
varfs=require('fs');
5+
varpath=require('path');
6+
varparse_loaders_1=require('./parse-loaders');
47
functionrunTaskTests(setup){
5-
vartests=_base_1.store.getState().taskTests;
6-
if(tests&&tests.length){
8+
vartestFile=_base_1.store.getState().taskTests;
9+
if(testFile){
710
varconfig=window.coderoad;
811
config.taskPosition=_base_1.store.getState().taskPosition;
9-
window.coderoad.runner(tests,config,test_result_1.handleResult);
12+
varfileType=testFile.substr(testFile.lastIndexOf('.')+1,testFile.length)||null;
13+
vartests=fs.readFileSync(testFile,'utf8');
14+
varoutput=parse_loaders_1.default(tests,fileType);
15+
vartarget=path.join(window.coderoad.tutorialDir||window.coderoad.dir,"_tmp"+window.coderoad.suffix);
16+
fs.writeFileSync(target,output,'utf8');
17+
window.coderoad.runner(target,config,test_result_1.handleResult);
1018
}
1119
returntrue;
1220
}

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

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
"use strict";
22
varfs=require('fs');
3-
varpath=require('path');
4-
varloaderMatch={
5-
js:/^\/\/\s?load\(['"`](.+)['"`]\)$/,
6-
py:/\#\s?load\(['"`](.+)['"`]\)$/
7-
};
83
functionunlink(targetFile){
94
returnnewPromise(function(resolve){
105
if(fs.existsSync(targetFile)){
@@ -13,34 +8,10 @@ function unlink(targetFile) {
138
resolve();
149
});
1510
}
16-
functionparseLoaders(data,fileType){
17-
varlines=data.split('\n');
18-
varimports='';
19-
vari=0;
20-
while(i<lines.length-1){
21-
i+=1;
22-
varloader=lines[i].match(loaderMatch[fileType]);
23-
if(loader){
24-
varfileToLoad=loader[1];
25-
varpathToFile=path.normalize(path.join(window.coderoad.dir,fileToLoad));
26-
imports.concat(fs.readFileSync(pathToFile,'utf8'));
27-
}
28-
}
29-
varoutput=null;
30-
if(imports.length>0){
31-
output=imports+'\n'.concat(data);
32-
}
33-
else{
34-
output=data;
35-
}
36-
returnoutput;
37-
}
3811
functionreadAppend(targetFile,file){
3912
try{
4013
vardata=fs.readFileSync(file,'utf8');
41-
varfileType=targetFile.substr(targetFile.lastIndexOf('.')+1,targetFile.length);
42-
varoutput=parseLoaders(data,fileType);
43-
fs.appendFileSync(targetFile,output,'utf8');
14+
fs.appendFileSync(targetFile,data,'utf8');
4415
returntrue;
4516
}
4617
catch(e){

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function taskTestsReducer(taskTests, action) {
66
if(taskTests===void0){taskTests='';}
77
switch(action.type){
88
caseType.SET_PAGE:
9-
vartarget=path.join(window.coderoad.tutorialDir||window.coderoad.dir,"_tmp"+window.coderoad.suffix);
9+
vartarget=path.join(window.coderoad.tutorialDir||window.coderoad.dir,"_tmpTests"+window.coderoad.suffix);
1010
loader_1.default(target,action.payload.taskTests);
1111
returntarget;
1212
default:
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import*aspathfrom'path';
2+
import*asfsfrom'fs';
3+
4+
constsupportedFileTypes=['js','jsx','ts','py'];
5+
constjs=/^\/\/\s?load\(['"`](.+)['"`]\)$/;
6+
constloaderMatch={
7+
js,// // load('file'),
8+
ts:js,
9+
jsx:js,
10+
py:/\#\s?load\(['"`](.+)['"`]\)$/// # load('file')
11+
};
12+
13+
exportdefaultfunctionparseLoaders(data:string,fileType:string){
14+
15+
if(supportedFileTypes.indexOf(fileType)<0){
16+
console.log(`File type "${fileType}" not supported.`);
17+
return'';
18+
}
19+
20+
letimports='';
21+
// loop over lines and add editor files
22+
leti=0;
23+
letlines=data.split('\n');
24+
25+
while(i<lines.length-1){
26+
i+=1;
27+
letloader:string[]=lines[i].match(loaderMatch[fileType]);
28+
29+
if(loader){
30+
// loader found
31+
letfileToLoad:string=loader[1];
32+
letpathToFile:string=path.normalize(path.join(window.coderoad.dir,fileToLoad));
33+
letfile:string=fs.readFileSync(pathToFile,'utf8');
34+
imports+=file;
35+
}
36+
}
37+
38+
letoutput:string=null;
39+
if(imports.length>0){
40+
output=imports+'\n'.concat(data);
41+
}else{
42+
output=data;
43+
}
44+
returnoutput;
45+
}

‎src/reducers/run-tests/run.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
import{handleResult}from'./test-result';
22
import{store}from'../../_base';
3+
import*asfsfrom'fs';
4+
import*aspathfrom'path';
5+
importparseLoadersfrom'./parse-loaders';
6+
7+
// TODO: use memcache for test files instead of read/writes
38

49
exportfunctionrunTaskTests(setup?:boolean):boolean{
5-
consttests:CR.TaskTest[]=store.getState().taskTests;
6-
if(tests&&tests.length){
10+
consttestFile:string=store.getState().taskTests;
11+
12+
if(testFile){
713
letconfig=window.coderoad;
814
config.taskPosition=store.getState().taskPosition;
15+
16+
letfileType:string=testFile.substr(testFile.lastIndexOf('.')+1,testFile.length)||null;
17+
lettests=fs.readFileSync(testFile,'utf8');
18+
letoutput=parseLoaders(tests,fileType);
19+
20+
lettarget=path.join(window.coderoad.tutorialDir||window.coderoad.dir,`_tmp${window.coderoad.suffix}`);
21+
fs.writeFileSync(target,output,'utf8');
22+
923
// call test runner
10-
window.coderoad.runner(tests,config,handleResult);
24+
window.coderoad.runner(target,config,handleResult);
1125
}
1226
returntrue;
1327
}

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

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import*asfsfrom'fs';
22
import*aspathfrom'path';
33

4-
constloaderMatch={
5-
js:/^\/\/\s?load\(['"`](.+)['"`]\)$/,
6-
py:/\#\s?load\(['"`](.+)['"`]\)$/
7-
};
8-
94
functionunlink(targetFile:string){
105
returnnewPromise((resolve)=>{
116
if(fs.existsSync(targetFile)){
@@ -15,38 +10,10 @@ function unlink(targetFile: string) {
1510
});
1611
}
1712

18-
functionparseLoaders(data:string,fileType:string){
19-
letlines=data.split('\n');
20-
letimports='';
21-
// loop over lines and add editor files
22-
leti=0;
23-
while(i<lines.length-1){
24-
i+=1;
25-
letloader:string[]=lines[i].match(loaderMatch[fileType]);
26-
27-
if(loader){
28-
// loader found
29-
letfileToLoad:string=loader[1];
30-
letpathToFile:string=path.normalize(path.join(window.coderoad.dir,fileToLoad));
31-
imports.concat(fs.readFileSync(pathToFile,'utf8'));
32-
}
33-
}
34-
35-
letoutput:string=null;
36-
if(imports.length>0){
37-
output=imports+'\n'.concat(data);
38-
}else{
39-
output=data;
40-
}
41-
returnoutput;
42-
}
43-
4413
functionreadAppend(targetFile:string,file:string):boolean{
4514
try{
4615
letdata=fs.readFileSync(file,'utf8');
47-
letfileType=targetFile.substr(targetFile.lastIndexOf('.')+1,targetFile.length);
48-
letoutput=parseLoaders(data,fileType);
49-
fs.appendFileSync(targetFile,output,'utf8');
16+
fs.appendFileSync(targetFile,data,'utf8');
5017
returntrue;
5118
}catch(e){
5219
console.log('Error reading test file',e);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import load from './loader';
66
exportdefaultfunctiontaskTestsReducer(taskTests='',action:CR.Action):string{
77
switch(action.type){
88
caseType.SET_PAGE:
9-
lettarget=path.join(window.coderoad.tutorialDir||window.coderoad.dir,`_tmp${window.coderoad.suffix}`);
9+
lettarget=path.join(window.coderoad.tutorialDir||window.coderoad.dir,`_tmpTests${window.coderoad.suffix}`);
1010
load(target,action.payload.taskTests);
1111
returntarget;
1212
default:

‎src/typings/cr/globals.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ interface IntrinsicAttributes {
2424
primaryText:string;
2525
primaryTogglesNestedList:any;
2626
}
27+
28+
typefileType='js'|'jsx'|'ts'|'py';

‎tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"src/reducers/project/project.ts",
8080
"src/reducers/reducer.ts",
8181
"src/reducers/route/route.ts",
82+
"src/reducers/run-tests/parse-loaders.ts",
8283
"src/reducers/run-tests/run-tests.ts",
8384
"src/reducers/run-tests/run.ts",
8485
"src/reducers/run-tests/test-result.ts",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp