Skip to content

Commit

Permalink
feat(init): deprecate --flatten option
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Deprecated (and removed) `--flatten` option
  • Loading branch information
tido64 committed Nov 12, 2024
1 parent 6c1c8ee commit 7508471
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 475 deletions.
14 changes: 2 additions & 12 deletions .github/actions/gradle/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,11 @@ inputs:
runs:
using: composite
steps:
- name: Determine build root directory
id: build-root-directory-finder
run: |
if [[ -f android/build.gradle ]]; then
echo "build-root-directory=${{ inputs.project-root }}/android" >> $GITHUB_OUTPUT
else
echo "build-root-directory=${{ inputs.project-root }}" >> $GITHUB_OUTPUT
fi
shell: bash
working-directory: ${{ inputs.project-root }}
- name: Configure Gradle wrapper
run: |
node --eval "require('./android/gradle-wrapper.js').configureGradleWrapper('${{ steps.build-root-directory-finder.outputs.build-root-directory }}')"
node --eval "require('./android/gradle-wrapper.js').configureGradleWrapper('${{ inputs.project-root }}/android')"
shell: bash
- name: Build
run: ./gradlew ${{ inputs.arguments }}
shell: bash
working-directory: ${{ steps.build-root-directory-finder.outputs.build-root-directory }}
working-directory: ${{ inputs.project-root }}/android
42 changes: 7 additions & 35 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,24 +226,15 @@ jobs:
- name: Determine whether the iOS app needs to be built
id: affected
uses: ./.github/actions/affected
- name: Determine project directory
id: configure
if: ${{ steps.affected.outputs.ios != '' }}
run: |
if [[ ${{ matrix.template }} == ios ]]; then
echo 'project-directory=.' >> $GITHUB_OUTPUT
else
echo 'project-directory=ios' >> $GITHUB_OUTPUT
fi
- name: Install Pods
if: ${{ steps.affected.outputs.ios != '' }}
run: |
pod install --project-directory=${{ steps.configure.outputs.project-directory }}
pod install --project-directory=ios
working-directory: template-example
- name: Build
if: ${{ steps.affected.outputs.ios != '' }}
run: |
../scripts/build/xcodebuild.sh ${{ steps.configure.outputs.project-directory }}/TemplateExample.xcworkspace build
../scripts/build/xcodebuild.sh ios/TemplateExample.xcworkspace build
working-directory: template-example
- name: react-native run-ios
if: ${{ steps.affected.outputs.ios != '' }}
Expand Down Expand Up @@ -439,24 +430,15 @@ jobs:
- name: Determine whether the macOS app needs to be built
id: affected
uses: ./.github/actions/affected
- name: Determine project directory
id: configure
if: ${{ steps.affected.outputs.macos != '' }}
run: |
if [[ ${{ matrix.template }} == macos ]]; then
echo 'project-directory=.' >> $GITHUB_OUTPUT
else
echo 'project-directory=macos' >> $GITHUB_OUTPUT
fi
- name: Install Pods
if: ${{ steps.affected.outputs.macos != '' }}
run: |
pod install --project-directory=${{ steps.configure.outputs.project-directory }}
pod install --project-directory=macos
working-directory: template-example
- name: Build
if: ${{ steps.affected.outputs.macos != '' }}
run: |
../scripts/build/xcodebuild.sh ${{ steps.configure.outputs.project-directory }}/TemplateExample.xcworkspace build
../scripts/build/xcodebuild.sh macos/TemplateExample.xcworkspace build
working-directory: template-example
timeout-minutes: 60
visionos:
Expand Down Expand Up @@ -540,24 +522,15 @@ jobs:
- name: Determine whether the visionOS app needs to be built
id: affected
uses: ./.github/actions/affected
- name: Determine project directory
id: configure
if: ${{ steps.affected.outputs.visionos != '' }}
run: |
if [[ ${{ matrix.template }} == visionos ]]; then
echo 'project-directory=.' >> $GITHUB_OUTPUT
else
echo 'project-directory=visionos' >> $GITHUB_OUTPUT
fi
- name: Install Pods
if: ${{ steps.affected.outputs.visionos != '' }}
run: |
pod install --project-directory=${{ steps.configure.outputs.project-directory }}
pod install --project-directory=visionos
working-directory: template-example
- name: Build
if: ${{ steps.affected.outputs.visionos != '' }}
run: |
../scripts/build/xcodebuild.sh ${{ steps.configure.outputs.project-directory }}/TemplateExample.xcworkspace build
../scripts/build/xcodebuild.sh visionos/TemplateExample.xcworkspace build
working-directory: template-example
timeout-minutes: 60
windows:
Expand Down Expand Up @@ -642,8 +615,7 @@ jobs:
yarn build:windows
- name: Generate Visual Studio solution
run: |
if ("${{ matrix.template }}" -eq "all") { yarn install-windows-test-app --use-nuget }
else { yarn install-windows-test-app --project-directory=. --use-nuget }
yarn install-windows-test-app --use-nuget
working-directory: template-example
- name: Determine whether the Windows app needs to be built
id: affected
Expand Down
134 changes: 57 additions & 77 deletions scripts/configure.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ import {
appManifest,
buildGradle,
podfile,
reactNativeConfigAndroidFlat,
reactNativeConfigAppleFlat,
reactNativeConfigWindowsFlat,
serialize,
settingsGradle,
} from "./template.mjs";
Expand Down Expand Up @@ -120,6 +117,46 @@ export function sortByKeys(obj) {
}, /** @type {Record<string, unknown>} */ ({}));
}

/**
* @param {string | string[]} input
* @returns {Platform[]}
*/
export function validatePlatforms(input) {
const platforms = Array.isArray(input) ? input : [input];

let includesApplePlatforms = false;
let includesIOS = false;

for (const p of platforms) {
switch (p) {
case "ios":
includesIOS = true;
break;

case "macos":
case "visionos":
includesApplePlatforms = true;
break;

case "android":
case "windows":
break;

default:
throw new Error(`Unknown platform: ${p}`);
}
}

// Autolinking currently assumes that `ios` is always present:
// https://github.com/facebook/react-native/blob/0.76-stable/packages/react-native/scripts/cocoapods/autolinking.rb#L41
// We need to include iOS if we want to target other Apple platforms.
if (includesApplePlatforms && !includesIOS) {
platforms.push("ios");
}

return /** @type {Platform[]} */ (platforms);
}

/**
* Prints a warning message to the console.
* @param {string} message
Expand Down Expand Up @@ -182,29 +219,7 @@ export function getPlatformPackage(platform, targetVersion) {
* @param {ConfigureParams} params
* @returns {string | FileCopy}
*/
export function reactNativeConfig(
{ name, testAppPath, platforms, flatten },
fs = nodefs
) {
const shouldFlatten = flatten && platforms.length === 1;
if (shouldFlatten) {
switch (platforms[0]) {
case "android":
return reactNativeConfigAndroidFlat();

case "ios":
case "macos":
case "visionos":
return reactNativeConfigAppleFlat();

case "windows":
return reactNativeConfigWindowsFlat(name);

default:
throw new Error(`Unknown platform: ${platforms[0]}`);
}
}

export function reactNativeConfig({ name, testAppPath }, fs = nodefs) {
const config = path.join(testAppPath, "example", "react-native.config.js");
return readTextFile(config, fs).replaceAll("Example", name);
}
Expand Down Expand Up @@ -235,8 +250,7 @@ export const getConfig = (() => {
fs = nodefs
) => {
if (disableCache || typeof configuration === "undefined") {
const { name, templatePath, testAppPath, targetVersion, flatten, init } =
params;
const { name, templatePath, testAppPath, targetVersion, init } = params;

// `.gitignore` files are only renamed when published.
const gitignore = ["_gitignore", ".gitignore"].find((filename) => {
Expand Down Expand Up @@ -431,7 +445,7 @@ export const getConfig = (() => {
scripts: {
"build:windows":
"npm run mkdist && react-native bundle --entry-file index.js --platform windows --dev true --bundle-output dist/main.windows.bundle --assets-dest dist",
windows: `react-native run-windows --sln ${flatten ? "" : "windows/"}${name}.sln`,
windows: "react-native run-windows",
},
dependencies: {},
},
Expand All @@ -447,13 +461,11 @@ export const getConfig = (() => {
* @returns Configuration
*/
export function gatherConfig(params, disableCache = false) {
const { flatten, platforms, targetVersion } = params;
const shouldFlatten = flatten && platforms.length === 1;
const options = { ...params, flatten: shouldFlatten };
const { platforms, targetVersion } = params;
const config = (() => {
return platforms.reduce(
(config, platform) => {
const platformConfig = getConfig(options, platform, disableCache);
const platformConfig = getConfig(params, platform, disableCache);
const dependencies = getPlatformPackage(platform, targetVersion);
if (!dependencies) {
/* node:coverage ignore next */
Expand All @@ -463,23 +475,17 @@ export function gatherConfig(params, disableCache = false) {
return mergeConfig(config, {
...platformConfig,
dependencies,
files: shouldFlatten
? platformConfig.files
: Object.fromEntries(
// Map each file into its platform specific folder, e.g.
// `Podfile` -> `ios/Podfile`
Object.entries(platformConfig.files).map(
([filename, content]) => [
path.join(platform, filename),
content,
]
)
),
oldFiles: shouldFlatten
? platformConfig.oldFiles
: platformConfig.oldFiles.map((file) => {
return path.join(platform, file);
}),
files: Object.fromEntries(
// Map each file into its platform specific folder, e.g.
// `Podfile` -> `ios/Podfile`
Object.entries(platformConfig.files).map(([filename, content]) => [
path.join(platform, filename),
content,
])
),
oldFiles: platformConfig.oldFiles.map((file) => {
return path.join(platform, file);
}),
});
},
/** @type {Configuration} */ ({
Expand All @@ -500,7 +506,7 @@ export function gatherConfig(params, disableCache = false) {
return config;
}

return mergeConfig(getConfig(options, "common", disableCache), config);
return mergeConfig(getConfig(params, "common", disableCache), config);
}

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

/** @type {(input: string | string[]) => Platform[] } */
const validatePlatforms = (input) => {
const platforms = Array.isArray(input) ? input : [input];
for (const p of platforms) {
switch (p) {
case "android":
case "ios":
case "macos":
case "visionos":
case "windows":
break;
default:
throw new Error(`Unknown platform: ${p}`);
}
}
return /** @type {Platform[]} */ (platforms);
};

parseArgs(
"Configures React Test App in an existing package",
{
flatten: {
description:
"Flatten the directory structure (when only one platform is selected)",
type: "boolean",
default: false,
},
force: {
description: "Allow destructive operations",
type: "boolean",
Expand Down Expand Up @@ -750,7 +732,6 @@ if (isMain(import.meta.url)) {
},
async ({
_: { [0]: name },
flatten,
force,
init,
package: packagePath,
Expand All @@ -764,7 +745,6 @@ if (isMain(import.meta.url)) {
testAppPath: fileURLToPath(new URL("..", import.meta.url)),
targetVersion,
platforms: validatePlatforms(platforms),
flatten,
force,
init,
});
Expand Down
9 changes: 6 additions & 3 deletions scripts/init.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { createRequire } from "node:module";
import * as path from "node:path";
import { URL, fileURLToPath } from "node:url";
import prompts from "prompts";
import { configure, getDefaultPlatformPackageName } from "./configure.mjs";
import {
configure,
getDefaultPlatformPackageName,
validatePlatforms,
} from "./configure.mjs";
import { memo, readJSONFile, toVersionNumber, v } from "./helpers.js";
import * as colors from "./utils/colors.mjs";
import { downloadPackage, fetchPackageMetadata } from "./utils/npm.mjs";
Expand Down Expand Up @@ -255,8 +259,7 @@ function main() {
templatePath,
testAppPath: fileURLToPath(new URL("..", import.meta.url)),
targetVersion,
platforms,
flatten: true,
platforms: validatePlatforms(platforms),
force: true,
init: true,
});
Expand Down
Loading

0 comments on commit 7508471

Please sign in to comment.