|
| 1 | +const { ConfigPlugin, withDangerousMod, createRunOncePlugin } = require('@expo/config-plugins'); |
| 2 | +const fs = require('fs'); |
| 3 | +const path = require('path'); |
| 4 | + |
| 5 | +// Define package metadata |
| 6 | +const pkg = { name: '@journeyapps/react-native-quick-sqlite', version: 'UNVERSIONED' }; |
| 7 | + |
| 8 | +// Function to modify the Podfile |
| 9 | +function modifyPodfile(podfilePath: string) { |
| 10 | + let podfile = fs.readFileSync(podfilePath, 'utf8'); |
| 11 | + const preinstallScript = ` |
| 12 | +pre_install do |installer| |
| 13 | + installer.pod_targets.each do |pod| |
| 14 | + if pod.name.eql?('react-native-quick-sqlite') |
| 15 | + def pod.build_type |
| 16 | + Pod::BuildType.static_library |
| 17 | + end |
| 18 | + end |
| 19 | + end |
| 20 | +end |
| 21 | +`; |
| 22 | + // Ensure script is added only once |
| 23 | + if (!podfile.includes('react-native-quick-sqlite')) { |
| 24 | + podfile = podfile.replace(/target\s+'[^']+'\s+do/, `$&\n${preinstallScript}`); |
| 25 | + fs.writeFileSync(podfilePath, podfile, 'utf8'); |
| 26 | + console.log(`Added pre_install script for react-native-quick-sqlite to Podfile`); |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +// Config Plugin |
| 31 | +const withUseFrameworks = (config, options = { staticLibrary: false }) => { |
| 32 | + const { staticLibrary } = options; |
| 33 | + |
| 34 | + return withDangerousMod(config, [ |
| 35 | + 'ios', |
| 36 | + (config) => { |
| 37 | + if (!staticLibrary) { |
| 38 | + return config; |
| 39 | + } |
| 40 | + |
| 41 | + const podfilePath = path.join(config.modRequest.platformProjectRoot, 'Podfile'); |
| 42 | + if (fs.existsSync(podfilePath)) { |
| 43 | + modifyPodfile(podfilePath); |
| 44 | + } else { |
| 45 | + console.warn(`Podfile not found at ${podfilePath}`); |
| 46 | + } |
| 47 | + return config; |
| 48 | + } |
| 49 | + ]); |
| 50 | +}; |
| 51 | + |
| 52 | +const pluginWithOptions = (config, options) => { |
| 53 | + return withUseFrameworks(config, options); |
| 54 | +}; |
| 55 | + |
| 56 | +// Export the plugin with Expo's createRunOncePlugin |
| 57 | +module.exports = createRunOncePlugin(pluginWithOptions, pkg.name, pkg.version); |
0 commit comments