UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

129 lines (127 loc) 7.93 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.runFlutterWizard = void 0; const Sentry = __importStar(require("@sentry/node")); const fs = __importStar(require("fs")); const path = __importStar(require("path")); const release_registry_1 = require("../utils/release-registry"); const codetools = __importStar(require("./code-tools")); const templates_1 = require("./templates"); // @ts-expect-error - clack is ESM and TS complains about that. It works though const clack = __importStar(require("@clack/prompts")); const chalk_1 = __importDefault(require("chalk")); const clack_1 = require("../utils/clack"); const telemetry_1 = require("../telemetry"); const code_tools_1 = require("./code-tools"); const mcp_config_1 = require("../utils/clack/mcp-config"); async function runFlutterWizard(options) { return (0, telemetry_1.withTelemetry)({ enabled: options.telemetryEnabled, integration: 'flutter', wizardOptions: options, }, () => runFlutterWizardWithTelemetry(options)); } exports.runFlutterWizard = runFlutterWizard; async function runFlutterWizardWithTelemetry(options) { (0, clack_1.printWelcome)({ wizardName: 'Sentry Flutter Wizard', promoCode: options.promoCode, }); await (0, clack_1.confirmContinueIfNoOrDirtyGitRepo)({ ignoreGitChanges: options.ignoreGitChanges, cwd: undefined, }); const { selectedProject, selfHosted, sentryUrl, authToken } = await (0, clack_1.getOrAskForProjectData)(options, 'flutter'); const projectDir = process.cwd(); const pubspecFile = path.join(projectDir, 'pubspec.yaml'); if (!fs.existsSync(pubspecFile)) { clack.log.error(`Could not find ${chalk_1.default.cyan('pubspec.yaml')}. Make sure you run the wizard in the projects root folder.`); return; } // ======== STEP 1. Add sentry_flutter and sentry_dart_plugin to pubspec.yaml ============ clack.log.step(`Adding ${chalk_1.default.bold('Sentry')} to your apps ${chalk_1.default.cyan('pubspec.yaml')} file.`); const flutterVersion = await (0, release_registry_1.fetchSdkVersion)('sentry.dart.flutter'); const flutterVersionOrAny = flutterVersion ? `^${flutterVersion}` : 'any'; const pluginVersion = await (0, release_registry_1.fetchSdkVersion)('sentry.dart.plugin'); const pluginVersionOrAny = pluginVersion ? `^${pluginVersion}` : 'any'; const pubspecPatched = (0, telemetry_1.traceStep)('Patch pubspec.yaml', () => codetools.patchPubspec(pubspecFile, flutterVersionOrAny, pluginVersionOrAny, selectedProject.slug, selectedProject.organization.slug)); if (!pubspecPatched) { clack.log.warn(`Could not patch ${chalk_1.default.cyan('pubspec.yaml')}. Add the dependencies to it.`); await (0, clack_1.showCopyPasteInstructions)({ filename: 'pubspec.yaml', codeSnippet: (0, templates_1.pubspecSnippetColored)(flutterVersionOrAny, pluginVersionOrAny, selectedProject.slug, selectedProject.organization.slug), hint: 'This ensures the Sentry SDK and plugin can be imported.', }); } Sentry.setTag('pubspec-patched', pubspecPatched); // ======== STEP 2. Add sentry.properties with auth token ============ const propertiesAdded = (0, telemetry_1.traceStep)('Add sentry.properties', () => codetools.addProperties(pubspecFile, authToken)); if (!propertiesAdded) { clack.log.warn(`We could not add ${chalk_1.default.cyan('sentry.properties')} file in your project directory in order to provide an auth token for Sentry CLI. You'll have to add it manually, or you can set the SENTRY_AUTH_TOKEN environment variable instead. See https://docs.sentry.io/cli/configuration/#auth-token for more information.`); } else { clack.log.info(`Created a ${chalk_1.default.cyan('sentry.properties')} 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.`); } Sentry.setTag('sentry-properties-added', pubspecPatched); // ======== STEP 3. Patch main.dart with setup and a test error snippet ============ clack.log.step(`Next, the wizard will patch your ${chalk_1.default.cyan('main.dart')} file with the SDK init and a test error snippet.`); const mainFile = (0, code_tools_1.findFile)(`${projectDir}/lib`, 'main.dart'); const dsn = selectedProject.keys[0].dsn.public; const canEnableProfiling = fs.existsSync(`${projectDir}/ios`) || fs.existsSync(`${projectDir}/macos`); const mainPatched = await (0, telemetry_1.traceStep)('Patch main.dart', () => codetools.patchMain(mainFile, dsn, canEnableProfiling)); if (!mainPatched) { clack.log.warn(`Could not patch ${chalk_1.default.cyan('main.dart')} file. Place the following code snippet within the apps main function.`); await (0, clack_1.showCopyPasteInstructions)({ filename: 'main.dart', codeSnippet: (0, templates_1.initSnippetColored)(dsn), hint: 'This ensures the Sentry SDK is ready to capture errors.', }); } Sentry.setTag('main-patched', mainPatched); // ======== OUTRO ======== // Offer optional project-scoped MCP config for Sentry with org and project scope await (0, mcp_config_1.offerProjectScopedMcpConfig)(selectedProject.organization.slug, selectedProject.slug); const issuesPageLink = selfHosted ? `${sentryUrl}organizations/${selectedProject.organization.slug}/issues/?project=${selectedProject.id}` : `https://${selectedProject.organization.slug}.sentry.io/issues/?project=${selectedProject.id}`; clack.outro(` ${chalk_1.default.greenBright('Successfully installed the Sentry Flutter SDK!')} ${chalk_1.default.cyan('Next steps:')} 1. Run ${chalk_1.default.bold('flutter run')} to test the setup - we've added a test error that will trigger on app start 2. For production builds, run ${chalk_1.default.bold('flutter build apk --obfuscate --split-debug-info=build/debug-info')} (or ios/macos) then ${chalk_1.default.bold('flutter pub run sentry_dart_plugin')} to upload debug symbols 3. View your test error and transaction data at ${issuesPageLink} ${chalk_1.default.cyan('Learn more:')} - Debug Symbols: https://docs.sentry.io/platforms/dart/guides/flutter/debug-symbols/ - Performance Monitoring: https://docs.sentry.io/platforms/dart/guides/flutter/performance/ - Integrations: https://docs.sentry.io/platforms/dart/guides/flutter/integrations/ `); } //# sourceMappingURL=flutter-wizard.js.map