UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

142 lines 7.03 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.runNuxtWizardWithTelemetry = exports.runNuxtWizard = void 0; // @ts-expect-error - clack is ESM and TS complains about that. It works though const clack = __importStar(require("@clack/prompts")); const Sentry = __importStar(require("@sentry/node")); const chalk_1 = __importDefault(require("chalk")); const semver_1 = require("semver"); const telemetry_1 = require("../telemetry"); const clack_1 = require("../utils/clack"); const package_json_1 = require("../utils/package-json"); const sdk_example_1 = require("./sdk-example"); const sdk_setup_1 = require("./sdk-setup"); const utils_1 = require("./utils"); function runNuxtWizard(options) { return (0, telemetry_1.withTelemetry)({ enabled: options.telemetryEnabled, integration: 'nuxt', wizardOptions: options, }, () => runNuxtWizardWithTelemetry(options)); } exports.runNuxtWizard = runNuxtWizard; async function runNuxtWizardWithTelemetry(options) { const { promoCode, telemetryEnabled, forceInstall } = options; (0, clack_1.printWelcome)({ wizardName: 'Sentry Nuxt Wizard', promoCode, telemetryEnabled, }); await (0, clack_1.confirmContinueIfNoOrDirtyGitRepo)({ ignoreGitChanges: options.ignoreGitChanges, cwd: undefined, }); const packageJson = await (0, clack_1.getPackageDotJson)(); await (0, clack_1.ensurePackageIsInstalled)(packageJson, 'nuxt', 'Nuxt'); const nuxtVersion = (0, package_json_1.getPackageVersion)('nuxt', packageJson); Sentry.setTag('nuxt-version', nuxtVersion); const minVer = (0, semver_1.minVersion)(nuxtVersion || '0.0.0'); if (!nuxtVersion || !minVer || (0, semver_1.lt)(minVer, '3.7.0')) { clack.log.warn("It seems you're using a Nuxt version <3.7.0 which is not supported by Sentry.\nWe recommend upgrading to the latest version before you continue."); const shouldContinue = await (0, clack_1.abortIfCancelled)(clack.select({ message: 'Do you want to continue anyway?', options: [ { label: 'Yes, continue', hint: 'The SDK might not work correctly', value: true, }, { label: "No, I'll upgrade first", value: false }, ], })); if (!shouldContinue) { await (0, clack_1.abort)('Exiting Wizard', 0); return; } } const { authToken, selectedProject, selfHosted, sentryUrl } = await (0, clack_1.getOrAskForProjectData)(options, 'javascript-nuxt'); const packageManager = await (0, clack_1.getPackageManager)(); await (0, sdk_setup_1.addNuxtOverrides)(packageJson, packageManager, minVer, forceInstall); const sdkAlreadyInstalled = (0, package_json_1.hasPackageInstalled)('@sentry/nuxt', packageJson); Sentry.setTag('sdk-already-installed', sdkAlreadyInstalled); await (0, clack_1.installPackage)({ packageName: '@sentry/nuxt@^10', alreadyInstalled: sdkAlreadyInstalled, packageManager, forceInstall, }); await (0, clack_1.addDotEnvSentryBuildPluginFile)(authToken); const nuxtConfig = await (0, telemetry_1.traceStep)('load-nuxt-config', sdk_setup_1.getNuxtConfig); const projectData = { org: selectedProject.organization.slug, project: selectedProject.slug, projectId: selectedProject.id, url: sentryUrl, selfHosted, }; const deploymentPlatform = await (0, sdk_setup_1.askDeploymentPlatform)(); Sentry.setTag('deployment-platform', deploymentPlatform); await (0, telemetry_1.traceStep)('configure-sdk', async () => { await (0, sdk_setup_1.addSDKModule)(nuxtConfig, projectData, deploymentPlatform); await (0, sdk_setup_1.createConfigFiles)(selectedProject.keys[0].dsn.public); }); let shouldCreateExamplePage = false; let shouldCreateExampleButton = false; const isV4 = await (0, utils_1.isNuxtV4)(nuxtConfig, nuxtVersion); const canCreateExamplePage = await (0, sdk_example_1.supportsExamplePage)(isV4); Sentry.setTag('supports-example-page-creation', canCreateExamplePage); if (canCreateExamplePage) { shouldCreateExamplePage = await (0, clack_1.askShouldCreateExamplePage)(); if (shouldCreateExamplePage) { await (0, telemetry_1.traceStep)('create-example-page', async () => (0, sdk_example_1.createExamplePage)(isV4, projectData)); } } else { shouldCreateExampleButton = await (0, clack_1.askShouldCreateExampleComponent)(); if (shouldCreateExampleButton) { await (0, telemetry_1.traceStep)('create-example-component', async () => (0, sdk_example_1.createExampleComponent)(isV4)); } } await (0, clack_1.runPrettierIfInstalled)({ cwd: undefined }); await (0, sdk_setup_1.confirmReadImportDocs)(deploymentPlatform); clack.outro(buildOutroMessage(shouldCreateExamplePage, shouldCreateExampleButton)); } exports.runNuxtWizardWithTelemetry = runNuxtWizardWithTelemetry; function buildOutroMessage(shouldCreateExamplePage, shouldCreateExampleButton) { let msg = chalk_1.default.green('\nSuccessfully installed the Sentry Nuxt SDK!'); if (shouldCreateExamplePage) { msg += `\n\nYou can validate your setup by visiting ${chalk_1.default.cyan('"/sentry-example-page"')}.`; } if (shouldCreateExampleButton) { msg += `\n\nYou can validate your setup by adding the ${chalk_1.default.cyan('`SentryExampleButton`')} component to a page and triggering it.`; } msg += `\n\nCheck out the SDK documentation for further configuration: ${chalk_1.default.underline('https://docs.sentry.io/platforms/javascript/guides/nuxt/')}`; return msg; } //# sourceMappingURL=nuxt-wizard.js.map