@@ -5,6 +5,24 @@ var path = require("path");
5
5
var fs = require ( "fs" ) ;
6
6
7
7
var ocamlSrcDir = path . join ( __dirname , ".." , "ocaml" ) ;
8
+ var ocamlVersionFilePath = path . join ( ocamlSrcDir , "VERSION" ) ;
9
+
10
+ /**
11
+ * Ensures the ocaml folder exists at the root of the project, either from the submodule,
12
+ * or by extracting the vendor/ocaml.tar.gz there
13
+ */
14
+ function ensureOCamlExistsSync ( ) {
15
+ if ( ! fs . existsSync ( ocamlSrcDir ) ) {
16
+ fs . mkdirSync ( ocamlSrcDir ) ;
17
+ }
18
+ if ( ! fs . existsSync ( ocamlVersionFilePath ) ) {
19
+ cp . execSync ( `tar xzvf ../vendor/ocaml.tar.gz` , {
20
+ cwd : ocamlSrcDir ,
21
+ stdio : [ 0 , 1 , 2 ]
22
+ } ) ;
23
+ }
24
+ }
25
+
8
26
/**
9
27
* @type {string }
10
28
*/
@@ -19,16 +37,10 @@ function getVersionPrefix() {
19
37
return cached ;
20
38
}
21
39
22
- var file = path . join ( __dirname , ".." , "ocaml" , "VERSION" ) ;
23
- if ( ! fs . existsSync ( file ) ) {
24
- cp . execSync ( `tar xzvf ../vendor/ocaml.tar.gz` , {
25
- cwd : ocamlSrcDir ,
26
- stdio : [ 0 , 1 , 2 ]
27
- } ) ;
28
- }
40
+ ensureOCamlExistsSync ( ) ;
29
41
30
- console . log ( `${ file } is used in version detection` ) ;
31
- var version = fs . readFileSync ( file , "ascii" ) ;
42
+ console . log ( `${ ocamlVersionFilePath } is used in version detection` ) ;
43
+ var version = fs . readFileSync ( ocamlVersionFilePath , "ascii" ) ;
32
44
cached = version . substr ( 0 , version . indexOf ( "+" ) ) ;
33
45
return cached ;
34
46
}
@@ -39,15 +51,7 @@ exports.getVersionPrefix = getVersionPrefix;
39
51
* @param {boolean } config
40
52
*/
41
53
function build ( config ) {
42
- if ( ! fs . existsSync ( ocamlSrcDir ) ) {
43
- fs . mkdirSync ( ocamlSrcDir ) ;
44
- }
45
- if ( ! fs . existsSync ( path . join ( ocamlSrcDir , "VERSION" ) ) ) {
46
- cp . execSync ( `tar xzvf ../vendor/ocaml.tar.gz` , {
47
- cwd : ocamlSrcDir ,
48
- stdio : [ 0 , 1 , 2 ]
49
- } ) ;
50
- }
54
+ ensureOCamlExistsSync ( ) ;
51
55
52
56
var prefix = path . normalize (
53
57
path . join ( __dirname , ".." , "native" , getVersionPrefix ( ) )
0 commit comments