99 */
1010const nodefs = require ( "node:fs" ) ;
1111const path = require ( "node:path" ) ;
12- const { generateAndroidManifest } = require ( "../android/android-manifest" ) ;
13- const { configureGradleWrapper } = require ( "../android/gradle-wrapper" ) ;
14- const { findFile, findNearest, readTextFile } = require ( "./helpers" ) ;
12+ const {
13+ configure : configureAndroid ,
14+ getAndroidPackageName,
15+ } = require ( "../android/template.config.mjs" ) ;
16+ const { configure : configureIOS } = require ( "../ios/template.config.mjs" ) ;
17+ const {
18+ configure : configureWindows ,
19+ } = require ( "../windows/template.config.mjs" ) ;
20+ const { findNearest } = require ( "./helpers" ) ;
1521
1622/**
1723 * Finds `react-native.config.[ts,mjs,cjs,js]`.
@@ -69,25 +75,6 @@ function findReactNativeConfig(fs = nodefs) {
6975 throw new Error ( "Failed to find `react-native.config.[ts,mjs,cjs,js]`" ) ;
7076}
7177
72- /**
73- * @returns {string | undefined }
74- */
75- function getAndroidPackageName ( ) {
76- return "com.microsoft.reacttestapp" ;
77- }
78-
79- /**
80- * @param {string } solutionFile
81- * @returns {ProjectParams["windows"]["project"] }
82- */
83- function windowsProjectPath ( solutionFile , fs = nodefs ) {
84- const sln = readTextFile ( solutionFile , fs ) ;
85- const m = sln . match (
86- / ( [ ^ " ] * ?n o d e _ m o d u l e s [ / \\ ] .g e n e r a t e d [ / \\ ] w i n d o w s [ / \\ ] .* ?\. v c x p r o j ) /
87- ) ;
88- return { projectFile : m ? m [ 1 ] : `(Failed to parse '${ solutionFile } ')` } ;
89- }
90-
9178/**
9279 * @param {ProjectConfig } configuration
9380 * @returns {Partial<ProjectParams> }
@@ -98,47 +85,15 @@ function configureProjects({ android, ios, windows }, fs = nodefs) {
9885 /** @type {Partial<ProjectParams> } */
9986 const config = { } ;
10087
88+ const projectRoot = path . dirname ( reactNativeConfig ) ;
10189 if ( android ) {
102- const { packageName, sourceDir } = android ;
103- const manifestPath = path . join (
104- "app" ,
105- "build" ,
106- "generated" ,
107- "rnta" ,
108- "src" ,
109- "main" ,
110- "AndroidManifest.xml"
111- ) ;
112- const projectRoot = path . dirname ( reactNativeConfig ) ;
113- const appManifestPath = findFile ( "app.json" , projectRoot , fs ) ;
114- if ( appManifestPath ) {
115- generateAndroidManifest (
116- appManifestPath ,
117- path . resolve ( projectRoot , sourceDir , manifestPath ) ,
118- fs
119- ) ;
120- }
121-
122- config . android = {
123- sourceDir,
124- manifestPath,
125- packageName : packageName || getAndroidPackageName ( ) ,
126- } ;
127-
128- configureGradleWrapper ( sourceDir , fs ) ;
90+ config . android = configureAndroid ( projectRoot , android , fs ) ;
12991 }
130-
13192 if ( ios ) {
132- config . ios = ios ;
93+ config . ios = configureIOS ( projectRoot , ios , fs ) ;
13394 }
134-
135- if ( windows && fs . existsSync ( windows . solutionFile ) ) {
136- const { sourceDir, solutionFile } = windows ;
137- config . windows = {
138- sourceDir,
139- solutionFile : path . relative ( sourceDir , solutionFile ) ,
140- project : windowsProjectPath ( solutionFile , fs ) ,
141- } ;
95+ if ( windows ) {
96+ config . windows = configureWindows ( projectRoot , windows , fs ) ;
14297 }
14398
14499 return config ;
0 commit comments