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

Commit3e3d29a

Browse files
committed
change to inline parse loaders
1 parent9a8b781 commit3e3d29a

File tree

3 files changed

+47
-24
lines changed

3 files changed

+47
-24
lines changed

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,23 @@ function parseLoaders(data, fileType) {
1414
console.log("File type \""+fileType+"\" not supported.");
1515
return'';
1616
}
17-
varimports='';
1817
vari=-1;
1918
varlines=data.split('\n');
19+
varfilesLoaded=[];
2020
while(i<lines.length-1){
2121
i+=1;
2222
varloader=lines[i].match(loaderMatch[fileType]);
2323
if(loader){
2424
varfileToLoad=loader[1];
25+
if(filesLoaded.indexOf(fileToLoad)>-1){
26+
console.log("\""+fileToLoad+"\" already loaded.");
27+
continue;
28+
}
2529
varpathToFile=path.normalize(path.join(window.coderoad.dir,fileToLoad));
26-
varfile=fs.readFileSync(pathToFile,'utf8');
27-
imports+=file;
30+
lines[i]=fs.readFileSync(pathToFile,'utf8');
2831
}
2932
}
30-
varoutput=null;
31-
if(imports.length>0){
32-
output=imports+'\n'.concat(data);
33-
}
34-
else{
35-
output=data;
36-
}
37-
returnoutput;
33+
returnlines.join('\n');
3834
}
3935
Object.defineProperty(exports,"__esModule",{value:true});
4036
exports.default=parseLoaders;

‎lib/services/write.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use strict";
2+
varfs=require('fs');
3+
varpath=require('path');
4+
functiongetPath(filePath){
5+
returnpath.normalize(path.join(window.coderoad.dir,filePath));
6+
}
7+
functionwrite(filePath,text){
8+
try{
9+
fs.writeFileSync(getPath(filePath),text,'utf8');
10+
}
11+
catch(e){
12+
if(e){
13+
console.log('Error writing to filePath',filePath);
14+
}
15+
}
16+
}
17+
exports.write=write;
18+
functionreadWrite(writePath,readPath){
19+
try{
20+
write(writePath,fs.readFileSync(getPath(readPath)));
21+
}
22+
catch(e){
23+
if(e){
24+
console.log('Error reading from filePath',readPath);
25+
}
26+
}
27+
}
28+
exports.readWrite=readWrite;

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import * as path from 'path';
22
import*asfsfrom'fs';
33

44
constsupportedFileTypes=['js','jsx','ts','py'];
5-
constjs=/^\/\/\s?load\(['"`](.+)['"`]\)$/m;
5+
constjs=/^\/\/\s?load\(['"`](.+)['"`]\)$/m;// // load('file'),
66
constloaderMatch={
7-
js,// // load('file'),
7+
js,
88
ts:js,
99
jsx:js,
1010
py:/^#\s?load\(['"`](.+)['"`]\)$/m// # load('file')
@@ -17,29 +17,28 @@ export default function parseLoaders(data: string, fileType: string) {
1717
return'';
1818
}
1919

20-
letimports='';
2120
// loop over lines and add editor files
2221
leti=-1;
2322
letlines=data.split('\n');
2423

24+
letfilesLoaded=[];
25+
2526
while(i<lines.length-1){
2627
i+=1;
2728
letloader:string[]=lines[i].match(loaderMatch[fileType]);
2829

2930
if(loader){
3031
// loader found
3132
letfileToLoad:string=loader[1];
33+
34+
if(filesLoaded.indexOf(fileToLoad)>-1){
35+
console.log(`"${fileToLoad}" already loaded.`);
36+
continue;
37+
}
38+
3239
letpathToFile:string=path.normalize(path.join(window.coderoad.dir,fileToLoad));
33-
letfile:string=fs.readFileSync(pathToFile,'utf8');
34-
imports+=file;
40+
lines[i]=fs.readFileSync(pathToFile,'utf8');
3541
}
3642
}
37-
38-
letoutput:string=null;
39-
if(imports.length>0){
40-
output=imports+'\n'.concat(data);
41-
}else{
42-
output=data;
43-
}
44-
returnoutput;
43+
returnlines.join('\n');
4544
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp