UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

119 lines (118 loc) 6.28 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.runAppleWizard = void 0; /* eslint-disable max-lines */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unused-vars */ // @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 telemetry_1 = require("../telemetry"); const SentryUtils = __importStar(require("../utils/sentrycli-utils")); const cocoapod = __importStar(require("./cocoapod")); const codeTools = __importStar(require("./code-tools")); /* eslint-enable @typescript-eslint/no-unused-vars */ const clack_1 = require("../utils/clack"); const check_installed_cli_1 = require("./check-installed-cli"); const configure_fastlane_1 = require("./configure-fastlane"); const lookup_xcode_project_1 = require("./lookup-xcode-project"); async function runAppleWizard(options) { return (0, telemetry_1.withTelemetry)({ enabled: options.telemetryEnabled, integration: 'ios', wizardOptions: options, }, () => runAppleWizardWithTelementry(options)); } exports.runAppleWizard = runAppleWizard; async function runAppleWizardWithTelementry(options) { // Define options with defaults const projectDir = options.projectDir ?? process.cwd(); // Step - Welcome Message (0, clack_1.printWelcome)({ wizardName: 'Sentry Apple Wizard', promoCode: options.promoCode, }); // Step - Git Status Check await (0, clack_1.confirmContinueIfNoOrDirtyGitRepo)({ ignoreGitChanges: options.ignoreGitChanges, cwd: projectDir, }); // Step - Sentry CLI Check await (0, check_installed_cli_1.checkInstalledCLI)(); // Step - Xcode Project Lookup // This step should be run before the Sentry Project and API Key step // because it can abort the wizard if no Xcode project is found. const { xcProject, target } = await (0, lookup_xcode_project_1.lookupXcodeProject)({ projectDir, }); // Step - Sentry Project and API Key const { selectedProject, authToken } = await (0, clack_1.getOrAskForProjectData)(options, 'apple-ios'); SentryUtils.createSentryCLIRC(projectDir, { auth_token: authToken }); prompts_1.default.log.info(`Created a ${chalk_1.default.cyan('.sentryclirc')} file in your project directory to provide an auth token for Sentry CLI. It was also added to your ${chalk_1.default.cyan('.gitignore')} file. Set the ${chalk_1.default.cyan('SENTRY_AUTH_TOKEN')} environment variable in your CI environment. See https://docs.sentry.io/cli/configuration/#auth-token for more information.`); let hasCocoa = cocoapod.usesCocoaPod(projectDir); Sentry.setTag('cocoapod-exists', hasCocoa); if (hasCocoa) { const pm = (await (0, telemetry_1.traceStep)('Choose a package manager', () => (0, clack_1.askForItemSelection)(['Swift Package Manager', 'CocoaPods'], 'Which package manager would you like to use to add Sentry?'))).value; hasCocoa = pm === 'CocoaPods'; if (hasCocoa) { const podAdded = await (0, telemetry_1.traceStep)('Add CocoaPods reference', () => cocoapod.addCocoaPods(projectDir)); Sentry.setTag('cocoapod-added', podAdded); if (!podAdded) { prompts_1.default.log.warn("Could not add Sentry pod to your Podfile. You'll have to add it manually.\nPlease follow the instructions at https://docs.sentry.io/platforms/apple/guides/ios/#install"); } } } Sentry.setTag('package-manager', hasCocoa ? 'cocoapods' : 'SPM'); (0, telemetry_1.traceStep)('Update Xcode project', () => { xcProject.updateXcodeProject(selectedProject, target, !hasCocoa, true); }); const codeAdded = (0, telemetry_1.traceStep)('Add code snippet', () => { const files = xcProject.filesForTarget(target); if (files === undefined || files.length == 0) return false; return codeTools.addCodeSnippetToProject(projectDir, files, selectedProject.keys[0].dsn.public); }); Sentry.setTag('Snippet-Added', codeAdded); if (!codeAdded) { prompts_1.default.log.warn('Added the Sentry dependency to your project but could not add the Sentry code snippet. Please add the code snipped manually by following the docs: https://docs.sentry.io/platforms/apple/guides/ios/#configure'); } // Step - Fastlane Configuration await (0, configure_fastlane_1.configureFastlane)({ projectDir, orgSlug: selectedProject.organization.slug, projectSlug: selectedProject.slug, }); prompts_1.default.log.success('Sentry was successfully added to your project! Run your project to send your first event to Sentry. Go to Sentry.io to see whether everything is working fine.'); } //# sourceMappingURL=apple-wizard.js.map