-
Notifications
You must be signed in to change notification settings - Fork 0
/
format.js
34 lines (30 loc) · 937 Bytes
/
format.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const child_process = require('child_process');
const fs = require('fs');
const path = require('path');
const excludes = JSON.parse(fs.readFileSync('format-excludes.json', 'utf8'));
function isExcluded(filepath) {
filepath = filepath.replace(/\\/g, '/');
for (let exclude of excludes) {
if (filepath === exclude) return true;
}
return false;
}
function format(dir) {
const files = fs.readdirSync(dir);
for (let file of files) {
if (file.startsWith('.')) continue;
let filepath = path.join(dir, file);
let info = fs.statSync(filepath);
if (info.isDirectory()) {
format(filepath);
}
else {
if (isExcluded(filepath)) continue;
if (file.endsWith('.cpp') || file.endsWith('.h') || file.endsWith('.m') || file.endsWith('.mm')) {
console.log('Format ' + filepath);
child_process.execFileSync('clang-format', ['-style=file', '-i', filepath]);
}
}
}
}
format('.');