@@ -24,27 +24,27 @@ module.exports = function generateNativeCode() {
2424 } ;
2525
2626 var partials = {
27- asyncFunction : utils . readFile ( "templates/partials/async_function.cc" ) ,
28- callbackHelpers : utils . readFile ( "templates/partials/callback_helpers.cc" ) ,
29- convertFromV8 : utils . readFile ( "templates/partials/convert_from_v8.cc" ) ,
30- convertToV8 : utils . readFile ( "templates/partials/convert_to_v8.cc" ) ,
31- doc : utils . readFile ( "templates/partials/doc.cc" ) ,
32- fields : utils . readFile ( "templates/partials/fields.cc" ) ,
33- guardArguments : utils . readFile ( "templates/partials/guard_arguments.cc" ) ,
34- syncFunction : utils . readFile ( "templates/partials/sync_function.cc" ) ,
35- fieldAccessors : utils . readFile ( "templates/partials/field_accessors.cc" ) ,
36- traits : utils . readFile ( "templates/partials/traits.h" )
27+ asyncFunction : utils . readLocalFile ( "templates/partials/async_function.cc" ) ,
28+ callbackHelpers : utils . readLocalFile ( "templates/partials/callback_helpers.cc" ) ,
29+ convertFromV8 : utils . readLocalFile ( "templates/partials/convert_from_v8.cc" ) ,
30+ convertToV8 : utils . readLocalFile ( "templates/partials/convert_to_v8.cc" ) ,
31+ doc : utils . readLocalFile ( "templates/partials/doc.cc" ) ,
32+ fields : utils . readLocalFile ( "templates/partials/fields.cc" ) ,
33+ guardArguments : utils . readLocalFile ( "templates/partials/guard_arguments.cc" ) ,
34+ syncFunction : utils . readLocalFile ( "templates/partials/sync_function.cc" ) ,
35+ fieldAccessors : utils . readLocalFile ( "templates/partials/field_accessors.cc" ) ,
36+ traits : utils . readLocalFile ( "templates/partials/traits.h" )
3737 } ;
3838
3939 var templates = {
40- class_content : utils . readFile ( "templates/templates/class_content.cc" ) ,
41- struct_content : utils . readFile ( "templates/templates/struct_content.cc" ) ,
42- class_header : utils . readFile ( "templates/templates/class_header.h" ) ,
43- struct_header : utils . readFile ( "templates/templates/struct_header.h" ) ,
44- binding : utils . readFile ( "templates/templates/binding.gyp" ) ,
45- nodegitCC : utils . readFile ( "templates/templates/nodegit.cc" ) ,
46- nodegitJS : utils . readFile ( "templates/templates/nodegit.js" ) ,
47- enums : utils . readFile ( "templates/templates/enums.js" )
40+ class_content : utils . readLocalFile ( "templates/templates/class_content.cc" ) ,
41+ struct_content : utils . readLocalFile ( "templates/templates/struct_content.cc" ) ,
42+ class_header : utils . readLocalFile ( "templates/templates/class_header.h" ) ,
43+ struct_header : utils . readLocalFile ( "templates/templates/struct_header.h" ) ,
44+ binding : utils . readLocalFile ( "templates/templates/binding.gyp" ) ,
45+ nodegitCC : utils . readLocalFile ( "templates/templates/nodegit.cc" ) ,
46+ nodegitJS : utils . readLocalFile ( "templates/templates/nodegit.js" ) ,
47+ enums : utils . readLocalFile ( "templates/templates/enums.js" )
4848 } ;
4949
5050 var filters = {
@@ -99,28 +99,32 @@ module.exports = function generateNativeCode() {
9999 return ! idef . ignore ;
100100 } ) ;
101101
102+ const tempDirPath = path . resolve ( __dirname , "../../temp" ) ;
103+ const tempSrcDirPath = path . join ( tempDirPath , "src" ) ;
104+ const tempIncludeDirPath = path . join ( tempDirPath , "include" ) ;
102105
103- fse . remove ( path . resolve ( __dirname , "../../src" ) ) . then ( function ( ) {
104- return fse . remove ( path . resolve ( __dirname , "../../include" ) ) ;
105- } ) . then ( function ( ) {
106- return fse . copy ( path . resolve ( __dirname , "../templates/manual/include" ) , path . resolve ( __dirname , "../../include" ) ) ;
106+ const finalSrcDirPath = path . join ( __dirname , '../../src' ) ;
107+ const finalIncludeDirPath = path . join ( __dirname , '../../include' ) ;
108+
109+ fse . remove ( tempDirPath ) . then ( function ( ) {
110+ return fse . copy ( path . resolve ( __dirname , "../templates/manual/include" ) , tempIncludeDirPath ) ;
107111 } ) . then ( function ( ) {
108- return fse . copy ( path . resolve ( __dirname , "../templates/manual/src" ) , path . resolve ( __dirname , "../../src" ) ) ;
112+ return fse . copy ( path . resolve ( __dirname , "../templates/manual/src" ) , tempSrcDirPath ) ;
109113 } ) . then ( function ( ) {
110114 // Write out single purpose templates.
111115 utils . writeFile ( "../binding.gyp" , beautify ( templates . binding . render ( enabled ) ) , "binding.gyp" ) ;
112- utils . writeFile ( "../src/nodegit.cc" , templates . nodegitCC . render ( enabled ) , "nodegit.cc" ) ;
116+ utils . writeFile ( "../temp/ src/nodegit.cc" , templates . nodegitCC . render ( enabled ) , "nodegit.cc" ) ;
113117 utils . writeFile ( "../lib/nodegit.js" , beautify ( templates . nodegitJS . render ( enabled ) ) , "nodegit.js" ) ;
114118 // Write out all the classes.
115119 enabled . forEach ( function ( idef ) {
116120 if ( idef . type && idef . type != "enum" ) {
117121 utils . writeFile (
118- "../src/" + idef . filename + ".cc" ,
122+ "../temp/ src/" + idef . filename + ".cc" ,
119123 templates [ idef . type + "_content" ] . render ( idef ) ,
120124 idef . type + "_content.cc"
121125 ) ;
122126 utils . writeFile (
123- "../include/" + idef . filename + ".h" ,
127+ "../temp/ include/" + idef . filename + ".h" ,
124128 templates [ idef . type + "_header" ] . render ( idef ) ,
125129 idef . type + "_header.h"
126130 ) ;
@@ -133,17 +137,24 @@ module.exports = function generateNativeCode() {
133137 if ( astyle ) {
134138 return exec (
135139 "astyle --options=\".astylerc\" "
136- + path . resolve ( __dirname , "../../src" ) + "/*.cc "
137- + path . resolve ( __dirname , "../../include" ) + "/*.h"
140+ + tempSrcDirPath + "/*.cc "
141+ + tempIncludeDirPath + "/*.h"
138142 ) . then ( function ( ) {
139143 return exec (
140144 "rm "
141- + path . resolve ( __dirname , "../../src" ) + "/*.cc.orig "
142- + path . resolve ( __dirname , "../../include" ) + "/*.h.orig "
145+ + tempSrcDirPath + "/*.cc.orig "
146+ + tempIncludeDirPath + "/*.h.orig "
143147 ) ;
144148 } ) ;
145149 }
146150 } , function ( ) { } )
151+ } ) . then ( function ( ) {
152+ return Promise . all ( [
153+ utils . syncDirs ( tempSrcDirPath , finalSrcDirPath ) ,
154+ utils . syncDirs ( tempIncludeDirPath , finalIncludeDirPath ) ,
155+ ] ) ;
156+ } ) . then ( function ( ) {
157+ return fse . remove ( tempDirPath ) ;
147158 } ) . catch ( console . log ) ;
148159
149160} ;
0 commit comments