Skip to content

Commit

Permalink
moving cache to dotfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
machellerogden committed Feb 15, 2017
1 parent 71c11c6 commit 71d1679
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/getSourceData.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ const rootDir = require('./rootDir');
const rc = require('rc')('bitcar', {});

module.exports = getSourceData;
const CACHE_PATH = path.normalize(process.env.HOME + '/.bitcar/cache.json');

function getSourceData(forceRefresh = false) {
if (fs.exists(path.normalize(__dirname + '/../sources/.cache.json')) && !forceRefresh) {
return Promise.resolve(fs.readJSON(__dirname + '/../sources/.cache.json'));
if (fs.exists(CACHE_PATH) && !forceRefresh) {
return Promise.resolve(fs.readJSON(CACHE_PATH));
} else {
const config = fs.readJSON(path.normalize(process.env.HOME + '/.bitcar/config'));
const sources = require('../sources');
Expand All @@ -20,7 +21,7 @@ function getSourceData(forceRefresh = false) {
sourceData = _.mapValues(sourceData, _.flow(_.flattenDeep, _.compact));
sourceData = _.mapValues(sourceData, (entries) => _.uniqBy(entries, 'name'));
return new Promise((resolve, reject) => {
fs.writeJSON(path.normalize(__dirname + '/../sources/.cache.json'), sourceData, null, 4);
fs.writeJSON(CACHE_PATH, sourceData, null, 4);
fs.commit((err) => {
if (err) return reject(err);
console.log('Cache set successfully');
Expand Down
3 changes: 2 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const inquirer = require('inquirer');
const path = require('path');

// store cache fixture in mem-fs
fs.writeJSON(path.normalize(__dirname + '/../sources/.cache.json'), require('./fixtures/cache.json'), null, 4);
const CACHE_PATH = path.normalize(process.env.HOME + '/.bitcar/cache.json');
fs.writeJSON(CACHE_PATH, require('./fixtures/cache.json'), null, 4);

const schemas = require('./schemas');
const mocks = require('./mocks');
Expand Down

0 comments on commit 71d1679

Please sign in to comment.