@sentry/wizard
Version:
Sentry wizard helping you to configure your project
104 lines (102 loc) • 5.25 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildOutroMessage = exports.runCloudflareWizard = void 0;
// @ts-expect-error - clack is ESM and TS complains about that. It works though
const prompts_1 = __importDefault(require("@clack/prompts"));
const chalk_1 = __importDefault(require("chalk"));
const telemetry_1 = require("../telemetry");
const clack_1 = require("../utils/clack");
const mcp_config_1 = require("../utils/clack/mcp-config");
const package_json_1 = require("../utils/package-json");
const sdk_setup_1 = require("./sdk-setup");
const abort_if_sportlight_not_supported_1 = require("../utils/abort-if-sportlight-not-supported");
const ensure_wrangler_config_1 = require("./wrangler/ensure-wrangler-config");
const update_wrangler_config_1 = require("./wrangler/update-wrangler-config");
const debug_1 = require("../utils/debug");
const get_entry_point_from_wrangler_config_1 = require("./wrangler/get-entry-point-from-wrangler-config");
async function runCloudflareWizard(options) {
return (0, telemetry_1.withTelemetry)({
enabled: options.telemetryEnabled,
integration: 'cloudflare',
wizardOptions: options,
}, () => runCloudflareWizardWithTelemetry(options));
}
exports.runCloudflareWizard = runCloudflareWizard;
async function runCloudflareWizardWithTelemetry(options) {
const { promoCode, telemetryEnabled, forceInstall } = options;
(0, clack_1.printWelcome)({
wizardName: 'Sentry Cloudflare 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, 'wrangler', 'Cloudflare');
(0, telemetry_1.traceStep)('Ensure Wrangler config', () => {
(0, ensure_wrangler_config_1.ensureWranglerConfig)();
});
const projectData = await (0, clack_1.getOrAskForProjectData)(options, 'node-cloudflare-workers');
if (projectData.spotlight) {
return (0, abort_if_sportlight_not_supported_1.abortIfSpotlightNotSupported)('Cloudflare');
}
const { selectedProject } = projectData;
await (0, clack_1.installPackage)({
packageName: '@sentry/cloudflare@^10',
packageNameDisplayLabel: '@sentry/cloudflare',
alreadyInstalled: (0, package_json_1.hasPackageInstalled)('@sentry/cloudflare', packageJson),
forceInstall,
});
const selectedFeatures = await (0, clack_1.featureSelectionPrompt)([
{
id: 'performance',
prompt: `Do you want to enable ${chalk_1.default.bold('Tracing')} to track the performance of your application?`,
enabledHint: 'recommended',
},
{
id: 'logs',
prompt: `Do you want to enable ${chalk_1.default.bold('Logs')} to send your application logs to Sentry?`,
enabledHint: 'recommended',
},
]);
await (0, telemetry_1.traceStep)('Create Sentry initialization', async () => {
try {
await (0, sdk_setup_1.createSentryInitFile)(selectedProject.keys[0].dsn.public, selectedFeatures);
}
catch (e) {
prompts_1.default.log.warn('Could not automatically set up Sentry initialization. Please set it up manually using instructions from https://docs.sentry.io/platforms/javascript/guides/cloudflare/');
(0, debug_1.debug)(e);
}
});
const mainFile = (0, get_entry_point_from_wrangler_config_1.getEntryPointFromWranglerConfig)();
await (0, telemetry_1.traceStep)('Update Wrangler config with Sentry requirements', () => (0, update_wrangler_config_1.updateWranglerConfig)({
...(mainFile ? {} : { main: get_entry_point_from_wrangler_config_1.defaultEntryPoint }),
compatibility_flags: ['nodejs_als'],
compatibility_date: new Date().toISOString().slice(0, 10),
version_metadata: {
binding: 'CF_VERSION_METADATA',
},
}));
await (0, clack_1.runPrettierIfInstalled)({ cwd: undefined });
// Offer optional project-scoped MCP config for Sentry with org and project scope
await (0, mcp_config_1.offerProjectScopedMcpConfig)(selectedProject.organization.slug, selectedProject.slug);
prompts_1.default.outro(buildOutroMessage());
}
function buildOutroMessage() {
return `
${chalk_1.default.green('Sentry has been successfully configured for your Cloudflare project.')}
${chalk_1.default.dim('Next steps:')}
${chalk_1.default.dim('1. Wrap your worker with Sentry as instructed above')}
${chalk_1.default.dim('2. Deploy your application with:')} ${chalk_1.default.cyan('wrangler deploy')}
${chalk_1.default.dim('3. Trigger an error to test Sentry integration')}
${chalk_1.default.cyan(`To learn more about using Sentry with Cloudflare, visit:
https://docs.sentry.io/platforms/javascript/guides/cloudflare/`)}
`;
}
exports.buildOutroMessage = buildOutroMessage;
//# sourceMappingURL=cloudflare-wizard.js.map