@@ -4,9 +4,9 @@ var child_process = require('child_process')
44var fs = require ( 'fs' )
55var path = require ( 'path' )
66var os = require ( 'os' )
7- var root = path . join ( __dirname , '..' )
7+ var root = path . join ( __dirname , '..' )
88var dest_bin = path . join ( root , 'lib' )
9- var dest_lib = path . join ( root , 'lib' , 'ocaml' )
9+ var dest_lib = path . join ( root , 'lib' , 'ocaml' )
1010
1111
1212var jscomp = path . join ( root , 'jscomp' )
@@ -16,89 +16,101 @@ var jscomp = path.join(root, 'jscomp')
1616/*
1717 * It is weird reaname cause Busy resource or lock error
1818 */
19- function copyFile ( file , target ) {
20- var stat = fs . statSync ( file )
21- fs . createReadStream ( file ) . pipe (
22- fs . createWriteStream ( target ,
23- { mode : stat . mode } ) )
24-
19+ function copyFile ( file , target ) {
20+ var stat = fs . statSync ( file )
21+ fs . createReadStream ( file ) . pipe (
22+ fs . createWriteStream ( target ,
23+ { mode : stat . mode } ) )
24+
2525}
2626
2727
2828/**
29- * @param {string } from
30- * @param {string } to
29+ * @param {string } from
30+ * @param {string } to
3131 */
32- function renameAsync ( from , to ) {
33- console . log ( from , '----->' , to )
34- // @ts -ignore
35- fs . rename ( from , to )
36- // fs.renameSync(from,to)
32+ function renameAsync ( from , to ) {
33+ console . log ( from , '----->' , to )
34+ // @ts -ignore
35+ fs . rename ( from , to )
36+ // fs.renameSync(from,to)
3737
3838}
3939
4040/**
4141 * @param {string } from
4242 * @param {string } to
4343 */
44- function poor_copy_sync ( from , to ) {
45- console . log ( from , '----->' , to )
46- fs . renameSync ( from , to )
47- // fs.renameSync(from,to)
44+ function poor_copy_sync ( from , to ) {
45+ console . log ( from , '----->' , to )
46+ fs . renameSync ( from , to )
47+ // fs.renameSync(from,to)
4848
4949}
5050
5151/**
52- * @param {string } dir
52+ * @param {string } dir
5353 * @param {string } dest_lib
5454 */
55- function install_directory ( dir , dest_lib ) {
56- var files = fs . readdirSync ( dir )
57- files . forEach ( function ( file ) {
58- var installed_fmt = [ '.cmt' , '.cmti' , '.cmj' , '.ml' , '.mli' , '.cmi' ]
59- var format_file = path . parse ( file )
60- if ( format_file &&
61- ( installed_fmt . indexOf ( format_file . ext ) !== - 1 )
62- ) {
63- var from = path . join ( dir , file )
64- var to = path . join ( dest_lib , file )
65- renameAsync ( from , to )
66- }
67- } )
55+ function install_directory ( dir , dest_lib ) {
56+ var files = fs . readdirSync ( dir )
57+ files . forEach ( function ( file ) {
58+ var installed_fmt = [ '.cmt' , '.cmti' , '.cmj' , '.ml' , '.mli' , '.cmi' ]
59+ var format_file = path . parse ( file )
60+ if ( format_file &&
61+ ( installed_fmt . indexOf ( format_file . ext ) !== - 1 )
62+ ) {
63+ var from = path . join ( dir , file )
64+ var to = path . join ( dest_lib , file )
65+ renameAsync ( from , to )
66+ }
67+ } )
6868
6969}
70- function install ( ) {
71- if ( ! fs . existsSync ( dest_bin ) ) {
72- fs . mkdirSync ( dest_bin )
73- }
74- if ( ! fs . existsSync ( dest_lib ) ) {
75- fs . mkdirSync ( dest_lib )
76- }
77-
78-
79-
80- var jscomp_runtime = path . join ( jscomp , 'runtime' )
81-
82- var files = fs . readdirSync ( jscomp_runtime )
83- files . forEach ( function ( file ) {
84- var format_file = path . parse ( file )
85- var special_files = [ 'js' , 'js_unsafe' , 'js_internal' , 'js_null' , 'js_undefined' , 'js_typed_array' , 'caml_exceptions' , 'js_float' ]
86- var installed_fmt = [ '.cmt' , '.cmti' , '.cmj' ]
87- if (
88- format_file &&
89- ( ( special_files . indexOf ( format_file . name ) !== - 1 )
90- ||
91- ( installed_fmt . indexOf ( format_file . ext ) !== - 1 ) )
92- ) {
93- var from = path . join ( jscomp_runtime , file )
94- var to = path . join ( dest_lib , file )
95- renameAsync ( from , to )
70+ function install ( ) {
71+ if ( ! fs . existsSync ( dest_bin ) ) {
72+ fs . mkdirSync ( dest_bin )
9673 }
97- } )
74+ if ( ! fs . existsSync ( dest_lib ) ) {
75+ fs . mkdirSync ( dest_lib )
76+ }
77+
78+
9879
99- install_directory ( path . join ( jscomp , 'stdlib' ) , dest_lib )
100- install_directory ( path . join ( jscomp , 'others' ) , dest_lib )
80+ var jscomp_runtime = path . join ( jscomp , 'runtime' )
81+
82+ var files = fs . readdirSync ( jscomp_runtime )
83+ files . forEach ( function ( file ) {
84+ var format_file = path . parse ( file )
85+ var special_files = [
86+ 'js' ,
87+ 'js_unsafe' ,
88+ 'js_internal' ,
89+ 'caml_exceptions' ,
90+ 'js_null' ,
91+ 'js_undefined' ,
92+ 'js_exn' ,
93+ 'js_int' ,
94+ 'js_float' ,
95+ 'js_typed_array'
96+ ]
97+ var installed_fmt = [ '.cmt' , '.cmti' , '.cmj' ]
98+ if (
99+ format_file &&
100+ ( ( special_files . indexOf ( format_file . name ) !== - 1 )
101+ ||
102+ ( installed_fmt . indexOf ( format_file . ext ) !== - 1 ) )
103+ // Always copy cmt* cmj*
104+ ) {
105+ var from = path . join ( jscomp_runtime , file )
106+ var to = path . join ( dest_lib , file )
107+ renameAsync ( from , to )
108+ }
109+ } )
110+
111+ install_directory ( path . join ( jscomp , 'stdlib' ) , dest_lib )
112+ install_directory ( path . join ( jscomp , 'others' ) , dest_lib )
101113}
102114
103- exports . install = install ;
115+ exports . install = install ;
104116exports . poor_copy_sync = poor_copy_sync ;
0 commit comments