@@ -4,6 +4,21 @@ const file = require("./util/file");
44const idefs = require ( "./idefs" ) ;
55const promisify = require ( "promisify-node" ) ;
66const 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+ } ) ;
722
823// Customize the delimiters so as to not process `{{{` or `}}}`.
924combyne . settings . delimiters = {
@@ -83,7 +98,7 @@ fse.remove(path.resolve(__dirname, "../src")).then(function() {
8398 return fse . copy ( path . resolve ( __dirname , "./manual/" ) , path . resolve ( __dirname , "../" ) ) ;
8499} ) . then ( function ( ) {
85100 // Write out single purpose templates.
86- file . write ( "../binding.gyp" , templates . binding . render ( enabled ) ) ;
101+ file . write ( "../binding.gyp" , beautify ( templates . binding . render ( enabled ) ) ) ;
87102 file . write ( "../src/nodegit.cc" , templates . nodegit . render ( enabled ) ) ;
88103
89104
@@ -106,5 +121,22 @@ fse.remove(path.resolve(__dirname, "../src")).then(function() {
106121 }
107122 } ) ;
108123
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+ } )
110142} ) ;
0 commit comments