-
-
Notifications
You must be signed in to change notification settings - Fork 360
Expand file tree
/
Copy pathutils.ts
More file actions
33 lines (26 loc) · 1.24 KB
/
utils.ts
File metadata and controls
33 lines (26 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// tsgolint incorrectly types `fs` as `error` — false positive with DANGEROUSLY_SUPPRESS_PROGRAM_DIAGNOSTICS
/* oxlint-disable typescript-eslint(no-unsafe-member-access) */
import * as fs from 'fs';
import * as path from 'path';
import { warnOnce } from './logger';
export function writeSentryPropertiesTo(filepath: string, sentryProperties: string): void {
if (!fs.existsSync(filepath)) {
throw new Error(`Directory '${filepath}' does not exist.`);
}
fs.writeFileSync(path.resolve(filepath, 'sentry.properties'), sentryProperties);
}
const SENTRY_OPTIONS_FILE_NAME = 'sentry.options.json';
export function writeSentryOptions(projectRoot: string, pluginOptions: Record<string, unknown>): void {
const optionsFilePath = path.resolve(projectRoot, SENTRY_OPTIONS_FILE_NAME);
let existingOptions: Record<string, unknown> = {};
if (fs.existsSync(optionsFilePath)) {
try {
existingOptions = JSON.parse(fs.readFileSync(optionsFilePath, 'utf8'));
} catch (e) {
warnOnce(`Failed to parse ${SENTRY_OPTIONS_FILE_NAME}: ${e}. These options will not be set.`);
return;
}
}
const mergedOptions = { ...existingOptions, ...pluginOptions };
fs.writeFileSync(optionsFilePath, `${JSON.stringify(mergedOptions, null, 2)}\n`);
}