UNPKG

smartech-base-expo-plugin

Version:

Smartech Base Expo SDK's React Native Plugin For React Native Projects.

59 lines (58 loc) 2.56 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Helper = void 0; const iosConstants_1 = require("./iosConstants"); const fs_1 = require("fs"); const path_1 = __importDefault(require("path")); class Helper { static Ios = class { static addDeepLinkHandler(content, props) { const smartechContentLines = content.split("\n"); const lastLine = this.getLastLine(smartechContentLines); const deepLinkHandlerLines = (0, iosConstants_1.deepLinkHandlerSnippet)(props.deepLinkDelay); const smartechDelegateContents = [ ...smartechContentLines.slice(0, lastLine + 1), deepLinkHandlerLines, ...smartechContentLines.slice(lastLine + 1), ].join("\n"); return smartechDelegateContents; } ; static getLastLine = (lineArray) => { return lineArray.lastIndexOf("@end") - 1; }; // Utility function to detect if project uses Swift static isSwiftProject = async (platformProjectRoot, projectName) => { try { const appDelegateSwiftPath = path_1.default.join(platformProjectRoot, projectName, 'AppDelegate.swift'); await fs_1.promises.access(appDelegateSwiftPath); return true; } catch { return false; } }; // Utility function to get the correct AppDelegate file path for Objective-C projects static getObjCAppDelegatePath = async (platformProjectRoot, projectName) => { const appDelegateMmPath = path_1.default.join(platformProjectRoot, projectName, 'AppDelegate.mm'); const appDelegateMPath = path_1.default.join(platformProjectRoot, projectName, 'AppDelegate.m'); try { await fs_1.promises.access(appDelegateMmPath); return appDelegateMmPath; } catch { return appDelegateMPath; // Fallback to .m even if it doesn't exist } }; }; static Android = class { static addDependency(appContents, dependency, version) { const dependencyTemplate = `api "${dependency}:${version}"`; return appContents.replace('dependencies {', `dependencies {\n ${dependencyTemplate}`); } }; } exports.Helper = Helper;