UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

79 lines 3.72 kB
"use strict"; 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.addExpoEnvLocal = void 0; // @ts-expect-error - clack is ESM and TS complains about that. It works though const clack = __importStar(require("@clack/prompts")); const chalk_1 = __importDefault(require("chalk")); const fs_1 = __importDefault(require("fs")); const Sentry = __importStar(require("@sentry/node")); const git_1 = require("./git"); const EXPO_ENV_LOCAL_FILE = '.env.local'; async function addExpoEnvLocal(options) { const newContent = `#DO NOT COMMIT THIS\nSENTRY_AUTH_TOKEN=${options.authToken}\n`; const added = await (0, git_1.addToGitignore)(EXPO_ENV_LOCAL_FILE); if (added) { Sentry.setTag('expo-env-local', 'added-to-gitignore'); clack.log.success(`Added ${chalk_1.default.cyan(EXPO_ENV_LOCAL_FILE)} to .gitignore.`); } else { Sentry.setTag('expo-env-local', 'add-to-gitignore-error'); clack.log.error(`Could not add ${chalk_1.default.cyan(EXPO_ENV_LOCAL_FILE)} to .gitignore, please add it to not commit your auth key.`); Sentry.captureException(`Could not add ${EXPO_ENV_LOCAL_FILE} to .gitignore`); } if (!fs_1.default.existsSync(EXPO_ENV_LOCAL_FILE)) { try { await fs_1.default.promises.writeFile(EXPO_ENV_LOCAL_FILE, newContent); Sentry.setTag('expo-env-local', 'written'); clack.log.success(`Written ${chalk_1.default.cyan(EXPO_ENV_LOCAL_FILE)}.`); return true; } catch (error) { Sentry.setTag('expo-env-local', 'write-error'); clack.log.error(`Unable to write ${chalk_1.default.cyan(EXPO_ENV_LOCAL_FILE)}.`); Sentry.captureException(`Unable to write ${EXPO_ENV_LOCAL_FILE}.`); return false; } } Sentry.setTag('expo-env-local', 'exists'); clack.log.info(`Updating existing ${chalk_1.default.cyan(EXPO_ENV_LOCAL_FILE)}.`); try { await fs_1.default.promises.appendFile(EXPO_ENV_LOCAL_FILE, newContent); Sentry.setTag('expo-env-local', 'updated'); clack.log.success(`Updated ${chalk_1.default.cyan(EXPO_ENV_LOCAL_FILE)}.`); return true; } catch (error) { Sentry.setTag('expo-env-local', 'update-error'); clack.log.error(`Unable to update ${chalk_1.default.cyan(EXPO_ENV_LOCAL_FILE)}.`); Sentry.captureException(`Unable to update ${EXPO_ENV_LOCAL_FILE}.`); return false; } } exports.addExpoEnvLocal = addExpoEnvLocal; //# sourceMappingURL=expo-env-file.js.map