UNPKG

@sentry/wizard

Version:

Sentry wizard helping you to configure your project

86 lines 3.85 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.podInstall = exports.addCocoaPods = exports.usesCocoaPod = void 0; const fs = __importStar(require("fs")); const path = __importStar(require("path")); const bash = __importStar(require("../utils/bash")); const Sentry = __importStar(require("@sentry/node")); // @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")); function usesCocoaPod(projPath) { return fs.existsSync(path.join(projPath, 'Podfile')); } exports.usesCocoaPod = usesCocoaPod; async function addCocoaPods(projPath) { const podfile = path.join(projPath, 'Podfile'); const podContent = fs.readFileSync(podfile, 'utf8'); if (/^\s*pod\s+(['"]Sentry['"]|['"]SentrySwiftUI['"])\s*$/im.test(podContent)) { // Already have Sentry pod return true; } let podMatch = /^( *)pod\s+['"](\w+)['"] *$/im.exec(podContent); if (!podMatch) { // No Podfile is empty, will try to add Sentry pod after "use_frameworks!" const frameworkMatch = /^( *)use_frameworks![^\n]* *$/im.exec(podContent); if (!frameworkMatch) { return false; } podMatch = frameworkMatch; } const insertIndex = podMatch.index + podMatch[0].length; const newFileContent = podContent.slice(0, insertIndex) + '\n' + podMatch[1] + "pod 'Sentry'\n" + podContent.slice(insertIndex); fs.writeFileSync(podfile, newFileContent, 'utf8'); clack.log.step('Sentry pod added to the project podFile.'); await podInstall(); return true; } exports.addCocoaPods = addCocoaPods; async function podInstall(dir = '.') { const installSpinner = clack.spinner(); installSpinner.start("Running 'pod install'. This may take a few minutes..."); try { await bash.execute(`cd ${dir} && pod repo update`); await bash.execute(`cd ${dir} && pod install --silent`); installSpinner.stop('Pods installed.'); Sentry.setTag('pods-installed', true); } catch (e) { installSpinner.stop('Failed to install pods.'); Sentry.setTag('pods-installed', false); clack.log.error(`${chalk_1.default.red('Encountered the following error during pods installation:')}\n\n${e}\n\n${chalk_1.default.dim('If you think this issue is caused by the Sentry wizard, let us know here:\nhttps://github.com/getsentry/sentry-wizard/issues')}`); Sentry.captureException('Sentry pod install failed.'); } } exports.podInstall = podInstall; //# sourceMappingURL=cocoapod.js.map