Skip to content

Commit 28b9db2

Browse files
author
Beatriz Rizental
authored
Merge pull request #261 from ChinYing-Li/bug_1699391
Bug 1699391: Add a spinner to the console output while setting up python virtual env
2 parents d271892 + 5fc3cc3 commit 28b9db2

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* [#260](https://github.com/mozilla/glean.js/pull/260): Set minimum node (>= 12.0.0) and npm (>= 7.0.0) versions.
66
* [#202](https://github.com/mozilla/glean.js/pull/202): Add a testing API for the ping type.
77
* [#253](https://github.com/mozilla/glean.js/pull/253): Implement the timespan metric type.
8+
* [#261](https://github.com/mozilla/glean.js/pull/261): Show a spinner while setting up python virtual environment
89

910
# v0.10.2 (2021-04-26)
1011

glean/src/cli.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,12 @@ async function createPythonVenv(venvPath: string): Promise<boolean> {
137137
const venvCmd = `${getSystemPythonBinName()} -m venv ${VIRTUAL_ENVIRONMENT_DIR}`;
138138

139139
for (const cmd of [venvCmd, pipCmd]) {
140+
const spinner = getStartedSpinner();
140141
const {err, stdout, stderr} = await new Promise<{err: exec.ExecException | null, stdout: string, stderr: string}>(resolve => {
141142
exec.exec(cmd, (err, stdout, stderr) => resolve({err, stdout, stderr}));
142143
});
143144

145+
stopSpinner(spinner);
144146
console.log(`${stdout}`);
145147

146148
if (err) {
@@ -176,6 +178,7 @@ async function setup(projectRoot: string) {
176178
* @param parserArgs the list of arguments passed to this command.
177179
*/
178180
async function runGlean(projectRoot: string, parserArgs: string[]) {
181+
const spinner = getStartedSpinner();
179182
const venvRoot = path.join(projectRoot, VIRTUAL_ENVIRONMENT_DIR);
180183
const pythonBin = path.join(getPythonVenvBinariesPath(venvRoot), getSystemPythonBinName());
181184
const cmd = `${pythonBin} -c "${PYTHON_SCRIPT}" online glean_parser ${GLEAN_PARSER_VERSION} ${parserArgs.join(" ")}`;
@@ -184,6 +187,7 @@ async function runGlean(projectRoot: string, parserArgs: string[]) {
184187
exec.exec(cmd, (err, stdout, stderr) => resolve({err, stdout, stderr}));
185188
});
186189

190+
stopSpinner(spinner);
187191
console.log(`${stdout}`);
188192

189193
if (err) {
@@ -214,3 +218,27 @@ async function run(args: string[]) {
214218
run(argv).catch(e => {
215219
console.error("There was an error running Glean", e);
216220
});
221+
222+
/**
223+
* Returns a spinner
224+
*
225+
* @returns an Interval ID that logs certain characters
226+
*/
227+
function getStartedSpinner() {
228+
const ticks = ["\\", "|", "/", "-"];
229+
let i = 0;
230+
return setInterval(function() {
231+
process.stdout.write(" "+ticks[i++]+"\r\r");
232+
i %= 4;
233+
}, 250);
234+
}
235+
236+
/**
237+
* Stops the spinner
238+
*
239+
* @param spinner is created by getStartedSpinner
240+
*/
241+
function stopSpinner(spinner: NodeJS.Timeout) {
242+
process.stdout.write(" \r");
243+
clearInterval(spinner);
244+
}

0 commit comments

Comments
 (0)