From 186543824933ac5c3d48975d12ffbfeb5af7bb57 Mon Sep 17 00:00:00 2001 From: ElenaDiachenko Date: Wed, 6 Mar 2024 09:15:30 +0200 Subject: [PATCH] fix generateBuildConfig --- packages/core/src/configs/buildConfig.ts | 15 ++++++++++++++ packages/core/src/context/runtime.ts | 26 ++++++++++++++++++++---- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/packages/core/src/configs/buildConfig.ts b/packages/core/src/configs/buildConfig.ts index 5d25291787..7ef9b7fa27 100644 --- a/packages/core/src/configs/buildConfig.ts +++ b/packages/core/src/configs/buildConfig.ts @@ -185,4 +185,19 @@ export const generateBuildConfig = (_c?: RnvContext) => { logWarning('Cannot save buildConfig as c.paths.project.builds.dir is not defined'); } } + + _checkBuildSchemeIfEngine(c); +}; + +const _checkBuildSchemeIfEngine = (c: RnvContext) => { + const { scheme } = c.program; + if (!c.platform || !scheme) return; + + const platform = c.buildConfig?.platforms?.[c.platform]; + if (!platform) return; + + const definedEngine = platform.buildSchemes?.[scheme]?.engine; + if (definedEngine) { + platform.engine = definedEngine; + } }; diff --git a/packages/core/src/context/runtime.ts b/packages/core/src/context/runtime.ts index 377a36f43d..5af75c8c60 100644 --- a/packages/core/src/context/runtime.ts +++ b/packages/core/src/context/runtime.ts @@ -1,14 +1,17 @@ +import path from 'path'; import { getEngineRunnerByPlatform } from '../engines'; import { isSystemWin } from '../system/is'; -import { getRealPath } from '../system/fs'; +import { fsExistsSync, fsReadFileSync, getRealPath } from '../system/fs'; import { RnvContext, RnvContextPlatform } from './types'; import { generateRuntimePropInjects } from '../system/injectors'; import { getConfigProp } from './contextProps'; -import { logDefault } from '../logger'; +import { logDebug, logDefault } from '../logger'; export const configureRuntimeDefaults = async (c: RnvContext) => { - c.runtime.appId = c.files.project?.configLocal?._meta?.currentAppConfigId; - + c.runtime.appId = c.files.project?.configLocal?._meta?.currentAppConfigId || _getAppId(c); + if (c.runtime.appId) { + c.runtime.appConfigDir = path.join(c.paths.project.appConfigsDir, c.runtime.appId); + } logDefault('configureRuntimeDefaults', `appId:${c.runtime.appId}`); // TODO: @@ -77,3 +80,18 @@ export const configureRuntimeDefaults = async (c: RnvContext) => { } return true; }; + +const _getAppId = (c: RnvContext) => { + logDebug(`_getAppId`); + const localConfigPath = path.join(c.paths.project.dir, 'renative.local.json'); + if (!fsExistsSync(localConfigPath)) return undefined; + try { + const fileAsString = fsReadFileSync(localConfigPath).toString(); + if (!fileAsString) return undefined; + + const appId = JSON.parse(fileAsString)?._meta?.currentAppConfigId; + return appId; + } catch (error) { + return undefined; + } +};