Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
6,133 additions
and
709 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,17 @@ | |||
#!/usr/bin/env node | |||
|
|||
// see lib/main.js for info | |||
|
|||
const ghAuth = require('./lib/ghauth') | |||
, main = require('./lib/main') | |||
, stats = require('./lib/stats') | |||
|
|||
const config = require('./config') | |||
|
|||
config.verbose = process.argv.indexOf('-v') > -1 | |||
config.quiet = process.argv.indexOf('-q') > -1 | |||
|
|||
if (process.argv.indexOf('-s') > -1) | |||
return stats(config) | |||
|
|||
ghAuth(config, main.bind(null, config)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,25 @@ | |||
module.exports = { | |||
inFile : 'data.js' | |||
, outFile : 'data-min.js' | |||
// for now; need to tweak this later | |||
, githubLastPushCutoffMonths : 48 | |||
, sizeExceptions : [ | |||
'Backbone' | |||
, 'Zepto' | |||
] | |||
, minifyExceptions : [ | |||
'cm.js' | |||
] | |||
, errorCountThreshold : 10 | |||
, maxGzipped : 5 * 1024 | |||
// these 3 are basic sanity cecks, minimums that we would expect the contents | |||
// to be, otherwise something might be wrong | |||
, minRaw : 300 | |||
, minMinified : 150 | |||
, minGzipped : 100 | |||
// this is to compare raw with minified, if it's too close then we may have | |||
// been given the minified source in the first place | |||
, minifierTollerance : 50 | |||
// give them this much wriggle room with the reported 'size' vs actual gzipped size | |||
, expectedTolleranceFraction : 0.5 | |||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,73 +1,70 @@ | |||
var uuid = require('node-uuid') | const uuid = require('node-uuid') | ||
, fs = require('fs') | , fs = require('fs') | ||
, async = require('async') | , memo = require('async-memo') | ||
, xml = require('./xml') | , moment = require('moment') | ||
, xml = require('./xml') | |||
|
|
||
require('date-utils') | const file = 'atom.xml' | ||
|
, footRegex = /(\n<\/feed>\n?)/ | ||
var file = 'atom.xml' | , dateStr = moment.utc().format('YYYY-MM-DD\'T\'HH:mm:ssZ') | ||
, footRegex = /(\n<\/feed>\n)/ | , entryTemplate = | ||
, dateStr = new Date().addMinutes(new Date().getTimezoneOffset()).toFormat('YYYY-MM-DD\'T\'HH24:MI:SSZ') | '\t<entry>\n' | ||
, entryTemplate = | + '\t\t<title>{xmlEncodedName}</title>\n' | ||
'\t<entry>\n' | + '\t\t<link href="{url}" />\n' | ||
+ '\t\t<title>{xmlEncodedName}</title>\n' | + '\t\t<id>urn:uuid:{atomUuid}</id>\n' | ||
+ '\t\t<link href="{url}" />\n' | + '\t\t<updated>{atomDate}</updated>\n' | ||
+ '\t\t<id>urn:uuid:{atomUuid}</id>\n' | + '\t\t<summary>{xmlEncodedDescription}</summary>\n' | ||
+ '\t\t<updated>{atomDate}</updated>\n' | + '\t</entry>\n\n' | ||
+ '\t\t<summary>{xmlEncodedDescription}</summary>\n' | + '$1' | ||
+ '\t</entry>\n\n' | // memoize so we only read once, but keep contents global so we can edit it | ||
+ '$1' | , fileContents = memo( | ||
, contents | |||
|
|||
// memoize so we only read once, but keep contents global so we can edit it | |||
, fileContents = async.memoize( | |||
function (callback) { | function (callback) { | ||
fs.readFile(file, 'utf-8', function (err, _contents) { | fs.readFile(file, 'utf-8', function (err, _contents) { | ||
contents = _contents | contents = _contents | ||
callback(err) | callback(err) | ||
}) | }) | ||
} | }) | ||
, function () { return '_' } | |||
) | |||
|
|
||
, escapeRegExp = function (string) { | var contents | ||
return string.replace(/[\-\[\]\{\}\(\)*+?.\\\^$|,#\s]/g, function (match) { return '\\' + match }) | |||
} | |||
|
|
||
, exists = function (contents, lib) { | function escapeRegExp (string) { | ||
return new RegExp(escapeRegExp('<title>' + lib.xmlEncodedName + '</title>')).test(contents) | return string.replace(/[\-\[\]\{\}\(\)*+?.\\\^$|,#\s]/g, function (match) { return '\\' + match }) | ||
} | } | ||
|
|
||
, t = function (s, d){ | function exists (contents, lib) { | ||
for (var p in d) | return new RegExp(escapeRegExp('<title>' + lib.xmlEncodedName + '</title>')).test(contents) | ||
s = s.replace(new RegExp('{' + p + '}', 'g'), d[p]) | } | ||
return s | |||
} | |||
|
|
||
, processLibrary = function (lib, callback) { | function t (s, d) { | ||
fileContents(function (err) { | for (var p in d) | ||
if (err) | s = s.replace(new RegExp('{' + p + '}', 'g'), d[p]) | ||
throw err | return s | ||
} | |||
|
|
||
lib.xmlEncodedName = xml.encodeXmlEntities(lib.name) | function processLibrary (lib, callback) { | ||
if (exists(contents, lib)) | fileContents(function (err) { | ||
return callback() | if (err) | ||
throw err | |||
|
|
||
lib.atomUuid = uuid.v1() | lib.xmlEncodedName = xml.encodeXmlEntities(lib.name) | ||
lib.atomDate = dateStr | if (exists(contents, lib)) | ||
lib.xmlEncodedDescription = xml.encodeXmlEntities(lib.description) | return callback() | ||
contents = contents.replace(footRegex, t(entryTemplate, lib)) | |||
;delete lib.atomUuid | |||
;delete lib.atomDate | |||
callback() | |||
}) | |||
} | |||
|
|
||
, write = function (callback) { | lib.atomUuid = uuid.v1() | ||
fs.writeFile(file, contents, 'utf-8', callback) | lib.atomDate = dateStr | ||
} | lib.xmlEncodedDescription = xml.encodeXmlEntities(lib.description) | ||
contents = contents.replace(footRegex, t(entryTemplate, lib)) | |||
;delete lib.atomUuid | |||
;delete lib.atomDate | |||
;delete lib.xmlEncodedName | |||
;delete lib.xmlEncodedDescription | |||
callback() | |||
}) | |||
} | |||
|
|
||
module.exports = { | function write (callback) { | ||
processLibrary: processLibrary | fs.writeFile(file, contents, 'utf-8', callback) | ||
, write: write | |||
} | } | ||
|
|||
module.exports.processLibrary = processLibrary | |||
module.exports.write = write |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,47 +1,39 @@ | |||
var zip = require('zip') | var zip = require('zip') | ||
, request = require('request') | , hyperquest = require('hyperquest') | ||
, bl = require('bl') | |||
|
|
||
, requestPool = { maxSockets: 20 } | function unzip (zipEntry, buffer) { | ||
var reader = zip.Reader(buffer) | |||
, data = null | |||
|
|
||
, unzip = function (zipEntry, buffer) { | // iterate through zipfile entries looking for the right name | ||
var reader = zip.Reader(buffer) | reader.forEach(function(entry) { | ||
, data = null | if (zipEntry === entry._header.file_name) { | ||
// iterate through zipfile entries looking for the right name | data = entry._stream.toString(); | ||
reader.forEach(function(entry) { | |||
if (zipEntry === entry._header.file_name) { | |||
data = entry._stream.toString(); | |||
} | |||
}) | |||
return data | |||
} | } | ||
}) | |||
return data | |||
} | |||
|
|
||
, fetch = function (sourceUrl, zipEntry, callback) { | function fetch (sourceUrl, zipEntry, callback) { | ||
var options = { | hyperquest(sourceUrl, { headers: { 'User-Agent': 'microjs.com-build-script' } }) | ||
url: sourceUrl | .pipe(bl(function (err, content) { | ||
, encoding: zipEntry ? null : 'utf8' | if (err) | ||
, timeout: 1 * 60 * 1000 | return callback(err) | ||
, pool: requestPool | |||
, maxRedirects: 2 | |||
, headers: {"User-Agent" : "microjs.com-build-script"} | |||
} | |||
, handle = function (err, response, body) { | |||
if (err) | |||
return callback(err) | |||
|
|
||
if (zipEntry) { | if (zipEntry) { | ||
try { | try { | ||
body = unzip(zipEntry, body) | content = unzip(zipEntry, content) | ||
} catch (e) { | } catch (e) { | ||
callback('unzip error' + e) | return callback('unzip error' + e) | ||
} | } | ||
if (!body) | |||
return callback('could not find entry "' + zipEntry + '" inside zip file') | |||
} | |||
|
|
||
callback(null, body) | if (!content) | ||
} | return callback('could not find entry ' + zipEntry + ' inside zip file') | ||
} | |||
|
|
||
request(options, handle) | callback(null, content.toString()) | ||
} | })) | ||
} | |||
|
|
||
module.exports = fetch | module.exports = fetch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,21 +1,21 @@ | |||
var read = require('read') | const read = require('read') | ||
, colors = require('colors') | , colors = require('colors') | ||
|
|
||
, auth = function (config, callback) { | function auth (config, callback) { | ||
console.log('To collect GitHub stats we need you to authenticate so we can exceed API rate-limiting.'.bold.green) | console.log('To collect GitHub stats we need you to authenticate so we can exceed API rate-limiting.'.bold.green) | ||
console.log('Leave the username field blank to skip stats collection.'.bold.green) | console.log('Leave the username field blank to skip stats collection.'.bold.green) | ||
console.log() | console.log() | ||
|
|
||
read({ prompt: 'GitHub username:'.bold }, function (err, data) { | read({ prompt: 'GitHub username:'.bold }, function (err, data) { | ||
if (err) return callback(err) | if (err) return callback(err) | ||
if (data === '') return callback() | if (data === '') return callback() | ||
config.ghUser = data | config.ghUser = data | ||
read({ prompt: 'GitHub password:'.bold, silent: true, replace: '\u2714' }, function (err, data) { | read({ prompt: 'GitHub password:'.bold, silent: true, replace: '\u2714' }, function (err, data) { | ||
if (err) return callback(err) | if (err) return callback(err) | ||
config.ghPass = data | config.ghPass = data | ||
callback() | callback() | ||
}) | }) | ||
}) | }) | ||
} | } | ||
|
|
||
module.exports = auth | module.exports = auth |
Oops, something went wrong.