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

Getting started improvements #1058

Merged
merged 2 commits into from
Mar 12, 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
13 changes: 12 additions & 1 deletion declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ interface IOpener {

interface IErrors {
fail(formatStr: string, ...args: any[]): never;
fail(opts: { formatStr?: string; errorCode?: number; suppressCommandHelp?: boolean, proxyAuthenticationRequired?: boolean }, ...args: any[]): never;
fail(opts: { formatStr?: string; errorCode?: number; suppressCommandHelp?: boolean, proxyAuthenticationRequired?: boolean, printOnStdout?: boolean }, ...args: any[]): never;
failWithoutHelp(message: string, ...args: any[]): never;
beginCommand(action: () => Promise<boolean>, printCommandHelp: () => Promise<void>): Promise<boolean>;
verifyHeap(message: string): void;
Expand Down Expand Up @@ -1347,6 +1347,17 @@ interface IDoctorService {
* @returns {Promise<boolean>} true if at least one warning was printed
*/
printWarnings(configOptions?: { trackResult: boolean }): Promise<boolean>;
/**
* Runs the setup script on host machine
* @returns {Promise<ISpawnResult>}
*/
runSetupScript(): Promise<ISpawnResult>;
/**
* Checks if the envrironment is properly configured and it is possible to execute local builds
* @param platform @optional The current platform
* @returns {Promise<boolean>} true if the environment is properly configured for local builds
*/
canExecuteLocalBuild(platform?: string): Promise<boolean>;
}

interface IUtils {
Expand Down
1 change: 1 addition & 0 deletions definitions/commands-service.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
interface ICommandsService {
currentCommandData: ICommandData;
allCommands(opts: {includeDevCommands: boolean}): string[];
tryExecuteCommand(commandName: string, commandArguments: string[]): Promise<void>;
executeCommandUnchecked(commandName: string, commandArguments: string[]): Promise<boolean>;
Expand Down
11 changes: 8 additions & 3 deletions errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export class Errors implements IErrors {
exception.errorCode = opts.errorCode || ErrorCodes.UNKNOWN;
exception.suppressCommandHelp = opts.suppressCommandHelp;
exception.proxyAuthenticationRequired = !!opts.proxyAuthenticationRequired;
exception.printOnStdout = opts.printOnStdout;
this.$injector.resolve("logger").trace(opts.formatStr);
throw exception;
}
Expand All @@ -158,9 +159,13 @@ export class Errors implements IErrors {
} catch (ex) {
const loggerLevel: string = $injector.resolve("logger").getLevel().toUpperCase();
const printCallStack = this.printCallStack || loggerLevel === "TRACE" || loggerLevel === "DEBUG";
console.error(printCallStack
? resolveCallStack(ex)
: "\x1B[31;1m" + ex.message + "\x1B[0m");
const message = printCallStack ? resolveCallStack(ex) : `\x1B[31;1m${ex.message}\x1B[0m`;

if (ex.printOnStdout) {
this.$injector.resolve("logger").out(message);
} else {
console.error(message);
}

if (!ex.suppressCommandHelp) {
try {
Expand Down
9 changes: 9 additions & 0 deletions services/commands-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ class CommandArgumentsValidationHelper {
}

export class CommandsService implements ICommandsService {
public get currentCommandData(): ICommandData {
return _.last(this.commands);
}

private areDynamicSubcommandsRegistered = false;
private commands: ICommandData[] = [];

constructor(private $analyticsSettingsService: IAnalyticsSettingsService,
private $commandsServiceProvider: ICommandsServiceProvider,
Expand All @@ -34,6 +39,7 @@ export class CommandsService implements ICommandsService {
}

public async executeCommandUnchecked(commandName: string, commandArguments: string[]): Promise<boolean> {
this.commands.push({ commandName, commandArguments });
const command = this.$injector.resolveCommand(commandName);
if (command) {
if (!this.$staticConfig.disableAnalytics && !command.disableAnalytics) {
Expand Down Expand Up @@ -81,8 +87,11 @@ export class CommandsService implements ICommandsService {
this.$logger.printMarkdown(~suggestionText.indexOf('%s') ? require('util').format(suggestionText, commandArguments) : suggestionText);
}

this.commands.pop();
return true;
}

this.commands.pop();
return false;
}

Expand Down