1
1
import * as fs from 'fs' ;
2
2
import * as path from 'path' ;
3
3
4
- const loaderMatch = {
5
- js :/ ^ \/ \/ \s ? l o a d \( [ ' " ` ] ( .+ ) [ ' " ` ] \) $ / ,
6
- py :/ \# \s ? l o a d \( [ ' " ` ] ( .+ ) [ ' " ` ] \) $ /
7
- } ;
8
-
9
4
function unlink ( targetFile :string ) {
10
5
return new Promise ( ( resolve ) => {
11
6
if ( fs . existsSync ( targetFile ) ) {
@@ -15,38 +10,10 @@ function unlink(targetFile: string) {
15
10
} ) ;
16
11
}
17
12
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
-
44
13
function readAppend ( targetFile :string , file :string ) :boolean {
45
14
try {
46
15
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' ) ;
50
17
return true ;
51
18
} catch ( e ) {
52
19
console . log ( 'Error reading test file' , e ) ;