Skip to content

Commit

Permalink
fixing bug with sync-existing where it would drop entries from cache …
Browse files Browse the repository at this point in the history
…when attempting to merge existing repo entries
  • Loading branch information
machellerogden committed Mar 2, 2017
1 parent b87ce6d commit 144907b
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lib/syncExisting.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ function syncExisting() {

function readdirpFilter(result) {
return _.reduce(paths, (acc, p) => {
let pattern = new RegExp('^' + p);
let pattern = new RegExp('^' + _.escapeRegExp(p));
acc = acc || pattern.test(result.fullPath);
return acc;
}, false);
}

function resultFilter(result) {
return _.reduce(paths, (acc, p) => {
let pattern = new RegExp('^' + p + '.+\/.+');
let pattern = new RegExp('^' + _.escapeRegExp(p) + '.+\/.+');
acc = acc || pattern.test(result.fullPath);
return acc;
}, false);
Expand All @@ -54,17 +54,19 @@ function syncExisting() {
acc[entry.host].push({ name: entry.name });
return acc;
}, {});
const sourceData = _.mapValues(entries, (repos, prop) => {
return _.map(repos, (repo) => {
let cachedRepo = _.find(cache[prop], { name: repo.name });
let selected = cachedRepo || repo;
if (!cachedRepo && prop === 'github.com') {
selected.clone = 'https://github.com/' + repo.name + '.git';
selected.html = 'https://github.com/' + repo.name;
}
return selected;
});

let sourceData = _.reduce(hosts, (acc, host) => {
acc[host] = _.unionBy(cache[host], entries[host], 'name');
return acc;
}, {});

sourceData['github.com'] = _.map(sourceData['github.com'] || [], (repo) => {
let name = _.lowerCase(_.replace(repo.name, ' ', '-'));
if (!repo.clone) repo.clone = 'https://github.com/' + repo.name + '.git';
if (!repo.html) repo.html = 'https://github.com/' + repo.name;
return repo;
});

fs.writeJSON(CACHE_PATH, sourceData, null, 4);
fs.commit((err) => {
if (err) return reject(err);
Expand Down

0 comments on commit 144907b

Please sign in to comment.