Skip to content

Commit 6a5f9cd

Browse files
authored
Merge pull request #2432 from microsoft/add-command-to-support-expo-eas-workflow
Add command to support expo eas workflow
2 parents ec1e149 + 71c8a6a commit 6a5f9cd

File tree

6 files changed

+79
-0
lines changed

6 files changed

+79
-0
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,12 @@
477477
"title": "Toggle Network View",
478478
"category": "React Native",
479479
"enablement": "!config.security.workspace.trust.enabled || isWorkspaceTrusted"
480+
},
481+
{
482+
"command": "reactNative.runEasBuild",
483+
"title": "Run EAS Build",
484+
"category": "React Native",
485+
"enablement": "!config.security.workspace.trust.enabled || isWorkspaceTrusted"
480486
}
481487
],
482488
"menus": {

src/common/error/errorStrings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,4 +425,5 @@ export const ERROR_STRINGS = {
425425
[InternalErrorCode.FailedToKillPort]: "Failed to kill port",
426426
[InternalErrorCode.FaiedToSetNewArch]: "Failed to set New Architecture",
427427
[InternalErrorCode.FailedToToggleNetworkView]: "Failed to config network view",
428+
[InternalErrorCode.FailedToRunEasBuild]: "Failed to run eas build",
428429
};

src/common/error/internalErrorCode.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export enum InternalErrorCode {
3838
FailedToKillPort = 133,
3939
FaiedToSetNewArch = 134,
4040
FailedToToggleNetworkView = 135,
41+
FailedToRunEasBuild = 136,
4142

4243
// Device Deployer errors
4344
IOSDeployNotFound = 201,

src/extension/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ export * from "./openExpoUpgradeHelper";
3737
export * from "./killPort";
3838
export * from "./setNewArch";
3939
export * from "./networkView";
40+
export * from "./runEasBuild";
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for details.
3+
4+
import * as assert from "assert";
5+
import * as path from "path";
6+
import * as fs from "fs";
7+
import * as vscode from "vscode";
8+
import { ErrorHelper } from "../../common/error/errorHelper";
9+
import { InternalErrorCode } from "../../common/error/internalErrorCode";
10+
import { ReactNativeCommand } from "./util/reactNativeCommand";
11+
12+
export class runEasBuild extends ReactNativeCommand {
13+
codeName = "runEasBuild";
14+
label = "Run EAS Build";
15+
error = ErrorHelper.getInternalError(InternalErrorCode.FailedToRunEasBuild);
16+
async baseFn(): Promise<void> {
17+
console.log("this.project:", this.project);
18+
19+
assert(this.project);
20+
const packager = await this.project.getPackager();
21+
const projectRootPath = await packager.getProjectPath();
22+
23+
if (!projectRootPath) {
24+
void vscode.window.showErrorMessage(
25+
"Project root directory not found. Please make sure a React Native project is open.",
26+
);
27+
return;
28+
}
29+
30+
const easJsonPath = path.join(projectRootPath, "eas.json");
31+
const workflowFolderPath = path.join(projectRootPath, ".eas", "workflows");
32+
const workflowFilePath = path.join(workflowFolderPath, "create-production-builds.yml");
33+
34+
try {
35+
if (!fs.existsSync(easJsonPath)) {
36+
fs.writeFileSync(easJsonPath, "{}", "utf8");
37+
}
38+
} catch (err) {
39+
void vscode.window.showErrorMessage(
40+
"Failed. Please check your permissions or disk status.",
41+
);
42+
return;
43+
}
44+
try {
45+
if (!fs.existsSync(workflowFilePath)) {
46+
fs.mkdirSync(workflowFolderPath, { recursive: true });
47+
48+
const workflowContent = `name: Create Production Builds
49+
jobs:
50+
build_android:
51+
type: build # This job type creates a production build for Android
52+
params:
53+
platform: android
54+
build_ios:
55+
type: build # This job type creates a production build for iOS
56+
params:
57+
platform: ios
58+
`;
59+
60+
fs.writeFileSync(workflowFilePath, workflowContent, "utf8");
61+
}
62+
} catch (err) {
63+
void vscode.window.showErrorMessage(
64+
"Failed. Please check your permissions or disk status.",
65+
);
66+
return;
67+
}
68+
}
69+
}

test/extension/rn-extension.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ suite("rn-extension", function () {
182182
"reactNative.killPort",
183183
"reactNative.setNewArch",
184184
"reactNative.toggleNetworkView",
185+
"reactNative.runEasBuild",
185186
]);
186187
});
187188
});

0 commit comments

Comments
 (0)