3
3
const sample = require ( 'lodash/sample' ) ;
4
4
const fs = require ( 'fs' ) ;
5
5
const ms = require ( 'ms' ) ;
6
+ const ora = require ( 'ora' ) ;
6
7
const cache = require ( './cache' ) ;
7
8
const search = require ( './search' ) ;
8
9
const platform = require ( './platform' ) ;
@@ -86,10 +87,11 @@ exports.clearCache = () => {
86
87
} ;
87
88
88
89
exports . updateCache = ( ) => {
89
- console . log ( 'Updating...' ) ;
90
+ const spinner = ora ( ) ;
91
+ spinner . start ( 'Updating' ) ;
90
92
return cache . update ( )
91
93
. then ( ( ) => {
92
- console . log ( 'Done' ) ;
94
+ spinner . succeed ( ) ;
93
95
} )
94
96
. catch ( ( err ) => {
95
97
console . error ( err ) ;
@@ -98,10 +100,11 @@ exports.updateCache = () => {
98
100
} ;
99
101
100
102
exports . updateIndex = ( ) => {
101
- console . log ( 'Creating index...' ) ;
103
+ const spinner = ora ( ) ;
104
+ spinner . start ( 'Creating index' ) ;
102
105
search . createIndex ( )
103
106
. then ( ( ) => {
104
- console . log ( 'Done' ) ;
107
+ spinner . succeed ( ) ;
105
108
} )
106
109
. catch ( ( err ) => {
107
110
console . error ( err ) ;
@@ -130,6 +133,8 @@ function printPages(pages, singleColumn) {
130
133
}
131
134
132
135
function printBestPage ( command , options = { } ) {
136
+ const spinner = ora ( ) ;
137
+
133
138
// Trying to get the page from cache first
134
139
cache . getPage ( command )
135
140
. then ( ( content ) => {
@@ -140,15 +145,16 @@ function printBestPage(command, options={}) {
140
145
return exit ( ) ;
141
146
}
142
147
// If not found, try to update
143
- console . log ( 'Page not found. Updating cache .. ' ) ;
148
+ spinner . start ( 'Page not found. Updating cache' ) ;
144
149
return cache . update ( ) ;
145
150
} )
146
151
. then ( ( ) => {
147
- console . log ( 'Creating index...' ) ;
152
+ spinner . succeed ( ) ;
153
+ spinner . start ( 'Creating index' ) ;
148
154
return search . createIndex ( ) ;
149
155
} )
150
156
. then ( ( ) => {
151
- console . log ( 'Done' ) ;
157
+ spinner . succeed ( ) ;
152
158
// And then, try to check in cache again
153
159
return cache . getPage ( command ) ;
154
160
} )
0 commit comments