@@ -4,6 +4,21 @@ const file = require("./util/file");
4
4
const idefs = require ( "./idefs" ) ;
5
5
const promisify = require ( "promisify-node" ) ;
6
6
const fse = promisify ( require ( "fs-extra" ) ) ;
7
+ const js_beautify = require ( 'js-beautify' ) . js_beautify ;
8
+ const beautify = function ( input ) {
9
+ return js_beautify ( input , {
10
+ "brace_style" : "end-expand" ,
11
+ "max_preserve_newlines" : 2 ,
12
+ "preserve_newlines" : true ,
13
+ "indent_size" : 2 ,
14
+ "indent_char" : " "
15
+ } ) ;
16
+ }
17
+
18
+
19
+ var exec = promisify ( function ( command , opts , callback ) {
20
+ return require ( "child_process" ) . exec ( command , opts , callback ) ;
21
+ } ) ;
7
22
8
23
// Customize the delimiters so as to not process `{{{` or `}}}`.
9
24
combyne . settings . delimiters = {
@@ -83,7 +98,7 @@ fse.remove(path.resolve(__dirname, "../src")).then(function() {
83
98
return fse . copy ( path . resolve ( __dirname , "./manual/" ) , path . resolve ( __dirname , "../" ) ) ;
84
99
} ) . then ( function ( ) {
85
100
// Write out single purpose templates.
86
- file . write ( "../binding.gyp" , templates . binding . render ( enabled ) ) ;
101
+ file . write ( "../binding.gyp" , beautify ( templates . binding . render ( enabled ) ) ) ;
87
102
file . write ( "../src/nodegit.cc" , templates . nodegit . render ( enabled ) ) ;
88
103
89
104
@@ -106,5 +121,22 @@ fse.remove(path.resolve(__dirname, "../src")).then(function() {
106
121
}
107
122
} ) ;
108
123
109
- file . write ( "../lib/enums.js" , templates . enums . render ( enabled ) ) ;
124
+
125
+ file . write ( "../lib/enums.js" , beautify ( templates . enums . render ( enabled ) ) ) ;
126
+ } ) . then ( function ( ) {
127
+ return exec ( 'command -v astyle' ) . then ( function ( astyle ) {
128
+ if ( astyle ) {
129
+ return exec (
130
+ 'astyle --options=\".astylerc\" '
131
+ + path . resolve ( __dirname , "../src" ) + "/*.cc "
132
+ + path . resolve ( __dirname , "../include" ) + "/*.h"
133
+ ) . then ( function ( ) {
134
+ return exec (
135
+ 'rm '
136
+ + path . resolve ( __dirname , "../src" ) + "/*.cc.orig "
137
+ + path . resolve ( __dirname , "../include" ) + "/*.h.orig "
138
+ ) ;
139
+ } ) ;
140
+ }
141
+ } )
110
142
} ) ;
0 commit comments