@sentry/wizard
Version:
Sentry wizard helping you to configure your project
139 lines (135 loc) • 5.84 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.checkIfMoreSuitableWizardExistsAndAskForRedirect = 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 sveltekit_wizard_1 = require("../../sveltekit/sveltekit-wizard");
const clack_1 = require("../../utils/clack");
const package_json_1 = require("../../utils/package-json");
const Sentry = __importStar(require("@sentry/node"));
const childProcess = __importStar(require("child_process"));
const sdkMap = {
'@sentry/sveltekit': {
frameworkName: 'SvelteKit',
frameworkPackage: '@sveltejs/kit',
sourcemapsDocsLink: 'https://docs.sentry.io/platforms/javascript/guides/sveltekit/manual-setup/#configure-source-maps-upload',
troubleshootingDocsLink: 'https://docs.sentry.io/platforms/javascript/guides/sveltekit/sourcemaps/troubleshooting_js/',
wizard: sveltekit_wizard_1.runSvelteKitWizard,
},
'@sentry/react-native': {
frameworkName: 'React Native',
frameworkPackage: 'react-native',
sourcemapsDocsLink: 'https://docs.sentry.io/platforms/react-native/sourcemaps/',
troubleshootingDocsLink: 'https://docs.sentry.io/platforms/react-native/troubleshooting/#source-maps',
wizard: runReactNativeWizard,
},
};
async function checkIfMoreSuitableWizardExistsAndAskForRedirect() {
const sdkName = await checkIfMoreSuitableWizardExists();
if (!sdkName) {
return undefined;
}
return await askForRedirect(sdkName);
}
exports.checkIfMoreSuitableWizardExistsAndAskForRedirect = checkIfMoreSuitableWizardExistsAndAskForRedirect;
async function checkIfMoreSuitableWizardExists() {
Sentry.setTag('using-wrong-wizard', false);
const packageJson = await (0, clack_1.getPackageDotJson)();
const installedSdkPackage = (0, package_json_1.findInstalledPackageFromList)(Object.keys(sdkMap), packageJson);
if (!installedSdkPackage) {
return undefined;
}
const sdkPackageName = installedSdkPackage.name;
const { frameworkPackage } = sdkMap[sdkPackageName];
if (!(0, package_json_1.hasPackageInstalled)(frameworkPackage, packageJson)) {
// The user has installed the SDK but not the framework.
// Maybe it's a false positive and the user is using a different framework.
// Let's not redirect them to the framework wizard in that case.
return undefined;
}
Sentry.setTag('using-wrong-wizard', true);
return sdkPackageName;
}
async function askForRedirect(sdkName) {
const { frameworkName, sourcemapsDocsLink, troubleshootingDocsLink, wizard } = sdkMap[sdkName];
prompts_1.default.log.warn(`${chalk_1.default.yellow(`It seems like you're using this wizard in a ${frameworkName} project.`)}
We recommend using our dedicated ${frameworkName} wizard instead of this wizard.
The ${frameworkName} wizard will set up our ${sdkName} SDK and also configure uploading source maps for you.
If you already tried the ${frameworkName} wizard and it didn't work for you, check out the following guides:
Manual source maps configuration for ${frameworkName}:
${sourcemapsDocsLink}
Troubleshooting Source Maps:
${troubleshootingDocsLink}
`);
const nextStep = await (0, clack_1.abortIfCancelled)(prompts_1.default.select({
message: `Do you want to run the ${frameworkName} wizard now?`,
options: [
{
label: 'Yes',
value: 'redirect',
hint: `${chalk_1.default.green('Recommended')}`,
},
{
label: 'No, continue with this wizard',
value: 'continue',
},
{
label: "No, I'll check out the guides ",
value: 'stop',
hint: 'Exit this wizard',
},
],
}));
Sentry.setTag('wrong-wizard-decision', nextStep);
switch (nextStep) {
case 'redirect':
return wizard;
case 'stop':
await (0, clack_1.abort)('Exiting Wizard', 0);
break;
default:
return undefined;
}
}
function runReactNativeWizard() {
const [runner, ...wizardArgs] = [...process.argv];
wizardArgs.push('--integration', 'reactNative');
try {
childProcess.spawnSync(runner, wizardArgs, {
cwd: process.cwd(),
stdio: 'inherit',
});
}
catch {
return Promise.reject();
}
return Promise.resolve();
}
//# sourceMappingURL=other-wizards.js.map
;