clang-format
Advanced tools
Comparing version
| #! /usr/bin/env node | ||
| // polyfill for node < 0.12 | ||
| var spawnSync = require('spawn-sync'); | ||
| var os = require('os'); | ||
| var fs = require('fs'); | ||
| var clangFormat = require('../index').spawnClangFormat; | ||
| var nativeBinary = __dirname + '/' + os.platform() + "_" + os.arch() + '/clang-format'; | ||
| if (!fs.existsSync(nativeBinary)) { | ||
| process.stdout.write("FATAL: This module doesn't bundle the clang-format executable for your platform. "); | ||
| process.stdout.write("(" + os.platform() + "_" + os.arch() + ")\n"); | ||
| process.stdout.write("Consider installing it with your native package manager instead.\n"); | ||
| process.exit(1); | ||
| try { | ||
| clangFormat(process.argv.slice(2), process.exit, 'inherit'); | ||
| } catch (e) { | ||
| process.stdout.write(e.message); | ||
| process.exit(1); | ||
| } | ||
| var result = spawnSync(nativeBinary, process.argv.slice(2)); | ||
| process.stderr.write(result.stderr); | ||
| // Note, status code will always equal 0 if using busy waiting fallback | ||
| if (result.status !== 0) { | ||
| process.exit(result.status); | ||
| } else { | ||
| process.stdout.write(result.stdout); | ||
| } |
41
index.js
| var spawn = require('child_process').spawn; | ||
| var os = require('os'); | ||
| var fs = require('fs'); | ||
@@ -12,20 +13,32 @@ /** | ||
| */ | ||
| function spawnClangFormat(file, enc, style, done) { | ||
| var child_process = | ||
| spawn('bin/' + os.platform() + "_" + os.arch() + '/clang-format', | ||
| ['-style=' + style, file.path], { | ||
| stdio: ['ignore', 'pipe', process.stderr], | ||
| cwd: __dirname, | ||
| encoding: enc | ||
| }); | ||
| function clangFormat(file, enc, style, done) { | ||
| return spawnClangFormat(['-style=' + style, file.path], done, | ||
| ['ignore', 'pipe', process.stderr]) | ||
| .stdout; | ||
| } | ||
| child_process.on('close', function(code) { | ||
| if (code) { | ||
| done(code); | ||
| /** | ||
| * Spawn the clang-format binary with given arguments | ||
| */ | ||
| function spawnClangFormat(args, done, stdio) { | ||
| var nativeBinary = __dirname + '/bin/' + os.platform() + "_" + os.arch() + '/clang-format'; | ||
| if (!fs.existsSync(nativeBinary)) { | ||
| message = "FATAL: This module doesn't bundle the clang-format executable for your platform. " + | ||
| "(" + os.platform() + "_" + os.arch() + ")\n" + | ||
| "Consider installing it with your native package manager instead.\n"; | ||
| throw new Error(message); | ||
| } | ||
| var child_process = spawn(nativeBinary, args, { | ||
| stdio: stdio, | ||
| cwd: __dirname, | ||
| }); | ||
| child_process.on('close', function(exit) { | ||
| if (exit) { | ||
| done(exit); | ||
| } | ||
| }); | ||
| return child_process.stdout; | ||
| return child_process; | ||
| } | ||
| module.exports = spawnClangFormat; | ||
| module.exports = clangFormat; | ||
| module.exports.spawnClangFormat = spawnClangFormat; |
| { | ||
| "name": "clang-format", | ||
| "version": "1.0.0", | ||
| "version": "1.0.1", | ||
| "description": "node wrapper around clang-format", | ||
@@ -10,3 +10,2 @@ "repository": { | ||
| "main": "index.js", | ||
| "preferGlobal": "true", | ||
| "bin": { | ||
@@ -16,6 +15,3 @@ "clang-format": "bin/wrapper.js" | ||
| "author": "Alex Eagle <alexeagle@google.com>", | ||
| "license": "Apache 2", | ||
| "dependencies": { | ||
| "spawn-sync": "^1.0.5" | ||
| } | ||
| "license": "Apache 2" | ||
| } |
Sorry, the diff of this file is not supported yet
0
-100%48
4.35%1441152
-0.28%- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed