react-native-video/src/expo-plugins/writeToPodfile.ts
Krzysztof Moch 08f6caa645
feat: add expo plugins (#3933)
* feat: add expo plugins

* add export

* fix import

* fix bugs

* build `lib` to `CommonJS`

* restore `build.gradle`

* remove plugin tmp

* add expo plugin for ios caching

* add docs for expo plugin

* fix expo plugin export

* fix docs
2024-07-10 11:49:13 +02:00

28 lines
756 B
TypeScript

import fs from 'fs';
import path from 'path';
import {mergeContents} from '@expo/config-plugins/build/utils/generateCode';
export const writeToPodfile = (
projectRoot: string,
key: string,
value: string,
) => {
const podfilePath = path.join(projectRoot, 'ios', 'Podfile');
const podfileContent = fs.readFileSync(podfilePath, 'utf8');
const newPodfileContent = mergeContents({
tag: `rn-video-set-${key.toLowerCase()}`,
src: podfileContent,
newSrc: `$${key} = ${value}`,
anchor: /platform :ios/,
offset: 0,
comment: '#',
});
if (newPodfileContent.didMerge) {
fs.writeFileSync(podfilePath, newPodfileContent.contents);
} else {
console.warn(`RNV - Failed to write "$${key} = ${value}" to Podfile`);
}
};