@@ -6,6 +6,7 @@ rescript convert -- it converts the current directory
6
6
7
7
var child_process = require ( "child_process" ) ;
8
8
var path = require ( "path" ) ;
9
+ var fs = require ( "fs" ) ;
9
10
10
11
/**
11
12
* @type {arg.boolref }
@@ -31,6 +32,32 @@ function shouldConvert(file) {
31
32
return [ ".ml" , ".mli" , ".re" , ".rei" ] . some ( ( x ) => file . endsWith ( x ) ) ;
32
33
}
33
34
35
+ /**
36
+ *
37
+ * @param {string } file
38
+ * @param {string } bsc_exe
39
+ * assume the file is convertible
40
+ */
41
+ function handleOneFile ( file , bsc_exe ) {
42
+ // console.log(`processing ${arg}`);
43
+ var nextExt = file . endsWith ( "i" ) ? ".resi" : ".res" ;
44
+ child_process . execFile (
45
+ bsc_exe ,
46
+ [ "-o" , file . substr ( 0 , file . lastIndexOf ( "." ) ) + nextExt , "-format" , file ] ,
47
+ ( error , stdout , stderr ) => {
48
+ if ( error === null ) {
49
+ // todo
50
+ fs . unlink ( file , ( ) => {
51
+ //ignore
52
+ } ) ;
53
+ } else {
54
+ // todo error handling
55
+ console . error ( `Error when converting ${ file } ` ) ;
56
+ console . log ( stderr ) ;
57
+ }
58
+ }
59
+ ) ;
60
+ }
34
61
/**
35
62
* @param {string[] } argv
36
63
* @param {string } bsb_exe
@@ -66,26 +93,7 @@ function main(argv, bsb_exe, bsc_exe) {
66
93
files = output . stdout . split ( "\n" ) . map ( ( x ) => x . trim ( ) ) ;
67
94
for ( let file of files ) {
68
95
if ( shouldConvert ( file ) ) {
69
- // console.log(`processing ${arg}`);
70
- var nextExt = file . endsWith ( "i" ) ? ".resi" : ".res" ;
71
- child_process . execFile (
72
- path . join ( __dirname , process . platform , "bsc.exe" ) ,
73
- [
74
- "-o" ,
75
- file . substr ( 0 , file . lastIndexOf ( "." ) ) + nextExt ,
76
- "-format" ,
77
- file ,
78
- ] ,
79
- ( error , stdout , stderr ) => {
80
- if ( error === null ) {
81
- // todo
82
- } else {
83
- // todo error handling
84
- console . error ( `Error when converting ${ file } ` ) ;
85
- console . log ( stderr ) ;
86
- }
87
- }
88
- ) ;
96
+ handleOneFile ( file , bsc_exe ) ;
89
97
}
90
98
}
91
99
} else {
@@ -97,23 +105,7 @@ function main(argv, bsb_exe, bsc_exe) {
97
105
}
98
106
}
99
107
files . forEach ( ( file ) => {
100
- var nextExt = file . endsWith ( "i" ) ? ".resi" : ".res" ;
101
- child_process . execFile (
102
- bsc_exe ,
103
- [
104
- "-o" ,
105
- file . substr ( 0 , file . lastIndexOf ( "." ) ) + nextExt ,
106
- "-format" ,
107
- file ,
108
- ] ,
109
- ( error , stdout , stderr ) => {
110
- if ( error === null ) {
111
- } else {
112
- console . error ( `Error when converting ${ file } ` ) ;
113
- console . log ( stderr ) ;
114
- }
115
- }
116
- ) ;
108
+ handleOneFile ( file , bsc_exe ) ;
117
109
} ) ;
118
110
}
119
111
} catch ( e ) {
0 commit comments