Permalink
Browse files

add platform check

  • Loading branch information...
1 parent 26e2041 commit 566e37a15a929995e503379db6c0164431daae19 @vavere committed Sep 29, 2012
Showing with 34 additions and 4 deletions.
  1. +3 −0 .gitignore
  2. +1 −0 package.json
  3. +30 −4 tidy.js
View
@@ -1 +1,4 @@
.c9*
+.settings
+node_modules
+
View
@@ -14,4 +14,5 @@
"engines": {
"node": ""
}
+ "os" : [ "linux","win32" ]
}
View
34 tidy.js
@@ -1,15 +1,41 @@
-var spawn = require('child_process').spawn;
var fs = require('fs');
+var path = require('path');
+var spawn = require('child_process').spawn;
+
+var tidyExeRel;
+
+switch (process.platform) {
+ case 'win32':
+ tidyExeRel = path.join('bin', 'tidy.exe');
+ break;
+ case 'linux':
+ tidyExeRel = path.join('bin', 'tidy');;
+ break;
+ default: // compatibility
+ log("tidy can only operate on linux and windows");
+ process.exit(1);
+ return;
+}
+
+var tidyExeAbs = path.join(__dirname, tidyExeRel);
+
+// compatibility
+var existsSync = fs.existsSync||path.existsSync;
+
+if (!existsSync(tidyExeAbs)) {
+ log('missing tidy executable: ' + tidyExeRel);
+ process.exit(2);
+ return;
+}
function tidy(str, callback) {
var buffer = '';
- var error = '';
+ var error = '';
if (!callback) {
throw new Error('No callback provided for tidy.html');
}
- var ptidy = spawn(
- 'tidy',
+ var ptidy = spawn(tidyExeAbs,
[
'--doctype','html5',
'--quiet','y',

0 comments on commit 566e37a

Please sign in to comment.