|
10 | 10 |
|
11 | 11 | const {librariesMappings, reactMappings} = require('./headers-mappings'); |
12 | 12 | const { |
| 13 | + symlinkCodegenHeaders, |
13 | 14 | symlinkHeadersFromPath, |
14 | 15 | symlinkReactAppleHeaders, |
15 | 16 | symlinkReactCommonHeaders, |
| 17 | + symlinkThirdPartyDependenciesHeaders, |
16 | 18 | } = require('./headers-utils'); |
17 | 19 | const fs = require('fs'); |
18 | 20 | const path = require('path'); |
19 | 21 |
|
| 22 | +/*:: |
| 23 | +type RequiredHeaders = 'react-native' | 'codegen' | 'third-party-dependencies' | 'all'; |
| 24 | +*/ |
| 25 | + |
| 26 | +/** |
| 27 | + * Prepares app dependencies headers for SwiftPM integration |
| 28 | + * @param {string} reactNativePath - Path to the React Native directory |
| 29 | + * @param {string} iosAppPath - Path to the iOS app directory |
| 30 | + * @param {string} outputFolder - Path to the output folder where headers will be hard linked |
| 31 | + * @param {string} requiredHeaders - Type of headers to include: 'react-native', 'codegen', 'third-party-dependencies', or 'all' |
| 32 | + */ |
| 33 | +function prepareAppDependenciesHeaders( |
| 34 | + reactNativePath /*: string */, |
| 35 | + iosAppPath /*: string */, |
| 36 | + outputFolder /*: string */, |
| 37 | + requiredHeaders /*: RequiredHeaders */, |
| 38 | +) /*: void */ { |
| 39 | + // Validate parameters |
| 40 | + if (!reactNativePath || !iosAppPath || !outputFolder || !requiredHeaders) { |
| 41 | + throw new Error( |
| 42 | + 'Missing required parameters. Usage: prepareAppDependenciesHeaders(reactNativePath, iosAppPath, outputFolder, requiredHeaders)', |
| 43 | + ); |
| 44 | + } |
| 45 | + |
| 46 | + if ( |
| 47 | + !['react-native', 'codegen', 'third-party-dependencies', 'all'].includes( |
| 48 | + requiredHeaders, |
| 49 | + ) |
| 50 | + ) { |
| 51 | + throw new Error( |
| 52 | + "requiredHeaders must be one of: 'react-native', 'codegen', 'third-party-dependencies', 'all'", |
| 53 | + ); |
| 54 | + } |
| 55 | + |
| 56 | + // Validate paths exist |
| 57 | + if (!fs.existsSync(reactNativePath)) { |
| 58 | + throw new Error(`React Native path does not exist: ${reactNativePath}`); |
| 59 | + } |
| 60 | + |
| 61 | + if (!fs.existsSync(iosAppPath)) { |
| 62 | + throw new Error(`iOS app path does not exist: ${iosAppPath}`); |
| 63 | + } |
| 64 | + |
| 65 | + // Create output folder if it doesn't exist |
| 66 | + if (!fs.existsSync(outputFolder)) { |
| 67 | + fs.mkdirSync(outputFolder, {recursive: true}); |
| 68 | + console.log(`Created output folder: ${outputFolder}`); |
| 69 | + } |
| 70 | + |
| 71 | + console.log('Preparing app dependencies headers...'); |
| 72 | + console.log(`React Native path: ${reactNativePath}`); |
| 73 | + console.log(`iOS app path: ${iosAppPath}`); |
| 74 | + console.log(`Output folder: ${outputFolder}`); |
| 75 | + console.log(`Required headers: ${requiredHeaders}`); |
| 76 | + |
| 77 | + try { |
| 78 | + switch (requiredHeaders) { |
| 79 | + case 'react-native': |
| 80 | + symlinkReactNativeHeaders(reactNativePath, outputFolder); |
| 81 | + break; |
| 82 | + case 'codegen': |
| 83 | + symlinkCodegenHeaders(reactNativePath, iosAppPath, outputFolder); |
| 84 | + break; |
| 85 | + case 'third-party-dependencies': |
| 86 | + symlinkThirdPartyDependenciesHeaders(reactNativePath, outputFolder); |
| 87 | + break; |
| 88 | + case 'all': |
| 89 | + symlinkReactNativeHeaders(reactNativePath, outputFolder); |
| 90 | + symlinkCodegenHeaders(reactNativePath, iosAppPath, outputFolder); |
| 91 | + symlinkThirdPartyDependenciesHeaders(reactNativePath, outputFolder); |
| 92 | + break; |
| 93 | + default: |
| 94 | + throw new Error( |
| 95 | + `Unsupported requiredHeaders value: ${requiredHeaders}`, |
| 96 | + ); |
| 97 | + } |
| 98 | + |
| 99 | + console.log('Successfully prepared app dependencies headers'); |
| 100 | + } catch (error) { |
| 101 | + console.error('Error preparing app dependencies headers:', error.message); |
| 102 | + throw error; |
| 103 | + } |
| 104 | +} |
| 105 | + |
20 | 106 | /** |
21 | 107 | * Create symlinks for React Native headers in the output folder. |
22 | 108 | * This function orchestrate the creation of all the headers required by React Native: |
@@ -100,4 +186,5 @@ function symlinkReactNativeHeaders( |
100 | 186 |
|
101 | 187 | module.exports = { |
102 | 188 | symlinkReactNativeHeaders, |
| 189 | + prepareAppDependenciesHeaders, |
103 | 190 | }; |
0 commit comments