Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 4 additions & 27 deletions lib/tldr.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const sample = require('lodash/sample');
const fs = require('fs-extra');
const ms = require('ms');
const ora = require('ora');
const { EmptyCacheError, MissingPageError, MissingRenderPathError } = require('./errors');
const Cache = require('./cache');
const search = require('./search');
Expand Down Expand Up @@ -90,15 +89,11 @@ class Tldr {
}

updateCache() {
return spinningPromise('Updating...', () => {
return this.cache.update();
});
return this.cache.update();
}

updateIndex() {
return spinningPromise('Creating index...', () => {
return search.createIndex();
});
return search.createIndex();
}

search(keywords) {
Expand Down Expand Up @@ -131,13 +126,9 @@ class Tldr {
if (this.config.skipUpdateWhenPageNotFound === true) {
return '';
}
return spinningPromise('Page not found. Updating cache...', () => {
return this.cache.update();
})
return this.cache.update()
.then(() => {
return spinningPromise('Creating index...', () => {
return search.createIndex();
});
return search.createIndex();
})
.then(() => {
// And then, try to check in cache again
Expand Down Expand Up @@ -181,18 +172,4 @@ class Tldr {
}
}

function spinningPromise(text, factory) {
const spinner = ora();
spinner.start(text);
return factory()
.then((val) => {
spinner.succeed();
return val;
})
.catch((err) => {
spinner.fail();
throw err;
});
}

module.exports = Tldr;
Loading
Loading