@sentry/wizard
Version:
Sentry wizard helping you to configure your project
92 lines • 3.48 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.SentryCli = void 0;
const path = __importStar(require("node:path"));
class SentryCli {
_argv;
_resolve = require.resolve;
constructor(_argv) {
this._argv = _argv;
}
setResolveFunction(resolve) {
this._resolve = resolve;
}
convertAnswersToProperties(answers) {
const props = {
'defaults/url': this._argv.url,
'defaults/org': answers.config?.organization?.slug ?? null,
'defaults/project': answers.config?.project?.slug ?? null,
'auth/token': answers.config?.auth?.token ?? null,
};
try {
const cliPath = this._resolve('@sentry/cli/bin/sentry-cli', {
paths: [process.cwd()],
});
props['cli/executable'] = path
.relative(process.cwd(), cliPath)
.replace(/\\/g, '\\\\');
}
catch (e) {
// we do nothing and leave everything as it is
}
return props;
}
/**
* Create the contents of a `sentry.properties` file
* @param props the properties to write to the file
* @param format the format of the file, either `rc`
* (.sentryclirc) or `properties` (sentry.properties)
*/
dumpProperties(props, format = 'properties') {
const propEntries = Object.entries(props);
const rv = [];
for (const [key, value] of propEntries) {
const normalizedKey = format === 'properties'
? key.replace(/\//g, '.')
: key.split('/').at(1) ?? '';
if (value === undefined || value === null) {
// comment that property out since it has no value
rv.push(`#${normalizedKey}=`);
}
else {
rv.push(`${normalizedKey}=${value}`);
}
}
// eslint-disable-next-line prefer-template
return rv.join('\n') + '\n';
}
dumpConfig(config) {
const dumpedSections = [];
for (const [sectionName, values] of Object.entries(config)) {
const props = values ? this.dumpProperties(values, 'rc') : '';
const section = `[${sectionName}]\n${props}`;
dumpedSections.push(section);
}
return dumpedSections.join('\n');
}
}
exports.SentryCli = SentryCli;
//# sourceMappingURL=SentryCli.js.map