Skip to content

Commit 7508471

Browse files
committed
feat(init): deprecate --flatten option
BREAKING CHANGE: Deprecated (and removed) `--flatten` option
1 parent 6c1c8ee commit 7508471

File tree

10 files changed

+74
-475
lines changed

10 files changed

+74
-475
lines changed

.github/actions/gradle/action.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,11 @@ inputs:
1010
runs:
1111
using: composite
1212
steps:
13-
- name: Determine build root directory
14-
id: build-root-directory-finder
15-
run: |
16-
if [[ -f android/build.gradle ]]; then
17-
echo "build-root-directory=${{ inputs.project-root }}/android" >> $GITHUB_OUTPUT
18-
else
19-
echo "build-root-directory=${{ inputs.project-root }}" >> $GITHUB_OUTPUT
20-
fi
21-
shell: bash
22-
working-directory: ${{ inputs.project-root }}
2313
- name: Configure Gradle wrapper
2414
run: |
25-
node --eval "require('./android/gradle-wrapper.js').configureGradleWrapper('${{ steps.build-root-directory-finder.outputs.build-root-directory }}')"
15+
node --eval "require('./android/gradle-wrapper.js').configureGradleWrapper('${{ inputs.project-root }}/android')"
2616
shell: bash
2717
- name: Build
2818
run: ./gradlew ${{ inputs.arguments }}
2919
shell: bash
30-
working-directory: ${{ steps.build-root-directory-finder.outputs.build-root-directory }}
20+
working-directory: ${{ inputs.project-root }}/android

.github/workflows/build.yml

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -226,24 +226,15 @@ jobs:
226226
- name: Determine whether the iOS app needs to be built
227227
id: affected
228228
uses: ./.github/actions/affected
229-
- name: Determine project directory
230-
id: configure
231-
if: ${{ steps.affected.outputs.ios != '' }}
232-
run: |
233-
if [[ ${{ matrix.template }} == ios ]]; then
234-
echo 'project-directory=.' >> $GITHUB_OUTPUT
235-
else
236-
echo 'project-directory=ios' >> $GITHUB_OUTPUT
237-
fi
238229
- name: Install Pods
239230
if: ${{ steps.affected.outputs.ios != '' }}
240231
run: |
241-
pod install --project-directory=${{ steps.configure.outputs.project-directory }}
232+
pod install --project-directory=ios
242233
working-directory: template-example
243234
- name: Build
244235
if: ${{ steps.affected.outputs.ios != '' }}
245236
run: |
246-
../scripts/build/xcodebuild.sh ${{ steps.configure.outputs.project-directory }}/TemplateExample.xcworkspace build
237+
../scripts/build/xcodebuild.sh ios/TemplateExample.xcworkspace build
247238
working-directory: template-example
248239
- name: react-native run-ios
249240
if: ${{ steps.affected.outputs.ios != '' }}
@@ -439,24 +430,15 @@ jobs:
439430
- name: Determine whether the macOS app needs to be built
440431
id: affected
441432
uses: ./.github/actions/affected
442-
- name: Determine project directory
443-
id: configure
444-
if: ${{ steps.affected.outputs.macos != '' }}
445-
run: |
446-
if [[ ${{ matrix.template }} == macos ]]; then
447-
echo 'project-directory=.' >> $GITHUB_OUTPUT
448-
else
449-
echo 'project-directory=macos' >> $GITHUB_OUTPUT
450-
fi
451433
- name: Install Pods
452434
if: ${{ steps.affected.outputs.macos != '' }}
453435
run: |
454-
pod install --project-directory=${{ steps.configure.outputs.project-directory }}
436+
pod install --project-directory=macos
455437
working-directory: template-example
456438
- name: Build
457439
if: ${{ steps.affected.outputs.macos != '' }}
458440
run: |
459-
../scripts/build/xcodebuild.sh ${{ steps.configure.outputs.project-directory }}/TemplateExample.xcworkspace build
441+
../scripts/build/xcodebuild.sh macos/TemplateExample.xcworkspace build
460442
working-directory: template-example
461443
timeout-minutes: 60
462444
visionos:
@@ -540,24 +522,15 @@ jobs:
540522
- name: Determine whether the visionOS app needs to be built
541523
id: affected
542524
uses: ./.github/actions/affected
543-
- name: Determine project directory
544-
id: configure
545-
if: ${{ steps.affected.outputs.visionos != '' }}
546-
run: |
547-
if [[ ${{ matrix.template }} == visionos ]]; then
548-
echo 'project-directory=.' >> $GITHUB_OUTPUT
549-
else
550-
echo 'project-directory=visionos' >> $GITHUB_OUTPUT
551-
fi
552525
- name: Install Pods
553526
if: ${{ steps.affected.outputs.visionos != '' }}
554527
run: |
555-
pod install --project-directory=${{ steps.configure.outputs.project-directory }}
528+
pod install --project-directory=visionos
556529
working-directory: template-example
557530
- name: Build
558531
if: ${{ steps.affected.outputs.visionos != '' }}
559532
run: |
560-
../scripts/build/xcodebuild.sh ${{ steps.configure.outputs.project-directory }}/TemplateExample.xcworkspace build
533+
../scripts/build/xcodebuild.sh visionos/TemplateExample.xcworkspace build
561534
working-directory: template-example
562535
timeout-minutes: 60
563536
windows:
@@ -642,8 +615,7 @@ jobs:
642615
yarn build:windows
643616
- name: Generate Visual Studio solution
644617
run: |
645-
if ("${{ matrix.template }}" -eq "all") { yarn install-windows-test-app --use-nuget }
646-
else { yarn install-windows-test-app --project-directory=. --use-nuget }
618+
yarn install-windows-test-app --use-nuget
647619
working-directory: template-example
648620
- name: Determine whether the Windows app needs to be built
649621
id: affected

scripts/configure.mjs

Lines changed: 57 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ import {
1919
appManifest,
2020
buildGradle,
2121
podfile,
22-
reactNativeConfigAndroidFlat,
23-
reactNativeConfigAppleFlat,
24-
reactNativeConfigWindowsFlat,
2522
serialize,
2623
settingsGradle,
2724
} from "./template.mjs";
@@ -120,6 +117,46 @@ export function sortByKeys(obj) {
120117
}, /** @type {Record<string, unknown>} */ ({}));
121118
}
122119

120+
/**
121+
* @param {string | string[]} input
122+
* @returns {Platform[]}
123+
*/
124+
export function validatePlatforms(input) {
125+
const platforms = Array.isArray(input) ? input : [input];
126+
127+
let includesApplePlatforms = false;
128+
let includesIOS = false;
129+
130+
for (const p of platforms) {
131+
switch (p) {
132+
case "ios":
133+
includesIOS = true;
134+
break;
135+
136+
case "macos":
137+
case "visionos":
138+
includesApplePlatforms = true;
139+
break;
140+
141+
case "android":
142+
case "windows":
143+
break;
144+
145+
default:
146+
throw new Error(`Unknown platform: ${p}`);
147+
}
148+
}
149+
150+
// Autolinking currently assumes that `ios` is always present:
151+
// https://github.com/facebook/react-native/blob/0.76-stable/packages/react-native/scripts/cocoapods/autolinking.rb#L41
152+
// We need to include iOS if we want to target other Apple platforms.
153+
if (includesApplePlatforms && !includesIOS) {
154+
platforms.push("ios");
155+
}
156+
157+
return /** @type {Platform[]} */ (platforms);
158+
}
159+
123160
/**
124161
* Prints a warning message to the console.
125162
* @param {string} message
@@ -182,29 +219,7 @@ export function getPlatformPackage(platform, targetVersion) {
182219
* @param {ConfigureParams} params
183220
* @returns {string | FileCopy}
184221
*/
185-
export function reactNativeConfig(
186-
{ name, testAppPath, platforms, flatten },
187-
fs = nodefs
188-
) {
189-
const shouldFlatten = flatten && platforms.length === 1;
190-
if (shouldFlatten) {
191-
switch (platforms[0]) {
192-
case "android":
193-
return reactNativeConfigAndroidFlat();
194-
195-
case "ios":
196-
case "macos":
197-
case "visionos":
198-
return reactNativeConfigAppleFlat();
199-
200-
case "windows":
201-
return reactNativeConfigWindowsFlat(name);
202-
203-
default:
204-
throw new Error(`Unknown platform: ${platforms[0]}`);
205-
}
206-
}
207-
222+
export function reactNativeConfig({ name, testAppPath }, fs = nodefs) {
208223
const config = path.join(testAppPath, "example", "react-native.config.js");
209224
return readTextFile(config, fs).replaceAll("Example", name);
210225
}
@@ -235,8 +250,7 @@ export const getConfig = (() => {
235250
fs = nodefs
236251
) => {
237252
if (disableCache || typeof configuration === "undefined") {
238-
const { name, templatePath, testAppPath, targetVersion, flatten, init } =
239-
params;
253+
const { name, templatePath, testAppPath, targetVersion, init } = params;
240254

241255
// `.gitignore` files are only renamed when published.
242256
const gitignore = ["_gitignore", ".gitignore"].find((filename) => {
@@ -431,7 +445,7 @@ export const getConfig = (() => {
431445
scripts: {
432446
"build:windows":
433447
"npm run mkdist && react-native bundle --entry-file index.js --platform windows --dev true --bundle-output dist/main.windows.bundle --assets-dest dist",
434-
windows: `react-native run-windows --sln ${flatten ? "" : "windows/"}${name}.sln`,
448+
windows: "react-native run-windows",
435449
},
436450
dependencies: {},
437451
},
@@ -447,13 +461,11 @@ export const getConfig = (() => {
447461
* @returns Configuration
448462
*/
449463
export function gatherConfig(params, disableCache = false) {
450-
const { flatten, platforms, targetVersion } = params;
451-
const shouldFlatten = flatten && platforms.length === 1;
452-
const options = { ...params, flatten: shouldFlatten };
464+
const { platforms, targetVersion } = params;
453465
const config = (() => {
454466
return platforms.reduce(
455467
(config, platform) => {
456-
const platformConfig = getConfig(options, platform, disableCache);
468+
const platformConfig = getConfig(params, platform, disableCache);
457469
const dependencies = getPlatformPackage(platform, targetVersion);
458470
if (!dependencies) {
459471
/* node:coverage ignore next */
@@ -463,23 +475,17 @@ export function gatherConfig(params, disableCache = false) {
463475
return mergeConfig(config, {
464476
...platformConfig,
465477
dependencies,
466-
files: shouldFlatten
467-
? platformConfig.files
468-
: Object.fromEntries(
469-
// Map each file into its platform specific folder, e.g.
470-
// `Podfile` -> `ios/Podfile`
471-
Object.entries(platformConfig.files).map(
472-
([filename, content]) => [
473-
path.join(platform, filename),
474-
content,
475-
]
476-
)
477-
),
478-
oldFiles: shouldFlatten
479-
? platformConfig.oldFiles
480-
: platformConfig.oldFiles.map((file) => {
481-
return path.join(platform, file);
482-
}),
478+
files: Object.fromEntries(
479+
// Map each file into its platform specific folder, e.g.
480+
// `Podfile` -> `ios/Podfile`
481+
Object.entries(platformConfig.files).map(([filename, content]) => [
482+
path.join(platform, filename),
483+
content,
484+
])
485+
),
486+
oldFiles: platformConfig.oldFiles.map((file) => {
487+
return path.join(platform, file);
488+
}),
483489
});
484490
},
485491
/** @type {Configuration} */ ({
@@ -500,7 +506,7 @@ export function gatherConfig(params, disableCache = false) {
500506
return config;
501507
}
502508

503-
return mergeConfig(getConfig(options, "common", disableCache), config);
509+
return mergeConfig(getConfig(params, "common", disableCache), config);
504510
}
505511

506512
/**
@@ -696,33 +702,9 @@ if (isMain(import.meta.url)) {
696702
const platformChoices = ["android", "ios", "macos", "windows"];
697703
const defaultPlatforms = platformChoices.join(", ");
698704

699-
/** @type {(input: string | string[]) => Platform[] } */
700-
const validatePlatforms = (input) => {
701-
const platforms = Array.isArray(input) ? input : [input];
702-
for (const p of platforms) {
703-
switch (p) {
704-
case "android":
705-
case "ios":
706-
case "macos":
707-
case "visionos":
708-
case "windows":
709-
break;
710-
default:
711-
throw new Error(`Unknown platform: ${p}`);
712-
}
713-
}
714-
return /** @type {Platform[]} */ (platforms);
715-
};
716-
717705
parseArgs(
718706
"Configures React Test App in an existing package",
719707
{
720-
flatten: {
721-
description:
722-
"Flatten the directory structure (when only one platform is selected)",
723-
type: "boolean",
724-
default: false,
725-
},
726708
force: {
727709
description: "Allow destructive operations",
728710
type: "boolean",
@@ -750,7 +732,6 @@ if (isMain(import.meta.url)) {
750732
},
751733
async ({
752734
_: { [0]: name },
753-
flatten,
754735
force,
755736
init,
756737
package: packagePath,
@@ -764,7 +745,6 @@ if (isMain(import.meta.url)) {
764745
testAppPath: fileURLToPath(new URL("..", import.meta.url)),
765746
targetVersion,
766747
platforms: validatePlatforms(platforms),
767-
flatten,
768748
force,
769749
init,
770750
});

scripts/init.mjs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import { createRequire } from "node:module";
44
import * as path from "node:path";
55
import { URL, fileURLToPath } from "node:url";
66
import prompts from "prompts";
7-
import { configure, getDefaultPlatformPackageName } from "./configure.mjs";
7+
import {
8+
configure,
9+
getDefaultPlatformPackageName,
10+
validatePlatforms,
11+
} from "./configure.mjs";
812
import { memo, readJSONFile, toVersionNumber, v } from "./helpers.js";
913
import * as colors from "./utils/colors.mjs";
1014
import { downloadPackage, fetchPackageMetadata } from "./utils/npm.mjs";
@@ -255,8 +259,7 @@ function main() {
255259
templatePath,
256260
testAppPath: fileURLToPath(new URL("..", import.meta.url)),
257261
targetVersion,
258-
platforms,
259-
flatten: true,
262+
platforms: validatePlatforms(platforms),
260263
force: true,
261264
init: true,
262265
});

0 commit comments

Comments
 (0)