Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 2691355

Browse files
committed
Share Progress indicator between the CLIs
See NativeScript/nativescript-cli#1294
1 parent eec8ca8 commit 2691355

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

bootstrap.ts

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ $injector.require("prompter", "./prompter");
3333
$injector.require("projectHelper", "./project-helper");
3434
$injector.require("pluginVariablesHelper", "./plugin-variables-helper");
3535
$injector.require("propertiesParser", "./properties-parser");
36+
$injector.require("progressIndicator", "./progress-indicator");
3637

3738
$injector.requireCommand(["help", "/?"], "./commands/help");
3839
$injector.requireCommand("usage-reporting", "./commands/analytics");

declarations.d.ts

+14
Original file line numberDiff line numberDiff line change
@@ -702,3 +702,17 @@ interface IWinReg {
702702
*/
703703
registryKeys: IHiveIds;
704704
}
705+
706+
/**
707+
* Used to show indication that a process is running
708+
*/
709+
interface IProgressIndicator {
710+
/**
711+
* Prints indication that a process is running
712+
* @param {IFuture<any>} future process
713+
* @param {number} timeout time interval for printing indication
714+
* @param {boolean} options whether to surpress the trailing new line printed after the process ends
715+
* @return {IFuture<void>}
716+
*/
717+
showProgressIndicator(future: IFuture<any>, timeout: number, options?: { surpressTrailingNewLine?: boolean }): IFuture<void>;
718+
}

progress-indicator.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
///<reference path=".d.ts"/>
2+
"use strict";
3+
4+
export class ProgressIndicator implements IProgressIndicator {
5+
constructor(private $logger: ILogger) { }
6+
7+
public showProgressIndicator(future: IFuture<any>, timeout: number, options?: { surpressTrailingNewLine?: boolean }): IFuture<void> {
8+
return (() => {
9+
let surpressTrailingNewLine = options && options.surpressTrailingNewLine;
10+
try {
11+
while(!future.isResolved()) {
12+
this.$logger.printMsgWithTimeout(".", timeout).wait();
13+
}
14+
15+
// Make sure future is not left behind and prevent "There are outstanding futures." error.
16+
future.wait();
17+
} catch (err) {
18+
this.$logger.out();
19+
throw err;
20+
}
21+
22+
if (!surpressTrailingNewLine) {
23+
this.$logger.out();
24+
}
25+
}).future<void>()();
26+
}
27+
}
28+
$injector.register("progressIndicator", ProgressIndicator);

0 commit comments

Comments
 (0)