UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

98 lines 4.94 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.lookupXcodeProject = void 0; // @ts-expect-error - clack is ESM and TS complains about that. It works though const prompts_1 = __importDefault(require("@clack/prompts")); const Sentry = __importStar(require("@sentry/node")); const chalk_1 = __importDefault(require("chalk")); const fs = __importStar(require("fs")); const path = __importStar(require("path")); const telemetry_1 = require("../telemetry"); const clack_1 = require("../utils/clack"); const debug_1 = require("../utils/debug"); const search_xcode_project_at_path_1 = require("./search-xcode-project-at-path"); const xcode_manager_1 = require("./xcode-manager"); async function lookupXcodeProject({ projectDir, }) { (0, debug_1.debug)(`Looking for Xcode project in directory: ${chalk_1.default.cyan(projectDir)}`); const xcodeProjFiles = (0, search_xcode_project_at_path_1.searchXcodeProjectAtPath)(projectDir); if (xcodeProjFiles.length === 0) { prompts_1.default.log.error('No Xcode project found. Please run this command from the root of your project.'); Sentry.setTag('no-xcode-project', true); return await (0, clack_1.abort)(); } (0, debug_1.debug)(`Found ${chalk_1.default.cyan(xcodeProjFiles.length.toString())} candidates for Xcode project`); // In case there is only one Xcode project, we can use that one. // Otherwise, we need to ask the user which one they want to use. let xcodeProjFile; if (xcodeProjFiles.length === 1) { (0, debug_1.debug)(`Found exactly one Xcode project, using it`); Sentry.setTag('multiple-projects', false); xcodeProjFile = xcodeProjFiles[0]; } else { (0, debug_1.debug)(`Found multiple Xcode projects, asking user to choose one`); Sentry.setTag('multiple-projects', true); xcodeProjFile = (await (0, telemetry_1.traceStep)('Choose Xcode project', () => (0, clack_1.askForItemSelection)(xcodeProjFiles, 'Which project do you want to add Sentry to?'))).value; } // Load the pbxproj file const pathToPbxproj = path.join(projectDir, xcodeProjFile, 'project.pbxproj'); (0, debug_1.debug)(`Loading Xcode project pbxproj at path: ${chalk_1.default.cyan(pathToPbxproj)}`); if (!fs.existsSync(pathToPbxproj)) { prompts_1.default.log.error(`No pbxproj found at ${xcodeProjFile}`); Sentry.setTag('pbxproj-not-found', true); return await (0, clack_1.abort)(); } const xcProject = new xcode_manager_1.XcodeProject(pathToPbxproj); const availableTargets = xcProject.getAllTargets(); if (availableTargets.length == 0) { prompts_1.default.log.error(`No suitable Xcode target found in ${xcodeProjFile}`); Sentry.setTag('No-Target', true); return await (0, clack_1.abort)(); } (0, debug_1.debug)(`Found ${chalk_1.default.cyan(availableTargets.length.toString())} targets in Xcode project`); // Step - Lookup Xcode Target let target; if (availableTargets.length == 1) { (0, debug_1.debug)(`Found exactly one target, using it`); Sentry.setTag('multiple-targets', false); target = availableTargets[0]; } else { (0, debug_1.debug)(`Found multiple targets, asking user to choose one`); Sentry.setTag('multiple-targets', true); target = (await (0, telemetry_1.traceStep)('Choose target', () => (0, clack_1.askForItemSelection)(availableTargets, 'Which target do you want to add Sentry to?'))).value; } (0, debug_1.debug)(`Selected target: ${chalk_1.default.cyan(target)}`); return { xcProject, target, }; } exports.lookupXcodeProject = lookupXcodeProject; //# sourceMappingURL=lookup-xcode-project.js.map