Skip to content

Commit 47a68d2

Browse files
committed
prettify generated output
1 parent fb52c7e commit 47a68d2

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

.astylerc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--style=linux
2+
--indent=spaces=2
3+
--attach-namespaces
4+
--attach-classes
5+
--attach-inlines
6+
--attach-extern-c

generate/index.js

+34-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ const file = require("./util/file");
44
const idefs = require("./idefs");
55
const promisify = require("promisify-node");
66
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+
});
722

823
// Customize the delimiters so as to not process `{{{` or `}}}`.
924
combyne.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
});

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"fs-extra": "^0.12.0",
6565
"lodash": "^2.4.1",
6666
"istanbul": "~0.3.2",
67+
"js-beautify": "^1.5.4",
6768
"jshint": "~2.5.6",
6869
"mocha": "~1.21.4",
6970
"nan": "~1.3.0",

0 commit comments

Comments
 (0)