Files

46 lines
925 B
JavaScript
Raw Permalink Normal View History

2015-03-23 05:15:10 -03:00
'use strict';
2015-03-19 05:11:58 -03:00
var util = require('util');
var path = require('path');
var JsonFile = require('./JsonFile');
2015-03-23 18:35:35 -03:00
var CANONICAL_NAME_EXPECTATION = /^([^:\s]*):([^\s]*)$/;
2015-03-19 05:11:58 -03:00
/**
2015-03-24 21:47:19 -03:00
* @constructor OverrideFile
2015-03-23 18:35:35 -03:00
*/
2015-03-24 21:47:19 -03:00
var OverrideFile = module.exports = function OverrideFile(){
2015-03-19 05:11:58 -03:00
2015-03-24 21:47:19 -03:00
if( !(this instanceof OverrideFile) )
return new OverrideFile();
2015-03-19 05:11:58 -03:00
JsonFile.call(this, path.resolve('./registry.json'));
};
2015-03-24 21:47:19 -03:00
util.inherits(OverrideFile, JsonFile);
2015-03-19 05:11:58 -03:00
2015-03-24 21:47:19 -03:00
OverrideFile.prototype.forEachRegistryEntry = function(fn){
2015-03-23 05:15:10 -03:00
2015-03-23 18:35:35 -03:00
return this.forEach(function(canonicalPackageName, registryEntryName){
2015-03-23 05:15:10 -03:00
var pkg = {};
2015-03-23 18:35:35 -03:00
var match = CANONICAL_NAME_EXPECTATION.exec(canonicalPackageName);
2015-03-23 05:15:10 -03:00
if (!match) {
pkg = {
2015-03-23 18:35:35 -03:00
canonical: canonicalPackageName,
2015-03-23 05:15:10 -03:00
endpoint: undefined,
name: undefined,
};
} else {
pkg = {
2015-03-23 18:35:35 -03:00
canonical: match[0],
2015-03-23 05:15:10 -03:00
endpoint: match[1],
name: match[2],
};
}
2015-03-23 18:35:35 -03:00
fn.call(this, pkg, registryEntryName);
2015-03-23 05:15:10 -03:00
});
2015-03-23 18:35:35 -03:00
2015-03-23 05:15:10 -03:00
};