UNPKG

nativescript-doctor

Version:

Library that helps identifying if the environment can be used for development of {N} apps.

237 lines (236 loc) 15.3 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const constants_1 = require("./constants"); const os_1 = require("os"); const semver = require("semver"); class Doctor { constructor(androidLocalBuildRequirements, helpers, hostInfo, iOSLocalBuildRequirements, sysInfo, androidToolsInfo) { this.androidLocalBuildRequirements = androidLocalBuildRequirements; this.helpers = helpers; this.hostInfo = hostInfo; this.iOSLocalBuildRequirements = iOSLocalBuildRequirements; this.sysInfo = sysInfo; this.androidToolsInfo = androidToolsInfo; } canExecuteLocalBuild(platform, projectDir, runtimeVersion) { return __awaiter(this, void 0, void 0, function* () { this.validatePlatform(platform); if (platform.toLowerCase() === constants_1.Constants.ANDROID_PLATFORM_NAME.toLowerCase()) { return yield this.androidLocalBuildRequirements.checkRequirements(projectDir, runtimeVersion); } else if (platform.toLowerCase() === constants_1.Constants.IOS_PLATFORM_NAME.toLowerCase()) { return yield this.iOSLocalBuildRequirements.checkRequirements(); } return false; }); } getInfos(config) { return __awaiter(this, void 0, void 0, function* () { let result = []; const sysInfoData = yield this.sysInfo.getSysInfo(config); if (!config || !config.platform || config.platform.toLowerCase() === constants_1.Constants.ANDROID_PLATFORM_NAME.toLowerCase()) { result = result.concat(this.getAndroidInfos(sysInfoData, config && config.projectDir, config && config.androidRuntimeVersion)); } if (!config || !config.platform || config.platform.toLowerCase() === constants_1.Constants.IOS_PLATFORM_NAME.toLowerCase()) { result = result.concat(yield this.getiOSInfos(sysInfoData)); } if (!this.hostInfo.isDarwin) { result.push({ message: "Local builds for iOS can be executed only on a macOS system. To build for iOS on a different operating system, you can use the NativeScript cloud infrastructure.", additionalInformation: "", platforms: [constants_1.Constants.IOS_PLATFORM_NAME], type: constants_1.Constants.INFO_TYPE_NAME }); } return result; }); } getWarnings(config) { return __awaiter(this, void 0, void 0, function* () { const info = yield this.getInfos(config); return info.filter(item => item.type === constants_1.Constants.WARNING_TYPE_NAME) .map(item => this.convertInfoToWarning(item)); }); } getAndroidInfos(sysInfoData, projectDir, runtimeVersion) { let result = []; result = result.concat(this.processValidationErrors({ warnings: this.androidToolsInfo.validateAndroidHomeEnvVariable(), infoMessage: "Your ANDROID_HOME environment variable is set and points to correct directory.", platforms: [constants_1.Constants.ANDROID_PLATFORM_NAME] }), this.processSysInfoItem({ item: sysInfoData.adbVer, infoMessage: "Your adb from the Android SDK is correctly installed.", warningMessage: "adb from the Android SDK is not installed or is not configured properly. ", additionalInformation: "For Android-related operations, the NativeScript CLI will use a built-in version of adb." + os_1.EOL + "To avoid possible issues with the native Android emulator, Genymotion or connected" + os_1.EOL + "Android devices, verify that you have installed the latest Android SDK and" + os_1.EOL + "its dependencies as described in http://developer.android.com/sdk/index.html#Requirements", platforms: [constants_1.Constants.ANDROID_PLATFORM_NAME] }), this.processSysInfoItem({ item: sysInfoData.isAndroidSdkConfiguredCorrectly, infoMessage: "The Android SDK is installed.", warningMessage: "The Android SDK is not installed or is not configured properly.", additionalInformation: "You will not be able to run your apps in the native emulator. To be able to run apps" + os_1.EOL + "in the native Android emulator, verify that you have installed the latest Android SDK " + os_1.EOL + "and its dependencies as described in http://developer.android.com/sdk/index.html#Requirements", platforms: [constants_1.Constants.ANDROID_PLATFORM_NAME] }), this.processValidationErrors({ warnings: this.androidToolsInfo.validateInfo({ projectDir }), infoMessage: "A compatible Android SDK for compilation is found.", platforms: [constants_1.Constants.ANDROID_PLATFORM_NAME] }), this.processValidationErrors({ warnings: this.androidToolsInfo.validateJavacVersion(sysInfoData.javacVersion, projectDir, runtimeVersion), infoMessage: "Javac is installed and is configured properly.", platforms: [constants_1.Constants.ANDROID_PLATFORM_NAME] }), this.processSysInfoItem({ item: sysInfoData.javacVersion, infoMessage: "The Java Development Kit (JDK) is installed and is configured properly.", warningMessage: "The Java Development Kit (JDK) is not installed or is not configured properly.", additionalInformation: "You will not be able to work with the Android SDK and you might not be able" + os_1.EOL + "to perform some Android-related operations. To ensure that you can develop and" + os_1.EOL + "test your apps for Android, verify that you have installed the JDK as" + os_1.EOL + "described in http://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html (for JDK 8).", platforms: [constants_1.Constants.ANDROID_PLATFORM_NAME] })); return result; } getiOSInfos(sysInfoData) { return __awaiter(this, void 0, void 0, function* () { let result = []; if (this.hostInfo.isDarwin) { result = result.concat(this.processSysInfoItem({ item: sysInfoData.xcodeVer, infoMessage: "Xcode is installed and is configured properly.", warningMessage: "Xcode is not installed or is not configured properly.", additionalInformation: "You will not be able to build your projects for iOS or run them in the iOS Simulator." + os_1.EOL + "To be able to build for iOS and run apps in the native emulator, verify that you have installed Xcode.", platforms: [constants_1.Constants.IOS_PLATFORM_NAME] }), this.processSysInfoItem({ item: sysInfoData.xcodeprojLocation, infoMessage: "xcodeproj is installed and is configured properly.", warningMessage: "xcodeproj is not installed or is not configured properly.", additionalInformation: "You will not be able to build your projects for iOS." + os_1.EOL + "To be able to build for iOS and run apps in the native emulator, verify that you have installed xcodeproj.", platforms: [constants_1.Constants.IOS_PLATFORM_NAME] }), this.processSysInfoItem({ item: sysInfoData.cocoaPodsVer, infoMessage: "CocoaPods are installed.", warningMessage: "CocoaPods is not installed or is not configured properly.", additionalInformation: "You will not be able to build your projects for iOS if they contain plugin with CocoaPod file." + os_1.EOL + "To be able to build such projects, verify that you have installed CocoaPods (`sudo gem install cocoapods`).", platforms: [constants_1.Constants.IOS_PLATFORM_NAME] }), this.processSysInfoItem({ item: !sysInfoData.cocoaPodsVer || !sysInfoData.isCocoaPodsUpdateRequired, infoMessage: "CocoaPods update is not required.", warningMessage: "CocoaPods update required.", additionalInformation: `You are using CocoaPods version ${sysInfoData.cocoaPodsVer} which does not support Xcode ${sysInfoData.xcodeVer} yet.${os_1.EOL}${os_1.EOL}You can update your cocoapods by running $sudo gem install cocoapods from a terminal.${os_1.EOL}${os_1.EOL}In order for the NativeScript CLI to be able to work correctly with this setup you need to install xcproj command line tool and add it to your PATH.Xcproj can be installed with homebrew by running $ brew install xcproj from the terminal`, platforms: [constants_1.Constants.IOS_PLATFORM_NAME] })); if (sysInfoData.xcodeVer && sysInfoData.cocoaPodsVer) { const isCocoaPodsWorkingCorrectly = yield this.sysInfo.isCocoaPodsWorkingCorrectly(); result = result.concat(this.processSysInfoItem({ item: isCocoaPodsWorkingCorrectly, infoMessage: "CocoaPods are configured properly.", warningMessage: "There was a problem with CocoaPods", additionalInformation: "Verify that CocoaPods are configured properly.", platforms: [constants_1.Constants.IOS_PLATFORM_NAME], })); } result = result.concat(this.processSysInfoItem({ item: !sysInfoData.cocoaPodsVer || !semver.valid(sysInfoData.cocoaPodsVer) || !semver.lt(sysInfoData.cocoaPodsVer, Doctor.MIN_SUPPORTED_POD_VERSION), infoMessage: `Your current CocoaPods version is newer than ${Doctor.MIN_SUPPORTED_POD_VERSION}.`, warningMessage: `Your current CocoaPods version is earlier than ${Doctor.MIN_SUPPORTED_POD_VERSION}.`, additionalInformation: "You will not be able to build your projects for iOS if they contain plugin with CocoaPod file." + os_1.EOL + `To be able to build such projects, verify that you have at least ${Doctor.MIN_SUPPORTED_POD_VERSION} version installed.`, platforms: [constants_1.Constants.IOS_PLATFORM_NAME] }), this.processSysInfoItem({ item: sysInfoData.pythonInfo.isInstalled, infoMessage: "Python installed and configured correctly.", warningMessage: `Couldn't retrieve installed python packages.`, additionalInformation: "We cannot verify your python installation is setup correctly. Please, make sure you have both 'python' and 'pip' installed." + os_1.EOL + `Error while validating Python packages. Error is: ${sysInfoData.pythonInfo.installationErrorMessage}`, platforms: [constants_1.Constants.IOS_PLATFORM_NAME] }), this.processSysInfoItem({ item: sysInfoData.pythonInfo.isSixPackageInstalled, infoMessage: `The Python 'six' package is found.`, warningMessage: `The Python 'six' package not found.`, additionalInformation: "This package is required by the Debugger library (LLDB) for iOS. You can install it by first making sure you have pip installed and then running 'pip install six' from the terminal.", platforms: [constants_1.Constants.IOS_PLATFORM_NAME] })); if (sysInfoData.xcodeVer) { result = result.concat(this.processSysInfoItem({ item: yield this.iOSLocalBuildRequirements.isXcodeVersionValid(), infoMessage: `Xcode version ${sysInfoData.xcodeVer} satisfies minimum required version ${constants_1.Constants.XCODE_MIN_REQUIRED_VERSION}.`, warningMessage: `Xcode version ${sysInfoData.xcodeVer} is lower than minimum required version ${constants_1.Constants.XCODE_MIN_REQUIRED_VERSION}.`, additionalInformation: "To build your application for iOS, update your Xcode.", platforms: [constants_1.Constants.IOS_PLATFORM_NAME] })); } } return result; }); } processSysInfoItem(data) { if (!data.item) { return { message: `WARNING: ${data.warningMessage}`, additionalInformation: data.additionalInformation, platforms: data.platforms, type: constants_1.Constants.WARNING_TYPE_NAME }; } return { message: `${data.infoMessage}`, platforms: data.platforms, type: constants_1.Constants.INFO_TYPE_NAME }; } processValidationErrors(data) { if (data.warnings.length > 0) { return data.warnings.map(warning => this.convertWarningToInfo(warning)); } return [{ message: data.infoMessage, platforms: data.platforms, type: constants_1.Constants.INFO_TYPE_NAME }]; } convertWarningToInfo(warning) { return { message: warning.warning, additionalInformation: warning.additionalInformation, platforms: warning.platforms, type: constants_1.Constants.WARNING_TYPE_NAME }; } convertInfoToWarning(info) { return { warning: info.message, additionalInformation: info.additionalInformation, platforms: info.platforms }; } isPlatformSupported(platform) { return constants_1.Constants.SUPPORTED_PLATFORMS.map(pl => pl.toLowerCase()).indexOf(platform.toLowerCase()) !== -1; } validatePlatform(platform) { if (!platform) { throw new Error("You must specify a platform."); } if (!this.isPlatformSupported(platform)) { throw new Error(`Platform ${platform} is not supported.The supported platforms are: ${constants_1.Constants.SUPPORTED_PLATFORMS.join(", ")} `); } } } exports.Doctor = Doctor; Doctor.MIN_SUPPORTED_POD_VERSION = "1.0.0";