@sentry/wizard
Version:
Sentry wizard helping you to configure your project
110 lines (108 loc) • 6.94 kB
JavaScript
;
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 codetools = __importStar(require("./code-tools"));
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const clack_utils_1 = require("../utils/clack-utils");
const templates_1 = require("./templates");
const release_registry_1 = require("../utils/release-registry");
// @ts-ignore - 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_utils_2 = require("../utils/clack-utils");
const telemetry_1 = require("../telemetry");
const code_tools_1 = require("./code-tools");
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_utils_2.printWelcome)({
wizardName: 'Sentry Flutter Wizard',
promoCode: options.promoCode,
});
await (0, clack_utils_2.confirmContinueIfNoOrDirtyGitRepo)();
const { selectedProject, selfHosted, sentryUrl, authToken } = await (0, clack_utils_2.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_utils_1.showCopyPasteInstructions)('pubspec.yaml', (0, templates_1.pubspecSnippetColored)(flutterVersionOrAny, pluginVersionOrAny, selectedProject.slug, selectedProject.organization.slug), '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(`We created ${chalk_1.default.cyan('sentry.properties')} file in your project directory in order to provide an auth token for Sentry CLI.\nIt was also added to your ".gitignore" file.\nAt your CI enviroment, you can set the SENTRY_AUTH_TOKEN environment variable instead. 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(`Patching ${chalk_1.default.cyan('main.dart')} with setup and 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_utils_1.showCopyPasteInstructions)('main.dart', (0, templates_1.initSnippetColored)(dsn), 'This ensures the Sentry SDK is ready to capture errors.');
}
Sentry.setTag('main-patched', mainPatched);
// ======== OUTRO ========
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(`You can validate your setup by launching your application and checking Sentry issues page afterwards
${issuesPageLink}`)}
Check out the SDK documentation for further configuration:
https://docs.sentry.io/platforms/flutter/
`);
}
//# sourceMappingURL=flutter-wizard.js.map