Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [#260](https://github.com/mozilla/glean.js/pull/260): Set minimum node (>= 12.0.0) and npm (>= 7.0.0) versions.
* [#202](https://github.com/mozilla/glean.js/pull/202): Add a testing API for the ping type.
* [#253](https://github.com/mozilla/glean.js/pull/253): Implement the timespan metric type.
* [#261](https://github.com/mozilla/glean.js/pull/261): Show a spinner while setting up python virtual environment

# v0.10.2 (2021-04-26)

Expand Down
28 changes: 28 additions & 0 deletions glean/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,12 @@ async function createPythonVenv(venvPath: string): Promise<boolean> {
const venvCmd = `${getSystemPythonBinName()} -m venv ${VIRTUAL_ENVIRONMENT_DIR}`;

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

stopSpinner(spinner);
console.log(`${stdout}`);

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

stopSpinner(spinner);
console.log(`${stdout}`);

if (err) {
Expand Down Expand Up @@ -214,3 +218,27 @@ async function run(args: string[]) {
run(argv).catch(e => {
console.error("There was an error running Glean", e);
});

/**
* Returns a spinner
*
* @returns an Interval ID that logs certain characters
*/
function getStartedSpinner() {
const ticks = ["\\", "|", "/", "-"];
let i = 0;
return setInterval(function() {
process.stdout.write(" "+ticks[i++]+"\r\r");
i %= 4;
}, 250);
}

/**
* Stops the spinner
*
* @param spinner is created by getStartedSpinner
*/
function stopSpinner(spinner: NodeJS.Timeout) {
process.stdout.write(" \r");
clearInterval(spinner);
}