Skip to content

Getting started improvements #3418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 7, 2018
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 lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,4 @@ $injector.requirePublic("extensibilityService", "./services/extensibility-servic

$injector.require("nodeModulesDependenciesBuilder", "./tools/node-modules/node-modules-dependencies-builder");
$injector.require("subscriptionService", "./services/subscription-service");
$injector.require("terminalSpinnerService", "./services/terminal-spinner-service");
2 changes: 1 addition & 1 deletion lib/commands/post-install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class PostInstallCliCommand extends PostInstallCommand {
$doctorService: IDoctorService,
$analyticsService: IAnalyticsService,
$logger: ILogger) {
super($fs, $staticConfig, $commandsService, $helpService, $settingsService, $doctorService, $analyticsService, $logger);
super($fs, $staticConfig, $commandsService, $helpService, $settingsService, $analyticsService, $logger);
}

public async execute(args: string[]): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion lib/common
97 changes: 97 additions & 0 deletions lib/definitions/terminal-spinner-service.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
interface ITerminalSpinnerService {
createSpinner(spinnerOptions?: ITerminalSpinnerOptions): ITerminalSpinner;
execute<T>(spinnerOptions: ITerminalSpinnerOptions, action: () => Promise<T>): Promise<T>;
}

type SpinnerName =
'dots'
| 'dots2'
| 'dots3'
| 'dots4'
| 'dots5'
| 'dots6'
| 'dots7'
| 'dots8'
| 'dots9'
| 'dots10'
| 'dots11'
| 'dots12'
| 'line'
| 'line2'
| 'pipe'
| 'simpleDots'
| 'simpleDotsScrolling'
| 'star'
| 'star2'
| 'flip'
| 'hamburger'
| 'growVertical'
| 'growHorizontal'
| 'balloon'
| 'balloon2'
| 'noise'
| 'bounce'
| 'boxBounce'
| 'boxBounce2'
| 'triangle'
| 'arc'
| 'circle'
| 'squareCorners'
| 'circleQuarters'
| 'circleHalves'
| 'squish'
| 'toggle'
| 'toggle2'
| 'toggle3'
| 'toggle4'
| 'toggle5'
| 'toggle6'
| 'toggle7'
| 'toggle8'
| 'toggle9'
| 'toggle10'
| 'toggle11'
| 'toggle12'
| 'toggle13'
| 'arrow'
| 'arrow2'
| 'arrow3'
| 'bouncingBar'
| 'bouncingBall'
| 'smiley'
| 'monkey'
| 'hearts'
| 'clock'
| 'earth'
| 'moon'
| 'runner'
| 'pong'
| 'shark'
| 'dqpb';

interface Spinner {
interval?: number;
frames: string[];
}

interface ITerminalSpinner {
text: string;
start(text?: string): ITerminalSpinner;
stop(): ITerminalSpinner;
succeed(text?: string): ITerminalSpinner;
fail(text?: string): ITerminalSpinner;
warn(text?: string): ITerminalSpinner;
info(text?: string): ITerminalSpinner;
clear(): ITerminalSpinner;
render(): ITerminalSpinner;
frame(): ITerminalSpinner;
}

interface ITerminalSpinnerOptions {
text?: string;
spinner?: SpinnerName | Spinner;
color?: 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray';
interval?: number;
stream?: NodeJS.WritableStream;
enabled?: boolean;
}
50 changes: 36 additions & 14 deletions lib/services/doctor-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ class DoctorService implements IDoctorService {
private $childProcess: IChildProcess,
private $opener: IOpener,
private $prompter: IPrompter,
private $terminalSpinnerService: ITerminalSpinnerService,
private $versionsService: IVersionsService) { }

public async printWarnings(configOptions?: { trackResult: boolean }): Promise<boolean> {
const warnings = await doctor.getWarnings();
const infos = await this.$terminalSpinnerService.execute<NativeScriptDoctor.IInfo[]>({
text: `Getting environment information ${EOL}`
}, () => doctor.getInfos());

const warnings = infos.filter(info => info.type === constants.WARNING_TYPE_NAME);
const hasWarnings = warnings.length > 0;

const hasAndroidWarnings = warnings.filter(warning => _.includes(warning.platforms, constants.ANDROID_PLATFORM_NAME)).length > 0;
Expand All @@ -32,20 +37,11 @@ class DoctorService implements IDoctorService {
await this.$analyticsService.track("DoctorEnvironmentSetup", hasWarnings ? "incorrect" : "correct");
}

if (hasWarnings) {
warnings.map(warning => {
this.$logger.warn(warning.warning);
this.$logger.out(warning.additionalInformation);
});
this.printInfosCore(infos);

if (hasWarnings) {
this.$logger.info("There seem to be issues with your configuration.");
if (this.$hostInfo.isDarwin) {
await this.promptForHelp(DoctorService.DarwinSetupDocsLink, DoctorService.DarwinSetupScriptLocation, []);
} else if (this.$hostInfo.isWindows) {
await this.promptForHelp(DoctorService.WindowsSetupDocsLink, DoctorService.WindowsSetupScriptExecutable, DoctorService.WindowsSetupScriptArguments);
} else {
await this.promptForDocs(DoctorService.LinuxSetupDocsLink);
}
await this.promptForHelp();
}

try {
Expand All @@ -63,20 +59,46 @@ class DoctorService implements IDoctorService {
}
}

private async promptForHelp(link: string, commandName: string, commandArguments: string[]): Promise<void> {
private async promptForHelpCore(link: string, commandName: string, commandArguments: string[]): Promise<void> {
await this.promptForDocs(link);

if (await this.$prompter.confirm("Do you want to run the setup script?", () => helpers.isInteractive())) {
await this.$childProcess.spawnFromEvent(commandName, commandArguments, "close", { stdio: "inherit" });
}
}

private async promptForHelp(): Promise<void> {
if (this.$hostInfo.isDarwin) {
await this.promptForHelpCore(DoctorService.DarwinSetupDocsLink, DoctorService.DarwinSetupScriptLocation, []);
} else if (this.$hostInfo.isWindows) {
await this.promptForHelpCore(DoctorService.WindowsSetupDocsLink, DoctorService.WindowsSetupScriptExecutable, DoctorService.WindowsSetupScriptArguments);
} else {
await this.promptForDocs(DoctorService.LinuxSetupDocsLink);
}
}

private printPackageManagerTip() {
if (this.$hostInfo.isWindows) {
this.$logger.out("TIP: To avoid setting up the necessary environment variables, you can use the chocolatey package manager to install the Android SDK and its dependencies." + EOL);
} else if (this.$hostInfo.isDarwin) {
this.$logger.out("TIP: To avoid setting up the necessary environment variables, you can use the Homebrew package manager to install the Android SDK and its dependencies." + EOL);
}
}

private printInfosCore(infos: NativeScriptDoctor.IInfo[]): void {
infos.filter(info => info.type === constants.INFO_TYPE_NAME)
.map(info => {
const spinner = this.$terminalSpinnerService.createSpinner();
spinner.text = info.message;
spinner.succeed();
});

infos.filter(info => info.type === constants.WARNING_TYPE_NAME)
.map(info => {
const spinner = this.$terminalSpinnerService.createSpinner();
spinner.text = `${info.message.yellow} ${EOL} ${info.additionalInformation} ${EOL}`;
spinner.fail();
});
}
}
$injector.register("doctorService", DoctorService);
6 changes: 3 additions & 3 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export class PlatformService extends EventEmitter implements IPlatformService {
constructor(private $devicesService: Mobile.IDevicesService,
private $preparePlatformNativeService: IPreparePlatformService,
private $preparePlatformJSService: IPreparePlatformService,
private $progressIndicator: IProgressIndicator,
private $errors: IErrors,
private $fs: IFileSystem,
private $logger: ILogger,
Expand All @@ -40,7 +39,8 @@ export class PlatformService extends EventEmitter implements IPlatformService {
private $npm: INodePackageManager,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $projectChangesService: IProjectChangesService,
private $analyticsService: IAnalyticsService) {
private $analyticsService: IAnalyticsService,
private $terminalSpinnerService: ITerminalSpinnerService) {
super();
}

Expand Down Expand Up @@ -115,7 +115,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
npmOptions["version"] = version;
}

const spinner = this.$progressIndicator.getSpinner("Installing " + packageToInstall);
const spinner = this.$terminalSpinnerService.createSpinner();
const projectDir = projectData.projectDir;
const platformPath = path.join(projectData.platformsDir, platform);

Expand Down
27 changes: 27 additions & 0 deletions lib/services/terminal-spinner-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as ora from 'ora';

export class TerminalSpinnerService implements ITerminalSpinnerService {
public createSpinner(spinnerOptions: ITerminalSpinnerOptions = {}): ITerminalSpinner {
spinnerOptions.stream = spinnerOptions.stream || process.stdout;
return new ora(spinnerOptions);
}

public async execute<T>(spinnerOptions: ITerminalSpinnerOptions, action: () => Promise<T>): Promise<T> {
const spinner = this.createSpinner(spinnerOptions);

spinner.start();

let result: T = null;
try {
result = await action();
} catch (err) {
spinner.fail();
return null;
}

spinner.succeed();

return result;
}
}
$injector.register('terminalSpinnerService', TerminalSpinnerService);
Loading