Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add pygments existence check. Closes #36

  • Loading branch information...
commit 4b8b4a2f7141190577c7730e8b86f785a7433b51 1 parent e56589b
@jbt authored
Showing with 40 additions and 0 deletions.
  1. +40 −0 src/docker.js
View
40 src/docker.js
@@ -44,6 +44,7 @@
// Include all the necessay node modules.
var mkdirp = require('mkdirp'),
fs = require('fs'),
+ os = require('os'),
path = require('path'),
exec = require('child_process').exec,
spawn = require('child_process').spawn,
@@ -64,6 +65,10 @@ if(typeof fs.exists != 'function') fs.exists = path.exists;
* * Or `indir`, `outDir`, `onlyUpdated`, `colourScheme` and `ignoreHidden` in order
*/
var Docker = module.exports = function( /* inDir, outDir, onlyUpdated, colourScheme, ignoreHidden */ ){
+ if(!this.checkForPygments()){
+ throw new Error("Pygments doesn't appear to be installed. Docker can't work.");
+ }
+
if(typeof arguments[0] === 'object'){
this.parseOpts(arguments[0]);
}else{
@@ -145,6 +150,41 @@ Docker.prototype.parseOpts = function(opts){
};
/**
+ * ## Docker.prototype.checkForPygments
+ *
+ * Checks to see whether Pygments is installed
+ *
+ * @return {boolean} True or false, whether Pygments is present
+ */
+Docker.prototype.checkForPygments = function(){
+
+ // Grab the platform type; it'll tell us how $PATH is delimited
+ var platformType = os.type();
+
+ var Path = process.env.path || process.env.Path || process.env.PATH;
+
+ Path = Path.split(/^Win/.test(platformType) ? ';' : ':');
+
+ // We care about whether the pygmentize command exists on at least
+ // one of the given paths. We can use Array.some for this
+ return Path.some(function(dir){
+
+ // Resolve where the command would be for this path
+ var guess = path.resolve(dir, 'pygmentize');
+
+ return fs.existsSync(guess) || (
+
+ // for Windows, there are a few more options
+ /^Win/.test(platformType) && (
+ fs.existsSync(guess + '.exe') ||
+ fs.existsSync(guess + '.cmd') ||
+ fs.existsSync(guess + '.bat')
+ ));
+
+ });
+};
+
+/**
* ## Docker.prototype.doc
*
* Generate documentation for a bunch of files
Please sign in to comment.
Something went wrong with that request. Please try again.