@sentry/wizard
Version:
Sentry wizard helping you to configure your project
142 lines (139 loc) • 5.91 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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Electron = void 0;
const fs = __importStar(require("node:fs"));
const inquirer_1 = require("inquirer");
const path = __importStar(require("node:path"));
const Logging_1 = require("../../Helper/Logging");
const SentryCli_1 = require("../../Helper/SentryCli");
const BaseIntegration_1 = require("./BaseIntegration");
const MIN_ELECTRON_VERSION_STRING = '23.0.0';
const MIN_ELECTRON_VERSION = parseInt(MIN_ELECTRON_VERSION_STRING.replace(/\D+/g, ''), 10);
const CODE_EXAMPLE_MAIN = `// ESM
import * as Sentry from '@sentry/electron/main';
// CommonJs
const Sentry = require('@sentry/electron/main');
Sentry.init({
dsn: '___DSN___',
// Enable sending user PII (Personally Identifiable Information)
// https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#sendDefaultPii
sendDefaultPii: true,
});`;
const CODE_EXAMPLE_RENDERER = `// ESM
import * as Sentry from '@sentry/electron/renderer';
// CommonJs
const Sentry = require('@sentry/electron/renderer');
Sentry.init({});`;
let appPackage = {};
function printExample(example, title = '') {
if (title) {
(0, Logging_1.l)(title);
}
(0, Logging_1.nl)();
(0, Logging_1.dim)(example.replace(/^/gm, ' '));
(0, Logging_1.nl)();
}
try {
appPackage = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'package.json'), 'utf-8'));
}
catch {
// We don't need to have this
}
class Electron extends BaseIntegration_1.BaseIntegration {
_argv;
_sentryCli;
constructor(_argv) {
super(_argv);
this._argv = _argv;
this._sentryCli = new SentryCli_1.SentryCli(this._argv);
}
// eslint-disable-next-line @typescript-eslint/require-await
async emit(answers) {
const dsn = answers.config?.dsn?.public ?? 'DSN NOT FOUND';
(0, Logging_1.nl)();
const sentryCliProps = this._sentryCli.convertAnswersToProperties(answers);
fs.writeFileSync('./sentry.properties', this._sentryCli.dumpProperties(sentryCliProps));
(0, Logging_1.green)('Successfully created sentry.properties');
(0, Logging_1.nl)();
printExample(CODE_EXAMPLE_MAIN.replace('___DSN___', dsn), 'Add these lines in to your main process code to setup Sentry:');
printExample(CODE_EXAMPLE_RENDERER, 'Add these lines in to your renderer processes code to setup Sentry:');
(0, Logging_1.l)('For more information, see https://docs.sentry.io/clients/electron/');
(0, Logging_1.nl)();
return {};
}
async shouldConfigure(_answers) {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
if (this._shouldConfigure) {
return this._shouldConfigure;
}
let success = true;
(0, Logging_1.nl)();
success =
this._checkDep('electron', MIN_ELECTRON_VERSION_STRING) && success;
success = this._checkDep('@sentry/electron') && success;
let continued = { continue: true };
if (!success && !this._argv.quiet) {
continued = await (0, inquirer_1.prompt)({
message: 'There were errors during your project checkup, do you still want to continue?',
name: 'continue',
default: false,
type: 'confirm',
});
}
(0, Logging_1.nl)();
if (!continued?.continue) {
throw new Error('Please install the required dependencies to continue.');
}
this._shouldConfigure = Promise.resolve({ electron: true });
// eslint-disable-next-line @typescript-eslint/unbound-method
return this.shouldConfigure;
}
_checkDep(packageName, minVersion) {
const depVersion = parseInt((appPackage.dependencies?.[packageName] || '0').replace(/\D+/g, ''), 10);
const devDepVersion = parseInt((appPackage.devDependencies?.[packageName] || '0').replace(/\D+/g, ''), 10);
if (!appPackage.dependencies?.[packageName] &&
!appPackage.devDependencies?.[packageName]) {
(0, Logging_1.red)(`✗ ${packageName} isn't in your dependencies`);
(0, Logging_1.red)(' please install it with yarn/npm');
return false;
}
if (minVersion &&
depVersion < MIN_ELECTRON_VERSION &&
devDepVersion < MIN_ELECTRON_VERSION) {
(0, Logging_1.red)(`✗ Your installed version of ${packageName} is to old, >${MIN_ELECTRON_VERSION_STRING} needed`);
return false;
}
if (minVersion) {
(0, Logging_1.green)(`✓ ${packageName} > ${minVersion} is installed`);
}
else {
(0, Logging_1.green)(`✓ ${packageName} is installed`);
}
return true;
}
}
exports.Electron = Electron;
//# sourceMappingURL=Electron.js.map