Skip to content

Commit 7d6b3f5

Browse files
committed
fix convert/format
- unlink file for converting
1 parent 564c7c4 commit 7d6b3f5

File tree

1 file changed

+29
-37
lines changed

1 file changed

+29
-37
lines changed

scripts/rescript_convert.js

+29-37
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ rescript convert -- it converts the current directory
66

77
var child_process = require("child_process");
88
var path = require("path");
9+
var fs = require("fs");
910

1011
/**
1112
* @type {arg.boolref}
@@ -31,6 +32,32 @@ function shouldConvert(file) {
3132
return [".ml", ".mli", ".re", ".rei"].some((x) => file.endsWith(x));
3233
}
3334

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+
}
3461
/**
3562
* @param {string[]} argv
3663
* @param {string} bsb_exe
@@ -66,26 +93,7 @@ function main(argv, bsb_exe, bsc_exe) {
6693
files = output.stdout.split("\n").map((x) => x.trim());
6794
for (let file of files) {
6895
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);
8997
}
9098
}
9199
} else {
@@ -97,23 +105,7 @@ function main(argv, bsb_exe, bsc_exe) {
97105
}
98106
}
99107
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);
117109
});
118110
}
119111
} catch (e) {

0 commit comments

Comments
 (0)