-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update build feedback with dots indicating activity (#8382)
* Add progress for analyzing and auto-prerendering * Add typing for tty-aware-progress and use stdout * Add fancier spinners * Update spinner and add handling for logs while spinning * Remove un-needed types package * Remove progress and combine analyzing/prerendering messages
- Loading branch information
1 parent
44bbf9a
commit 204028d
Showing
6 changed files
with
144 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import ora from 'ora' | ||
|
||
const dotsSpinner = { | ||
frames: ['.', '..', '...'], | ||
interval: 200, | ||
} | ||
|
||
export default function createSpinner( | ||
text: string | { prefixText: string }, | ||
options: ora.Options = {} | ||
) { | ||
let spinner: undefined | ora.Ora | ||
let prefixText = text && typeof text === 'object' && text.prefixText | ||
|
||
if (process.stdout.isTTY) { | ||
spinner = ora({ | ||
text: typeof text === 'string' ? text : undefined, | ||
prefixText: typeof prefixText === 'string' ? prefixText : undefined, | ||
spinner: dotsSpinner, | ||
stream: process.stdout, | ||
...options, | ||
}).start() | ||
|
||
const origLog = console.log | ||
const origWarn = console.warn | ||
const origError = console.error | ||
const origStop = spinner.stop.bind(spinner) | ||
const origStopAndPersist = spinner.stopAndPersist.bind(spinner) | ||
|
||
const logHandle = (method: any, args: any[]) => { | ||
origStop() | ||
method(...args) | ||
spinner!.start() | ||
} | ||
|
||
console.log = (...args: any) => logHandle(origLog, args) | ||
console.warn = (...args: any) => logHandle(origWarn, args) | ||
console.error = (...args: any) => logHandle(origError, args) | ||
|
||
const resetLog = () => { | ||
console.log = origLog | ||
} | ||
spinner.stop = (): ora.Ora => { | ||
origStop() | ||
resetLog() | ||
return spinner! | ||
} | ||
spinner.stopAndPersist = (): ora.Ora => { | ||
origStopAndPersist() | ||
resetLog() | ||
return spinner! | ||
} | ||
} else if (prefixText || text) { | ||
console.log(prefixText || text) | ||
} | ||
|
||
return spinner | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters