From 0adb5ab03b0de5d4cff1d64e24ef877a25851847 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Sun, 8 Aug 2021 14:30:46 +0200 Subject: [PATCH 1/3] chore: disable preview --- docs/man_pages/start.md | 1 - lib/commands/preview.ts | 132 +++--- lib/common/definitions/config.d.ts | 1 - lib/config.ts | 22 - .../analytics/analytics-broker-process.ts | 2 +- lib/services/analytics/analytics-service.ts | 38 +- .../platform-environment-requirements.ts | 400 +++++++++--------- 7 files changed, 296 insertions(+), 300 deletions(-) diff --git a/docs/man_pages/start.md b/docs/man_pages/start.md index b051aac65d..79c2979925 100644 --- a/docs/man_pages/start.md +++ b/docs/man_pages/start.md @@ -30,7 +30,6 @@ Command | Description ---|--- [create](project/creation/create.html) | Creates a new project for native development with NativeScript. [clean](general/clean.html) | Cleans project artifacts. -[preview](project/testing/preview.html) | Generates a QR code that can be scanned by the NativeScript PlayGround app. [platform add ``](project/configuration/platform-add.html) | Configures the current project to target the selected platform. [platform list](project/configuration/platform.html) | Lists all platforms that the project currently targets. [platform remove ``](project/configuration/platform-remove.html) | Removes the selected platform from the platforms that the project currently targets. This operation deletes all platform-specific files and subdirectories from your project. diff --git a/lib/commands/preview.ts b/lib/commands/preview.ts index d5e527cbbe..088217f2da 100644 --- a/lib/commands/preview.ts +++ b/lib/commands/preview.ts @@ -1,73 +1,85 @@ -import { DEVICE_LOG_EVENT_NAME } from "../common/constants"; -import { IProjectData } from "../definitions/project"; -import { IMigrateController } from "../definitions/migrate"; -import { INetworkConnectivityValidator, IOptions } from "../declarations"; import { ICommandParameter, ICommand } from "../common/definitions/commands"; -import { IAnalyticsService, IErrors } from "../common/declarations"; -import { ICleanupService } from "../definitions/cleanup-service"; +import { IErrors } from "../common/declarations"; import { injector } from "../common/yok"; export class PreviewCommand implements ICommand { - public allowedParameters: ICommandParameter[] = []; + allowedParameters: ICommandParameter[] = []; - constructor( - private $analyticsService: IAnalyticsService, - private $errors: IErrors, - private $logger: ILogger, - private $migrateController: IMigrateController, - private $previewAppController: IPreviewAppController, - private $networkConnectivityValidator: INetworkConnectivityValidator, - private $projectData: IProjectData, - private $options: IOptions, - private $previewAppLogProvider: IPreviewAppLogProvider, - private $previewQrCodeService: IPreviewQrCodeService, - $cleanupService: ICleanupService - ) { - this.$analyticsService.setShouldDispose(false); - $cleanupService.setShouldDispose(false); - } + constructor(private $errors: IErrors) {} - public async execute(): Promise { - this.$previewAppLogProvider.on( - DEVICE_LOG_EVENT_NAME, - (deviceId: string, message: string) => { - this.$logger.info(message); - } + async execute(args: string[]): Promise { + this.$errors.fail( + `The Preview service has been disabled until further notice.\n\n` + + `Configure local builds and use "ns run ${args.join(" ")}" instead.` ); - - await this.$previewAppController.startPreview({ - projectDir: this.$projectData.projectDir, - useHotModuleReload: this.$options.hmr, - env: this.$options.env, - }); - - await this.$previewQrCodeService.printLiveSyncQrCode({ - projectDir: this.$projectData.projectDir, - useHotModuleReload: this.$options.hmr, - link: this.$options.link, - }); } - public async canExecute(args: string[]): Promise { - if (args && args.length) { - this.$errors.failWithHelp( - `The ${args.length > 1 ? "arguments" : "argument"} '${args.join( - " " - )}' ${ - args.length > 1 ? "are" : "is" - } not valid for the preview command.` - ); - } - - if (!this.$options.force) { - await this.$migrateController.validate({ - projectDir: this.$projectData.projectDir, - platforms: [], - }); - } - - await this.$networkConnectivityValidator.validate(); + async canExecute(args: string[]): Promise { return true; } } + +// export class PreviewCommand implements ICommand { +// public allowedParameters: ICommandParameter[] = []; +// +// constructor( +// private $analyticsService: IAnalyticsService, +// private $errors: IErrors, +// private $logger: ILogger, +// private $migrateController: IMigrateController, +// private $previewAppController: IPreviewAppController, +// private $networkConnectivityValidator: INetworkConnectivityValidator, +// private $projectData: IProjectData, +// private $options: IOptions, +// private $previewAppLogProvider: IPreviewAppLogProvider, +// private $previewQrCodeService: IPreviewQrCodeService, +// $cleanupService: ICleanupService +// ) { +// this.$analyticsService.setShouldDispose(false); +// $cleanupService.setShouldDispose(false); +// } +// +// public async execute(): Promise { +// this.$previewAppLogProvider.on( +// DEVICE_LOG_EVENT_NAME, +// (deviceId: string, message: string) => { +// this.$logger.info(message); +// } +// ); +// +// await this.$previewAppController.startPreview({ +// projectDir: this.$projectData.projectDir, +// useHotModuleReload: this.$options.hmr, +// env: this.$options.env, +// }); +// +// await this.$previewQrCodeService.printLiveSyncQrCode({ +// projectDir: this.$projectData.projectDir, +// useHotModuleReload: this.$options.hmr, +// link: this.$options.link, +// }); +// } +// +// public async canExecute(args: string[]): Promise { +// if (args && args.length) { +// this.$errors.failWithHelp( +// `The ${args.length > 1 ? "arguments" : "argument"} '${args.join( +// " " +// )}' ${ +// args.length > 1 ? "are" : "is" +// } not valid for the preview command.` +// ); +// } +// +// if (!this.$options.force) { +// await this.$migrateController.validate({ +// projectDir: this.$projectData.projectDir, +// platforms: [], +// }); +// } +// +// await this.$networkConnectivityValidator.validate(); +// return true; +// } +// } injector.registerCommand("preview", PreviewCommand); diff --git a/lib/common/definitions/config.d.ts b/lib/common/definitions/config.d.ts index 8a22ed1450..d69dd2142f 100644 --- a/lib/common/definitions/config.d.ts +++ b/lib/common/definitions/config.d.ts @@ -9,7 +9,6 @@ declare module Config { ANALYTICS_INSTALLATION_ID_SETTING_NAME: string; TRACK_FEATURE_USAGE_SETTING_NAME: string; ERROR_REPORT_SETTING_NAME: string; - SYS_REQUIREMENTS_LINK: string; version: string; getAdbFilePath(): Promise; disableAnalytics?: boolean; diff --git a/lib/config.ts b/lib/config.ts index c8406ae677..3d297cf3fd 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -61,28 +61,6 @@ export class StaticConfig implements IStaticConfig { return true; } - public get SYS_REQUIREMENTS_LINK(): string { - let linkToSysRequirements: string; - switch (process.platform) { - case "linux": - linkToSysRequirements = - "https://docs.nativescript.org/start/general-requirements#full-setup-requirements-linux"; - break; - case "win32": - linkToSysRequirements = - "https://docs.nativescript.org/start/general-requirements#full-setup-requirements-windows"; - break; - case "darwin": - linkToSysRequirements = - "https://docs.nativescript.org/start/general-requirements#full-setup-requirements-macos"; - break; - default: - linkToSysRequirements = ""; - } - - return linkToSysRequirements; - } - public version = require("../package.json").version; public get HTML_CLI_HELPERS_DIR(): string { diff --git a/lib/services/analytics/analytics-broker-process.ts b/lib/services/analytics/analytics-broker-process.ts index e4c052d561..7fae8a961a 100644 --- a/lib/services/analytics/analytics-broker-process.ts +++ b/lib/services/analytics/analytics-broker-process.ts @@ -102,7 +102,7 @@ process.on("message", async (data: ITrackingInformation) => { }); if (data.type === TrackingTypes.PreviewAppData) { - await trackPreviewAppData(data); + // await trackPreviewAppData(data); return; } diff --git a/lib/services/analytics/analytics-service.ts b/lib/services/analytics/analytics-service.ts index 32df2030ae..a95a171e02 100644 --- a/lib/services/analytics/analytics-service.ts +++ b/lib/services/analytics/analytics-service.ts @@ -200,25 +200,25 @@ export class AnalyticsService implements IAnalyticsService, IDisposable { platform: string, projectDir: string ): Promise { - const customDimensions: IStringDictionary = {}; - this.setProjectRelatedCustomDimensions(customDimensions, projectDir); - - let label: string = ""; - label = this.addDataToLabel( - label, - this.$mobileHelper.normalizePlatformName(platform) - ); - - const eventActionData = { - googleAnalyticsDataType: GoogleAnalyticsDataType.Event, - action: TrackActionNames.PreviewAppData, - platform, - label, - customDimensions, - type: TrackingTypes.PreviewAppData, - }; - - await this.trackInGoogleAnalytics(eventActionData); + // const customDimensions: IStringDictionary = {}; + // this.setProjectRelatedCustomDimensions(customDimensions, projectDir); + // + // let label: string = ""; + // label = this.addDataToLabel( + // label, + // this.$mobileHelper.normalizePlatformName(platform) + // ); + // + // const eventActionData = { + // googleAnalyticsDataType: GoogleAnalyticsDataType.Event, + // action: TrackActionNames.PreviewAppData, + // platform, + // label, + // customDimensions, + // type: TrackingTypes.PreviewAppData, + // }; + // + // await this.trackInGoogleAnalytics(eventActionData); } public async finishTracking(): Promise { diff --git a/lib/services/platform-environment-requirements.ts b/lib/services/platform-environment-requirements.ts index 8e3adf6b50..f4c73f55a8 100644 --- a/lib/services/platform-environment-requirements.ts +++ b/lib/services/platform-environment-requirements.ts @@ -1,60 +1,61 @@ import { TrackActionNames } from "../constants"; -import { isInteractive, hook } from "../common/helpers"; +import { hook } from "../common/helpers"; import { EOL } from "os"; import { IPlatformEnvironmentRequirements, ICheckEnvironmentRequirementsInput, ICheckEnvironmentRequirementsOutput, } from "../definitions/platform"; -import { IStaticConfig, IOptions } from "../declarations"; import { - IDoctorService, IErrors, IAnalyticsService, + IDoctorService, } from "../common/declarations"; import { IInjector } from "../common/definitions/yok"; import { injector } from "../common/yok"; -import { INotConfiguredEnvOptions } from "../common/definitions/commands"; export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequirements { constructor( private $doctorService: IDoctorService, private $errors: IErrors, - private $logger: ILogger, - private $prompter: IPrompter, - private $staticConfig: IStaticConfig, + // private $logger: ILogger, + // private $prompter: IPrompter, + // private $staticConfig: IStaticConfig, private $analyticsService: IAnalyticsService, - private $injector: IInjector, - private $previewQrCodeService: IPreviewQrCodeService - ) {} + // @ts-ignore - required by the hook helper! + private $injector: IInjector + ) // private $previewQrCodeService: IPreviewQrCodeService + {} - public get $previewAppController(): IPreviewAppController { - return this.$injector.resolve("previewAppController"); - } + // public get $previewAppController(): IPreviewAppController { + // return this.$injector.resolve("previewAppController"); + // } - public static LOCAL_SETUP_OPTION_NAME = "Configure for Local Builds"; - public static SYNC_TO_PREVIEW_APP_OPTION_NAME = "Sync to Playground"; - public static MANUALLY_SETUP_OPTION_NAME = "Skip Step and Configure Manually"; - private static CHOOSE_OPTIONS_MESSAGE = - "To continue, choose one of the following options: "; - private static NOT_CONFIGURED_ENV_AFTER_SETUP_SCRIPT_MESSAGE = `The setup script was not able to configure your environment for local builds. To execute local builds, you have to set up your environment manually. Please consult our setup instructions here 'https://docs.nativescript.org/start/quick-setup'.`; private static MISSING_LOCAL_SETUP_MESSAGE = "Your environment is not configured properly and you will not be able to execute local builds."; - private static RUN_TNS_SETUP_MESSAGE = - "Run $ tns setup command to run the setup script to try to automatically configure your environment for local builds."; - private static SYNC_TO_PREVIEW_APP_MESSAGE = `Select "Sync to Playground" to enjoy NativeScript without any local setup. All you need is a couple of companion apps installed on your devices.`; - private static RUN_PREVIEW_COMMAND_MESSAGE = `Run $ tns preview command to enjoy NativeScript without any local setup.`; + + // public static LOCAL_SETUP_OPTION_NAME = "Configure for Local Builds"; + // public static SYNC_TO_PREVIEW_APP_OPTION_NAME = "Sync to Playground"; + // public static MANUALLY_SETUP_OPTION_NAME = "Skip Step and Configure Manually"; + // private static CHOOSE_OPTIONS_MESSAGE = + // "To continue, choose one of the following options: "; + // private static NOT_CONFIGURED_ENV_AFTER_SETUP_SCRIPT_MESSAGE = `The setup script was not able to configure your environment for local builds. To execute local builds, you have to set up your environment manually. Please consult our setup instructions here 'https://docs.nativescript.org/start/quick-setup'.`; + + // private static RUN_TNS_SETUP_MESSAGE = + // "Run $ tns setup command to run the setup script to try to automatically configure your environment for local builds."; + // private static SYNC_TO_PREVIEW_APP_MESSAGE = `Select "Sync to Playground" to enjoy NativeScript without any local setup. All you need is a couple of companion apps installed on your devices.`; + // private static RUN_PREVIEW_COMMAND_MESSAGE = `Run $ tns preview command to enjoy NativeScript without any local setup.`; @hook("checkEnvironment") public async checkEnvironmentRequirements( input: ICheckEnvironmentRequirementsInput ): Promise { const { platform, projectDir, runtimeVersion } = input; - const notConfiguredEnvOptions = input.notConfiguredEnvOptions || {}; - const options = input.options || {}; + // const notConfiguredEnvOptions = input.notConfiguredEnvOptions || {}; + // const options = input.options || {}; - let selectedOption = null; + const selectedOption: any = null; if (process.env.NS_SKIP_ENV_CHECK) { await this.$analyticsService.trackEventActionInGoogleAnalytics({ @@ -75,54 +76,54 @@ export class PlatformEnvironmentRequirements }); if (!canExecute) { - if (!isInteractive()) { - await this.$analyticsService.trackEventActionInGoogleAnalytics({ - action: TrackActionNames.CheckEnvironmentRequirements, - additionalData: - "Non-interactive terminal, unable to execute local builds.", - }); - this.fail(this.getNonInteractiveConsoleMessage(platform)); - } - - const infoMessage = this.getInteractiveConsoleMessage( - notConfiguredEnvOptions - ); - - const choices = this.getChoices(notConfiguredEnvOptions); - - selectedOption = await this.promptForChoice({ infoMessage, choices }); - - this.processManuallySetupIfNeeded(selectedOption, platform); - await this.processSyncToPreviewAppIfNeeded( - selectedOption, - projectDir, - options - ); - - if ( - selectedOption === - PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME - ) { - await this.$doctorService.runSetupScript(); - - if ( - await this.$doctorService.canExecuteLocalBuild({ - platform, - projectDir, - runtimeVersion, - forceCheck: input.forceCheck, - }) - ) { - return { - canExecute: true, - selectedOption, - }; - } - - this.fail( - PlatformEnvironmentRequirements.NOT_CONFIGURED_ENV_AFTER_SETUP_SCRIPT_MESSAGE - ); - } + // if (!isInteractive()) { + await this.$analyticsService.trackEventActionInGoogleAnalytics({ + action: TrackActionNames.CheckEnvironmentRequirements, + additionalData: + "Non-interactive terminal, unable to execute local builds.", + }); + this.fail(this.getNonInteractiveConsoleMessage(platform)); + // } + + // const infoMessage = this.getInteractiveConsoleMessage( + // notConfiguredEnvOptions + // ); + + // const choices = this.getChoices(notConfiguredEnvOptions); + + // selectedOption = await this.promptForChoice({ infoMessage, choices }); + + // this.processManuallySetupIfNeeded(selectedOption, platform); + // await this.processSyncToPreviewAppIfNeeded( + // selectedOption, + // projectDir, + // options + // ); + + // if ( + // selectedOption === + // PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME + // ) { + // await this.$doctorService.runSetupScript(); + // + // if ( + // await this.$doctorService.canExecuteLocalBuild({ + // platform, + // projectDir, + // runtimeVersion, + // forceCheck: input.forceCheck, + // }) + // ) { + // return { + // canExecute: true, + // selectedOption, + // }; + // } + // + // this.fail( + // PlatformEnvironmentRequirements.NOT_CONFIGURED_ENV_AFTER_SETUP_SCRIPT_MESSAGE + // ); + // } } return { @@ -131,139 +132,146 @@ export class PlatformEnvironmentRequirements }; } - private processManuallySetupIfNeeded( - selectedOption: string, - platform?: string - ) { - if ( - selectedOption === - PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME - ) { - this.processManuallySetup(platform); - } - } - - private async processSyncToPreviewAppIfNeeded( - selectedOption: string, - projectDir: string, - options: IOptions - ) { - if ( - selectedOption === - PlatformEnvironmentRequirements.SYNC_TO_PREVIEW_APP_OPTION_NAME - ) { - if (!projectDir) { - this.$errors.fail( - `No project found. In order to sync to playground you need to go to project directory or specify --path option.` - ); - } - - await this.$previewAppController.startPreview({ - projectDir, - env: options.env, - useHotModuleReload: options.hmr, - }); - - await this.$previewQrCodeService.printLiveSyncQrCode({ - projectDir, - useHotModuleReload: options.hmr, - link: options.link, - }); - } - } - - private processManuallySetup(platform?: string): void { - this.fail( - `To be able to ${ - platform ? `build for ${platform}` : "build" - }, verify that your environment is configured according to the system requirements described at ${ - this.$staticConfig.SYS_REQUIREMENTS_LINK - }. If you have any questions, check Stack Overflow: 'https://stackoverflow.com/questions/tagged/nativescript' and our public Discord channel: 'https://nativescript.org/discord/'` - ); - } - private fail(message: string): void { this.$errors.fail({ formatStr: message, printOnStdout: true }); } private getNonInteractiveConsoleMessage(platform: string) { - return this.buildMultilineMessage([ - `${PlatformEnvironmentRequirements.MISSING_LOCAL_SETUP_MESSAGE} ${PlatformEnvironmentRequirements.CHOOSE_OPTIONS_MESSAGE}`, - PlatformEnvironmentRequirements.RUN_PREVIEW_COMMAND_MESSAGE, - PlatformEnvironmentRequirements.RUN_TNS_SETUP_MESSAGE, - this.getEnvVerificationMessage(), - ]); + return [ + PlatformEnvironmentRequirements.MISSING_LOCAL_SETUP_MESSAGE, + // PlatformEnvironmentRequirements.RUN_PREVIEW_COMMAND_MESSAGE, + // PlatformEnvironmentRequirements.RUN_TNS_SETUP_MESSAGE, + this.getEnvVerificationMessage(platform), + ].join(EOL); } - private getInteractiveConsoleMessage(options: INotConfiguredEnvOptions) { - const message = PlatformEnvironmentRequirements.MISSING_LOCAL_SETUP_MESSAGE; - const choices = [ - `Select "Configure for Local Builds" to run the setup script and automatically configure your environment for local builds.`, - `Select "Skip Step and Configure Manually" to disregard this option and install any required components manually.`, - ]; - - if (!options.hideSyncToPreviewAppOption) { - choices.unshift( - PlatformEnvironmentRequirements.SYNC_TO_PREVIEW_APP_MESSAGE - ); - } - - const lines = [message].concat(choices); - const result = this.buildMultilineMessage(lines); - return result; - } - - private async promptForChoice(opts: { - infoMessage: string; - choices: string[]; - }): Promise { - this.$logger.info(opts.infoMessage); - - await this.$analyticsService.trackEventActionInGoogleAnalytics({ - action: TrackActionNames.CheckEnvironmentRequirements, - additionalData: `User should select: ${opts.infoMessage}`, - }); - - const selection = await this.$prompter.promptForChoice( - PlatformEnvironmentRequirements.CHOOSE_OPTIONS_MESSAGE, - opts.choices + private getEnvVerificationMessage(platform: string) { + // map process.platform to OS name used in docs + const os = ({ + linux: "linux", + win32: "windows", + darwin: "macos", + } as any)[process.platform]; + + return ( + `Verify that your environment is configured according to the system requirements described at\n` + + `https://docs.nativescript.org/environment-setup.html#${os}-${platform.toLowerCase()}.` ); - - await this.$analyticsService.trackEventActionInGoogleAnalytics({ - action: TrackActionNames.CheckEnvironmentRequirements, - additionalData: `User selected: ${selection}`, - }); - - return selection; - } - - private getEnvVerificationMessage() { - return `Verify that your environment is configured according to the system requirements described at ${this.$staticConfig.SYS_REQUIREMENTS_LINK}.`; } - private buildMultilineMessage(parts: string[]): string { - return parts.join(EOL); - } - - private getChoices(options: INotConfiguredEnvOptions): string[] { - const choices: string[] = []; - - choices.push( - ...[ - PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME, - PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME, - ] - ); - - if (!options.hideSyncToPreviewAppOption) { - choices.unshift( - PlatformEnvironmentRequirements.SYNC_TO_PREVIEW_APP_OPTION_NAME - ); - } - - return choices; - } + // private processManuallySetupIfNeeded( + // selectedOption: string, + // platform?: string + // ) { + // if ( + // selectedOption === + // PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME + // ) { + // this.processManuallySetup(platform); + // } + // } + + // private async processSyncToPreviewAppIfNeeded( + // selectedOption: string, + // projectDir: string, + // options: IOptions + // ) { + // if ( + // selectedOption === + // PlatformEnvironmentRequirements.SYNC_TO_PREVIEW_APP_OPTION_NAME + // ) { + // if (!projectDir) { + // this.$errors.fail( + // `No project found. In order to sync to playground you need to go to project directory or specify --path option.` + // ); + // } + // + // await this.$previewAppController.startPreview({ + // projectDir, + // env: options.env, + // useHotModuleReload: options.hmr, + // }); + // + // await this.$previewQrCodeService.printLiveSyncQrCode({ + // projectDir, + // useHotModuleReload: options.hmr, + // link: options.link, + // }); + // } + // } + + // private processManuallySetup(platform?: string): void { + // this.fail( + // `To be able to ${ + // platform ? `build for ${platform}` : "build" + // }, verify that your environment is configured according to the system requirements described at ${ + // this.$staticConfig.SYS_REQUIREMENTS_LINK + // }. If you have any questions, check Stack Overflow: 'https://stackoverflow.com/questions/tagged/nativescript' and our public Discord channel: 'https://nativescript.org/discord/'` + // ); + // } + + // private getInteractiveConsoleMessage(options: INotConfiguredEnvOptions) { + // const message = PlatformEnvironmentRequirements.MISSING_LOCAL_SETUP_MESSAGE; + // const choices = [ + // `Select "Configure for Local Builds" to run the setup script and automatically configure your environment for local builds.`, + // `Select "Skip Step and Configure Manually" to disregard this option and install any required components manually.`, + // ]; + // + // if (!options.hideSyncToPreviewAppOption) { + // choices.unshift( + // PlatformEnvironmentRequirements.SYNC_TO_PREVIEW_APP_MESSAGE + // ); + // } + // + // const lines = [message].concat(choices); + // const result = this.buildMultilineMessage(lines); + // return result; + // } + + // private async promptForChoice(opts: { + // infoMessage: string; + // choices: string[]; + // }): Promise { + // this.$logger.info(opts.infoMessage); + // + // await this.$analyticsService.trackEventActionInGoogleAnalytics({ + // action: TrackActionNames.CheckEnvironmentRequirements, + // additionalData: `User should select: ${opts.infoMessage}`, + // }); + // + // const selection = await this.$prompter.promptForChoice( + // PlatformEnvironmentRequirements.CHOOSE_OPTIONS_MESSAGE, + // opts.choices + // ); + // + // await this.$analyticsService.trackEventActionInGoogleAnalytics({ + // action: TrackActionNames.CheckEnvironmentRequirements, + // additionalData: `User selected: ${selection}`, + // }); + // + // return selection; + // } + + // private getChoices(options: INotConfiguredEnvOptions): string[] { + // const choices: string[] = []; + // + // choices.push( + // ...[ + // PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME, + // PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME, + // ] + // ); + // + // if (!options.hideSyncToPreviewAppOption) { + // choices.unshift( + // PlatformEnvironmentRequirements.SYNC_TO_PREVIEW_APP_OPTION_NAME + // ); + // } + // + // return choices; + // } } + injector.register( "platformEnvironmentRequirements", PlatformEnvironmentRequirements From c2d018785d540217734aaea5e3794ea88cf32d77 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Sun, 8 Aug 2021 14:46:20 +0200 Subject: [PATCH 2/3] chore: cleanup --- .../analytics/analytics-broker-process.ts | 80 +++--- .../platform-environment-requirements.ts | 271 +++++++++--------- 2 files changed, 173 insertions(+), 178 deletions(-) diff --git a/lib/services/analytics/analytics-broker-process.ts b/lib/services/analytics/analytics-broker-process.ts index 7fae8a961a..ff59071929 100644 --- a/lib/services/analytics/analytics-broker-process.ts +++ b/lib/services/analytics/analytics-broker-process.ts @@ -4,11 +4,7 @@ import * as fs from "fs"; import * as _ from "lodash"; import { AnalyticsBroker } from "./analytics-broker"; import { FileLogService } from "../../detached-processes/file-log-service"; -import { - IAnalyticsBroker, - ITrackingInformation, - IPreviewAppTrackingInformation, -} from "./analytics"; +import { IAnalyticsBroker, ITrackingInformation } from "./analytics"; import { injector } from "../../common/yok"; import { TrackingTypes } from "../../common/declarations"; @@ -56,43 +52,43 @@ const killCurrentProcessGracefully = () => { process.exit(); }; -const trackPreviewAppData = async (data: any) => { - const mobileHelper = injector.resolve("mobileHelper"); - const devicesService = injector.resolve( - "devicesService" - ); - await devicesService.initialize({ - platform: data.platform, - skipDeviceDetectionInterval: true, - skipEmulatorStart: true, - }); - - const devices = await devicesService.getDevicesForPlatform(data.platform); - _.each(devices, async (device: Mobile.IDevice) => { - try { - let previewAppFilePath = null; - if (mobileHelper.isAndroidPlatform(device.deviceInfo.platform)) { - previewAppFilePath = "/sdcard/org.nativescript.preview/device.json"; - } else if (mobileHelper.isiOSPlatform(device.deviceInfo.platform)) { - previewAppFilePath = "Documents/device.json"; - } - - const previewAppFileContent = await device.fileSystem.getFileContent( - previewAppFilePath, - "org.nativescript.preview" - ); - const previewAppDeviceId = JSON.parse(previewAppFileContent).id; - data.label += `_${previewAppDeviceId}`; - - analyticsLoggingService.logData({ - message: `analytics-broker-process will send the data from preview app: ${data}`, - }); - await sendDataForTracking(data); - } catch (err) { - // ignore the error - } - }); -}; +// const trackPreviewAppData = async (data: any) => { +// const mobileHelper = injector.resolve("mobileHelper"); +// const devicesService = injector.resolve( +// "devicesService" +// ); +// await devicesService.initialize({ +// platform: data.platform, +// skipDeviceDetectionInterval: true, +// skipEmulatorStart: true, +// }); +// +// const devices = await devicesService.getDevicesForPlatform(data.platform); +// _.each(devices, async (device: Mobile.IDevice) => { +// try { +// let previewAppFilePath = null; +// if (mobileHelper.isAndroidPlatform(device.deviceInfo.platform)) { +// previewAppFilePath = "/sdcard/org.nativescript.preview/device.json"; +// } else if (mobileHelper.isiOSPlatform(device.deviceInfo.platform)) { +// previewAppFilePath = "Documents/device.json"; +// } +// +// const previewAppFileContent = await device.fileSystem.getFileContent( +// previewAppFilePath, +// "org.nativescript.preview" +// ); +// const previewAppDeviceId = JSON.parse(previewAppFileContent).id; +// data.label += `_${previewAppDeviceId}`; +// +// analyticsLoggingService.logData({ +// message: `analytics-broker-process will send the data from preview app: ${data}`, +// }); +// await sendDataForTracking(data); +// } catch (err) { +// // ignore the error +// } +// }); +// }; process.on("message", async (data: ITrackingInformation) => { analyticsLoggingService.logData({ diff --git a/test/services/platform-environment-requirements.ts b/test/services/platform-environment-requirements.ts index 34864cc79e..5e43f5acae 100644 --- a/test/services/platform-environment-requirements.ts +++ b/test/services/platform-environment-requirements.ts @@ -2,15 +2,15 @@ import { Yok } from "../../lib/common/yok"; import { PlatformEnvironmentRequirements } from "../../lib/services/platform-environment-requirements"; import * as stubs from "../stubs"; import { assert } from "chai"; -import { EOL } from "os"; +// import { EOL } from "os"; import { IPlatformEnvironmentRequirements } from "../../lib/definitions/platform"; import { IInjector } from "../../lib/common/definitions/yok"; const helpers = require("../../lib/common/helpers"); const originalIsInteractive = helpers.isInteractive; const platform = "android"; -const manuallySetupErrorMessage = `To be able to build for ${platform}, verify that your environment is configured according to the system requirements described at `; -const nonInteractiveConsoleMessage = `Your environment is not configured properly and you will not be able to execute local builds. To continue, choose one of the following options: ${EOL}Run $ tns preview command to enjoy NativeScript without any local setup.${EOL}Run $ tns setup command to run the setup script to try to automatically configure your environment for local builds.${EOL}Verify that your environment is configured according to the system requirements described at .`; +// const manuallySetupErrorMessage = `To be able to build for ${platform}, verify that your environment is configured according to the system requirements described at `; +// const nonInteractiveConsoleMessage = `Your environment is not configured properly and you will not be able to execute local builds. ${EOL}Verify that your environment is configured according to the system requirements described at`; function createTestInjector() { const testInjector = new Yok(); @@ -65,23 +65,23 @@ describe("platformEnvironmentRequirements ", () => { } } - function mockPrompter(data: { - firstCallOptionName: string; - secondCallOptionName?: string; - }) { - const prompter = testInjector.resolve("prompter"); - prompter.promptForChoice = (message: string, choices: string[]) => { - promptForChoiceData.push({ message: message, choices: choices }); - - if (promptForChoiceData.length === 1) { - return Promise.resolve(data.firstCallOptionName); - } - - if (data.secondCallOptionName) { - return Promise.resolve(data.secondCallOptionName); - } - }; - } + // function mockPrompter(data: { + // firstCallOptionName: string; + // secondCallOptionName?: string; + // }) { + // const prompter = testInjector.resolve("prompter"); + // prompter.promptForChoice = (message: string, choices: string[]) => { + // promptForChoiceData.push({ message: message, choices: choices }); + // + // if (promptForChoiceData.length === 1) { + // return Promise.resolve(data.firstCallOptionName); + // } + // + // if (data.secondCallOptionName) { + // return Promise.resolve(data.secondCallOptionName); + // } + // }; + // } beforeEach(() => { testInjector = createTestInjector(); @@ -105,56 +105,56 @@ describe("platformEnvironmentRequirements ", () => { assert.isTrue(result.canExecute); assert.isTrue(promptForChoiceData.length === 0); }); - it("should show prompt when environment is not configured", async () => { - mockDoctorService({ canExecuteLocalBuild: false }); - mockPrompter({ - firstCallOptionName: - PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME, - }); - - await assert.isRejected( - platformEnvironmentRequirements.checkEnvironmentRequirements({ - platform, - }) - ); - assert.isTrue(promptForChoiceData.length === 1); - assert.deepStrictEqual( - "To continue, choose one of the following options: ", - promptForChoiceData[0].message - ); - assert.deepStrictEqual( - [ - "Sync to Playground", - "Configure for Local Builds", - "Skip Step and Configure Manually", - ], - promptForChoiceData[0].choices - ); - }); - - it("should not show 'Sync to Playground' option when hideSyncToPreviewAppOption is provided", async () => { - mockDoctorService({ canExecuteLocalBuild: false }); - mockPrompter({ - firstCallOptionName: - PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME, - }); - - await assert.isRejected( - platformEnvironmentRequirements.checkEnvironmentRequirements({ - platform, - notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true }, - }) - ); - assert.isTrue(promptForChoiceData.length === 1); - assert.deepStrictEqual( - "To continue, choose one of the following options: ", - promptForChoiceData[0].message - ); - assert.deepStrictEqual( - ["Configure for Local Builds", "Skip Step and Configure Manually"], - promptForChoiceData[0].choices - ); - }); + // it("should show prompt when environment is not configured", async () => { + // mockDoctorService({ canExecuteLocalBuild: false }); + // mockPrompter({ + // firstCallOptionName: + // PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME, + // }); + // + // await assert.isRejected( + // platformEnvironmentRequirements.checkEnvironmentRequirements({ + // platform, + // }) + // ); + // assert.isTrue(promptForChoiceData.length === 1); + // assert.deepStrictEqual( + // "To continue, choose one of the following options: ", + // promptForChoiceData[0].message + // ); + // assert.deepStrictEqual( + // [ + // "Sync to Playground", + // "Configure for Local Builds", + // "Skip Step and Configure Manually", + // ], + // promptForChoiceData[0].choices + // ); + // }); + + // it("should not show 'Sync to Playground' option when hideSyncToPreviewAppOption is provided", async () => { + // mockDoctorService({ canExecuteLocalBuild: false }); + // mockPrompter({ + // firstCallOptionName: + // PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME, + // }); + // + // await assert.isRejected( + // platformEnvironmentRequirements.checkEnvironmentRequirements({ + // platform, + // notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true }, + // }) + // ); + // assert.isTrue(promptForChoiceData.length === 1); + // assert.deepStrictEqual( + // "To continue, choose one of the following options: ", + // promptForChoiceData[0].message + // ); + // assert.deepStrictEqual( + // ["Configure for Local Builds", "Skip Step and Configure Manually"], + // promptForChoiceData[0].choices + // ); + // }); it("should skip env check when NS_SKIP_ENV_CHECK environment variable is passed", async () => { (process.env).NS_SKIP_ENV_CHECK = true; @@ -166,70 +166,70 @@ describe("platformEnvironmentRequirements ", () => { assert.isTrue(promptForChoiceData.length === 0); }); - describe("when local setup option is selected", () => { - beforeEach(() => { - mockPrompter({ - firstCallOptionName: - PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME, - }); - }); - - it("should return true when env is configured after executing setup script", async () => { - const doctorService = testInjector.resolve("doctorService"); - doctorService.canExecuteLocalBuild = () => false; - doctorService.runSetupScript = async () => { - doctorService.canExecuteLocalBuild = () => true; - }; - - const output = await platformEnvironmentRequirements.checkEnvironmentRequirements( - { platform } - ); - assert.isTrue(output.canExecute); - }); - - describe("and env is not configured after executing setup script", () => { - beforeEach(() => { - mockDoctorService({ - canExecuteLocalBuild: false, - mockSetupScript: true, - }); - }); - - it("should list 2 posibile options to select", async () => { - mockPrompter({ - firstCallOptionName: - PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME, - }); - - await assert.isRejected( - platformEnvironmentRequirements.checkEnvironmentRequirements({ - platform, - }), - "The setup script was not able to configure your environment for local builds. To execute local builds, you have to set up your environment manually." + - " Please consult our setup instructions here 'https://docs.nativescript.org/start/quick-setup" - ); - }); - }); - }); - - describe("when manually setup option is selected", () => { - beforeEach(() => { - mockDoctorService({ canExecuteLocalBuild: false }); - mockPrompter({ - firstCallOptionName: - PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME, - }); - }); - - it("should fail", async () => { - await assert.isRejected( - platformEnvironmentRequirements.checkEnvironmentRequirements({ - platform, - }), - manuallySetupErrorMessage - ); - }); - }); + // describe("when local setup option is selected", () => { + // beforeEach(() => { + // mockPrompter({ + // firstCallOptionName: + // PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME, + // }); + // }); + // + // it("should return true when env is configured after executing setup script", async () => { + // const doctorService = testInjector.resolve("doctorService"); + // doctorService.canExecuteLocalBuild = () => false; + // doctorService.runSetupScript = async () => { + // doctorService.canExecuteLocalBuild = () => true; + // }; + // + // const output = await platformEnvironmentRequirements.checkEnvironmentRequirements( + // { platform } + // ); + // assert.isTrue(output.canExecute); + // }); + // + // describe("and env is not configured after executing setup script", () => { + // beforeEach(() => { + // mockDoctorService({ + // canExecuteLocalBuild: false, + // mockSetupScript: true, + // }); + // }); + // + // it("should list 2 posibile options to select", async () => { + // mockPrompter({ + // firstCallOptionName: + // PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME, + // }); + // + // await assert.isRejected( + // platformEnvironmentRequirements.checkEnvironmentRequirements({ + // platform, + // }), + // "The setup script was not able to configure your environment for local builds. To execute local builds, you have to set up your environment manually." + + // " Please consult our setup instructions here 'https://docs.nativescript.org/start/quick-setup" + // ); + // }); + // }); + // }); + + // describe("when manually setup option is selected", () => { + // beforeEach(() => { + // mockDoctorService({ canExecuteLocalBuild: false }); + // mockPrompter({ + // firstCallOptionName: + // PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME, + // }); + // }); + // + // it("should fail", async () => { + // await assert.isRejected( + // platformEnvironmentRequirements.checkEnvironmentRequirements({ + // platform, + // }), + // manuallySetupErrorMessage + // ); + // }); + // }); describe("when console is non interactive", () => { beforeEach(() => { @@ -241,8 +241,7 @@ describe("platformEnvironmentRequirements ", () => { await assert.isRejected( platformEnvironmentRequirements.checkEnvironmentRequirements({ platform, - }), - nonInteractiveConsoleMessage + }) ); }); }); From 22c963950e478237f6a3d731226f08a3e79678a4 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Sun, 8 Aug 2021 14:46:40 +0200 Subject: [PATCH 3/3] feat: better post-creation message --- lib/commands/create-project.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/commands/create-project.ts b/lib/commands/create-project.ts index c35333f13c..4ab9e239ac 100644 --- a/lib/commands/create-project.ts +++ b/lib/commands/create-project.ts @@ -343,7 +343,17 @@ can skip this prompt next time using the --template option, or the --ng, --react const { projectDir } = this.createdProjectData; const relativePath = path.relative(process.cwd(), projectDir); this.$logger.printMarkdown( - `Now you can navigate to your project with \`$ cd ${relativePath}\`` + `Now you can navigate to your project with \`$ cd ${relativePath}\` and then:` + ); + this.$logger.printMarkdown( + [ + `- Run the project on iOS \`$ ns run ios\``, + `- Run the project on Android \`$ ns run android\``, + `- Debug the project on iOS \`$ ns debug ios\``, + `- Debug the project on Android \`$ ns debug android\``, + ``, + `For more options consult the docs or run \`$ ns --help\``, + ].join("\n") ); // Commented as we may bring this back with a playground revision/rewrite // this.$logger.printMarkdown(