UNPKG

@nativescript/doctor

Version:

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

324 lines (323 loc) 20.2 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()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (g && (g = 0, op[0] && (_ = 0)), _) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Doctor = void 0; var constants_1 = require("./constants"); var os_1 = require("os"); var semver = require("semver"); var Doctor = (function () { function Doctor(androidLocalBuildRequirements, helpers, hostInfo, iOSLocalBuildRequirements, sysInfo, androidToolsInfo) { this.androidLocalBuildRequirements = androidLocalBuildRequirements; this.helpers = helpers; this.hostInfo = hostInfo; this.iOSLocalBuildRequirements = iOSLocalBuildRequirements; this.sysInfo = sysInfo; this.androidToolsInfo = androidToolsInfo; } Doctor.prototype.canExecuteLocalBuild = function (platform, projectDir, runtimeVersion) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: this.validatePlatform(platform); if (!(platform.toLowerCase() === constants_1.Constants.ANDROID_PLATFORM_NAME.toLowerCase())) return [3, 2]; return [4, this.androidLocalBuildRequirements.checkRequirements(projectDir, runtimeVersion)]; case 1: return [2, _a.sent()]; case 2: if (!(platform.toLowerCase() === constants_1.Constants.IOS_PLATFORM_NAME.toLowerCase())) return [3, 4]; return [4, this.iOSLocalBuildRequirements.checkRequirements()]; case 3: return [2, _a.sent()]; case 4: return [2, false]; } }); }); }; Doctor.prototype.getInfos = function (config) { return __awaiter(this, void 0, void 0, function () { var result, sysInfoData, _a, _b; return __generator(this, function (_c) { switch (_c.label) { case 0: result = []; return [4, this.sysInfo.getSysInfo(config)]; case 1: sysInfoData = _c.sent(); 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())) return [3, 3]; _b = (_a = result).concat; return [4, this.getiOSInfos(sysInfoData)]; case 2: result = _b.apply(_a, [_c.sent()]); _c.label = 3; case 3: 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 [2, result]; } }); }); }; Doctor.prototype.getWarnings = function (config) { return __awaiter(this, void 0, void 0, function () { var info; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4, this.getInfos(config)]; case 1: info = _a.sent(); return [2, info .filter(function (item) { return item.type === constants_1.Constants.WARNING_TYPE_NAME; }) .map(function (item) { return _this.convertInfoToWarning(item); })]; } }); }); }; Doctor.prototype.getAndroidInfos = function (sysInfoData, projectDir, runtimeVersion) { var 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: 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; }; Doctor.prototype.getiOSInfos = function (sysInfoData) { return __awaiter(this, void 0, void 0, function () { var result, isCocoaPodsWorkingCorrectly, _a, _b, _c; var _d; return __generator(this, function (_e) { switch (_e.label) { case 0: result = []; if (!this.hostInfo.isDarwin) return [3, 4]; 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 ".concat(sysInfoData.cocoaPodsVer, " which does not support Xcode ").concat(sysInfoData.xcodeVer, " yet.").concat(os_1.EOL).concat(os_1.EOL, "You can update your cocoapods by running $sudo gem install cocoapods from a terminal.").concat(os_1.EOL).concat(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)) return [3, 2]; return [4, this.sysInfo.isCocoaPodsWorkingCorrectly()]; case 1: isCocoaPodsWorkingCorrectly = _e.sent(); 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], })); _e.label = 2; case 2: 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 ".concat(Doctor.MIN_SUPPORTED_POD_VERSION, "."), warningMessage: "Your current CocoaPods version is earlier than ".concat(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 ".concat(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 'python3' and 'pip3' installed." + os_1.EOL + "Error while validating Python packages. Error is: ".concat(sysInfoData.pythonInfo.installationErrorMessage), platforms: [constants_1.Constants.IOS_PLATFORM_NAME], })); if (!sysInfoData.xcodeVer) return [3, 4]; _b = (_a = result).concat; _c = this.processSysInfoItem; _d = {}; return [4, this.iOSLocalBuildRequirements.isXcodeVersionValid()]; case 3: result = _b.apply(_a, [_c.apply(this, [(_d.item = _e.sent(), _d.infoMessage = "Xcode version ".concat(sysInfoData.xcodeVer, " satisfies minimum required version ").concat(constants_1.Constants.XCODE_MIN_REQUIRED_VERSION, "."), _d.warningMessage = "Xcode version ".concat(sysInfoData.xcodeVer, " is lower than minimum required version ").concat(constants_1.Constants.XCODE_MIN_REQUIRED_VERSION, "."), _d.additionalInformation = "To build your application for iOS, update your Xcode.", _d.platforms = [constants_1.Constants.IOS_PLATFORM_NAME], _d)])]); _e.label = 4; case 4: return [2, result]; } }); }); }; Doctor.prototype.processSysInfoItem = function (data) { if (!data.item) { return { message: "WARNING: ".concat(data.warningMessage), additionalInformation: data.additionalInformation, platforms: data.platforms, type: constants_1.Constants.WARNING_TYPE_NAME, }; } return { message: "".concat(data.infoMessage), platforms: data.platforms, type: constants_1.Constants.INFO_TYPE_NAME, }; }; Doctor.prototype.processValidationErrors = function (data) { var _this = this; if (data.warnings.length > 0) { return data.warnings.map(function (warning) { return _this.convertWarningToInfo(warning); }); } return [ { message: data.infoMessage, platforms: data.platforms, type: constants_1.Constants.INFO_TYPE_NAME, }, ]; }; Doctor.prototype.convertWarningToInfo = function (warning) { return { message: warning.warning, additionalInformation: warning.additionalInformation, platforms: warning.platforms, type: constants_1.Constants.WARNING_TYPE_NAME, }; }; Doctor.prototype.convertInfoToWarning = function (info) { return { warning: info.message, additionalInformation: info.additionalInformation, platforms: info.platforms, }; }; Doctor.prototype.isPlatformSupported = function (platform) { return (constants_1.Constants.SUPPORTED_PLATFORMS.map(function (pl) { return pl.toLowerCase(); }).indexOf(platform.toLowerCase()) !== -1); }; Doctor.prototype.validatePlatform = function (platform) { if (!platform) { throw new Error("You must specify a platform."); } if (!this.isPlatformSupported(platform)) { throw new Error("Platform ".concat(platform, " is not supported.The supported platforms are: ").concat(constants_1.Constants.SUPPORTED_PLATFORMS.join(", "), " ")); } }; Doctor.MIN_SUPPORTED_POD_VERSION = "1.0.0"; return Doctor; }()); exports.Doctor = Doctor;