11const path = require ( "path" ) ;
22const fse = require ( "fs-extra" ) ;
3- const os = require ( 'os' ) ;
4- const exec = require ( ' ../../utils/execPromise' ) ;
3+ const os = require ( "os" ) ;
4+ const exec = require ( " ../../utils/execPromise" ) ;
55const utils = require ( "./utils" ) ;
66
77module . exports = function generateNativeCode ( ) {
@@ -25,20 +25,24 @@ module.exports = function generateNativeCode() {
2525
2626 var partials = {
2727 asyncFunction : utils . readLocalFile ( "templates/partials/async_function.cc" ) ,
28- callbackHelpers : utils . readLocalFile ( "templates/partials/callback_helpers.cc" ) ,
28+ callbackHelpers :
29+ utils . readLocalFile ( "templates/partials/callback_helpers.cc" ) ,
2930 convertFromV8 : utils . readLocalFile ( "templates/partials/convert_from_v8.cc" ) ,
3031 convertToV8 : utils . readLocalFile ( "templates/partials/convert_to_v8.cc" ) ,
3132 doc : utils . readLocalFile ( "templates/partials/doc.cc" ) ,
3233 fields : utils . readLocalFile ( "templates/partials/fields.cc" ) ,
33- guardArguments : utils . readLocalFile ( "templates/partials/guard_arguments.cc" ) ,
34+ guardArguments :
35+ utils . readLocalFile ( "templates/partials/guard_arguments.cc" ) ,
3436 syncFunction : utils . readLocalFile ( "templates/partials/sync_function.cc" ) ,
35- fieldAccessors : utils . readLocalFile ( "templates/partials/field_accessors.cc" ) ,
37+ fieldAccessors :
38+ utils . readLocalFile ( "templates/partials/field_accessors.cc" ) ,
3639 traits : utils . readLocalFile ( "templates/partials/traits.h" )
3740 } ;
3841
3942 var templates = {
4043 class_content : utils . readLocalFile ( "templates/templates/class_content.cc" ) ,
41- struct_content : utils . readLocalFile ( "templates/templates/struct_content.cc" ) ,
44+ struct_content :
45+ utils . readLocalFile ( "templates/templates/struct_content.cc" ) ,
4246 class_header : utils . readLocalFile ( "templates/templates/class_header.h" ) ,
4347 struct_header : utils . readLocalFile ( "templates/templates/struct_header.h" ) ,
4448 binding : utils . readLocalFile ( "templates/templates/binding.gyp" ) ,
@@ -69,7 +73,7 @@ module.exports = function generateNativeCode() {
6973 returnsInfo : require ( "../templates/filters/returns_info" ) ,
7074 subtract : require ( "../templates/filters/subtract" ) ,
7175 titleCase : require ( "../templates/filters/title_case" ) ,
72- toBool : require ( ' ../templates/filters/to_bool' ) ,
76+ toBool : require ( " ../templates/filters/to_bool" ) ,
7377 unPointer : require ( "../templates/filters/un_pointer" ) ,
7478 setUnsigned : require ( "../templates/filters/unsigned" ) ,
7579 upper : require ( "../templates/filters/upper" )
@@ -88,9 +92,12 @@ module.exports = function generateNativeCode() {
8892 // Attach all partials to select templates.
8993 Object . keys ( partials ) . forEach ( function ( partial ) {
9094 templates . class_header . registerPartial ( partial , combyne ( partials [ partial ] ) ) ;
91- templates . class_content . registerPartial ( partial , combyne ( partials [ partial ] ) ) ;
92- templates . struct_header . registerPartial ( partial , combyne ( partials [ partial ] ) ) ;
93- templates . struct_content . registerPartial ( partial , combyne ( partials [ partial ] ) ) ;
95+ templates . class_content
96+ . registerPartial ( partial , combyne ( partials [ partial ] ) ) ;
97+ templates . struct_header
98+ . registerPartial ( partial , combyne ( partials [ partial ] ) ) ;
99+ templates . struct_content
100+ . registerPartial ( partial , combyne ( partials [ partial ] ) ) ;
94101 } ) ;
95102
96103
@@ -101,22 +108,41 @@ module.exports = function generateNativeCode() {
101108 return ! idef . ignore ;
102109 } ) ;
103110
104- const tempDirPath = path . join ( os . tmpdir ( ) , ' nodegit_build' ) ;
111+ const tempDirPath = path . join ( os . tmpdir ( ) , " nodegit_build" ) ;
105112 const tempSrcDirPath = path . join ( tempDirPath , "src" ) ;
106113 const tempIncludeDirPath = path . join ( tempDirPath , "include" ) ;
107114
108- const finalSrcDirPath = path . join ( __dirname , '../../src' ) ;
109- const finalIncludeDirPath = path . join ( __dirname , '../../include' ) ;
110-
111- fse . remove ( tempDirPath ) . then ( function ( ) {
112- return fse . copy ( path . resolve ( __dirname , "../templates/manual/include" ) , tempIncludeDirPath ) ;
113- } ) . then ( function ( ) {
114- return fse . copy ( path . resolve ( __dirname , "../templates/manual/src" ) , tempSrcDirPath ) ;
115+ const finalSrcDirPath = path . join ( __dirname , "../../src" ) ;
116+ const finalIncludeDirPath = path . join ( __dirname , "../../include" ) ;
117+
118+ fse . remove ( tempDirPath )
119+ . then ( function ( ) {
120+ return fse . copy (
121+ path . resolve ( __dirname , "../templates/manual/include" ) ,
122+ tempIncludeDirPath
123+ ) ;
124+ } ) . then ( function ( ) {
125+ return fse . copy (
126+ path . resolve ( __dirname , "../templates/manual/src" ) ,
127+ tempSrcDirPath
128+ ) ;
115129 } ) . then ( function ( ) {
116130 // Write out single purpose templates.
117- utils . writeLocalFile ( "../binding.gyp" , beautify ( templates . binding . render ( enabled ) ) , "binding.gyp" ) ;
118- utils . writeFile ( path . join ( tempSrcDirPath , "nodegit.cc" ) , templates . nodegitCC . render ( enabled ) , "nodegit.cc" ) ;
119- utils . writeLocalFile ( "../lib/nodegit.js" , beautify ( templates . nodegitJS . render ( enabled ) ) , "nodegit.js" ) ;
131+ utils . writeLocalFile (
132+ "../binding.gyp" ,
133+ beautify ( templates . binding . render ( enabled ) ) ,
134+ "binding.gyp"
135+ ) ;
136+ utils . writeFile (
137+ path . join ( tempSrcDirPath , "nodegit.cc" ) ,
138+ templates . nodegitCC . render ( enabled ) ,
139+ "nodegit.cc"
140+ ) ;
141+ utils . writeLocalFile (
142+ "../lib/nodegit.js" ,
143+ beautify ( templates . nodegitJS . render ( enabled ) ) ,
144+ "nodegit.js"
145+ ) ;
120146 // Write out all the classes.
121147 enabled . forEach ( function ( idef ) {
122148 if ( idef . type && idef . type != "enum" ) {
@@ -134,7 +160,11 @@ module.exports = function generateNativeCode() {
134160 }
135161 } ) ;
136162
137- utils . writeLocalFile ( "../lib/enums.js" , beautify ( templates . enums . render ( enabled ) ) , "enums.js" ) ;
163+ utils . writeLocalFile (
164+ "../lib/enums.js" ,
165+ beautify ( templates . enums . render ( enabled ) ) ,
166+ "enums.js"
167+ ) ;
138168 } ) . then ( function ( ) {
139169 return exec ( "command -v astyle" ) . then ( function ( astyle ) {
140170 if ( astyle ) {
@@ -159,7 +189,6 @@ module.exports = function generateNativeCode() {
159189 } ) . then ( function ( ) {
160190 return fse . remove ( tempDirPath ) ;
161191 } ) . catch ( console . log ) ;
162-
163192} ;
164193
165194if ( require . main === module ) {
0 commit comments