diff --git a/src/drivers/npm/index.js b/src/drivers/npm/index.js index 35ffd2a35..153273a70 100644 --- a/src/drivers/npm/index.js +++ b/src/drivers/npm/index.js @@ -4,26 +4,65 @@ var request = require('request'); var fs = require('fs'); var path = require('path'); -//TODO -exports.detectFromHTML = function(options) {}; +/** +* Does the actual detection with information passed +**/ +exports.detect = function(options, data, cb) { + // run the wrapper function that will + // trigger the actual library to run + runWrappalyer(options, data, cb); + +}; + +/** +* Wraps the detect method, just kept to reuse old method names +* and not break anything. Although this was just stubbed out. +**/ +exports.detectFromHTML = function(options, data, cb) { + + // run the detect method + exports.detect(options, data, cb); + +}; + +/** +* Do a actual request for the body & headers, then +* run through detection +**/ exports.detectFromUrl = function(options, cb) { - var url = options.url; + // ensure options and url were + if(!options || !options.url) { - if (options.debug) { - console.log('Fetching the page'); - } + // send back a error ... + cb(new Error("\"url\" is a required option to run" + + " wappalyzer and get the page content")) - getHTMLFromUrl(url, function(err, data) { - if (err || data === null) { - cb(err, null); - } else { - runWrappalyer(options, data, function(err, detected, appInfo) { - cb(null, detected, appInfo); - }); - } - }); + } else { + + // local variables to + var url = options.url; + + // get the body content from the url + getHTMLFromUrl(url, function(err, data) { + + // check for error or if we got no data back + if (err || data === null) { + + // handle the error and don't do anything else .. + cb(err, null); + + } else { + + // run actual detection + exports.detect(options, data, cb); + + } + + }); + + } }; function getHTMLFromUrl(url, cb) { @@ -42,7 +81,7 @@ function getHTMLFromUrl(url, cb) { } function getAppsJson(cb) { - fs.readFile(path.resolve(__dirname, 'apps.json'), 'utf8', function(err, data) { + fs.readFile(path.resolve(__dirname, '../../apps.json'), 'utf8', function(err, data) { if (err) throw err; return cb(null, JSON.parse(data)); }); @@ -51,7 +90,20 @@ function getAppsJson(cb) { function runWrappalyer(options, data, cb) { var debug = options.debug || false; - var wappalyzer = require('./wappalyzer').wappalyzer; + // according to environment check it + var wappalyzer = null; + + // change depending on the environment + if( process.env.NODE_ENV ) { + + wappalyzer = require('../../wappalyzer').wappalyzer; + + } else { + + wappalyzer = require('./wappalyzer').wappalyzer; + + } + getAppsJson(function(err, apps) { var w = wappalyzer; w.driver = { diff --git a/src/drivers/npm/package.json b/src/drivers/npm/package.json index d1131c707..71171aac7 100644 --- a/src/drivers/npm/package.json +++ b/src/drivers/npm/package.json @@ -4,7 +4,7 @@ "description": "NPM Module that uncovers the technologies used on websites", "main": "index.js", "scripts": { - "test": "mocha -t 15000" + "test": "NODE_ENV=testing mocha -t 15000" }, "repository": { "type": "git", diff --git a/src/drivers/npm/test/sample.headers.json b/src/drivers/npm/test/sample.headers.json new file mode 100644 index 000000000..c8441bf8e --- /dev/null +++ b/src/drivers/npm/test/sample.headers.json @@ -0,0 +1,20 @@ +{ + "Date":"Fri, 17 Jul 2015 11:05:08 GMT", + "Content-Encoding":"gzip", + "Age":"0", + "X-Cache":"MISS", + "Connection":"keep-alive", + "Content-Length":"1940", + "Via":"1.1 varnish", + "X-Served-By":"cache-lcy1122-LCY", + "Last-Modified":"Thu, 16 Apr 2015 14:24:18 GMT", + "Server":"GitHub.com", + "X-Timer":"S1437131108.300792,VS0,VE84", + "Vary":"Accept-Encoding", + "Content-Type":"text/html; charset=utf-8", + "Access-Control-Allow-Origin":"*", + "Expires":"Fri, 17 Jul 2015 11:10:54 GMT", + "Cache-Control":"max-age=600", + "Accept-Ranges":"bytes", + "X-Cache-Hits":"0" +} \ No newline at end of file diff --git a/src/drivers/npm/test/sample.html b/src/drivers/npm/test/sample.html new file mode 100644 index 000000000..f8624a4e1 --- /dev/null +++ b/src/drivers/npm/test/sample.html @@ -0,0 +1,149 @@ + + + +
+ + + +Github - + {{presentation.github}} +
+Demo - + {{presentation.demo}} +
+ +License - {{presentation.license}}
+ +Language - {{presentation.language}}
+