UNPKG

react-native-integrate

Version:

Automate integration of additional code into React Native projects

86 lines (85 loc) 3.19 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.summary = void 0; exports.gradlePropertiesTask = gradlePropertiesTask; exports.runTask = runTask; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const constants_1 = require("../constants"); const applyContentModification_1 = require("../utils/applyContentModification"); const checkCondition_1 = require("../utils/checkCondition"); const getErrMessage_1 = require("../utils/getErrMessage"); const getProjectPath_1 = require("../utils/getProjectPath"); const setState_1 = require("../utils/setState"); const variables_1 = require("../variables"); async function gradlePropertiesTask(args) { let { content } = args; const { task, configPath, packageName } = args; for (const action of task.actions) { variables_1.variables.set('CONTENT', content); if (action.when && !(0, checkCondition_1.checkCondition)(action.when)) { (0, setState_1.setState)(action.name, { state: 'skipped', reason: 'when', }); continue; } (0, setState_1.setState)(action.name, { state: 'progress', }); try { content = await (0, applyContentModification_1.applyContentModification)({ action, findOrCreateBlock, configPath, packageName, content, indentation: 0, buildComment: buildGradlePropertiesComment, }); (0, setState_1.setState)(action.name, { state: 'done', }); } catch (e) { (0, setState_1.setState)(action.name, { state: 'error', reason: (0, getErrMessage_1.getErrMessage)(e), }); throw e; } } return content; } function findOrCreateBlock() { throw new Error('block is not supported in gradleProperties'); } function buildGradlePropertiesComment(comment) { return comment.split('\n').map(x => `# ${x}`); } function getGradlePropertiesPath() { const projectPath = (0, getProjectPath_1.getProjectPath)(); return path_1.default.join(projectPath, 'android', constants_1.Constants.GRADLE_PROPERTIES_FILE_NAME); } function readGradlePropertiesContent() { const gradlePropertiesPath = getGradlePropertiesPath(); if (!fs_1.default.existsSync(gradlePropertiesPath)) return ''; return fs_1.default.readFileSync(gradlePropertiesPath, 'utf-8'); } function writeGradlePropertiesContent(content) { const gradlePropertiesPath = getGradlePropertiesPath(); return fs_1.default.writeFileSync(gradlePropertiesPath, content, 'utf-8'); } async function runTask(args) { let content = readGradlePropertiesContent(); content = await gradlePropertiesTask({ ...args, content, }); writeGradlePropertiesContent(content); } exports.summary = 'gradle.properties modification';