microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/commands/configEASBuild.ts
74lines · modeblame
ee2a3185Ezio Li3 years ago | 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 nls from "vscode-nls"; | |
| 6 | import { OutputChannelLogger } from "../log/OutputChannelLogger"; | |
| 7 | import { ErrorHelper } from "../../common/error/errorHelper"; | |
| 8 | import { InternalErrorCode } from "../../common/error/internalErrorCode"; | |
| 9 | import { CommandExecutor } from "../../common/commandExecutor"; | |
| 10 | import { FileSystem } from "../../common/node/fileSystem"; | |
| 11 | import { ReactNativeCommand } from "./util/reactNativeCommand"; | |
| 12 | | |
| 13 | nls.config({ | |
| 14 | messageFormat: nls.MessageFormat.bundle, | |
| 15 | bundleFormat: nls.BundleFormat.standalone, | |
| 16 | })(); | |
| 17 | const localize = nls.loadMessageBundle(); | |
| 18 | const logger = OutputChannelLogger.getMainChannel(); | |
| 19 | | |
| 20 | export class ConfigEASBuild extends ReactNativeCommand { | |
| 21 | nodeModulesRoot: string; | |
| 22 | codeName = "createExpoEASBuildConfigFile"; | |
| 23 | label = "Config Expo app with EAS build"; | |
| 24 | error = ErrorHelper.getInternalError(InternalErrorCode.FailedToConfigEASBuild); | |
| 25 | | |
| 26 | async baseFn(): Promise<void> { | |
| 27 | assert(this.project); | |
9c71977dEzio Li2 years ago | 28 | const projectRootPath = this.project.getPackager().getProjectPath(); |
| 29 | const expoHelper = this.project.getExponentHelper(); | |
| 30 | logger.info(localize("CheckExpoEnvironment", "Checking Expo project environment.")); | |
ee2a3185Ezio Li3 years ago | 31 | const isExpo = await expoHelper.isExpoManagedApp(true); |
| 32 | | |
| 33 | if (isExpo) { | |
| 34 | const fs = new FileSystem(); | |
| 35 | const exists = await fs.exists(`${projectRootPath}/eas.json`); | |
| 36 | if (exists) { | |
| 37 | logger.info( | |
| 38 | localize( | |
| 39 | "FoundEASJsonFile", | |
| 40 | "There is an eas.json file already existing in your app root.", | |
| 41 | ), | |
| 42 | ); | |
| 43 | } else { | |
| 44 | logger.info( | |
| 45 | localize("ConfigEASBuildInProgress", "Creating EAS build config file."), | |
| 46 | ); | |
| 47 | | |
| 48 | try { | |
| 49 | await new CommandExecutor(this.nodeModulesRoot, projectRootPath).execute( | |
| 50 | "eas build:configure --platform all", | |
| 51 | ); | |
| 52 | | |
| 53 | logger.info( | |
| 54 | localize( | |
| 55 | "ConfigEASBuildSuccessfully", | |
| 56 | "Create EAS build config file successfully.", | |
| 57 | ), | |
| 58 | ); | |
| 59 | } catch { | |
| 60 | logger.error( | |
| 61 | localize( | |
| 62 | "NoExistingEASProject", | |
| 63 | "Unable to find existing EAS project. Please run 'eas init' firstly to bind your app to EAS project.", | |
| 64 | ), | |
| 65 | ); | |
| 66 | } | |
| 67 | } | |
| 68 | } else { | |
| 69 | throw new Error( | |
| 70 | localize("NotExpoApplication", "The current app is not an Expo application."), | |
| 71 | ); | |
| 72 | } | |
| 73 | } | |
| 74 | } |