diff --git a/INSTALL.md b/INSTALL.md index a18636d..41a3441 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -85,10 +85,10 @@ The format is the following: # Defaults -If you want to add a colorscheme, head to `colorscheme.json`. Each scheme has a -name and a [CSS/SVG color][] for the color used in the first box (for the first -piece of text, field `colorA`) and for the one used in the second box (field -`colorB`). +If you want to add a colorscheme, head to `lib/colorscheme.json`. Each scheme +has a name and a [CSS/SVG color][] for the color used in the first box (for the +first piece of text, field `colorA`) and for the one used in the second box +(field `colorB`). [CSS/SVG color]: http://www.w3.org/TR/SVG/types.html#DataTypeColor diff --git a/gh-badge.js b/gh-badge.js index 24b406e..95be6eb 100755 --- a/gh-badge.js +++ b/gh-badge.js @@ -1,8 +1,8 @@ #!/usr/bin/env node var path = require('path'); -var badge = require(path.join(__dirname, 'badge.js')); -var svg2img = require(path.join(__dirname, 'svg-to-img.js')); -var colorscheme = require(path.join(__dirname, 'colorscheme.json')); +var badge = require(path.join(__dirname, 'lib', 'badge.js')); +var svg2img = require(path.join(__dirname, 'lib', 'svg-to-img.js')); +var colorscheme = require(path.join(__dirname, 'lib', 'colorscheme.json')); if (process.argv.length < 4) { console.log('Usage: badge subject status [:colorscheme] [.output] [@style]'); console.log('Or: badge subject status right-color [left-color] [.output] [@style]'); diff --git a/badge.js b/lib/badge.js similarity index 95% rename from badge.js rename to lib/badge.js index 1d7cb73..b4143ca 100644 --- a/badge.js +++ b/lib/badge.js @@ -2,16 +2,16 @@ var fs = require('fs'); var path = require('path'); var SVGO = require('svgo'); var dot = require('dot'); -var measureTextWidth = require('./measure-text'); +var measureTextWidth = require('./measure-text.js'); // cache templates. var templates = {}; -var templateFiles = fs.readdirSync(path.join(__dirname, 'templates')); +var templateFiles = fs.readdirSync(path.join(__dirname, '..', 'templates')); dot.templateSettings.strip = false; // Do not strip whitespace. templateFiles.forEach(function(filename) { if (filename[0] === '.') { return; } var templateData = fs.readFileSync( - path.join(__dirname, 'templates', filename)).toString(); + path.join(__dirname, '..', 'templates', filename)).toString(); var extension = path.extname(filename).slice(1); var style = filename.slice(0, -(('-template.' + extension).length)); // Compile the template. Necessary to always have a working template. diff --git a/colorscheme.json b/lib/colorscheme.json similarity index 100% rename from colorscheme.json rename to lib/colorscheme.json diff --git a/load-logos.js b/lib/load-logos.js similarity index 77% rename from load-logos.js rename to lib/load-logos.js index 3aa8407..bc2c545 100644 --- a/load-logos.js +++ b/lib/load-logos.js @@ -3,12 +3,12 @@ var path = require('path'); var loadLogos = function() { var logos = {}; - var logoFiles = fs.readdirSync(path.join(__dirname, 'logo')); + var logoFiles = fs.readdirSync(path.join(__dirname, '..', 'logo')); logoFiles.forEach(function(filename) { if (filename[0] === '.') { return; } // filename is eg, github.svg var svg = fs.readFileSync( - path.join(__dirname, 'logo', filename)).toString(); + path.join(__dirname, '..', 'logo', filename)).toString(); // eg, github var name = filename.slice(0, -('.svg'.length)); diff --git a/lru-cache.js b/lib/lru-cache.js similarity index 100% rename from lru-cache.js rename to lib/lru-cache.js diff --git a/measure-text.js b/lib/measure-text.js similarity index 91% rename from measure-text.js rename to lib/measure-text.js index 7bc9751..06a1b7a 100644 --- a/measure-text.js +++ b/lib/measure-text.js @@ -17,7 +17,7 @@ function loadFont(path, callback) { } } -loadFont(path.join(__dirname, 'Verdana.ttf')); +loadFont(path.join(__dirname, '..', 'Verdana.ttf')); doc = doc.fontSize(11); function measure(str) { diff --git a/suggest.js b/lib/suggest.js similarity index 99% rename from suggest.js rename to lib/suggest.js index d050e36..ca041c5 100644 --- a/suggest.js +++ b/lib/suggest.js @@ -4,7 +4,7 @@ var serverSecrets; try { // Everything that cannot be checked in but is useful server-side // is stored in this JSON data. - serverSecrets = require('./private/secret.json'); + serverSecrets = require('../private/secret.json'); } catch(e) { console.error('No secret data (private/secret.json, see server.js):', e); } diff --git a/svg-to-img.js b/lib/svg-to-img.js similarity index 98% rename from svg-to-img.js rename to lib/svg-to-img.js index abf16d7..a521b6d 100644 --- a/svg-to-img.js +++ b/lib/svg-to-img.js @@ -1,5 +1,4 @@ var gm = require('gm'); -var fs = require('fs'); var LruCache = require('./lru-cache.js'); var imageMagick = gm.subClass({ imageMagick: true }); diff --git a/package.json b/package.json index 30b8464..1b6694e 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ }, "license": "CC0-1.0", "author": "Thaddée Tyl ", - "main": "badge.js", + "main": "lib/badge.js", "repository": { "type": "git", "url": "https://github.com/badges/shields" @@ -44,14 +44,14 @@ "badge": "./gh-badge.js" }, "files": [ - "badge.js", "README.md", "gh-badge.js", - "measure-text.js", + "lib/badge.js", + "lib/colorscheme.json", + "lib/lru-cache.js", + "lib/measure-text.js", + "lib/svg-to-img.js", "templates", - "svg-to-img.js", - "colorscheme.json", - "lru-cache.js", "logo" ], "devDependencies": { diff --git a/server.js b/server.js index f42ca0a..3b12b8c 100644 --- a/server.js +++ b/server.js @@ -16,10 +16,10 @@ console.log('http://[::1]:' + serverPort + '/try.html'); var domain = require('domain'); var request = require('request'); var fs = require('fs'); -var LruCache = require('./lru-cache.js'); -var badge = require('./badge.js'); -var svg2img = require('./svg-to-img.js'); -var loadLogos = require('./load-logos.js'); +var LruCache = require('./lib/lru-cache.js'); +var badge = require('./lib/badge.js'); +var svg2img = require('./lib/svg-to-img.js'); +var loadLogos = require('./lib/load-logos.js'); var githubAuth = require('./lib/github-auth.js'); var querystring = require('querystring'); var xml2js = require('xml2js'); @@ -149,7 +149,7 @@ function incrMonthlyAnalytics(monthlyAnalytics) { } analyticsAutoLoad(); -var suggest = require('./suggest.js'); +var suggest = require('./lib/suggest.js'); camp.ajax.on('analytics/v1', function(json, end) { end(analytics); }); camp.ajax.on('suggest/v1', suggest);