clang-format
Advanced tools
Comparing version 1.0.34 to 1.0.35
53
index.js
@@ -9,2 +9,4 @@ #!/usr/bin/env node | ||
var spawn = require('child_process').spawn; | ||
var glob = require("glob"); | ||
var async = require("async"); | ||
@@ -52,7 +54,48 @@ var VERSION = require('./package.json').version; | ||
} | ||
var clangFormatProcess = spawn(nativeBinary, args, {stdio: stdio}); | ||
clangFormatProcess.on('close', function(exit) { | ||
if (exit) done(exit); | ||
}); | ||
return clangFormatProcess; | ||
// extract glob, if present | ||
var filesGlob = args.filter(function(arg){return arg.indexOf('--glob=') === 0;}) | ||
.map(function(arg){return arg.replace('--glob=', '');}) | ||
.shift(); | ||
if (filesGlob) { | ||
// remove glob from arg list | ||
args = args.filter(function(arg){return arg.indexOf('--glob=') === -1;}); | ||
return glob(filesGlob, function(er, files) { | ||
// split file array into chunks of 30 | ||
var i,j, chunks = [], chunkSize = 30; | ||
for (i=0,j=files.length; i<j; i+=chunkSize) { | ||
chunks.push( files.slice(i,i+chunkSize)); | ||
} | ||
// launch a new process for each chunk | ||
async.series( | ||
chunks.map(function(chunk) { | ||
return function(callback) { | ||
var clangFormatProcess = spawn(nativeBinary, | ||
args.concat(chunk), | ||
{stdio: stdio}); | ||
clangFormatProcess.on('close', function(exit) { | ||
if (exit !== 0) callback(exit); | ||
else callback(null, exit); | ||
}); | ||
}; | ||
}), | ||
function(err, results) { | ||
if (err) done(err); | ||
console.log('\n'); | ||
console.log('ran clang-format on', | ||
files.length, | ||
files.length === 1 ? 'file' : 'files'); | ||
done(results.shift() || 0); | ||
}); | ||
}); | ||
} else { | ||
var clangFormatProcess = spawn(nativeBinary, args, {stdio: stdio}); | ||
clangFormatProcess.on('close', function(exit) { | ||
if (exit) done(exit); | ||
}); | ||
return clangFormatProcess; | ||
} | ||
} | ||
@@ -59,0 +102,0 @@ |
{ | ||
"name": "clang-format", | ||
"version": "1.0.34", | ||
"version": "1.0.35", | ||
"description": "node wrapper around clang-format", | ||
@@ -19,8 +19,11 @@ "repository": { | ||
"Alex Eagle <alexeagle@google.com>", | ||
"Martin Probst <martinprobst@google.com>" | ||
"Martin Probst <martinprobst@google.com>", | ||
"Filipe Silva <filipematossilva@gmail.com>" | ||
], | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"async": "^1.5.2", | ||
"glob": "^7.0.0", | ||
"resolve": "^1.1.6" | ||
} | ||
} |
@@ -13,2 +13,10 @@ # clang-format | ||
## Globbing files | ||
$ clang-format --glob=folder/**/*.js | ||
This will run `clang-format` once per file result, and show the total | ||
formatted files at the end. | ||
See [node-glob](https://github.com/isaacs/node-glob) for globbing semantics. | ||
## Compiling clang-format | ||
@@ -15,0 +23,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5329528
129
41
3
+ Addedasync@^1.5.2
+ Addedglob@^7.0.0
+ Addedasync@1.5.2(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedwrappy@1.0.2(transitive)