|
| 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 | +} |
0 commit comments