Organize local modules in lib

This commit is contained in:
Thaddee Tyl 2017-02-27 23:15:57 +01:00
parent 47a8bf51dc
commit 11b6e06f2f
11 changed files with 25 additions and 26 deletions

View File

@ -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

View File

@ -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]');

View File

@ -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.

View File

@ -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));

View File

@ -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) {

View File

@ -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);
}

View File

@ -1,5 +1,4 @@
var gm = require('gm');
var fs = require('fs');
var LruCache = require('./lru-cache.js');
var imageMagick = gm.subClass({ imageMagick: true });

View File

@ -16,7 +16,7 @@
},
"license": "CC0-1.0",
"author": "Thaddée Tyl <thaddee.tyl@gmail.com>",
"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": {

View File

@ -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);