Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add buildScript option #504

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
37 changes: 37 additions & 0 deletions packages/docs/docs/launch-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,43 @@ Below is an example of how the `launch.json` file could look like with android v
}
```

### Custom build settings

Instead of letting Radon IDE build your app, you can use scripts or [Expo
Application Services (EAS)](https://expo.dev/eas) to do
it with `buildScript` configuration option.

The requirement for scripts is to output the absolute path to the built app as the
last line of standard output.

You can also use `eas build`, `eas build:list` or `eas build:view` with
JSON output to use builds from EAS. If multiple builds are present, Radon IDE
will take the most recent one. Builds for iOS need to have `"ios.simulator":
true` config option set.

`buildScript` configuration option is an object with `ios` and `android` keys.
Both are optional, specifying any of them will replace default build logic for
that platform with command of your choice.

Below is an example that replaces Android build with build from EAS:

```json
{
"version": "0.2.0",
"configurations": [
{
"type": "radon-ide",
"request": "launch",
"name": "Radon IDE panel",
"buildScript": {
"android": "eas build:list --non-interactive --json --platform android"
}
}
]
}
```


### Other settings

Here, we list other attributes that can be configured using launch configuration which doesn't fit in any of the above categories:
Expand Down
70 changes: 61 additions & 9 deletions packages/vscode-extension/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,64 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off",
"cmake.configureOnOpen": false
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off",
"cmake.configureOnOpen": false,
"cSpell.words": [
"Aapt",
"avds",
"codicon",
"codicons",
"debugadapter",
"debuggable",
"debugprotocol",
"Deeplink",
"devmenu",
"execa",
"fastboot",
"getprop",
"gradlew",
"initscript",
"keyevent",
"launchservices",
"libexec",
"msgpack",
"ncore",
"openurl",
"outfile",
"playstore",
"Preact",
"prefs",
"RNIDE",
"Runtimes",
"schemeapproval",
"sdcard",
"sdkmanager",
"sharedpreferences",
"simctl",
"siri",
"sourcer",
"swmansion",
"sysdir",
"UDID",
"uimode",
"uuidv4",
"virtualscene",
"xcodebuild",
"xcodeproj",
"xcrun",
"xcscheme",
"xcschemes",
"xcshareddata",
"xcworkspace",
"xlarge",
"xsmall",
"xxlarge",
"xxxlarge"
]
}
3 changes: 2 additions & 1 deletion packages/vscode-extension/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 17 additions & 3 deletions packages/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"side-panel",
"secondary-side-panel"
],
"description": "Controlls location of the IDE panel. Due to vscode API limitations, when secondary side panel is selected, you need to manually move the IDE panel to the secondary side panel. Changing this option closes and reopens the IDE."
"description": "Controls location of the IDE panel. Due to vscode API limitations, when secondary side panel is selected, you need to manually move the IDE panel to the secondary side panel. Changing this option closes and reopens the IDE."
},
"RadonIDE.showDeviceFrame": {
"type": "boolean",
Expand Down Expand Up @@ -194,7 +194,7 @@
"properties": {
"appRoot": {
"type": "string",
"description": "Location of the React Native application root folder relative to the workspace. This is used for monorepo type setups when the workspace root is not the root of the React Native project. The IDE extension tries to locate the React Native application root automatically, but in case it failes to do so (i.e. there are multiple applications defined in the workspace), you can use this setting to override the location."
"description": "Location of the React Native application root folder relative to the workspace. This is used for monorepo type setups when the workspace root is not the root of the React Native project. The IDE extension tries to locate the React Native application root automatically, but in case it fails to do so (i.e. there are multiple applications defined in the workspace), you can use this setting to override the location."
},
"isExpo": {
"type": "boolean",
Expand All @@ -208,6 +208,20 @@
"type": "string",
"description": "Location of Metro config relative to the workspace. This is used for using custom configs for e.g. development."
},
"buildScript": {
"type": "object",
"description": "Scripts used to build Android or iOS app or fetch them from known location. Executed as a part of building process. Should print a JSON result from `eas build` command or a filesystem path to the built app as the last line of the standard output.\nIf using EAS, it should be invoked with --json --non-interactive flags and use a profile for development, iOS additionally needs `\"ios.simulator\": true` config option in eas.json",
"properties": {
"ios": {
"type": "string",
"description": "Script used to build iOS app."
},
"android": {
"type": "string",
"description": "Script used to build Android app."
}
}
},
"ios": {
"description": "Provides a way to customize Xcode builds for iOS",
"type": "object",
Expand Down Expand Up @@ -322,7 +336,7 @@
}
},
"preview": {
"description": "Custommize the behavior of device preview",
"description": "Customize the behavior of device preview",
"type": "object",
"properties": {
"waitForAppLaunch": {
Expand Down
5 changes: 3 additions & 2 deletions packages/vscode-extension/src/builders/BuildManager.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import fs from "fs";
import { Disposable, OutputChannel, window } from "vscode";

import { Logger } from "../Logger";
import { generateWorkspaceFingerprint } from "../utilities/fingerprint";
import { AndroidBuildResult, buildAndroid } from "./buildAndroid";
import { IOSBuildResult, buildIos } from "./buildIOS";
import fs from "fs";
import { calculateMD5 } from "../utilities/common";
import { DeviceInfo, DevicePlatform } from "../common/DeviceManager";
import { extensionContext, getAppRootFolder } from "../utilities/extensionContext";
import { Disposable, OutputChannel, window } from "vscode";
import { DependencyManager } from "../dependency/DependencyManager";
import { CancelToken } from "./cancelToken";

Expand Down
37 changes: 28 additions & 9 deletions packages/vscode-extension/src/builders/buildAndroid.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import path from "path";
import fs from "fs";
import semver from "semver";
import { OutputChannel } from "vscode";

import { getNativeABI } from "../utilities/common";
import { ANDROID_HOME, JAVA_HOME } from "../utilities/android";
import { Logger } from "../Logger";
import { exec, lineReader } from "../utilities/subprocess";
import semver from "semver";
import { CancelToken } from "./cancelToken";
import path from "path";
import fs from "fs";
import { OutputChannel } from "vscode";
import { extensionContext } from "../utilities/extensionContext";
import { BuildAndroidProgressProcessor } from "./BuildAndroidProgressProcessor";
import { getLaunchConfiguration } from "../utilities/launchConfiguration";
import { EXPO_GO_PACKAGE_NAME, downloadExpoGo, isExpoGoProject } from "./expoGo";
import { DevicePlatform } from "../common/DeviceManager";
import { getReactNativeVersion } from "../utilities/reactNative";
import { runExternalBuild } from "./customBuild";

export type AndroidBuildResult = {
platform: DevicePlatform.Android;
Expand Down Expand Up @@ -76,14 +78,31 @@
outputChannel: OutputChannel,
progressListener: (newProgress: number) => void
): Promise<AndroidBuildResult> {
const { buildScript, env, android } = getLaunchConfiguration();

if (buildScript?.android) {
const apkPath = await runExternalBuild(
jakub-gonet marked this conversation as resolved.
Show resolved Hide resolved
cancelToken,
DevicePlatform.Android,
buildScript.android,
env
);

return {
apkPath,
packageName: await extractPackageName(apkPath, cancelToken),
platform: DevicePlatform.Android,
};
}

if (await isExpoGoProject()) {
const apkPath = await downloadExpoGo(DevicePlatform.Android, cancelToken);
return { apkPath, packageName: EXPO_GO_PACKAGE_NAME, platform: DevicePlatform.Android };
}

const androidSourceDir = getAndroidSourceDir(appRootFolder);
const buildOptions = getLaunchConfiguration();
const productFlavor = buildOptions.android?.productFlavor || "";
const buildType = buildOptions.android?.buildType || "debug";
const productFlavor = android?.productFlavor || "";
const buildType = android?.buildType || "debug";
const gradleArgs = [
"-x",
"lint",
Expand Down Expand Up @@ -114,7 +133,7 @@
const buildProcess = cancelToken.adapt(
exec("./gradlew", gradleArgs, {
cwd: androidSourceDir,
env: { ...buildOptions.env, JAVA_HOME, ANDROID_HOME },
env: { ...env, JAVA_HOME, ANDROID_HOME },

Check warning on line 136 in packages/vscode-extension/src/builders/buildAndroid.ts

View workflow job for this annotation

GitHub Actions / check

Object Literal Property name `JAVA_HOME` must match one of the following formats: camelCase

Check warning on line 136 in packages/vscode-extension/src/builders/buildAndroid.ts

View workflow job for this annotation

GitHub Actions / check

Object Literal Property name `ANDROID_HOME` must match one of the following formats: camelCase
buffer: false,
})
);
Expand All @@ -126,7 +145,7 @@
});

await buildProcess;
Logger.debug("Android build sucessful");
Logger.debug("Android build successful");
const apkInfo = await getAndroidBuildPaths(appRootFolder, cancelToken, productFlavor, buildType);
return { ...apkInfo, platform: DevicePlatform.Android };
}
16 changes: 14 additions & 2 deletions packages/vscode-extension/src/builders/buildIOS.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { OutputChannel } from "vscode";
import path from "path";

import { exec, lineReader } from "../utilities/subprocess";
import { Logger } from "../Logger";
import path from "path";
import { CancelToken } from "./cancelToken";
import { BuildIOSProgressProcessor } from "./BuildIOSProgressProcessor";
import { getLaunchConfiguration } from "../utilities/launchConfiguration";
Expand All @@ -14,6 +15,7 @@
import { IOSDeviceInfo, DevicePlatform } from "../common/DeviceManager";
import { EXPO_GO_BUNDLE_ID, downloadExpoGo, isExpoGoProject } from "./expoGo";
import { findXcodeProject, findXcodeScheme, IOSProjectInfo } from "../utilities/xcode";
import { runExternalBuild } from "./customBuild";

export type IOSBuildResult = {
platform: DevicePlatform.IOS;
Expand All @@ -37,7 +39,7 @@
}

function buildProject(
UDID: string,

Check warning on line 42 in packages/vscode-extension/src/builders/buildIOS.ts

View workflow job for this annotation

GitHub Actions / check

Parameter name `UDID` must match one of the following formats: camelCase
xcodeProject: IOSProjectInfo,
buildDir: string,
scheme: string,
Expand All @@ -62,7 +64,7 @@
return exec("xcodebuild", xcodebuildArgs, {
env: {
...getLaunchConfiguration().env,
RCT_NO_LAUNCH_PACKAGER: "true",

Check warning on line 67 in packages/vscode-extension/src/builders/buildIOS.ts

View workflow job for this annotation

GitHub Actions / check

Object Literal Property name `RCT_NO_LAUNCH_PACKAGER` must match one of the following formats: camelCase
},
cwd: buildDir,
buffer: false,
Expand All @@ -83,7 +85,17 @@
cancelToken: CancelToken
) => Promise<void>
): Promise<IOSBuildResult> {
const { ios: buildOptions } = getLaunchConfiguration();
const { buildScript, ios: buildOptions } = getLaunchConfiguration();

if (buildScript?.ios) {
const appPath = await runExternalBuild(cancelToken, DevicePlatform.IOS, buildScript.ios, env);

return {
appPath,
bundleID: await getBundleID(appPath),
platform: DevicePlatform.IOS,
};
}

if (await isExpoGoProject()) {
const appPath = await downloadExpoGo(DevicePlatform.IOS, cancelToken);
Expand Down Expand Up @@ -112,7 +124,7 @@
Logger.debug(`Xcode build will use "${scheme}" scheme`);

let platformName: string | undefined;
const buildProcess = withTemporarySimulator(deviceInfo, (UDID) => {

Check warning on line 127 in packages/vscode-extension/src/builders/buildIOS.ts

View workflow job for this annotation

GitHub Actions / check

Parameter name `UDID` must match one of the following formats: camelCase
const process = cancelToken.adapt(
buildProject(
UDID,
Expand Down Expand Up @@ -228,7 +240,7 @@
const simulators = await listSimulators(SimulatorDeviceSet.Default);
const removedSimulators = simulators
.filter(({ name }) => name.startsWith(TEMP_SIMULATOR_NAME_PREFIX))
.map(({ UDID }) => removeIosSimulator(UDID, SimulatorDeviceSet.Default));

Check warning on line 243 in packages/vscode-extension/src/builders/buildIOS.ts

View workflow job for this annotation

GitHub Actions / check

Parameter name `UDID` must match one of the following formats: camelCase

await Promise.allSettled(removedSimulators);
}
Loading
Loading