@sentry/wizard
Version:
Sentry wizard helping you to configure your project
110 lines • 5.5 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.createExampleComponent = exports.createExamplePage = exports.supportsExamplePage = void 0;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
// @ts-expect-error - clack is ESM and TS complains about that. It works though
const prompts_1 = __importDefault(require("@clack/prompts"));
const templates_1 = require("./templates");
const clack_1 = require("../utils/clack");
const chalk_1 = __importDefault(require("chalk"));
const Sentry = __importStar(require("@sentry/node"));
function getSrcDirectory(isNuxtV4) {
// In nuxt v4, the src directory is `app/` unless
// users already had a `pages` directory
return isNuxtV4 && !fs.existsSync(path.resolve('pages')) ? 'app' : '.';
}
async function supportsExamplePage(isNuxtV4) {
// We currently only support creating an example page
// if users can reliably access it without having to
// add code changes themselves.
//
// If users have an `app.vue` layout without the
// needed component to render routes (<NuxtPage/>),
// we bail out of creating an example page altogether.
const src = getSrcDirectory(isNuxtV4);
const app = path.join(src, 'app.vue');
// If there's no `app.vue` layout, nuxt automatically renders
// the routes.
if (!fs.existsSync(path.resolve(app))) {
return true;
}
const content = await fs.promises.readFile(path.resolve(app), 'utf8');
return !!content.match(/<NuxtPage/g);
}
exports.supportsExamplePage = supportsExamplePage;
async function createExamplePage(isNuxtV4, options) {
try {
const src = getSrcDirectory(isNuxtV4);
const pages = path.join(src, 'pages');
if (!fs.existsSync(path.resolve(pages))) {
fs.mkdirSync(path.resolve(pages), { recursive: true });
const indexPage = path.join(pages, 'index.vue');
await fs.promises.writeFile(path.resolve(indexPage), (0, templates_1.getIndexRouteTemplate)());
prompts_1.default.log.success(`Created ${chalk_1.default.cyan(indexPage)}.`);
}
const examplePage = path.join(pages, 'sentry-example-page.vue');
if (fs.existsSync(path.resolve(examplePage))) {
prompts_1.default.log.warn(`It seems like a sentry example page already exists. Skipping creation of example page.`);
return;
}
await fs.promises.writeFile(path.resolve(examplePage), (0, templates_1.getSentryExamplePageTemplate)(options));
prompts_1.default.log.success(`Created ${chalk_1.default.cyan(examplePage)}.`);
const api = path.join('server', 'api');
if (!fs.existsSync(path.resolve(api))) {
fs.mkdirSync(path.resolve(api), { recursive: true });
}
const exampleApi = path.join(api, (0, clack_1.isUsingTypeScript)() ? 'sentry-example-api.ts' : 'sentry-example-api.js');
await fs.promises.writeFile(path.resolve(exampleApi), (0, templates_1.getSentryExampleApiTemplate)());
prompts_1.default.log.success(`Created ${chalk_1.default.cyan(exampleApi)}.`);
}
catch (e) {
prompts_1.default.log.error('Error while creating an example page to test Sentry:');
prompts_1.default.log.info(chalk_1.default.dim(typeof e === 'object' && e != null && 'toString' in e
? e.toString()
: typeof e === 'string'
? e
: 'Unknown error'));
Sentry.captureException('Error while creating an example Nuxt page to test Sentry');
await (0, clack_1.abort)('Exiting Wizard');
}
}
exports.createExamplePage = createExamplePage;
async function createExampleComponent(isNuxtV4) {
const src = getSrcDirectory(isNuxtV4);
const components = path.join(src, 'components');
if (!fs.existsSync(path.resolve(components))) {
fs.mkdirSync(path.resolve(components), { recursive: true });
}
const exampleComponent = path.join(components, 'SentryErrorButton.vue');
await fs.promises.writeFile(path.resolve(exampleComponent), (0, templates_1.getSentryErrorButtonTemplate)());
prompts_1.default.log.success(`Created ${chalk_1.default.cyan(exampleComponent)}.`);
}
exports.createExampleComponent = createExampleComponent;
//# sourceMappingURL=sdk-example.js.map
;