UNPKG

react-native-integrate

Version:

Automate integration of additional code into React Native projects

46 lines (45 loc) 2.47 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.importAndroidAppId = importAndroidAppId; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const picocolors_1 = __importDefault(require("picocolors")); const prompter_1 = require("../../../prompter"); const escapeRegExp_1 = require("../../escapeRegExp"); const getProjectPath_1 = require("../../getProjectPath"); const searchReplaceAllFiles_1 = require("../../searchReplaceAllFiles"); function importAndroidAppId(projectPath) { try { const buildGradlePath = path_1.default.join(projectPath, 'android/app/build.gradle'); const buildGradle = fs_1.default.readFileSync(buildGradlePath, 'utf8'); const appIdMatch = buildGradle.match(/applicationId "(.*)"/); const appId = appIdMatch?.[1]; const currentBuildGradlePath = path_1.default.join((0, getProjectPath_1.getProjectPath)(), 'android/app/build.gradle'); const currentBuildGradle = fs_1.default.readFileSync(currentBuildGradlePath, 'utf8'); const currentAppIdMatch = currentBuildGradle.match(/applicationId "(.*)"/); const currentAppId = currentAppIdMatch?.[1]; if (!appId || !currentAppId) return null; return { id: 'androidAppId', title: 'Android App Id', value: appId, apply: () => setAndroidAppId(currentAppId, appId), }; } catch (_e) { return null; } } async function setAndroidAppId(currentAppId, newAppId) { if (currentAppId == newAppId) { (0, prompter_1.logMessageGray)(`android app id is already set to ${picocolors_1.default.yellow(newAppId)}`); return; } (0, prompter_1.startSpinner)(`changing android app id in all files from ${picocolors_1.default.yellow(currentAppId)} to ${picocolors_1.default.yellow(newAppId)}`); const changes = await (0, searchReplaceAllFiles_1.searchReplaceAllFiles)(path_1.default.join((0, getProjectPath_1.getProjectPath)(), 'android'), (0, escapeRegExp_1.escapeRegExp)(currentAppId), newAppId, false); (0, prompter_1.stopSpinner)(`changed android app id in ${picocolors_1.default.yellow(changes)} files from ${picocolors_1.default.yellow(currentAppId)} to ${picocolors_1.default.yellow(newAppId)}`); }