11import * as fs from 'fs' ;
22import * as path from 'path' ;
33
4- const loaderMatch = {
5- js : / ^ \/ \/ \s ? l o a d \( [ ' " ` ] ( .+ ) [ ' " ` ] \) $ / ,
6- py : / \# \s ? l o a d \( [ ' " ` ] ( .+ ) [ ' " ` ] \) $ /
7- } ;
8-
94function unlink ( targetFile : string ) {
105 return new Promise ( ( resolve ) => {
116 if ( fs . existsSync ( targetFile ) ) {
@@ -15,38 +10,10 @@ function unlink(targetFile: string) {
1510 } ) ;
1611}
1712
18- function parseLoaders ( data : string , fileType : string ) {
19- let lines = data . split ( '\n' ) ;
20- let imports = '' ;
21- // loop over lines and add editor files
22- let i = 0 ;
23- while ( i < lines . length - 1 ) {
24- i += 1 ;
25- let loader : string [ ] = lines [ i ] . match ( loaderMatch [ fileType ] ) ;
26-
27- if ( loader ) {
28- // loader found
29- let fileToLoad : string = loader [ 1 ] ;
30- let pathToFile : string = path . normalize ( path . join ( window . coderoad . dir , fileToLoad ) ) ;
31- imports . concat ( fs . readFileSync ( pathToFile , 'utf8' ) ) ;
32- }
33- }
34-
35- let output : string = null ;
36- if ( imports . length > 0 ) {
37- output = imports + '\n' . concat ( data ) ;
38- } else {
39- output = data ;
40- }
41- return output ;
42- }
43-
4413function readAppend ( targetFile : string , file : string ) : boolean {
4514 try {
4615 let data = fs . readFileSync ( file , 'utf8' ) ;
47- let fileType = targetFile . substr ( targetFile . lastIndexOf ( '.' ) + 1 , targetFile . length ) ;
48- let output = parseLoaders ( data , fileType ) ;
49- fs . appendFileSync ( targetFile , output , 'utf8' ) ;
16+ fs . appendFileSync ( targetFile , data , 'utf8' ) ;
5017 return true ;
5118 } catch ( e ) {
5219 console . log ( 'Error reading test file' , e ) ;
0 commit comments