From 6bea8062f23e4e6c3fb046751a63a084e5f7fe7d Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 28 Aug 2023 22:55:24 +0200 Subject: [PATCH 01/83] add initial types --- packages/rnv/src/cli/{index.js => index.ts} | 5 +-- packages/rnv/src/cli/{prompt.js => prompt.ts} | 32 ++++++++++++------- packages/rnv/src/cli/types.ts | 18 +++++++++++ .../configManager/{config.js => config.ts} | 28 ++++++++++------ packages/rnv/src/core/constants.ts | 3 +- packages/rnv/src/types.ts | 8 +++++ 6 files changed, 70 insertions(+), 24 deletions(-) rename packages/rnv/src/cli/{index.js => index.ts} (93%) rename packages/rnv/src/cli/{prompt.js => prompt.ts} (78%) create mode 100644 packages/rnv/src/cli/types.ts rename packages/rnv/src/core/configManager/{config.js => config.ts} (77%) create mode 100644 packages/rnv/src/types.ts diff --git a/packages/rnv/src/cli/index.js b/packages/rnv/src/cli/index.ts similarity index 93% rename from packages/rnv/src/cli/index.js rename to packages/rnv/src/cli/index.ts index 2255486569..a18a1ad5e9 100644 --- a/packages/rnv/src/cli/index.js +++ b/packages/rnv/src/cli/index.ts @@ -7,13 +7,14 @@ import { loadIntegrations } from '../core/integrationManager'; import { initializeTask, findSuitableTask } from '../core/taskManager'; import EngineCore from '../engine-core'; +import { RnvConfog } from '../types'; const IGNORE_MISSING_ENGINES_TASKS = ['link', 'unlink']; -const run = async (c) => { +const run = async (c: RnvConfog) => { await registerEngine(c, EngineCore); await configureRuntimeDefaults(c); - await checkAndMigrateProject(c); + await checkAndMigrateProject(); await updateRenativeConfigs(c); await checkAndBootstrapIfRequired(c); if (c.program.npxMode) { diff --git a/packages/rnv/src/cli/prompt.js b/packages/rnv/src/cli/prompt.ts similarity index 78% rename from packages/rnv/src/cli/prompt.js rename to packages/rnv/src/cli/prompt.ts index 9916c156f5..998f0af865 100644 --- a/packages/rnv/src/cli/prompt.js +++ b/packages/rnv/src/cli/prompt.ts @@ -1,8 +1,9 @@ import inquirer from 'inquirer'; import { chalk, logWarning, logTask, logDebug } from '../core/systemManager/logger'; import Config from '../core/configManager/config'; +import { PromptOptions, PromptParams } from './types'; -export const inquirerPrompt = async (params) => { +export const inquirerPrompt = async (params: PromptParams) => { const c = Config.getConfig(); if (c.program?.yes) return true; @@ -25,7 +26,7 @@ export const inquirerPrompt = async (params) => { const { type, name } = params; if (type === 'confirm' && !name) params.name = 'confirm'; - return inquirer.prompt(params); + return inquirer.prompt(params as any); }; export const pressAnyKeyToContinue = () => { @@ -34,20 +35,27 @@ export const pressAnyKeyToContinue = () => { name: 'confirm', message: 'Press any key to continue', }; - return inquirer.prompt(params); + return inquirer.prompt(params as any); }; -export const generateOptions = (inputData, isMultiChoice = false, mapping, renderMethod) => { +export const generateOptions = (inputData: any, isMultiChoice = false, mapping: any, renderMethod: any) => { logDebug('generateOptions', isMultiChoice); let asString = ''; - const valuesAsObject = {}; - const valuesAsArray = []; - const keysAsObject = {}; - const keysAsArray = []; - const optionsAsArray = []; + const valuesAsObject: Record = {}; + const valuesAsArray: Array = []; + const keysAsObject: Record = {}; + const keysAsArray: Array = []; + const optionsAsArray: Array = []; const isArray = Array.isArray(inputData); - const output = {}; + const output: PromptOptions = { + keysAsArray: [], + valuesAsArray: [], + keysAsObject: {}, + valuesAsObject: {}, + asString: '', + optionsAsArray: [], + }; const renderer = renderMethod || _generateOptionString; if (isArray) { inputData.forEach((v, i) => { @@ -81,7 +89,7 @@ export const generateOptions = (inputData, isMultiChoice = false, mapping, rende return output; }; -const _sort = (a, b) => { +const _sort = (a: any, b: any) => { let aStr = ''; let bStr = ''; if (typeof a === 'string') { @@ -103,5 +111,5 @@ const _sort = (a, b) => { return com; }; -const _generateOptionString = (i, obj, mapping, defaultVal) => +const _generateOptionString = (i: number, _obj: any, mapping: any, defaultVal: string) => ` [${chalk().bold.grey(i + 1)}]> ${chalk().bold.grey(mapping ? '' : defaultVal)} \n`; diff --git a/packages/rnv/src/cli/types.ts b/packages/rnv/src/cli/types.ts new file mode 100644 index 0000000000..6f088dc8ba --- /dev/null +++ b/packages/rnv/src/cli/types.ts @@ -0,0 +1,18 @@ +export type PromptOptions = { + keysAsArray: any; + valuesAsArray: any; + keysAsObject: any; + valuesAsObject: any; + asString: any; + optionsAsArray: any; +}; + +export type PromptParams = { + logMessage: string; + warningMessage: string; + message: string; + choices: any; + default: any; + name: string; + type: string; +}; diff --git a/packages/rnv/src/core/configManager/config.js b/packages/rnv/src/core/configManager/config.ts similarity index 77% rename from packages/rnv/src/core/configManager/config.js rename to packages/rnv/src/core/configManager/config.ts index 4bb50b92d6..c4c3954895 100644 --- a/packages/rnv/src/core/configManager/config.js +++ b/packages/rnv/src/core/configManager/config.ts @@ -1,13 +1,21 @@ import { writeFileSync, fsExistsSync } from '../systemManager/fileutils'; import { logWarning } from '../systemManager/logger'; import { configSchema } from '../constants'; +import { RnvConfog } from '../../types'; class Config { + config: RnvConfog; + constructor() { - this.config = {}; + this.config = { + program: {}, + command: {}, + paths: {}, + buildConfig: {}, + }; } - initializeConfig(c) { + initializeConfig(c: RnvConfog) { this.config = c; return c; } @@ -17,7 +25,7 @@ class Config { } // RNV CONFIG - getConfigValueSeparate(key, global = false) { + getConfigValueSeparate(key: string, global = false) { const { paths } = this.config; if (!global && !fsExistsSync(paths.project.config)) return 'N/A'; // string because there might be a setting where we will use null @@ -29,7 +37,7 @@ class Config { return value; } - getMergedConfigValue(key) { + getMergedConfigValue(key: string) { let value = this.config.buildConfig?.[configSchema[key].key]; if (value === undefined && configSchema[key].default) { value = configSchema[key].default; @@ -37,7 +45,7 @@ class Config { return value; } - listConfigValue(key) { + listConfigValue(key: string) { let localVal = this.getConfigValueSeparate(key).toString(); let globalVal = this.getConfigValueSeparate(key, true).toString(); @@ -46,7 +54,7 @@ class Config { } if (localVal === 'N/A') localVal = globalVal; - const table = [ + const table: Array> = [ { Key: key, 'Global Value': globalVal, @@ -60,7 +68,7 @@ class Config { return table; } - isConfigValueValid(key, value) { + isConfigValueValid(key: string, value: string | boolean) { const keySchema = configSchema[key]; if (!keySchema) { logWarning(`Unknown config param ${key}`); @@ -75,7 +83,7 @@ class Config { return true; } - setConfigValue(key, value) { + setConfigValue(key: string, value: string | boolean) { const { program: { global }, paths, @@ -86,7 +94,9 @@ class Config { const configPath = global ? paths.GLOBAL_RNV_CONFIG : paths.project.config; const config = require(configPath); - if (['true', 'false'].includes(isValid)) isValid = isValid === 'true'; // convert string to bool if it matches a bool value + if (typeof isValid === 'string') { + if (['true', 'false'].includes(isValid)) isValid = isValid === 'true'; // convert string to bool if it matches a bool value + } config[configSchema[key].key] = isValid; writeFileSync(configPath, config); diff --git a/packages/rnv/src/core/constants.ts b/packages/rnv/src/core/constants.ts index 8a66bd2b9a..01f4ba4349 100644 --- a/packages/rnv/src/core/constants.ts +++ b/packages/rnv/src/core/constants.ts @@ -1,6 +1,7 @@ // PLATFORM import { homedir } from 'os'; import path from 'path'; +import { RnvConfigSchema } from '../types'; export const USER_HOME_DIR = homedir(); export const RNV_HOME_DIR = path.join(__dirname, '../..'); @@ -539,7 +540,7 @@ export const PARAMS = { all: Object.keys(PARAM_KEYS), }; -export const configSchema = { +export const configSchema: RnvConfigSchema = { analytics: { values: ['true', 'false'], key: 'enableAnalytics', diff --git a/packages/rnv/src/types.ts b/packages/rnv/src/types.ts new file mode 100644 index 0000000000..0d5b3293f6 --- /dev/null +++ b/packages/rnv/src/types.ts @@ -0,0 +1,8 @@ +export interface RnvConfog { + program: any; + command: any; + paths: any; + buildConfig: any; +} + +export type RnvConfigSchema = Record; From b41dbbefe23ec5832b33078084decc457aa8877b Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 28 Aug 2023 23:56:25 +0200 Subject: [PATCH 02/83] add config types, package manager --- packages/rnv/src/cli/index.ts | 2 +- packages/rnv/src/core/configManager/config.ts | 6 +- .../core/configManager/{index.js => index.ts} | 63 +++++++++++-------- packages/rnv/src/core/configManager/types.ts | 35 +++++++++++ packages/rnv/src/core/constants.ts | 2 +- packages/rnv/src/types.ts | 8 --- 6 files changed, 79 insertions(+), 37 deletions(-) rename packages/rnv/src/core/configManager/{index.js => index.ts} (94%) create mode 100644 packages/rnv/src/core/configManager/types.ts delete mode 100644 packages/rnv/src/types.ts diff --git a/packages/rnv/src/cli/index.ts b/packages/rnv/src/cli/index.ts index a18a1ad5e9..f3bd329709 100644 --- a/packages/rnv/src/cli/index.ts +++ b/packages/rnv/src/cli/index.ts @@ -7,7 +7,7 @@ import { loadIntegrations } from '../core/integrationManager'; import { initializeTask, findSuitableTask } from '../core/taskManager'; import EngineCore from '../engine-core'; -import { RnvConfog } from '../types'; +import { RnvConfog } from '../core/configManager/types'; const IGNORE_MISSING_ENGINES_TASKS = ['link', 'unlink']; diff --git a/packages/rnv/src/core/configManager/config.ts b/packages/rnv/src/core/configManager/config.ts index c4c3954895..20889bb5cc 100644 --- a/packages/rnv/src/core/configManager/config.ts +++ b/packages/rnv/src/core/configManager/config.ts @@ -1,7 +1,7 @@ import { writeFileSync, fsExistsSync } from '../systemManager/fileutils'; import { logWarning } from '../systemManager/logger'; import { configSchema } from '../constants'; -import { RnvConfog } from '../../types'; +import { RnvConfog } from './types'; class Config { config: RnvConfog; @@ -12,6 +12,10 @@ class Config { command: {}, paths: {}, buildConfig: {}, + runtime: {}, + platform: '', + files: {}, + configPropsInjects: {}, }; } diff --git a/packages/rnv/src/core/configManager/index.js b/packages/rnv/src/core/configManager/index.ts similarity index 94% rename from packages/rnv/src/core/configManager/index.js rename to packages/rnv/src/core/configManager/index.ts index ece052b8a9..633a9257bb 100644 --- a/packages/rnv/src/core/configManager/index.js +++ b/packages/rnv/src/core/configManager/index.ts @@ -36,11 +36,12 @@ import { getConfigProp } from '../common'; import { getWorkspaceDirPath } from '../projectManager/workspace'; import { chalk, logError, logTask, logWarning, logDebug } from '../systemManager/logger'; import { doResolve } from '../systemManager/resolve'; +import { RnvConfigFileObj, RnvConfigPathObj, RnvConfog } from './types'; // import { loadPluginTemplates } from '../pluginManager'; const IGNORE_FOLDERS = ['.git']; -export const checkIsRenativeProject = (c) => +export const checkIsRenativeProject = (c: RnvConfog) => new Promise((resolve, reject) => { if (!c.paths.project.configExists) { return reject( @@ -50,10 +51,10 @@ export const checkIsRenativeProject = (c) => ); } - return resolve(); + return resolve(true); }); -const _generateConfigPaths = (pathObj, dir, configName) => { +const _generateConfigPaths = (pathObj: RnvConfigPathObj, dir: string, configName?: string) => { pathObj.dir = dir; pathObj.config = path.join(dir, configName || RENATIVE_CONFIG_NAME); pathObj.configLocal = path.join(dir, RENATIVE_CONFIG_LOCAL_NAME); @@ -61,15 +62,15 @@ const _generateConfigPaths = (pathObj, dir, configName) => { pathObj.appConfigsDir = path.join(dir, '..'); }; -const _arrayMergeOverride = (destinationArray, sourceArray) => sourceArray; +const _arrayMergeOverride = (_destinationArray: Array, sourceArray: Array) => sourceArray; -const getEnginesPluginDelta = (c) => { +const getEnginesPluginDelta = (c: RnvConfog) => { logDebug('getEnginesPluginDelta'); if (!c.buildConfig) return; - const enginePlugins = {}; - const missingEnginePlugins = {}; + const enginePlugins: Record = {}; + const missingEnginePlugins: Record = {}; const engineConfig = c.runtime.enginesByPlatform[c.platform]?.config; if (engineConfig?.plugins) { @@ -88,13 +89,13 @@ const getEnginesPluginDelta = (c) => { return enginePlugins; }; -export const writeRenativeConfigFile = (c, configPath, configData) => { +export const writeRenativeConfigFile = (c: RnvConfog, configPath: string, configData: string) => { logDebug(`writeRenativeConfigFile:${configPath}`); writeFileSync(configPath, configData); generateBuildConfig(c); }; -export const generateBuildConfig = (c) => { +export const generateBuildConfig = (c: RnvConfog) => { logDebug('generateBuildConfig'); const mergeOrder = [ @@ -129,7 +130,7 @@ export const generateBuildConfig = (c) => { return exists; }); - const pluginTemplates = {}; + const pluginTemplates: Record = {}; if (c.files.rnv.pluginTemplates.configs) { Object.keys(c.files.rnv.pluginTemplates.configs).forEach((v) => { const plgs = c.files.rnv.pluginTemplates.configs[v]; @@ -179,7 +180,7 @@ export const generateBuildConfig = (c) => { `generateBuildConfig:mergeOrder.length:${mergeOrder.length},cleanPaths.length:${cleanPaths.length},existsPaths.length:${existsPaths.length},existsFiles.length:${existsFiles.length}` ); - let out = merge.all([...meta, ...existsFiles], { + let out: any = merge.all([...meta, ...existsFiles], { arrayMerge: _arrayMergeOverride, }); out = merge({}, out); @@ -219,7 +220,12 @@ export const generateBuildConfig = (c) => { } }; -export const loadFileExtended = (c, fileObj, pathObj, key) => { +export const loadFileExtended = ( + c: RnvConfog, + fileObj: Record, + pathObj: RnvConfigPathObj, + key: string +) => { const result = loadFile(fileObj, pathObj, key); if (fileObj[key]) { fileObj[`${key}_original`] = { ...fileObj[key] }; @@ -257,10 +263,15 @@ export const loadFileExtended = (c, fileObj, pathObj, key) => { return result; }; -const _loadConfigFiles = (c, fileObj, pathObj, parseAppConfigs) => { +const _loadConfigFiles = ( + c: RnvConfog, + fileObj: RnvConfigFileObj, + pathObj: RnvConfigPathObj, + parseAppConfigs?: boolean +) => { let result = false; let extendAppId; - if (loadFileExtended(c, fileObj, pathObj, 'config', true)) { + if (loadFileExtended(c, fileObj, pathObj, 'config')) { extendAppId = fileObj.config.extend || extendAppId; result = true; } @@ -286,11 +297,11 @@ const _loadConfigFiles = (c, fileObj, pathObj, parseAppConfigs) => { fileObj.configs = []; fileObj.configsLocal = []; fileObj.configsPrivate = []; - const fileObj1 = {}; + const fileObj1: RnvConfigFileObj = {}; // PATH1: appConfigs/base const path1 = path.join(pathObj.appConfigsDir, 'base'); - const pathObj1 = { + const pathObj1: RnvConfigPathObj = { config: path.join(path1, RENATIVE_CONFIG_NAME), configLocal: path.join(path1, RENATIVE_CONFIG_LOCAL_NAME), configPrivate: path.join(path1, RENATIVE_CONFIG_PRIVATE_NAME), @@ -313,12 +324,12 @@ const _loadConfigFiles = (c, fileObj, pathObj, parseAppConfigs) => { const appConfigsDirNames = fsReaddirSync(pathObj.appConfigsDir); if (parseAppConfigs && extendAppId && appConfigsDirNames.includes(extendAppId)) { const path2 = path.join(pathObj.appConfigsDir, extendAppId); - const pathObj2 = { + const pathObj2: RnvConfigPathObj = { config: path.join(path2, RENATIVE_CONFIG_NAME), configLocal: path.join(path2, RENATIVE_CONFIG_LOCAL_NAME), configPrivate: path.join(path2, RENATIVE_CONFIG_PRIVATE_NAME), }; - const fileObj2 = {}; + const fileObj2: RnvConfigFileObj = {}; // PATH2: appConfigs/ pathObj.dirs.push(path2); pathObj.fontsDirs.push(path.join(path2, 'fonts')); @@ -382,7 +393,7 @@ export const generateRuntimeConfig = async (c) => { return true; }; -export const generateLocalConfig = (c, resetAppId) => { +export const generateLocalConfig = (c: RnvConfog, resetAppId?: boolean) => { logTask('generateLocalConfig', `resetAppId:${!!resetAppId}`); const configLocal = c.files.project.configLocal || {}; configLocal._meta = configLocal._meta || {}; @@ -395,7 +406,7 @@ export const generateLocalConfig = (c, resetAppId) => { writeFileSync(c.paths.project.configLocal, configLocal); }; -const _generatePlatformTemplatePaths = (c) => { +const _generatePlatformTemplatePaths = (c: RnvConfog) => { logTask('_generatePlatformTemplatePaths'); if (!c.buildConfig.paths) { logWarning(`You're missing paths object in your ${chalk().red(c.paths.project.config)}`); @@ -423,10 +434,10 @@ const _generatePlatformTemplatePaths = (c) => { ); } const pt = c.buildConfig.paths.platformTemplatesDirs || c.buildConfig.platformTemplatesDirs || {}; - const result = {}; + const result: Record = {}; if (c.buildConfig.defaults) { - c.buildConfig.defaults.supportedPlatforms.forEach((platform) => { + c.buildConfig.defaults.supportedPlatforms.forEach((platform: string) => { const engine = c.runtime.enginesByPlatform[platform]; if (engine) { const originalPath = engine.originalTemplatePlatformsDir; @@ -449,7 +460,7 @@ const _generatePlatformTemplatePaths = (c) => { return result; }; -export const listAppConfigsFoldersSync = (c, ignoreHiddenConfigs, appConfigsDirPath) => { +export const listAppConfigsFoldersSync = (c: RnvConfog, ignoreHiddenConfigs, appConfigsDirPath) => { logTask('listAppConfigsFoldersSync', `ignoreHiddenConfigs:${!!ignoreHiddenConfigs}`); if (!c.paths?.project) return []; @@ -457,7 +468,7 @@ export const listAppConfigsFoldersSync = (c, ignoreHiddenConfigs, appConfigsDirP const dirPath = appConfigsDirPath || c.paths.project.appConfigsDir; if (!fsExistsSync(dirPath)) return []; - const appConfigsDirs = []; + const appConfigsDirs: Array = []; fsReaddirSync(dirPath).forEach((dir) => { const appConfigDir = path.join(dirPath, dir); if (!IGNORE_FOLDERS.includes(dir) && fsLstatSync(appConfigDir).isDirectory()) { @@ -481,7 +492,7 @@ export const listAppConfigsFoldersSync = (c, ignoreHiddenConfigs, appConfigsDirP return appConfigsDirs; }; -const _loadWorkspacesSync = (c) => { +const _loadWorkspacesSync = (c: RnvConfog) => { // CHECK WORKSPACES if (fsExistsSync(c.paths.rnv.configWorkspaces)) { logDebug(`${c.paths.rnv.configWorkspaces} file exists!`); @@ -514,7 +525,7 @@ const _loadWorkspacesSync = (c) => { } }; -export const parseRenativeConfigs = async (c) => { +export const parseRenativeConfigs = async (c: RnvConfog) => { logTask('parseRenativeConfigs'); // LOAD ./package.json loadFile(c.files.project, c.paths.project, 'package'); diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts new file mode 100644 index 0000000000..b4c6561f74 --- /dev/null +++ b/packages/rnv/src/core/configManager/types.ts @@ -0,0 +1,35 @@ +export interface RnvConfog { + program: any; + command: any; + paths: any; + buildConfig: any; + runtime: any; + platform: string; + files: any; + configPropsInjects: any; +} + +export type RnvConfigSchema = Record; + +export interface RnvConfigPathObj { + dir: string; + config: string; + configLocal: string; + configPrivate: string; + appConfigsDir: string; + dirs: Array; + fontsDirs: Array; + pluginDirs: Array; + configs: Array; + configsLocal: Array; + configsPrivate: Array; +} + +export interface RnvConfigFileObj { + config: any; + configLocal: any; + configPrivate: any; + configs: Array; + configsLocal: Array; + configsPrivate: Array; +} diff --git a/packages/rnv/src/core/constants.ts b/packages/rnv/src/core/constants.ts index 01f4ba4349..b0142b62fc 100644 --- a/packages/rnv/src/core/constants.ts +++ b/packages/rnv/src/core/constants.ts @@ -1,7 +1,7 @@ // PLATFORM import { homedir } from 'os'; import path from 'path'; -import { RnvConfigSchema } from '../types'; +import { RnvConfigSchema } from './configManager/types'; export const USER_HOME_DIR = homedir(); export const RNV_HOME_DIR = path.join(__dirname, '../..'); diff --git a/packages/rnv/src/types.ts b/packages/rnv/src/types.ts deleted file mode 100644 index 0d5b3293f6..0000000000 --- a/packages/rnv/src/types.ts +++ /dev/null @@ -1,8 +0,0 @@ -export interface RnvConfog { - program: any; - command: any; - paths: any; - buildConfig: any; -} - -export type RnvConfigSchema = Record; From c0eb9a35bf043e56faa6f0fbf80e3bc3e91276cb Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Tue, 29 Aug 2023 00:36:48 +0200 Subject: [PATCH 03/83] rename files, main config defaults structure migrations --- packages/rnv/src/core/configManager/config.ts | 12 +- .../rnv/src/core/configManager/configBase.ts | 147 ++++++++++++ packages/rnv/src/core/configManager/index.ts | 160 +------------ .../{packageParser.js => packageParser.ts} | 0 .../{schemeParser.js => schemeParser.ts} | 0 packages/rnv/src/core/configManager/types.ts | 222 +++++++++++++++++- 6 files changed, 371 insertions(+), 170 deletions(-) create mode 100644 packages/rnv/src/core/configManager/configBase.ts rename packages/rnv/src/core/configManager/{packageParser.js => packageParser.ts} (100%) rename packages/rnv/src/core/configManager/{schemeParser.js => schemeParser.ts} (100%) diff --git a/packages/rnv/src/core/configManager/config.ts b/packages/rnv/src/core/configManager/config.ts index 20889bb5cc..dd320c8de1 100644 --- a/packages/rnv/src/core/configManager/config.ts +++ b/packages/rnv/src/core/configManager/config.ts @@ -2,21 +2,13 @@ import { writeFileSync, fsExistsSync } from '../systemManager/fileutils'; import { logWarning } from '../systemManager/logger'; import { configSchema } from '../constants'; import { RnvConfog } from './types'; +import { generateConfigBase } from './configBase'; class Config { config: RnvConfog; constructor() { - this.config = { - program: {}, - command: {}, - paths: {}, - buildConfig: {}, - runtime: {}, - platform: '', - files: {}, - configPropsInjects: {}, - }; + this.config = generateConfigBase(); } initializeConfig(c: RnvConfog) { diff --git a/packages/rnv/src/core/configManager/configBase.ts b/packages/rnv/src/core/configManager/configBase.ts new file mode 100644 index 0000000000..efda3f32b1 --- /dev/null +++ b/packages/rnv/src/core/configManager/configBase.ts @@ -0,0 +1,147 @@ +import { fsExistsSync, fsReadFileSync, fsReaddirSync, fsWriteFileSync } from '../systemManager/fileutils'; + +import path from 'path'; +import { RnvConfog } from './types'; + +export const generateConfigBase = (): RnvConfog => ({ + program: {}, + buildConfig: {}, + command: '', + subCommand: '', + platform: '', + process: {}, + //========== + _renativePluginCache: {}, + cli: {}, + api: { + fsExistsSync, + fsReadFileSync, + fsReaddirSync, + fsWriteFileSync, + path, + }, + configPropsInjects: {}, + runtime: { + enginesByPlatform: {}, + enginesByIndex: [], + enginesById: {}, + }, + paths: { + GLOBAL_RNV_CONFIG: '', + rnv: { + pluginTemplates: { + configs: {}, + }, + platformTemplates: {}, + projectTemplates: {}, + platformTemplate: {}, + plugins: {}, + engines: {}, + projectTemplate: {}, + }, + workspace: { + project: { + appConfigBase: {}, + builds: {}, + assets: {}, + platformTemplates: {}, + appConfigsDirs: [], + appConfigsDirNames: [], + }, + appConfig: { + configs: [], + configsPrivate: [], + configsLocal: [], + }, + }, + defaultWorkspace: { + project: { + appConfigBase: {}, + builds: {}, + assets: {}, + platformTemplates: {}, + appConfigsDirs: [], + appConfigsDirNames: [], + }, + appConfig: { + configs: [], + configsPrivate: [], + configsLocal: [], + }, + }, + project: { + config: '', + appConfigBase: {}, + builds: {}, + assets: {}, + platformTemplates: {}, + appConfigsDirs: [], + appConfigsDirNames: [], + }, + appConfig: { + configs: [], + configsPrivate: [], + configsLocal: [], + }, + // EXTRA + GLOBAL_RNV_DIR: '', + buildHooks: { + dist: {}, + }, + home: {}, + template: { + appConfigBase: {}, + builds: {}, + assets: {}, + platformTemplates: {}, + }, + }, + files: { + rnv: { + pluginTemplates: {}, + platformTemplates: {}, + projectTemplates: {}, + platformTemplate: {}, + plugins: {}, + engines: {}, + projectTemplate: {}, + }, + workspace: { + project: { + appConfigBase: {}, + builds: {}, + assets: {}, + platformTemplates: {}, + }, + appConfig: { + configs: [], + configsPrivate: [], + configsLocal: [], + }, + }, + defaultWorkspace: { + project: { + appConfigBase: {}, + builds: {}, + assets: {}, + platformTemplates: {}, + }, + appConfig: { + configs: [], + configsPrivate: [], + configsLocal: [], + }, + }, + project: { + appConfigBase: {}, + builds: {}, + assets: {}, + platformTemplates: {}, + }, + appConfig: { + configs: [], + configsPrivate: [], + configsLocal: [], + }, + }, +}); diff --git a/packages/rnv/src/core/configManager/index.ts b/packages/rnv/src/core/configManager/index.ts index 633a9257bb..46f215b562 100644 --- a/packages/rnv/src/core/configManager/index.ts +++ b/packages/rnv/src/core/configManager/index.ts @@ -28,7 +28,6 @@ import { fsReadFileSync, fsReaddirSync, fsLstatSync, - fsWriteFileSync, loadFile, formatBytes, } from '../systemManager/fileutils'; @@ -37,6 +36,7 @@ import { getWorkspaceDirPath } from '../projectManager/workspace'; import { chalk, logError, logTask, logWarning, logDebug } from '../systemManager/logger'; import { doResolve } from '../systemManager/resolve'; import { RnvConfigFileObj, RnvConfigPathObj, RnvConfog } from './types'; +import { generateConfigBase } from './configBase'; // import { loadPluginTemplates } from '../pluginManager'; const IGNORE_FOLDERS = ['.git']; @@ -412,27 +412,7 @@ const _generatePlatformTemplatePaths = (c: RnvConfog) => { logWarning(`You're missing paths object in your ${chalk().red(c.paths.project.config)}`); c.buildConfig.paths = {}; } - if (c.files.config?.platformTemplatesDirs) { - logWarning( - `DEPRECATED: platformTemplatesDirs in ${chalk().white( - c.paths.project.config - )} has been moved to engine config` - ); - } - if (c.files.config?.paths?.platformTemplatesDir) { - logWarning( - `DEPRECATED: paths.platformTemplatesDir in ${chalk().white( - c.paths.project.config - )} has been moved to engine config` - ); - } - if (c.files.config?.platformTemplatesDir) { - logWarning( - `DEPRECATED: platformTemplatesDir in ${chalk().white( - c.paths.project.config - )} has been moved to engine config` - ); - } + const pt = c.buildConfig.paths.platformTemplatesDirs || c.buildConfig.platformTemplatesDirs || {}; const result: Record = {}; @@ -609,140 +589,8 @@ export const parseRenativeConfigs = async (c: RnvConfog) => { } }; -export const createRnvConfig = (program, process, cmd, subCmd, { projectRoot } = {}) => { - const c = { - _renativePluginCache: {}, - cli: {}, - api: { - fsExistsSync, - fsReadFileSync, - fsReaddirSync, - fsWriteFileSync, - path, - }, - configPropsInjects: {}, - runtime: { - enginesByPlatform: {}, - enginesByIndex: [], - enginesById: {}, - }, - paths: { - rnv: { - pluginTemplates: { - configs: {}, - }, - platformTemplates: {}, - projectTemplates: {}, - platformTemplate: {}, - plugins: {}, - engines: {}, - projectTemplate: {}, - }, - workspace: { - project: { - appConfigBase: {}, - builds: {}, - assets: {}, - platformTemplates: {}, - appConfigsDirs: [], - appConfigsDirNames: [], - }, - appConfig: { - configs: [], - configsPrivate: [], - configsLocal: [], - }, - }, - defaultWorkspace: { - project: { - appConfigBase: {}, - builds: {}, - assets: {}, - platformTemplates: {}, - appConfigsDirs: [], - appConfigsDirNames: [], - }, - appConfig: { - configs: [], - configsPrivate: [], - configsLocal: [], - }, - }, - project: { - appConfigBase: {}, - builds: {}, - assets: {}, - platformTemplates: {}, - appConfigsDirs: [], - appConfigsDirNames: [], - }, - appConfig: { - configs: [], - configsPrivate: [], - configsLocal: [], - }, - // EXTRA - GLOBAL_RNV_DIR: '', - buildHooks: { - dist: {}, - }, - home: {}, - template: { - appConfigBase: {}, - builds: {}, - assets: {}, - platformTemplates: {}, - }, - }, - files: { - rnv: { - pluginTemplates: {}, - platformTemplates: {}, - projectTemplates: {}, - platformTemplate: {}, - plugins: {}, - engines: {}, - projectTemplate: {}, - }, - workspace: { - project: { - appConfigBase: {}, - builds: {}, - assets: {}, - platformTemplates: {}, - }, - appConfig: { - configs: [], - configsPrivate: [], - configsLocal: [], - }, - }, - defaultWorkspace: { - project: { - appConfigBase: {}, - builds: {}, - assets: {}, - platformTemplates: {}, - }, - appConfig: { - configs: [], - configsPrivate: [], - configsLocal: [], - }, - }, - project: { - appConfigBase: {}, - builds: {}, - assets: {}, - platformTemplates: {}, - }, - appConfig: { - configs: [], - configsPrivate: [], - configsLocal: [], - }, - }, - }; +export const createRnvConfig = (program: any, process: any, cmd: string, subCmd: string, { projectRoot } = {}) => { + const c: RnvConfog = generateConfigBase(); global.RNV_CONFIG = c; diff --git a/packages/rnv/src/core/configManager/packageParser.js b/packages/rnv/src/core/configManager/packageParser.ts similarity index 100% rename from packages/rnv/src/core/configManager/packageParser.js rename to packages/rnv/src/core/configManager/packageParser.ts diff --git a/packages/rnv/src/core/configManager/schemeParser.js b/packages/rnv/src/core/configManager/schemeParser.ts similarity index 100% rename from packages/rnv/src/core/configManager/schemeParser.js rename to packages/rnv/src/core/configManager/schemeParser.ts diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index b4c6561f74..a47ea1611c 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -1,12 +1,220 @@ export interface RnvConfog { program: any; - command: any; - paths: any; + command: string; + subCommand: string; buildConfig: any; - runtime: any; platform: string; - files: any; + process: any; + //======= + _renativePluginCache: any; + cli: any; + api: { + fsExistsSync: any; + fsReadFileSync: any; + fsReaddirSync: any; + fsWriteFileSync: any; + path: any; + }; configPropsInjects: any; + runtime: { + appId: string; + enginesByPlatform: any; + enginesByIndex: Array; + enginesById: Record; + missingEnginePlugins: Record; + }; + paths: { + GLOBAL_RNV_CONFIG: string; + GLOBAL_RNV_DIR: string; + //======= + rnv: { + configWorkspaces: any; + pluginTemplates: { + configs: Record; + //ADDON + dir: string; + config: string; + }; + platformTemplates: Record; + projectTemplates: Record; + platformTemplate: Record; + plugins: Record; + engines: Record; + projectTemplate: Record; + //ADDON + dir: string; + package: string; + // config: string; + // configLocal: string; + // configPrivate: string; + // appConfigsDir: string; + // dirs: Array; + // fontsDirs: Array; + // pluginDirs: Array; + // configs: Array; + // configsLocal: Array; + // configsPrivate: Array; + }; + workspace: { + project: { + appConfigBase: Record; + builds: Record; + assets: Record; + platformTemplates: Record; + appConfigsDirs: Array; + appConfigsDirNames: Array; + //ADDON + dir: string; + config: string; + configExists: boolean; + configLocal: string; + configPrivate: string; + appConfigsDir: string; + }; + appConfig: { + configs: Array; + configsPrivate: Array; + configsLocal: Array; + }; + //ADDON + config: string; + configLocal: string; + configPrivate: string; + dir: string; + }; + defaultWorkspace: { + //ADDON + config: string; + project: { + appConfigBase: Record; + builds: Record; + assets: Record; + platformTemplates: Record; + appConfigsDirs: Array; + appConfigsDirNames: Array; + }; + appConfig: { + configs: Array; + configsPrivate: Array; + configsLocal: Array; + }; + }; + project: { + config: string; + configExists: boolean; + appConfigBase: Record; + builds: Record; + assets: Record; + platformTemplates: Record; + appConfigsDirs: Array; + appConfigsDirNames: Array; + //ADDON + dir: string; + nodeModulesDir: string; + srcDir: string; + appConfigsDir: string; + package: string; + rnCliConfig: string; + babelConfig: string; + configLocal: string; + configPrivate: string; + platformTemplatesDirs: Record; + // appConfigsDir: string; + // dirs: Array; + // fontsDirs: Array; + // pluginDirs: Array; + // configs: Array; + // configsLocal: Array; + // configsPrivate: Array; + }; + appConfig: { + configs: Array; + configsPrivate: Array; + configsLocal: Array; + }; + // EXTRA + buildHooks: { + dist: Record; + //ADDON + dir: string; + index: string; + }; + home: Record; + template: { + appConfigBase: Record; + builds: Record; + assets: Record; + platformTemplates: Record; + }; + }; + files: { + rnv: { + pluginTemplates: Record; + platformTemplates: Record; + projectTemplates: Record; + platformTemplate: Record; + plugins: Record; + engines: Record; + projectTemplate: Record; + //ADDON + configWorkspaces: any; + package: any; + }; + workspace: { + project: { + appConfigBase: Record; + builds: Record; + assets: Record; + platformTemplates: Record; + //ADDON + config: any; + configLocal: any; + configPrivate: any; + }; + appConfig: { + configs: Array; + configsPrivate: Array; + configsLocal: Array; + }; + //ADDON + config: any; + configLocal: any; + configPrivate: any; + }; + defaultWorkspace: { + project: { + appConfigBase: Record; + builds: Record; + assets: Record; + platformTemplates: Record; + }; + appConfig: { + configs: Array; + configsPrivate: Array; + configsLocal: Array; + }; + //ADDON + config: any; + configLocal: any; + configPrivate: any; + }; + project: { + appConfigBase: Record; + builds: Record; + assets: Record; + platformTemplates: Record; + //ADDON + config: any; + configLocal: any; + configPrivate: any; + }; + appConfig: { + config?: any; + configs: Array; + configsPrivate: Array; + configsLocal: Array; + }; + }; } export type RnvConfigSchema = Record; @@ -23,6 +231,12 @@ export interface RnvConfigPathObj { configs: Array; configsLocal: Array; configsPrivate: Array; + // appConfigBase: Record; + // builds: Record; + // assets: Record; + // platformTemplates: Record; + // appConfigsDirs: Array; + // appConfigsDirNames: Array; } export interface RnvConfigFileObj { From dff8d9917983a1cd35ad8b7c82fb94d01555c5dd Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Tue, 29 Aug 2023 10:02:15 +0200 Subject: [PATCH 04/83] types refactor --- packages/rnv/src/cli/index.ts | 4 +-- packages/rnv/src/cli/prompt.ts | 3 +- packages/rnv/src/cli/types.ts | 8 ++--- packages/rnv/src/core/configManager/config.ts | 6 ++-- .../rnv/src/core/configManager/configBase.ts | 4 +-- packages/rnv/src/core/configManager/index.ts | 26 +++++++-------- .../src/core/configManager/packageParser.ts | 9 ++--- packages/rnv/src/core/configManager/types.ts | 33 ++++++++++--------- 8 files changed, 49 insertions(+), 44 deletions(-) diff --git a/packages/rnv/src/cli/index.ts b/packages/rnv/src/cli/index.ts index f3bd329709..78233a64cf 100644 --- a/packages/rnv/src/cli/index.ts +++ b/packages/rnv/src/cli/index.ts @@ -7,11 +7,11 @@ import { loadIntegrations } from '../core/integrationManager'; import { initializeTask, findSuitableTask } from '../core/taskManager'; import EngineCore from '../engine-core'; -import { RnvConfog } from '../core/configManager/types'; +import { RnvConfig } from '../core/configManager/types'; const IGNORE_MISSING_ENGINES_TASKS = ['link', 'unlink']; -const run = async (c: RnvConfog) => { +const run = async (c: RnvConfig) => { await registerEngine(c, EngineCore); await configureRuntimeDefaults(c); await checkAndMigrateProject(); diff --git a/packages/rnv/src/cli/prompt.ts b/packages/rnv/src/cli/prompt.ts index 998f0af865..ca977333ba 100644 --- a/packages/rnv/src/cli/prompt.ts +++ b/packages/rnv/src/cli/prompt.ts @@ -26,7 +26,8 @@ export const inquirerPrompt = async (params: PromptParams) => { const { type, name } = params; if (type === 'confirm' && !name) params.name = 'confirm'; - return inquirer.prompt(params as any); + const resp = inquirer.prompt(params as any); + return resp; }; export const pressAnyKeyToContinue = () => { diff --git a/packages/rnv/src/cli/types.ts b/packages/rnv/src/cli/types.ts index 6f088dc8ba..a175366999 100644 --- a/packages/rnv/src/cli/types.ts +++ b/packages/rnv/src/cli/types.ts @@ -8,11 +8,11 @@ export type PromptOptions = { }; export type PromptParams = { - logMessage: string; - warningMessage: string; + logMessage?: string; + warningMessage?: string; message: string; - choices: any; - default: any; + choices?: any; + default?: any; name: string; type: string; }; diff --git a/packages/rnv/src/core/configManager/config.ts b/packages/rnv/src/core/configManager/config.ts index dd320c8de1..3eace80f1e 100644 --- a/packages/rnv/src/core/configManager/config.ts +++ b/packages/rnv/src/core/configManager/config.ts @@ -1,17 +1,17 @@ import { writeFileSync, fsExistsSync } from '../systemManager/fileutils'; import { logWarning } from '../systemManager/logger'; import { configSchema } from '../constants'; -import { RnvConfog } from './types'; +import { RnvConfig } from './types'; import { generateConfigBase } from './configBase'; class Config { - config: RnvConfog; + config: RnvConfig; constructor() { this.config = generateConfigBase(); } - initializeConfig(c: RnvConfog) { + initializeConfig(c: RnvConfig) { this.config = c; return c; } diff --git a/packages/rnv/src/core/configManager/configBase.ts b/packages/rnv/src/core/configManager/configBase.ts index efda3f32b1..759b383e1a 100644 --- a/packages/rnv/src/core/configManager/configBase.ts +++ b/packages/rnv/src/core/configManager/configBase.ts @@ -1,9 +1,9 @@ import { fsExistsSync, fsReadFileSync, fsReaddirSync, fsWriteFileSync } from '../systemManager/fileutils'; import path from 'path'; -import { RnvConfog } from './types'; +import { RnvConfig } from './types'; -export const generateConfigBase = (): RnvConfog => ({ +export const generateConfigBase = (): RnvConfig => ({ program: {}, buildConfig: {}, command: '', diff --git a/packages/rnv/src/core/configManager/index.ts b/packages/rnv/src/core/configManager/index.ts index 46f215b562..0c2a216813 100644 --- a/packages/rnv/src/core/configManager/index.ts +++ b/packages/rnv/src/core/configManager/index.ts @@ -35,13 +35,13 @@ import { getConfigProp } from '../common'; import { getWorkspaceDirPath } from '../projectManager/workspace'; import { chalk, logError, logTask, logWarning, logDebug } from '../systemManager/logger'; import { doResolve } from '../systemManager/resolve'; -import { RnvConfigFileObj, RnvConfigPathObj, RnvConfog } from './types'; +import { RnvConfigFileObj, RnvConfigPathObj, RnvConfig } from './types'; import { generateConfigBase } from './configBase'; // import { loadPluginTemplates } from '../pluginManager'; const IGNORE_FOLDERS = ['.git']; -export const checkIsRenativeProject = (c: RnvConfog) => +export const checkIsRenativeProject = (c: RnvConfig) => new Promise((resolve, reject) => { if (!c.paths.project.configExists) { return reject( @@ -64,7 +64,7 @@ const _generateConfigPaths = (pathObj: RnvConfigPathObj, dir: string, configName const _arrayMergeOverride = (_destinationArray: Array, sourceArray: Array) => sourceArray; -const getEnginesPluginDelta = (c: RnvConfog) => { +const getEnginesPluginDelta = (c: RnvConfig) => { logDebug('getEnginesPluginDelta'); if (!c.buildConfig) return; @@ -89,13 +89,13 @@ const getEnginesPluginDelta = (c: RnvConfog) => { return enginePlugins; }; -export const writeRenativeConfigFile = (c: RnvConfog, configPath: string, configData: string) => { +export const writeRenativeConfigFile = (c: RnvConfig, configPath: string, configData: string) => { logDebug(`writeRenativeConfigFile:${configPath}`); writeFileSync(configPath, configData); generateBuildConfig(c); }; -export const generateBuildConfig = (c: RnvConfog) => { +export const generateBuildConfig = (c: RnvConfig) => { logDebug('generateBuildConfig'); const mergeOrder = [ @@ -221,7 +221,7 @@ export const generateBuildConfig = (c: RnvConfog) => { }; export const loadFileExtended = ( - c: RnvConfog, + c: RnvConfig, fileObj: Record, pathObj: RnvConfigPathObj, key: string @@ -264,7 +264,7 @@ export const loadFileExtended = ( }; const _loadConfigFiles = ( - c: RnvConfog, + c: RnvConfig, fileObj: RnvConfigFileObj, pathObj: RnvConfigPathObj, parseAppConfigs?: boolean @@ -393,7 +393,7 @@ export const generateRuntimeConfig = async (c) => { return true; }; -export const generateLocalConfig = (c: RnvConfog, resetAppId?: boolean) => { +export const generateLocalConfig = (c: RnvConfig, resetAppId?: boolean) => { logTask('generateLocalConfig', `resetAppId:${!!resetAppId}`); const configLocal = c.files.project.configLocal || {}; configLocal._meta = configLocal._meta || {}; @@ -406,7 +406,7 @@ export const generateLocalConfig = (c: RnvConfog, resetAppId?: boolean) => { writeFileSync(c.paths.project.configLocal, configLocal); }; -const _generatePlatformTemplatePaths = (c: RnvConfog) => { +const _generatePlatformTemplatePaths = (c: RnvConfig) => { logTask('_generatePlatformTemplatePaths'); if (!c.buildConfig.paths) { logWarning(`You're missing paths object in your ${chalk().red(c.paths.project.config)}`); @@ -440,7 +440,7 @@ const _generatePlatformTemplatePaths = (c: RnvConfog) => { return result; }; -export const listAppConfigsFoldersSync = (c: RnvConfog, ignoreHiddenConfigs, appConfigsDirPath) => { +export const listAppConfigsFoldersSync = (c: RnvConfig, ignoreHiddenConfigs, appConfigsDirPath) => { logTask('listAppConfigsFoldersSync', `ignoreHiddenConfigs:${!!ignoreHiddenConfigs}`); if (!c.paths?.project) return []; @@ -472,7 +472,7 @@ export const listAppConfigsFoldersSync = (c: RnvConfog, ignoreHiddenConfigs, app return appConfigsDirs; }; -const _loadWorkspacesSync = (c: RnvConfog) => { +const _loadWorkspacesSync = (c: RnvConfig) => { // CHECK WORKSPACES if (fsExistsSync(c.paths.rnv.configWorkspaces)) { logDebug(`${c.paths.rnv.configWorkspaces} file exists!`); @@ -505,7 +505,7 @@ const _loadWorkspacesSync = (c: RnvConfog) => { } }; -export const parseRenativeConfigs = async (c: RnvConfog) => { +export const parseRenativeConfigs = async (c: RnvConfig) => { logTask('parseRenativeConfigs'); // LOAD ./package.json loadFile(c.files.project, c.paths.project, 'package'); @@ -590,7 +590,7 @@ export const parseRenativeConfigs = async (c: RnvConfog) => { }; export const createRnvConfig = (program: any, process: any, cmd: string, subCmd: string, { projectRoot } = {}) => { - const c: RnvConfog = generateConfigBase(); + const c: RnvConfig = generateConfigBase(); global.RNV_CONFIG = c; diff --git a/packages/rnv/src/core/configManager/packageParser.ts b/packages/rnv/src/core/configManager/packageParser.ts index efb709698f..4083ce118f 100644 --- a/packages/rnv/src/core/configManager/packageParser.ts +++ b/packages/rnv/src/core/configManager/packageParser.ts @@ -10,8 +10,9 @@ import { writeRenativeConfigFile } from './index'; import { overrideTemplatePlugins } from '../pluginManager'; import { configureFonts } from '../projectManager'; import { getConfigProp } from '../common'; +import { DependencyType, RnvConfig } from './types'; -const injectProjectDependency = async (c, dependency, version, type, skipInstall = false) => { +const injectProjectDependency = async (c: RnvConfig, dependency, version, type, skipInstall = false) => { logTask('injectProjectDependency'); const currentPackage = c.files.project.package; @@ -28,10 +29,10 @@ const injectProjectDependency = async (c, dependency, version, type, skipInstall }; export const checkRequiredPackage = async ( - c, - pkg, + c: RnvConfig, + pkg: string, version = false, - type, + type: DependencyType = 'dependencies', skipAsking = false, skipInstall = false, skipVersionCheck = false diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index a47ea1611c..f0f0b8e71b 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -1,4 +1,4 @@ -export interface RnvConfog { +export interface RnvConfig { program: any; command: string; subCommand: string; @@ -32,8 +32,8 @@ export interface RnvConfog { pluginTemplates: { configs: Record; //ADDON - dir: string; - config: string; + dir?: string; + config?: string; }; platformTemplates: Record; projectTemplates: Record; @@ -42,8 +42,8 @@ export interface RnvConfog { engines: Record; projectTemplate: Record; //ADDON - dir: string; - package: string; + dir?: string; + package?: string; // config: string; // configLocal: string; // configPrivate: string; @@ -64,12 +64,12 @@ export interface RnvConfog { appConfigsDirs: Array; appConfigsDirNames: Array; //ADDON - dir: string; - config: string; - configExists: boolean; - configLocal: string; - configPrivate: string; - appConfigsDir: string; + dir?: string; + config?: string; + configExists?: boolean; + configLocal?: string; + configPrivate?: string; + appConfigsDir?: string; }; appConfig: { configs: Array; @@ -77,10 +77,10 @@ export interface RnvConfog { configsLocal: Array; }; //ADDON - config: string; - configLocal: string; - configPrivate: string; - dir: string; + config?: string; + configLocal?: string; + configPrivate?: string; + dir?: string; }; defaultWorkspace: { //ADDON @@ -207,6 +207,7 @@ export interface RnvConfog { config: any; configLocal: any; configPrivate: any; + package: any; }; appConfig: { config?: any; @@ -217,6 +218,8 @@ export interface RnvConfog { }; } +export type DependencyType = 'devDependencies' | 'dependencies' | 'peerDependencies'; + export type RnvConfigSchema = Record; export interface RnvConfigPathObj { From fbed06d2bbfe091336ca424096098e4d0989e672 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Tue, 29 Aug 2023 10:19:50 +0200 Subject: [PATCH 05/83] exec types --- .../src/core/configManager/packageParser.ts | 8 ++- packages/rnv/src/core/configManager/types.ts | 1 + .../core/systemManager/{exec.js => exec.ts} | 58 ++++++++++--------- packages/rnv/src/core/systemManager/types.ts | 17 ++++++ 4 files changed, 56 insertions(+), 28 deletions(-) rename packages/rnv/src/core/systemManager/{exec.js => exec.ts} (88%) create mode 100644 packages/rnv/src/core/systemManager/types.ts diff --git a/packages/rnv/src/core/configManager/packageParser.ts b/packages/rnv/src/core/configManager/packageParser.ts index 4083ce118f..c963ecdb8a 100644 --- a/packages/rnv/src/core/configManager/packageParser.ts +++ b/packages/rnv/src/core/configManager/packageParser.ts @@ -12,7 +12,13 @@ import { configureFonts } from '../projectManager'; import { getConfigProp } from '../common'; import { DependencyType, RnvConfig } from './types'; -const injectProjectDependency = async (c: RnvConfig, dependency, version, type, skipInstall = false) => { +const injectProjectDependency = async ( + c: RnvConfig, + dependency: string, + version: string, + type: DependencyType, + skipInstall = false +) => { logTask('injectProjectDependency'); const currentPackage = c.files.project.package; diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index f0f0b8e71b..131cfec29c 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -22,6 +22,7 @@ export interface RnvConfig { enginesByIndex: Array; enginesById: Record; missingEnginePlugins: Record; + localhost: string; }; paths: { GLOBAL_RNV_CONFIG: string; diff --git a/packages/rnv/src/core/systemManager/exec.js b/packages/rnv/src/core/systemManager/exec.ts similarity index 88% rename from packages/rnv/src/core/systemManager/exec.js rename to packages/rnv/src/core/systemManager/exec.ts index a5ced55c53..4271b20ba3 100755 --- a/packages/rnv/src/core/systemManager/exec.js +++ b/packages/rnv/src/core/systemManager/exec.ts @@ -4,7 +4,7 @@ import path from 'path'; import { access, accessSync, constants } from 'fs'; -import execa from 'execa'; +import execa, { ExecaChildProcess } from 'execa'; import NClient from 'netcat/client'; import ora from '../../cli/ora'; import Config from '../configManager/config'; @@ -12,6 +12,8 @@ import Config from '../configManager/config'; import { chalk, logDebug, logRaw, logError } from './logger'; import { fsExistsSync } from './fileutils'; import { replaceOverridesInString } from './utils'; +import { RnvConfig } from '../configManager/types'; +import { ExecOptions } from './types'; const { exec, execSync } = require('child_process'); @@ -33,8 +35,8 @@ const { exec, execSync } = require('child_process'); * @returns {Promise} * */ -const _execute = (c, command, opts = {}) => { - const defaultOpts = { +const _execute = (c: RnvConfig, command: string, opts: ExecOptions = {}) => { + const defaultOpts: ExecOptions = { stdio: 'pipe', localDir: path.resolve('./node_modules/.bin'), preferLocal: true, @@ -59,7 +61,7 @@ const _execute = (c, command, opts = {}) => { : null; let cleanCommand = command; - let interval; + let interval: NodeJS.Timer; const intervalTimer = 30000; // 30s let timer = intervalTimer; const privateMask = '*******'; @@ -87,7 +89,7 @@ const _execute = (c, command, opts = {}) => { timer += intervalTimer; }, intervalTimer); } - let child; + let child: ExecaChildProcess; if (opts.rawCommand) { const { args } = opts.rawCommand; child = execa(command, args, mergedOpts); @@ -100,8 +102,10 @@ const _execute = (c, command, opts = {}) => { const printLastLine = (buffer) => { const text = Buffer.from(buffer).toString().trim(); const lastLine = text.split('\n').pop(); - spinner.text = replaceOverridesInString(lastLine.substring(0, MAX_OUTPUT_LENGTH), privateParams, privateMask); - if (lastLine.length === MAX_OUTPUT_LENGTH) spinner.text += '...\n'; + spinner.text = replaceOverridesInString(lastLine?.substring(0, MAX_OUTPUT_LENGTH), privateParams, privateMask); + if (lastLine?.length === MAX_OUTPUT_LENGTH) { + if (spinner !== false) spinner.text += '...\n'; + } }; if (c.program?.info && child?.stdout?.pipe) { @@ -116,7 +120,7 @@ const _execute = (c, command, opts = {}) => { spinner && child.stdout.off('data', printLastLine); } - !silent && !mono && spinner.succeed(`Executing: ${logMessage}`); + !silent && !mono && !!spinner && spinner.succeed(`Executing: ${logMessage}`); logDebug(replaceOverridesInString(res.all, privateParams, privateMask)); interval && clearInterval(interval); // logDebug(res); @@ -127,13 +131,13 @@ const _execute = (c, command, opts = {}) => { spinner && child.stdout.off('data', printLastLine); } - if (!silent && !mono && !ignoreErrors) { + if (!silent && !mono && !ignoreErrors && !!spinner) { spinner.fail(`FAILED: ${logMessage}`); } // parseErrorMessage will return false if nothing is found, default to previous implementation logDebug(replaceOverridesInString(err.all, privateParams, privateMask)); interval && clearInterval(interval); // logDebug(err); - if (ignoreErrors && !silent && !mono) { + if (ignoreErrors && !silent && !mono && !!spinner) { spinner.succeed(`Executing: ${logMessage}`); return true; } @@ -175,7 +179,7 @@ const _execute = (c, command, opts = {}) => { * @returns {Promise} * */ -const execCLI = (c, cli, command, opts = {}) => { +const execCLI = (c: RnvConfig, cli: string, command: string, opts: ExecOptions = {}) => { if (!c.program) { return Promise.reject('You need to pass c object as first parameter to execCLI()'); } @@ -207,7 +211,7 @@ const execCLI = (c, cli, command, opts = {}) => { * @returns {Promise} * */ -const executeAsync = async (_c, _cmd, _opts) => { +const executeAsync = async (_c: RnvConfig, _cmd: string, _opts: ExecOptions) => { // swap values if c is not specified and get it from it's rightful place, config :) let c = _c; let cmd = _cmd; @@ -255,7 +259,7 @@ const executeAsync = async (_c, _cmd, _opts) => { * @returns {Promise} * */ -const executeTelnet = (c, port, command) => +const executeTelnet = (c: RnvConfig, port: string, command: string) => new Promise((resolve) => { logDebug(`execTelnet: ${port} ${command}`); try { @@ -270,7 +274,7 @@ const executeTelnet = (c, port, command) => nc2.on('close', () => resolve(output)); } catch (e) { logError(e); - resolve(); + resolve(true); } }); @@ -293,7 +297,7 @@ const executeTelnet = (c, port, command) => // return extractError(text); // }; -export const parseErrorMessage = (text, maxErrorLength = 800) => { +export const parseErrorMessage = (text: string, maxErrorLength = 800) => { if (!text) return ''; // Gradle specific const gradleFailIndex = text.indexOf('FAILURE: Build failed with an exception.'); @@ -365,13 +369,13 @@ export const parseErrorMessage = (text, maxErrorLength = 800) => { const isUsingWindows = process.platform === 'win32'; -const fileNotExists = (commandName, callback) => { +const fileNotExists = (commandName: string, callback) => { access(commandName, constants.F_OK, (err) => { callback(!err); }); }; -const fileNotExistsSync = (commandName) => { +const fileNotExistsSync = (commandName: string) => { try { accessSync(commandName, constants.F_OK); return false; @@ -380,13 +384,13 @@ const fileNotExistsSync = (commandName) => { } }; -const localExecutable = (commandName, callback) => { +const localExecutable = (commandName: string, callback) => { access(commandName, constants.F_OK | constants.X_OK, (err) => { callback(null, !err); }); }; -const localExecutableSync = (commandName) => { +const localExecutableSync = (commandName: string) => { try { accessSync(commandName, constants.F_OK | constants.X_OK); return true; @@ -395,8 +399,8 @@ const localExecutableSync = (commandName) => { } }; -const commandExistsUnix = (commandName, cleanedCommandName, callback) => { - fileNotExists(commandName, (isFile) => { +const commandExistsUnix = (commandName: string, cleanedCommandName: string, callback) => { + fileNotExists(commandName, (isFile: boolean) => { if (!isFile) { exec( `command -v ${cleanedCommandName} 2>/dev/null` + ` && { echo >&1 ${cleanedCommandName}; exit 0; }`, @@ -411,7 +415,7 @@ const commandExistsUnix = (commandName, cleanedCommandName, callback) => { }); }; -const commandExistsWindows = (commandName, cleanedCommandName, callback) => { +const commandExistsWindows = (commandName: string, cleanedCommandName: string, callback) => { if (/[\x00-\x1f<>:"|?*]/.test(commandName)) { callback(null, false); return; @@ -425,7 +429,7 @@ const commandExistsWindows = (commandName, cleanedCommandName, callback) => { }); }; -const commandExistsUnixSync = (commandName, cleanedCommandName) => { +const commandExistsUnixSync = (commandName: string, cleanedCommandName: string) => { if (fileNotExistsSync(commandName)) { try { const stdout = execSync( @@ -439,7 +443,7 @@ const commandExistsUnixSync = (commandName, cleanedCommandName) => { return localExecutableSync(commandName); }; -const commandExistsWindowsSync = (commandName, cleanedCommandName) => { +const commandExistsWindowsSync = (commandName: string, cleanedCommandName: string) => { if (/[\x00-\x1f<>:"|?*]/.test(commandName)) { return false; } @@ -451,7 +455,7 @@ const commandExistsWindowsSync = (commandName, cleanedCommandName) => { } }; -let cleanInput = (_s) => { +let cleanInput = (_s: string) => { let s = _s; if (/[^A-Za-z0-9_/:=-]/.test(s)) { s = `'${s.replace(/'/g, "'\\''")}'`; @@ -474,7 +478,7 @@ if (isUsingWindows) { }; } -const commandExists = (commandName, callback) => { +const commandExists = (commandName: string, callback) => { const cleanedCommandName = cleanInput(commandName); if (!callback && typeof Promise !== 'undefined') { return new Promise((resolve, reject) => { @@ -494,7 +498,7 @@ const commandExists = (commandName, callback) => { } }; -const commandExistsSync = (commandName) => { +const commandExistsSync = (commandName: string) => { const cleanedCommandName = cleanInput(commandName); if (isUsingWindows) { return commandExistsWindowsSync(commandName, cleanedCommandName); diff --git a/packages/rnv/src/core/systemManager/types.ts b/packages/rnv/src/core/systemManager/types.ts new file mode 100644 index 0000000000..46c56621ca --- /dev/null +++ b/packages/rnv/src/core/systemManager/types.ts @@ -0,0 +1,17 @@ +export type ExecOptions = { + interactive?: boolean; + silent?: boolean; + stdio?: 'pipe' | 'inherit'; + shell?: boolean; + localDir?: string; + preferLocal?: boolean; + all?: boolean; + maxErrorLength?: number; + mono?: boolean; + rawCommand?: { + args: Array; + }; + privateParams?: Array; + env?: Record; + ignoreErrors?: boolean; +}; From 55a22ce668e67d307bc90507c6f7306fd3a66db6 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Tue, 29 Aug 2023 10:30:42 +0200 Subject: [PATCH 06/83] rename files --- packages/rnv/src/core/adapter/{index.js => index.ts} | 0 packages/rnv/src/core/{common.js => common.ts} | 0 packages/rnv/src/core/engineManager/{index.js => index.ts} | 0 packages/rnv/src/core/integrationManager/{index.js => index.ts} | 0 packages/rnv/src/core/platformManager/{index.js => index.ts} | 0 packages/rnv/src/core/pluginManager/{index.js => index.ts} | 0 .../rnv/src/core/projectManager/{buildHooks.js => buildHooks.ts} | 0 packages/rnv/src/core/projectManager/{index.js => index.ts} | 0 packages/rnv/src/core/projectManager/{migrator.js => migrator.ts} | 0 packages/rnv/src/core/projectManager/{package.js => package.ts} | 0 .../rnv/src/core/projectManager/{workspace.js => workspace.ts} | 0 packages/rnv/src/core/runtimeManager/{index.js => index.ts} | 0 packages/rnv/src/core/schemaManager/{index.js => index.ts} | 0 .../{schemaRenativeJson.js => schemaRenativeJson.ts} | 0 .../{schemaRuntimeObject.js => schemaRuntimeObject.ts} | 0 .../src/core/sdkManager/deviceUtils/{android.js => android.ts} | 0 .../rnv/src/core/sdkManager/deviceUtils/{apple.js => apple.ts} | 0 .../rnv/src/core/sdkManager/deviceUtils/{common.js => common.ts} | 0 .../rnv/src/core/sdkManager/deviceUtils/{kaios.js => kaios.ts} | 0 .../rnv/src/core/sdkManager/deviceUtils/{tizen.js => tizen.ts} | 0 .../rnv/src/core/sdkManager/deviceUtils/{webos.js => webos.ts} | 0 packages/rnv/src/core/sdkManager/{index.js => index.ts} | 0 packages/rnv/src/core/sdkManager/{installer.js => installer.ts} | 0 packages/rnv/src/core/setupManager/{base.js => base.ts} | 0 packages/rnv/src/core/setupManager/{config.js => config.ts} | 0 packages/rnv/src/core/setupManager/{darwin.js => darwin.ts} | 0 packages/rnv/src/core/setupManager/{index.js => index.ts} | 0 packages/rnv/src/core/setupManager/{linux.js => linux.ts} | 0 packages/rnv/src/core/setupManager/{windows.js => windows.ts} | 0 .../rnv/src/core/systemManager/{analytics.js => analytics.ts} | 0 packages/rnv/src/core/systemManager/{crypto.js => crypto.ts} | 0 packages/rnv/src/core/systemManager/{doctor.js => doctor.ts} | 0 .../rnv/src/core/systemManager/{fileutils.js => fileutils.ts} | 0 packages/rnv/src/core/systemManager/{gitUtils.js => gitUtils.ts} | 0 packages/rnv/src/core/systemManager/{logger.js => logger.ts} | 0 packages/rnv/src/core/systemManager/{npmUtils.js => npmUtils.ts} | 0 .../rnv/src/core/systemManager/{objectUtils.js => objectUtils.ts} | 0 packages/rnv/src/core/systemManager/{resolve.js => resolve.ts} | 0 packages/rnv/src/core/systemManager/{utils.js => utils.ts} | 0 packages/rnv/src/core/taskManager/{index.js => index.ts} | 0 packages/rnv/src/core/templateManager/{index.js => index.ts} | 0 packages/rnv/src/engine-core/{index.js => index.ts} | 0 .../{task.rnv.app.configure.js => task.rnv.app.configure.ts} | 0 .../tasks/{task.rnv.app.create.js => task.rnv.app.create.ts} | 0 .../engine-core/tasks/{task.rnv.clean.js => task.rnv.clean.ts} | 0 .../engine-core/tasks/{task.rnv.config.js => task.rnv.config.ts} | 0 .../{task.rnv.configureSoft.js => task.rnv.configureSoft.ts} | 0 .../{task.rnv.crypto.decrypt.js => task.rnv.crypto.decrypt.ts} | 0 .../{task.rnv.crypto.encrypt.js => task.rnv.crypto.encrypt.ts} | 0 .../engine-core/tasks/{task.rnv.doctor.js => task.rnv.doctor.ts} | 0 .../tasks/{task.rnv.fastlane.js => task.rnv.fastlane.ts} | 0 .../src/engine-core/tasks/{task.rnv.help.js => task.rnv.help.ts} | 0 .../tasks/{task.rnv.hooks.list.js => task.rnv.hooks.list.ts} | 0 .../tasks/{task.rnv.hooks.pipes.js => task.rnv.hooks.pipes.ts} | 0 .../tasks/{task.rnv.hooks.run.js => task.rnv.hooks.run.ts} | 0 .../tasks/{task.rnv.install.js => task.rnv.install.ts} | 0 .../src/engine-core/tasks/{task.rnv.kill.js => task.rnv.kill.ts} | 0 .../src/engine-core/tasks/{task.rnv.link.js => task.rnv.link.ts} | 0 .../src/engine-core/tasks/{task.rnv.new.js => task.rnv.new.ts} | 0 .../src/engine-core/tasks/{task.rnv.pkg.js => task.rnv.pkg.ts} | 0 ...k.rnv.platform.configure.js => task.rnv.platform.configure.ts} | 0 ...{task.rnv.platform.connect.js => task.rnv.platform.connect.ts} | 0 .../{task.rnv.platform.eject.js => task.rnv.platform.eject.ts} | 0 .../{task.rnv.platform.list.js => task.rnv.platform.list.ts} | 0 .../{task.rnv.platform.setup.js => task.rnv.platform.setup.ts} | 0 .../tasks/{task.rnv.plugin.add.js => task.rnv.plugin.add.ts} | 0 .../tasks/{task.rnv.plugin.list.js => task.rnv.plugin.list.ts} | 0 .../{task.rnv.plugin.update.js => task.rnv.plugin.update.ts} | 0 ...ask.rnv.project.configure.js => task.rnv.project.configure.ts} | 0 .../{task.rnv.project.upgrade.js => task.rnv.project.upgrade.ts} | 0 .../tasks/{task.rnv.publish.js => task.rnv.publish.ts} | 0 .../engine-core/tasks/{task.rnv.status.js => task.rnv.status.ts} | 0 .../engine-core/tasks/{task.rnv.switch.js => task.rnv.switch.ts} | 0 .../{task.rnv.target.launch.js => task.rnv.target.launch.ts} | 0 .../tasks/{task.rnv.target.list.js => task.rnv.target.list.ts} | 0 .../tasks/{task.rnv.template.add.js => task.rnv.template.add.ts} | 0 .../{task.rnv.template.apply.js => task.rnv.template.apply.ts} | 0 .../{task.rnv.template.list.js => task.rnv.template.list.ts} | 0 .../engine-core/tasks/{task.rnv.unlink.js => task.rnv.unlink.ts} | 0 .../{task.rnv.workspace.add.js => task.rnv.workspace.add.ts} | 0 ...rnv.workspace.configure.js => task.rnv.workspace.configure.ts} | 0 ...ask.rnv.workspace.connect.js => task.rnv.workspace.connect.ts} | 0 .../{task.rnv.workspace.list.js => task.rnv.workspace.list.ts} | 0 ...{task.rnv.workspace.update.js => task.rnv.workspace.update.ts} | 0 packages/rnv/src/{index.js => index.ts} | 0 85 files changed, 0 insertions(+), 0 deletions(-) rename packages/rnv/src/core/adapter/{index.js => index.ts} (100%) rename packages/rnv/src/core/{common.js => common.ts} (100%) rename packages/rnv/src/core/engineManager/{index.js => index.ts} (100%) rename packages/rnv/src/core/integrationManager/{index.js => index.ts} (100%) rename packages/rnv/src/core/platformManager/{index.js => index.ts} (100%) rename packages/rnv/src/core/pluginManager/{index.js => index.ts} (100%) rename packages/rnv/src/core/projectManager/{buildHooks.js => buildHooks.ts} (100%) rename packages/rnv/src/core/projectManager/{index.js => index.ts} (100%) rename packages/rnv/src/core/projectManager/{migrator.js => migrator.ts} (100%) rename packages/rnv/src/core/projectManager/{package.js => package.ts} (100%) rename packages/rnv/src/core/projectManager/{workspace.js => workspace.ts} (100%) rename packages/rnv/src/core/runtimeManager/{index.js => index.ts} (100%) rename packages/rnv/src/core/schemaManager/{index.js => index.ts} (100%) rename packages/rnv/src/core/schemaManager/{schemaRenativeJson.js => schemaRenativeJson.ts} (100%) rename packages/rnv/src/core/schemaManager/{schemaRuntimeObject.js => schemaRuntimeObject.ts} (100%) rename packages/rnv/src/core/sdkManager/deviceUtils/{android.js => android.ts} (100%) rename packages/rnv/src/core/sdkManager/deviceUtils/{apple.js => apple.ts} (100%) rename packages/rnv/src/core/sdkManager/deviceUtils/{common.js => common.ts} (100%) rename packages/rnv/src/core/sdkManager/deviceUtils/{kaios.js => kaios.ts} (100%) rename packages/rnv/src/core/sdkManager/deviceUtils/{tizen.js => tizen.ts} (100%) rename packages/rnv/src/core/sdkManager/deviceUtils/{webos.js => webos.ts} (100%) rename packages/rnv/src/core/sdkManager/{index.js => index.ts} (100%) rename packages/rnv/src/core/sdkManager/{installer.js => installer.ts} (100%) rename packages/rnv/src/core/setupManager/{base.js => base.ts} (100%) rename packages/rnv/src/core/setupManager/{config.js => config.ts} (100%) rename packages/rnv/src/core/setupManager/{darwin.js => darwin.ts} (100%) rename packages/rnv/src/core/setupManager/{index.js => index.ts} (100%) rename packages/rnv/src/core/setupManager/{linux.js => linux.ts} (100%) rename packages/rnv/src/core/setupManager/{windows.js => windows.ts} (100%) rename packages/rnv/src/core/systemManager/{analytics.js => analytics.ts} (100%) rename packages/rnv/src/core/systemManager/{crypto.js => crypto.ts} (100%) rename packages/rnv/src/core/systemManager/{doctor.js => doctor.ts} (100%) rename packages/rnv/src/core/systemManager/{fileutils.js => fileutils.ts} (100%) rename packages/rnv/src/core/systemManager/{gitUtils.js => gitUtils.ts} (100%) rename packages/rnv/src/core/systemManager/{logger.js => logger.ts} (100%) rename packages/rnv/src/core/systemManager/{npmUtils.js => npmUtils.ts} (100%) rename packages/rnv/src/core/systemManager/{objectUtils.js => objectUtils.ts} (100%) rename packages/rnv/src/core/systemManager/{resolve.js => resolve.ts} (100%) rename packages/rnv/src/core/systemManager/{utils.js => utils.ts} (100%) rename packages/rnv/src/core/taskManager/{index.js => index.ts} (100%) rename packages/rnv/src/core/templateManager/{index.js => index.ts} (100%) rename packages/rnv/src/engine-core/{index.js => index.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.app.configure.js => task.rnv.app.configure.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.app.create.js => task.rnv.app.create.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.clean.js => task.rnv.clean.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.config.js => task.rnv.config.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.configureSoft.js => task.rnv.configureSoft.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.crypto.decrypt.js => task.rnv.crypto.decrypt.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.crypto.encrypt.js => task.rnv.crypto.encrypt.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.doctor.js => task.rnv.doctor.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.fastlane.js => task.rnv.fastlane.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.help.js => task.rnv.help.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.hooks.list.js => task.rnv.hooks.list.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.hooks.pipes.js => task.rnv.hooks.pipes.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.hooks.run.js => task.rnv.hooks.run.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.install.js => task.rnv.install.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.kill.js => task.rnv.kill.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.link.js => task.rnv.link.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.new.js => task.rnv.new.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.pkg.js => task.rnv.pkg.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.platform.configure.js => task.rnv.platform.configure.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.platform.connect.js => task.rnv.platform.connect.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.platform.eject.js => task.rnv.platform.eject.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.platform.list.js => task.rnv.platform.list.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.platform.setup.js => task.rnv.platform.setup.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.plugin.add.js => task.rnv.plugin.add.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.plugin.list.js => task.rnv.plugin.list.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.plugin.update.js => task.rnv.plugin.update.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.project.configure.js => task.rnv.project.configure.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.project.upgrade.js => task.rnv.project.upgrade.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.publish.js => task.rnv.publish.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.status.js => task.rnv.status.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.switch.js => task.rnv.switch.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.target.launch.js => task.rnv.target.launch.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.target.list.js => task.rnv.target.list.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.template.add.js => task.rnv.template.add.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.template.apply.js => task.rnv.template.apply.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.template.list.js => task.rnv.template.list.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.unlink.js => task.rnv.unlink.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.workspace.add.js => task.rnv.workspace.add.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.workspace.configure.js => task.rnv.workspace.configure.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.workspace.connect.js => task.rnv.workspace.connect.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.workspace.list.js => task.rnv.workspace.list.ts} (100%) rename packages/rnv/src/engine-core/tasks/{task.rnv.workspace.update.js => task.rnv.workspace.update.ts} (100%) rename packages/rnv/src/{index.js => index.ts} (100%) diff --git a/packages/rnv/src/core/adapter/index.js b/packages/rnv/src/core/adapter/index.ts similarity index 100% rename from packages/rnv/src/core/adapter/index.js rename to packages/rnv/src/core/adapter/index.ts diff --git a/packages/rnv/src/core/common.js b/packages/rnv/src/core/common.ts similarity index 100% rename from packages/rnv/src/core/common.js rename to packages/rnv/src/core/common.ts diff --git a/packages/rnv/src/core/engineManager/index.js b/packages/rnv/src/core/engineManager/index.ts similarity index 100% rename from packages/rnv/src/core/engineManager/index.js rename to packages/rnv/src/core/engineManager/index.ts diff --git a/packages/rnv/src/core/integrationManager/index.js b/packages/rnv/src/core/integrationManager/index.ts similarity index 100% rename from packages/rnv/src/core/integrationManager/index.js rename to packages/rnv/src/core/integrationManager/index.ts diff --git a/packages/rnv/src/core/platformManager/index.js b/packages/rnv/src/core/platformManager/index.ts similarity index 100% rename from packages/rnv/src/core/platformManager/index.js rename to packages/rnv/src/core/platformManager/index.ts diff --git a/packages/rnv/src/core/pluginManager/index.js b/packages/rnv/src/core/pluginManager/index.ts similarity index 100% rename from packages/rnv/src/core/pluginManager/index.js rename to packages/rnv/src/core/pluginManager/index.ts diff --git a/packages/rnv/src/core/projectManager/buildHooks.js b/packages/rnv/src/core/projectManager/buildHooks.ts similarity index 100% rename from packages/rnv/src/core/projectManager/buildHooks.js rename to packages/rnv/src/core/projectManager/buildHooks.ts diff --git a/packages/rnv/src/core/projectManager/index.js b/packages/rnv/src/core/projectManager/index.ts similarity index 100% rename from packages/rnv/src/core/projectManager/index.js rename to packages/rnv/src/core/projectManager/index.ts diff --git a/packages/rnv/src/core/projectManager/migrator.js b/packages/rnv/src/core/projectManager/migrator.ts similarity index 100% rename from packages/rnv/src/core/projectManager/migrator.js rename to packages/rnv/src/core/projectManager/migrator.ts diff --git a/packages/rnv/src/core/projectManager/package.js b/packages/rnv/src/core/projectManager/package.ts similarity index 100% rename from packages/rnv/src/core/projectManager/package.js rename to packages/rnv/src/core/projectManager/package.ts diff --git a/packages/rnv/src/core/projectManager/workspace.js b/packages/rnv/src/core/projectManager/workspace.ts similarity index 100% rename from packages/rnv/src/core/projectManager/workspace.js rename to packages/rnv/src/core/projectManager/workspace.ts diff --git a/packages/rnv/src/core/runtimeManager/index.js b/packages/rnv/src/core/runtimeManager/index.ts similarity index 100% rename from packages/rnv/src/core/runtimeManager/index.js rename to packages/rnv/src/core/runtimeManager/index.ts diff --git a/packages/rnv/src/core/schemaManager/index.js b/packages/rnv/src/core/schemaManager/index.ts similarity index 100% rename from packages/rnv/src/core/schemaManager/index.js rename to packages/rnv/src/core/schemaManager/index.ts diff --git a/packages/rnv/src/core/schemaManager/schemaRenativeJson.js b/packages/rnv/src/core/schemaManager/schemaRenativeJson.ts similarity index 100% rename from packages/rnv/src/core/schemaManager/schemaRenativeJson.js rename to packages/rnv/src/core/schemaManager/schemaRenativeJson.ts diff --git a/packages/rnv/src/core/schemaManager/schemaRuntimeObject.js b/packages/rnv/src/core/schemaManager/schemaRuntimeObject.ts similarity index 100% rename from packages/rnv/src/core/schemaManager/schemaRuntimeObject.js rename to packages/rnv/src/core/schemaManager/schemaRuntimeObject.ts diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/android.js b/packages/rnv/src/core/sdkManager/deviceUtils/android.ts similarity index 100% rename from packages/rnv/src/core/sdkManager/deviceUtils/android.js rename to packages/rnv/src/core/sdkManager/deviceUtils/android.ts diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/apple.js b/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts similarity index 100% rename from packages/rnv/src/core/sdkManager/deviceUtils/apple.js rename to packages/rnv/src/core/sdkManager/deviceUtils/apple.ts diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/common.js b/packages/rnv/src/core/sdkManager/deviceUtils/common.ts similarity index 100% rename from packages/rnv/src/core/sdkManager/deviceUtils/common.js rename to packages/rnv/src/core/sdkManager/deviceUtils/common.ts diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/kaios.js b/packages/rnv/src/core/sdkManager/deviceUtils/kaios.ts similarity index 100% rename from packages/rnv/src/core/sdkManager/deviceUtils/kaios.js rename to packages/rnv/src/core/sdkManager/deviceUtils/kaios.ts diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.js b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts similarity index 100% rename from packages/rnv/src/core/sdkManager/deviceUtils/tizen.js rename to packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/webos.js b/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts similarity index 100% rename from packages/rnv/src/core/sdkManager/deviceUtils/webos.js rename to packages/rnv/src/core/sdkManager/deviceUtils/webos.ts diff --git a/packages/rnv/src/core/sdkManager/index.js b/packages/rnv/src/core/sdkManager/index.ts similarity index 100% rename from packages/rnv/src/core/sdkManager/index.js rename to packages/rnv/src/core/sdkManager/index.ts diff --git a/packages/rnv/src/core/sdkManager/installer.js b/packages/rnv/src/core/sdkManager/installer.ts similarity index 100% rename from packages/rnv/src/core/sdkManager/installer.js rename to packages/rnv/src/core/sdkManager/installer.ts diff --git a/packages/rnv/src/core/setupManager/base.js b/packages/rnv/src/core/setupManager/base.ts similarity index 100% rename from packages/rnv/src/core/setupManager/base.js rename to packages/rnv/src/core/setupManager/base.ts diff --git a/packages/rnv/src/core/setupManager/config.js b/packages/rnv/src/core/setupManager/config.ts similarity index 100% rename from packages/rnv/src/core/setupManager/config.js rename to packages/rnv/src/core/setupManager/config.ts diff --git a/packages/rnv/src/core/setupManager/darwin.js b/packages/rnv/src/core/setupManager/darwin.ts similarity index 100% rename from packages/rnv/src/core/setupManager/darwin.js rename to packages/rnv/src/core/setupManager/darwin.ts diff --git a/packages/rnv/src/core/setupManager/index.js b/packages/rnv/src/core/setupManager/index.ts similarity index 100% rename from packages/rnv/src/core/setupManager/index.js rename to packages/rnv/src/core/setupManager/index.ts diff --git a/packages/rnv/src/core/setupManager/linux.js b/packages/rnv/src/core/setupManager/linux.ts similarity index 100% rename from packages/rnv/src/core/setupManager/linux.js rename to packages/rnv/src/core/setupManager/linux.ts diff --git a/packages/rnv/src/core/setupManager/windows.js b/packages/rnv/src/core/setupManager/windows.ts similarity index 100% rename from packages/rnv/src/core/setupManager/windows.js rename to packages/rnv/src/core/setupManager/windows.ts diff --git a/packages/rnv/src/core/systemManager/analytics.js b/packages/rnv/src/core/systemManager/analytics.ts similarity index 100% rename from packages/rnv/src/core/systemManager/analytics.js rename to packages/rnv/src/core/systemManager/analytics.ts diff --git a/packages/rnv/src/core/systemManager/crypto.js b/packages/rnv/src/core/systemManager/crypto.ts similarity index 100% rename from packages/rnv/src/core/systemManager/crypto.js rename to packages/rnv/src/core/systemManager/crypto.ts diff --git a/packages/rnv/src/core/systemManager/doctor.js b/packages/rnv/src/core/systemManager/doctor.ts similarity index 100% rename from packages/rnv/src/core/systemManager/doctor.js rename to packages/rnv/src/core/systemManager/doctor.ts diff --git a/packages/rnv/src/core/systemManager/fileutils.js b/packages/rnv/src/core/systemManager/fileutils.ts similarity index 100% rename from packages/rnv/src/core/systemManager/fileutils.js rename to packages/rnv/src/core/systemManager/fileutils.ts diff --git a/packages/rnv/src/core/systemManager/gitUtils.js b/packages/rnv/src/core/systemManager/gitUtils.ts similarity index 100% rename from packages/rnv/src/core/systemManager/gitUtils.js rename to packages/rnv/src/core/systemManager/gitUtils.ts diff --git a/packages/rnv/src/core/systemManager/logger.js b/packages/rnv/src/core/systemManager/logger.ts similarity index 100% rename from packages/rnv/src/core/systemManager/logger.js rename to packages/rnv/src/core/systemManager/logger.ts diff --git a/packages/rnv/src/core/systemManager/npmUtils.js b/packages/rnv/src/core/systemManager/npmUtils.ts similarity index 100% rename from packages/rnv/src/core/systemManager/npmUtils.js rename to packages/rnv/src/core/systemManager/npmUtils.ts diff --git a/packages/rnv/src/core/systemManager/objectUtils.js b/packages/rnv/src/core/systemManager/objectUtils.ts similarity index 100% rename from packages/rnv/src/core/systemManager/objectUtils.js rename to packages/rnv/src/core/systemManager/objectUtils.ts diff --git a/packages/rnv/src/core/systemManager/resolve.js b/packages/rnv/src/core/systemManager/resolve.ts similarity index 100% rename from packages/rnv/src/core/systemManager/resolve.js rename to packages/rnv/src/core/systemManager/resolve.ts diff --git a/packages/rnv/src/core/systemManager/utils.js b/packages/rnv/src/core/systemManager/utils.ts similarity index 100% rename from packages/rnv/src/core/systemManager/utils.js rename to packages/rnv/src/core/systemManager/utils.ts diff --git a/packages/rnv/src/core/taskManager/index.js b/packages/rnv/src/core/taskManager/index.ts similarity index 100% rename from packages/rnv/src/core/taskManager/index.js rename to packages/rnv/src/core/taskManager/index.ts diff --git a/packages/rnv/src/core/templateManager/index.js b/packages/rnv/src/core/templateManager/index.ts similarity index 100% rename from packages/rnv/src/core/templateManager/index.js rename to packages/rnv/src/core/templateManager/index.ts diff --git a/packages/rnv/src/engine-core/index.js b/packages/rnv/src/engine-core/index.ts similarity index 100% rename from packages/rnv/src/engine-core/index.js rename to packages/rnv/src/engine-core/index.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.app.configure.js b/packages/rnv/src/engine-core/tasks/task.rnv.app.configure.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.app.configure.js rename to packages/rnv/src/engine-core/tasks/task.rnv.app.configure.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.app.create.js b/packages/rnv/src/engine-core/tasks/task.rnv.app.create.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.app.create.js rename to packages/rnv/src/engine-core/tasks/task.rnv.app.create.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.clean.js b/packages/rnv/src/engine-core/tasks/task.rnv.clean.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.clean.js rename to packages/rnv/src/engine-core/tasks/task.rnv.clean.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.config.js b/packages/rnv/src/engine-core/tasks/task.rnv.config.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.config.js rename to packages/rnv/src/engine-core/tasks/task.rnv.config.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.configureSoft.js b/packages/rnv/src/engine-core/tasks/task.rnv.configureSoft.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.configureSoft.js rename to packages/rnv/src/engine-core/tasks/task.rnv.configureSoft.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.crypto.decrypt.js b/packages/rnv/src/engine-core/tasks/task.rnv.crypto.decrypt.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.crypto.decrypt.js rename to packages/rnv/src/engine-core/tasks/task.rnv.crypto.decrypt.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.js b/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.js rename to packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.doctor.js b/packages/rnv/src/engine-core/tasks/task.rnv.doctor.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.doctor.js rename to packages/rnv/src/engine-core/tasks/task.rnv.doctor.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.fastlane.js b/packages/rnv/src/engine-core/tasks/task.rnv.fastlane.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.fastlane.js rename to packages/rnv/src/engine-core/tasks/task.rnv.fastlane.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.help.js b/packages/rnv/src/engine-core/tasks/task.rnv.help.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.help.js rename to packages/rnv/src/engine-core/tasks/task.rnv.help.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.hooks.list.js b/packages/rnv/src/engine-core/tasks/task.rnv.hooks.list.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.hooks.list.js rename to packages/rnv/src/engine-core/tasks/task.rnv.hooks.list.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.hooks.pipes.js b/packages/rnv/src/engine-core/tasks/task.rnv.hooks.pipes.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.hooks.pipes.js rename to packages/rnv/src/engine-core/tasks/task.rnv.hooks.pipes.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.hooks.run.js b/packages/rnv/src/engine-core/tasks/task.rnv.hooks.run.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.hooks.run.js rename to packages/rnv/src/engine-core/tasks/task.rnv.hooks.run.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.install.js b/packages/rnv/src/engine-core/tasks/task.rnv.install.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.install.js rename to packages/rnv/src/engine-core/tasks/task.rnv.install.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.kill.js b/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.kill.js rename to packages/rnv/src/engine-core/tasks/task.rnv.kill.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.link.js b/packages/rnv/src/engine-core/tasks/task.rnv.link.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.link.js rename to packages/rnv/src/engine-core/tasks/task.rnv.link.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.new.js b/packages/rnv/src/engine-core/tasks/task.rnv.new.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.new.js rename to packages/rnv/src/engine-core/tasks/task.rnv.new.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.pkg.js b/packages/rnv/src/engine-core/tasks/task.rnv.pkg.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.pkg.js rename to packages/rnv/src/engine-core/tasks/task.rnv.pkg.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.platform.configure.js b/packages/rnv/src/engine-core/tasks/task.rnv.platform.configure.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.platform.configure.js rename to packages/rnv/src/engine-core/tasks/task.rnv.platform.configure.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.platform.connect.js b/packages/rnv/src/engine-core/tasks/task.rnv.platform.connect.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.platform.connect.js rename to packages/rnv/src/engine-core/tasks/task.rnv.platform.connect.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.platform.eject.js b/packages/rnv/src/engine-core/tasks/task.rnv.platform.eject.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.platform.eject.js rename to packages/rnv/src/engine-core/tasks/task.rnv.platform.eject.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.platform.list.js b/packages/rnv/src/engine-core/tasks/task.rnv.platform.list.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.platform.list.js rename to packages/rnv/src/engine-core/tasks/task.rnv.platform.list.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.platform.setup.js b/packages/rnv/src/engine-core/tasks/task.rnv.platform.setup.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.platform.setup.js rename to packages/rnv/src/engine-core/tasks/task.rnv.platform.setup.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.plugin.add.js b/packages/rnv/src/engine-core/tasks/task.rnv.plugin.add.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.plugin.add.js rename to packages/rnv/src/engine-core/tasks/task.rnv.plugin.add.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.plugin.list.js b/packages/rnv/src/engine-core/tasks/task.rnv.plugin.list.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.plugin.list.js rename to packages/rnv/src/engine-core/tasks/task.rnv.plugin.list.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.plugin.update.js b/packages/rnv/src/engine-core/tasks/task.rnv.plugin.update.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.plugin.update.js rename to packages/rnv/src/engine-core/tasks/task.rnv.plugin.update.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.project.configure.js b/packages/rnv/src/engine-core/tasks/task.rnv.project.configure.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.project.configure.js rename to packages/rnv/src/engine-core/tasks/task.rnv.project.configure.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.project.upgrade.js b/packages/rnv/src/engine-core/tasks/task.rnv.project.upgrade.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.project.upgrade.js rename to packages/rnv/src/engine-core/tasks/task.rnv.project.upgrade.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.publish.js b/packages/rnv/src/engine-core/tasks/task.rnv.publish.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.publish.js rename to packages/rnv/src/engine-core/tasks/task.rnv.publish.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.status.js b/packages/rnv/src/engine-core/tasks/task.rnv.status.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.status.js rename to packages/rnv/src/engine-core/tasks/task.rnv.status.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.switch.js b/packages/rnv/src/engine-core/tasks/task.rnv.switch.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.switch.js rename to packages/rnv/src/engine-core/tasks/task.rnv.switch.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.target.launch.js b/packages/rnv/src/engine-core/tasks/task.rnv.target.launch.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.target.launch.js rename to packages/rnv/src/engine-core/tasks/task.rnv.target.launch.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.target.list.js b/packages/rnv/src/engine-core/tasks/task.rnv.target.list.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.target.list.js rename to packages/rnv/src/engine-core/tasks/task.rnv.target.list.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.template.add.js b/packages/rnv/src/engine-core/tasks/task.rnv.template.add.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.template.add.js rename to packages/rnv/src/engine-core/tasks/task.rnv.template.add.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.template.apply.js b/packages/rnv/src/engine-core/tasks/task.rnv.template.apply.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.template.apply.js rename to packages/rnv/src/engine-core/tasks/task.rnv.template.apply.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.template.list.js b/packages/rnv/src/engine-core/tasks/task.rnv.template.list.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.template.list.js rename to packages/rnv/src/engine-core/tasks/task.rnv.template.list.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.unlink.js b/packages/rnv/src/engine-core/tasks/task.rnv.unlink.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.unlink.js rename to packages/rnv/src/engine-core/tasks/task.rnv.unlink.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.workspace.add.js b/packages/rnv/src/engine-core/tasks/task.rnv.workspace.add.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.workspace.add.js rename to packages/rnv/src/engine-core/tasks/task.rnv.workspace.add.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.workspace.configure.js b/packages/rnv/src/engine-core/tasks/task.rnv.workspace.configure.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.workspace.configure.js rename to packages/rnv/src/engine-core/tasks/task.rnv.workspace.configure.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.workspace.connect.js b/packages/rnv/src/engine-core/tasks/task.rnv.workspace.connect.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.workspace.connect.js rename to packages/rnv/src/engine-core/tasks/task.rnv.workspace.connect.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.workspace.list.js b/packages/rnv/src/engine-core/tasks/task.rnv.workspace.list.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.workspace.list.js rename to packages/rnv/src/engine-core/tasks/task.rnv.workspace.list.ts diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.workspace.update.js b/packages/rnv/src/engine-core/tasks/task.rnv.workspace.update.ts similarity index 100% rename from packages/rnv/src/engine-core/tasks/task.rnv.workspace.update.js rename to packages/rnv/src/engine-core/tasks/task.rnv.workspace.update.ts diff --git a/packages/rnv/src/index.js b/packages/rnv/src/index.ts similarity index 100% rename from packages/rnv/src/index.js rename to packages/rnv/src/index.ts From 0f5e2cc8cdf21083a1a20f40eabd7646aefc40d4 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Tue, 29 Aug 2023 10:32:21 +0200 Subject: [PATCH 07/83] code formatting --- package.json | 2 +- packages/engine-lightning/package.json | 2 +- packages/engine-rn-electron/package.json | 2 +- packages/engine-rn-macos/package.json | 2 +- packages/engine-rn-next/package.json | 2 +- packages/engine-rn-tvos/package.json | 2 +- packages/engine-rn-web/package.json | 2 +- packages/engine-rn-windows/package.json | 2 +- packages/engine-rn/package.json | 2 +- packages/engine-roku/package.json | 2 +- packages/integration-docker/package.json | 2 +- packages/integration-ftp/package.json | 2 +- packages/integration-terraform/package.json | 2 +- packages/integration-vercel/package.json | 2 +- packages/renative/package.json | 2 +- .../rnv/coreTemplateFiles/renative.templates.json | 2 +- packages/rnv/package.json | 2 +- packages/sdk-android/package.json | 2 +- packages/sdk-apple/package.json | 2 +- packages/sdk-webpack/package.json | 2 +- packages/template-starter/package.json | 2 +- packages/template-starter/renative.json | 14 ++++---------- 22 files changed, 25 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index e6bccf22ac..51abf48fa7 100644 --- a/package.json +++ b/package.json @@ -164,4 +164,4 @@ "ejs": "3.1.7", "shell-quote": "1.7.3" } -} \ No newline at end of file +} diff --git a/packages/engine-lightning/package.json b/packages/engine-lightning/package.json index 29a7bc1199..1ef45a48d5 100644 --- a/packages/engine-lightning/package.json +++ b/packages/engine-lightning/package.json @@ -54,4 +54,4 @@ "access": "public" }, "gitHead": "930edaf234cc321ad9f1e296c5d394e3144845e2" -} \ No newline at end of file +} diff --git a/packages/engine-rn-electron/package.json b/packages/engine-rn-electron/package.json index f1d4bc82b0..c1e9d46119 100644 --- a/packages/engine-rn-electron/package.json +++ b/packages/engine-rn-electron/package.json @@ -61,4 +61,4 @@ "access": "public" }, "gitHead": "930edaf234cc321ad9f1e296c5d394e3144845e2" -} \ No newline at end of file +} diff --git a/packages/engine-rn-macos/package.json b/packages/engine-rn-macos/package.json index 8c04e6225d..4733484d3a 100644 --- a/packages/engine-rn-macos/package.json +++ b/packages/engine-rn-macos/package.json @@ -50,4 +50,4 @@ "access": "public" }, "gitHead": "930edaf234cc321ad9f1e296c5d394e3144845e2" -} \ No newline at end of file +} diff --git a/packages/engine-rn-next/package.json b/packages/engine-rn-next/package.json index ac3364ca93..57d46c4337 100644 --- a/packages/engine-rn-next/package.json +++ b/packages/engine-rn-next/package.json @@ -60,4 +60,4 @@ "access": "public" }, "gitHead": "930edaf234cc321ad9f1e296c5d394e3144845e2" -} \ No newline at end of file +} diff --git a/packages/engine-rn-tvos/package.json b/packages/engine-rn-tvos/package.json index 9ef46d3d8d..36b4dc5bf3 100644 --- a/packages/engine-rn-tvos/package.json +++ b/packages/engine-rn-tvos/package.json @@ -53,4 +53,4 @@ "access": "public" }, "gitHead": "930edaf234cc321ad9f1e296c5d394e3144845e2" -} \ No newline at end of file +} diff --git a/packages/engine-rn-web/package.json b/packages/engine-rn-web/package.json index 6ad64f5cb6..7141b458ea 100644 --- a/packages/engine-rn-web/package.json +++ b/packages/engine-rn-web/package.json @@ -59,4 +59,4 @@ "access": "public" }, "gitHead": "930edaf234cc321ad9f1e296c5d394e3144845e2" -} \ No newline at end of file +} diff --git a/packages/engine-rn-windows/package.json b/packages/engine-rn-windows/package.json index 81758e9cb7..6723a8b159 100644 --- a/packages/engine-rn-windows/package.json +++ b/packages/engine-rn-windows/package.json @@ -56,4 +56,4 @@ "access": "public" }, "gitHead": "930edaf234cc321ad9f1e296c5d394e3144845e2" -} \ No newline at end of file +} diff --git a/packages/engine-rn/package.json b/packages/engine-rn/package.json index 262979ca93..11e7e8307b 100644 --- a/packages/engine-rn/package.json +++ b/packages/engine-rn/package.json @@ -50,4 +50,4 @@ "access": "public" }, "gitHead": "930edaf234cc321ad9f1e296c5d394e3144845e2" -} \ No newline at end of file +} diff --git a/packages/engine-roku/package.json b/packages/engine-roku/package.json index da6628a179..7b576e56f0 100644 --- a/packages/engine-roku/package.json +++ b/packages/engine-roku/package.json @@ -47,4 +47,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +} diff --git a/packages/integration-docker/package.json b/packages/integration-docker/package.json index 5661c4dd4b..b0de335d6a 100644 --- a/packages/integration-docker/package.json +++ b/packages/integration-docker/package.json @@ -46,4 +46,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +} diff --git a/packages/integration-ftp/package.json b/packages/integration-ftp/package.json index d129769e4f..7bbdfff91d 100644 --- a/packages/integration-ftp/package.json +++ b/packages/integration-ftp/package.json @@ -47,4 +47,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +} diff --git a/packages/integration-terraform/package.json b/packages/integration-terraform/package.json index b6ae6b67ef..50e41282d0 100644 --- a/packages/integration-terraform/package.json +++ b/packages/integration-terraform/package.json @@ -44,4 +44,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +} diff --git a/packages/integration-vercel/package.json b/packages/integration-vercel/package.json index 46cd5da003..06f7e6566e 100644 --- a/packages/integration-vercel/package.json +++ b/packages/integration-vercel/package.json @@ -46,4 +46,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +} diff --git a/packages/renative/package.json b/packages/renative/package.json index 0b1fd860fb..d856c8d37f 100644 --- a/packages/renative/package.json +++ b/packages/renative/package.json @@ -74,4 +74,4 @@ } }, "gitHead": "930edaf234cc321ad9f1e296c5d394e3144845e2" -} \ No newline at end of file +} diff --git a/packages/rnv/coreTemplateFiles/renative.templates.json b/packages/rnv/coreTemplateFiles/renative.templates.json index d8c52b7ef3..549d636cad 100644 --- a/packages/rnv/coreTemplateFiles/renative.templates.json +++ b/packages/rnv/coreTemplateFiles/renative.templates.json @@ -111,4 +111,4 @@ "engine": "engine-rn-web" } } -} \ No newline at end of file +} diff --git a/packages/rnv/package.json b/packages/rnv/package.json index e46a0667a6..c7e3641930 100644 --- a/packages/rnv/package.json +++ b/packages/rnv/package.json @@ -135,4 +135,4 @@ }, "title": "ReNative CLI", "gitHead": "930edaf234cc321ad9f1e296c5d394e3144845e2" -} \ No newline at end of file +} diff --git a/packages/sdk-android/package.json b/packages/sdk-android/package.json index 5ae41bca68..b61293644e 100644 --- a/packages/sdk-android/package.json +++ b/packages/sdk-android/package.json @@ -56,4 +56,4 @@ ] }, "gitHead": "930edaf234cc321ad9f1e296c5d394e3144845e2" -} \ No newline at end of file +} diff --git a/packages/sdk-apple/package.json b/packages/sdk-apple/package.json index 73a374a551..fa8111330f 100644 --- a/packages/sdk-apple/package.json +++ b/packages/sdk-apple/package.json @@ -58,4 +58,4 @@ ] }, "gitHead": "930edaf234cc321ad9f1e296c5d394e3144845e2" -} \ No newline at end of file +} diff --git a/packages/sdk-webpack/package.json b/packages/sdk-webpack/package.json index 621f324d2a..ee2f39ab14 100644 --- a/packages/sdk-webpack/package.json +++ b/packages/sdk-webpack/package.json @@ -99,4 +99,4 @@ ] }, "gitHead": "930edaf234cc321ad9f1e296c5d394e3144845e2" -} \ No newline at end of file +} diff --git a/packages/template-starter/package.json b/packages/template-starter/package.json index 87097f78cd..6375af26fd 100644 --- a/packages/template-starter/package.json +++ b/packages/template-starter/package.json @@ -118,4 +118,4 @@ "last 1 safari version" ] } -} \ No newline at end of file +} diff --git a/packages/template-starter/renative.json b/packages/template-starter/renative.json index d7aff69f00..5c79bcf193 100644 --- a/packages/template-starter/renative.json +++ b/packages/template-starter/renative.json @@ -120,9 +120,7 @@ "org.gradle.configureondemand": true }, "engine": "engine-rn-tvos", - "includedPermissions": [ - "INTERNET" - ] + "includedPermissions": ["INTERNET"] }, "androidwear": { "minSdkVersion": 26, @@ -144,9 +142,7 @@ "org.gradle.parallel": true, "org.gradle.configureondemand": true }, - "includedPermissions": [ - "INTERNET" - ], + "includedPermissions": ["INTERNET"], "mainActivity": { "onCreate": "super.onCreate(null)" } @@ -172,9 +168,7 @@ "org.gradle.configureondemand": true }, "engine": "engine-rn-tvos", - "includedPermissions": [ - "INTERNET" - ] + "includedPermissions": ["INTERNET"] }, "web": { "engine": "engine-rn-next" @@ -215,4 +209,4 @@ } } } -} \ No newline at end of file +} From 796417d292bd8e51736d1aa7fb3dd17dda274b3e Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Tue, 29 Aug 2023 19:41:23 +0200 Subject: [PATCH 08/83] ts conversions, add global ts, 1856 togo --- packages/rnv/src/core/configManager/index.ts | 4 +- packages/rnv/src/core/configManager/types.ts | 14 ++ packages/rnv/src/core/systemManager/exec.ts | 56 ++++---- .../rnv/src/core/systemManager/fileutils.ts | 57 ++++---- packages/rnv/src/core/systemManager/logger.ts | 124 +++++++++--------- packages/rnv/src/core/systemManager/types.ts | 4 + packages/rnv/src/typings/global.d.ts | 14 ++ 7 files changed, 161 insertions(+), 112 deletions(-) create mode 100644 packages/rnv/src/typings/global.d.ts diff --git a/packages/rnv/src/core/configManager/index.ts b/packages/rnv/src/core/configManager/index.ts index 0c2a216813..dc75080425 100644 --- a/packages/rnv/src/core/configManager/index.ts +++ b/packages/rnv/src/core/configManager/index.ts @@ -35,7 +35,7 @@ import { getConfigProp } from '../common'; import { getWorkspaceDirPath } from '../projectManager/workspace'; import { chalk, logError, logTask, logWarning, logDebug } from '../systemManager/logger'; import { doResolve } from '../systemManager/resolve'; -import { RnvConfigFileObj, RnvConfigPathObj, RnvConfig } from './types'; +import { RnvConfigFileObj, RnvConfigPathObj, RnvConfig, RnvFileKey } from './types'; import { generateConfigBase } from './configBase'; // import { loadPluginTemplates } from '../pluginManager'; @@ -224,7 +224,7 @@ export const loadFileExtended = ( c: RnvConfig, fileObj: Record, pathObj: RnvConfigPathObj, - key: string + key: RnvFileKey ) => { const result = loadFile(fileObj, pathObj, key); if (fileObj[key]) { diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index 131cfec29c..ca92550afe 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -5,6 +5,7 @@ export interface RnvConfig { buildConfig: any; platform: string; process: any; + rnvVersion: string; //======= _renativePluginCache: any; cli: any; @@ -23,6 +24,17 @@ export interface RnvConfig { enginesById: Record; missingEnginePlugins: Record; localhost: string; + scheme: string; + bundleAssets: boolean; + activeTemplate: string; + engine: any; + target: string; + supportedPlatforms: Array<{ + platform: string; + isConnected: boolean; + }>; + keepSessionActive: boolean; + platformBuildsProjectPath: string; }; paths: { GLOBAL_RNV_CONFIG: string; @@ -219,6 +231,8 @@ export interface RnvConfig { }; } +export type RnvFileKey = 'config' | 'configLocal' | 'configPrivate'; + export type DependencyType = 'devDependencies' | 'dependencies' | 'peerDependencies'; export type RnvConfigSchema = Record; diff --git a/packages/rnv/src/core/systemManager/exec.ts b/packages/rnv/src/core/systemManager/exec.ts index 4271b20ba3..75e9e1da82 100755 --- a/packages/rnv/src/core/systemManager/exec.ts +++ b/packages/rnv/src/core/systemManager/exec.ts @@ -1,6 +1,4 @@ /* eslint-disable no-control-regex */ -/* eslint-disable no-bitwise */ -/* eslint-disable no-await-in-loop */ import path from 'path'; import { access, accessSync, constants } from 'fs'; @@ -13,7 +11,7 @@ import { chalk, logDebug, logRaw, logError } from './logger'; import { fsExistsSync } from './fileutils'; import { replaceOverridesInString } from './utils'; import { RnvConfig } from '../configManager/types'; -import { ExecOptions } from './types'; +import { ExecCallback, ExecCallback2, ExecOptions } from './types'; const { exec, execSync } = require('child_process'); @@ -56,7 +54,7 @@ const _execute = (c: RnvConfig, command: string, opts: ExecOptions = {}) => { const env = opts.env && c.program.info ? Object.keys(opts.env) - .map((k) => `${k}=${opts.env[k]}`) + .map((k) => `${k}=${opts?.env?.[k]}`) .join(' ') : null; @@ -99,10 +97,17 @@ const _execute = (c: RnvConfig, command: string, opts: ExecOptions = {}) => { const MAX_OUTPUT_LENGTH = 200; - const printLastLine = (buffer) => { + const printLastLine = (buffer: WithImplicitCoercion) => { const text = Buffer.from(buffer).toString().trim(); const lastLine = text.split('\n').pop(); - spinner.text = replaceOverridesInString(lastLine?.substring(0, MAX_OUTPUT_LENGTH), privateParams, privateMask); + if (spinner !== false) { + spinner.text = replaceOverridesInString( + lastLine?.substring(0, MAX_OUTPUT_LENGTH), + privateParams, + privateMask + ); + } + if (lastLine?.length === MAX_OUTPUT_LENGTH) { if (spinner !== false) spinner.text += '...\n'; } @@ -211,17 +216,24 @@ const execCLI = (c: RnvConfig, cli: string, command: string, opts: ExecOptions = * @returns {Promise} * */ -const executeAsync = async (_c: RnvConfig, _cmd: string, _opts: ExecOptions) => { +const executeAsync = async (_c: RnvConfig | string, _cmd?: string | ExecOptions, _opts?: ExecOptions) => { // swap values if c is not specified and get it from it's rightful place, config :) - let c = _c; - let cmd = _cmd; - let opts = _opts; - if (typeof c === 'string') { - opts = cmd; - cmd = c; + let c: RnvConfig; + let cmd = ''; + let opts: ExecOptions = {}; + if (typeof _c === 'string') { + cmd = _c; c = Config.getConfig(); + } else { + c = _c; } - opts = opts || {}; + + if (typeof _cmd === 'string') { + cmd = _cmd; + } else if (_cmd) { + opts = _cmd; + } + if (cmd.includes('npm') && process.platform === 'win32') { cmd.replace('npm', 'npm.cmd'); } @@ -266,7 +278,7 @@ const executeTelnet = (c: RnvConfig, port: string, command: string) => let output = ''; const nc2 = new NClient(); nc2.addr(c.runtime.localhost).port(parseInt(port, 10)).connect().send(`${command}\n`); - nc2.on('data', (data) => { + nc2.on('data', (data: WithImplicitCoercion) => { const resp = Buffer.from(data).toString(); output += resp; if (output.includes('OK')) nc2.close(); @@ -369,7 +381,7 @@ export const parseErrorMessage = (text: string, maxErrorLength = 800) => { const isUsingWindows = process.platform === 'win32'; -const fileNotExists = (commandName: string, callback) => { +const fileNotExists = (commandName: string, callback: ExecCallback) => { access(commandName, constants.F_OK, (err) => { callback(!err); }); @@ -384,7 +396,7 @@ const fileNotExistsSync = (commandName: string) => { } }; -const localExecutable = (commandName: string, callback) => { +const localExecutable = (commandName: string, callback: ExecCallback2) => { access(commandName, constants.F_OK | constants.X_OK, (err) => { callback(null, !err); }); @@ -399,12 +411,12 @@ const localExecutableSync = (commandName: string) => { } }; -const commandExistsUnix = (commandName: string, cleanedCommandName: string, callback) => { +const commandExistsUnix = (commandName: string, cleanedCommandName: string, callback: ExecCallback2) => { fileNotExists(commandName, (isFile: boolean) => { if (!isFile) { exec( `command -v ${cleanedCommandName} 2>/dev/null` + ` && { echo >&1 ${cleanedCommandName}; exit 0; }`, - (error, stdout) => { + (_error: any, stdout: any) => { callback(null, !!stdout); } ); @@ -415,12 +427,12 @@ const commandExistsUnix = (commandName: string, cleanedCommandName: string, call }); }; -const commandExistsWindows = (commandName: string, cleanedCommandName: string, callback) => { +const commandExistsWindows = (commandName: string, cleanedCommandName: string, callback: ExecCallback2) => { if (/[\x00-\x1f<>:"|?*]/.test(commandName)) { callback(null, false); return; } - exec(`where ${cleanedCommandName}`, (error) => { + exec(`where ${cleanedCommandName}`, (error: any) => { if (error !== null) { callback(null, false); } else { @@ -478,7 +490,7 @@ if (isUsingWindows) { }; } -const commandExists = (commandName: string, callback) => { +const commandExists = (commandName: string, callback: ExecCallback2) => { const cleanedCommandName = cleanInput(commandName); if (!callback && typeof Promise !== 'undefined') { return new Promise((resolve, reject) => { diff --git a/packages/rnv/src/core/systemManager/fileutils.ts b/packages/rnv/src/core/systemManager/fileutils.ts index 420a1ccd18..2468fefda7 100755 --- a/packages/rnv/src/core/systemManager/fileutils.ts +++ b/packages/rnv/src/core/systemManager/fileutils.ts @@ -6,6 +6,7 @@ import shelljs from 'shelljs'; import merge from 'deepmerge'; import ncp from 'ncp'; import { chalk, logDebug, logError, logWarning } from './logger'; +import { RnvConfig } from '../configManager/types'; export const configureFilesystem = (_getConfigProp, _doResolve, _isSystemWin) => { global.getConfigProp = _getConfigProp; @@ -13,47 +14,47 @@ export const configureFilesystem = (_getConfigProp, _doResolve, _isSystemWin) => global.isSystemWin = _isSystemWin; }; -export const fsWriteFileSync = (dest, data, encoding) => { +export const fsWriteFileSync = (dest: string, data: string, options?: fs.WriteFileOptions) => { // if (dest && dest.includes('renative.json')) { // console.log('FS_WRITE', dest, data.length); // } - fs.writeFileSync(dest, data, encoding); + fs.writeFileSync(dest, data, options); }; -export const fsCopyFileSync = (source, dest) => { +export const fsCopyFileSync = (source: string, dest: string) => { // console.log('FS_COPY', source); fs.copyFileSync(source, dest); }; -export const fsExistsSync = (dest) => fs.existsSync(dest); +export const fsExistsSync = (dest: fs.PathLike) => fs.existsSync(dest); -export const fsReaddirSync = (dest) => fs.readdirSync(dest); +export const fsReaddirSync = (dest: fs.PathLike) => fs.readdirSync(dest); -export const fsLstatSync = (dest) => fs.lstatSync(dest); +export const fsLstatSync = (dest: fs.PathLike) => fs.lstatSync(dest); -export const fsReadFileSync = (dest) => fs.readFileSync(dest); +export const fsReadFileSync = (dest: fs.PathLike) => fs.readFileSync(dest); -export const fsChmodSync = (dest, flag) => fs.chmodSync(dest, flag); +export const fsChmodSync = (dest: fs.PathLike, flag: fs.Mode) => fs.chmodSync(dest, flag); -export const fsRenameSync = (arg1, arg2) => fs.renameSync(arg1, arg2); +export const fsRenameSync = (arg1: fs.PathLike, arg2: fs.PathLike) => fs.renameSync(arg1, arg2); -export const fsStatSync = (arg1) => fs.statSync(arg1); +export const fsStatSync = (arg1: fs.PathLike) => fs.statSync(arg1); -export const fsMkdirSync = (arg1) => fs.mkdirSync(arg1); +export const fsMkdirSync = (arg1: fs.PathLike) => fs.mkdirSync(arg1); -export const fsUnlinkSync = (arg1) => fs.unlinkSync(arg1); +export const fsUnlinkSync = (arg1: fs.PathLike) => fs.unlinkSync(arg1); -export const fsSymlinkSync = (arg1, arg2) => { +export const fsSymlinkSync = (arg1: fs.PathLike, arg2: fs.PathLike) => { fs.symlinkSync(arg1, arg2); }; -export const fsReadFile = (arg1, arg2) => { +export const fsReadFile = (arg1: fs.PathLike, arg2) => { fs.readFile(arg1, arg2); }; -export const fsReaddir = (arg1, arg2) => fs.readdir(arg1, arg2); +export const fsReaddir = (arg1: fs.PathLike, arg2) => fs.readdir(arg1, arg2); -const _getSanitizedPath = (origPath, timestampPathsConfig) => { +const _getSanitizedPath = (origPath: fs.PathLike, timestampPathsConfig) => { if (timestampPathsConfig?.paths?.length && timestampPathsConfig?.timestamp) { const pths = timestampPathsConfig.paths; if (pths.includes(origPath)) { @@ -67,7 +68,7 @@ const _getSanitizedPath = (origPath, timestampPathsConfig) => { return origPath; }; -export const copyFileSync = (source, target, skipOverride, timestampPathsConfig) => { +export const copyFileSync = (source: string, target: string, skipOverride: boolean, timestampPathsConfig) => { logDebug('copyFileSync', source); let targetFile = target; // if target is a directory a new file with the same name will be created @@ -431,7 +432,7 @@ export const removeDirSync = (_dir, _rmSelf) => { } }; -export const writeFileSync = (filePath, obj, spaces = 4, addNewLine = true) => { +export const writeFileSync = (filePath: string, obj, spaces = 4, addNewLine = true) => { logDebug('writeFileSync', filePath); if (filePath.includes('?') || filePath.includes('undefined')) return; let output; @@ -448,13 +449,13 @@ export const writeFileSync = (filePath, obj, spaces = 4, addNewLine = true) => { return output; }; -export const writeObjectSync = (filePath, obj, spaces, addNewLine = true) => { +export const writeObjectSync = (filePath: string, obj, spaces, addNewLine = true) => { logDebug('writeObjectSync', filePath); logWarning('writeObjectSync is DEPRECATED. use writeFileSync instead'); return writeFileSync(filePath, obj, spaces, addNewLine); }; -export const readObjectSync = (filePath, sanitize = false, c) => { +export const readObjectSync = (filePath: string, sanitize?: boolean, c?: RnvConfig) => { logDebug(`readObjectSync:${sanitize}:${filePath}`); if (!filePath) { logDebug('readObjectSync: filePath is undefined'); @@ -466,7 +467,7 @@ export const readObjectSync = (filePath, sanitize = false, c) => { } let obj; try { - obj = JSON.parse(fs.readFileSync(filePath)); + obj = JSON.parse(fs.readFileSync(filePath).toString()); if (sanitize) { logDebug(`readObjectSync: will sanitize file at: ${filePath}`); if (c) { @@ -488,7 +489,7 @@ export const readObjectSync = (filePath, sanitize = false, c) => { return obj; }; -export const updateObjectSync = (filePath, updateObj) => { +export const updateObjectSync = (filePath: string, updateObj) => { let output; const obj = readObjectSync(filePath); if (obj) { @@ -500,7 +501,7 @@ export const updateObjectSync = (filePath, updateObj) => { return output; }; -export const getRealPath = (c, p, key = 'undefined', original) => { +export const getRealPath = (c: RnvConfig, p: string, key = 'undefined', original: string) => { if (!p) { if (original) { logDebug(`Path ${chalk().white(key)} is not defined. using default: ${chalk().white(original)}`); @@ -522,7 +523,7 @@ export const getRealPath = (c, p, key = 'undefined', original) => { return output; }; -const _refToValue = (c, ref, key) => { +const _refToValue = (c: RnvConfig, ref, key) => { const val = ref.replace('$REF$:', '').split('$...'); const realPath = getRealPath(c, val[0], key); @@ -574,7 +575,7 @@ export const sanitizeDynamicRefs = (c, obj) => { return obj; }; -export const resolvePackage = (text) => { +export const resolvePackage = (text: string) => { if (typeof text !== 'string') return text; const regEx = /{{resolvePackage\(([\s\S]*?)\)}}/g; const matches = text.match(regEx); @@ -590,7 +591,7 @@ export const resolvePackage = (text) => { return newText; }; -export const sanitizeDynamicProps = (obj, propConfig) => { +export const sanitizeDynamicProps = (obj: any, propConfig) => { if (!obj) { return obj; } @@ -668,8 +669,8 @@ export const mergeObjects = (c, obj1, obj2, dynamicRefs = true, replaceArrays = return dynamicRefs ? sanitizeDynamicRefs(c, obj) : obj; }; -export const updateConfigFile = async (update, globalConfigPath) => { - const configContents = JSON.parse(fs.readFileSync(globalConfigPath)); +export const updateConfigFile = async (update, globalConfigPath: string) => { + const configContents = JSON.parse(fs.readFileSync(globalConfigPath).toString()); if (update.androidSdk) { configContents.sdks.ANDROID_SDK = update.androidSdk; diff --git a/packages/rnv/src/core/systemManager/logger.ts b/packages/rnv/src/core/systemManager/logger.ts index fbdf984482..eb618d41d9 100644 --- a/packages/rnv/src/core/systemManager/logger.ts +++ b/packages/rnv/src/core/systemManager/logger.ts @@ -1,5 +1,6 @@ /* eslint-disable no-console */ import _chalk from 'chalk'; +import { RnvConfig } from '../configManager/types'; import { isSystemWin } from './utils'; function ansiRegex({ onlyFirst = false } = {}) { @@ -11,7 +12,7 @@ function ansiRegex({ onlyFirst = false } = {}) { return new RegExp(pattern, onlyFirst ? undefined : 'g'); } -export function stripAnsi(string) { +export function stripAnsi(string: string) { if (typeof string !== 'string') { throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``); } @@ -22,19 +23,21 @@ export function stripAnsi(string) { const ICN_ROCKET = isSystemWin ? 'RNV' : '🚀'; const ICN_UNICORN = isSystemWin ? 'unicorn' : '🦄'; +const _chalkPass = (v: string | boolean): string => (typeof v === 'string' ? v : String(v)); + const _chalkCols = { - white: (v) => v, - green: (v) => v, - red: (v) => v, - yellow: (v) => v, - default: (v) => v, - gray: (v) => v, - grey: (v) => v, - blue: (v) => v, - cyan: (v) => v, - magenta: (v) => v, + white: (v: string | boolean) => _chalkPass(v), + green: (v: string) => _chalkPass(v), + red: (v: string) => _chalkPass(v), + yellow: (v: string) => _chalkPass(v), + default: (v: string) => _chalkPass(v), + gray: (v: string) => _chalkPass(v), + grey: (v: string) => _chalkPass(v), + blue: (v: string) => _chalkPass(v), + cyan: (v: string) => _chalkPass(v), + magenta: (v: string) => _chalkPass(v), + rgb: () => (v: string) => _chalkPass(v), }; -_chalkCols.rgb = () => (v) => v; _chalkCols.bold = _chalkCols; const _chalkMono = { ..._chalkCols, @@ -62,14 +65,14 @@ export const logWelcome = () => { if (cnf().files?.rnv?.package?.version) { cnf().rnvVersion = cnf().files.rnv.package.version; - str += printIntoBox(` Version: ${currentChalk.green(cnf().rnvVersion)}`, 1); + str += printIntoBox(` Version: ${currentChalk.green(cnf().rnvVersion)}`); if (cnf().rnvVersion?.includes?.('alpha')) { - str += printIntoBox(` ${currentChalk.yellow('WARNING: this is a prerelease version.')}`, 1); + str += printIntoBox(` ${currentChalk.yellow('WARNING: this is a prerelease version.')}`); } } - str += printIntoBox(` ${currentChalk.grey('https://renative.org')}`, 1); - str += printIntoBox(` ${ICN_ROCKET} ${currentChalk.yellow('Firing up!...')}`, 1); - str += printIntoBox(` $ ${currentChalk.cyan(getCurrentCommand(true))}`, 1); + str += printIntoBox(` ${currentChalk.grey('https://renative.org')}`); + str += printIntoBox(` ${ICN_ROCKET} ${currentChalk.yellow('Firing up!...')}`); + str += printIntoBox(` $ ${currentChalk.cyan(getCurrentCommand(true))}`); if (global.timeStart) { str += printIntoBox(` Start Time: ${currentChalk.grey(global.timeStart.toLocaleString())}`); } @@ -80,15 +83,15 @@ export const logWelcome = () => { console.log(str); }; -let _currentProcess; +let _currentProcess: any; let _isInfoEnabled = false; -let _infoFilter = []; -let _c; +let _infoFilter: Array = []; +let _c: RnvConfig; let _isMono = false; -let _defaultColor; -let _highlightColor; +let _defaultColor = _chalkCols.white; +let _highlightColor = _chalkCols.white; let _analytics; -let _jsonOnly; +let _jsonOnly: boolean; const cnf = () => { if (!_c) { @@ -97,7 +100,7 @@ const cnf = () => { return _c; }; -const _configureLogger = (c, analytics) => { +const _configureLogger = (c: RnvConfig, analytics) => { global._messages = []; _c = c; if (!global.timeStart) global.timeStart = new Date(); @@ -120,7 +123,7 @@ const _updateDefaultColors = () => { }; _updateDefaultColors(); -export const logAndSave = (msg, skipLog) => { +export const logAndSave = (msg: string, skipLog: boolean) => { if (global._messages && !global._messages.includes(msg)) global._messages.push(msg); if (!skipLog) console.log(`${msg}`); }; @@ -155,12 +158,12 @@ export const getCurrentCommand = (excludeDollar = false) => { return `${dollar}rnv ${output}`; }; -export const logToSummary = (v, sanitizePaths) => { +export const logToSummary = (v: string, sanitizePaths?: () => string) => { const _v = sanitizePaths ? _sanitizePaths(v) : v; global._messages.push(`\n${_v}`); }; -export const logRaw = (...args) => { +export const logRaw = (...args: Array) => { if (_jsonOnly) { return _printJson({ type: 'rawLog', @@ -187,36 +190,35 @@ export const logSummary = (header = 'SUMMARY') => { let str = printBoxStart(`${ICN_ROCKET} ${header} ${timeString}`, getCurrentCommand()); - str += printIntoBox(`ReNative Version: ${_highlightColor(cnf().rnvVersion)}`, 1); + str += printIntoBox(`ReNative Version: ${_highlightColor(cnf().rnvVersion)}`); if (cnf().files?.project?.package) { - str += printIntoBox(`Project Name ($package.name): ${_highlightColor(cnf().files.project.package.name)}`, 1); + str += printIntoBox(`Project Name ($package.name): ${_highlightColor(cnf().files.project.package.name)}`); str += printIntoBox( - `Project Version ($package.version): ${_highlightColor(cnf().files.project.package.version)}`, - 1 + `Project Version ($package.version): ${_highlightColor(cnf().files.project.package.version)}` ); } if (cnf().buildConfig?.workspaceID) { - str += printIntoBox(`Workspace ($.workspaceID): ${_highlightColor(cnf().buildConfig.workspaceID)}`, 1); + str += printIntoBox(`Workspace ($.workspaceID): ${_highlightColor(cnf().buildConfig.workspaceID)}`); } if (cnf().platform) { - str += printIntoBox(`Platform (-p): ${_highlightColor(cnf().platform)}`, 1); + str += printIntoBox(`Platform (-p): ${_highlightColor(cnf().platform)}`); } if (cnf().runtime?.engine) { let addon = ''; if (cnf().platform) { addon = ` ($.platforms.${cnf().platform}.engine)`; } - str += printIntoBox(`Engine${addon}: ${_highlightColor(cnf().runtime?.engine?.config?.id)}`, 1); + str += printIntoBox(`Engine${addon}: ${_highlightColor(cnf().runtime?.engine?.config?.id)}`); } if (cnf().runtime?.activeTemplate) { - str += printIntoBox(`Template: ${_highlightColor(cnf().runtime?.activeTemplate)}`, 1); + str += printIntoBox(`Template: ${_highlightColor(cnf().runtime?.activeTemplate)}`); } if (cnf().buildConfig?._meta?.currentAppConfigId) { - str += printIntoBox(`App Config (-c): ${_highlightColor(cnf().buildConfig._meta?.currentAppConfigId)}`, 1); + str += printIntoBox(`App Config (-c): ${_highlightColor(cnf().buildConfig._meta?.currentAppConfigId)}`); } if (cnf().runtime?.scheme) { - str += printIntoBox(`Build Scheme (-s): ${_highlightColor(cnf().runtime?.scheme)}`, 1); + str += printIntoBox(`Build Scheme (-s): ${_highlightColor(cnf().runtime?.scheme)}`); } if (cnf().runtime?.bundleAssets) { str += printIntoBox( @@ -227,13 +229,13 @@ export const logSummary = (header = 'SUMMARY') => { ); } if (cnf().runtime?.target) { - str += printIntoBox(`Target (-t): ${_highlightColor(cnf().runtime?.target)}`, 1); + str += printIntoBox(`Target (-t): ${_highlightColor(cnf().runtime?.target)}`); } if (cnf().program?.reset) { - str += printIntoBox(`Reset Project (-r): ${_highlightColor(!!cnf().program?.reset)}`, 1); + str += printIntoBox(`Reset Project (-r): ${_highlightColor(!!cnf().program?.reset)}`); } if (cnf().program?.resetHard) { - str += printIntoBox(`Reset Project and Assets (-R): ${_highlightColor(!!cnf().program?.resetHard)}`, 1); + str += printIntoBox(`Reset Project and Assets (-R): ${_highlightColor(!!cnf().program?.resetHard)}`); } if (cnf().runtime?.supportedPlatforms?.length) { const plats = cnf().runtime.supportedPlatforms.map((v) => `${v.platform}${v.isConnected ? '' : '(ejected)'}`); @@ -243,17 +245,19 @@ export const logSummary = (header = 'SUMMARY') => { if (cnf().files?.project?.config?.defaults) { const defaultProjectConfigs = cnf().files.project.config.defaults; if (defaultProjectConfigs?.template) { - str += printIntoBox(`Master Template: ${_highlightColor(defaultProjectConfigs.template)}`, 1); + str += printIntoBox(`Master Template: ${_highlightColor(defaultProjectConfigs.template)}`); } } if (cnf().process) { const envString = `${cnf().process.platform} | ${cnf().process.arch} | node v${cnf().process.versions?.node}`; - str += printIntoBox(`Env Info: ${currentChalk.gray(envString)}`, 1); + str += printIntoBox(`Env Info: ${currentChalk.gray(envString)}`); } if (global.timeEnd) { - str += printIntoBox(`Executed Time: ${currentChalk.yellow(_msToTime(global.timeEnd - global.timeStart))}`, 1); + str += printIntoBox( + `Executed Time: ${currentChalk.yellow(_msToTime(global.timeEnd.getTime() - global.timeStart.getTime()))}` + ); } str += printIntoBox(''); @@ -261,14 +265,14 @@ export const logSummary = (header = 'SUMMARY') => { str += printIntoBox(''); if (cnf().runtime?.platformBuildsProjectPath) { str += printIntoBox('Project location:'); - str += printIntoBox(`${currentChalk.cyan(_sanitizePaths(cnf().runtime.platformBuildsProjectPath))}`, 1); + str += printIntoBox(`${currentChalk.cyan(_sanitizePaths(cnf().runtime.platformBuildsProjectPath))}`); } str += printBoxEnd(); console.log(str); }; -const _msToTime = (seconds) => { +const _msToTime = (seconds: number) => { let s = seconds; const ms = s % 1000; s = (s - ms) / 1000; @@ -282,7 +286,7 @@ const _msToTime = (seconds) => { const _getCurrentTask = () => (cnf()._currentTask ? currentChalk.grey(` [${cnf()._currentTask}]`) : ''); -const _sanitizePaths = (msg) => { +const _sanitizePaths = (msg: string) => { // let dir // const config = cnf().files?.project?.config; // if(config && config.isMonorepo) { @@ -294,9 +298,9 @@ const _sanitizePaths = (msg) => { return msg; }; -const TASK_COUNTER = {}; +const TASK_COUNTER: Record = {}; -export const logTask = (task, customChalk) => { +export const logTask = (task: string, customChalk: any) => { if (!TASK_COUNTER[task]) TASK_COUNTER[task] = 0; TASK_COUNTER[task] += 1; const taskCount = currentChalk.grey(`[${TASK_COUNTER[task]}]`); @@ -323,7 +327,7 @@ export const logTask = (task, customChalk) => { console.log(_sanitizePaths(msg)); }; -export const logInitTask = (task, customChalk) => { +export const logInitTask = (task: string, customChalk) => { if (_jsonOnly) { return _printJson({ type: 'taskInit', @@ -343,7 +347,7 @@ export const logInitTask = (task, customChalk) => { console.log(msg); }; -export const logExitTask = (task, customChalk) => { +export const logExitTask = (task: string, customChalk) => { if (_jsonOnly) { return _printJson({ type: 'taskExit', @@ -376,7 +380,7 @@ export const logHook = (hook = '', msg = '') => { ); }; -export const logWarning = (msg) => { +export const logWarning = (msg: string) => { if (_jsonOnly) { return _printJson({ type: 'log', @@ -388,7 +392,7 @@ export const logWarning = (msg) => { logAndSave(currentChalk.yellow(`[ warn ]${_getCurrentTask()} ${_sanitizePaths(msg)}`)); }; -export const logInfo = (msg) => { +export const logInfo = (msg: string) => { if (_jsonOnly) { return _printJson({ type: 'log', @@ -400,7 +404,7 @@ export const logInfo = (msg) => { console.log(currentChalk.cyan(`[ info ]${_getCurrentTask()} ${_sanitizePaths(msg)}`)); }; -export const logDebug = (...args) => { +export const logDebug = (...args: Array) => { if (_isInfoEnabled) { if (_jsonOnly) { return _printJson({ @@ -473,7 +477,7 @@ export const logError = (e, isEnd = false, skipAnalytics = false) => { if (isEnd) logEnd(1); }; -export const logEnd = (code) => { +export const logEnd = (code: number) => { if (!_jsonOnly) { logSummary(); } @@ -490,13 +494,13 @@ export const logInitialize = () => { if (!_jsonOnly) logWelcome(); }; -export const logAppInfo = (c) => { +export const logAppInfo = (c: RnvConfig) => { if (!_jsonOnly) { logInfo(`Current App Config: ${currentChalk.bold.white(c.runtime.appId)}`); } }; -export const printIntoBox = (str) => { +export const printIntoBox = (str: string) => { let output = _defaultColor('│ '); const strLenDiff = str.length - stripAnsi(str).length; @@ -515,7 +519,7 @@ export const printIntoBox = (str) => { return output; }; -export const printArrIntoBox = (arr, prefix = '') => { +export const printArrIntoBox = (arr: Array, prefix = '') => { if (_jsonOnly) return arr; let output = ''; @@ -527,7 +531,7 @@ export const printArrIntoBox = (arr, prefix = '') => { if (i === 0 && prefix.length) { output += printIntoBox(`${_defaultColor(prefix)}${_defaultColor(stringArr)}`, 2); } else { - output += printIntoBox(_defaultColor(stringArr), 1); + output += printIntoBox(_defaultColor(stringArr)); } stringArr = ''; @@ -539,13 +543,13 @@ export const printArrIntoBox = (arr, prefix = '') => { if (i === 0 && prefix.length) { output += printIntoBox(`${_defaultColor(prefix)}${_defaultColor(stringArr.slice(0, -2))}`, 2); } else { - output += printIntoBox(_defaultColor(stringArr.slice(0, -2)), 1); + output += printIntoBox(_defaultColor(stringArr.slice(0, -2))); } return output; }; -export const printBoxStart = (str, str2) => { +export const printBoxStart = (str: string, str2: string) => { let output = _defaultColor('┌──────────────────────────────────────────────────────────────────────────────┐\n'); output += printIntoBox(str); output += printIntoBox(str2 || ''); diff --git a/packages/rnv/src/core/systemManager/types.ts b/packages/rnv/src/core/systemManager/types.ts index 46c56621ca..f15a8f0eef 100644 --- a/packages/rnv/src/core/systemManager/types.ts +++ b/packages/rnv/src/core/systemManager/types.ts @@ -15,3 +15,7 @@ export type ExecOptions = { env?: Record; ignoreErrors?: boolean; }; + +export type ExecCallback = (isError: boolean) => void; + +export type ExecCallback2 = (result: any, isError: boolean) => void; diff --git a/packages/rnv/src/typings/global.d.ts b/packages/rnv/src/typings/global.d.ts new file mode 100644 index 0000000000..d63e937ec2 --- /dev/null +++ b/packages/rnv/src/typings/global.d.ts @@ -0,0 +1,14 @@ +export {}; + +declare global { + //eslint-disable-next-line no-var + var _messages: Array; + //eslint-disable-next-line no-var + var timeEnd: Date + //eslint-disable-next-line no-var + var timeStart: Date + //eslint-disable-next-line no-var + var RNV_CONFIG + //eslint-disable-next-line no-var + var RNV_ANALYTICS +} From 4739e196619f20ea3ada5187c920f975d46442b9 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Tue, 29 Aug 2023 21:25:37 +0200 Subject: [PATCH 09/83] types conversions, 1647 togo --- packages/rnv/src/core/configManager/types.ts | 5 +- .../rnv/src/core/systemManager/analytics.ts | 2 +- packages/rnv/src/core/systemManager/crypto.ts | 7 +- packages/rnv/src/core/systemManager/doctor.ts | 21 ++--- .../rnv/src/core/systemManager/fileutils.ts | 77 ++++++++++--------- packages/rnv/src/core/systemManager/logger.ts | 42 ++++++---- packages/rnv/src/core/systemManager/types.ts | 10 +++ packages/rnv/src/typings/global.d.ts | 4 + 8 files changed, 100 insertions(+), 68 deletions(-) diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index ca92550afe..863b27d10a 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -6,6 +6,7 @@ export interface RnvConfig { platform: string; process: any; rnvVersion: string; + _currentTask?: string; //======= _renativePluginCache: any; cli: any; @@ -55,8 +56,8 @@ export interface RnvConfig { engines: Record; projectTemplate: Record; //ADDON - dir?: string; - package?: string; + dir: string; + package: string; // config: string; // configLocal: string; // configPrivate: string; diff --git a/packages/rnv/src/core/systemManager/analytics.ts b/packages/rnv/src/core/systemManager/analytics.ts index 0c5ad6482e..3d43c86384 100644 --- a/packages/rnv/src/core/systemManager/analytics.ts +++ b/packages/rnv/src/core/systemManager/analytics.ts @@ -43,7 +43,7 @@ class Redash { } } -class Analytics { +export class Analytics { constructor() { this.errorFixer = null; this.knowItAll = null; diff --git a/packages/rnv/src/core/systemManager/crypto.ts b/packages/rnv/src/core/systemManager/crypto.ts index e7d4e6a7e5..d7d55960b0 100644 --- a/packages/rnv/src/core/systemManager/crypto.ts +++ b/packages/rnv/src/core/systemManager/crypto.ts @@ -4,15 +4,16 @@ import { isSystemWin } from './utils'; import { getRealPath, fsExistsSync, fsReadFileSync } from './fileutils'; import { TASK_CRYPTO_DECRYPT } from '../constants'; import { executeTask } from '../taskManager'; +import { RnvConfig } from '../configManager/types'; -export const getEnvExportCmd = (envVar, key) => { +export const getEnvExportCmd = (envVar: string, key: string) => { if (isSystemWin) { return `${chalk().white(`setx ${envVar} "${key}"`)}`; } return `${chalk().white(`export ${envVar}="${key}"`)}`; }; -export const getEnvVar = (c) => { +export const getEnvVar = (c: RnvConfig) => { const p1 = c.paths.workspace.dir.split('/').pop().replace('.', ''); const p2 = c.files.project.package.name.replace('@', '').replace('/', '_').replace(/-/g, '_'); const envVar = `CRYPTO_${p1}_${p2}`.toUpperCase(); @@ -20,7 +21,7 @@ export const getEnvVar = (c) => { return envVar; }; -export const checkCrypto = async (c, parentTask, originTask) => { +export const checkCrypto = async (c: RnvConfig, parentTask, originTask) => { logTask('checkCrypto'); if (c.program.ci || c.files.project.config?.crypto?.optional) return; diff --git a/packages/rnv/src/core/systemManager/doctor.ts b/packages/rnv/src/core/systemManager/doctor.ts index 55ffa8dc68..f94e9de73c 100644 --- a/packages/rnv/src/core/systemManager/doctor.ts +++ b/packages/rnv/src/core/systemManager/doctor.ts @@ -1,12 +1,13 @@ import { writeFileSync, readObjectSync } from './fileutils'; import { PACKAGE_JSON_FILEDS } from '../constants'; import { chalk, logWarning } from './logger'; +import { RnvConfig } from '../configManager/types'; -const getSortedObject = (obj) => { +const getSortedObject = (obj: any) => { if (obj !== null && typeof obj === 'object' && !Array.isArray(obj)) { const keys = Object.keys(obj).sort(); - const newObj = {}; - const addedKeys = {}; + const newObj: Record = {}; + const addedKeys: Record = {}; keys.forEach((v) => { if (!addedKeys[v]) { newObj[v] = obj[v]; @@ -21,8 +22,8 @@ const getSortedObject = (obj) => { return obj; }; -const checkForDuplicates = (arr) => { - const dupCheck = {}; +const checkForDuplicates = (arr: Array) => { + const dupCheck: Record = {}; arr.forEach((v) => { if (v) { Object.keys(v).forEach((k) => { @@ -35,8 +36,8 @@ const checkForDuplicates = (arr) => { }); }; -const fixPackageJson = (c, pkgPath) => - new Promise((resolve) => { +const fixPackageJson = (c: RnvConfig, pkgPath: string) => + new Promise((resolve) => { const pth = pkgPath || c.paths.project.package; const pp = readObjectSync(pth); const output = fixPackageObject(pp); @@ -44,9 +45,9 @@ const fixPackageJson = (c, pkgPath) => resolve(); }); -const fixPackageObject = (pp) => { - const output = {}; - const usedKeys = {}; +const fixPackageObject = (pp: Record) => { + const output: Record = {}; + const usedKeys: Record = {}; PACKAGE_JSON_FILEDS.forEach((v) => { if (pp[v] !== null) { diff --git a/packages/rnv/src/core/systemManager/fileutils.ts b/packages/rnv/src/core/systemManager/fileutils.ts index 2468fefda7..d1e3dcb5c7 100755 --- a/packages/rnv/src/core/systemManager/fileutils.ts +++ b/packages/rnv/src/core/systemManager/fileutils.ts @@ -7,6 +7,7 @@ import merge from 'deepmerge'; import ncp from 'ncp'; import { chalk, logDebug, logError, logWarning } from './logger'; import { RnvConfig } from '../configManager/types'; +import { OverridesOptions } from './types'; export const configureFilesystem = (_getConfigProp, _doResolve, _isSystemWin) => { global.getConfigProp = _getConfigProp; @@ -138,7 +139,7 @@ export const writeCleanFile = (source, destination, overrides, timestampPathsCon } }; -export const readCleanFile = (source, overrides) => { +export const readCleanFile = (source: string, overrides: OverridesOptions) => { // logTask(`writeCleanFile`) // console.log('readCleanFile', source); if (!fs.existsSync(source)) { @@ -158,7 +159,14 @@ export const readCleanFile = (source, overrides) => { return Buffer.from(pFileClean, 'utf8'); }; -export const copyFileWithInjectSync = (source, target, skipOverride, injectObject, timestampPathsConfig, c) => { +export const copyFileWithInjectSync = ( + source: string, + target: string, + skipOverride: boolean, + injectObject: object | null, + timestampPathsConfig, + c: RnvConfig +) => { logDebug('copyFileWithInjectSync', source); let targetFile = target; @@ -175,7 +183,7 @@ export const copyFileWithInjectSync = (source, target, skipOverride, injectObjec const src = readCleanFile(source, injectObject); const dst = fs.readFileSync(targetFile); - if (Buffer.compare(src, dst) === 0) return; + if (src && Buffer.compare(src, dst) === 0) return; } logDebug('copyFileSync', source, targetFile, 'executed'); @@ -186,7 +194,7 @@ export const copyFileWithInjectSync = (source, target, skipOverride, injectObjec } }; -export const invalidatePodsChecksum = (c) => { +export const invalidatePodsChecksum = (c: RnvConfig) => { const appFolder = path.join(c.paths.project.builds.dir, `${c.runtime.appId}_${c.platform}`); const podChecksumPath = path.join(appFolder, 'Podfile.checksum'); if (fs.existsSync(podChecksumPath)) { @@ -195,14 +203,14 @@ export const invalidatePodsChecksum = (c) => { }; export const copyFolderRecursiveSync = ( - source, - target, + source: string, + target: string, convertSvg = true, - skipOverride, + skipOverride: boolean, injectObject = null, timestampPathsConfig = null, - c, - extFilter = null + c: RnvConfig, + extFilter: Array | null = null ) => { logDebug('copyFolderRecursiveSync', source, target); if (!fs.existsSync(source)) return; @@ -235,7 +243,7 @@ export const copyFolderRecursiveSync = ( saveAsJs(curSource, jsDest); } else if (injectObject !== null) { copyFileWithInjectSync(curSource, targetFolder, skipOverride, injectObject, timestampPathsConfig, c); - } else if (extFilter?.length > 0) { + } else if (extFilter && extFilter?.length > 0) { if (extFilter.includes(path.extname(curSource)) || extFilter.includes(path.basename(curSource))) { copyFileSync(curSource, targetFolder, skipOverride, timestampPathsConfig); } @@ -247,15 +255,15 @@ export const copyFolderRecursiveSync = ( }; export const copyFolderContentsRecursiveSync = ( - source, - target, + source: string, + target: string, convertSvg = true, - skipPaths, - skipOverride, - injectObject = null, + skipPaths: Array, + skipOverride: boolean, + injectObject: object | null = null, timestampPathsConfig = null, - c, - extFilter = null + c: RnvConfig, + extFilter: Array | null = null ) => { logDebug('copyFolderContentsRecursiveSync', source, target, skipPaths); if (!fs.existsSync(source)) return; @@ -293,7 +301,7 @@ export const copyFolderContentsRecursiveSync = ( const jsDest = path.join(targetFolder, `${path.basename(curSource)}.js`); logDebug(`file ${curSource} is svg and convertSvg is set to true. converting to ${jsDest}`); saveAsJs(curSource, jsDest); - } else if (extFilter?.length > 0) { + } else if (extFilter && extFilter?.length > 0) { if (extFilter.includes(path.extname(curSource)) || extFilter.includes(path.basename(curSource))) { copyFileSync(curSource, targetFolder, skipOverride, timestampPathsConfig); } @@ -305,8 +313,8 @@ export const copyFolderContentsRecursiveSync = ( } }; -export const copyFolderContentsRecursive = (source, target, convertSvg = true, skipPaths) => - new Promise((resolve, reject) => { +export const copyFolderContentsRecursive = (source: string, target: string, convertSvg = true, skipPaths?: boolean) => + new Promise((resolve, reject) => { logDebug('copyFolderContentsRecursive', source, target, skipPaths, convertSvg); if (!fs.existsSync(source)) return; const targetFolder = path.resolve(target); @@ -321,18 +329,18 @@ export const copyFolderContentsRecursive = (source, target, convertSvg = true, s }); }); -export const saveAsJs = (source, dest) => { +export const saveAsJs = (source: string, dest: string) => { Svg2Js.createSync({ source, destination: dest, }); }; -export const removeDir = (pth, callback) => { +export const removeDir = (pth: string, callback) => { rimraf(pth, callback); }; -export const mkdirSync = (dir) => { +export const mkdirSync = (dir: string) => { if (!dir) return; if (fs.existsSync(dir)) return; try { @@ -342,8 +350,8 @@ export const mkdirSync = (dir) => { } }; -export const cleanFolder = (d) => - new Promise((resolve) => { +export const cleanFolder = (d: string) => + new Promise((resolve) => { logDebug('cleanFolder', d); removeDir(d, () => { mkdirSync(d); @@ -351,7 +359,7 @@ export const cleanFolder = (d) => }); }); -export const removeFilesSync = (filePaths) => { +export const removeFilesSync = (filePaths: Array) => { logDebug('removeFilesSync', filePaths); filePaths.forEach((filePath) => { try { @@ -366,7 +374,7 @@ export const removeFilesSync = (filePaths) => { }); }; -export const removeDirsSync = (dirPaths) => { +export const removeDirsSync = (dirPaths: Array) => { logDebug('removeDirsSync', dirPaths); for (let i = 0; i < dirPaths.length; i++) { @@ -378,14 +386,13 @@ export const removeDirsSync = (dirPaths) => { } }; -/* eslint-disable no-loop-func */ -export const removeDirs = (dirPaths) => - new Promise((resolve) => { +export const removeDirs = (dirPaths: Array) => + new Promise((resolve) => { logDebug('removeDirs', dirPaths); const allFolders = dirPaths.length; let deletedFolders = 0; for (let i = 0; i < allFolders; i++) { - rimraf(dirPaths[i], (e) => { + rimraf(dirPaths[i], (e: string | Error) => { if (e) { logError(e); } @@ -396,7 +403,7 @@ export const removeDirs = (dirPaths) => if (allFolders === 0) resolve(); }); -export const removeDirSync = (_dir, _rmSelf) => { +export const removeDirSync = (_dir: string, _rmSelf?: boolean) => { let dir = _dir; let rmSelf = _rmSelf; let files; @@ -660,7 +667,7 @@ const _bindStringVals = (obj, _val, newKey, propConfig) => { } }; -export const mergeObjects = (c, obj1, obj2, dynamicRefs = true, replaceArrays = false) => { +export const mergeObjects = (c: RnvConfig, obj1, obj2, dynamicRefs = true, replaceArrays = false) => { if (!obj2) return obj1; if (!obj1) return obj2; const obj = merge(obj1, obj2, { @@ -694,8 +701,8 @@ export const replaceHomeFolder = (p) => { return p.replace('~', process.env.HOME); }; -export const getFileListSync = (dir) => { - let results = []; +export const getFileListSync = (dir: fs.PathLike) => { + let results: Array = []; const list = fs.readdirSync(dir); list.forEach((file) => { const fileFixed = `${dir}/${file}`; diff --git a/packages/rnv/src/core/systemManager/logger.ts b/packages/rnv/src/core/systemManager/logger.ts index eb618d41d9..ce9a7bd90b 100644 --- a/packages/rnv/src/core/systemManager/logger.ts +++ b/packages/rnv/src/core/systemManager/logger.ts @@ -1,6 +1,7 @@ /* eslint-disable no-console */ import _chalk from 'chalk'; import { RnvConfig } from '../configManager/types'; +import { AnalyticsApi } from './types'; import { isSystemWin } from './utils'; function ansiRegex({ onlyFirst = false } = {}) { @@ -90,7 +91,7 @@ let _c: RnvConfig; let _isMono = false; let _defaultColor = _chalkCols.white; let _highlightColor = _chalkCols.white; -let _analytics; +let _analytics: AnalyticsApi; let _jsonOnly: boolean; const cnf = () => { @@ -123,14 +124,14 @@ const _updateDefaultColors = () => { }; _updateDefaultColors(); -export const logAndSave = (msg: string, skipLog: boolean) => { +export const logAndSave = (msg: string, skipLog?: boolean) => { if (global._messages && !global._messages.includes(msg)) global._messages.push(msg); if (!skipLog) console.log(`${msg}`); }; const PRIVATE_PARAMS = ['-k', '--key']; -const _printJson = (obj) => { +const _printJson = (obj: PrintJsonPayload) => { // sanitize if (obj.task) { obj.task = obj.task.trim().replace('[', '').replace(']', ''); @@ -224,8 +225,7 @@ export const logSummary = (header = 'SUMMARY') => { str += printIntoBox( `Bundle assets ($.platforms.${cnf().platform}.bundleAssets): ${_highlightColor( !!cnf().runtime?.bundleAssets - )}`, - 1 + )}` ); } if (cnf().runtime?.target) { @@ -300,7 +300,7 @@ const _sanitizePaths = (msg: string) => { const TASK_COUNTER: Record = {}; -export const logTask = (task: string, customChalk: any) => { +export const logTask = (task: string, customChalk?: any) => { if (!TASK_COUNTER[task]) TASK_COUNTER[task] = 0; TASK_COUNTER[task] += 1; const taskCount = currentChalk.grey(`[${TASK_COUNTER[task]}]`); @@ -327,7 +327,7 @@ export const logTask = (task: string, customChalk: any) => { console.log(_sanitizePaths(msg)); }; -export const logInitTask = (task: string, customChalk) => { +export const logInitTask = (task: string, customChalk: string | ((s: string) => string)) => { if (_jsonOnly) { return _printJson({ type: 'taskInit', @@ -347,7 +347,15 @@ export const logInitTask = (task: string, customChalk) => { console.log(msg); }; -export const logExitTask = (task: string, customChalk) => { +type PrintJsonPayload = { + type: string; + task?: string; + message: string; + hook?: any; + level?: string; +}; + +export const logExitTask = (task: string, customChalk: (s: string) => string) => { if (_jsonOnly) { return _printJson({ type: 'taskExit', @@ -369,7 +377,7 @@ export const logExitTask = (task: string, customChalk) => { export const logHook = (hook = '', msg = '') => { if (_jsonOnly) { - const payload = { type: 'hook', hook, message: stripAnsi(_sanitizePaths(msg)) }; + const payload: PrintJsonPayload = { type: 'hook', hook, message: stripAnsi(_sanitizePaths(msg)) }; if (_getCurrentTask()) payload.task = stripAnsi(_getCurrentTask()); return _printJson(payload); } @@ -404,14 +412,14 @@ export const logInfo = (msg: string) => { console.log(currentChalk.cyan(`[ info ]${_getCurrentTask()} ${_sanitizePaths(msg)}`)); }; -export const logDebug = (...args: Array) => { +export const logDebug = (...args: Array) => { if (_isInfoEnabled) { if (_jsonOnly) { return _printJson({ type: 'log', level: 'debug', task: stripAnsi(_getCurrentTask()), - message: stripAnsi(_sanitizePaths(...args)), + message: stripAnsi(_sanitizePaths(args.join(' '))), }); } if (_infoFilter) { @@ -434,7 +442,7 @@ export const logComplete = (isEnd = false) => { if (isEnd) logEnd(0); }; -export const logSuccess = (msg) => { +export const logSuccess = (msg: string) => { if (_jsonOnly) { return _printJson({ type: 'success', @@ -445,7 +453,7 @@ export const logSuccess = (msg) => { logAndSave(currentChalk.magenta(`[ success ]${_getCurrentTask()} ${_sanitizePaths(msg)}`)); }; -export const logError = (e, isEnd = false, skipAnalytics = false) => { +export const logError = (e: Error | string, isEnd = false, skipAnalytics = false) => { if (!skipAnalytics && !!_analytics) { const extra = { command: getCurrentCommand(), @@ -465,9 +473,9 @@ export const logError = (e, isEnd = false, skipAnalytics = false) => { type: 'log', level: 'error', task: stripAnsi(_getCurrentTask()), - message: stripAnsi(_sanitizePaths(e?.message || e)), + message: stripAnsi(_sanitizePaths(e instanceof Error ? e.message : e)), }); - } else if (e && e.message) { + } else if (e && e instanceof Error && e.message) { logAndSave(currentChalk.red(`[ error ]${_getCurrentTask()} ${e.message}\n${e.stack}`), isEnd); } else { logAndSave(currentChalk.red(`[ error ]${_getCurrentTask()} ${e}`), isEnd); @@ -529,7 +537,7 @@ export const printArrIntoBox = (arr: Array, prefix = '') => { const l = i === 0 ? 60 - _defaultColor(prefix).length : 60; if (stringArr.length > l) { if (i === 0 && prefix.length) { - output += printIntoBox(`${_defaultColor(prefix)}${_defaultColor(stringArr)}`, 2); + output += printIntoBox(`${_defaultColor(prefix)}${_defaultColor(stringArr)}`); } else { output += printIntoBox(_defaultColor(stringArr)); } @@ -541,7 +549,7 @@ export const printArrIntoBox = (arr: Array, prefix = '') => { // stringArr[i] += `${c.platformDefaults[v].icon} ${currentChalk.white(v)}, `; }); if (i === 0 && prefix.length) { - output += printIntoBox(`${_defaultColor(prefix)}${_defaultColor(stringArr.slice(0, -2))}`, 2); + output += printIntoBox(`${_defaultColor(prefix)}${_defaultColor(stringArr.slice(0, -2))}`); } else { output += printIntoBox(_defaultColor(stringArr.slice(0, -2))); } diff --git a/packages/rnv/src/core/systemManager/types.ts b/packages/rnv/src/core/systemManager/types.ts index f15a8f0eef..c5cfcdff5e 100644 --- a/packages/rnv/src/core/systemManager/types.ts +++ b/packages/rnv/src/core/systemManager/types.ts @@ -19,3 +19,13 @@ export type ExecOptions = { export type ExecCallback = (isError: boolean) => void; export type ExecCallback2 = (result: any, isError: boolean) => void; + +export type AnalyticsApi = { + captureException: (e: string | Error, context: { extra: any }) => void; + teardown: () => Promise; +}; + +export type OverridesOptions = Array<{ + pattern: string; + override: string; +}>; diff --git a/packages/rnv/src/typings/global.d.ts b/packages/rnv/src/typings/global.d.ts index d63e937ec2..205d105f94 100644 --- a/packages/rnv/src/typings/global.d.ts +++ b/packages/rnv/src/typings/global.d.ts @@ -11,4 +11,8 @@ declare global { var RNV_CONFIG //eslint-disable-next-line no-var var RNV_ANALYTICS + //eslint-disable-next-line no-var + var isSystemWin: boolean; + //eslint-disable-next-line no-var + var doResolve; } From 6a2e9a5cefd429ab25b3828dbac7bb79bf115d28 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Tue, 29 Aug 2023 21:48:10 +0200 Subject: [PATCH 10/83] type migrations, 1518 togo --- packages/rnv/src/core/common.ts | 7 +- packages/rnv/src/core/configManager/types.ts | 6 +- .../rnv/src/core/integrationManager/index.ts | 5 +- .../rnv/src/core/platformManager/index.ts | 18 +++-- .../rnv/src/core/systemManager/analytics.ts | 15 ++-- .../rnv/src/core/systemManager/fileutils.ts | 70 ++++++++++--------- .../rnv/src/core/systemManager/gitUtils.ts | 3 +- .../rnv/src/core/systemManager/resolve.ts | 12 ++-- packages/rnv/src/typings/global.d.ts | 2 + 9 files changed, 81 insertions(+), 57 deletions(-) diff --git a/packages/rnv/src/core/common.ts b/packages/rnv/src/core/common.ts index cb0bb7100f..0e542b88f6 100755 --- a/packages/rnv/src/core/common.ts +++ b/packages/rnv/src/core/common.ts @@ -10,6 +10,7 @@ import { CLI_PROPS } from './constants'; import { fsExistsSync, writeCleanFile } from './systemManager/fileutils'; import { chalk, logDebug, logError, logSuccess, logTask, logWarning } from './systemManager/logger'; import { getValidLocalhost } from './systemManager/utils'; +import { RnvConfig } from './configManager/types'; export const getTimestampPathsConfig = (c, platform) => { let timestampBuildFiles; @@ -174,7 +175,7 @@ export const confirmActiveBundler = async (c) => { return true; }; -export const getPlatformBuildDir = (c, isRelativePath) => { +export const getPlatformBuildDir = (c: RnvConfig, isRelativePath?: boolean) => { if (!c.runtime.engine) { logError('getPlatformBuildDir not available without specific engine'); return null; @@ -217,7 +218,7 @@ export const getTemplateProjectDir = (c) => { }; // DEPRECATED -export const getAppFolder = (c, isRelativePath) => { +export const getAppFolder = (c: RnvConfig, isRelativePath?: boolean) => { if (isRelativePath) { return `platformBuilds/${c.runtime.appId}_${c.platform}${c.runtime._platformBuildsSuffix || ''}`; } @@ -228,7 +229,7 @@ export const getAppFolder = (c, isRelativePath) => { }; // DEPRECATED -export const getAppTemplateFolder = (c, platform) => +export const getAppTemplateFolder = (c: RnvConfig, platform: string) => path.join(c.paths.project.platformTemplatesDirs[platform], `${platform}`); const _getValueOrMergedObject = (resultCli, resultScheme, resultPlatforms, resultCommon) => { diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index 863b27d10a..64633fc908 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -33,9 +33,12 @@ export interface RnvConfig { supportedPlatforms: Array<{ platform: string; isConnected: boolean; + engine: any; }>; keepSessionActive: boolean; platformBuildsProjectPath: string; + availablePlatforms: Array; + _platformBuildsSuffix?: string; }; paths: { GLOBAL_RNV_CONFIG: string; @@ -94,7 +97,7 @@ export interface RnvConfig { config?: string; configLocal?: string; configPrivate?: string; - dir?: string; + dir: string; }; defaultWorkspace: { //ADDON @@ -142,6 +145,7 @@ export interface RnvConfig { // configsPrivate: Array; }; appConfig: { + config: string; configs: Array; configsPrivate: Array; configsLocal: Array; diff --git a/packages/rnv/src/core/integrationManager/index.ts b/packages/rnv/src/core/integrationManager/index.ts index ed74ab70e0..f49b77b05e 100644 --- a/packages/rnv/src/core/integrationManager/index.ts +++ b/packages/rnv/src/core/integrationManager/index.ts @@ -1,10 +1,11 @@ import path from 'path'; +import { RnvConfig } from '../configManager/types'; import { fsExistsSync } from '../systemManager/fileutils'; // import { getScopedVersion } from '../systemManager/utils'; import { logTask, logWarning } from '../systemManager/logger'; import { registerCustomTask } from '../taskManager'; -export const loadIntegrations = async (c) => { +export const loadIntegrations = async (c: RnvConfig) => { logTask('loadIntegrations'); const integrations = c.buildConfig?.integrations; @@ -20,7 +21,7 @@ export const loadIntegrations = async (c) => { try { const instance = require(intPath)?.default; if (instance) { - instance.getTasks().forEach((task) => { + instance.getTasks().forEach((task: any) => { registerCustomTask(c, task); }); } diff --git a/packages/rnv/src/core/platformManager/index.ts b/packages/rnv/src/core/platformManager/index.ts index d6a2921ecd..7295f952eb 100644 --- a/packages/rnv/src/core/platformManager/index.ts +++ b/packages/rnv/src/core/platformManager/index.ts @@ -5,8 +5,9 @@ import { cleanFolder, copyFolderContentsRecursiveSync, writeFileSync } from '../ import { checkAndConfigureSdks } from '../sdkManager/installer'; import { getTimestampPathsConfig, getPlatformBuildDir, getAppFolder } from '../common'; import { SUPPORTED_PLATFORMS } from '../constants'; +import { RnvConfig } from '../configManager/types'; -export const logErrorPlatform = (c) => { +export const logErrorPlatform = (c: RnvConfig) => { logError( `Platform: ${chalk().white(c.platform)} doesn't support command: ${chalk().white(c.command)}`, true // kill it if we're not supporting this @@ -14,7 +15,7 @@ export const logErrorPlatform = (c) => { return false; }; -export const updateProjectPlatforms = (c, platforms) => { +export const updateProjectPlatforms = (c: RnvConfig, platforms: Array) => { const { project: { config }, } = c.paths; @@ -24,7 +25,7 @@ export const updateProjectPlatforms = (c, platforms) => { writeFileSync(config, currentConfig); }; -export const generatePlatformChoices = (c) => { +export const generatePlatformChoices = (c: RnvConfig) => { const options = c.runtime.supportedPlatforms.map((v) => ({ name: `${v.platform} - ${ v.isConnected ? chalk().green('(connected)') : chalk().yellow('(ejected)') @@ -35,7 +36,7 @@ export const generatePlatformChoices = (c) => { return options; }; -export const cleanPlatformBuild = (c, platform) => +export const cleanPlatformBuild = (c: RnvConfig, platform: string) => new Promise((resolve) => { logTask('cleanPlatformBuild'); @@ -133,7 +134,12 @@ export const isPlatformSupported = async (c, isGlobalScope = false) => { return c.platform; }; -export const isPlatformSupportedSync = (c, platform, resolve, reject) => { +export const isPlatformSupportedSync = ( + c: RnvConfig, + platform: string, + resolve?: () => void, + reject?: (e: string) => void +) => { if (!platform) { if (reject) { reject( @@ -162,7 +168,7 @@ export const isPlatformSupportedSync = (c, platform, resolve, reject) => { return true; }; -export const isPlatformActive = (c, platform, resolve) => { +export const isPlatformActive = (c: RnvConfig, platform: string, resolve: () => void) => { if (!c.buildConfig || !c.buildConfig.platforms) { logError( `Your appConfigFile is not configured properly! check ${chalk().white(c.paths.appConfig.config)} location.` diff --git a/packages/rnv/src/core/systemManager/analytics.ts b/packages/rnv/src/core/systemManager/analytics.ts index 3d43c86384..6aeb8ef6bd 100644 --- a/packages/rnv/src/core/systemManager/analytics.ts +++ b/packages/rnv/src/core/systemManager/analytics.ts @@ -9,7 +9,7 @@ import pkg from '../../../package.json'; import { REDASH_KEY, REDASH_URL, SENTRY_ENDPOINT } from '../constants'; // deal with useless duplicate errors on sentry because of different error texts -const sanitizeError = (err) => { +const sanitizeError = (err: string) => { if (err) { if (err.includes('file if your SDK path is correct.')) { return err.toLowerCase().split('. check your ')[0]; @@ -23,7 +23,7 @@ const sanitizeError = (err) => { }; class Redash { - captureEvent(e) { + captureEvent(e: any) { const defaultProps = { fingerprint: machineIdSync(), os: os.platform(), @@ -44,6 +44,9 @@ class Redash { } export class Analytics { + errorFixer: any; + knowItAll: any; + constructor() { this.errorFixer = null; this.knowItAll = null; @@ -61,7 +64,7 @@ export class Analytics { integrations: [ new RewriteFrames({ root: '/', - iteratee: (frame) => { + iteratee: (frame: any) => { if ( frame.filename.includes(`rnv${path.sep}dist${path.sep}`) || frame.filename.includes(`rnv${path.sep}src${path.sep}`) @@ -87,7 +90,7 @@ export class Analytics { } } - captureException(e, context = {}) { + captureException(e: any, context = {}) { if (Config.isAnalyticsEnabled && this.errorFixer) { this.errorFixer.withScope((scope) => { const { extra = {}, tags = {} } = context; @@ -102,7 +105,7 @@ export class Analytics { } } - async captureEvent(e) { + async captureEvent(e: any) { if (Config.isAnalyticsEnabled && this.knowItAll) { return this.knowItAll.captureEvent(e); } @@ -110,7 +113,7 @@ export class Analytics { } teardown() { - return new Promise((resolve) => { + return new Promise((resolve) => { if (Config.isAnalyticsEnabled && this.errorFixer) { const client = this.errorFixer.getCurrentHub().getClient(); if (client) { diff --git a/packages/rnv/src/core/systemManager/fileutils.ts b/packages/rnv/src/core/systemManager/fileutils.ts index d1e3dcb5c7..c9e0820a4b 100755 --- a/packages/rnv/src/core/systemManager/fileutils.ts +++ b/packages/rnv/src/core/systemManager/fileutils.ts @@ -9,7 +9,7 @@ import { chalk, logDebug, logError, logWarning } from './logger'; import { RnvConfig } from '../configManager/types'; import { OverridesOptions } from './types'; -export const configureFilesystem = (_getConfigProp, _doResolve, _isSystemWin) => { +export const configureFilesystem = (_getConfigProp: () => string, _doResolve: () => any, _isSystemWin: boolean) => { global.getConfigProp = _getConfigProp; global.doResolve = _doResolve; global.isSystemWin = _isSystemWin; @@ -96,7 +96,7 @@ export const copyFileSync = (source: string, target: string, skipOverride: boole }; const SKIP_INJECT_EXTENSIONS = ['.jpg', '.jpeg', '.png', '.svg', '.jar', '.zip', '.ico']; -export const writeCleanFile = (source, destination, overrides, timestampPathsConfig, c) => { +export const writeCleanFile = (source: string, destination: string, overrides, timestampPathsConfig, c) => { // logTask(`writeCleanFile`) // console.log('writeCleanFile', destination); if (!fs.existsSync(source)) { @@ -258,11 +258,11 @@ export const copyFolderContentsRecursiveSync = ( source: string, target: string, convertSvg = true, - skipPaths: Array, - skipOverride: boolean, + skipPaths?: Array, + skipOverride?: boolean, injectObject: object | null = null, timestampPathsConfig = null, - c: RnvConfig, + c?: RnvConfig, extFilter: Array | null = null ) => { logDebug('copyFolderContentsRecursiveSync', source, target, skipPaths); @@ -508,7 +508,7 @@ export const updateObjectSync = (filePath: string, updateObj) => { return output; }; -export const getRealPath = (c: RnvConfig, p: string, key = 'undefined', original: string) => { +export const getRealPath = (c: RnvConfig, p: string, key = 'undefined', original?: string) => { if (!p) { if (original) { logDebug(`Path ${chalk().white(key)} is not defined. using default: ${chalk().white(original)}`); @@ -530,7 +530,7 @@ export const getRealPath = (c: RnvConfig, p: string, key = 'undefined', original return output; }; -const _refToValue = (c: RnvConfig, ref, key) => { +const _refToValue = (c: RnvConfig, ref: string, key: string) => { const val = ref.replace('$REF$:', '').split('$...'); const realPath = getRealPath(c, val[0], key); @@ -552,20 +552,21 @@ const _refToValue = (c: RnvConfig, ref, key) => { return ref; }; -export const arrayMerge = (destinationArray, sourceArray) => { +export const arrayMerge = (destinationArray: Array, sourceArray: Array) => { const jointArray = destinationArray.concat(sourceArray); const uniqueArray = jointArray.filter((item, index) => jointArray.indexOf(item) === index); return uniqueArray; }; -const _arrayMergeOverride = (destinationArray, sourceArray) => sourceArray; +const _arrayMergeOverride = (_destinationArray: Array, sourceArray: Array) => sourceArray; -export const sanitizeDynamicRefs = (c, obj) => { +export const sanitizeDynamicRefs = (c: RnvConfig, obj: any) => { if (!obj) return obj; if (Array.isArray(obj)) { obj.forEach((v) => { sanitizeDynamicRefs(c, v); }); + return obj; } Object.keys(obj).forEach((key) => { const val = obj[key]; @@ -667,7 +668,7 @@ const _bindStringVals = (obj, _val, newKey, propConfig) => { } }; -export const mergeObjects = (c: RnvConfig, obj1, obj2, dynamicRefs = true, replaceArrays = false) => { +export const mergeObjects = (c: RnvConfig, obj1: any, obj2: any, dynamicRefs = true, replaceArrays = false) => { if (!obj2) return obj1; if (!obj1) return obj2; const obj = merge(obj1, obj2, { @@ -696,9 +697,9 @@ export const updateConfigFile = async (update, globalConfigPath: string) => { fsWriteFileSync(globalConfigPath, JSON.stringify(configContents, null, 3)); }; -export const replaceHomeFolder = (p) => { - if (global.isSystemWin) return p.replace('~', process.env.USERPROFILE); - return p.replace('~', process.env.HOME); +export const replaceHomeFolder = (p: string) => { + if (global.isSystemWin) return p.replace('~', process.env.USERPROFILE || ''); + return p.replace('~', process.env.HOME || ''); }; export const getFileListSync = (dir: fs.PathLike) => { @@ -718,9 +719,11 @@ export const getFileListSync = (dir: fs.PathLike) => { return results; }; -export const loadFile = (fileObj, pathObj, key) => { +export const loadFile = (fileObj: any, pathObj: Record, key: string) => { const pKey = `${key}Exists`; - if (!fsExistsSync(pathObj[key])) { + const pth = pathObj[key]; + + if (typeof pth === 'string' && !fsExistsSync(pth)) { pathObj[pKey] = false; logDebug(`WARNING: loadFile: Path ${pathObj[key]} does not exists!`); logDebug(`FILE_EXISTS: ${key}:false path:${pathObj[key]}`); @@ -728,19 +731,22 @@ export const loadFile = (fileObj, pathObj, key) => { } pathObj[pKey] = true; try { - const fileString = fsReadFileSync(pathObj[key]).toString(); - fileObj[key] = JSON.parse(fileString); - pathObj[pKey] = true; - logDebug(`FILE_EXISTS: ${key}:true size:${formatBytes(Buffer.byteLength(fileString, 'utf8'))}`); - // if (validateRuntimeObjectSchema && fileObj[key]) { - // const valid = ajv.validate(schemaRoot, fileObj[key]); - // if (!valid) { - // logWarning(`Invalid schema in ${pathObj[key]}. ISSUES: ${JSON.stringify(ajv.errors, null, 2)}`); - // } - // } - // if (pathObj[key].includes?.('renative.json')) { - // console.log(`FILE_EXISTS: ${key}:true size:${formatBytes(Buffer.byteLength(fileString, 'utf8'))}`); - // } + if (typeof pth === 'string') { + const fileString = fsReadFileSync(pth).toString(); + fileObj[key] = JSON.parse(fileString); + pathObj[pKey] = true; + logDebug(`FILE_EXISTS: ${key}:true size:${formatBytes(Buffer.byteLength(fileString, 'utf8'))}`); + // if (validateRuntimeObjectSchema && fileObj[key]) { + // const valid = ajv.validate(schemaRoot, fileObj[key]); + // if (!valid) { + // logWarning(`Invalid schema in ${pathObj[key]}. ISSUES: ${JSON.stringify(ajv.errors, null, 2)}`); + // } + // } + // if (pathObj[key].includes?.('renative.json')) { + // console.log(`FILE_EXISTS: ${key}:true size:${formatBytes(Buffer.byteLength(fileString, 'utf8'))}`); + // } + } + return fileObj[key]; } catch (e) { logError(`loadFile: ${pathObj[key]} :: ${e}`, true); // crash if there's an error in the config file @@ -748,7 +754,7 @@ export const loadFile = (fileObj, pathObj, key) => { } }; -export const formatBytes = (bytes, decimals = 2) => { +export const formatBytes = (bytes: number, decimals = 2) => { if (bytes === 0) return '0 Bytes'; const k = 1024; @@ -761,13 +767,13 @@ export const formatBytes = (bytes, decimals = 2) => { }; // Return all directories within a directory -export const getDirectories = (source) => +export const getDirectories = (source: string) => fs .readdirSync(source, { withFileTypes: true }) .filter((dirent) => dirent.isDirectory()) .map((dirent) => dirent.name); -export const cleanEmptyFoldersRecursively = (folder) => { +export const cleanEmptyFoldersRecursively = (folder: string) => { const isDir = fsStatSync(folder).isDirectory(); if (!isDir) { return; diff --git a/packages/rnv/src/core/systemManager/gitUtils.ts b/packages/rnv/src/core/systemManager/gitUtils.ts index ca9dd483a4..dc459dfc22 100644 --- a/packages/rnv/src/core/systemManager/gitUtils.ts +++ b/packages/rnv/src/core/systemManager/gitUtils.ts @@ -1,9 +1,10 @@ import path from 'path'; +import { RnvConfig } from '../configManager/types'; import { executeAsync, commandExistsSync } from './exec'; import { fsExistsSync } from './fileutils'; import { logTask, logWarning, logInfo } from './logger'; -export const configureGit = async (c) => { +export const configureGit = async (c: RnvConfig) => { const projectPath = c.paths.project.dir; logTask(`configureGit:${projectPath}`); diff --git a/packages/rnv/src/core/systemManager/resolve.ts b/packages/rnv/src/core/systemManager/resolve.ts index 07bdf479dd..7bf1ad1da3 100644 --- a/packages/rnv/src/core/systemManager/resolve.ts +++ b/packages/rnv/src/core/systemManager/resolve.ts @@ -17,7 +17,7 @@ import path from 'path'; * @param {*} mandatory - whether it throws * @param {*} options - docs - https://tinyurl.com/r9sfpf7 && {keepSuffix: boolean} */ -export const doResolve = (aPath, mandatory = true, options = {}) => { +export const doResolve = (aPath: string, mandatory = true, options = {}) => { options.basedir = options.basedir ?? process.cwd(); try { if (aPath.startsWith('file:')) { @@ -67,7 +67,7 @@ export const doResolvePath = (aPath, mandatory = true, options = {}, fallbackBas } }; -export const isScopedPackagePath = (aPath) => { +export const isScopedPackagePath = (aPath: string) => { if (aPath.startsWith('@')) { if (!aPath.includes('/')) { throw new Error( @@ -78,8 +78,8 @@ export const isScopedPackagePath = (aPath) => { } }; -const _getPackagePathParts = (aPath) => { - let parts = []; +const _getPackagePathParts = (aPath: string) => { + let parts: RegExpMatchArray | null; if (isScopedPackagePath(aPath)) { parts = aPath.match(/^([^/]+\/[^/]+)(?:\/?(.*))/); } else { @@ -94,7 +94,7 @@ const _getPackagePathParts = (aPath) => { /** * We support path linking using 'file:' protocol (not part of official node resolution alg.) */ -const _doResolveFSPath = (aPath, options) => { +const _doResolveFSPath = (aPath: string, options) => { const fileRelPath = `${options.basedir ? `${options.basedir}/`.replace(/.*\/+$/, '/') : ''}${aPath.replace( 'file:', '' @@ -108,7 +108,7 @@ const _doResolveFSPath = (aPath, options) => { /** * @see 'LOAD_NODE_MODULES' of node resolution alg. - https://tinyurl.com/pgz6f33 */ -const _doResolveExternalPackage = (aPath, options) => { +const _doResolveExternalPackage = (aPath: string, options) => { const [packageBase, packageSuffix] = _getPackagePathParts(aPath); try { diff --git a/packages/rnv/src/typings/global.d.ts b/packages/rnv/src/typings/global.d.ts index 205d105f94..8e746947e0 100644 --- a/packages/rnv/src/typings/global.d.ts +++ b/packages/rnv/src/typings/global.d.ts @@ -15,4 +15,6 @@ declare global { var isSystemWin: boolean; //eslint-disable-next-line no-var var doResolve; + //eslint-disable-next-line no-var + var getConfigProp } From f79f79122b7e08b786b9f634b254657a553b2a98 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Tue, 29 Aug 2023 22:22:52 +0200 Subject: [PATCH 11/83] type conversions, 1395 togo --- packages/rnv/src/core/common.ts | 104 ++++++++---------- packages/rnv/src/core/configManager/index.ts | 2 +- packages/rnv/src/core/configManager/types.ts | 18 +++ packages/rnv/src/core/engineManager/index.ts | 4 +- .../rnv/src/core/platformManager/index.ts | 4 +- packages/rnv/src/core/projectManager/index.ts | 2 +- .../rnv/src/core/projectManager/package.ts | 4 +- .../core/sdkManager/deviceUtils/android.ts | 4 +- .../src/core/sdkManager/deviceUtils/apple.ts | 8 +- .../src/core/sdkManager/deviceUtils/tizen.ts | 3 +- packages/rnv/src/core/sdkManager/types.ts | 3 + packages/rnv/src/core/systemManager/exec.ts | 2 +- .../rnv/src/core/systemManager/fileutils.ts | 11 +- packages/rnv/src/core/systemManager/types.ts | 6 + .../rnv/src/core/templateManager/index.ts | 11 +- 15 files changed, 106 insertions(+), 80 deletions(-) create mode 100644 packages/rnv/src/core/sdkManager/types.ts diff --git a/packages/rnv/src/core/common.ts b/packages/rnv/src/core/common.ts index 0e542b88f6..ff5d5a746f 100755 --- a/packages/rnv/src/core/common.ts +++ b/packages/rnv/src/core/common.ts @@ -10,9 +10,9 @@ import { CLI_PROPS } from './constants'; import { fsExistsSync, writeCleanFile } from './systemManager/fileutils'; import { chalk, logDebug, logError, logSuccess, logTask, logWarning } from './systemManager/logger'; import { getValidLocalhost } from './systemManager/utils'; -import { RnvConfig } from './configManager/types'; +import { RenativeConfigBuildScheme, RenativeConfigFile, RnvConfig } from './configManager/types'; -export const getTimestampPathsConfig = (c, platform) => { +export const getTimestampPathsConfig = (c: RnvConfig, platform: string) => { let timestampBuildFiles; const pPath = path.join(c.paths.project.builds.dir, `${c.runtime.appId}_${platform}`); if (platform === 'web') { @@ -24,7 +24,7 @@ export const getTimestampPathsConfig = (c, platform) => { return null; }; -export const getCliArguments = (c) => { +export const getCliArguments = (c: RnvConfig) => { const { args, rawArgs } = c.program; const argsCopy = [...args]; let missingArg = rawArgs[rawArgs.indexOf(argsCopy[1]) + 1]; @@ -40,7 +40,7 @@ export const getCliArguments = (c) => { return argsCopy.filter((arg) => !!arg); }; -export const addSystemInjects = (c, injects) => { +export const addSystemInjects = (c: RnvConfig, injects: Array) => { if (!c.systemPropsInjects) c.systemPropsInjects = []; if (injects) { injects.forEach((item) => { @@ -69,7 +69,7 @@ export const sanitizeColor = (val, key) => { }; }; -export const getDevServerHost = (c) => { +export const getDevServerHost = (c: RnvConfig) => { let devServerHostOrig = getConfigProp(c, c.platform, 'devServerHost'); if (!devServerHostOrig) { devServerHostOrig = getConfigProp(c, c.platform, 'webpack', {}).devServerHost; @@ -129,12 +129,12 @@ export const waitForHost = async (c, suffix = 'assets/bundle.js') => { }); }; -export const existBuildsOverrideForTargetPathSync = (c, destPath) => { +export const existBuildsOverrideForTargetPathSync = (c: RnvConfig, destPath: string) => { const appFolder = getAppFolder(c); const relativePath = path.relative(appFolder, destPath); let result = false; - const pathsToCheck = []; + const pathsToCheck: Array = []; if (c.paths.appConfig.dirs) { c.paths.appConfig.dirs.forEach((v) => { @@ -183,7 +183,7 @@ export const getPlatformBuildDir = (c: RnvConfig, isRelativePath?: boolean) => { return getAppFolder(c, isRelativePath); }; -export const getPlatformOutputDir = (c) => { +export const getPlatformOutputDir = (c: RnvConfig) => { if (!c.runtime.engine) { logError('getPlatformOutputDir not available without specific engine'); return null; @@ -191,7 +191,7 @@ export const getPlatformOutputDir = (c) => { return path.join(getAppFolder(c), c.runtime.engine.outputDirName || ''); }; -export const getPlatformProjectDir = (c) => { +export const getPlatformProjectDir = (c: RnvConfig) => { if (!c.runtime.engine) { logError('getPlatformProjectDir not available without specific engine'); return null; @@ -199,7 +199,7 @@ export const getPlatformProjectDir = (c) => { return path.join(getAppFolder(c), c.runtime.engine.projectDirName || ''); }; -export const getPlatformServerDir = (c) => { +export const getPlatformServerDir = (c: RnvConfig) => { if (!c.runtime.engine) { logError('getPlatformProjectDir not available without specific engine'); return null; @@ -207,9 +207,10 @@ export const getPlatformServerDir = (c) => { return path.join(getAppFolder(c), c.runtime.engine.serverDirName || ''); }; -export const getTemplateDir = (c) => path.join(c.paths.project.platformTemplatesDirs[c.platform], `${c.platform}`); +export const getTemplateDir = (c: RnvConfig) => + path.join(c.paths.project.platformTemplatesDirs[c.platform], `${c.platform}`); -export const getTemplateProjectDir = (c) => { +export const getTemplateProjectDir = (c: RnvConfig) => { if (!c.runtime.engine) { logError('getTemplateProjectDir not available without specific engine'); return null; @@ -253,7 +254,7 @@ const _getValueOrMergedObject = (resultCli, resultScheme, resultPlatforms, resul return resultCommon; }; -export const getConfigProp = (c, platform, key, defaultVal) => { +export const getConfigProp = (c: RnvConfig, platform: string, key: string, defaultVal?: any) => { if (!c.buildConfig) { logError('getConfigProp: c.buildConfig is undefined!'); return null; @@ -261,7 +262,13 @@ export const getConfigProp = (c, platform, key, defaultVal) => { return _getConfigProp(c, platform, key, defaultVal, c.buildConfig); }; -export const _getConfigProp = (c, platform, key, defaultVal, sourceObj) => { +export const _getConfigProp = ( + c: RnvConfig, + platform: string, + key: string, + defaultVal?: any, + sourceObj?: RenativeConfigFile +) => { if (!sourceObj) return null; if (!key || !key.split) { @@ -275,15 +282,16 @@ export const _getConfigProp = (c, platform, key, defaultVal, sourceObj) => { const subKey = keyArr.join('.'); let resultPlatforms; - let scheme; + let scheme: RenativeConfigBuildScheme; if (p) { - scheme = p.buildSchemes ? p.buildSchemes[ps] : undefined; + scheme = p.buildSchemes?.[ps] || {}; resultPlatforms = getFlavouredProp(c, sourceObj.platforms[platform], baseKey); + } else { + scheme = {}; } - scheme = scheme || {}; - const resultCli = CLI_PROPS.includes(baseKey) ? c.program[baseKey] : undefined; - const resultScheme = scheme[baseKey]; + const resultCli = baseKey && CLI_PROPS.includes(baseKey) ? c.program[baseKey] : undefined; + const resultScheme = baseKey && scheme[baseKey]; const resultCommonRoot = getFlavouredProp(c, sourceObj.common, baseKey); const resultCommonScheme = getFlavouredProp(c, sourceObj.common?.buildSchemes?.[c.runtime.scheme] || {}, baseKey); const resultCommon = resultCommonScheme || resultCommonRoot; @@ -300,8 +308,8 @@ export const _getConfigProp = (c, platform, key, defaultVal, sourceObj) => { return result; }; -export const getConfigPropArray = (c, platform, key) => { - const result = []; +export const getConfigPropArray = (c: RnvConfig, platform: string, key: string) => { + const result: Array = []; const configArr = [ c.files.defaultWorkspace.config, c.files.rnv.projectTemplates.config, @@ -333,26 +341,28 @@ export const getConfigPropArray = (c, platform, key) => { return result; }; -export const getAppId = (c, platform) => { +export const getAppId = (c: RnvConfig, platform: string) => { const id = getConfigProp(c, platform, 'id'); const idSuffix = getConfigProp(c, platform, 'idSuffix'); return idSuffix ? `${id}${idSuffix}` : id; }; -export const getAppTitle = (c, platform) => getConfigProp(c, platform, 'title'); +export const getAppTitle = (c: RnvConfig, platform: string) => getConfigProp(c, platform, 'title'); -export const getAppAuthor = (c, platform) => getConfigProp(c, platform, 'author') || c.files.project.package?.author; +export const getAppAuthor = (c: RnvConfig, platform: string) => + getConfigProp(c, platform, 'author') || c.files.project.package?.author; -export const getAppLicense = (c, platform) => getConfigProp(c, platform, 'license') || c.files.project.package?.license; +export const getAppLicense = (c: RnvConfig, platform: string) => + getConfigProp(c, platform, 'license') || c.files.project.package?.license; -export const getEntryFile = (c, platform) => c.buildConfig.platforms?.[platform]?.entryFile; +export const getEntryFile = (c: RnvConfig, platform: string) => c.buildConfig.platforms?.[platform]?.entryFile; -export const getGetJsBundleFile = (c, platform) => getConfigProp(c, platform, 'getJsBundleFile'); +export const getGetJsBundleFile = (c: RnvConfig, platform: string) => getConfigProp(c, platform, 'getJsBundleFile'); -export const getAppDescription = (c, platform) => +export const getAppDescription = (c: RnvConfig, platform: string) => getConfigProp(c, platform, 'description') || c.files.project.package?.description; -export const getAppVersion = (c, platform) => { +export const getAppVersion = (c: RnvConfig, platform: string) => { const version = getConfigProp(c, platform, 'version') || c.files.project.package?.version; if (!version) { logWarning('You are missing version prop in your config. will default to 0'); @@ -364,9 +374,9 @@ export const getAppVersion = (c, platform) => { const dotLength = versionCodeArr.length; const isNumArr = versionCodeArr.map((v) => !Number.isNaN(Number(v))); - const verArr = []; + const verArr: Array = []; let i = 0; - version.split('.').map((v) => + version.split('.').map((v: string) => v.split('-').map((v2) => v2.split('+').forEach((v3) => { const isNum = !Number.isNaN(Number(v3)); @@ -389,7 +399,7 @@ export const getAppVersion = (c, platform) => { return output; }; -export const getAppVersionCode = (c, platform) => { +export const getAppVersionCode = (c: RnvConfig, platform: string) => { const versionCode = getConfigProp(c, platform, 'versionCode'); if (versionCode) return versionCode; const version = getConfigProp(c, platform, 'version') || c.files.project.package?.version; @@ -398,7 +408,7 @@ export const getAppVersionCode = (c, platform) => { return '0'; } const versionCodeFormat = getConfigProp(c, platform, 'versionCodeFormat', '00.00.00'); - const vFormatArr = versionCodeFormat.split('.').map((v) => v.length); + const vFormatArr = versionCodeFormat.split('.').map((v: string) => v.length); const versionCodeMaxCount = vFormatArr.length; const verArr = []; @@ -459,7 +469,7 @@ export const getMonorepoRoot = () => { } }; -export const getBuildsFolder = (c, platform, customPath) => { +export const getBuildsFolder = (c: RnvConfig, platform: string, customPath: string) => { const pp = customPath || c.paths.appConfig.dir; // if (!fsExistsSync(pp)) { // logWarning(`Path ${chalk().white(pp)} does not exist! creating one for you..`); @@ -479,7 +489,7 @@ export const getBuildsFolder = (c, platform, customPath) => { export const getIP = () => ip.address(); -export const checkPortInUse = (c, platform, port) => +export const checkPortInUse = (c: RnvConfig, platform: string, port: string) => new Promise((resolve, reject) => { if (port === undefined || port === null) { resolve(false); @@ -495,14 +505,14 @@ export const checkPortInUse = (c, platform, port) => }); }); -export const getFlavouredProp = (c, obj, key) => { +export const getFlavouredProp = (c: RnvConfig, obj: Record, key: string) => { if (!key || !obj) return null; const val1 = obj[`${key}@${c.runtime.scheme}`]; if (val1) return val1; return obj[key]; }; -export const getBuildFilePath = (c, platform, filePath) => { +export const getBuildFilePath = (c: RnvConfig, platform: string, filePath: string) => { // P1 => platformTemplates let sp = path.join(getAppTemplateFolder(c, platform), filePath); // P2 => appConfigs/base + @buildSchemes @@ -532,24 +542,4 @@ export default { getConfigProp, getIP, checkPortInUse, - logTask: (val) => { - logError('DEPRECATED: Common.logTask() has been removed. use Logger.logTask() instead'); - logTask(val); - }, - logWarning: (val) => { - logError('DEPRECATED: Common.logWarning() has been removed. use Logger.logWarning() instead'); - logWarning(val); - }, - logError: (val) => { - logError('DEPRECATED: Common.logError() has been removed. use Logger.logError() instead'); - logError(val); - }, - logSuccess: (val) => { - logError('DEPRECATED: Common.logError() has been removed. use Logger.logError() instead'); - logSuccess(val); - }, - logDebug: (val) => { - logError('DEPRECATED: Common.logDebug() has been removed. use Logger.logDebug() instead'); - logDebug(val); - }, }; diff --git a/packages/rnv/src/core/configManager/index.ts b/packages/rnv/src/core/configManager/index.ts index dc75080425..b120b42c18 100644 --- a/packages/rnv/src/core/configManager/index.ts +++ b/packages/rnv/src/core/configManager/index.ts @@ -440,7 +440,7 @@ const _generatePlatformTemplatePaths = (c: RnvConfig) => { return result; }; -export const listAppConfigsFoldersSync = (c: RnvConfig, ignoreHiddenConfigs, appConfigsDirPath) => { +export const listAppConfigsFoldersSync = (c: RnvConfig, ignoreHiddenConfigs: boolean, appConfigsDirPath?: string) => { logTask('listAppConfigsFoldersSync', `ignoreHiddenConfigs:${!!ignoreHiddenConfigs}`); if (!c.paths?.project) return []; diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index 64633fc908..ea46baf1e8 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -7,6 +7,7 @@ export interface RnvConfig { process: any; rnvVersion: string; _currentTask?: string; + systemPropsInjects: Array; //======= _renativePluginCache: any; cli: any; @@ -39,6 +40,7 @@ export interface RnvConfig { platformBuildsProjectPath: string; availablePlatforms: Array; _platformBuildsSuffix?: string; + timestamp: number; }; paths: { GLOBAL_RNV_CONFIG: string; @@ -149,6 +151,7 @@ export interface RnvConfig { configs: Array; configsPrivate: Array; configsLocal: Array; + dir: string; }; // EXTRA buildHooks: { @@ -163,6 +166,7 @@ export interface RnvConfig { builds: Record; assets: Record; platformTemplates: Record; + appConfigsDir: string; }; }; files: { @@ -270,3 +274,17 @@ export interface RnvConfigFileObj { configsLocal: Array; configsPrivate: Array; } + +export type RenativeConfigFile = { + common: { + buildSchemes: Record; + }; + platforms: Record< + string, + { + buildSchemes: Record; + } + >; +}; + +export type RenativeConfigBuildScheme = Record; diff --git a/packages/rnv/src/core/engineManager/index.ts b/packages/rnv/src/core/engineManager/index.ts index ce130bccb0..e6183e7f62 100644 --- a/packages/rnv/src/core/engineManager/index.ts +++ b/packages/rnv/src/core/engineManager/index.ts @@ -421,7 +421,7 @@ const _getMergedEngineConfigs = (c) => { return mergedEngineConfigs; }; -const _getEngineConfigByPlatform = (c, platform) => { +const _getEngineConfigByPlatform = (c: RnvConfig, platform: string) => { const mergedEngineConfigs = _getMergedEngineConfigs(c); const engineId = c.program.engine || getConfigProp(c, platform, 'engine'); let selectedEngineConfig; @@ -459,7 +459,7 @@ const _resolvePkgPath = (c, packageName) => { return pkgPath; }; -const _registerPlatformEngine = (c, platform) => { +const _registerPlatformEngine = (c: RnvConfig, platform: string) => { // Only register active platform engine to be faster if (platform === true || !platform) return; const selectedEngineConfig = _getEngineConfigByPlatform(c, platform); diff --git a/packages/rnv/src/core/platformManager/index.ts b/packages/rnv/src/core/platformManager/index.ts index 7295f952eb..ee1d2e592a 100644 --- a/packages/rnv/src/core/platformManager/index.ts +++ b/packages/rnv/src/core/platformManager/index.ts @@ -59,7 +59,7 @@ export const cleanPlatformBuild = (c: RnvConfig, platform: string) => }); }); -export const createPlatformBuild = (c, platform) => +export const createPlatformBuild = (c: RnvConfig, platform: string) => new Promise((resolve, reject) => { logTask('createPlatformBuild'); @@ -197,7 +197,7 @@ export const copySharedPlatforms = (c) => resolve(); }); -export const ejectPlatform = (c, platform) => { +export const ejectPlatform = (c: RnvConfig, platform: string) => { const engine = c.runtime.enginesByPlatform[platform]; const destDir = path.join(c.paths.project.dir, 'platformTemplates', platform); const sourcePlatformDir = engine.originalTemplatePlatformsDir; diff --git a/packages/rnv/src/core/projectManager/index.ts b/packages/rnv/src/core/projectManager/index.ts index 1264cf102d..97f1ffd616 100644 --- a/packages/rnv/src/core/projectManager/index.ts +++ b/packages/rnv/src/core/projectManager/index.ts @@ -530,7 +530,7 @@ export const copyAssetsFolder = async (c, platform, subPath, customFn) => { // } // }; -export const copyBuildsFolder = (c, platform) => +export const copyBuildsFolder = (c: RnvConfig, platform: string) => new Promise((resolve) => { logTask('copyBuildsFolder'); if (!isPlatformActive(c, platform, resolve)) return; diff --git a/packages/rnv/src/core/projectManager/package.ts b/packages/rnv/src/core/projectManager/package.ts index 5bec8de583..4416a0b351 100644 --- a/packages/rnv/src/core/projectManager/package.ts +++ b/packages/rnv/src/core/projectManager/package.ts @@ -13,7 +13,7 @@ import { } from '../systemManager/fileutils'; import { logError } from '../systemManager/logger'; -const bumpVersions = (version) => { +const bumpVersions = (version: string) => { const { project: { dir }, rnv: { pluginTemplates }, @@ -34,7 +34,7 @@ const bumpVersions = (version) => { }); // check if it's our turf and do some extra magic const renativePkgPath = path.join(packagesDir, 'renative'); - if (fsExistsSync(renativePkgPath)) { + if (pluginTemplates.config && fsExistsSync(renativePkgPath)) { copyFileSync(path.join(dir, 'README.md'), path.join(renativePkgPath, 'README.md')); updateObjectSync(pluginTemplates.config, { pluginTemplates: { diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/android.ts b/packages/rnv/src/core/sdkManager/deviceUtils/android.ts index 0e219777ea..29c99f74b9 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/android.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/android.ts @@ -495,7 +495,7 @@ const _getDeviceProp = (arr, prop) => { return ''; }; -export const askForNewEmulator = async (c, platform) => { +export const askForNewEmulator = async (c: RnvConfig, platform: string) => { logTask('askForNewEmulator'); const emuName = c.files.workspace.config.defaultTargets[platform]; @@ -580,7 +580,7 @@ export const checkForActiveEmulator = (c) => reject('Could not find any active emulators'); // TODO: Asking for new emulator is worng as it diverts // user from underlying failure of not being able to connect - // return _askForNewEmulator(c, platform); + // return _askForNewEmulator(c , platform); } running = false; } diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts b/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts index 58f45a48ba..371cef00a2 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts @@ -3,8 +3,10 @@ import child_process from 'child_process'; import { chalk, logToSummary, logTask, logWarning, logDebug } from '../../systemManager/logger'; import { IOS, TVOS } from '../../constants'; import { executeAsync } from '../../systemManager/exec'; +import { AppleDevice } from '../types'; +import { RnvConfig } from '../../configManager/types'; -export const getAppleDevices = async (c, ignoreDevices, ignoreSimulators) => { +export const getAppleDevices = async (c: RnvConfig, ignoreDevices?: boolean, ignoreSimulators?: boolean) => { const { platform } = c; logTask('getAppleDevices', `ignoreDevices:${ignoreDevices} ignoreSimulators${ignoreSimulators}`); @@ -206,7 +208,7 @@ export const launchAppleSimulator = async (c, target) => { return Promise.reject('Action canceled!'); }; -const _launchSimulator = async (selectedDevice) => { +const _launchSimulator = async (selectedDevice: AppleDevice) => { try { child_process.spawnSync('xcrun', ['simctl', 'boot', selectedDevice.udid]); } catch (e) { @@ -217,7 +219,7 @@ const _launchSimulator = async (selectedDevice) => { return true; }; -export const listAppleDevices = async (c) => { +export const listAppleDevices = async (c: RnvConfig) => { logTask('listAppleDevices'); const { platform } = c; const devicesArr = await getAppleDevices(c); diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts index 5dbc3bb36d..5daab33132 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts @@ -2,6 +2,7 @@ import inquirer from 'inquirer'; import net from 'net'; import path from 'path'; import { getConfigProp, getPlatformProjectDir } from '../../common'; +import { RnvConfig } from '../../configManager/types'; import { CLI_SDB_TIZEN, CLI_TIZEN, CLI_TIZEN_EMULATOR, RENATIVE_CONFIG_NAME } from '../../constants'; import { execCLI } from '../../systemManager/exec'; import { fsRenameSync } from '../../systemManager/fileutils'; @@ -187,7 +188,7 @@ const _getRunningDevices = async (c) => { return devices; }; -const _waitForEmulatorToBeReady = (c, target) => +const _waitForEmulatorToBeReady = (c: RnvConfig, target) => waitForEmulator(c, CLI_SDB_TIZEN, 'devices', (res) => { const lines = res.trim().split(/\r?\n/); const devices = lines.filter((line) => line.includes(target) && line.includes('device')); diff --git a/packages/rnv/src/core/sdkManager/types.ts b/packages/rnv/src/core/sdkManager/types.ts new file mode 100644 index 0000000000..349b651b25 --- /dev/null +++ b/packages/rnv/src/core/sdkManager/types.ts @@ -0,0 +1,3 @@ +export type AppleDevice = { + udid: string; +}; diff --git a/packages/rnv/src/core/systemManager/exec.ts b/packages/rnv/src/core/systemManager/exec.ts index 75e9e1da82..234c69c184 100755 --- a/packages/rnv/src/core/systemManager/exec.ts +++ b/packages/rnv/src/core/systemManager/exec.ts @@ -11,7 +11,7 @@ import { chalk, logDebug, logRaw, logError } from './logger'; import { fsExistsSync } from './fileutils'; import { replaceOverridesInString } from './utils'; import { RnvConfig } from '../configManager/types'; -import { ExecCallback, ExecCallback2, ExecOptions } from './types'; +import { ExecCallback, ExecCallback2, ExecOptions, RnvCLI } from './types'; const { exec, execSync } = require('child_process'); diff --git a/packages/rnv/src/core/systemManager/fileutils.ts b/packages/rnv/src/core/systemManager/fileutils.ts index c9e0820a4b..62f6aabb25 100755 --- a/packages/rnv/src/core/systemManager/fileutils.ts +++ b/packages/rnv/src/core/systemManager/fileutils.ts @@ -7,7 +7,7 @@ import merge from 'deepmerge'; import ncp from 'ncp'; import { chalk, logDebug, logError, logWarning } from './logger'; import { RnvConfig } from '../configManager/types'; -import { OverridesOptions } from './types'; +import { OverridesOptions, TimestampPathsConfig } from './types'; export const configureFilesystem = (_getConfigProp: () => string, _doResolve: () => any, _isSystemWin: boolean) => { global.getConfigProp = _getConfigProp; @@ -55,7 +55,7 @@ export const fsReadFile = (arg1: fs.PathLike, arg2) => { export const fsReaddir = (arg1: fs.PathLike, arg2) => fs.readdir(arg1, arg2); -const _getSanitizedPath = (origPath: fs.PathLike, timestampPathsConfig) => { +const _getSanitizedPath = (origPath: fs.PathLike, timestampPathsConfig: TimestampPathsConfig) => { if (timestampPathsConfig?.paths?.length && timestampPathsConfig?.timestamp) { const pths = timestampPathsConfig.paths; if (pths.includes(origPath)) { @@ -69,7 +69,12 @@ const _getSanitizedPath = (origPath: fs.PathLike, timestampPathsConfig) => { return origPath; }; -export const copyFileSync = (source: string, target: string, skipOverride: boolean, timestampPathsConfig) => { +export const copyFileSync = ( + source: string, + target: string, + skipOverride?: boolean, + timestampPathsConfig?: TimestampPathsConfig +) => { logDebug('copyFileSync', source); let targetFile = target; // if target is a directory a new file with the same name will be created diff --git a/packages/rnv/src/core/systemManager/types.ts b/packages/rnv/src/core/systemManager/types.ts index c5cfcdff5e..6e56fd6766 100644 --- a/packages/rnv/src/core/systemManager/types.ts +++ b/packages/rnv/src/core/systemManager/types.ts @@ -29,3 +29,9 @@ export type OverridesOptions = Array<{ pattern: string; override: string; }>; + +export type TimestampPathsConfig = { + timestamp: Array; +}; + +export type RnvCLI = Record; diff --git a/packages/rnv/src/core/templateManager/index.ts b/packages/rnv/src/core/templateManager/index.ts index 6d32ad8c06..a270c92683 100644 --- a/packages/rnv/src/core/templateManager/index.ts +++ b/packages/rnv/src/core/templateManager/index.ts @@ -20,6 +20,7 @@ import { getConfigProp } from '../common'; import { listAppConfigsFoldersSync, generateBuildConfig, loadFileExtended } from '../configManager'; import { doResolve } from '../systemManager/resolve'; import { checkIfProjectAndNodeModulesExists } from '../systemManager/npmUtils'; +import { RnvConfig } from '../configManager/types'; export const checkIfTemplateConfigured = async (c) => { logTask('checkIfTemplateConfigured'); @@ -130,7 +131,7 @@ const _applyTemplate = async (c) => { }; const _configureSrc = (c) => - new Promise((resolve) => { + new Promise((resolve) => { // Check src logDebug('configureProject:check src'); if (!fsExistsSync(c.paths.project.srcDir)) { @@ -140,7 +141,7 @@ const _configureSrc = (c) => resolve(); }); -const _configureAppConfigs = async (c) => { +const _configureAppConfigs = async (c: RnvConfig) => { // Check appConfigs logDebug('configureProject:check appConfigs'); // @@ -192,7 +193,7 @@ const _configureAppConfigs = async (c) => { }; const _configureProjectConfig = (c) => - new Promise((resolve) => { + new Promise((resolve) => { // Check projectConfigs logDebug('configureProject:check projectConfigs'); if (!fsExistsSync(c.paths.project.appConfigBase.dir)) { @@ -243,7 +244,7 @@ export const configureTemplateFiles = async (c) => { const includedPaths = templateConfig?.templateConfig?.includedPaths; if (includedPaths) { - includedPaths.forEach((name) => { + includedPaths.forEach((name: string) => { const sourcePath = path.join(c.paths.template.dir, name); const destPath = path.join(c.paths.project.dir, name); if (!fsExistsSync(destPath) && fsExistsSync(sourcePath)) { @@ -263,7 +264,7 @@ export const configureTemplateFiles = async (c) => { } }; -export const configureEntryPoint = async (c, platform) => { +export const configureEntryPoint = async (c: RnvConfig, platform: string) => { logTask('configureEntryPoint'); if (c.files.project.config.isTemplate) return true; From 47dee6e474acdd224979710f3f5c4876e8fd1587 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Tue, 29 Aug 2023 22:57:55 +0200 Subject: [PATCH 12/83] add more types, 1324 togo --- packages/rnv/src/core/configManager/types.ts | 8 +++-- packages/rnv/src/core/engineManager/index.ts | 36 +++++++++++-------- packages/rnv/src/core/engineManager/types.ts | 12 +++++++ packages/rnv/src/core/runtimeManager/index.ts | 3 +- packages/rnv/src/core/setupManager/base.ts | 9 ++++- packages/rnv/src/core/setupManager/config.ts | 6 ++-- packages/rnv/src/core/systemManager/utils.ts | 11 +++--- packages/rnv/src/core/taskManager/types.ts | 7 ++++ packages/rnv/src/core/types.ts | 10 ++++++ 9 files changed, 77 insertions(+), 25 deletions(-) create mode 100644 packages/rnv/src/core/engineManager/types.ts create mode 100644 packages/rnv/src/core/taskManager/types.ts create mode 100644 packages/rnv/src/core/types.ts diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index ea46baf1e8..c373c387fc 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -22,7 +22,11 @@ export interface RnvConfig { runtime: { appId: string; enginesByPlatform: any; - enginesByIndex: Array; + enginesByIndex: Array<{ + config: { + id: string; + }; + }>; enginesById: Record; missingEnginePlugins: Record; localhost: string; @@ -96,7 +100,7 @@ export interface RnvConfig { configsLocal: Array; }; //ADDON - config?: string; + config: string; configLocal?: string; configPrivate?: string; dir: string; diff --git a/packages/rnv/src/core/engineManager/index.ts b/packages/rnv/src/core/engineManager/index.ts index e6183e7f62..af4ee47a33 100644 --- a/packages/rnv/src/core/engineManager/index.ts +++ b/packages/rnv/src/core/engineManager/index.ts @@ -9,6 +9,10 @@ import { getScopedVersion } from '../systemManager/utils'; import { writeRenativeConfigFile } from '../configManager'; import { configurePlugins } from '../pluginManager'; import { inquirerPrompt } from '../../cli/prompt'; +import { RnvConfig } from '../configManager/types'; +import { RnvTask, RnvTaskMap } from '../taskManager/types'; +import { RnvModuleConfig, RnvNextJSConfig, RnvPlatform } from '../types'; +import { RnvEngineConfigMap, RnvEngineInstallConfig } from './types'; const ENGINE_CORE = 'engine-core'; @@ -315,14 +319,14 @@ const _getFilteredEngines = (c) => { return filteredEngines; }; -export const loadEngines = async (c, failOnMissingDeps) => { +export const loadEngines = async (c: RnvConfig, failOnMissingDeps: boolean): Promise => { logTask('loadEngines'); if (!fsExistsSync(c.paths.project.config)) return true; const filteredEngines = _getFilteredEngines(c); - const enginesToInstall = []; - const readyEngines = []; - const engineConfigs = []; + const enginesToInstall: Array = []; + const readyEngines: Array = []; + const engineConfigs: Array = []; // if (filteredEngines) { Object.keys(filteredEngines).forEach((k) => { const engineRootPath = doResolve(k); @@ -394,10 +398,10 @@ ${enginesToInstall.map((v) => `> ${v.key}@${v.version}`).join('\n')} return true; }; -const _getMergedEngineConfigs = (c) => { +const _getMergedEngineConfigs = (c: RnvConfig) => { const engines = c.buildConfig?.engines; const engineTemplates = c.buildConfig?.engineTemplates; - const mergedEngineConfigs = {}; + const mergedEngineConfigs: RnvEngineConfigMap = {}; Object.keys(engineTemplates).forEach((packageName) => { mergedEngineConfigs[packageName] = { packageName, @@ -434,7 +438,7 @@ const _getEngineConfigByPlatform = (c: RnvConfig, platform: string) => { return selectedEngineConfig; }; -const _resolvePkgPath = (c, packageName) => { +const _resolvePkgPath = (c: RnvConfig, packageName: string) => { if (IS_LINKED && !c.program.unlinked) { // In the instances of running linked rnv instead of installed one load local packages try { @@ -459,7 +463,7 @@ const _resolvePkgPath = (c, packageName) => { return pkgPath; }; -const _registerPlatformEngine = (c: RnvConfig, platform: string) => { +const _registerPlatformEngine = (c: RnvConfig, platform: RnvPlatform) => { // Only register active platform engine to be faster if (platform === true || !platform) return; const selectedEngineConfig = _getEngineConfigByPlatform(c, platform); @@ -481,7 +485,7 @@ Maybe you forgot to define platforms.${platform}.engine in your renative.json?`) } }; -export const generateEnvVars = (c, moduleConfig, nextConfig) => { +export const generateEnvVars = (c: RnvConfig, moduleConfig: RnvModuleConfig, nextConfig: RnvNextJSConfig) => { const isMonorepo = getConfigProp(c, c.platform, 'isMonorepo'); const monoRoot = getConfigProp(c, c.platform, 'monoRoot'); return { @@ -514,7 +518,7 @@ export const getPlatformExtensions = (c, excludeServer = false, addDotPrefix = f return output; }; -export const getEngineRunnerByPlatform = (c, platform, ignoreMissingError) => { +export const getEngineRunnerByPlatform = (c: RnvConfig, platform: string, ignoreMissingError?: boolean) => { const selectedEngine = c.runtime.enginesByPlatform[platform]; if (!selectedEngine && !ignoreMissingError) { logDebug(`ERROR: Engine for platform: ${platform} does not exists or is not registered ${new Error()}`); @@ -523,7 +527,11 @@ export const getEngineRunnerByPlatform = (c, platform, ignoreMissingError) => { return selectedEngine; }; -export const getEngineTask = (task, tasks, customTasks) => { +export const getEngineTask = ( + task: string, + tasks: Record, + customTasks?: Record +): RnvTask => { const customTask = customTasks?.[task]; if (customTask) return customTask; let tsk; @@ -535,13 +543,13 @@ export const getEngineTask = (task, tasks, customTasks) => { return tsk; }; -export const hasEngineTask = (task, tasks, isProjectScope) => +export const hasEngineTask = (task: string, tasks: RnvTaskMap, isProjectScope: boolean) => isProjectScope ? !!getEngineTask(task, tasks) : getEngineTask(task, tasks)?.isGlobalScope; -export const getEngineSubTasks = (task, tasks, exactMatch) => +export const getEngineSubTasks = (task: string, tasks: RnvTaskMap, exactMatch: boolean) => Object.values(tasks).filter((v) => (exactMatch ? v.task.split(' ')[0] === task : v.task.startsWith(task))); -export const getEngineRunner = (c, task, customTasks, failOnMissingEngine = true) => { +export const getEngineRunner = (c: RnvConfig, task: string, customTasks: RnvTaskMap, failOnMissingEngine = true) => { if (customTasks?.[task]) { return c.runtime.enginesById[ENGINE_CORE]; } diff --git a/packages/rnv/src/core/engineManager/types.ts b/packages/rnv/src/core/engineManager/types.ts new file mode 100644 index 0000000000..6ab562a769 --- /dev/null +++ b/packages/rnv/src/core/engineManager/types.ts @@ -0,0 +1,12 @@ +export type RnvEngineConfig = { + id: string; +}; + +export type RnvEngineConfigMap = Record; + +export type RnvEngineInstallConfig = { + key: string; + version?: string; + engineRootPath: string; + configPath?: string; +}; diff --git a/packages/rnv/src/core/runtimeManager/index.ts b/packages/rnv/src/core/runtimeManager/index.ts index c6a005e230..64667676c8 100644 --- a/packages/rnv/src/core/runtimeManager/index.ts +++ b/packages/rnv/src/core/runtimeManager/index.ts @@ -6,6 +6,7 @@ import { getConfigProp } from '../common'; import { logTask } from '../systemManager/logger'; import { loadPluginTemplates } from '../pluginManager'; import { parseRenativeConfigs } from '../configManager/index'; +import { RnvConfig } from '../configManager/types'; export const updateRenativeConfigs = async (c) => { await loadPluginTemplates(c); @@ -13,7 +14,7 @@ export const updateRenativeConfigs = async (c) => { return true; }; -export const configureRuntimeDefaults = async (c) => { +export const configureRuntimeDefaults = async (c: RnvConfig) => { c.runtime.appId = c.files.project?.configLocal?._meta?.currentAppConfigId || null; // c.runtime.appConfigDir = c.files.project?.configLocal?._meta?.currentAppConfigDir || null; diff --git a/packages/rnv/src/core/setupManager/base.ts b/packages/rnv/src/core/setupManager/base.ts index af76b1d985..d92dd6f57d 100644 --- a/packages/rnv/src/core/setupManager/base.ts +++ b/packages/rnv/src/core/setupManager/base.ts @@ -9,9 +9,16 @@ import { replaceHomeFolder, updateConfigFile } from '../systemManager/fileutils' import setupConfig from './config'; import Config from '../configManager/config'; import { logTask, logError, logInfo, logDebug, logSuccess } from '../systemManager/logger'; +import { RnvConfig } from '../configManager/types'; class BasePlatformSetup { - constructor(os, c) { + os: string; + c: RnvConfig; + globalConfigPath: string; + availableDownloader: string | null; + androidSdkLocation: string; + + constructor(os: string, c: RnvConfig) { // eslint-disable-next-line no-param-reassign if (!c) c = Config.getConfig(); const { paths } = c; diff --git a/packages/rnv/src/core/setupManager/config.ts b/packages/rnv/src/core/setupManager/config.ts index 0d906afc07..523ed55156 100644 --- a/packages/rnv/src/core/setupManager/config.ts +++ b/packages/rnv/src/core/setupManager/config.ts @@ -15,9 +15,9 @@ if (process.platform === 'darwin') { tizenExtension = 'dmg'; } -export const replaceHomeFolder = (p) => { - if (isSystemWin) return p.replace('~', process.env.USERPROFILE); - return p.replace('~', process.env.HOME); +export const replaceHomeFolder = (p: string) => { + if (isSystemWin) return p.replace('~', process.env.USERPROFILE || ''); + return p.replace('~', process.env.HOME || ''); }; export default { diff --git a/packages/rnv/src/core/systemManager/utils.ts b/packages/rnv/src/core/systemManager/utils.ts index 91e2c2bf63..294ed048f2 100644 --- a/packages/rnv/src/core/systemManager/utils.ts +++ b/packages/rnv/src/core/systemManager/utils.ts @@ -1,10 +1,13 @@ +import { RnvConfig } from '../configManager/types'; +import { RenativeConfigVersion } from '../types'; + export const isSystemMac = process.platform === 'darwin'; export const isSystemLinux = process.platform === 'linux'; export const isSystemWin = process.platform === 'win32'; -export const replaceOverridesInString = (string, overrides, mask) => { +export const replaceOverridesInString = (string: string, overrides: Array, mask: string) => { let replacedString = string; if (overrides?.length && replacedString?.replace) { overrides.forEach((v) => { @@ -15,7 +18,7 @@ export const replaceOverridesInString = (string, overrides, mask) => { return replacedString; }; -export const getValidLocalhost = (value, localhost) => { +export const getValidLocalhost = (value: string, localhost: string) => { if (!value) return localhost; switch (value) { case 'localhost': @@ -27,7 +30,7 @@ export const getValidLocalhost = (value, localhost) => { } }; -export const isUrlLocalhost = (value) => { +export const isUrlLocalhost = (value: string) => { if (value?.includes) { if (value.includes('localhost')) return true; if (value.includes('0.0.0.0')) return true; @@ -36,7 +39,7 @@ export const isUrlLocalhost = (value) => { return false; }; -export const getScopedVersion = (c, key, val, sourceObjKey) => { +export const getScopedVersion = (c: RnvConfig, key: string, val: RenativeConfigVersion, sourceObjKey: string) => { if (typeof val === 'string') { if (val.startsWith('source:')) { const sourceObj = c.buildConfig?.[sourceObjKey]; diff --git a/packages/rnv/src/core/taskManager/types.ts b/packages/rnv/src/core/taskManager/types.ts new file mode 100644 index 0000000000..fe316f2c9e --- /dev/null +++ b/packages/rnv/src/core/taskManager/types.ts @@ -0,0 +1,7 @@ +export type RnvTask = { + task: string; + params: Array; + isGlobalScope: boolean; +}; + +export type RnvTaskMap = Record; diff --git a/packages/rnv/src/core/types.ts b/packages/rnv/src/core/types.ts new file mode 100644 index 0000000000..8d2a00ca9e --- /dev/null +++ b/packages/rnv/src/core/types.ts @@ -0,0 +1,10 @@ +export type RnvPlatform = string | boolean; + +export type RnvModuleConfig = { + modulePaths: Array; + moduleAliasesArray: Array; +}; + +export type RnvNextJSConfig = {}; + +export type RenativeConfigVersion = string | { version: string }; From 6c03ab3081003e49dff6849f2402daef9cf7ac7a Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Tue, 29 Aug 2023 23:15:08 +0200 Subject: [PATCH 13/83] more type refactors, 1227 togo --- packages/rnv/src/cli/types.ts | 1 + packages/rnv/src/core/common.ts | 2 +- packages/rnv/src/core/configManager/index.ts | 2 +- .../src/core/configManager/packageParser.ts | 2 +- .../src/core/configManager/schemeParser.ts | 2 +- packages/rnv/src/core/configManager/types.ts | 6 +++- packages/rnv/src/core/constants.ts | 8 ++--- packages/rnv/src/core/engineManager/index.ts | 22 +++++++------- packages/rnv/src/core/pluginManager/index.ts | 30 +++++++++---------- .../rnv/src/core/projectManager/buildHooks.ts | 2 +- packages/rnv/src/core/projectManager/index.ts | 24 +++++++-------- .../rnv/src/core/projectManager/workspace.ts | 2 +- packages/rnv/src/core/runtimeManager/index.ts | 2 +- .../core/sdkManager/deviceUtils/android.ts | 8 ++--- .../src/core/sdkManager/deviceUtils/tizen.ts | 12 ++++---- .../src/core/sdkManager/deviceUtils/webos.ts | 8 ++--- packages/rnv/src/core/sdkManager/installer.ts | 10 +++---- packages/rnv/src/core/setupManager/index.ts | 3 +- packages/rnv/src/core/setupManager/linux.ts | 4 +-- packages/rnv/src/core/systemManager/logger.ts | 2 +- .../rnv/src/core/systemManager/npmUtils.ts | 6 ++-- packages/rnv/src/core/systemManager/types.ts | 1 + packages/rnv/src/core/taskManager/index.ts | 20 +++++++++---- packages/rnv/src/core/taskManager/types.ts | 10 ++++++- .../rnv/src/core/templateManager/index.ts | 12 ++++---- .../tasks/task.rnv.app.configure.ts | 15 ++++++---- .../engine-core/tasks/task.rnv.app.create.ts | 2 +- .../tasks/task.rnv.crypto.encrypt.ts | 2 +- .../engine-core/tasks/task.rnv.fastlane.ts | 2 +- .../src/engine-core/tasks/task.rnv.link.ts | 4 +-- .../rnv/src/engine-core/tasks/task.rnv.new.ts | 6 ++-- .../tasks/task.rnv.template.add.ts | 4 +-- .../src/engine-core/tasks/task.rnv.unlink.ts | 4 +-- .../tasks/task.rnv.workspace.configure.ts | 2 +- 34 files changed, 134 insertions(+), 108 deletions(-) diff --git a/packages/rnv/src/cli/types.ts b/packages/rnv/src/cli/types.ts index a175366999..e97dcb5959 100644 --- a/packages/rnv/src/cli/types.ts +++ b/packages/rnv/src/cli/types.ts @@ -15,4 +15,5 @@ export type PromptParams = { default?: any; name: string; type: string; + pageSize?: number; }; diff --git a/packages/rnv/src/core/common.ts b/packages/rnv/src/core/common.ts index ff5d5a746f..57edd082f0 100755 --- a/packages/rnv/src/core/common.ts +++ b/packages/rnv/src/core/common.ts @@ -151,7 +151,7 @@ export const existBuildsOverrideForTargetPathSync = (c: RnvConfig, destPath: str return result; }; -export const confirmActiveBundler = async (c) => { +export const confirmActiveBundler = async (c: RnvConfig) => { if (c.runtime.skipActiveServerCheck) return true; if (c.program.ci) { diff --git a/packages/rnv/src/core/configManager/index.ts b/packages/rnv/src/core/configManager/index.ts index b120b42c18..61778e1442 100644 --- a/packages/rnv/src/core/configManager/index.ts +++ b/packages/rnv/src/core/configManager/index.ts @@ -369,7 +369,7 @@ const _loadConfigFiles = ( return result; }; -export const generateRuntimeConfig = async (c) => { +export const generateRuntimeConfig = async (c: RnvConfig) => { logTask('generateRuntimeConfig'); // c.assetConfig = { // common: c.buildConfig.common, diff --git a/packages/rnv/src/core/configManager/packageParser.ts b/packages/rnv/src/core/configManager/packageParser.ts index c963ecdb8a..d60dc04d5c 100644 --- a/packages/rnv/src/core/configManager/packageParser.ts +++ b/packages/rnv/src/core/configManager/packageParser.ts @@ -107,7 +107,7 @@ export const checkRequiredPackage = async ( return false; }; -export const injectPlatformDependencies = async (c) => { +export const injectPlatformDependencies = async (c: RnvConfig) => { logTask('injectPlatformDependencies'); const { platform } = c; const engine = getEngineRunnerByPlatform(c, platform); diff --git a/packages/rnv/src/core/configManager/schemeParser.ts b/packages/rnv/src/core/configManager/schemeParser.ts index 464b419786..f4b7e8c65e 100644 --- a/packages/rnv/src/core/configManager/schemeParser.ts +++ b/packages/rnv/src/core/configManager/schemeParser.ts @@ -2,7 +2,7 @@ import merge from 'deepmerge'; import { logError, logTask, logWarning, chalk, logInfo } from '../systemManager/logger'; import { inquirerPrompt } from '../../cli/prompt'; -export const isBuildSchemeSupported = async (c) => { +export const isBuildSchemeSupported = async (c: RnvConfig) => { logTask('isBuildSchemeSupported'); const { scheme } = c.program; diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index c373c387fc..32c5eb3381 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -20,7 +20,8 @@ export interface RnvConfig { }; configPropsInjects: any; runtime: { - appId: string; + appId: string | null; + appDir: string; enginesByPlatform: any; enginesByIndex: Array<{ config: { @@ -45,6 +46,8 @@ export interface RnvConfig { availablePlatforms: Array; _platformBuildsSuffix?: string; timestamp: number; + appConfigDir: string; + hasAllEnginesRegistered: boolean; }; paths: { GLOBAL_RNV_CONFIG: string; @@ -231,6 +234,7 @@ export interface RnvConfig { platformTemplates: Record; //ADDON config: any; + config_original: any; configLocal: any; configPrivate: any; package: any; diff --git a/packages/rnv/src/core/constants.ts b/packages/rnv/src/core/constants.ts index b0142b62fc..6746a0a6e5 100644 --- a/packages/rnv/src/core/constants.ts +++ b/packages/rnv/src/core/constants.ts @@ -513,9 +513,9 @@ Object.keys(PARAM_KEYS).forEach((k) => { }); export const PARAMS = { - withBase: (arr: any) => + withBase: (arr?: any) => [PARAM_KEYS.info, PARAM_KEYS.ci, PARAM_KEYS.mono, PARAM_KEYS.maxErrorLength, PARAM_KEYS.only].concat(arr || []), - withConfigure: (arr: any) => + withConfigure: (arr?: any) => [ PARAM_KEYS.reset, PARAM_KEYS.resetHard, @@ -525,7 +525,7 @@ export const PARAMS = { PARAM_KEYS.scheme, PARAM_KEYS.platform, ].concat(arr || []), - withRun: (arr: any) => + withRun: (arr?: any) => [ PARAM_KEYS.target, PARAM_KEYS.device, @@ -536,7 +536,7 @@ export const PARAMS = { PARAM_KEYS.skipTargetCheck, PARAM_KEYS.host, ].concat(arr || []), - withAll: (arr: any) => Object.values(PARAM_KEYS).concat(arr || []), + withAll: (arr?: any) => Object.values(PARAM_KEYS).concat(arr || []), all: Object.keys(PARAM_KEYS), }; diff --git a/packages/rnv/src/core/engineManager/index.ts b/packages/rnv/src/core/engineManager/index.ts index af4ee47a33..fecbd76059 100644 --- a/packages/rnv/src/core/engineManager/index.ts +++ b/packages/rnv/src/core/engineManager/index.ts @@ -12,7 +12,7 @@ import { inquirerPrompt } from '../../cli/prompt'; import { RnvConfig } from '../configManager/types'; import { RnvTask, RnvTaskMap } from '../taskManager/types'; import { RnvModuleConfig, RnvNextJSConfig, RnvPlatform } from '../types'; -import { RnvEngineConfigMap, RnvEngineInstallConfig } from './types'; +import { RnvEngineConfig, RnvEngineConfigMap, RnvEngineInstallConfig } from './types'; const ENGINE_CORE = 'engine-core'; @@ -33,7 +33,7 @@ export const registerEngine = async (c, engine, platform, engConfig) => { _registerEnginePlatform(c, platform, engine); }; -const _registerEnginePlatform = (c, platform, engine) => { +const _registerEnginePlatform = (c: RnvConfig, platform, engine) => { if (platform) { c.runtime.enginesByPlatform[platform] = engine; } @@ -80,7 +80,7 @@ export const generateEngineTasks = (taskArr) => { return tasks; }; -export const configureEngines = async (c) => { +export const configureEngines = async (c: RnvConfig) => { logTask('configureEngines'); // const { engines } = c.files.project.config; const engines = _getFilteredEngines(c); @@ -134,13 +134,13 @@ export const registerMissingPlatformEngines = async (c, taskInstance) => { return true; }; -export const registerAllPlatformEngines = async (c) => { +export const registerAllPlatformEngines = async (c: RnvConfig) => { logTask('registerAllPlatformEngines'); if (!c.buildConfig?.defaults?.supportedPlatforms?.forEach) { c.runtime.hasAllEnginesRegistered = true; return true; } - const registerEngineList = []; + const registerEngineList: Array> = []; c.buildConfig.defaults.supportedPlatforms.forEach((platform) => { registerEngineList.push(_registerPlatformEngine(c, platform)); }); @@ -152,7 +152,7 @@ export const registerAllPlatformEngines = async (c) => { return true; }; -export const loadEnginePluginDeps = async (c, engineConfigs) => { +export const loadEnginePluginDeps = async (c: RnvConfig, engineConfigs) => { logTask('loadEnginePluginDeps'); if (c.files.project.config.isTemplate) return 0; @@ -425,10 +425,10 @@ const _getMergedEngineConfigs = (c: RnvConfig) => { return mergedEngineConfigs; }; -const _getEngineConfigByPlatform = (c: RnvConfig, platform: string) => { +const _getEngineConfigByPlatform = (c: RnvConfig, platform: string): RnvEngineConfig | null => { const mergedEngineConfigs = _getMergedEngineConfigs(c); const engineId = c.program.engine || getConfigProp(c, platform, 'engine'); - let selectedEngineConfig; + let selectedEngineConfig: RnvEngineConfig | null = null; Object.values(mergedEngineConfigs).forEach((engineConfig) => { if (engineConfig.id === engineId) { selectedEngineConfig = engineConfig; @@ -463,7 +463,7 @@ const _resolvePkgPath = (c: RnvConfig, packageName: string) => { return pkgPath; }; -const _registerPlatformEngine = (c: RnvConfig, platform: RnvPlatform) => { +const _registerPlatformEngine = async (c: RnvConfig, platform: RnvPlatform): Promise => { // Only register active platform engine to be faster if (platform === true || !platform) return; const selectedEngineConfig = _getEngineConfigByPlatform(c, platform); @@ -503,7 +503,7 @@ export const generateEnvVars = (c: RnvConfig, moduleConfig: RnvModuleConfig, nex }; }; -export const getPlatformExtensions = (c, excludeServer = false, addDotPrefix = false) => { +export const getPlatformExtensions = (c: RnvConfig, excludeServer = false, addDotPrefix = false) => { const { engine } = c.runtime; let output; const { platforms } = engine; @@ -549,7 +549,7 @@ export const hasEngineTask = (task: string, tasks: RnvTaskMap, isProjectScope: b export const getEngineSubTasks = (task: string, tasks: RnvTaskMap, exactMatch: boolean) => Object.values(tasks).filter((v) => (exactMatch ? v.task.split(' ')[0] === task : v.task.startsWith(task))); -export const getEngineRunner = (c: RnvConfig, task: string, customTasks: RnvTaskMap, failOnMissingEngine = true) => { +export const getEngineRunner = (c: RnvConfig, task: string, customTasks?: RnvTaskMap, failOnMissingEngine = true) => { if (customTasks?.[task]) { return c.runtime.enginesById[ENGINE_CORE]; } diff --git a/packages/rnv/src/core/pluginManager/index.ts b/packages/rnv/src/core/pluginManager/index.ts index 556deb394d..cd7700bcc2 100644 --- a/packages/rnv/src/core/pluginManager/index.ts +++ b/packages/rnv/src/core/pluginManager/index.ts @@ -20,7 +20,7 @@ import { chalk, logDebug, logError, logInfo, logSuccess, logTask, logWarning } f import { installPackageDependencies } from '../systemManager/npmUtils'; import { doResolve, doResolvePath } from '../systemManager/resolve'; -export const getPluginList = (c, isUpdate = false) => { +export const getPluginList = (c: RnvConfig, isUpdate = false) => { const output = { asString: '', asArray: [], @@ -108,7 +108,7 @@ const _getPluginScope = (plugin) => { return { scope: 'rnv' }; }; -export const getMergedPlugin = (c, key) => { +export const getMergedPlugin = (c: RnvConfig, key) => { logDebug(`getMergedPlugin:${key}`); const plugin = c.buildConfig.plugins?.[key]; @@ -126,7 +126,7 @@ export const getMergedPlugin = (c, key) => { return mergedPlugin; }; -const _getMergedPlugin = (c, plugin, pluginKey, parentScope, scopes, skipSanitize) => { +const _getMergedPlugin = (c: RnvConfig, plugin, pluginKey, parentScope, scopes, skipSanitize) => { if (!plugin) { return {}; } @@ -205,7 +205,7 @@ const _getMergedPlugin = (c, plugin, pluginKey, parentScope, scopes, skipSanitiz return mergedPlugin; }; -export const configurePlugins = async (c) => { +export const configurePlugins = async (c: RnvConfig) => { logTask('configurePlugins'); if (c.program.skipDependencyCheck) return true; @@ -324,14 +324,14 @@ ${ovMsg}` return true; }; -const _updatePackage = (c, override) => { +const _updatePackage = (c: RnvConfig, override) => { const newPackage = merge(c.files.project.package, override); writeRenativeConfigFile(c, c.paths.project.package, newPackage); c.files.project.package = newPackage; c._requiresNpmInstall = true; }; -export const resolvePluginDependants = async (c) => { +export const resolvePluginDependants = async (c: RnvConfig) => { logTask('resolvePluginDependants'); const { plugins } = c.buildConfig; @@ -396,7 +396,7 @@ const _resolvePluginDependencies = async (c, key, keyScope, parentKey) => { return true; }; -export const parsePlugins = (c, platform, pluginCallback, ignorePlatformObjectCheck) => { +export const parsePlugins = (c: RnvConfig, platform, pluginCallback, ignorePlatformObjectCheck) => { logTask('parsePlugins'); if (c.buildConfig) { const includedPlugins = getConfigProp(c, platform, 'includedPlugins', []); @@ -456,7 +456,7 @@ export const parsePlugins = (c, platform, pluginCallback, ignorePlatformObjectCh } }; -export const loadPluginTemplates = async (c) => { +export const loadPluginTemplates = async (c: RnvConfig) => { logTask('loadPluginTemplates'); //This comes from project dependency @@ -515,7 +515,7 @@ export const loadPluginTemplates = async (c) => { return true; }; -const _parsePluginTemplateDependencies = (c, customPluginTemplates, scope = 'root') => { +const _parsePluginTemplateDependencies = (c: RnvConfig, customPluginTemplates, scope = 'root') => { logTask('_parsePluginTemplateDependencies', `scope:${scope}`); const missingDeps = []; if (customPluginTemplates) { @@ -574,7 +574,7 @@ const _parsePluginTemplateDependencies = (c, customPluginTemplates, scope = 'roo // Alternative Regex seem more accurate const getCleanRegExString = (str) => str.replace(/[-\\.,_*+?^$[\](){}!=|`]/gi, '\\$&'); -const _overridePlugin = (c, pluginsPath, dir) => { +const _overridePlugin = (c: RnvConfig, pluginsPath, dir) => { const source = path.resolve(pluginsPath, dir, 'overrides'); const dest = doResolve(dir, false); if (!dest) return; @@ -706,7 +706,7 @@ export const overrideFileContents = (dest, override, overridePath = '') => { } }; -export const installPackageDependenciesAndPlugins = async (c) => { +export const installPackageDependenciesAndPlugins = async (c: RnvConfig) => { logTask('installPackageDependenciesAndPlugins'); await installPackageDependencies(c); @@ -715,7 +715,7 @@ export const installPackageDependenciesAndPlugins = async (c) => { await checkForPluginDependencies(c); }; -const _getPluginConfiguration = (c, pluginName) => { +const _getPluginConfiguration = (c: RnvConfig, pluginName) => { let renativePluginPath; try { renativePluginPath = require.resolve(`${pluginName}/renative.plugin.json`, { paths: [c.paths.project.dir] }); @@ -729,7 +729,7 @@ const _getPluginConfiguration = (c, pluginName) => { return null; }; -export const checkForPluginDependencies = async (c) => { +export const checkForPluginDependencies = async (c: RnvConfig) => { const toAdd = {}; Object.keys(c.buildConfig.plugins).forEach((pluginName) => { const renativePluginConfig = _getPluginConfiguration(c, pluginName); @@ -781,7 +781,7 @@ export const checkForPluginDependencies = async (c) => { } }; -export const overrideTemplatePlugins = async (c) => { +export const overrideTemplatePlugins = async (c: RnvConfig) => { logTask('overrideTemplatePlugins'); const rnvPluginsDirs = c.paths.rnv.pluginTemplates.dirs; @@ -918,7 +918,7 @@ export const getLocalRenativePlugin = () => ({ }, }); -export const getModuleConfigs = (c, primaryKey) => { +export const getModuleConfigs = (c: RnvConfig, primaryKey) => { let modulePaths = []; const moduleAliases = {}; diff --git a/packages/rnv/src/core/projectManager/buildHooks.ts b/packages/rnv/src/core/projectManager/buildHooks.ts index b68324037b..112d99afd1 100644 --- a/packages/rnv/src/core/projectManager/buildHooks.ts +++ b/packages/rnv/src/core/projectManager/buildHooks.ts @@ -24,7 +24,7 @@ export const executePipe = async (c, key) => { } }; -export const buildHooks = async (c) => { +export const buildHooks = async (c: RnvConfig) => { logDebug('buildHooks'); const enableHookRebuild = getConfigProp(c, c.platform, 'enableHookRebuild'); diff --git a/packages/rnv/src/core/projectManager/index.ts b/packages/rnv/src/core/projectManager/index.ts index 97f1ffd616..fbc3208f36 100644 --- a/packages/rnv/src/core/projectManager/index.ts +++ b/packages/rnv/src/core/projectManager/index.ts @@ -33,7 +33,7 @@ import { chalk, logTask, logWarning, logDebug, logInfo, getCurrentCommand } from import { configureTemplateFiles, configureEntryPoint } from '../templateManager'; import { parseRenativeConfigs } from '../configManager'; -export const checkAndBootstrapIfRequired = async (c) => { +export const checkAndBootstrapIfRequired = async (c: RnvConfig) => { logTask('checkAndBootstrapIfRequired'); const { template } = c.program; if (!c.paths.project.configExists && template) { @@ -177,7 +177,7 @@ export const checkAndBootstrapIfRequired = async (c) => { return true; }; -export const checkAndCreateGitignore = async (c) => { +export const checkAndCreateGitignore = async (c: RnvConfig) => { logTask('checkAndCreateGitignore'); const ignrPath = path.join(c.paths.project.dir, '.gitignore'); if (!fsExistsSync(ignrPath)) { @@ -188,7 +188,7 @@ export const checkAndCreateGitignore = async (c) => { return true; }; -export const checkAndCreateBabelConfig = async (c) => { +export const checkAndCreateBabelConfig = async (c: RnvConfig) => { logTask('checkAndCreateBabelConfig'); if (!c.paths.project.configExists) return false; @@ -203,7 +203,7 @@ export const checkAndCreateBabelConfig = async (c) => { return true; }; -export const configureFonts = async (c) => { +export const configureFonts = async (c: RnvConfig) => { // FONTS let fontsObj = 'export default ['; @@ -274,7 +274,7 @@ export const configureFonts = async (c) => { return true; }; -export const copyRuntimeAssets = async (c) => { +export const copyRuntimeAssets = async (c: RnvConfig) => { logTask('copyRuntimeAssets'); const destPath = path.join(c.paths.project.assets.dir, 'runtime'); @@ -306,7 +306,7 @@ export const copyRuntimeAssets = async (c) => { return true; }; -export const parseFonts = (c, callback) => { +export const parseFonts = (c: RnvConfig, callback) => { logTask('parseFonts'); if (c.buildConfig) { @@ -347,7 +347,7 @@ export const parseFonts = (c, callback) => { } }; -const _parseFontSources = (c, fontSourcesArr, callback) => { +const _parseFontSources = (c: RnvConfig, fontSourcesArr, callback) => { const fontSources = fontSourcesArr.map((v) => _resolvePackage(c, v)); fontSources.forEach((fontSourceDir) => { if (fsExistsSync(fontSourceDir)) { @@ -358,14 +358,14 @@ const _parseFontSources = (c, fontSourcesArr, callback) => { }); }; -const _resolvePackage = (c, v) => { +const _resolvePackage = (c: RnvConfig, v) => { if (v?.startsWith?.('./')) { return path.join(c.paths.project.dir, v); } return resolvePackage(v); }; -// const _requiresAssetOverride = async (c) => { +// const _requiresAssetOverride = async (c: RnvConfig) => { // const requiredAssets = c.runtime.engine?.platforms?.[c.platform]?.requiredAssets || []; // const assetsToCopy = []; @@ -617,7 +617,7 @@ const SYNCED_DEPS = [ const SYNCED_TEMPLATES = ['@rnv/template-starter']; -export const versionCheck = async (c) => { +export const versionCheck = async (c: RnvConfig) => { logTask('versionCheck'); if (c.runtime.versionCheckCompleted || c.files.project?.config?.skipAutoUpdate || c.program.skipDependencyCheck) { @@ -661,7 +661,7 @@ It is recommended that you run your rnv command with npx prefix: ${recCmd} . or return true; }; -export const upgradeProjectDependencies = (c, version) => { +export const upgradeProjectDependencies = (c: RnvConfig, version) => { logTask('upgradeProjectDependencies'); // const templates = c.files.project.config?.templates; @@ -713,7 +713,7 @@ const _fixDeps = (deps, version) => { }); }; -export const cleanPlaformAssets = async (c) => { +export const cleanPlaformAssets = async (c: RnvConfig) => { logTask('cleanPlaformAssets'); await cleanFolder(c.paths.project.assets.dir); diff --git a/packages/rnv/src/core/projectManager/workspace.ts b/packages/rnv/src/core/projectManager/workspace.ts index d5500f0f42..b4addbb38d 100644 --- a/packages/rnv/src/core/projectManager/workspace.ts +++ b/packages/rnv/src/core/projectManager/workspace.ts @@ -20,7 +20,7 @@ export const createWorkspace = async (c, workspaceID, workspacePath) => { return true; }; -export const getWorkspaceDirPath = async (c) => { +export const getWorkspaceDirPath = async (c: RnvConfig) => { logTask('getWorkspaceDirPath'); const wss = c.files.rnv.configWorkspaces; const ws = c.runtime.selectedWorkspace || c.buildConfig?.workspaceID; diff --git a/packages/rnv/src/core/runtimeManager/index.ts b/packages/rnv/src/core/runtimeManager/index.ts index 64667676c8..8cfdd1c2cf 100644 --- a/packages/rnv/src/core/runtimeManager/index.ts +++ b/packages/rnv/src/core/runtimeManager/index.ts @@ -8,7 +8,7 @@ import { loadPluginTemplates } from '../pluginManager'; import { parseRenativeConfigs } from '../configManager/index'; import { RnvConfig } from '../configManager/types'; -export const updateRenativeConfigs = async (c) => { +export const updateRenativeConfigs = async (c: RnvConfig) => { await loadPluginTemplates(c); await parseRenativeConfigs(c); return true; diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/android.ts b/packages/rnv/src/core/sdkManager/deviceUtils/android.ts index 29c99f74b9..4cc350a284 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/android.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/android.ts @@ -87,7 +87,7 @@ export const launchAndroidSimulator = async (c, target, isIndependentThread = fa return Promise.reject('No simulator -t target name specified!'); }; -export const listAndroidTargets = async (c) => { +export const listAndroidTargets = async (c: RnvConfig) => { logTask('listAndroidTargets'); const { program: { device }, @@ -314,7 +314,7 @@ const getDeviceType = async (device, c) => { return device; }; -const getAvdDetails = (c, deviceName) => { +const getAvdDetails = (c: RnvConfig, deviceName) => { const { ANDROID_SDK_HOME, ANDROID_AVD_HOME } = process.env; // .avd dir might be in other place than homedir. (https://developer.android.com/studio/command-line/variables) @@ -529,7 +529,7 @@ export const askForNewEmulator = async (c: RnvConfig, platform: string) => { return Promise.reject('Action canceled!'); }; -const _createEmulator = (c, apiVersion, emuPlatform, emuName, arch = 'x86') => { +const _createEmulator = (c: RnvConfig, apiVersion, emuPlatform, emuName, arch = 'x86') => { logTask('_createEmulator'); return execCLI(c, CLI_ANDROID_SDKMANAGER, `"system-images;android-${apiVersion};${emuPlatform};${arch}"`) @@ -546,7 +546,7 @@ const _createEmulator = (c, apiVersion, emuPlatform, emuName, arch = 'x86') => { .catch((e) => logError(e, true)); }; -const waitForEmulatorToBeReady = (c, emulator) => +const waitForEmulatorToBeReady = (c: RnvConfig, emulator) => waitForEmulator(c, CLI_ANDROID_ADB, `-s ${emulator} shell getprop init.svc.bootanim`, (res) => res.includes('stopped') ); diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts index 5daab33132..9164e680d5 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts @@ -15,12 +15,12 @@ const parser = new xml2js.Parser(); export const DEFAULT_CERTIFICATE_NAME = 'tizen_author'; -const formatXMLObject = (obj) => { +const formatXMLObject = (obj: Record) => { const platArr = obj['model-config']?.platform; const platKeyArr = platArr?.[0]?.key || platArr?.key; if (platKeyArr) { return { - ...platKeyArr.reduce((acc, cur) => { + ...platKeyArr.reduce((acc: Record, cur: any) => { acc[cur.$.name] = cur._; return acc; }, {}), @@ -32,7 +32,7 @@ const formatXMLObject = (obj) => { export const DEFAULT_SECURITY_PROFILE_NAME = 'RNVanillaCert'; -export const launchTizenSimulator = (c, name) => { +export const launchTizenSimulator = (c: RnvConfig, name: string) => { logTask(`launchTizenSimulator:${name}`); if (name) { @@ -43,7 +43,7 @@ export const launchTizenSimulator = (c, name) => { return Promise.reject('No simulator -t target name specified!'); }; -export const listTizenTargets = async (c) => { +export const listTizenTargets = async (c: RnvConfig) => { const targets = await execCLI(c, CLI_TIZEN_EMULATOR, 'list-vm', { detached: true, }); @@ -83,7 +83,7 @@ export const createDevelopTizenCertificate = (c) => }); }); -export const addDevelopTizenCertificate = (c, secureProfileConfig) => +export const addDevelopTizenCertificate = (c: RnvConfig, secureProfileConfig) => new Promise((resolve) => { logTask('addDevelopTizenCertificate'); @@ -136,7 +136,7 @@ const _getDeviceID = async (c, target) => { return Promise.reject(`No device matching ${target} could be found.`); }; -const _getRunningDevices = async (c) => { +const _getRunningDevices = async (c: RnvConfig) => { const { platform } = c.program; const devicesList = await execCLI(c, CLI_SDB_TIZEN, 'devices'); const lines = devicesList diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts b/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts index e5962839a8..ca6e637c24 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts @@ -46,7 +46,7 @@ export const launchWebOSimulator = (c) => { // } // }; -const parseDevices = (c, devicesResponse) => { +const parseDevices = (c: RnvConfig, devicesResponse) => { const linesArray = devicesResponse .split('\n') .slice(2) @@ -107,7 +107,7 @@ const buildDeviceChoices = (devices) => value: device.name, })); -export const listWebOSTargets = async (c) => { +export const listWebOSTargets = async (c: RnvConfig) => { const devicesResponse = await execCLI(c, CLI_WEBOS_ARES_DEVICE_INFO, '-D'); const devices = await parseDevices(c, devicesResponse); @@ -118,7 +118,7 @@ export const listWebOSTargets = async (c) => { return true; }; -const waitForEmulatorToBeReady = async (c) => { +const waitForEmulatorToBeReady = async (c: RnvConfig) => { const devicesResponse = await execCLI(c, CLI_WEBOS_ARES_DEVICE_INFO, '-D'); const devices = await parseDevices(c, devicesResponse); const emulator = devices.filter((d) => !d.isDevice)[0]; @@ -127,7 +127,7 @@ const waitForEmulatorToBeReady = async (c) => { return waitForEmulator(c, CLI_WEBOS_ARES_DEVICE_INFO, `-d ${emulator.name}`, (res) => res.includes('modelName')); }; -export const runWebosSimOrDevice = async (c) => { +export const runWebosSimOrDevice = async (c: RnvConfig) => { const { device } = c.program; const tDir = getPlatformProjectDir(c); diff --git a/packages/rnv/src/core/sdkManager/installer.ts b/packages/rnv/src/core/sdkManager/installer.ts index 6eec31f599..c7576405e7 100644 --- a/packages/rnv/src/core/sdkManager/installer.ts +++ b/packages/rnv/src/core/sdkManager/installer.ts @@ -68,7 +68,7 @@ const _logSdkWarning = (c) => { logWarning(`Your ${c.paths.workspace.config} is missing SDK configuration object`); }; -export const checkAndConfigureAndroidSdks = async (c) => { +export const checkAndConfigureAndroidSdks = async (c: RnvConfig) => { const sdk = c.buildConfig?.sdks?.ANDROID_SDK; logTask('checkAndConfigureAndroidSdks', `(${sdk})`); @@ -98,7 +98,7 @@ export const checkAndConfigureAndroidSdks = async (c) => { c.cli[CLI_ANDROID_SDKMANAGER] = sdkManagerPath; }; -export const checkAndConfigureTizenSdks = async (c) => { +export const checkAndConfigureTizenSdks = async (c: RnvConfig) => { logTask(`checkAndConfigureTizenSdks:${c.platform}`); const sdk = c.buildConfig?.sdks?.TIZEN_SDK; if (sdk) { @@ -113,7 +113,7 @@ export const checkAndConfigureTizenSdks = async (c) => { } }; -export const checkAndConfigureWebosSdks = async (c) => { +export const checkAndConfigureWebosSdks = async (c: RnvConfig) => { logTask(`checkAndConfigureWebosSdks:${c.platform}`); const sdk = c.buildConfig?.sdks?.WEBOS_SDK; if (sdk) { @@ -147,7 +147,7 @@ export const checkAndConfigureWebosSdks = async (c) => { } }; -export const checkAndConfigureSdks = async (c) => { +export const checkAndConfigureSdks = async (c: RnvConfig) => { logTask('checkAndConfigureSdks'); switch (c.platform) { @@ -264,7 +264,7 @@ const _attemptAutoFix = async (c, sdkPlatform, sdkKey, traverseUntilFoundFile) = return true; }; -export const checkSdk = async (c) => { +export const checkSdk = async (c: RnvConfig) => { logTask('checkSdk'); if (!_isSdkInstalled(c)) { logWarning( diff --git a/packages/rnv/src/core/setupManager/index.ts b/packages/rnv/src/core/setupManager/index.ts index 535ad64a1d..6f3c8f6cd6 100644 --- a/packages/rnv/src/core/setupManager/index.ts +++ b/packages/rnv/src/core/setupManager/index.ts @@ -2,8 +2,9 @@ import LinuxPlatformSetup from './linux'; import WindowsPlatformSetup from './windows'; import DarwinPlatformSetup from './darwin'; import Config from '../configManager/config'; +import { RnvConfig } from '../configManager/types'; -export default (_c) => { +export default (_c: RnvConfig) => { let c = _c; if (!c) c = Config.getConfig(); const { diff --git a/packages/rnv/src/core/setupManager/linux.ts b/packages/rnv/src/core/setupManager/linux.ts index a42adc49bc..b0b61771a0 100644 --- a/packages/rnv/src/core/setupManager/linux.ts +++ b/packages/rnv/src/core/setupManager/linux.ts @@ -13,7 +13,7 @@ class LinuxPlatformSetup extends BasePlatformSetup { super('linux', c); } - async installSoftware(software) { + async installSoftware(software: string) { if (commandExistsSync('apt-get')) { await shell.exec(`apt-get -qq update && apt-get install ${software} -y > /dev/null`); } @@ -41,7 +41,7 @@ class LinuxPlatformSetup extends BasePlatformSetup { return true; } - async postInstall(sdk) { + async postInstall(sdk: string) { if (sdk === 'android') { const { location } = setupConfig.android; logDebug( diff --git a/packages/rnv/src/core/systemManager/logger.ts b/packages/rnv/src/core/systemManager/logger.ts index ce9a7bd90b..d9798de2f7 100644 --- a/packages/rnv/src/core/systemManager/logger.ts +++ b/packages/rnv/src/core/systemManager/logger.ts @@ -327,7 +327,7 @@ export const logTask = (task: string, customChalk?: any) => { console.log(_sanitizePaths(msg)); }; -export const logInitTask = (task: string, customChalk: string | ((s: string) => string)) => { +export const logInitTask = (task: string, customChalk?: string | ((s: string) => string)) => { if (_jsonOnly) { return _printJson({ type: 'taskInit', diff --git a/packages/rnv/src/core/systemManager/npmUtils.ts b/packages/rnv/src/core/systemManager/npmUtils.ts index 30ef05fff6..a9fa8f3081 100644 --- a/packages/rnv/src/core/systemManager/npmUtils.ts +++ b/packages/rnv/src/core/systemManager/npmUtils.ts @@ -46,7 +46,7 @@ export const checkNpxIsInstalled = async () => { } }; -export const checkAndCreateProjectPackage = async (c) => { +export const checkAndCreateProjectPackage = async (c: RnvConfig) => { logTask('checkAndCreateProjectPackage'); if (!packageJsonIsValid(c)) { @@ -140,7 +140,7 @@ export const listAndSelectNpmVersion = async (c, npmPackage) => { return inputTemplateVersion; }; -export const checkIfProjectAndNodeModulesExists = async (c) => { +export const checkIfProjectAndNodeModulesExists = async (c: RnvConfig) => { logTask('checkIfProjectAndNodeModulesExists'); if (c.paths.project.configExists && !fsExistsSync(c.paths.project.nodeModulesDir)) { @@ -270,7 +270,7 @@ export const installPackageDependencies = async (c, failOnError = false) => { } }; -export const jetifyIfRequired = async (c) => { +export const jetifyIfRequired = async (c: RnvConfig) => { logTask('jetifyIfRequired'); if (c.files.project.configLocal?._meta?.requiresJetify) { if (doResolve('jetifier')) { diff --git a/packages/rnv/src/core/systemManager/types.ts b/packages/rnv/src/core/systemManager/types.ts index 6e56fd6766..8998b11f5e 100644 --- a/packages/rnv/src/core/systemManager/types.ts +++ b/packages/rnv/src/core/systemManager/types.ts @@ -14,6 +14,7 @@ export type ExecOptions = { privateParams?: Array; env?: Record; ignoreErrors?: boolean; + detached?: boolean; }; export type ExecCallback = (isError: boolean) => void; diff --git a/packages/rnv/src/core/taskManager/index.ts b/packages/rnv/src/core/taskManager/index.ts index e92c6d1c9c..166d0368dd 100644 --- a/packages/rnv/src/core/taskManager/index.ts +++ b/packages/rnv/src/core/taskManager/index.ts @@ -12,12 +12,14 @@ import { registerAllPlatformEngines, } from '../engineManager'; import { TASK_CONFIGURE_SOFT } from '../constants'; +import { RnvConfig } from '../configManager/types'; +import { RnvTask, RnvTaskMap } from './types'; let executedTasks = {}; -const CUSTOM_TASKS = {}; +const CUSTOM_TASKS: RnvTaskMap = {}; -export const registerCustomTask = async (c, task) => { +export const registerCustomTask = async (_c: RnvConfig, task: RnvTask) => { if (task.task) { CUSTOM_TASKS[task.task] = task; } @@ -58,7 +60,7 @@ const _getTaskObj = (taskInstance) => { }; }; -export const findSuitableTask = async (c, specificTask) => { +export const findSuitableTask = async (c: RnvConfig, specificTask) => { logTask('findSuitableTask'); const REGISTERED_ENGINES = getRegisteredEngines(c); let task; @@ -242,7 +244,7 @@ export const findSuitableTask = async (c, specificTask) => { return getEngineTask(task, c.runtime.engine.tasks); }; -const _populateExtraParameters = (c, task) => { +const _populateExtraParameters = (c: RnvConfig, task: RnvTask) => { if (task.params) { task.params.forEach((param) => { let cmd = ''; @@ -287,7 +289,13 @@ const _executePipe = async (c, task, phase) => executePipe(c, `${task.split(' ') const TASK_LIMIT = 20; -export const executeTask = async (c, task, parentTask, originTask, isFirstTask) => { +export const executeTask = async ( + c: RnvConfig, + task: string, + parentTask: string | null, + originTask: string, + isFirstTask?: boolean +) => { const pt = parentTask ? `=> [${parentTask}] ` : ''; c._currentTask = task; logInitTask(`${pt}=> [${chalk().bold.rgb(170, 106, 170)(task)}]`); @@ -324,7 +332,7 @@ const _logSkip = (task) => { logInfo(`Original RNV task ${chalk().white(task)} marked to ignore. SKIPPING...`); }; -export const shouldSkipTask = (c, task, originTask) => { +export const shouldSkipTask = (c: RnvConfig, task, originTask) => { const tasks = c.buildConfig?.tasks; c.runtime.platform = c.platform; if (!tasks) return; diff --git a/packages/rnv/src/core/taskManager/types.ts b/packages/rnv/src/core/taskManager/types.ts index fe316f2c9e..34ce149b9e 100644 --- a/packages/rnv/src/core/taskManager/types.ts +++ b/packages/rnv/src/core/taskManager/types.ts @@ -1,7 +1,15 @@ export type RnvTask = { task: string; - params: Array; + params: Array; isGlobalScope: boolean; }; +export type RnvTaskParameter = { + shortcut: string; + value: string; + key: string; + isRequired: boolean; + description: string; +}; + export type RnvTaskMap = Record; diff --git a/packages/rnv/src/core/templateManager/index.ts b/packages/rnv/src/core/templateManager/index.ts index a270c92683..806f2c7140 100644 --- a/packages/rnv/src/core/templateManager/index.ts +++ b/packages/rnv/src/core/templateManager/index.ts @@ -22,7 +22,7 @@ import { doResolve } from '../systemManager/resolve'; import { checkIfProjectAndNodeModulesExists } from '../systemManager/npmUtils'; import { RnvConfig } from '../configManager/types'; -export const checkIfTemplateConfigured = async (c) => { +export const checkIfTemplateConfigured = async (c: RnvConfig) => { logTask('checkIfTemplateConfigured'); if (c.program.skipDependencyCheck || c.files.project.config.isTemplate) return true; if (!c.buildConfig.templates) { @@ -73,7 +73,7 @@ const _cleanProjectTemplateSync = (c) => { removeFilesSync(filesToRemove); }; -const _applyTemplate = async (c) => { +const _applyTemplate = async (c: RnvConfig) => { logTask('_applyTemplate', `current:${c.buildConfig.currentTemplate} selected:${c.runtime.selectedTemplate}`); if (c.runtime.selectedTemplate) { @@ -207,7 +207,7 @@ const _configureProjectConfig = (c) => resolve(); }); -const _configureRenativeConfig = async (c) => { +const _configureRenativeConfig = async (c: RnvConfig) => { // renative.json const templateConfig = readObjectSync(c.paths.template.configTemplate); logDebug('configureProject:check renative.json'); @@ -237,7 +237,7 @@ const _configureRenativeConfig = async (c) => { return true; }; -export const configureTemplateFiles = async (c) => { +export const configureTemplateFiles = async (c: RnvConfig) => { logTask('configureTemplateFiles'); const templateConfig = readObjectSync(c.paths.template.configTemplate); @@ -299,12 +299,12 @@ export const configureEntryPoint = async (c: RnvConfig, platform: string) => { return true; }; -const _writeObjectSync = (c, p, s) => { +const _writeObjectSync = (c: RnvConfig, p, s) => { writeFileSync(p, s); generateBuildConfig(c); }; -export const getTemplateOptions = (c, isGlobalScope) => { +export const getTemplateOptions = (c: RnvConfig, isGlobalScope) => { let defaultProjectTemplates; if (isGlobalScope) { defaultProjectTemplates = c.files.rnv.projectTemplates.config.projectTemplates; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.app.configure.ts b/packages/rnv/src/engine-core/tasks/task.rnv.app.configure.ts index d244a905cf..0a1f2b2732 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.app.configure.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.app.configure.ts @@ -6,6 +6,7 @@ import { TASK_APP_CONFIGURE, PARAMS } from '../../core/constants'; import { writeFileSync, fsExistsSync, fsReadFileSync, fsRenameSync } from '../../core/systemManager/fileutils'; import { chalk, logError, logTask, logWarning, logDebug, logInfo, logAppInfo } from '../../core/systemManager/logger'; import { inquirerPrompt } from '../../cli/prompt'; +import { RnvConfig } from '../../core/configManager/types'; const _loadAppConfigIDfromDir = (dirName, appConfigsDir) => { logDebug(`_loadAppConfigIDfromDir:${dirName}:${appConfigsDir}`, chalk().grey); @@ -94,7 +95,7 @@ const matchAppConfigID = async (c, appConfigID) => { return false; }; -const _findAndSwitchAppConfigDir = async (c) => { +const _findAndSwitchAppConfigDir = async (c: RnvConfig) => { logTask('_findAndSwitchAppConfigDir'); const { appConfigsDirNames } = c.paths.project; if (appConfigsDirNames.length) { @@ -123,7 +124,7 @@ const _findAndSwitchAppConfigDir = async (c) => { return false; }; -const _setAppId = (c, appId) => { +const _setAppId = (c: RnvConfig, appId: string) => { const currentAppConfigId = c.files.project?.configLocal?._meta?.currentAppConfigId; logTask('_setAppId', `appId:${appId} runtime.appId:${c.runtime.appId} _meta.appId:${currentAppConfigId}`); @@ -131,7 +132,7 @@ const _setAppId = (c, appId) => { c.runtime.appDir = path.join(c.paths.project.builds.dir, `${c.runtime.appId}_${c.platform}`); }; -export const taskRnvAppConfigure = async (c) => { +export const taskRnvAppConfigure = async (c: RnvConfig) => { logTask('taskRnvAppConfigure'); c.paths.project.appConfigsDirNames = listAppConfigsFoldersSync(c, true); @@ -151,7 +152,7 @@ export const taskRnvAppConfigure = async (c) => { } // Reset appId if appConfig no longer exists but renative.local.json still has reference to it - if (!c.paths.project.appConfigsDirNames.includes(c.runtime.appId)) { + if (c.runtime.appId && !c.paths.project.appConfigsDirNames.includes(c.runtime.appId)) { c.runtime.appId = null; } @@ -179,8 +180,10 @@ export const taskRnvAppConfigure = async (c) => { } // Generate true path to appConfig (ensure external appConfigsDirs are included) - c.runtime.appConfigDir = - c.paths.project.appConfigsDirs[c.paths.project.appConfigsDirNames.indexOf(c.runtime.appId)]; + if (c.runtime.appId) { + c.runtime.appConfigDir = + c.paths.project.appConfigsDirs[c.paths.project.appConfigsDirNames.indexOf(c.runtime.appId)]; + } await updateRenativeConfigs(c); logAppInfo(c); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.app.create.ts b/packages/rnv/src/engine-core/tasks/task.rnv.app.create.ts index 0571d45ed4..77df416413 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.app.create.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.app.create.ts @@ -13,7 +13,7 @@ import { } from '../../core/systemManager/fileutils'; import { doResolve } from '../../core/systemManager/resolve'; -export const taskRnvAppCreate = async (c) => { +export const taskRnvAppCreate = async (c: RnvConfig) => { logTask('taskRnvAppCreate'); await configureRuntimeDefaults(c); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts b/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts index 2394acd881..057c97f344 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts @@ -27,7 +27,7 @@ const generateRandomKey = (length) => .map((x) => x[Math.floor(Math.random() * x.length)]) .join(''); -const _checkAndConfigureCrypto = async (c) => { +const _checkAndConfigureCrypto = async (c: RnvConfig) => { // handle missing config const source = `./${c.files.project.package.name}`; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.fastlane.ts b/packages/rnv/src/engine-core/tasks/task.rnv.fastlane.ts index 3ff972aa53..94df561639 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.fastlane.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.fastlane.ts @@ -3,7 +3,7 @@ import { getAppFolder, getCliArguments } from '../../core/common'; import { IOS, TVOS, ANDROID, ANDROID_TV, FIRE_TV, ANDROID_WEAR, PARAMS } from '../../core/constants'; import PlatformSetup from '../../core/setupManager'; -export const taskRnvFastlane = async (c) => { +export const taskRnvFastlane = async (c: RnvConfig) => { const args = getCliArguments(c); args.shift(); // we know the first one is fastlane, trash it diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.link.ts b/packages/rnv/src/engine-core/tasks/task.rnv.link.ts index f1c11ac0ec..c2e00f76f5 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.link.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.link.ts @@ -3,7 +3,7 @@ import { logInfo, logTask, logSuccess } from '../../core/systemManager/logger'; import { PARAMS, RNV_PACKAGES } from '../../core/constants'; import { fsExistsSync, fsRenameSync, fsSymlinkSync } from '../../core/systemManager/fileutils'; -const _linkPackage = (c, key, folder) => { +const _linkPackage = (c: RnvConfig, key, folder) => { const rnvPath = path.join(c.paths.project.nodeModulesDir, key); const rnvPathUnlinked = path.join(c.paths.project.nodeModulesDir, `${key}_unlinked`); const pkgDir = path.join(c.paths.rnv.dir, '../', folder); @@ -17,7 +17,7 @@ const _linkPackage = (c, key, folder) => { } }; -export const taskRnvLink = async (c) => { +export const taskRnvLink = async (c: RnvConfig) => { logTask('taskRnvLink'); RNV_PACKAGES.forEach((pkg) => { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.new.ts b/packages/rnv/src/engine-core/tasks/task.rnv.new.ts index ca96939b99..dbb7f3679c 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.new.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.new.ts @@ -36,7 +36,7 @@ import { isYarnInstalled, listAndSelectNpmVersion } from '../../core/systemManag const highlight = chalk().green; -const _prepareProjectOverview = (c, data) => { +const _prepareProjectOverview = (c: RnvConfig, data) => { data.appTitle = data.inputAppTitle || data.defaultAppTitle; data.teamID = ''; data.appID = data.inputAppID ? data.inputAppID.replace(/\s+/g, '-').toLowerCase() : data.appID; @@ -138,7 +138,7 @@ const interactiveQuestion = async (results, bootstrapQuestions, providedAnswers) } }; -export const taskRnvNew = async (c) => { +export const taskRnvNew = async (c: RnvConfig) => { logTask('taskRnvNew'); const { ci, @@ -604,7 +604,7 @@ export const taskRnvNew = async (c) => { ); }; -const findEngineKeyById = (c, id) => { +const findEngineKeyById = (c: RnvConfig, id) => { const { engineTemplates } = c.files.rnv.projectTemplates.config; const etk = Object.keys(engineTemplates); for (let i = 0; i < etk.length; i++) { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.template.add.ts b/packages/rnv/src/engine-core/tasks/task.rnv.template.add.ts index bb9222661d..b7c51bf5d3 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.template.add.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.template.add.ts @@ -7,12 +7,12 @@ import { TASK_PROJECT_CONFIGURE, TASK_TEMPLATE_ADD, PARAMS } from '../../core/co import { getTemplateOptions } from '../../core/templateManager'; -const _writeObjectSync = (c, p, s) => { +const _writeObjectSync = (c: RnvConfig, p, s) => { writeFileSync(p, s); generateBuildConfig(c); }; -export const _addTemplate = (c, template) => { +export const _addTemplate = (c: RnvConfig, template) => { logTask('addTemplate'); c.files.project.config.templates = c.files.project.config.templates || {}; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.unlink.ts b/packages/rnv/src/engine-core/tasks/task.rnv.unlink.ts index c5195131cc..1b836840a5 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.unlink.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.unlink.ts @@ -3,7 +3,7 @@ import { logInfo, logTask, logSuccess } from '../../core/systemManager/logger'; import { PARAMS, RNV_PACKAGES } from '../../core/constants'; import { fsExistsSync, fsRenameSync, fsUnlinkSync, fsLstatSync } from '../../core/systemManager/fileutils'; -const _unlinkPackage = (c, key) => { +const _unlinkPackage = (c: RnvConfig, key) => { const rnvPath = path.join(c.paths.project.nodeModulesDir, key); const rnvPathUnlinked = path.join(c.paths.project.nodeModulesDir, `${key}_unlinked`); @@ -20,7 +20,7 @@ const _unlinkPackage = (c, key) => { } }; -export const taskRnvUnlink = async (c) => { +export const taskRnvUnlink = async (c: RnvConfig) => { logTask('taskRnvUnlink'); RNV_PACKAGES.forEach((pkg) => { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.workspace.configure.ts b/packages/rnv/src/engine-core/tasks/task.rnv.workspace.configure.ts index 0572543cfe..25f3c4a875 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.workspace.configure.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.workspace.configure.ts @@ -9,7 +9,7 @@ import { } from '../../core/systemManager/fileutils'; import { chalk, logTask, logWarning, logDebug, logInfo } from '../../core/systemManager/logger'; -export const taskRnvWorkspaceConfigure = async (c) => { +export const taskRnvWorkspaceConfigure = async (c: RnvConfig) => { logTask('taskRnvWorkspaceConfigure'); // Check globalConfig Dir From 08fdb10d78e576711d083ab3ef377a5a4ba30acf Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Tue, 29 Aug 2023 23:51:01 +0200 Subject: [PATCH 14/83] more types refactor, 1081 togo --- packages/rnv/src/cli/prompt.ts | 9 +++++++-- packages/rnv/src/cli/types.ts | 2 ++ packages/rnv/src/core/common.ts | 2 +- packages/rnv/src/core/configManager/types.ts | 5 +++++ packages/rnv/src/core/constants.ts | 11 ++++++----- packages/rnv/src/core/engineManager/index.ts | 6 +++--- packages/rnv/src/core/platformManager/index.ts | 2 +- packages/rnv/src/core/pluginManager/index.ts | 2 +- .../rnv/src/core/projectManager/buildHooks.ts | 2 +- packages/rnv/src/core/projectManager/index.ts | 4 ++-- .../rnv/src/core/projectManager/workspace.ts | 2 +- .../src/core/sdkManager/deviceUtils/android.ts | 18 +++++++++--------- .../src/core/sdkManager/deviceUtils/apple.ts | 2 +- .../src/core/sdkManager/deviceUtils/tizen.ts | 4 ++-- .../src/core/sdkManager/deviceUtils/webos.ts | 2 +- packages/rnv/src/core/sdkManager/installer.ts | 2 +- packages/rnv/src/core/systemManager/logger.ts | 2 +- .../rnv/src/core/systemManager/npmUtils.ts | 4 ++-- packages/rnv/src/core/systemManager/types.ts | 1 + packages/rnv/src/core/taskManager/index.ts | 10 +++++----- packages/rnv/src/core/taskManager/types.ts | 15 +++++++++++---- packages/rnv/src/core/templateManager/index.ts | 8 ++++---- .../tasks/task.rnv.app.configure.ts | 6 +++--- .../src/engine-core/tasks/task.rnv.clean.ts | 3 ++- .../tasks/task.rnv.configureSoft.ts | 3 ++- .../tasks/task.rnv.crypto.decrypt.ts | 13 +++++++++++-- .../tasks/task.rnv.crypto.encrypt.ts | 6 ++++-- .../src/engine-core/tasks/task.rnv.doctor.ts | 4 +++- .../rnv/src/engine-core/tasks/task.rnv.help.ts | 3 ++- .../engine-core/tasks/task.rnv.hooks.list.ts | 5 +++-- .../engine-core/tasks/task.rnv.hooks.pipes.ts | 2 +- .../engine-core/tasks/task.rnv.hooks.run.ts | 3 ++- .../src/engine-core/tasks/task.rnv.install.ts | 3 ++- .../rnv/src/engine-core/tasks/task.rnv.kill.ts | 3 ++- .../rnv/src/engine-core/tasks/task.rnv.link.ts | 6 ++++-- .../rnv/src/engine-core/tasks/task.rnv.pkg.ts | 6 +++--- .../tasks/task.rnv.platform.configure.ts | 2 +- .../tasks/task.rnv.platform.connect.ts | 2 +- .../tasks/task.rnv.platform.eject.ts | 5 +++-- .../tasks/task.rnv.platform.list.ts | 3 ++- .../tasks/task.rnv.platform.setup.ts | 3 ++- .../engine-core/tasks/task.rnv.plugin.add.ts | 5 +++-- .../engine-core/tasks/task.rnv.plugin.list.ts | 3 ++- .../tasks/task.rnv.plugin.update.ts | 2 +- .../tasks/task.rnv.project.configure.ts | 2 +- .../tasks/task.rnv.project.upgrade.ts | 2 +- .../src/engine-core/tasks/task.rnv.publish.ts | 5 +++-- .../src/engine-core/tasks/task.rnv.switch.ts | 2 +- .../tasks/task.rnv.target.launch.ts | 2 +- .../engine-core/tasks/task.rnv.target.list.ts | 7 ++++--- .../engine-core/tasks/task.rnv.template.add.ts | 10 +++++++--- .../tasks/task.rnv.template.apply.ts | 3 ++- .../tasks/task.rnv.template.list.ts | 3 ++- .../src/engine-core/tasks/task.rnv.unlink.ts | 6 ++++-- .../tasks/task.rnv.workspace.add.ts | 7 +++++-- .../tasks/task.rnv.workspace.configure.ts | 3 ++- .../tasks/task.rnv.workspace.connect.ts | 2 +- .../tasks/task.rnv.workspace.list.ts | 3 ++- .../tasks/task.rnv.workspace.update.ts | 3 ++- 59 files changed, 165 insertions(+), 101 deletions(-) diff --git a/packages/rnv/src/cli/prompt.ts b/packages/rnv/src/cli/prompt.ts index ca977333ba..655670a6ca 100644 --- a/packages/rnv/src/cli/prompt.ts +++ b/packages/rnv/src/cli/prompt.ts @@ -1,7 +1,7 @@ import inquirer from 'inquirer'; import { chalk, logWarning, logTask, logDebug } from '../core/systemManager/logger'; import Config from '../core/configManager/config'; -import { PromptOptions, PromptParams } from './types'; +import { PromptOptions, PromptParams, PromptRenderFn } from './types'; export const inquirerPrompt = async (params: PromptParams) => { const c = Config.getConfig(); @@ -39,7 +39,12 @@ export const pressAnyKeyToContinue = () => { return inquirer.prompt(params as any); }; -export const generateOptions = (inputData: any, isMultiChoice = false, mapping: any, renderMethod: any) => { +export const generateOptions = ( + inputData: any, + isMultiChoice = false, + mapping?: any, + renderMethod?: PromptRenderFn +) => { logDebug('generateOptions', isMultiChoice); let asString = ''; const valuesAsObject: Record = {}; diff --git a/packages/rnv/src/cli/types.ts b/packages/rnv/src/cli/types.ts index e97dcb5959..be1597f6e0 100644 --- a/packages/rnv/src/cli/types.ts +++ b/packages/rnv/src/cli/types.ts @@ -17,3 +17,5 @@ export type PromptParams = { type: string; pageSize?: number; }; + +export type PromptRenderFn = (i: number, obj, mapping, defaultVal) => string; diff --git a/packages/rnv/src/core/common.ts b/packages/rnv/src/core/common.ts index 57edd082f0..8be355583f 100755 --- a/packages/rnv/src/core/common.ts +++ b/packages/rnv/src/core/common.ts @@ -90,7 +90,7 @@ export const getDevServerHost = (c: RnvConfig) => { return devServerHostFixed; }; -export const waitForHost = async (c, suffix = 'assets/bundle.js') => { +export const waitForHost = async (c: RnvConfig, suffix = 'assets/bundle.js') => { logTask('waitForHost', `port:${c.runtime.port}`); let attempts = 0; const maxAttempts = 10; diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index 32c5eb3381..e3caf2e584 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -8,9 +8,11 @@ export interface RnvConfig { rnvVersion: string; _currentTask?: string; systemPropsInjects: Array; + _requiresNpmInstall?: boolean; //======= _renativePluginCache: any; cli: any; + buildHooks: Record Promise>; api: { fsExistsSync: any; fsReadFileSync: any; @@ -48,6 +50,8 @@ export interface RnvConfig { timestamp: number; appConfigDir: string; hasAllEnginesRegistered: boolean; + skipPackageUpdate?: boolean; + selectedTemplate?: string; }; paths: { GLOBAL_RNV_CONFIG: string; @@ -175,6 +179,7 @@ export interface RnvConfig { platformTemplates: Record; appConfigsDir: string; }; + appConfigBase: string; }; files: { rnv: { diff --git a/packages/rnv/src/core/constants.ts b/packages/rnv/src/core/constants.ts index 6746a0a6e5..8fe818479f 100644 --- a/packages/rnv/src/core/constants.ts +++ b/packages/rnv/src/core/constants.ts @@ -2,6 +2,7 @@ import { homedir } from 'os'; import path from 'path'; import { RnvConfigSchema } from './configManager/types'; +import { RnvTaskParameter } from './taskManager/types'; export const USER_HOME_DIR = homedir(); export const RNV_HOME_DIR = path.join(__dirname, '../..'); @@ -236,7 +237,7 @@ export const TASK_KILL = 'kill'; export const CLI_PROPS = ['provisioningStyle', 'codeSignIdentity', 'provisionProfileSpecifier']; -export const PARAM_KEYS: any = { +export const PARAM_KEYS: Record = { info: { shortcut: 'i', value: 'value', @@ -513,9 +514,9 @@ Object.keys(PARAM_KEYS).forEach((k) => { }); export const PARAMS = { - withBase: (arr?: any) => + withBase: (arr?: Array) => [PARAM_KEYS.info, PARAM_KEYS.ci, PARAM_KEYS.mono, PARAM_KEYS.maxErrorLength, PARAM_KEYS.only].concat(arr || []), - withConfigure: (arr?: any) => + withConfigure: (arr?: Array) => [ PARAM_KEYS.reset, PARAM_KEYS.resetHard, @@ -525,7 +526,7 @@ export const PARAMS = { PARAM_KEYS.scheme, PARAM_KEYS.platform, ].concat(arr || []), - withRun: (arr?: any) => + withRun: (arr?: Array) => [ PARAM_KEYS.target, PARAM_KEYS.device, @@ -536,7 +537,7 @@ export const PARAMS = { PARAM_KEYS.skipTargetCheck, PARAM_KEYS.host, ].concat(arr || []), - withAll: (arr?: any) => Object.values(PARAM_KEYS).concat(arr || []), + withAll: (arr?: Array) => Object.values(PARAM_KEYS).concat(arr || []), all: Object.keys(PARAM_KEYS), }; diff --git a/packages/rnv/src/core/engineManager/index.ts b/packages/rnv/src/core/engineManager/index.ts index fecbd76059..c4d0b19a2e 100644 --- a/packages/rnv/src/core/engineManager/index.ts +++ b/packages/rnv/src/core/engineManager/index.ts @@ -16,7 +16,7 @@ import { RnvEngineConfig, RnvEngineConfigMap, RnvEngineInstallConfig } from './t const ENGINE_CORE = 'engine-core'; -export const registerEngine = async (c, engine, platform, engConfig) => { +export const registerEngine = async (c: RnvConfig, engine, platform, engConfig) => { logTask(`registerEngine:${engine.config.id}`); c.runtime.enginesById[engine.config.id] = engine; engine.initializeRuntimeConfig(c); @@ -114,7 +114,7 @@ export const configureEngines = async (c: RnvConfig) => { return true; }; -export const registerMissingPlatformEngines = async (c, taskInstance) => { +export const registerMissingPlatformEngines = async (c: RnvConfig, taskInstance) => { logTask('registerMissingPlatformEngines'); if ( !taskInstance || @@ -202,7 +202,7 @@ If you don't want to use this dependency make sure you remove platform which req return Object.keys(addedPlugins).length; }; -export const loadEnginePackageDeps = async (c, engineConfigs) => { +export const loadEnginePackageDeps = async (c: RnvConfig, engineConfigs) => { logTask('loadEnginePackageDeps'); if (c.program.skipDependencyCheck || c.files.project.config.isTemplate) return 0; // Check engine dependencies diff --git a/packages/rnv/src/core/platformManager/index.ts b/packages/rnv/src/core/platformManager/index.ts index ee1d2e592a..d10ec8a406 100644 --- a/packages/rnv/src/core/platformManager/index.ts +++ b/packages/rnv/src/core/platformManager/index.ts @@ -82,7 +82,7 @@ export const createPlatformBuild = (c: RnvConfig, platform: string) => resolve(); }); -export const isPlatformSupported = async (c, isGlobalScope = false) => { +export const isPlatformSupported = async (c: RnvConfig, isGlobalScope = false) => { logTask('isPlatformSupported'); if (c.platform && c.platform !== true && isGlobalScope) { diff --git a/packages/rnv/src/core/pluginManager/index.ts b/packages/rnv/src/core/pluginManager/index.ts index cd7700bcc2..fcdff64467 100644 --- a/packages/rnv/src/core/pluginManager/index.ts +++ b/packages/rnv/src/core/pluginManager/index.ts @@ -346,7 +346,7 @@ export const resolvePluginDependants = async (c: RnvConfig) => { return true; }; -const _resolvePluginDependencies = async (c, key, keyScope, parentKey) => { +const _resolvePluginDependencies = async (c: RnvConfig, key, keyScope, parentKey) => { // IMPORTANT: Do not cache this valuse as they need to be refreshed every // round in case new plugin has been installed and c.buildConfig generated if (keyScope === null) { diff --git a/packages/rnv/src/core/projectManager/buildHooks.ts b/packages/rnv/src/core/projectManager/buildHooks.ts index 112d99afd1..510d94f412 100644 --- a/packages/rnv/src/core/projectManager/buildHooks.ts +++ b/packages/rnv/src/core/projectManager/buildHooks.ts @@ -6,7 +6,7 @@ import { fsExistsSync, copyFolderContentsRecursiveSync } from '../systemManager/ import { getConfigProp } from '../common'; import { doResolve } from '../systemManager/resolve'; -export const executePipe = async (c, key) => { +export const executePipe = async (c: RnvConfig, key) => { logHook('executePipe', c?.program?.json ? key : `('${key}')`); await buildHooks(c); diff --git a/packages/rnv/src/core/projectManager/index.ts b/packages/rnv/src/core/projectManager/index.ts index fbc3208f36..b8c78410a6 100644 --- a/packages/rnv/src/core/projectManager/index.ts +++ b/packages/rnv/src/core/projectManager/index.ts @@ -424,7 +424,7 @@ const _resolvePackage = (c: RnvConfig, v) => { // return false; // }; -export const copyAssetsFolder = async (c, platform, subPath, customFn) => { +export const copyAssetsFolder = async (c: RnvConfig, platform, subPath, customFn) => { logTask('copyAssetsFolder'); if (!isPlatformActive(c, platform)) return; @@ -506,7 +506,7 @@ export const copyAssetsFolder = async (c, platform, subPath, customFn) => { }; //NOTE: Default assets have been removed from engines -// const generateDefaultAssets = async (c, platform, sourcePath, forceTrue) => { +// const generateDefaultAssets = async (c: RnvConfig, platform, sourcePath, forceTrue) => { // logTask('generateDefaultAssets'); // let confirmAssets = true; // if (c.program.ci !== true && c.program.yes !== true && !forceTrue) { diff --git a/packages/rnv/src/core/projectManager/workspace.ts b/packages/rnv/src/core/projectManager/workspace.ts index b4addbb38d..134f996ccf 100644 --- a/packages/rnv/src/core/projectManager/workspace.ts +++ b/packages/rnv/src/core/projectManager/workspace.ts @@ -3,7 +3,7 @@ import { generateOptions, inquirerPrompt } from '../../cli/prompt'; import { chalk, logTask, logWarning, logDebug, logInfo } from '../systemManager/logger'; import { writeFileSync, mkdirSync, fsExistsSync } from '../systemManager/fileutils'; -export const createWorkspace = async (c, workspaceID, workspacePath) => { +export const createWorkspace = async (c: RnvConfig, workspaceID, workspacePath) => { c.files.rnv.configWorkspaces.workspaces[workspaceID] = { path: workspacePath, }; diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/android.ts b/packages/rnv/src/core/sdkManager/deviceUtils/android.ts index 4cc350a284..7aa1cc7acc 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/android.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/android.ts @@ -41,7 +41,7 @@ export const composeDevicesString = (devices, returnArray) => { return `\n${devicesArray.join('')}`; }; -export const launchAndroidSimulator = async (c, target, isIndependentThread = false) => { +export const launchAndroidSimulator = async (c: RnvConfig, target, isIndependentThread = false) => { logTask('launchAndroidSimulator', `target:${target} independentThread:${!!isIndependentThread}`); let newTarget = target; if (target === true) { @@ -124,7 +124,7 @@ const _getDeviceString = (device, i) => { return ` [${i + 1}]> ${deviceString}\n`; }; -export const resetAdb = async (c, ranBefore) => { +export const resetAdb = async (c: RnvConfig, ranBefore) => { try { if (!ranBefore) await execCLI(c, CLI_ANDROID_ADB, 'kill-server'); } catch (e) { @@ -141,7 +141,7 @@ export const resetAdb = async (c, ranBefore) => { } }; -export const getAndroidTargets = async (c, skipDevices, skipAvds, deviceOnly = false) => { +export const getAndroidTargets = async (c: RnvConfig, skipDevices, skipAvds, deviceOnly = false) => { logTask('getAndroidTargets', `skipDevices:${!!skipDevices} skipAvds:${!!skipAvds} deviceOnly:${!!deviceOnly}`); // Temp workaround for race conditions receiving devices with offline status await new Promise((r) => setTimeout(r, 1000)); @@ -169,7 +169,7 @@ const calculateDeviceDiagonal = (width, height, density) => { return Math.sqrt(widthInches * widthInches + heightInches * heightInches); }; -const getRunningDeviceProp = async (c, udid, prop) => { +const getRunningDeviceProp = async (c: RnvConfig, udid, prop) => { // avoid multiple calls to the same device if (currentDeviceProps[udid]) { if (!prop) return currentDeviceProps[udid]; @@ -191,7 +191,7 @@ const getRunningDeviceProp = async (c, udid, prop) => { return getRunningDeviceProp(c, udid, prop); }; -const decideIfTVRunning = async (c, device) => { +const decideIfTVRunning = async (c: RnvConfig, device) => { const { udid, model, product } = device; const mod = await getRunningDeviceProp(c, udid, 'ro.product.model'); const name = await getRunningDeviceProp(c, udid, 'ro.product.name'); @@ -217,7 +217,7 @@ const decideIfTVRunning = async (c, device) => { return isTV; }; -const decideIfWearRunning = async (c, device) => { +const decideIfWearRunning = async (c: RnvConfig, device) => { const { udid, model, product } = device; const fingerprint = await getRunningDeviceProp(c, udid, 'ro.vendor.build.fingerprint'); const name = await getRunningDeviceProp(c, udid, 'ro.product.vendor.name'); @@ -353,7 +353,7 @@ const getAvdDetails = (c: RnvConfig, deviceName) => { return results; }; -const getEmulatorName = async (c, words) => { +const getEmulatorName = async (c: RnvConfig, words) => { const emulator = words[0]; const port = emulator.split('-')[1]; @@ -364,7 +364,7 @@ const getEmulatorName = async (c, words) => { return emulatorName; }; -export const connectToWifiDevice = async (c, target) => { +export const connectToWifiDevice = async (c: RnvConfig, target) => { let connect_str = `connect ${target}`; if (!target.includes(':')) { @@ -377,7 +377,7 @@ export const connectToWifiDevice = async (c, target) => { return false; }; -const _parseDevicesResult = async (c, devicesString, avdsString, deviceOnly) => { +const _parseDevicesResult = async (c: RnvConfig, devicesString, avdsString, deviceOnly) => { logDebug(`_parseDevicesResult:${devicesString}:${avdsString}:${deviceOnly}`); const devices = []; const { skipTargetCheck } = c.program; diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts b/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts index 371cef00a2..8a662d1daa 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts @@ -170,7 +170,7 @@ const _parseIOSDevicesList = (rawDevices, platform, ignoreDevices = false, ignor return devices; }; -export const launchAppleSimulator = async (c, target) => { +export const launchAppleSimulator = async (c: RnvConfig, target) => { logTask('launchAppleSimulator', `${target}`); const devicesArr = await getAppleDevices(c, true); diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts index 9164e680d5..b116522600 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts @@ -98,7 +98,7 @@ export const addDevelopTizenCertificate = (c: RnvConfig, secureProfileConfig) => }); }); -const _getDeviceID = async (c, target) => { +const _getDeviceID = async (c: RnvConfig, target) => { const { device } = c.program; if (device) { @@ -208,7 +208,7 @@ const _composeDevicesString = (devices) => // } // }; -export const runTizenSimOrDevice = async (c, buildCoreWebpackProject) => { +export const runTizenSimOrDevice = async (c: RnvConfig, buildCoreWebpackProject) => { const { hosted } = c.program; const { target, engine } = c.runtime; const { platform } = c; diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts b/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts index ca6e637c24..d6757603dd 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts @@ -80,7 +80,7 @@ const parseDevices = (c: RnvConfig, devicesResponse) => { ); }; -const installAndLaunchApp = async (c, target, appPath, tId) => { +const installAndLaunchApp = async (c: RnvConfig, target, appPath, tId) => { try { await execCLI(c, CLI_WEBOS_ARES_INSTALL, `--device ${target} ${appPath}`); } catch (e) { diff --git a/packages/rnv/src/core/sdkManager/installer.ts b/packages/rnv/src/core/sdkManager/installer.ts index c7576405e7..df87431fc1 100644 --- a/packages/rnv/src/core/sdkManager/installer.ts +++ b/packages/rnv/src/core/sdkManager/installer.ts @@ -197,7 +197,7 @@ const _findFolderWithFile = (dir, fileToFind) => { return foundDir; }; -const _attemptAutoFix = async (c, sdkPlatform, sdkKey, traverseUntilFoundFile) => { +const _attemptAutoFix = async (c: RnvConfig, sdkPlatform, sdkKey, traverseUntilFoundFile) => { logTask('_attemptAutoFix'); if (c.program.hosted) { diff --git a/packages/rnv/src/core/systemManager/logger.ts b/packages/rnv/src/core/systemManager/logger.ts index d9798de2f7..0dbc16eea5 100644 --- a/packages/rnv/src/core/systemManager/logger.ts +++ b/packages/rnv/src/core/systemManager/logger.ts @@ -557,7 +557,7 @@ export const printArrIntoBox = (arr: Array, prefix = '') => { return output; }; -export const printBoxStart = (str: string, str2: string) => { +export const printBoxStart = (str: string, str2?: string) => { let output = _defaultColor('┌──────────────────────────────────────────────────────────────────────────────┐\n'); output += printIntoBox(str); output += printIntoBox(str2 || ''); diff --git a/packages/rnv/src/core/systemManager/npmUtils.ts b/packages/rnv/src/core/systemManager/npmUtils.ts index a9fa8f3081..c4f5223176 100644 --- a/packages/rnv/src/core/systemManager/npmUtils.ts +++ b/packages/rnv/src/core/systemManager/npmUtils.ts @@ -90,7 +90,7 @@ export const checkAndCreateProjectPackage = async (c: RnvConfig) => { export const areNodeModulesInstalled = () => !!doResolve('resolve', false); -export const listAndSelectNpmVersion = async (c, npmPackage) => { +export const listAndSelectNpmVersion = async (c: RnvConfig, npmPackage) => { const templateVersionsStr = await executeAsync(c, `npm view ${npmPackage} versions`); const versionArr = templateVersionsStr.replace(/\r?\n|\r|\s|'|\[|\]/g, '').split(','); @@ -166,7 +166,7 @@ const _getInstallScript = (c) => { export const isYarnInstalled = () => commandExistsSync('yarn') || doResolve('yarn', false); -export const installPackageDependencies = async (c, failOnError = false) => { +export const installPackageDependencies = async (c: RnvConfig, failOnError = false) => { c.runtime.forceBuildHookRebuild = true; const customScript = _getInstallScript(c); diff --git a/packages/rnv/src/core/systemManager/types.ts b/packages/rnv/src/core/systemManager/types.ts index 8998b11f5e..746b324d23 100644 --- a/packages/rnv/src/core/systemManager/types.ts +++ b/packages/rnv/src/core/systemManager/types.ts @@ -15,6 +15,7 @@ export type ExecOptions = { env?: Record; ignoreErrors?: boolean; detached?: boolean; + cwd?: string; }; export type ExecCallback = (isError: boolean) => void; diff --git a/packages/rnv/src/core/taskManager/index.ts b/packages/rnv/src/core/taskManager/index.ts index 166d0368dd..01341dc65a 100644 --- a/packages/rnv/src/core/taskManager/index.ts +++ b/packages/rnv/src/core/taskManager/index.ts @@ -25,7 +25,7 @@ export const registerCustomTask = async (_c: RnvConfig, task: RnvTask) => { } }; -export const initializeTask = async (c, task) => { +export const initializeTask = async (c: RnvConfig, task) => { logTask('initializeTask', task); c.runtime.task = task; executedTasks = {}; @@ -265,7 +265,7 @@ const _populateExtraParameters = (c: RnvConfig, task: RnvTask) => { } }; -const _selectPlatform = async (c, suitableEngines, task) => { +const _selectPlatform = async (c: RnvConfig, suitableEngines, task) => { const supportedPlatforms = {}; suitableEngines.forEach((engine) => { getEngineTask(task, engine.tasks).platforms.forEach((plat) => { @@ -285,7 +285,7 @@ const _selectPlatform = async (c, suitableEngines, task) => { } }; -const _executePipe = async (c, task, phase) => executePipe(c, `${task.split(' ').join(':')}:${phase}`); +const _executePipe = async (c: RnvConfig, task, phase) => executePipe(c, `${task.split(' ').join(':')}:${phase}`); const TASK_LIMIT = 20; @@ -318,7 +318,7 @@ To avoid that test your task code against parentTask and avoid executing same ta logExitTask(`${prt}<= ${task}`); }; -export const executeOrSkipTask = async (c, task, parentTask, originTask) => { +export const executeOrSkipTask = async (c: RnvConfig, task, parentTask, originTask) => { if (!c.program.only) { return executeTask(c, task, parentTask, originTask); } @@ -391,7 +391,7 @@ export const shouldSkipTask = (c: RnvConfig, task, originTask) => { return false; }; -export const executeEngineTask = async (c, task, parentTask, originTask, tasks, isFirstTask) => { +export const executeEngineTask = async (c: RnvConfig, task, parentTask, originTask, tasks, isFirstTask) => { const needsHelp = Object.prototype.hasOwnProperty.call(c.program, 'help'); const t = getEngineTask(task, tasks, CUSTOM_TASKS); diff --git a/packages/rnv/src/core/taskManager/types.ts b/packages/rnv/src/core/taskManager/types.ts index 34ce149b9e..06f4c34d34 100644 --- a/packages/rnv/src/core/taskManager/types.ts +++ b/packages/rnv/src/core/taskManager/types.ts @@ -1,3 +1,5 @@ +import { RnvConfig } from '../configManager/types'; + export type RnvTask = { task: string; params: Array; @@ -5,11 +7,16 @@ export type RnvTask = { }; export type RnvTaskParameter = { - shortcut: string; - value: string; - key: string; - isRequired: boolean; + shortcut?: string; + value?: string; + key?: string; + isRequired?: boolean; description: string; + examples?: Array; + options?: Array; + variadic?: boolean; }; export type RnvTaskMap = Record; + +export type RnvTaskFn = (c: RnvConfig, parentTask: string, originTask: string) => Promise; diff --git a/packages/rnv/src/core/templateManager/index.ts b/packages/rnv/src/core/templateManager/index.ts index 806f2c7140..43d8cb0fd2 100644 --- a/packages/rnv/src/core/templateManager/index.ts +++ b/packages/rnv/src/core/templateManager/index.ts @@ -299,12 +299,12 @@ export const configureEntryPoint = async (c: RnvConfig, platform: string) => { return true; }; -const _writeObjectSync = (c: RnvConfig, p, s) => { +const _writeObjectSync = (c: RnvConfig, p: string, s: string) => { writeFileSync(p, s); generateBuildConfig(c); }; -export const getTemplateOptions = (c: RnvConfig, isGlobalScope) => { +export const getTemplateOptions = (c: RnvConfig, isGlobalScope?: boolean) => { let defaultProjectTemplates; if (isGlobalScope) { defaultProjectTemplates = c.files.rnv.projectTemplates.config.projectTemplates; @@ -328,10 +328,10 @@ export const getInstalledTemplateOptions = (c) => { return []; }; -export const isTemplateInstalled = (c) => +export const isTemplateInstalled = (c: RnvConfig) => c.buildConfig.currentTemplate ? doResolve(c.buildConfig.currentTemplate) : false; -export const applyTemplate = async (c, selectedTemplate) => { +export const applyTemplate = async (c: RnvConfig, selectedTemplate: string) => { logTask('applyTemplate', `${c.buildConfig.currentTemplate}=>${selectedTemplate}`); if (c.files.project.config.isTemplate) return true; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.app.configure.ts b/packages/rnv/src/engine-core/tasks/task.rnv.app.configure.ts index 0a1f2b2732..a66d88de44 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.app.configure.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.app.configure.ts @@ -8,7 +8,7 @@ import { chalk, logError, logTask, logWarning, logDebug, logInfo, logAppInfo } f import { inquirerPrompt } from '../../cli/prompt'; import { RnvConfig } from '../../core/configManager/types'; -const _loadAppConfigIDfromDir = (dirName, appConfigsDir) => { +const _loadAppConfigIDfromDir = (dirName: string, appConfigsDir: string) => { logDebug(`_loadAppConfigIDfromDir:${dirName}:${appConfigsDir}`, chalk().grey); const filePath = path.join(appConfigsDir, 'renative.json'); if (fsExistsSync(filePath)) { @@ -22,7 +22,7 @@ const _loadAppConfigIDfromDir = (dirName, appConfigsDir) => { return { dir: dirName, id: null }; }; -const _askUserAboutConfigs = async (c, dir, id, basePath) => { +const _askUserAboutConfigs = async (c: RnvConfig, dir, id, basePath) => { logTask('_askUserAboutConfigs'); logWarning( `AppConfig error - It seems you have a mismatch between appConfig folder name (${dir}) and the id defined in renative.json (${id}). They must match.` @@ -75,7 +75,7 @@ const _askUserAboutConfigs = async (c, dir, id, basePath) => { }; /* eslint-disable no-await-in-loop */ -const matchAppConfigID = async (c, appConfigID) => { +const matchAppConfigID = async (c: RnvConfig, appConfigID) => { logTask('matchAppConfigID', `appId:${appConfigID}`); if (!appConfigID) return false; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.clean.ts b/packages/rnv/src/engine-core/tasks/task.rnv.clean.ts index b60ceb01b8..5da9ec5838 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.clean.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.clean.ts @@ -6,6 +6,7 @@ import { chalk, logTask, logToSummary, logDebug } from '../../core/systemManager import { executeAsync } from '../../core/systemManager/exec'; import { PARAMS } from '../../core/constants'; import { isSystemWin } from '../../core/systemManager/utils'; +import { RnvConfig } from '../../core/configManager/types'; function clearWindowsCacheFiles() { const opts = { @@ -33,7 +34,7 @@ function clearWindowsCacheFiles() { return true; } -export const taskRnvClean = async (c, skipQuestionParam = false) => { +export const taskRnvClean = async (c: RnvConfig, skipQuestionParam = false) => { logTask('taskRnvClean'); const skipQuestion = c.program.ci ? true : skipQuestionParam; const pathsToRemove = []; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.configureSoft.ts b/packages/rnv/src/engine-core/tasks/task.rnv.configureSoft.ts index fda842b500..925f6a2542 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.configureSoft.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.configureSoft.ts @@ -5,8 +5,9 @@ import { configureRuntimeDefaults } from '../../core/runtimeManager'; import { executeTask } from '../../core/taskManager'; import { TASK_APP_CONFIGURE, TASK_CONFIGURE_SOFT, PARAMS } from '../../core/constants'; import { checkSdk } from '../../core/sdkManager/installer'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvConfigureSoft = async (c, parentTask, originTask) => { +export const taskRnvConfigureSoft: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvConfigureSoft'); await configureRuntimeDefaults(c); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.crypto.decrypt.ts b/packages/rnv/src/engine-core/tasks/task.rnv.crypto.decrypt.ts index 386a6d3aab..e8fe7b5fd1 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.crypto.decrypt.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.crypto.decrypt.ts @@ -14,10 +14,19 @@ import { inquirerPrompt } from '../../cli/prompt'; import { getEnvVar, getEnvExportCmd } from '../../core/systemManager/crypto'; import { executeTask } from '../../core/taskManager'; import { TASK_CRYPTO_DECRYPT, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; +import { RnvConfig } from '../../core/configManager/types'; +import { RnvTaskFn } from '../../core/taskManager/types'; const iocane = require('iocane'); -const _unzipAndCopy = async (c, shouldCleanFolder, destTemp, wsPath, ts, destFolder) => { +const _unzipAndCopy = async ( + c: RnvConfig, + shouldCleanFolder: boolean, + destTemp: string, + wsPath: string, + ts: string, + destFolder: string +) => { if (shouldCleanFolder) { await cleanFolder(wsPath); } @@ -34,7 +43,7 @@ const _unzipAndCopy = async (c, shouldCleanFolder, destTemp, wsPath, ts, destFol logSuccess(`Files succesfully extracted into ${destFolder}`); }; -export const taskRnvCryptoDecrypt = async (c, parentTask, originTask) => { +export const taskRnvCryptoDecrypt: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvCryptoDecrypt'); if (!parentTask) { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts b/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts index 057c97f344..c9538f00ad 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts @@ -16,12 +16,14 @@ import { inquirerPrompt } from '../../cli/prompt'; import { getEnvVar, getEnvExportCmd } from '../../core/systemManager/crypto'; import { executeTask } from '../../core/taskManager'; import { TASK_CRYPTO_ENCRYPT, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; +import { RnvConfig } from '../../core/configManager/types'; +import { RnvTaskFn } from '../../core/taskManager/types'; const iocane = require('iocane'); const readdirAsync = promisify(fsReaddir); -const generateRandomKey = (length) => +const generateRandomKey = (length: number) => Array(length) .fill('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%^&*') .map((x) => x[Math.floor(Math.random() * x.length)]) @@ -115,7 +117,7 @@ ${getEnvExportCmd(envVar, key)} } }; -export const taskRnvCryptoEncrypt = async (c, parentTask, originTask) => { +export const taskRnvCryptoEncrypt: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvCryptoEncrypt'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_CRYPTO_ENCRYPT, originTask); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.doctor.ts b/packages/rnv/src/engine-core/tasks/task.rnv.doctor.ts index 72feb8f21a..b4936bc3d7 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.doctor.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.doctor.ts @@ -8,6 +8,8 @@ import { validateRenativeJsonSchema, // validateRuntimeObjectSchema } from '../../core/schemaManager'; +import { RnvConfig } from '../../core/configManager/types'; +import { RnvTaskFn } from '../../core/taskManager/types'; const configTargets = [ 'workspace.config', @@ -17,7 +19,7 @@ const configTargets = [ 'appConfig.configs', ]; -export const taskRnvDoctor = async (c, parentTask, originTask) => { +export const taskRnvDoctor: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvDoctor'); await configureRuntimeDefaults(c); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.help.ts b/packages/rnv/src/engine-core/tasks/task.rnv.help.ts index 0c7accf06a..dfbce1f94f 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.help.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.help.ts @@ -1,8 +1,9 @@ import { chalk, logToSummary, logTask } from '../../core/systemManager/logger'; import { PARAMS } from '../../core/constants'; import { getRegisteredEngines } from '../../core/engineManager'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvHelp = (c) => { +export const taskRnvHelp: RnvTaskFn = async (c) => { logTask('taskRnvHelp'); // PARAMS diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.hooks.list.ts b/packages/rnv/src/engine-core/tasks/task.rnv.hooks.list.ts index 5fd1e33834..4aa267d450 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.hooks.list.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.hooks.list.ts @@ -3,8 +3,9 @@ import { generateOptions } from '../../cli/prompt'; import { buildHooks } from '../../core/projectManager/buildHooks'; import { executeTask } from '../../core/taskManager'; import { TASK_HOOKS_LIST, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvHooksList = async (c, parentTask, originTask) => { +export const taskRnvHooksList: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvHooksList'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_HOOKS_LIST, originTask); @@ -19,7 +20,7 @@ export const taskRnvHooksList = async (c, parentTask, originTask) => { hooksAsString += `\n${'Pipes:'}\n${pipeOpts.asString}`; } logToSummary(hooksAsString); - return true; + return; } return Promise.reject('Your buildHooks object is empty!'); }; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.hooks.pipes.ts b/packages/rnv/src/engine-core/tasks/task.rnv.hooks.pipes.ts index 1d79774156..4781b0c439 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.hooks.pipes.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.hooks.pipes.ts @@ -4,7 +4,7 @@ import { buildHooks } from '../../core/projectManager/buildHooks'; import { executeTask } from '../../core/taskManager'; import { TASK_HOOKS_PIPES, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; -export const taskRnvHooksPipes = async (c, parentTask, originTask) => { +export const taskRnvHooksPipes = async (c: RnvConfig, parentTask, originTask) => { logTask('taskRnvHooksPipes'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_HOOKS_PIPES, originTask); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.hooks.run.ts b/packages/rnv/src/engine-core/tasks/task.rnv.hooks.run.ts index c48ccd584d..7416fec751 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.hooks.run.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.hooks.run.ts @@ -4,8 +4,9 @@ import { buildHooks } from '../../core/projectManager/buildHooks'; import { executeTask } from '../../core/taskManager'; import { fsExistsSync } from '../../core/systemManager/fileutils'; import { TASK_HOOKS_RUN, TASK_PROJECT_CONFIGURE, PARAMS, PARAM_KEYS } from '../../core/constants'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvHooksRun = async (c, parentTask, originTask) => { +export const taskRnvHooksRun: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvHooksRun'); if (fsExistsSync(c.paths.project.config)) { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.install.ts b/packages/rnv/src/engine-core/tasks/task.rnv.install.ts index 4e358edc61..ad5c56b8fe 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.install.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.install.ts @@ -2,8 +2,9 @@ import { areNodeModulesInstalled } from '../../core/systemManager/npmUtils'; import { PARAMS } from '../../core/constants'; import { installPackageDependenciesAndPlugins } from '../../core/pluginManager'; import { logTask, logInfo } from '../../core/systemManager/logger'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvInstall = async (c, parentTask) => { +export const taskRnvInstall: RnvTaskFn = async (c, parentTask, _) => { logTask('taskRnvInstall', `requiresInstall:${!!c._requiresNpmInstall}:${!c.runtime.skipPackageUpdate}`); if (c.program.only && !!parentTask) return true; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts b/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts index e70540e0f0..50ad74ec13 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts @@ -6,8 +6,9 @@ import { chalk, logTask, logSuccess } from '../../core/systemManager/logger'; import { configureRuntimeDefaults } from '../../core/runtimeManager'; import { PARAMS, TASK_KILL, TASK_APP_CONFIGURE } from '../../core/constants'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvKill = async (c, parentTask, originTask) => { +export const taskRnvKill: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvKill'); const usedPorts = []; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.link.ts b/packages/rnv/src/engine-core/tasks/task.rnv.link.ts index c2e00f76f5..e98cd9c269 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.link.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.link.ts @@ -2,8 +2,10 @@ import path from 'path'; import { logInfo, logTask, logSuccess } from '../../core/systemManager/logger'; import { PARAMS, RNV_PACKAGES } from '../../core/constants'; import { fsExistsSync, fsRenameSync, fsSymlinkSync } from '../../core/systemManager/fileutils'; +import { RnvTaskFn } from '../../core/taskManager/types'; +import { RnvConfig } from '../../core/configManager/types'; -const _linkPackage = (c: RnvConfig, key, folder) => { +const _linkPackage = (c: RnvConfig, key: string, folder: string) => { const rnvPath = path.join(c.paths.project.nodeModulesDir, key); const rnvPathUnlinked = path.join(c.paths.project.nodeModulesDir, `${key}_unlinked`); const pkgDir = path.join(c.paths.rnv.dir, '../', folder); @@ -17,7 +19,7 @@ const _linkPackage = (c: RnvConfig, key, folder) => { } }; -export const taskRnvLink = async (c: RnvConfig) => { +export const taskRnvLink: RnvTaskFn = async (c, _parentTask, _originalTask) => { logTask('taskRnvLink'); RNV_PACKAGES.forEach((pkg) => { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.pkg.ts b/packages/rnv/src/engine-core/tasks/task.rnv.pkg.ts index 7ae78b898b..9e1e39501c 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.pkg.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.pkg.ts @@ -15,7 +15,7 @@ import { PARAMS, TASK_PKG, TASK_PROJECT_CONFIGURE } from '../../core/constants'; import { logError, logTask } from '../../core/systemManager/logger'; import { executeTask } from '../../core/taskManager'; -const bumpVersions = (version) => { +const bumpVersions = (version: string) => { const { project: { dir }, rnv: { pluginTemplates }, @@ -36,7 +36,7 @@ const bumpVersions = (version) => { }); // check if it's our turf and do some extra magic const renativePkgPath = path.join(packagesDir, 'renative'); - if (fsExistsSync(renativePkgPath)) { + if (pluginTemplates.config && fsExistsSync(renativePkgPath)) { copyFileSync(path.join(dir, 'README.md'), path.join(renativePkgPath, 'README.md')); updateObjectSync(pluginTemplates.config, { pluginTemplates: { @@ -66,7 +66,7 @@ const publishAll = () => { return true; }; -export const taskRnvPkg = async (c, parentTask, originTask) => { +export const taskRnvPkg = async (c: RnvConfig, parentTask, originTask) => { logTask('taskRnvPkg'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_PKG, originTask); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.platform.configure.ts b/packages/rnv/src/engine-core/tasks/task.rnv.platform.configure.ts index addacb5573..798c998406 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.platform.configure.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.platform.configure.ts @@ -10,7 +10,7 @@ import { PARAMS, TASK_PLATFORM_CONFIGURE, TASK_PROJECT_CONFIGURE, TASK_INSTALL } import { checkSdk } from '../../core/sdkManager/installer'; -export const taskRnvPlatformConfigure = async (c, parentTask, originTask) => { +export const taskRnvPlatformConfigure = async (c: RnvConfig, parentTask, originTask) => { logTask('taskRnvPlatformConfigure', ''); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_PLATFORM_CONFIGURE, originTask); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.platform.connect.ts b/packages/rnv/src/engine-core/tasks/task.rnv.platform.connect.ts index 5fe32f8ce0..5700017299 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.platform.connect.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.platform.connect.ts @@ -7,7 +7,7 @@ import { generatePlatformChoices } from '../../core/platformManager'; import { executeTask } from '../../core/taskManager'; import { TASK_PROJECT_CONFIGURE, TASK_PLATFORM_CONNECT, PARAMS } from '../../core/constants'; -export const taskRnvPlatformConnect = async (c, parentTask, originTask) => { +export const taskRnvPlatformConnect = async (c: RnvConfig, parentTask, originTask) => { logTask('taskRnvPlatformConnect'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_PLATFORM_CONNECT, originTask); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.platform.eject.ts b/packages/rnv/src/engine-core/tasks/task.rnv.platform.eject.ts index c4b26f2799..f039dc9f2a 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.platform.eject.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.platform.eject.ts @@ -4,12 +4,13 @@ import { writeFileSync } from '../../core/systemManager/fileutils'; import { TASK_PLATFORM_EJECT, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; import { generatePlatformChoices, ejectPlatform } from '../../core/platformManager'; import { executeTask } from '../../core/taskManager'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvPlatformEject = async (c, parentTask, originTask) => { +export const taskRnvPlatformEject: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvPlatformEject'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_PLATFORM_EJECT, originTask); - let selectedPlatforms; + let selectedPlatforms: Array; if (c.platform) { selectedPlatforms = [c.platform]; } else { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.platform.list.ts b/packages/rnv/src/engine-core/tasks/task.rnv.platform.list.ts index 63cf0187ad..0edc55b6ed 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.platform.list.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.platform.list.ts @@ -3,8 +3,9 @@ import { chalk, logToSummary, logTask } from '../../core/systemManager/logger'; import { generatePlatformChoices } from '../../core/platformManager'; import { executeTask } from '../../core/taskManager'; import { TASK_PLATFORM_LIST, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvPlatformList = async (c, parentTask, originTask) => { +export const taskRnvPlatformList: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvPlatformList'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_PLATFORM_LIST, originTask); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.platform.setup.ts b/packages/rnv/src/engine-core/tasks/task.rnv.platform.setup.ts index 7f55ac6753..d8695a3278 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.platform.setup.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.platform.setup.ts @@ -3,8 +3,9 @@ import { TASK_PLATFORM_SETUP, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/ import { updateProjectPlatforms } from '../../core/platformManager'; import { logTask } from '../../core/systemManager/logger'; import { executeTask } from '../../core/taskManager'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvPlatformSetup = async (c, parentTask, originTask) => { +export const taskRnvPlatformSetup: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvPlatformSetup'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_PLATFORM_SETUP, originTask); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.plugin.add.ts b/packages/rnv/src/engine-core/tasks/task.rnv.plugin.add.ts index 8e2632874d..f93aea6c5a 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.plugin.add.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.plugin.add.ts @@ -5,9 +5,10 @@ import { TASK_INSTALL, TASK_PLUGIN_ADD, TASK_PROJECT_CONFIGURE, PARAMS } from '. import { chalk, logSuccess, logTask } from '../../core/systemManager/logger'; import { getPluginList, resolvePluginDependants } from '../../core/pluginManager'; import { executeTask } from '../../core/taskManager'; +import { RnvTaskFn } from '../../core/taskManager/types'; /* eslint-disable no-await-in-loop */ -export const taskRnvPluginAdd = async (c, parentTask, originTask) => { +export const taskRnvPluginAdd: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvPluginAdd'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_PLUGIN_ADD, originTask); @@ -17,7 +18,7 @@ export const taskRnvPluginAdd = async (c, parentTask, originTask) => { const o = getPluginList(c); const selPlugin = selPluginKey && o.allPlugins[selPluginKey]; - const selectedPlugins = {}; + const selectedPlugins: Record = {}; const installMessage = []; if (!selPlugin) { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.plugin.list.ts b/packages/rnv/src/engine-core/tasks/task.rnv.plugin.list.ts index 4d18446d71..887f54af06 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.plugin.list.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.plugin.list.ts @@ -2,8 +2,9 @@ import { logTask, logToSummary } from '../../core/systemManager/logger'; import { getPluginList } from '../../core/pluginManager'; import { executeTask } from '../../core/taskManager'; import { TASK_PLUGIN_LIST, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvPluginList = async (c, parentTask, originTask) => { +export const taskRnvPluginList: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvPluginList'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_PLUGIN_LIST, originTask); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.plugin.update.ts b/packages/rnv/src/engine-core/tasks/task.rnv.plugin.update.ts index 2183997aaa..6a20cf8910 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.plugin.update.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.plugin.update.ts @@ -5,7 +5,7 @@ import { getPluginList } from '../../core/pluginManager'; import { executeTask } from '../../core/taskManager'; import { TASK_PLUGIN_UPDATE, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; -export const taskRnvPluginUpdate = async (c, parentTask, originTask) => { +export const taskRnvPluginUpdate = async (c: RnvConfig, parentTask, originTask) => { logTask('taskRnvPluginUpdate'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_PLUGIN_UPDATE, originTask); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.project.configure.ts b/packages/rnv/src/engine-core/tasks/task.rnv.project.configure.ts index c1643da929..74715c9c09 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.project.configure.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.project.configure.ts @@ -35,7 +35,7 @@ import { import { configureEngines } from '../../core/engineManager'; import { executeTask, initializeTask, findSuitableTask } from '../../core/taskManager'; -export const taskRnvProjectConfigure = async (c, parentTask, originTask) => { +export const taskRnvProjectConfigure = async (c: RnvConfig, parentTask, originTask) => { logTask('taskRnvProjectConfigure'); if (c.paths.project.builds.dir && !fsExistsSync(c.paths.project.builds.dir)) { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.project.upgrade.ts b/packages/rnv/src/engine-core/tasks/task.rnv.project.upgrade.ts index 8b4bfdaf4e..cf0d434ed5 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.project.upgrade.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.project.upgrade.ts @@ -8,7 +8,7 @@ import { listAndSelectNpmVersion } from '../../core/systemManager/npmUtils'; import { installPackageDependenciesAndPlugins } from '../../core/pluginManager'; import { fsExistsSync, readObjectSync } from '../../core/systemManager/fileutils'; -export const taskRnvProjectUpgrade = async (c, parentTask, originTask) => { +export const taskRnvProjectUpgrade = async (c: RnvConfig, parentTask, originTask) => { logTask('taskRnvProjectUpgrade'); const upgradedPaths = []; if (fsExistsSync(c.paths.project.config)) { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.publish.ts b/packages/rnv/src/engine-core/tasks/task.rnv.publish.ts index 5dd5d09ce7..61163cb5eb 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.publish.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.publish.ts @@ -5,8 +5,9 @@ import { logWarning, logTask } from '../../core/systemManager/logger'; import { writeFileSync } from '../../core/systemManager/fileutils'; import { executeTask } from '../../core/taskManager'; import { TASK_PUBLISH, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; +import { RnvTaskFn } from '../../core/taskManager/types'; -const includesPre = (version) => { +const includesPre = (version: string) => { if (version.includes('alpha')) return 'alpha'; if (version.includes('beta')) return 'beta'; if (version.includes('rc')) return 'rc'; @@ -27,7 +28,7 @@ const includesPre = (version) => { * if you are publishing a beta/alpha/rc. That is done automatically by checking if the second arg is alpha, beta, rc. * */ -export const taskRnvPublish = async (c, parentTask, originTask) => { +export const taskRnvPublish: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvPublish'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_PUBLISH, originTask); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.switch.ts b/packages/rnv/src/engine-core/tasks/task.rnv.switch.ts index 3a0266897f..d7c02843ac 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.switch.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.switch.ts @@ -4,7 +4,7 @@ import { generateRuntimeConfig } from '../../core/configManager'; import { executeTask } from '../../core/taskManager'; import { TASK_SWITCH, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; -export const taskRnvSwitch = async (c, parentTask, originTask) => { +export const taskRnvSwitch = async (c: RnvConfig, parentTask, originTask) => { logTask('taskRnvSwitch'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_SWITCH, originTask); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.target.launch.ts b/packages/rnv/src/engine-core/tasks/task.rnv.target.launch.ts index cc4850594d..d778b19543 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.target.launch.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.target.launch.ts @@ -23,7 +23,7 @@ import { launchAppleSimulator } from '../../core/sdkManager/deviceUtils/apple'; import { launchKaiOSSimulator } from '../../core/sdkManager/deviceUtils/kaios'; import { executeTask } from '../../core/taskManager'; -export const taskRnvTargetLaunch = async (c, parentTask, originTask) => { +export const taskRnvTargetLaunch = async (c: RnvConfig, parentTask, originTask) => { logTask('taskRnvTargetLaunch'); await isPlatformSupported(c, true); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.target.list.ts b/packages/rnv/src/engine-core/tasks/task.rnv.target.list.ts index bda0e74b85..52efdd5b6c 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.target.list.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.target.list.ts @@ -22,8 +22,9 @@ import { listAndroidTargets } from '../../core/sdkManager/deviceUtils/android'; import { listAppleDevices } from '../../core/sdkManager/deviceUtils/apple'; import { executeTask } from '../../core/taskManager'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvTargetList = async (c, parentTask, originTask) => { +export const taskRnvTargetList: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvTargetList'); await isPlatformSupported(c, true); @@ -38,12 +39,12 @@ export const taskRnvTargetList = async (c, parentTask, originTask) => { case ANDROID_TV: case FIRE_TV: case ANDROID_WEAR: - return listAndroidTargets(c, platform); + return listAndroidTargets(c); case IOS: case TVOS: return listAppleDevices(c); case TIZEN: - return listTizenTargets(c, platform); + return listTizenTargets(c); case WEBOS: return listWebOSTargets(c); default: diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.template.add.ts b/packages/rnv/src/engine-core/tasks/task.rnv.template.add.ts index b7c51bf5d3..34a4f96e6e 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.template.add.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.template.add.ts @@ -6,13 +6,15 @@ import { executeTask } from '../../core/taskManager'; import { TASK_PROJECT_CONFIGURE, TASK_TEMPLATE_ADD, PARAMS } from '../../core/constants'; import { getTemplateOptions } from '../../core/templateManager'; +import { RnvConfig } from '../../core/configManager/types'; +import { RnvTaskFn } from '../../core/taskManager/types'; -const _writeObjectSync = (c: RnvConfig, p, s) => { +const _writeObjectSync = (c: RnvConfig, p: string, s: string) => { writeFileSync(p, s); generateBuildConfig(c); }; -export const _addTemplate = (c: RnvConfig, template) => { +export const _addTemplate = (c: RnvConfig, template: string) => { logTask('addTemplate'); c.files.project.config.templates = c.files.project.config.templates || {}; @@ -26,7 +28,7 @@ export const _addTemplate = (c: RnvConfig, template) => { _writeObjectSync(c, c.paths.project.config, c.files.project.config); }; -export const taskRnvTemplateAdd = async (c, parentTask, originTask) => { +export const taskRnvTemplateAdd: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvTemplateAdd'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_TEMPLATE_ADD, originTask); @@ -41,6 +43,8 @@ export const taskRnvTemplateAdd = async (c, parentTask, originTask) => { }); _addTemplate(c, template); + + return true; }; export default { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.template.apply.ts b/packages/rnv/src/engine-core/tasks/task.rnv.template.apply.ts index 4a6f1b76c6..47b76fb07f 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.template.apply.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.template.apply.ts @@ -3,8 +3,9 @@ import { logTask } from '../../core/systemManager/logger'; import { applyTemplate, getInstalledTemplateOptions } from '../../core/templateManager'; import { executeTask } from '../../core/taskManager'; import { TASK_TEMPLATE_APPLY, TASK_PROJECT_CONFIGURE, TASK_APP_CONFIGURE, PARAMS } from '../../core/constants'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvTemplateApply = async (c, parentTask, originTask) => { +export const taskRnvTemplateApply: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvTemplateApply', `template: ${c.program.template}`); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_TEMPLATE_APPLY, originTask); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.template.list.ts b/packages/rnv/src/engine-core/tasks/task.rnv.template.list.ts index fbed872833..66e8739a55 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.template.list.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.template.list.ts @@ -2,8 +2,9 @@ import { logToSummary, logTask } from '../../core/systemManager/logger'; import { getTemplateOptions } from '../../core/templateManager'; import { executeTask } from '../../core/taskManager'; import { TASK_TEMPLATE_LIST, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvTemplateList = async (c, parentTask, originTask) => { +export const taskRnvTemplateList: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvTemplateList'); if (c.paths.project.configExists) { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.unlink.ts b/packages/rnv/src/engine-core/tasks/task.rnv.unlink.ts index 1b836840a5..df4e32c7c2 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.unlink.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.unlink.ts @@ -2,8 +2,10 @@ import path from 'path'; import { logInfo, logTask, logSuccess } from '../../core/systemManager/logger'; import { PARAMS, RNV_PACKAGES } from '../../core/constants'; import { fsExistsSync, fsRenameSync, fsUnlinkSync, fsLstatSync } from '../../core/systemManager/fileutils'; +import { RnvTaskFn } from '../../core/taskManager/types'; +import { RnvConfig } from '../../core/configManager/types'; -const _unlinkPackage = (c: RnvConfig, key) => { +const _unlinkPackage = (c: RnvConfig, key: string) => { const rnvPath = path.join(c.paths.project.nodeModulesDir, key); const rnvPathUnlinked = path.join(c.paths.project.nodeModulesDir, `${key}_unlinked`); @@ -20,7 +22,7 @@ const _unlinkPackage = (c: RnvConfig, key) => { } }; -export const taskRnvUnlink = async (c: RnvConfig) => { +export const taskRnvUnlink: RnvTaskFn = async (c) => { logTask('taskRnvUnlink'); RNV_PACKAGES.forEach((pkg) => { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.workspace.add.ts b/packages/rnv/src/engine-core/tasks/task.rnv.workspace.add.ts index 065474240f..304a5488c4 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.workspace.add.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.workspace.add.ts @@ -5,8 +5,9 @@ import { createWorkspace } from '../../core/projectManager/workspace'; import { fsExistsSync } from '../../core/systemManager/fileutils'; import { executeTask } from '../../core/taskManager'; import { TASK_WORKSPACE_ADD, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvWorkspaceAdd = async (c, parentTask, originTask) => { +export const taskRnvWorkspaceAdd: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvWorkspaceAdd'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_WORKSPACE_ADD, originTask); @@ -26,7 +27,7 @@ export const taskRnvWorkspaceAdd = async (c, parentTask, originTask) => { type: 'confirm', message: `Folder ${workspacePath} already exists are you sure you want to override it?`, }); - if (!confirm) return; + if (!confirm) return false; } let workspaceID = workspacePath.split('/').pop().replace(/@|\./g, ''); @@ -39,6 +40,8 @@ export const taskRnvWorkspaceAdd = async (c, parentTask, originTask) => { workspaceID = workspaceIDInput || workspaceID; createWorkspace(c, workspaceID, workspacePath); + + return true; }; export default { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.workspace.configure.ts b/packages/rnv/src/engine-core/tasks/task.rnv.workspace.configure.ts index 25f3c4a875..16cf2ebdd8 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.workspace.configure.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.workspace.configure.ts @@ -8,8 +8,9 @@ import { fsReadFileSync, } from '../../core/systemManager/fileutils'; import { chalk, logTask, logWarning, logDebug, logInfo } from '../../core/systemManager/logger'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvWorkspaceConfigure = async (c: RnvConfig) => { +export const taskRnvWorkspaceConfigure: RnvTaskFn = async (c) => { logTask('taskRnvWorkspaceConfigure'); // Check globalConfig Dir diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.workspace.connect.ts b/packages/rnv/src/engine-core/tasks/task.rnv.workspace.connect.ts index 2700b53f4c..a65957b210 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.workspace.connect.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.workspace.connect.ts @@ -4,7 +4,7 @@ import { getWorkspaceConnectionString } from '../../core/projectManager/workspac import { executeTask } from '../../core/taskManager'; import { TASK_WORKSPACE_CONNECT, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; -export const taskRnvWorkspaceConnect = async (c, parentTask, originTask) => { +export const taskRnvWorkspaceConnect = async (c: RnvConfig, parentTask, originTask) => { logTask('taskRnvWorkspaceConnect'); if (!c.paths.project.configExists) { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.workspace.list.ts b/packages/rnv/src/engine-core/tasks/task.rnv.workspace.list.ts index ae396c0b65..bfc9c192fa 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.workspace.list.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.workspace.list.ts @@ -2,8 +2,9 @@ import { generateOptions } from '../../cli/prompt'; import { chalk, logTask, logToSummary } from '../../core/systemManager/logger'; import { executeTask } from '../../core/taskManager'; import { TASK_WORKSPACE_LIST, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvWorkspaceList = async (c, parentTask, originTask) => { +export const taskRnvWorkspaceList: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvWorkspaceList'); if (c.paths.project.configExists) { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.workspace.update.ts b/packages/rnv/src/engine-core/tasks/task.rnv.workspace.update.ts index 2ae15e067e..6d6b1c591f 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.workspace.update.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.workspace.update.ts @@ -1,8 +1,9 @@ import { logTask } from '../../core/systemManager/logger'; import { executeTask } from '../../core/taskManager'; import { TASK_WORKSPACE_UPDATE, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvWorkspaceUpdate = async (c, parentTask, originTask) => { +export const taskRnvWorkspaceUpdate: RnvTaskFn = async (c, _parentTask, originTask) => { // TODO: taskRnvWorkspaceUpdate logTask('taskRnvWorkspaceUpdate'); From 547f90b55d756ab7e47fe6fb95aa107021df9cbd Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Wed, 30 Aug 2023 00:24:54 +0200 Subject: [PATCH 15/83] add module typings, 1062 togo --- package.json | 8 +++ .../rnv/src/core/platformManager/index.ts | 2 +- packages/rnv/src/core/systemManager/crypto.ts | 4 +- packages/rnv/src/core/systemManager/exec.ts | 2 +- packages/rnv/src/typings/modules.d.ts | 7 ++ yarn.lock | 70 ++++++++++++++++++- 6 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 packages/rnv/src/typings/modules.d.ts diff --git a/package.json b/package.json index 51abf48fa7..5813fb7ee0 100644 --- a/package.json +++ b/package.json @@ -95,6 +95,14 @@ "@flexn/build-hooks-git": "0.1.0", "@types/jest": "~27.0.2", "@types/node": "~16.11.7", + "@types/node-fetch": "2.6.4", + "@types/lodash.set": "4.3.7", + "@types/lodash.get": "4.4.7", + "@types/lodash.intersection": "4.4.7", + "@types/kill-port": "2.0.0", + "@types/tar": "6.1.5", + "@types/shelljs": "0.8.12", + "@types/ncp": "2.0.5", "@typescript-eslint/eslint-plugin": "^5.4.0", "@typescript-eslint/parser": "^5.4.0", "babel-jest": "26.6.3", diff --git a/packages/rnv/src/core/platformManager/index.ts b/packages/rnv/src/core/platformManager/index.ts index d10ec8a406..45963d9b50 100644 --- a/packages/rnv/src/core/platformManager/index.ts +++ b/packages/rnv/src/core/platformManager/index.ts @@ -37,7 +37,7 @@ export const generatePlatformChoices = (c: RnvConfig) => { }; export const cleanPlatformBuild = (c: RnvConfig, platform: string) => - new Promise((resolve) => { + new Promise((resolve) => { logTask('cleanPlatformBuild'); const cleanTasks = []; diff --git a/packages/rnv/src/core/systemManager/crypto.ts b/packages/rnv/src/core/systemManager/crypto.ts index d7d55960b0..52a9158969 100644 --- a/packages/rnv/src/core/systemManager/crypto.ts +++ b/packages/rnv/src/core/systemManager/crypto.ts @@ -14,14 +14,14 @@ export const getEnvExportCmd = (envVar: string, key: string) => { }; export const getEnvVar = (c: RnvConfig) => { - const p1 = c.paths.workspace.dir.split('/').pop().replace('.', ''); + const p1 = c.paths.workspace.dir.split('/').pop()?.replace?.('.', ''); const p2 = c.files.project.package.name.replace('@', '').replace('/', '_').replace(/-/g, '_'); const envVar = `CRYPTO_${p1}_${p2}`.toUpperCase(); logDebug('encrypt looking for env var:', envVar); return envVar; }; -export const checkCrypto = async (c: RnvConfig, parentTask, originTask) => { +export const checkCrypto = async (c: RnvConfig, parentTask: string, originTask: string) => { logTask('checkCrypto'); if (c.program.ci || c.files.project.config?.crypto?.optional) return; diff --git a/packages/rnv/src/core/systemManager/exec.ts b/packages/rnv/src/core/systemManager/exec.ts index 234c69c184..75e9e1da82 100755 --- a/packages/rnv/src/core/systemManager/exec.ts +++ b/packages/rnv/src/core/systemManager/exec.ts @@ -11,7 +11,7 @@ import { chalk, logDebug, logRaw, logError } from './logger'; import { fsExistsSync } from './fileutils'; import { replaceOverridesInString } from './utils'; import { RnvConfig } from '../configManager/types'; -import { ExecCallback, ExecCallback2, ExecOptions, RnvCLI } from './types'; +import { ExecCallback, ExecCallback2, ExecOptions } from './types'; const { exec, execSync } = require('child_process'); diff --git a/packages/rnv/src/typings/modules.d.ts b/packages/rnv/src/typings/modules.d.ts new file mode 100644 index 0000000000..e66125c1c5 --- /dev/null +++ b/packages/rnv/src/typings/modules.d.ts @@ -0,0 +1,7 @@ +declare module 'netcat'; +declare module 'color-string'; +declare module 'detect-port'; +declare module 'ip'; +declare module 'get-installed-path' + +export {} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 2a186415cd..91748a61c3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5039,9 +5039,9 @@ dependencies: "@types/node" "*" -"@types/glob@^7.1.1": +"@types/glob@^7.1.1", "@types/glob@~7.2.0": version "7.2.0" - resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.2.0.tgz#bc1b5bf3aa92f25bd5dd39f35c57361bdce5b2eb" + resolved "https://registry.npmjs.org/@types/glob/-/glob-7.2.0.tgz#bc1b5bf3aa92f25bd5dd39f35c57361bdce5b2eb" integrity sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA== dependencies: "@types/minimatch" "*" @@ -5133,6 +5133,14 @@ dependencies: "@types/node" "*" +"@types/kill-port@2.0.0": + version "2.0.0" + resolved "https://registry.npmjs.org/@types/kill-port/-/kill-port-2.0.0.tgz#ba28034ace13a1444e7a3428c0a487b4e09322f2" + integrity sha512-AegaqABFauES4++49NeNX7TyZJ7t48t10+qJn4QGVGQqDogEk89M0iI4W0HXS+TEUk/hYAtEsgJ+6nyuSyYxlw== + dependencies: + "@types/node" "*" + shell-exec "^1" + "@types/lodash.flattendeep@^4.4.6": version "4.4.7" resolved "https://registry.yarnpkg.com/@types/lodash.flattendeep/-/lodash.flattendeep-4.4.7.tgz#0ce3dccbe006826d58e9824b27df4b00ed3e90e6" @@ -5140,6 +5148,20 @@ dependencies: "@types/lodash" "*" +"@types/lodash.get@4.4.7": + version "4.4.7" + resolved "https://registry.npmjs.org/@types/lodash.get/-/lodash.get-4.4.7.tgz#1ea63d8b94709f6bc9e231f252b31440abe312cf" + integrity sha512-af34Mj+KdDeuzsJBxc/XeTtOx0SZHZNLd+hdrn+PcKGQs0EG2TJTzQAOTCZTgDJCArahlCzLWSy8c2w59JRz7Q== + dependencies: + "@types/lodash" "*" + +"@types/lodash.intersection@4.4.7": + version "4.4.7" + resolved "https://registry.npmjs.org/@types/lodash.intersection/-/lodash.intersection-4.4.7.tgz#fb7850d59e3259238dfe0ecb20952c589dd31dc5" + integrity sha512-7ukD2s54bmRNNpiH9ApEErO4H6mB8+WmXFr/6RpP3e/n7h3UFhEJC7QwLcoWAqOrYCIRFMAAwDf3ambSsW8c5Q== + dependencies: + "@types/lodash" "*" + "@types/lodash.pickby@^4.6.6": version "4.6.7" resolved "https://registry.yarnpkg.com/@types/lodash.pickby/-/lodash.pickby-4.6.7.tgz#fd089a5a7f8cbe7294ae5c90ea5ecd9f4cae4d2c" @@ -5147,6 +5169,13 @@ dependencies: "@types/lodash" "*" +"@types/lodash.set@4.3.7": + version "4.3.7" + resolved "https://registry.npmjs.org/@types/lodash.set/-/lodash.set-4.3.7.tgz#784fccea3fbef4d0949d1897a780f592da700942" + integrity sha512-bS5Wkg/nrT82YUfkNYPSccFrNZRL+irl7Yt4iM6OTSQ0VZJED2oUIVm15NkNtUAQ8SRhCe+axqERUV6MJgkeEg== + dependencies: + "@types/lodash" "*" + "@types/lodash.union@^4.6.6": version "4.6.7" resolved "https://registry.yarnpkg.com/@types/lodash.union/-/lodash.union-4.6.7.tgz#ceace5ed9f3610652ba4a72e0e0afb2a0eec7a4d" @@ -5194,6 +5223,21 @@ resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.31.tgz#31b7ca6407128a3d2bbc27fe2d21b345397f6197" integrity sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA== +"@types/ncp@2.0.5": + version "2.0.5" + resolved "https://registry.npmjs.org/@types/ncp/-/ncp-2.0.5.tgz#5c53b229a321946102a188b603306162137f4fb9" + integrity sha512-ocK0p8JuFmX7UkMabFPjY0F7apPvQyLWt5qtdvuvQEBz9i4m2dbzV+6L1zNaUp042RfnL6pHnxDE53OH6XQ9VQ== + dependencies: + "@types/node" "*" + +"@types/node-fetch@2.6.4": + version "2.6.4" + resolved "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.4.tgz#1bc3a26de814f6bf466b25aeb1473fa1afe6a660" + integrity sha512-1ZX9fcN4Rvkvgv4E6PAY5WXUFWFcRWxZa3EW83UjycOB9ljJCedb2CupIP4RZMEwF/M3eTcCihbBRgwtGbg5Rg== + dependencies: + "@types/node" "*" + form-data "^3.0.0" + "@types/node@*": version "20.3.1" resolved "https://registry.yarnpkg.com/@types/node/-/node-20.3.1.tgz#e8a83f1aa8b649377bb1fb5d7bac5cb90e784dfe" @@ -5385,6 +5429,14 @@ "@types/mime" "*" "@types/node" "*" +"@types/shelljs@0.8.12": + version "0.8.12" + resolved "https://registry.npmjs.org/@types/shelljs/-/shelljs-0.8.12.tgz#79dc9632af7d5ca1b5afb65a6bfc1422d79b5fa0" + integrity sha512-ZA8U81/gldY+rR5zl/7HSHrG2KDfEb3lzG6uCUDhW1DTQE9yC/VBQ45fXnXq8f3CgInfhZmjtdu/WOUlrXRQUg== + dependencies: + "@types/glob" "~7.2.0" + "@types/node" "*" + "@types/shimmer@^1.0.2": version "1.0.2" resolved "https://registry.yarnpkg.com/@types/shimmer/-/shimmer-1.0.2.tgz#93eb2c243c351f3f17d5c580c7467ae5d686b65f" @@ -5424,6 +5476,14 @@ resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.8.tgz#b94a4391c85666c7b73299fd3ad79d4faa435310" integrity sha512-ipixuVrh2OdNmauvtT51o3d8z12p6LtFW9in7U79der/kwejjdNchQC5UMn5u/KxNoM7VHHOs/l8KS8uHxhODQ== +"@types/tar@6.1.5": + version "6.1.5" + resolved "https://registry.npmjs.org/@types/tar/-/tar-6.1.5.tgz#90ccb3b6a35430e7427410d50eed564e85feaaff" + integrity sha512-qm2I/RlZij5RofuY7vohTpYNaYcrSQlN2MyjucQc7ZweDwaEWkdN/EeNh6e9zjK6uEm6PwjdMXkcj05BxZdX1Q== + dependencies: + "@types/node" "*" + minipass "^4.0.0" + "@types/through@*": version "0.0.30" resolved "https://registry.yarnpkg.com/@types/through/-/through-0.0.30.tgz#e0e42ce77e897bd6aead6f6ea62aeb135b8a3895" @@ -23182,6 +23242,11 @@ shell-exec@1.0.2: resolved "https://registry.yarnpkg.com/shell-exec/-/shell-exec-1.0.2.tgz#2e9361b0fde1d73f476c4b6671fa17785f696756" integrity sha512-jyVd+kU2X+mWKMmGhx4fpWbPsjvD53k9ivqetutVW/BQ+WIZoDoP4d8vUMGezV6saZsiNoW2f9GIhg9Dondohg== +shell-exec@^1: + version "1.1.2" + resolved "https://registry.npmjs.org/shell-exec/-/shell-exec-1.1.2.tgz#d4056f96638d8406c8ab498f9f8b28938eba2dd0" + integrity sha512-v2NWVDP0ws+S7miKy2oSpJ/OuL6NKuMosPNUZLDWFBlMnBtuoZxZOwxpQJwhsFZgMb+r7frpDTT8p4OSnhkpsg== + shell-quote@1.7.3, shell-quote@^1.4.3, shell-quote@^1.6.1, shell-quote@^1.7.2, shell-quote@^1.7.3: version "1.7.3" resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.7.3.tgz#aa40edac170445b9a431e17bb62c0b881b9c4123" @@ -26384,6 +26449,7 @@ workerpool@6.2.0: integrity sha512-Rsk5qQHJ9eowMH28Jwhe8HEbmdYDX4lwoMWshiCXugjtHqMD9ZbiqSDLxcsfdqsETPzVUtX5s1Z5kStiIM6l4A== "wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: + name wrap-ansi-cjs version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== From c48e60004f82f8c4c0c691d7325288d2d22f2182 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Wed, 30 Aug 2023 01:42:59 +0200 Subject: [PATCH 16/83] more ts refactor, 1029 togo --- packages/rnv/src/cli/types.ts | 3 +- packages/rnv/src/core/common.ts | 29 +++++---- packages/rnv/src/core/configManager/types.ts | 41 +++++++++---- packages/rnv/src/core/engineManager/index.ts | 5 +- packages/rnv/src/core/engineManager/types.ts | 4 ++ .../rnv/src/core/platformManager/index.ts | 2 +- .../src/core/sdkManager/deviceUtils/apple.ts | 5 +- .../src/core/sdkManager/deviceUtils/common.ts | 3 +- packages/rnv/src/core/setupManager/base.ts | 13 ++-- packages/rnv/src/core/setupManager/linux.ts | 3 +- .../rnv/src/core/systemManager/fileutils.ts | 60 ++++++++++--------- .../rnv/src/core/systemManager/npmUtils.ts | 1 + .../rnv/src/core/systemManager/objectUtils.ts | 26 ++++---- .../rnv/src/core/systemManager/resolve.ts | 17 ++++-- packages/rnv/src/core/systemManager/types.ts | 21 +++++++ packages/rnv/src/core/taskManager/index.ts | 13 ++-- packages/rnv/src/core/taskManager/types.ts | 1 + .../rnv/src/core/templateManager/index.ts | 4 +- .../src/engine-core/tasks/task.rnv.config.ts | 5 +- .../tasks/task.rnv.crypto.decrypt.ts | 2 +- .../tasks/task.rnv.crypto.encrypt.ts | 2 +- .../src/engine-core/tasks/task.rnv.kill.ts | 9 ++- .../tasks/task.rnv.project.configure.ts | 3 +- packages/rnv/src/typings/modules.d.ts | 1 + 24 files changed, 177 insertions(+), 96 deletions(-) diff --git a/packages/rnv/src/cli/types.ts b/packages/rnv/src/cli/types.ts index be1597f6e0..1cab8c2e35 100644 --- a/packages/rnv/src/cli/types.ts +++ b/packages/rnv/src/cli/types.ts @@ -16,6 +16,7 @@ export type PromptParams = { name: string; type: string; pageSize?: number; + validate?: (i: string) => string; }; -export type PromptRenderFn = (i: number, obj, mapping, defaultVal) => string; +export type PromptRenderFn = (i: number, obj: any, mapping: any, defaultVal: string) => string; diff --git a/packages/rnv/src/core/common.ts b/packages/rnv/src/core/common.ts index 8be355583f..8f8502ded7 100755 --- a/packages/rnv/src/core/common.ts +++ b/packages/rnv/src/core/common.ts @@ -8,7 +8,7 @@ import path from 'path'; import { inquirerPrompt } from '../cli/prompt'; import { CLI_PROPS } from './constants'; import { fsExistsSync, writeCleanFile } from './systemManager/fileutils'; -import { chalk, logDebug, logError, logSuccess, logTask, logWarning } from './systemManager/logger'; +import { chalk, logError, logTask, logWarning } from './systemManager/logger'; import { getValidLocalhost } from './systemManager/utils'; import { RenativeConfigBuildScheme, RenativeConfigFile, RnvConfig } from './configManager/types'; @@ -49,7 +49,7 @@ export const addSystemInjects = (c: RnvConfig, injects: Array) => { } }; -export const sanitizeColor = (val, key) => { +export const sanitizeColor = (val: string, key: string) => { if (!val) { logWarning(`You are missing ${chalk().white(key)} in your renative config. will use default #FFFFFF instead`); return { @@ -64,7 +64,7 @@ export const sanitizeColor = (val, key) => { return { rgb, - rgbDecimal: rgb.map((v) => (v > 1 ? Math.round((v / 255) * 10) / 10 : v)), + rgbDecimal: rgb.map((v: number) => (v > 1 ? Math.round((v / 255) * 10) / 10 : v)), hex, }; }; @@ -278,7 +278,7 @@ export const _getConfigProp = ( const p = sourceObj.platforms?.[platform]; const ps = c.runtime.scheme; const keyArr = key.split('.'); - const baseKey = keyArr.shift(); + const baseKey = keyArr.shift() || ''; const subKey = keyArr.join('.'); let resultPlatforms; @@ -469,7 +469,7 @@ export const getMonorepoRoot = () => { } }; -export const getBuildsFolder = (c: RnvConfig, platform: string, customPath: string) => { +export const getBuildsFolder = (c: RnvConfig, platform: string, customPath?: string) => { const pp = customPath || c.paths.appConfig.dir; // if (!fsExistsSync(pp)) { // logWarning(`Path ${chalk().white(pp)} does not exist! creating one for you..`); @@ -495,7 +495,7 @@ export const checkPortInUse = (c: RnvConfig, platform: string, port: string) => resolve(false); return; } - detectPort(port, (err, availablePort) => { + detectPort(port, (err: string, availablePort: string) => { if (err) { reject(err); return; @@ -516,11 +516,20 @@ export const getBuildFilePath = (c: RnvConfig, platform: string, filePath: strin // P1 => platformTemplates let sp = path.join(getAppTemplateFolder(c, platform), filePath); // P2 => appConfigs/base + @buildSchemes - const sp2 = path.join(getBuildsFolder(c, platform, c.paths.project.appConfigBase.dir), filePath); - if (fsExistsSync(sp2)) sp = sp2; + const sp2bf = getBuildsFolder(c, platform, c.paths.project.appConfigBase.dir); + if (sp2bf) { + const sp2 = path.join(sp2bf, filePath); + if (fsExistsSync(sp2)) sp = sp2; + } + // P3 => appConfigs + @buildSchemes - const sp3 = path.join(getBuildsFolder(c, platform), filePath); - if (fsExistsSync(sp3)) sp = sp3; + const sp3bf = getBuildsFolder(c, platform); + + if (sp3bf) { + const sp3 = path.join(sp3bf, filePath); + if (fsExistsSync(sp3)) sp = sp3; + } + return sp; }; diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index e3caf2e584..abac80dbd8 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -1,14 +1,22 @@ +import { RnvEngine } from '../engineManager/types'; +import { RnvPlatform } from '../types'; + export interface RnvConfig { program: any; - command: string; - subCommand: string; - buildConfig: any; - platform: string; + command: string | null; + subCommand: string | null; + buildConfig: RenativeConfigFile & { + _meta: { + currentAppConfigId: string; + }; + }; + platform: RnvPlatform; process: any; rnvVersion: string; _currentTask?: string; systemPropsInjects: Array; _requiresNpmInstall?: boolean; + buildPipes: Record Promise>>; //======= _renativePluginCache: any; cli: any; @@ -24,13 +32,9 @@ export interface RnvConfig { runtime: { appId: string | null; appDir: string; - enginesByPlatform: any; - enginesByIndex: Array<{ - config: { - id: string; - }; - }>; - enginesById: Record; + enginesByPlatform: Record; + enginesByIndex: Array; + enginesById: Record; missingEnginePlugins: Record; localhost: string; scheme: string; @@ -52,6 +56,8 @@ export interface RnvConfig { hasAllEnginesRegistered: boolean; skipPackageUpdate?: boolean; selectedTemplate?: string; + runtimeExtraProps: string; + requiresBootstrap: boolean; }; paths: { GLOBAL_RNV_CONFIG: string; @@ -178,6 +184,7 @@ export interface RnvConfig { assets: Record; platformTemplates: Record; appConfigsDir: string; + configTemplate: string; }; appConfigBase: string; }; @@ -289,15 +296,27 @@ export interface RnvConfigFileObj { } export type RenativeConfigFile = { + workspaceID: string; common: { buildSchemes: Record; }; + defaults: { + ports: Record; + }; platforms: Record< string, { buildSchemes: Record; + entryFile?: string; } >; + templates: Record; + currentTemplate: string; + projectTemplates: object; + paths: { + appConfigsDirs: Array; + }; + integrations: Record; }; export type RenativeConfigBuildScheme = Record; diff --git a/packages/rnv/src/core/engineManager/index.ts b/packages/rnv/src/core/engineManager/index.ts index c4d0b19a2e..fe6396a79b 100644 --- a/packages/rnv/src/core/engineManager/index.ts +++ b/packages/rnv/src/core/engineManager/index.ts @@ -555,7 +555,8 @@ export const getEngineRunner = (c: RnvConfig, task: string, customTasks?: RnvTas } const { configExists } = c.paths.project; - let engine = c.runtime.enginesByPlatform[c.platform]; + + let engine = typeof c.platform === 'string' && c.runtime.enginesByPlatform[c.platform]; if (!engine) { engine = c.runtime.enginesById['engine-core']; } @@ -577,4 +578,4 @@ export const getEngineRunner = (c: RnvConfig, task: string, customTasks?: RnvTas return null; }; -export const getRegisteredEngines = (c) => c.runtime.enginesByIndex; +export const getRegisteredEngines = (c: RnvConfig) => c.runtime.enginesByIndex; diff --git a/packages/rnv/src/core/engineManager/types.ts b/packages/rnv/src/core/engineManager/types.ts index 6ab562a769..34a24854e2 100644 --- a/packages/rnv/src/core/engineManager/types.ts +++ b/packages/rnv/src/core/engineManager/types.ts @@ -1,3 +1,7 @@ +export type RnvEngine = { + config: RnvEngineConfig; +}; + export type RnvEngineConfig = { id: string; }; diff --git a/packages/rnv/src/core/platformManager/index.ts b/packages/rnv/src/core/platformManager/index.ts index 45963d9b50..87c7350ef8 100644 --- a/packages/rnv/src/core/platformManager/index.ts +++ b/packages/rnv/src/core/platformManager/index.ts @@ -60,7 +60,7 @@ export const cleanPlatformBuild = (c: RnvConfig, platform: string) => }); export const createPlatformBuild = (c: RnvConfig, platform: string) => - new Promise((resolve, reject) => { + new Promise((resolve, reject) => { logTask('createPlatformBuild'); if (!isPlatformSupportedSync(c, platform, null, reject)) return; diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts b/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts index 8a662d1daa..74b96f2c23 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts @@ -25,7 +25,8 @@ export const getAppleDevices = async (c: RnvConfig, ignoreDevices?: boolean, ign // xcode < 13 devicesAndSims = await executeAsync('xcrun instruments -s'); } - const simctl = JSON.parse(await executeAsync('xcrun simctl list --json')); + const res = await executeAsync('xcrun simctl list --json'); + const simctl = JSON.parse(res.toString()); const availableSims = []; Object.keys(simctl.devices).forEach((runtime) => { logDebug('runtime', runtime); @@ -170,7 +171,7 @@ const _parseIOSDevicesList = (rawDevices, platform, ignoreDevices = false, ignor return devices; }; -export const launchAppleSimulator = async (c: RnvConfig, target) => { +export const launchAppleSimulator = async (c: RnvConfig, target: string) => { logTask('launchAppleSimulator', `${target}`); const devicesArr = await getAppleDevices(c, true); diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/common.ts b/packages/rnv/src/core/sdkManager/deviceUtils/common.ts index fe5d6e0910..42a824941d 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/common.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/common.ts @@ -1,7 +1,8 @@ import ora from '../../../cli/ora'; +import { RnvConfig } from '../../configManager/types'; import { execCLI } from '../../systemManager/exec'; -export const waitForEmulator = async (c, cli, command, callback) => { +export const waitForEmulator = async (c: RnvConfig, cli: string, command: string, callback) => { let attempts = 0; const maxAttempts = 30; const CHECK_INTEVAL = 2000; diff --git a/packages/rnv/src/core/setupManager/base.ts b/packages/rnv/src/core/setupManager/base.ts index d92dd6f57d..d1372628a1 100644 --- a/packages/rnv/src/core/setupManager/base.ts +++ b/packages/rnv/src/core/setupManager/base.ts @@ -17,8 +17,11 @@ class BasePlatformSetup { globalConfigPath: string; availableDownloader: string | null; androidSdkLocation: string; + sdksToInstall: string; + webosSdkPath?: string; + tizenSdkPath?: string; - constructor(os: string, c: RnvConfig) { + constructor(os: string, c?: RnvConfig) { // eslint-disable-next-line no-param-reassign if (!c) c = Config.getConfig(); const { paths } = c; @@ -49,7 +52,7 @@ class BasePlatformSetup { return true; } - async postInstall(sdk) { + async postInstall(sdk: string) { if (sdk === 'android') { const { location } = setupConfig.android; await updateConfigFile({ androidSdk: location }, this.globalConfigPath); @@ -67,7 +70,7 @@ class BasePlatformSetup { } } - async downloadSdk(sdk) { + async downloadSdk(sdk: string) { const downloader = this.availableDownloader; if (!downloader) throw new Error('Wget or cURL not installed!'); logDebug(`Downloading ${sdk} SDK to ${setupConfig[sdk].downloadLocation} using ${downloader}`); @@ -163,13 +166,13 @@ class BasePlatformSetup { logError( 'Install fastlane not supported yet. Follow https://docs.fastlane.tools/getting-started/ios/setup/ to install it manually' ); - return true; + return; } async installDocker() { // to be overwritten logError('Install docker not supported yet'); - return true; + return; } async installAws() { diff --git a/packages/rnv/src/core/setupManager/linux.ts b/packages/rnv/src/core/setupManager/linux.ts index b0b61771a0..f7eeaaa864 100644 --- a/packages/rnv/src/core/setupManager/linux.ts +++ b/packages/rnv/src/core/setupManager/linux.ts @@ -7,9 +7,10 @@ import BasePlatformSetup from './base'; import { updateConfigFile, getRealPath } from '../systemManager/fileutils'; import setupConfig from './config'; import { CLI_ANDROID_ADB, CLI_ANDROID_AVDMANAGER, CLI_ANDROID_EMULATOR, CLI_ANDROID_SDKMANAGER } from '../constants'; +import { RnvConfig } from '../configManager/types'; class LinuxPlatformSetup extends BasePlatformSetup { - constructor(c) { + constructor(c: RnvConfig) { super('linux', c); } diff --git a/packages/rnv/src/core/systemManager/fileutils.ts b/packages/rnv/src/core/systemManager/fileutils.ts index 62f6aabb25..a6982c9ea7 100755 --- a/packages/rnv/src/core/systemManager/fileutils.ts +++ b/packages/rnv/src/core/systemManager/fileutils.ts @@ -7,7 +7,7 @@ import merge from 'deepmerge'; import ncp from 'ncp'; import { chalk, logDebug, logError, logWarning } from './logger'; import { RnvConfig } from '../configManager/types'; -import { OverridesOptions, TimestampPathsConfig } from './types'; +import { FileUtilsPropConfig, FileUtilsUpdateConfig, OverridesOptions, TimestampPathsConfig } from './types'; export const configureFilesystem = (_getConfigProp: () => string, _doResolve: () => any, _isSystemWin: boolean) => { global.getConfigProp = _getConfigProp; @@ -144,7 +144,7 @@ export const writeCleanFile = (source: string, destination: string, overrides, t } }; -export const readCleanFile = (source: string, overrides: OverridesOptions) => { +export const readCleanFile = (source: string, overrides?: OverridesOptions) => { // logTask(`writeCleanFile`) // console.log('readCleanFile', source); if (!fs.existsSync(source)) { @@ -168,9 +168,9 @@ export const copyFileWithInjectSync = ( source: string, target: string, skipOverride: boolean, - injectObject: object | null, - timestampPathsConfig, - c: RnvConfig + injectObject?: OverridesOptions, + timestampPathsConfig?: TimestampPathsConfig, + c?: RnvConfig ) => { logDebug('copyFileWithInjectSync', source); @@ -212,10 +212,10 @@ export const copyFolderRecursiveSync = ( target: string, convertSvg = true, skipOverride: boolean, - injectObject = null, - timestampPathsConfig = null, - c: RnvConfig, - extFilter: Array | null = null + injectObject?: OverridesOptions, + timestampPathsConfig?: TimestampPathsConfig, + c?: RnvConfig, + extFilter?: Array ) => { logDebug('copyFolderRecursiveSync', source, target); if (!fs.existsSync(source)) return; @@ -260,17 +260,18 @@ export const copyFolderRecursiveSync = ( }; export const copyFolderContentsRecursiveSync = ( - source: string, + source: string | null, target: string, convertSvg = true, skipPaths?: Array, skipOverride?: boolean, - injectObject: object | null = null, - timestampPathsConfig = null, + injectObject?: OverridesOptions, + timestampPathsConfig?: TimestampPathsConfig, c?: RnvConfig, - extFilter: Array | null = null + extFilter?: Array ) => { logDebug('copyFolderContentsRecursiveSync', source, target, skipPaths); + if (!source) return; if (!fs.existsSync(source)) return; let files = []; const targetFolder = path.join(target); @@ -287,7 +288,7 @@ export const copyFolderContentsRecursiveSync = ( curSource, targetFolder, convertSvg, - skipOverride, + skipOverride || false, injectObject, timestampPathsConfig, c, @@ -297,7 +298,7 @@ export const copyFolderContentsRecursiveSync = ( copyFileWithInjectSync( curSource, targetFolder, - skipOverride, + skipOverride || false, injectObject, timestampPathsConfig, c @@ -341,7 +342,7 @@ export const saveAsJs = (source: string, dest: string) => { }); }; -export const removeDir = (pth: string, callback) => { +export const removeDir = (pth: string, callback: () => void) => { rimraf(pth, callback); }; @@ -385,7 +386,7 @@ export const removeDirsSync = (dirPaths: Array) => { for (let i = 0; i < dirPaths.length; i++) { try { removeDirSync(dirPaths[i]); - } catch (e) { + } catch (e: any) { logError(e); } } @@ -444,7 +445,7 @@ export const removeDirSync = (_dir: string, _rmSelf?: boolean) => { } }; -export const writeFileSync = (filePath: string, obj, spaces = 4, addNewLine = true) => { +export const writeFileSync = (filePath: string, obj: string | object, spaces = 4, addNewLine = true) => { logDebug('writeFileSync', filePath); if (filePath.includes('?') || filePath.includes('undefined')) return; let output; @@ -461,7 +462,7 @@ export const writeFileSync = (filePath: string, obj, spaces = 4, addNewLine = tr return output; }; -export const writeObjectSync = (filePath: string, obj, spaces, addNewLine = true) => { +export const writeObjectSync = (filePath: string, obj: string | object, spaces: number, addNewLine = true) => { logDebug('writeObjectSync', filePath); logWarning('writeObjectSync is DEPRECATED. use writeFileSync instead'); return writeFileSync(filePath, obj, spaces, addNewLine); @@ -487,10 +488,10 @@ export const readObjectSync = (filePath: string, sanitize?: boolean, c?: RnvConf } if (obj._refs) { obj = sanitizeDynamicProps(obj, { - files: c.files, - runtimeProps: c.runtime, + files: c?.files, + runtimeProps: c?.runtime, props: obj._refs, - configProps: c.configPropsInjects, + configProps: c?.configPropsInjects, }); } } @@ -501,8 +502,8 @@ export const readObjectSync = (filePath: string, sanitize?: boolean, c?: RnvConf return obj; }; -export const updateObjectSync = (filePath: string, updateObj) => { - let output; +export const updateObjectSync = (filePath: string, updateObj: object) => { + let output: object; const obj = readObjectSync(filePath); if (obj) { output = merge(obj, updateObj); @@ -604,7 +605,7 @@ export const resolvePackage = (text: string) => { return newText; }; -export const sanitizeDynamicProps = (obj: any, propConfig) => { +export const sanitizeDynamicProps = (obj: Record, propConfig: FileUtilsPropConfig) => { if (!obj) { return obj; } @@ -645,7 +646,12 @@ const BIND_CONFIG_PROPS = '{{configProps.'; const BIND_RUNTIME_PROPS = '{{runtimeProps.'; const BIND_ENV = '{{env.'; -const _bindStringVals = (obj, _val, newKey, propConfig) => { +const _bindStringVals = ( + obj: Record, + _val: string, + newKey: string, + propConfig: FileUtilsPropConfig +) => { const { props = {}, configProps = {}, runtimeProps = {} } = propConfig; let val = _val; if (val.includes(BIND_FILES)) { @@ -682,7 +688,7 @@ export const mergeObjects = (c: RnvConfig, obj1: any, obj2: any, dynamicRefs = t return dynamicRefs ? sanitizeDynamicRefs(c, obj) : obj; }; -export const updateConfigFile = async (update, globalConfigPath: string) => { +export const updateConfigFile = async (update: FileUtilsUpdateConfig, globalConfigPath: string) => { const configContents = JSON.parse(fs.readFileSync(globalConfigPath).toString()); if (update.androidSdk) { diff --git a/packages/rnv/src/core/systemManager/npmUtils.ts b/packages/rnv/src/core/systemManager/npmUtils.ts index c4f5223176..7a1bf38a1b 100644 --- a/packages/rnv/src/core/systemManager/npmUtils.ts +++ b/packages/rnv/src/core/systemManager/npmUtils.ts @@ -17,6 +17,7 @@ import { doResolve } from './resolve'; import { inquirerPrompt } from '../../cli/prompt'; import { getConfigProp } from '../common'; +import { RnvConfig } from '../configManager/types'; const packageJsonIsValid = (c) => { if (!fsExistsSync(c.paths.project.package)) return false; diff --git a/packages/rnv/src/core/systemManager/objectUtils.ts b/packages/rnv/src/core/systemManager/objectUtils.ts index 222c1c6120..72c8a481d5 100644 --- a/packages/rnv/src/core/systemManager/objectUtils.ts +++ b/packages/rnv/src/core/systemManager/objectUtils.ts @@ -1,28 +1,28 @@ -const isObject = (value) => value && typeof value === 'object' && value.constructor === Object; +const isObject = (value: any) => value && typeof value === 'object' && value.constructor === Object; -const isArray = (value) => value && typeof value === 'object' && value.constructor === Array; +const isArray = (value: any) => value && typeof value === 'object' && value.constructor === Array; -const isString = (value) => typeof value === 'string' || value instanceof String; +const isString = (value: any) => typeof value === 'string' || value instanceof String; -const isNumber = (value) => typeof value === 'number' && Number.isFinite(value); +const isNumber = (value: any) => typeof value === 'number' && Number.isFinite(value); -const isFunction = (value) => typeof value === 'function'; +const isFunction = (value: any) => typeof value === 'function'; -const isBool = (value) => typeof value === 'boolean'; +const isBool = (value: any) => typeof value === 'boolean'; -const isNull = (value) => value === null; +const isNull = (value: any) => value === null; -const isUndefined = (value) => typeof value === 'undefined'; +const isUndefined = (value: any) => typeof value === 'undefined'; -const isRegExp = (value) => value && typeof value === 'object' && value.constructor === RegExp; +const isRegExp = (value: any) => value && typeof value === 'object' && value.constructor === RegExp; -const isError = (value) => value instanceof Error && typeof value.message !== 'undefined'; +const isError = (value: any) => value instanceof Error && typeof value.message !== 'undefined'; -const isDate = (value) => value instanceof Date; +const isDate = (value: any) => value instanceof Date; -const isSymbol = (value) => typeof value === 'symbol'; +const isSymbol = (value: any) => typeof value === 'symbol'; -const isLikeNull = (value) => isNull(value) || isUndefined(value); +const isLikeNull = (value: any) => isNull(value) || isUndefined(value); export { isObject, diff --git a/packages/rnv/src/core/systemManager/resolve.ts b/packages/rnv/src/core/systemManager/resolve.ts index 7bf1ad1da3..deff87836c 100644 --- a/packages/rnv/src/core/systemManager/resolve.ts +++ b/packages/rnv/src/core/systemManager/resolve.ts @@ -1,6 +1,7 @@ import resolve from 'resolve'; import fs from 'fs'; import path from 'path'; +import { ResolveOptions } from './types'; /** * An attempt at drying out filesystem references to [external packages](https://tinyurl.com/mao2dy6). * @@ -17,27 +18,31 @@ import path from 'path'; * @param {*} mandatory - whether it throws * @param {*} options - docs - https://tinyurl.com/r9sfpf7 && {keepSuffix: boolean} */ -export const doResolve = (aPath: string, mandatory = true, options = {}) => { +export const doResolve = (aPath: string, mandatory = true, options: ResolveOptions = {}) => { options.basedir = options.basedir ?? process.cwd(); try { if (aPath.startsWith('file:')) { return _withPathFix(_doResolveFSPath(aPath, options), options?.forceForwardPaths); } - return _withPathFix(_doResolveExternalPackage(aPath, options), options?.forceForwardPaths); + const pth = _doResolveExternalPackage(aPath, options); + if (pth) { + return _withPathFix(pth, options?.forceForwardPaths); + } + return undefined; } catch (err) { // perhaps do some warning logging here.. if (mandatory) throw err; } }; -const _withPathFix = (p, forceForwardPaths) => { +const _withPathFix = (p: string, forceForwardPaths?: boolean) => { if (p && forceForwardPaths) { return p.replace(/\\/g, '/'); } return p; }; -export const doResolvePath = (aPath, mandatory = true, options = {}, fallbackBase = '') => { +export const doResolvePath = (aPath: string, mandatory = true, options: ResolveOptions = {}, fallbackBase = '') => { options.basedir = options.basedir ?? process.cwd(); try { @@ -94,7 +99,7 @@ const _getPackagePathParts = (aPath: string) => { /** * We support path linking using 'file:' protocol (not part of official node resolution alg.) */ -const _doResolveFSPath = (aPath: string, options) => { +const _doResolveFSPath = (aPath: string, options: ResolveOptions) => { const fileRelPath = `${options.basedir ? `${options.basedir}/`.replace(/.*\/+$/, '/') : ''}${aPath.replace( 'file:', '' @@ -108,7 +113,7 @@ const _doResolveFSPath = (aPath: string, options) => { /** * @see 'LOAD_NODE_MODULES' of node resolution alg. - https://tinyurl.com/pgz6f33 */ -const _doResolveExternalPackage = (aPath: string, options) => { +const _doResolveExternalPackage = (aPath: string, options: ResolveOptions) => { const [packageBase, packageSuffix] = _getPackagePathParts(aPath); try { diff --git a/packages/rnv/src/core/systemManager/types.ts b/packages/rnv/src/core/systemManager/types.ts index 746b324d23..b05620dfda 100644 --- a/packages/rnv/src/core/systemManager/types.ts +++ b/packages/rnv/src/core/systemManager/types.ts @@ -16,6 +16,14 @@ export type ExecOptions = { ignoreErrors?: boolean; detached?: boolean; cwd?: string; + timeout?: number; +}; + +export type ResolveOptions = { + basedir?: string; + forceForwardPaths?: boolean; + extensions?: Array; + keepSuffix?: boolean; }; export type ExecCallback = (isError: boolean) => void; @@ -37,3 +45,16 @@ export type TimestampPathsConfig = { }; export type RnvCLI = Record; + +export type FileUtilsPropConfig = { + props: Record; + configProps?: Record; + runtimeProps?: Record; + files: Array; +}; + +export type FileUtilsUpdateConfig = { + androidSdk: string; + tizenSdk: string; + webosSdk: string; +}; diff --git a/packages/rnv/src/core/taskManager/index.ts b/packages/rnv/src/core/taskManager/index.ts index 01341dc65a..48f87b342a 100644 --- a/packages/rnv/src/core/taskManager/index.ts +++ b/packages/rnv/src/core/taskManager/index.ts @@ -60,10 +60,10 @@ const _getTaskObj = (taskInstance) => { }; }; -export const findSuitableTask = async (c: RnvConfig, specificTask) => { +export const findSuitableTask = async (c: RnvConfig, specificTask?: string) => { logTask('findSuitableTask'); const REGISTERED_ENGINES = getRegisteredEngines(c); - let task; + let task: string; if (!specificTask) { if (!c.command) { const suitableTaskInstances = {}; @@ -265,7 +265,7 @@ const _populateExtraParameters = (c: RnvConfig, task: RnvTask) => { } }; -const _selectPlatform = async (c: RnvConfig, suitableEngines, task) => { +const _selectPlatform = async (c: RnvConfig, suitableEngines, task: string) => { const supportedPlatforms = {}; suitableEngines.forEach((engine) => { getEngineTask(task, engine.tasks).platforms.forEach((plat) => { @@ -285,15 +285,16 @@ const _selectPlatform = async (c: RnvConfig, suitableEngines, task) => { } }; -const _executePipe = async (c: RnvConfig, task, phase) => executePipe(c, `${task.split(' ').join(':')}:${phase}`); +const _executePipe = async (c: RnvConfig, task: string, phase: string) => + executePipe(c, `${task.split(' ').join(':')}:${phase}`); const TASK_LIMIT = 20; export const executeTask = async ( c: RnvConfig, task: string, - parentTask: string | null, - originTask: string, + parentTask?: string | null, + originTask?: string, isFirstTask?: boolean ) => { const pt = parentTask ? `=> [${parentTask}] ` : ''; diff --git a/packages/rnv/src/core/taskManager/types.ts b/packages/rnv/src/core/taskManager/types.ts index 06f4c34d34..da718aca60 100644 --- a/packages/rnv/src/core/taskManager/types.ts +++ b/packages/rnv/src/core/taskManager/types.ts @@ -4,6 +4,7 @@ export type RnvTask = { task: string; params: Array; isGlobalScope: boolean; + platforms: Array; }; export type RnvTaskParameter = { diff --git a/packages/rnv/src/core/templateManager/index.ts b/packages/rnv/src/core/templateManager/index.ts index 43d8cb0fd2..b7d2bfc7f6 100644 --- a/packages/rnv/src/core/templateManager/index.ts +++ b/packages/rnv/src/core/templateManager/index.ts @@ -319,7 +319,7 @@ export const getTemplateOptions = (c: RnvConfig, isGlobalScope?: boolean) => { }); }; -export const getInstalledTemplateOptions = (c) => { +export const getInstalledTemplateOptions = (c: RnvConfig) => { if (c.files.project.config.isTemplate) return []; if (c.buildConfig.templates) { return generateOptions(c.buildConfig.templates); @@ -331,7 +331,7 @@ export const getInstalledTemplateOptions = (c) => { export const isTemplateInstalled = (c: RnvConfig) => c.buildConfig.currentTemplate ? doResolve(c.buildConfig.currentTemplate) : false; -export const applyTemplate = async (c: RnvConfig, selectedTemplate: string) => { +export const applyTemplate = async (c: RnvConfig, selectedTemplate?: string) => { logTask('applyTemplate', `${c.buildConfig.currentTemplate}=>${selectedTemplate}`); if (c.files.project.config.isTemplate) return true; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.config.ts b/packages/rnv/src/engine-core/tasks/task.rnv.config.ts index 2e0e533c77..e8e5b6e276 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.config.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.config.ts @@ -4,13 +4,14 @@ import { logWarning, logTask } from '../../core/systemManager/logger'; import { configSchema, PARAMS } from '../../core/constants'; import Config from '../../core/configManager/config'; import { getCliArguments } from '../../core/common'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvConfig = (c) => { +export const taskRnvConfig: RnvTaskFn = async (c) => { logTask('taskRnvConfig'); const [, key, value] = getCliArguments(c); // first arg is config so it's useless if (key === 'list') { - const rows = []; + const rows: Array = []; Object.keys(configSchema).forEach((k) => rows.push(Config.listConfigValue(k))); printTable([].concat(...rows)); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.crypto.decrypt.ts b/packages/rnv/src/engine-core/tasks/task.rnv.crypto.decrypt.ts index e8fe7b5fd1..01780e904b 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.crypto.decrypt.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.crypto.decrypt.ts @@ -108,7 +108,7 @@ ${getEnvExportCmd(envVar, 'REPLACE_WITH_ENV_VARIABLE')} let data; try { data = await iocane.createSession().use('cbc').decrypt(fsReadFileSync(source), key); - } catch (e) { + } catch (e: any) { if (e?.message?.includes) { if (e.message.includes('Signature mismatch')) { const err = `You're trying to decode crypto file encoded with previous version of crypto. diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts b/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts index c9538f00ad..48f73c4566 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts @@ -21,7 +21,7 @@ import { RnvTaskFn } from '../../core/taskManager/types'; const iocane = require('iocane'); -const readdirAsync = promisify(fsReaddir); +const readdirAsync = promisify>(fsReaddir); const generateRandomKey = (length: number) => Array(length) diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts b/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts index 50ad74ec13..85986d4599 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts @@ -11,10 +11,13 @@ import { RnvTaskFn } from '../../core/taskManager/types'; export const taskRnvKill: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvKill'); - const usedPorts = []; - let platArray = []; + const usedPorts: Array = []; + let platArray: Array<{ + platform: string; + port: string; + }> = []; const results = []; - let ports; + let ports: Record = {}; await configureRuntimeDefaults(c); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.project.configure.ts b/packages/rnv/src/engine-core/tasks/task.rnv.project.configure.ts index 74715c9c09..10db91effc 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.project.configure.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.project.configure.ts @@ -34,8 +34,9 @@ import { } from '../../core/projectManager'; import { configureEngines } from '../../core/engineManager'; import { executeTask, initializeTask, findSuitableTask } from '../../core/taskManager'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvProjectConfigure = async (c: RnvConfig, parentTask, originTask) => { +export const taskRnvProjectConfigure: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvProjectConfigure'); if (c.paths.project.builds.dir && !fsExistsSync(c.paths.project.builds.dir)) { diff --git a/packages/rnv/src/typings/modules.d.ts b/packages/rnv/src/typings/modules.d.ts index e66125c1c5..3c67f00adf 100644 --- a/packages/rnv/src/typings/modules.d.ts +++ b/packages/rnv/src/typings/modules.d.ts @@ -1,4 +1,5 @@ declare module 'netcat'; +declare module 'netcat/client'; declare module 'color-string'; declare module 'detect-port'; declare module 'ip'; From 33af2c5686e3f5b2631cef9534f50188ca4bf850 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Wed, 30 Aug 2023 02:07:28 +0200 Subject: [PATCH 17/83] more ts refactor 928 togo --- packages/rnv/src/core/configManager/types.ts | 15 ++++++- .../core/sdkManager/deviceUtils/android.ts | 32 ++++++------- .../src/core/sdkManager/deviceUtils/common.ts | 7 ++- .../src/core/sdkManager/deviceUtils/kaios.ts | 7 +-- .../src/core/sdkManager/deviceUtils/tizen.ts | 6 +-- packages/rnv/src/core/sdkManager/types.ts | 15 +++++++ .../rnv/src/core/systemManager/npmUtils.ts | 20 +++++---- .../rnv/src/core/templateManager/index.ts | 45 +++++++++++-------- packages/rnv/src/core/types.ts | 2 + .../rnv/src/engine-core/tasks/task.rnv.new.ts | 1 + packages/rnv/src/typings/modules.d.ts | 1 + 11 files changed, 101 insertions(+), 50 deletions(-) diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index abac80dbd8..b947dbaba7 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -58,6 +58,9 @@ export interface RnvConfig { selectedTemplate?: string; runtimeExtraProps: string; requiresBootstrap: boolean; + currentTemplate: string; + requiresForcedTemplateApply: boolean; + forceBuildHookRebuild: boolean; }; paths: { GLOBAL_RNV_CONFIG: string; @@ -185,6 +188,8 @@ export interface RnvConfig { platformTemplates: Record; appConfigsDir: string; configTemplate: string; + config: string; + dir?: string; }; appConfigBase: string; }; @@ -296,12 +301,14 @@ export interface RnvConfigFileObj { } export type RenativeConfigFile = { + sdks: Record; workspaceID: string; common: { buildSchemes: Record; }; defaults: { ports: Record; + supportedPlatforms: Array; }; platforms: Record< string, @@ -310,13 +317,19 @@ export type RenativeConfigFile = { entryFile?: string; } >; - templates: Record; + templates: Record< + string, + { + version: string; + } + >; currentTemplate: string; projectTemplates: object; paths: { appConfigsDirs: Array; }; integrations: Record; + tasks: Array | Record; }; export type RenativeConfigBuildScheme = Record; diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/android.ts b/packages/rnv/src/core/sdkManager/deviceUtils/android.ts index 7aa1cc7acc..9ded1a2e7a 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/android.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/android.ts @@ -28,6 +28,8 @@ import { CLI_ANDROID_SDKMANAGER, USER_HOME_DIR, } from '../../constants'; +import { RnvConfig } from '../../configManager/types'; +import { AndroidDevice } from '../types'; const CHECK_INTEVAL = 5000; @@ -124,10 +126,10 @@ const _getDeviceString = (device, i) => { return ` [${i + 1}]> ${deviceString}\n`; }; -export const resetAdb = async (c: RnvConfig, ranBefore) => { +export const resetAdb = async (c: RnvConfig, ranBefore?: boolean) => { try { if (!ranBefore) await execCLI(c, CLI_ANDROID_ADB, 'kill-server'); - } catch (e) { + } catch (e: any) { logWarning(e); } try { @@ -141,7 +143,7 @@ export const resetAdb = async (c: RnvConfig, ranBefore) => { } }; -export const getAndroidTargets = async (c: RnvConfig, skipDevices, skipAvds, deviceOnly = false) => { +export const getAndroidTargets = async (c: RnvConfig, skipDevices: boolean, skipAvds: boolean, deviceOnly = false) => { logTask('getAndroidTargets', `skipDevices:${!!skipDevices} skipAvds:${!!skipAvds} deviceOnly:${!!deviceOnly}`); // Temp workaround for race conditions receiving devices with offline status await new Promise((r) => setTimeout(r, 1000)); @@ -162,14 +164,14 @@ export const getAndroidTargets = async (c: RnvConfig, skipDevices, skipAvds, dev } }; -const calculateDeviceDiagonal = (width, height, density) => { +const calculateDeviceDiagonal = (width: number, height: number, density: number) => { // Calculate the diagonal in inches const widthInches = width / density; const heightInches = height / density; return Math.sqrt(widthInches * widthInches + heightInches * heightInches); }; -const getRunningDeviceProp = async (c: RnvConfig, udid, prop) => { +const getRunningDeviceProp = async (c: RnvConfig, udid: string, prop) => { // avoid multiple calls to the same device if (currentDeviceProps[udid]) { if (!prop) return currentDeviceProps[udid]; @@ -191,7 +193,7 @@ const getRunningDeviceProp = async (c: RnvConfig, udid, prop) => { return getRunningDeviceProp(c, udid, prop); }; -const decideIfTVRunning = async (c: RnvConfig, device) => { +const decideIfTVRunning = async (c: RnvConfig, device: AndroidDevice) => { const { udid, model, product } = device; const mod = await getRunningDeviceProp(c, udid, 'ro.product.model'); const name = await getRunningDeviceProp(c, udid, 'ro.product.name'); @@ -217,7 +219,7 @@ const decideIfTVRunning = async (c: RnvConfig, device) => { return isTV; }; -const decideIfWearRunning = async (c: RnvConfig, device) => { +const decideIfWearRunning = async (c: RnvConfig, device: AndroidDevice) => { const { udid, model, product } = device; const fingerprint = await getRunningDeviceProp(c, udid, 'ro.vendor.build.fingerprint'); const name = await getRunningDeviceProp(c, udid, 'ro.product.vendor.name'); @@ -233,7 +235,7 @@ const decideIfWearRunning = async (c: RnvConfig, device) => { return isWear; }; -const getDeviceType = async (device, c) => { +const getDeviceType = async (device: AndroidDevice, c: RnvConfig) => { logDebug('getDeviceType - in', { device }); if (device.udid !== 'unknown') { @@ -314,7 +316,7 @@ const getDeviceType = async (device, c) => { return device; }; -const getAvdDetails = (c: RnvConfig, deviceName) => { +const getAvdDetails = (c: RnvConfig, deviceName: string) => { const { ANDROID_SDK_HOME, ANDROID_AVD_HOME } = process.env; // .avd dir might be in other place than homedir. (https://developer.android.com/studio/command-line/variables) @@ -353,7 +355,7 @@ const getAvdDetails = (c: RnvConfig, deviceName) => { return results; }; -const getEmulatorName = async (c: RnvConfig, words) => { +const getEmulatorName = async (c: RnvConfig, words: Array) => { const emulator = words[0]; const port = emulator.split('-')[1]; @@ -377,9 +379,9 @@ export const connectToWifiDevice = async (c: RnvConfig, target) => { return false; }; -const _parseDevicesResult = async (c: RnvConfig, devicesString, avdsString, deviceOnly) => { +const _parseDevicesResult = async (c: RnvConfig, devicesString: string, avdsString: string, deviceOnly: boolean) => { logDebug(`_parseDevicesResult:${devicesString}:${avdsString}:${deviceOnly}`); - const devices = []; + const devices: Array = []; const { skipTargetCheck } = c.program; if (devicesString) { @@ -529,7 +531,7 @@ export const askForNewEmulator = async (c: RnvConfig, platform: string) => { return Promise.reject('Action canceled!'); }; -const _createEmulator = (c: RnvConfig, apiVersion, emuPlatform, emuName, arch = 'x86') => { +const _createEmulator = (c: RnvConfig, apiVersion: string, emuPlatform: string, emuName: string, arch = 'x86') => { logTask('_createEmulator'); return execCLI(c, CLI_ANDROID_SDKMANAGER, `"system-images;android-${apiVersion};${emuPlatform};${arch}"`) @@ -546,12 +548,12 @@ const _createEmulator = (c: RnvConfig, apiVersion, emuPlatform, emuName, arch = .catch((e) => logError(e, true)); }; -const waitForEmulatorToBeReady = (c: RnvConfig, emulator) => +const waitForEmulatorToBeReady = (c: RnvConfig, emulator: string) => waitForEmulator(c, CLI_ANDROID_ADB, `-s ${emulator} shell getprop init.svc.bootanim`, (res) => res.includes('stopped') ); -export const checkForActiveEmulator = (c) => +export const checkForActiveEmulator = (c: RnvConfig) => new Promise((resolve, reject) => { logTask('checkForActiveEmulator'); const { platform } = c; diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/common.ts b/packages/rnv/src/core/sdkManager/deviceUtils/common.ts index 42a824941d..f5e237554e 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/common.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/common.ts @@ -2,7 +2,12 @@ import ora from '../../../cli/ora'; import { RnvConfig } from '../../configManager/types'; import { execCLI } from '../../systemManager/exec'; -export const waitForEmulator = async (c: RnvConfig, cli: string, command: string, callback) => { +export const waitForEmulator = async ( + c: RnvConfig, + cli: string, + command: string, + callback: (resp: string | true) => boolean +) => { let attempts = 0; const maxAttempts = 30; const CHECK_INTEVAL = 2000; diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/kaios.ts b/packages/rnv/src/core/sdkManager/deviceUtils/kaios.ts index fb5ea52384..6f7e8e7109 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/kaios.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/kaios.ts @@ -3,11 +3,12 @@ import path from 'path'; import { fsExistsSync, getRealPath } from '../../systemManager/fileutils'; import { chalk, logTask } from '../../systemManager/logger'; import { KAIOS_SDK } from '../../constants'; +import { RnvConfig } from '../../configManager/types'; const childProcess = require('child_process'); -export const launchKaiOSSimulator = (c) => - new Promise((resolve, reject) => { +export const launchKaiOSSimulator = (c: RnvConfig) => + new Promise((resolve, reject) => { logTask('launchKaiOSSimulator'); if (!c.buildConfig?.sdks?.KAIOS_SDK) { @@ -23,7 +24,7 @@ export const launchKaiOSSimulator = (c) => const ePath = getRealPath(path.join(c.buildConfig?.sdks?.KAIOS_SDK)); - if (!fsExistsSync(ePath)) { + if (ePath && !fsExistsSync(ePath)) { reject(`Can't find emulator at path: ${ePath}`); return; } diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts index b116522600..4d6c2c6261 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts @@ -84,7 +84,7 @@ export const createDevelopTizenCertificate = (c) => }); export const addDevelopTizenCertificate = (c: RnvConfig, secureProfileConfig) => - new Promise((resolve) => { + new Promise((resolve) => { logTask('addDevelopTizenCertificate'); const { profileName, certPath, certPassword } = secureProfileConfig || {}; @@ -98,11 +98,11 @@ export const addDevelopTizenCertificate = (c: RnvConfig, secureProfileConfig) => }); }); -const _getDeviceID = async (c: RnvConfig, target) => { +const _getDeviceID = async (c: RnvConfig, target: string) => { const { device } = c.program; if (device) { - let connectResponse; + let connectResponse: string; try { connectResponse = await execCLI(c, CLI_SDB_TIZEN, `connect ${target}`); } catch (e) { diff --git a/packages/rnv/src/core/sdkManager/types.ts b/packages/rnv/src/core/sdkManager/types.ts index 349b651b25..2a2308d7b0 100644 --- a/packages/rnv/src/core/sdkManager/types.ts +++ b/packages/rnv/src/core/sdkManager/types.ts @@ -1,3 +1,18 @@ export type AppleDevice = { udid: string; }; + +export type AndroidDevice = { + udid: string; + model: string; + product: string; + isPhone: boolean; + isTablet: boolean; + isWear: boolean; + isTV: boolean; + isMobile: boolean; + screenProps: any; + arch: string; + avdConfig: any; + isNotEligibleAndroid: boolean; +}; diff --git a/packages/rnv/src/core/systemManager/npmUtils.ts b/packages/rnv/src/core/systemManager/npmUtils.ts index 7a1bf38a1b..a977cdc610 100644 --- a/packages/rnv/src/core/systemManager/npmUtils.ts +++ b/packages/rnv/src/core/systemManager/npmUtils.ts @@ -18,6 +18,7 @@ import { doResolve } from './resolve'; import { inquirerPrompt } from '../../cli/prompt'; import { getConfigProp } from '../common'; import { RnvConfig } from '../configManager/types'; +import { RnvError } from '../types'; const packageJsonIsValid = (c) => { if (!fsExistsSync(c.paths.project.package)) return false; @@ -96,7 +97,10 @@ export const listAndSelectNpmVersion = async (c: RnvConfig, npmPackage) => { const versionArr = templateVersionsStr.replace(/\r?\n|\r|\s|'|\[|\]/g, '').split(','); const templateTagsStr = await executeAsync(c, `npm dist-tag ls ${npmPackage}`); - const tagArr = []; + const tagArr: Array<{ + name: string; + version: string; + }> = []; templateTagsStr.split('\n').forEach((tString) => { const tArr = tString.split(': '); tagArr.push({ @@ -111,7 +115,7 @@ export const listAndSelectNpmVersion = async (c: RnvConfig, npmPackage) => { let recommendedVersion; validVersions.forEach((item) => { let matchStr = ''; - const matchArr = []; + const matchArr: Array = []; tagArr.forEach((tag) => { if (tag.version === item.value) { matchArr.push(tag.name); @@ -151,7 +155,7 @@ export const checkIfProjectAndNodeModulesExists = async (c: RnvConfig) => { } }; -const _getInstallScript = (c) => { +const _getInstallScript = (c: RnvConfig) => { const tasks = c.buildConfig?.tasks; if (!tasks) return null; if (Array.isArray(tasks)) { @@ -229,7 +233,7 @@ export const installPackageDependencies = async (c: RnvConfig, failOnError = fal try { await executeAsync(command); await invalidatePodsChecksum(c); - } catch (e) { + } catch (e: RnvError) { if (failOnError) { logError(e); throw e; @@ -238,9 +242,9 @@ export const installPackageDependencies = async (c: RnvConfig, failOnError = fal `${e}\n Seems like your node_modules is corrupted by other libs. ReNative will try to fix it for you` ); try { - await cleanNodeModules(c); + await cleanNodeModules(); await installPackageDependencies(c, true); - } catch (npmErr) { + } catch (npmErr: RnvError) { logError(npmErr); throw npmErr; } @@ -265,7 +269,7 @@ export const installPackageDependencies = async (c: RnvConfig, failOnError = fal } c._requiresNpmInstall = false; return true; - } catch (jetErr) { + } catch (jetErr: RnvError) { logError(jetErr); return false; } @@ -284,7 +288,7 @@ export const jetifyIfRequired = async (c: RnvConfig) => { }; export const cleanNodeModules = () => - new Promise((resolve, reject) => { + new Promise((resolve, reject) => { logTask('cleanNodeModules'); const dirs = [ 'react-native-safe-area-view/.git', diff --git a/packages/rnv/src/core/templateManager/index.ts b/packages/rnv/src/core/templateManager/index.ts index b7d2bfc7f6..a09bd35b54 100644 --- a/packages/rnv/src/core/templateManager/index.ts +++ b/packages/rnv/src/core/templateManager/index.ts @@ -21,6 +21,7 @@ import { listAppConfigsFoldersSync, generateBuildConfig, loadFileExtended } from import { doResolve } from '../systemManager/resolve'; import { checkIfProjectAndNodeModulesExists } from '../systemManager/npmUtils'; import { RnvConfig } from '../configManager/types'; +import { RnvError } from '../types'; export const checkIfTemplateConfigured = async (c: RnvConfig) => { logTask('checkIfTemplateConfigured'); @@ -56,7 +57,7 @@ export const checkIfTemplateConfigured = async (c: RnvConfig) => { return true; }; -const _cleanProjectTemplateSync = (c) => { +const _cleanProjectTemplateSync = (c: RnvConfig) => { logTask('_cleanProjectTemplateSync'); const dirsToRemove = [ path.join(c.paths.project.appConfigBase.dir), @@ -94,9 +95,11 @@ const _applyTemplate = async (c: RnvConfig) => { // c.paths.template.dir = path.join(c.paths.project.nodeModulesDir, c.buildConfig.currentTemplate); } - c.paths.template.configTemplate = path.join(c.paths.template.dir, RENATIVE_CONFIG_TEMPLATE_NAME); + if (c.paths.template.dir) { + c.paths.template.configTemplate = path.join(c.paths.template.dir, RENATIVE_CONFIG_TEMPLATE_NAME); - c.paths.template.config = path.join(c.paths.template.dir, RENATIVE_CONFIG_NAME); + c.paths.template.config = path.join(c.paths.template.dir, RENATIVE_CONFIG_NAME); + } // if (fsExistsSync(c.paths.template.config)) { // c.files.template.config = readObjectSync(c.paths.template.config); @@ -113,7 +116,7 @@ const _applyTemplate = async (c: RnvConfig) => { logDebug(`_applyTemplate:${c.runtime.selectedTemplate}:${c.paths.template.dir}`); - c.paths.template.appConfigsDir = path.join(c.paths.template.dir, 'appConfigs'); + if (c.paths.template.dir) c.paths.template.appConfigsDir = path.join(c.paths.template.dir, 'appConfigs'); c.paths.template.appConfigBase.dir = path.join(c.paths.template.appConfigsDir, 'base'); c.runtime.currentTemplate = c.files.project.config.currentTemplate; if (!c.runtime.currentTemplate) { @@ -130,7 +133,7 @@ const _applyTemplate = async (c: RnvConfig) => { return true; }; -const _configureSrc = (c) => +const _configureSrc = (c: RnvConfig) => new Promise((resolve) => { // Check src logDebug('configureProject:check src'); @@ -186,13 +189,13 @@ const _configureAppConfigs = async (c: RnvConfig) => { } } }); - } catch (e) { + } catch (e: RnvError) { logError(e); } } }; -const _configureProjectConfig = (c) => +const _configureProjectConfig = (c: RnvConfig) => new Promise((resolve) => { // Check projectConfigs logDebug('configureProject:check projectConfigs'); @@ -245,19 +248,23 @@ export const configureTemplateFiles = async (c: RnvConfig) => { const includedPaths = templateConfig?.templateConfig?.includedPaths; if (includedPaths) { includedPaths.forEach((name: string) => { - const sourcePath = path.join(c.paths.template.dir, name); - const destPath = path.join(c.paths.project.dir, name); - if (!fsExistsSync(destPath) && fsExistsSync(sourcePath)) { - try { - if (fsLstatSync(sourcePath).isDirectory()) { - logInfo(`Missing directory ${chalk().white(`${destPath}.js`)}. COPYING from TEMPATE...DONE`); - copyFolderContentsRecursiveSync(sourcePath, destPath); - } else { - logInfo(`Missing file ${chalk().white(`${destPath}.js`)}. COPYING from TEMPATE...DONE`); - copyFileSync(sourcePath, destPath); + if (c.paths.template.dir) { + const sourcePath = path.join(c.paths.template.dir, name); + const destPath = path.join(c.paths.project.dir, name); + if (!fsExistsSync(destPath) && fsExistsSync(sourcePath)) { + try { + if (fsLstatSync(sourcePath).isDirectory()) { + logInfo( + `Missing directory ${chalk().white(`${destPath}.js`)}. COPYING from TEMPATE...DONE` + ); + copyFolderContentsRecursiveSync(sourcePath, destPath); + } else { + logInfo(`Missing file ${chalk().white(`${destPath}.js`)}. COPYING from TEMPATE...DONE`); + copyFileSync(sourcePath, destPath); + } + } catch (e) { + // Get some beer and order hookers } - } catch (e) { - // Get some beer and order hookers } } }); diff --git a/packages/rnv/src/core/types.ts b/packages/rnv/src/core/types.ts index 8d2a00ca9e..e921d54107 100644 --- a/packages/rnv/src/core/types.ts +++ b/packages/rnv/src/core/types.ts @@ -8,3 +8,5 @@ export type RnvModuleConfig = { export type RnvNextJSConfig = {}; export type RenativeConfigVersion = string | { version: string }; + +export type RnvError = any; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.new.ts b/packages/rnv/src/engine-core/tasks/task.rnv.new.ts index dbb7f3679c..c87393a49f 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.new.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.new.ts @@ -33,6 +33,7 @@ import { printIntoBox, } from '../../core/systemManager/logger'; import { isYarnInstalled, listAndSelectNpmVersion } from '../../core/systemManager/npmUtils'; +import { RnvConfig } from '../../core/configManager/types'; const highlight = chalk().green; diff --git a/packages/rnv/src/typings/modules.d.ts b/packages/rnv/src/typings/modules.d.ts index 3c67f00adf..6cec241c6e 100644 --- a/packages/rnv/src/typings/modules.d.ts +++ b/packages/rnv/src/typings/modules.d.ts @@ -4,5 +4,6 @@ declare module 'color-string'; declare module 'detect-port'; declare module 'ip'; declare module 'get-installed-path' +declare module 'color-string'; export {} \ No newline at end of file From 57beb90fab1ea20b1631b87262368d96f1282849 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Wed, 30 Aug 2023 02:46:41 +0200 Subject: [PATCH 18/83] more types refactored, 767 togo --- packages/rnv/src/cli/prompt.ts | 2 +- packages/rnv/src/cli/types.ts | 4 +- packages/rnv/src/core/adapter/index.ts | 27 +++++++------ packages/rnv/src/core/common.ts | 4 +- .../src/core/configManager/packageParser.ts | 6 +-- .../src/core/configManager/schemeParser.ts | 11 ++++-- packages/rnv/src/core/configManager/types.ts | 19 +++++++++ packages/rnv/src/core/engineManager/index.ts | 22 +++++------ packages/rnv/src/core/engineManager/types.ts | 2 + .../rnv/src/core/platformManager/index.ts | 4 +- packages/rnv/src/core/projectManager/index.ts | 39 +++++++++++++------ .../src/core/sdkManager/deviceUtils/tizen.ts | 4 +- .../src/core/sdkManager/deviceUtils/webos.ts | 1 + packages/rnv/src/core/sdkManager/installer.ts | 7 ++-- .../rnv/src/core/systemManager/npmUtils.ts | 2 +- packages/rnv/src/core/types.ts | 2 +- .../tasks/task.rnv.crypto.encrypt.ts | 6 +-- .../src/engine-core/tasks/task.rnv.doctor.ts | 3 +- .../rnv/src/engine-core/tasks/task.rnv.new.ts | 2 +- .../tasks/task.rnv.platform.configure.ts | 3 +- .../tasks/task.rnv.target.launch.ts | 3 +- 21 files changed, 110 insertions(+), 63 deletions(-) diff --git a/packages/rnv/src/cli/prompt.ts b/packages/rnv/src/cli/prompt.ts index 655670a6ca..61e0f13541 100644 --- a/packages/rnv/src/cli/prompt.ts +++ b/packages/rnv/src/cli/prompt.ts @@ -3,7 +3,7 @@ import { chalk, logWarning, logTask, logDebug } from '../core/systemManager/logg import Config from '../core/configManager/config'; import { PromptOptions, PromptParams, PromptRenderFn } from './types'; -export const inquirerPrompt = async (params: PromptParams) => { +export const inquirerPrompt = async (params: PromptParams): Promise => { const c = Config.getConfig(); if (c.program?.yes) return true; diff --git a/packages/rnv/src/cli/types.ts b/packages/rnv/src/cli/types.ts index 1cab8c2e35..d7e7390b5a 100644 --- a/packages/rnv/src/cli/types.ts +++ b/packages/rnv/src/cli/types.ts @@ -10,10 +10,10 @@ export type PromptOptions = { export type PromptParams = { logMessage?: string; warningMessage?: string; - message: string; + message?: string; choices?: any; default?: any; - name: string; + name?: string; type: string; pageSize?: number; validate?: (i: string) => string; diff --git a/packages/rnv/src/core/adapter/index.ts b/packages/rnv/src/core/adapter/index.ts index 03c6a3c582..afe4da5e67 100644 --- a/packages/rnv/src/core/adapter/index.ts +++ b/packages/rnv/src/core/adapter/index.ts @@ -1,7 +1,7 @@ import fs from 'fs'; import { logInfo } from '../systemManager/logger'; -export const withDefaultRNVBabel = (cnf) => ({ +export const withDefaultRNVBabel = (cnf: any) => ({ retainLines: true, presets: [['@babel/preset-env', {}]], plugins: [ @@ -15,25 +15,30 @@ export const withDefaultRNVBabel = (cnf) => ({ ...cnf, }); -export const withRNVBabel = (cnf) => (api) => { - if (!fs.existsSync(process.env.RNV_ENGINE_PATH)) { +export const withRNVBabel = (cnf: any) => (api: any) => { + if (process.env.RNV_ENGINE_PATH && !fs.existsSync(process.env.RNV_ENGINE_PATH)) { logInfo(`Path to engine cannot be resolved: ${process.env.RNV_ENGINE_PATH}. Will use default one`); api.cache(false); return withDefaultRNVBabel(cnf); } - const engine = require(process.env.RNV_ENGINE_PATH); - api.cache(true); - if (engine.withRNVBabel) { - return engine.withRNVBabel(cnf); + + if (process.env.RNV_ENGINE_PATH) { + const engine = require(process.env.RNV_ENGINE_PATH); + api.cache(true); + if (engine.withRNVBabel) { + return engine.withRNVBabel(cnf); + } } return cnf; }; -export const withRNVMetro = (cnf) => { - const engine = require(process.env.RNV_ENGINE_PATH); - if (engine.withRNV) { - return engine.withRNV(cnf); +export const withRNVMetro = (cnf: any) => { + if (process.env.RNV_ENGINE_PATH) { + const engine = require(process.env.RNV_ENGINE_PATH); + if (engine.withRNV) { + return engine.withRNV(cnf); + } } return cnf; diff --git a/packages/rnv/src/core/common.ts b/packages/rnv/src/core/common.ts index 8f8502ded7..49853408f9 100755 --- a/packages/rnv/src/core/common.ts +++ b/packages/rnv/src/core/common.ts @@ -233,7 +233,7 @@ export const getAppFolder = (c: RnvConfig, isRelativePath?: boolean) => { export const getAppTemplateFolder = (c: RnvConfig, platform: string) => path.join(c.paths.project.platformTemplatesDirs[platform], `${platform}`); -const _getValueOrMergedObject = (resultCli, resultScheme, resultPlatforms, resultCommon) => { +const _getValueOrMergedObject = (resultCli: any, resultScheme: any, resultPlatforms: any, resultCommon: any) => { if (resultCli !== undefined) { return resultCli; } @@ -372,7 +372,7 @@ export const getAppVersion = (c: RnvConfig, platform: string) => { if (!versionFormat) return version; const versionCodeArr = versionFormat.split('.'); const dotLength = versionCodeArr.length; - const isNumArr = versionCodeArr.map((v) => !Number.isNaN(Number(v))); + const isNumArr = versionCodeArr.map((v: string) => !Number.isNaN(Number(v))); const verArr: Array = []; let i = 0; diff --git a/packages/rnv/src/core/configManager/packageParser.ts b/packages/rnv/src/core/configManager/packageParser.ts index d60dc04d5c..ba2b97ca47 100644 --- a/packages/rnv/src/core/configManager/packageParser.ts +++ b/packages/rnv/src/core/configManager/packageParser.ts @@ -72,7 +72,7 @@ export const checkRequiredPackage = async ( } else if (!version) { // package exists, checking version only if version is not const currentVersion = projectConfig.package[type][pkg]; - let latestVersion = false; + let latestVersion; try { latestVersion = await executeAsync(`npm show ${pkg} version`); // eslint-disable-next-line no-empty @@ -114,10 +114,10 @@ export const injectPlatformDependencies = async (c: RnvConfig) => { const npmDepsBase = engine?.config?.npm || {}; const npmDepsExt = engine?.config?.platforms[platform]?.npm || {}; - const npmDeps = merge(npmDepsBase, npmDepsExt); + const npmDeps = merge(npmDepsBase, npmDepsExt); if (npmDeps) { - const promises = Object.keys(npmDeps).reduce((acc, type) => { + const promises = Object.keys(npmDeps).reduce>>((acc, type) => { // iterate over dependencies, devDepencencies or optionalDependencies Object.keys(npmDeps[type]).forEach((dep) => { // iterate over deps diff --git a/packages/rnv/src/core/configManager/schemeParser.ts b/packages/rnv/src/core/configManager/schemeParser.ts index f4b7e8c65e..a774053faa 100644 --- a/packages/rnv/src/core/configManager/schemeParser.ts +++ b/packages/rnv/src/core/configManager/schemeParser.ts @@ -1,6 +1,7 @@ import merge from 'deepmerge'; import { logError, logTask, logWarning, chalk, logInfo } from '../systemManager/logger'; import { inquirerPrompt } from '../../cli/prompt'; +import { RnvConfig } from './types'; export const isBuildSchemeSupported = async (c: RnvConfig) => { logTask('isBuildSchemeSupported'); @@ -8,11 +9,13 @@ export const isBuildSchemeSupported = async (c: RnvConfig) => { const { scheme } = c.program; if (!c.buildConfig.platforms[c.platform]) { - c.buildConfig.platforms[c.platform] = {}; + c.buildConfig.platforms[c.platform] = { + buildSchemes: {}, + }; } const baseBuildSchemes = c.buildConfig.common?.buildSchemes || {}; - const platformBuildSchemes = c.buildConfig.platforms?.[c.platform]?.buildSchemes || {}; + const platformBuildSchemes = c.buildConfig.platforms[c.platform]?.buildSchemes; const buildSchemes = merge(baseBuildSchemes, platformBuildSchemes); @@ -27,8 +30,8 @@ export const isBuildSchemeSupported = async (c: RnvConfig) => { logError('Build scheme you picked does not exists.'); } // const opts = generateOptions(buildSchemes); - const schemeOptions = []; - const schemeVals = {}; + const schemeOptions: Array = []; + const schemeVals: Record = {}; Object.keys(buildSchemes).forEach((k) => { const s = buildSchemes[k]; const desc = s.description ? chalk().grey(` (${s.description})`) : ''; diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index b947dbaba7..bd21633f02 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -61,6 +61,16 @@ export interface RnvConfig { currentTemplate: string; requiresForcedTemplateApply: boolean; forceBuildHookRebuild: boolean; + disableReset: boolean; + skipActiveServerCheck: boolean; + port: number; + rnvVersionRunner: string; + rnvVersionProject: string; + versionCheckCompleted: boolean; + currentPlatform: { + isWebHosted: boolean; + }; + _skipPluginScopeWarnings: boolean; }; paths: { GLOBAL_RNV_CONFIG: string; @@ -172,6 +182,7 @@ export interface RnvConfig { configsPrivate: Array; configsLocal: Array; dir: string; + dirs: Array; }; // EXTRA buildHooks: { @@ -330,6 +341,14 @@ export type RenativeConfigFile = { }; integrations: Record; tasks: Array | Record; + engineTemplates: Record; + engines: Record; }; export type RenativeConfigBuildScheme = Record; + +export type NpmPackageFile = { + devDependencies: Record; + dependencies: Record; + peerDependencies: Record; +}; diff --git a/packages/rnv/src/core/engineManager/index.ts b/packages/rnv/src/core/engineManager/index.ts index fe6396a79b..b6f9312f94 100644 --- a/packages/rnv/src/core/engineManager/index.ts +++ b/packages/rnv/src/core/engineManager/index.ts @@ -16,7 +16,7 @@ import { RnvEngineConfig, RnvEngineConfigMap, RnvEngineInstallConfig } from './t const ENGINE_CORE = 'engine-core'; -export const registerEngine = async (c: RnvConfig, engine, platform, engConfig) => { +export const registerEngine = async (c: RnvConfig, engine, platform: RnvPlatform, engConfig) => { logTask(`registerEngine:${engine.config.id}`); c.runtime.enginesById[engine.config.id] = engine; engine.initializeRuntimeConfig(c); @@ -33,13 +33,13 @@ export const registerEngine = async (c: RnvConfig, engine, platform, engConfig) _registerEnginePlatform(c, platform, engine); }; -const _registerEnginePlatform = (c: RnvConfig, platform, engine) => { +const _registerEnginePlatform = (c: RnvConfig, platform: RnvPlatform, engine) => { if (platform) { c.runtime.enginesByPlatform[platform] = engine; } }; -export const registerEngineExtension = (ext, eExt, extras = []) => { +export const registerEngineExtension = (ext: string | null, eExt: string | null, extras: Array = []) => { const e1 = ext ? `${ext}.` : ''; const e2 = eExt ? `${eExt}.` : ''; let extArr; @@ -62,7 +62,7 @@ export const registerEngineExtension = (ext, eExt, extras = []) => { return extArr; }; -export const generateEngineExtensions = (exts, config) => { +export const generateEngineExtensions = (exts: Array, config) => { const { id, engineExtension } = config; let extArr = [...registerEngineExtension(id)]; exts.forEach((ext) => { @@ -72,8 +72,8 @@ export const generateEngineExtensions = (exts, config) => { return extArr; }; -export const generateEngineTasks = (taskArr) => { - const tasks = {}; +export const generateEngineTasks = (taskArr: Array) => { + const tasks: RnvTaskMap = {}; taskArr.forEach((taskInstance) => { tasks[taskInstance.task] = taskInstance; }); @@ -157,7 +157,7 @@ export const loadEnginePluginDeps = async (c: RnvConfig, engineConfigs) => { if (c.files.project.config.isTemplate) return 0; // Check engine dependencies - const addedPlugins = {}; + const addedPlugins: Record> = {}; let hasAddedPlugins = false; const originalProjectPlugins = c.files.project.config_original.plugins || {}; engineConfigs.forEach((ecf) => { @@ -280,7 +280,7 @@ export const loadEnginePackageDeps = async (c: RnvConfig, engineConfigs) => { return addedDeps.length; }; -const ENGINE_ID_MAP = { +const ENGINE_ID_MAP: Record = { 'engine-lightning': '@rnv/engine-lightning', 'engine-rn': '@rnv/engine-rn', 'engine-rn-electron': '@rnv/engine-rn-electron', @@ -291,7 +291,7 @@ const ENGINE_ID_MAP = { 'engine-rn-windows': '@rnv/engine-rn-windows', }; -const _getFilteredEngines = (c) => { +const _getFilteredEngines = (c: RnvConfig) => { const engines = c.buildConfig?.engines; if (!engines) { logError('Engine configs missing in your renative.json. FIXING...DONE'); @@ -301,7 +301,7 @@ const _getFilteredEngines = (c) => { const supportedPlatforms = c.files.project.config.defaults?.supportedPlatforms || []; const filteredEngines = {}; - supportedPlatforms.forEach((v) => { + supportedPlatforms.forEach((v: string) => { const platforms = c.files.project.config.platforms || {}; const engineKey = platforms[v]?.engine || rnvPlatforms[v]?.engine; @@ -372,7 +372,7 @@ ${enginesToInstall.map((v) => `> ${v.key}@${v.version}`).join('\n')} if (plugDepsCount + pkgDepsCount > 0) { c.runtime._skipPluginScopeWarnings = true; - await configurePlugins(c, true); // TODO: This is too early as scoped plugin have not been installed + await configurePlugins(c); // TODO: This is too early as scoped plugin have not been installed c.runtime._skipPluginScopeWarnings = false; await installPackageDependencies(c); } diff --git a/packages/rnv/src/core/engineManager/types.ts b/packages/rnv/src/core/engineManager/types.ts index 34a24854e2..8cd7015669 100644 --- a/packages/rnv/src/core/engineManager/types.ts +++ b/packages/rnv/src/core/engineManager/types.ts @@ -4,6 +4,8 @@ export type RnvEngine = { export type RnvEngineConfig = { id: string; + platforms: any; + npm: any; }; export type RnvEngineConfigMap = Record; diff --git a/packages/rnv/src/core/platformManager/index.ts b/packages/rnv/src/core/platformManager/index.ts index 87c7350ef8..d41f62a0c8 100644 --- a/packages/rnv/src/core/platformManager/index.ts +++ b/packages/rnv/src/core/platformManager/index.ts @@ -168,7 +168,7 @@ export const isPlatformSupportedSync = ( return true; }; -export const isPlatformActive = (c: RnvConfig, platform: string, resolve: () => void) => { +export const isPlatformActive = (c: RnvConfig, platform: string, resolve?: () => void) => { if (!c.buildConfig || !c.buildConfig.platforms) { logError( `Your appConfigFile is not configured properly! check ${chalk().white(c.paths.appConfig.config)} location.` @@ -184,7 +184,7 @@ export const isPlatformActive = (c: RnvConfig, platform: string, resolve: () => return true; }; export const copySharedPlatforms = (c) => - new Promise((resolve) => { + new Promise((resolve) => { logTask('copySharedPlatforms'); if (c.platform) { diff --git a/packages/rnv/src/core/projectManager/index.ts b/packages/rnv/src/core/projectManager/index.ts index b8c78410a6..46b6a27125 100644 --- a/packages/rnv/src/core/projectManager/index.ts +++ b/packages/rnv/src/core/projectManager/index.ts @@ -32,6 +32,7 @@ import { chalk, logTask, logWarning, logDebug, logInfo, getCurrentCommand } from import { configureTemplateFiles, configureEntryPoint } from '../templateManager'; import { parseRenativeConfigs } from '../configManager'; +import { NpmPackageFile, RenativeConfigFile, RnvConfig } from '../configManager/types'; export const checkAndBootstrapIfRequired = async (c: RnvConfig) => { logTask('checkAndBootstrapIfRequired'); @@ -443,7 +444,7 @@ export const copyAssetsFolder = async (c: RnvConfig, platform, subPath, customFn const assetSources = getConfigProp(c, platform, 'assetSources', []); - const validAssetSources = []; + const validAssetSources: Array = []; assetSources.forEach((v) => { const assetsPath = path.join(_resolvePackage(c, v), assetFolderPlatform); if (fsExistsSync(assetsPath)) { @@ -531,14 +532,14 @@ export const copyAssetsFolder = async (c: RnvConfig, platform, subPath, customFn // }; export const copyBuildsFolder = (c: RnvConfig, platform: string) => - new Promise((resolve) => { + new Promise((resolve) => { logTask('copyBuildsFolder'); if (!isPlatformActive(c, platform, resolve)) return; const destPath = path.join(getAppFolder(c)); const tsPathsConfig = getTimestampPathsConfig(c, platform); - const configPropsInjects = []; + const configPropsInjects: Array = []; INJECTABLE_CONFIG_PROPS.forEach((v) => { configPropsInjects.push({ pattern: `{{configProps.${v}}}`, @@ -550,15 +551,23 @@ export const copyBuildsFolder = (c: RnvConfig, platform: string) => // FOLDER MERGERS PROJECT CONFIG const sourcePath1 = getBuildsFolder(c, platform, c.paths.project.appConfigBase.dir); - copyFolderContentsRecursiveSync(sourcePath1, destPath, true, false, false, allInjects, tsPathsConfig); + copyFolderContentsRecursiveSync(sourcePath1, destPath, true, undefined, false, allInjects, tsPathsConfig); // FOLDER MERGERS PROJECT CONFIG (PRIVATE) const sourcePath1secLegacy = getBuildsFolder(c, platform, c.paths.workspace.project.appConfigBase.dir_LEGACY); - copyFolderContentsRecursiveSync(sourcePath1secLegacy, destPath, true, false, false, allInjects, tsPathsConfig); + copyFolderContentsRecursiveSync( + sourcePath1secLegacy, + destPath, + true, + undefined, + false, + allInjects, + tsPathsConfig + ); // FOLDER MERGERS PROJECT CONFIG (PRIVATE) const sourcePath1sec = getBuildsFolder(c, platform, c.paths.workspace.project.appConfigBase.dir); - copyFolderContentsRecursiveSync(sourcePath1sec, destPath, true, false, false, allInjects, tsPathsConfig); + copyFolderContentsRecursiveSync(sourcePath1sec, destPath, true, undefined, false, allInjects, tsPathsConfig); if (fsExistsSync(sourcePath1secLegacy)) { logWarning(`Path: ${chalk().red(sourcePath1secLegacy)} is DEPRECATED. @@ -578,14 +587,14 @@ Move your files to: ${chalk().white(sourcePath1sec)} instead`); if (c.paths.appConfig.dirs) { c.paths.appConfig.dirs.forEach((v) => { const sourceV = getBuildsFolder(c, platform, v); - copyFolderContentsRecursiveSync(sourceV, destPath, true, false, false, allInjects, tsPathsConfig); + copyFolderContentsRecursiveSync(sourceV, destPath, true, undefined, false, allInjects, tsPathsConfig); }); } else { copyFolderContentsRecursiveSync( getBuildsFolder(c, platform, c.paths.appConfig.dir), destPath, true, - false, + undefined, false, allInjects, tsPathsConfig @@ -594,7 +603,7 @@ Move your files to: ${chalk().white(sourcePath1sec)} instead`); // FOLDER MERGERS FROM APP CONFIG (PRIVATE) const sourcePath0sec = getBuildsFolder(c, platform, c.paths.workspace.appConfig.dir); - copyFolderContentsRecursiveSync(sourcePath0sec, destPath, true, false, false, allInjects, tsPathsConfig); + copyFolderContentsRecursiveSync(sourcePath0sec, destPath, true, undefined, false, allInjects, tsPathsConfig); copyTemplatePluginsSync(c); @@ -661,7 +670,7 @@ It is recommended that you run your rnv command with npx prefix: ${recCmd} . or return true; }; -export const upgradeProjectDependencies = (c: RnvConfig, version) => { +export const upgradeProjectDependencies = (c: RnvConfig, version: string) => { logTask('upgradeProjectDependencies'); // const templates = c.files.project.config?.templates; @@ -678,7 +687,13 @@ export const upgradeProjectDependencies = (c: RnvConfig, version) => { return result; }; -export const upgradeDependencies = (packageFile, packagesPath, configFile, configPath, version) => { +export const upgradeDependencies = ( + packageFile: NpmPackageFile, + packagesPath: string, + configFile: RenativeConfigFile, + configPath: string, + version: string +) => { // logTask('upgradeDependencies'); const result = []; @@ -703,7 +718,7 @@ export const upgradeDependencies = (packageFile, packagesPath, configFile, confi return result; }; -const _fixDeps = (deps, version) => { +const _fixDeps = (deps: Record, version: string) => { SYNCED_DEPS.forEach((dep) => { const d = deps?.[dep]; if (d) { diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts index 4d6c2c6261..7ff366441c 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts @@ -195,7 +195,7 @@ const _waitForEmulatorToBeReady = (c: RnvConfig, target) => return devices.length > 0; }); -const _composeDevicesString = (devices) => +const _composeDevicesString = (devices: Array) => devices.map((device) => ({ key: device.id, name: device.name, @@ -208,7 +208,7 @@ const _composeDevicesString = (devices) => // } // }; -export const runTizenSimOrDevice = async (c: RnvConfig, buildCoreWebpackProject) => { +export const runTizenSimOrDevice = async (c: RnvConfig, buildCoreWebpackProject: () => Promise) => { const { hosted } = c.program; const { target, engine } = c.runtime; const { platform } = c; diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts b/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts index d6757603dd..ae6f9a4e10 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts @@ -16,6 +16,7 @@ import { CLI_WEBOS_ARES_SETUP_DEVICE, } from '../../constants'; import { isSystemWin, isUrlLocalhost } from '../../systemManager/utils'; +import { RnvConfig } from '../../configManager/types'; export const launchWebOSimulator = (c) => { logTask('launchWebOSimulator'); diff --git a/packages/rnv/src/core/sdkManager/installer.ts b/packages/rnv/src/core/sdkManager/installer.ts index df87431fc1..2d1dc06598 100644 --- a/packages/rnv/src/core/sdkManager/installer.ts +++ b/packages/rnv/src/core/sdkManager/installer.ts @@ -35,8 +35,9 @@ import { getRealPath, writeFileSync, fsExistsSync, fsReaddirSync, fsLstatSync } import { chalk, logTask, logWarning, logSuccess, logError, logInfo } from '../systemManager/logger'; import PlatformSetup from '../setupManager'; import { generateBuildConfig } from '../configManager'; +import { RnvConfig } from '../configManager/types'; -const SDK_LOCATIONS = { +const SDK_LOCATIONS: Record> = { android: [ path.join('/usr/local/android-sdk'), path.join(USER_HOME_DIR, 'Library/Android/sdk'), @@ -174,7 +175,7 @@ const _isSdkInstalled = (c) => { if (!SDK_PLATFORMS[c.platform]) return true; - const sdkPath = _getCurrentSdkPath(c, c.platform); + const sdkPath = _getCurrentSdkPath(c); return fsExistsSync(getRealPath(c, sdkPath)); }; @@ -197,7 +198,7 @@ const _findFolderWithFile = (dir, fileToFind) => { return foundDir; }; -const _attemptAutoFix = async (c: RnvConfig, sdkPlatform, sdkKey, traverseUntilFoundFile) => { +const _attemptAutoFix = async (c: RnvConfig, sdkPlatform: string, sdkKey: string, traverseUntilFoundFile: boolean) => { logTask('_attemptAutoFix'); if (c.program.hosted) { diff --git a/packages/rnv/src/core/systemManager/npmUtils.ts b/packages/rnv/src/core/systemManager/npmUtils.ts index a977cdc610..7c4881c0e1 100644 --- a/packages/rnv/src/core/systemManager/npmUtils.ts +++ b/packages/rnv/src/core/systemManager/npmUtils.ts @@ -110,7 +110,7 @@ export const listAndSelectNpmVersion = async (c: RnvConfig, npmPackage) => { }); versionArr.reverse(); - const validVersions = versionArr.map((v) => ({ name: v, value: v })); + const validVersions = versionArr.map((v: string) => ({ name: v, value: v })); let recommendedVersion; validVersions.forEach((item) => { diff --git a/packages/rnv/src/core/types.ts b/packages/rnv/src/core/types.ts index e921d54107..af603c7840 100644 --- a/packages/rnv/src/core/types.ts +++ b/packages/rnv/src/core/types.ts @@ -1,4 +1,4 @@ -export type RnvPlatform = string | boolean; +export type RnvPlatform = string; export type RnvModuleConfig = { modulePaths: Array; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts b/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts index 48f73c4566..d955545c22 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts @@ -21,7 +21,7 @@ import { RnvTaskFn } from '../../core/taskManager/types'; const iocane = require('iocane'); -const readdirAsync = promisify>(fsReaddir); +const readdirAsync = promisify(fsReaddir); const generateRandomKey = (length: number) => Array(length) @@ -66,9 +66,9 @@ RNV will create it for you, make sure you add whatever you want encrypted in it mkdirSync(path.join(sourceFolder, 'certs')); writeFileSync(path.join(sourceFolder, 'renative.private.json'), {}); - const appConfigsDirs = await readdirAsync(c.paths.project.appConfigsDir); + const appConfigsDirs: any = await readdirAsync(c.paths.project.appConfigsDir); - appConfigsDirs.forEach((item) => { + appConfigsDirs.forEach((item: string) => { const appConfigDir = path.join(sourceFolder, item); mkdirSync(appConfigDir); mkdirSync(path.join(appConfigDir, 'certs')); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.doctor.ts b/packages/rnv/src/engine-core/tasks/task.rnv.doctor.ts index b4936bc3d7..f34d94b469 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.doctor.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.doctor.ts @@ -8,7 +8,6 @@ import { validateRenativeJsonSchema, // validateRuntimeObjectSchema } from '../../core/schemaManager'; -import { RnvConfig } from '../../core/configManager/types'; import { RnvTaskFn } from '../../core/taskManager/types'; const configTargets = [ @@ -26,7 +25,7 @@ export const taskRnvDoctor: RnvTaskFn = async (c, parentTask, originTask) => { await executeTask(c, TASK_APP_CONFIGURE, parentTask, originTask); await configureRuntimeDefaults(c); - const configPaths = []; + const configPaths: Array = []; configTargets.forEach((target) => { const tPath = lGet(c.paths, target); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.new.ts b/packages/rnv/src/engine-core/tasks/task.rnv.new.ts index c87393a49f..7e746a015e 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.new.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.new.ts @@ -605,7 +605,7 @@ export const taskRnvNew = async (c: RnvConfig) => { ); }; -const findEngineKeyById = (c: RnvConfig, id) => { +const findEngineKeyById = (c: RnvConfig, id: string) => { const { engineTemplates } = c.files.rnv.projectTemplates.config; const etk = Object.keys(engineTemplates); for (let i = 0; i < etk.length; i++) { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.platform.configure.ts b/packages/rnv/src/engine-core/tasks/task.rnv.platform.configure.ts index 798c998406..e8ec0b87a8 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.platform.configure.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.platform.configure.ts @@ -9,8 +9,9 @@ import { executeTask, shouldSkipTask } from '../../core/taskManager'; import { PARAMS, TASK_PLATFORM_CONFIGURE, TASK_PROJECT_CONFIGURE, TASK_INSTALL } from '../../core/constants'; import { checkSdk } from '../../core/sdkManager/installer'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvPlatformConfigure = async (c: RnvConfig, parentTask, originTask) => { +export const taskRnvPlatformConfigure: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvPlatformConfigure', ''); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_PLATFORM_CONFIGURE, originTask); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.target.launch.ts b/packages/rnv/src/engine-core/tasks/task.rnv.target.launch.ts index d778b19543..1c50348f29 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.target.launch.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.target.launch.ts @@ -22,8 +22,9 @@ import { launchAndroidSimulator } from '../../core/sdkManager/deviceUtils/androi import { launchAppleSimulator } from '../../core/sdkManager/deviceUtils/apple'; import { launchKaiOSSimulator } from '../../core/sdkManager/deviceUtils/kaios'; import { executeTask } from '../../core/taskManager'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvTargetLaunch = async (c: RnvConfig, parentTask, originTask) => { +export const taskRnvTargetLaunch: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvTargetLaunch'); await isPlatformSupported(c, true); From 50874e1dfcd718ea669dd56e7176a08cfb47df26 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Wed, 30 Aug 2023 03:14:53 +0200 Subject: [PATCH 19/83] more ts refactor, 672 togo --- packages/rnv/src/core/configManager/types.ts | 14 ++++++ packages/rnv/src/core/pluginManager/index.ts | 45 ++++++++++++------- packages/rnv/src/core/projectManager/index.ts | 7 +-- packages/rnv/src/core/schemaManager/index.ts | 4 +- .../core/schemaManager/schemaRenativeJson.ts | 2 +- .../src/core/sdkManager/deviceUtils/webos.ts | 8 ++-- packages/rnv/src/core/setupManager/base.ts | 4 +- packages/rnv/src/core/setupManager/windows.ts | 9 ++-- .../rnv/src/core/systemManager/fileutils.ts | 6 +-- packages/rnv/src/core/systemManager/logger.ts | 4 +- .../rnv/src/core/systemManager/npmUtils.ts | 18 +++++--- packages/rnv/src/core/systemManager/types.ts | 5 ++- 12 files changed, 80 insertions(+), 46 deletions(-) diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index bd21633f02..8cffb6d827 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -9,6 +9,7 @@ export interface RnvConfig { _meta: { currentAppConfigId: string; }; + _refs: any; }; platform: RnvPlatform; process: any; @@ -17,6 +18,7 @@ export interface RnvConfig { systemPropsInjects: Array; _requiresNpmInstall?: boolean; buildPipes: Record Promise>>; + isBuildHooksReady: boolean; //======= _renativePluginCache: any; cli: any; @@ -71,6 +73,8 @@ export interface RnvConfig { isWebHosted: boolean; }; _skipPluginScopeWarnings: boolean; + skipBuildHooks: boolean; + isFirstRunAfterNew: boolean; }; paths: { GLOBAL_RNV_CONFIG: string; @@ -83,6 +87,7 @@ export interface RnvConfig { //ADDON dir?: string; config?: string; + dirs: Array; }; platformTemplates: Record; projectTemplates: Record; @@ -124,6 +129,7 @@ export interface RnvConfig { configs: Array; configsPrivate: Array; configsLocal: Array; + dir: string; }; //ADDON config: string; @@ -334,6 +340,13 @@ export type RenativeConfigFile = { version: string; } >; + plugins: Record< + string, + { + 'no-npm': boolean; + version: string; + } + >; currentTemplate: string; projectTemplates: object; paths: { @@ -343,6 +356,7 @@ export type RenativeConfigFile = { tasks: Array | Record; engineTemplates: Record; engines: Record; + pluginTemplates: Record; }; export type RenativeConfigBuildScheme = Record; diff --git a/packages/rnv/src/core/pluginManager/index.ts b/packages/rnv/src/core/pluginManager/index.ts index fcdff64467..763cc9dbfd 100644 --- a/packages/rnv/src/core/pluginManager/index.ts +++ b/packages/rnv/src/core/pluginManager/index.ts @@ -19,6 +19,9 @@ import { import { chalk, logDebug, logError, logInfo, logSuccess, logTask, logWarning } from '../systemManager/logger'; import { installPackageDependencies } from '../systemManager/npmUtils'; import { doResolve, doResolvePath } from '../systemManager/resolve'; +import { RnvConfig } from '../configManager/types'; +import { RnvPlatform } from '../types'; +import { ResolveOptions } from '../systemManager/types'; export const getPluginList = (c: RnvConfig, isUpdate = false) => { const output = { @@ -221,8 +224,8 @@ export const configurePlugins = async (c: RnvConfig) => { } const { isTemplate } = c.files.project.config; - const newDeps = {}; - const newDevDeps = {}; + const newDeps: Record = {}; + const newDevDeps: Record = {}; const { dependencies, devDependencies } = c.files.project.package; const ovMsg = isTemplate ? 'This is template. NO ACTION' : 'package.json will be overriden'; Object.keys(c.buildConfig.plugins).forEach((k) => { @@ -346,7 +349,7 @@ export const resolvePluginDependants = async (c: RnvConfig) => { return true; }; -const _resolvePluginDependencies = async (c: RnvConfig, key, keyScope, parentKey) => { +const _resolvePluginDependencies = async (c: RnvConfig, key: string, keyScope: string | null, parentKey: string) => { // IMPORTANT: Do not cache this valuse as they need to be refreshed every // round in case new plugin has been installed and c.buildConfig generated if (keyScope === null) { @@ -396,7 +399,12 @@ const _resolvePluginDependencies = async (c: RnvConfig, key, keyScope, parentKey return true; }; -export const parsePlugins = (c: RnvConfig, platform, pluginCallback, ignorePlatformObjectCheck) => { +export const parsePlugins = ( + c: RnvConfig, + platform: RnvPlatform, + pluginCallback, + ignorePlatformObjectCheck?: boolean +) => { logTask('parsePlugins'); if (c.buildConfig) { const includedPlugins = getConfigProp(c, platform, 'includedPlugins', []); @@ -461,7 +469,7 @@ export const loadPluginTemplates = async (c: RnvConfig) => { //This comes from project dependency let flexnPluginsPath = doResolve('@flexn/plugins'); - if (!fsExistsSync(flexnPluginsPath)) { + if (flexnPluginsPath && !fsExistsSync(flexnPluginsPath)) { //This comes from rnv built-in dependency (installed via npm) flexnPluginsPath = path.resolve(__dirname, '../../../node_modules/@flexn/plugins'); if (!fsExistsSync(flexnPluginsPath)) { @@ -472,6 +480,9 @@ export const loadPluginTemplates = async (c: RnvConfig) => { } } } + + if (!flexnPluginsPath) return Promise.reject(`flexnPluginsPath missing`); + const flexnPluginTemplatesPath = path.join(flexnPluginsPath, 'pluginTemplates'); const flexnPluginTemplates = readObjectSync(path.join(flexnPluginTemplatesPath, 'renative.plugins.json')); @@ -517,7 +528,7 @@ export const loadPluginTemplates = async (c: RnvConfig) => { const _parsePluginTemplateDependencies = (c: RnvConfig, customPluginTemplates, scope = 'root') => { logTask('_parsePluginTemplateDependencies', `scope:${scope}`); - const missingDeps = []; + const missingDeps: Array = []; if (customPluginTemplates) { Object.keys(customPluginTemplates).forEach((k) => { const val = customPluginTemplates[k]; @@ -572,9 +583,9 @@ const _parsePluginTemplateDependencies = (c: RnvConfig, customPluginTemplates, s // .replace(/\+/g, '\\+') // .replace(/ /g, ' {1,}'); // Alternative Regex seem more accurate -const getCleanRegExString = (str) => str.replace(/[-\\.,_*+?^$[\](){}!=|`]/gi, '\\$&'); +const getCleanRegExString = (str: string) => str.replace(/[-\\.,_*+?^$[\](){}!=|`]/gi, '\\$&'); -const _overridePlugin = (c: RnvConfig, pluginsPath, dir) => { +const _overridePlugin = (c: RnvConfig, pluginsPath: string, dir: string) => { const source = path.resolve(pluginsPath, dir, 'overrides'); const dest = doResolve(dir, false); if (!dest) return; @@ -608,11 +619,11 @@ const _overridePlugin = (c: RnvConfig, pluginsPath, dir) => { ); } - let overridePath; + let overridePath: string; if (plugin.version) { const pluginVerArr = plugin.version.split('.'); - const pluginVersions = []; - let prevVersion; + const pluginVersions: Array = []; + let prevVersion: string; pluginVerArr.forEach((v) => { if (prevVersion) { prevVersion = `${prevVersion}.${v}`; @@ -651,7 +662,7 @@ const _overridePlugin = (c: RnvConfig, pluginsPath, dir) => { } }; -export const overrideFileContents = (dest, override, overridePath = '') => { +export const overrideFileContents = (dest: string, override, overridePath = '') => { if (fsExistsSync(dest)) { let fileToFix = fsReadFileSync(dest).toString(); let foundRegEx = false; @@ -887,7 +898,7 @@ export const copyTemplatePluginsSync = (c) => { }); }; -export const sanitizePluginPath = (str, name, mandatory, options) => { +export const sanitizePluginPath = (str: string, name: string, mandatory: boolean, options: ResolveOptions) => { let newStr = str; try { if (str?.replace) { @@ -899,7 +910,7 @@ export const sanitizePluginPath = (str, name, mandatory, options) => { return newStr; }; -export const includesPluginPath = (str) => { +export const includesPluginPath = (str: string) => { if (str?.includes) { return str.includes('{{PLUGIN_ROOT}}'); } @@ -918,9 +929,9 @@ export const getLocalRenativePlugin = () => ({ }, }); -export const getModuleConfigs = (c: RnvConfig, primaryKey) => { +export const getModuleConfigs = (c: RnvConfig, primaryKey: string) => { let modulePaths = []; - const moduleAliases = {}; + const moduleAliases: Record = {}; const doNotResolveModulePaths = []; @@ -972,7 +983,7 @@ export const getModuleConfigs = (c: RnvConfig, primaryKey) => { true ); - const moduleAliasesArray = []; + const moduleAliasesArray: Array = []; Object.keys(moduleAliases).forEach((key) => { moduleAliasesArray.push(`${key}:${moduleAliases[key]}`); }); diff --git a/packages/rnv/src/core/projectManager/index.ts b/packages/rnv/src/core/projectManager/index.ts index 46b6a27125..913cd85b49 100644 --- a/packages/rnv/src/core/projectManager/index.ts +++ b/packages/rnv/src/core/projectManager/index.ts @@ -33,6 +33,7 @@ import { chalk, logTask, logWarning, logDebug, logInfo, getCurrentCommand } from import { configureTemplateFiles, configureEntryPoint } from '../templateManager'; import { parseRenativeConfigs } from '../configManager'; import { NpmPackageFile, RenativeConfigFile, RnvConfig } from '../configManager/types'; +import { RnvPlatform } from '../types'; export const checkAndBootstrapIfRequired = async (c: RnvConfig) => { logTask('checkAndBootstrapIfRequired'); @@ -425,7 +426,7 @@ const _resolvePackage = (c: RnvConfig, v) => { // return false; // }; -export const copyAssetsFolder = async (c: RnvConfig, platform, subPath, customFn) => { +export const copyAssetsFolder = async (c: RnvConfig, platform: RnvPlatform, subPath: string, customFn) => { logTask('copyAssetsFolder'); if (!isPlatformActive(c, platform)) return; @@ -462,7 +463,7 @@ export const copyAssetsFolder = async (c: RnvConfig, platform, subPath, customFn )}. Will be used to generate assets.` ); validAssetSources.forEach((sourcePath) => { - copyFolderContentsRecursiveSync(sourcePath, destPath, true, false, false, {}, tsPathsConfig, c); + copyFolderContentsRecursiveSync(sourcePath, destPath, true, undefined, false, {}, tsPathsConfig, c); }); return; } @@ -569,7 +570,7 @@ export const copyBuildsFolder = (c: RnvConfig, platform: string) => const sourcePath1sec = getBuildsFolder(c, platform, c.paths.workspace.project.appConfigBase.dir); copyFolderContentsRecursiveSync(sourcePath1sec, destPath, true, undefined, false, allInjects, tsPathsConfig); - if (fsExistsSync(sourcePath1secLegacy)) { + if (sourcePath1secLegacy && fsExistsSync(sourcePath1secLegacy)) { logWarning(`Path: ${chalk().red(sourcePath1secLegacy)} is DEPRECATED. Move your files to: ${chalk().white(sourcePath1sec)} instead`); } diff --git a/packages/rnv/src/core/schemaManager/index.ts b/packages/rnv/src/core/schemaManager/index.ts index daef180bb8..e040f0f916 100644 --- a/packages/rnv/src/core/schemaManager/index.ts +++ b/packages/rnv/src/core/schemaManager/index.ts @@ -6,13 +6,13 @@ const ajvRenativeJson = new Ajv({ schemas: SCHEMAS_RENATIVE_JSON, allErrors: tru const ajvRuntimeObject = new Ajv({ schemas: SCHEMAS_RUNTIME_OBJECT, allErrors: true, allowUnionTypes: true }); export const getRenativeJsonSchema = () => SCHEMAS_RENATIVE_JSON[0]; -export const validateRenativeJsonSchema = (cObj) => { +export const validateRenativeJsonSchema = (cObj: any) => { const valid = ajvRenativeJson.validate(SCHEMAS_RENATIVE_JSON[0], cObj); return [valid, ajvRenativeJson]; }; export const getRuntimeObjectSchema = () => SCHEMAS_RUNTIME_OBJECT[0]; -export const validateRuntimeObjectSchema = (cObj) => { +export const validateRuntimeObjectSchema = (cObj: any) => { const valid = ajvRuntimeObject.validate(SCHEMAS_RUNTIME_OBJECT[0], cObj); return [valid, ajvRuntimeObject]; }; diff --git a/packages/rnv/src/core/schemaManager/schemaRenativeJson.ts b/packages/rnv/src/core/schemaManager/schemaRenativeJson.ts index 9ae648daa3..0d53c14f08 100644 --- a/packages/rnv/src/core/schemaManager/schemaRenativeJson.ts +++ b/packages/rnv/src/core/schemaManager/schemaRenativeJson.ts @@ -956,7 +956,7 @@ const platformChromecastProps = { // BUILD SCHEME PROPS // ================================================== -const generateBuildSchemeProps = (obj) => ({ +const generateBuildSchemeProps = (obj: any) => ({ buildSchemes: { additionalProperties: { type: 'object', diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts b/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts index ae6f9a4e10..06a3362bd0 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts @@ -18,7 +18,7 @@ import { import { isSystemWin, isUrlLocalhost } from '../../systemManager/utils'; import { RnvConfig } from '../../configManager/types'; -export const launchWebOSimulator = (c) => { +export const launchWebOSimulator = (c: RnvConfig) => { logTask('launchWebOSimulator'); const availableEmulatorVersions = getDirectories( @@ -47,7 +47,7 @@ export const launchWebOSimulator = (c) => { // } // }; -const parseDevices = (c: RnvConfig, devicesResponse) => { +const parseDevices = (c: RnvConfig, devicesResponse: string) => { const linesArray = devicesResponse .split('\n') .slice(2) @@ -81,7 +81,7 @@ const parseDevices = (c: RnvConfig, devicesResponse) => { ); }; -const installAndLaunchApp = async (c: RnvConfig, target, appPath, tId) => { +const installAndLaunchApp = async (c: RnvConfig, target: string, appPath: string, tId: string) => { try { await execCLI(c, CLI_WEBOS_ARES_INSTALL, `--device ${target} ${appPath}`); } catch (e) { @@ -137,7 +137,7 @@ export const runWebosSimOrDevice = async (c: RnvConfig) => { const configFilePath = path.join(tDir, 'appinfo.json'); // logTask(`runWebOS:${target}:${isHosted}`, chalk().grey); - const cnfg = JSON.parse(fsReadFileSync(configFilePath, 'utf-8')); + const cnfg = JSON.parse(fsReadFileSync(configFilePath).toString()); const tId = cnfg.id; const appPath = path.join(tOut, `${tId}_${cnfg.version}_all.ipk`); diff --git a/packages/rnv/src/core/setupManager/base.ts b/packages/rnv/src/core/setupManager/base.ts index d1372628a1..3926f45599 100644 --- a/packages/rnv/src/core/setupManager/base.ts +++ b/packages/rnv/src/core/setupManager/base.ts @@ -95,7 +95,7 @@ class BasePlatformSetup { await shell.exec(command); } - async unzipSdk(sdk) { + async unzipSdk(sdk: string) { logDebug(`Unzipping from ${setupConfig[sdk].downloadLocation} to ${setupConfig[sdk].location}`); if (!commandExistsSync('unzip')) { throw new Error('unzip is not installed'); @@ -183,7 +183,7 @@ class BasePlatformSetup { return true; } - async askToInstallSDK(sdk) { + async askToInstallSDK(sdk: string) { let sdkInstall; if (!this.c.program.ci) { const response = await inquirer.prompt([ diff --git a/packages/rnv/src/core/setupManager/windows.ts b/packages/rnv/src/core/setupManager/windows.ts index c97060f27e..98873d47ce 100644 --- a/packages/rnv/src/core/setupManager/windows.ts +++ b/packages/rnv/src/core/setupManager/windows.ts @@ -9,9 +9,12 @@ import { logInfo, logDebug } from '../systemManager/logger'; import { replaceHomeFolder, fsExistsSync } from '../systemManager/fileutils'; import BasePlatformSetup from './base'; import setupConfig from './config'; +import { RnvConfig } from '../configManager/types'; class LinuxPlatformSetup extends BasePlatformSetup { - constructor(c) { + scoopInstalled: boolean; + + constructor(c: RnvConfig) { super('win32', c); this.scoopInstalled = false; } @@ -29,13 +32,13 @@ class LinuxPlatformSetup extends BasePlatformSetup { } } - async installSoftware(software) { + async installSoftware(software: string) { await shell.exec(replaceHomeFolder(`~/scoop/shims/scoop install ${software}`)); await this.reloadPathEnv(); return true; } - addScoopBucket(bucket) { + addScoopBucket(bucket: string) { return shell.exec(replaceHomeFolder(`~/scoop/shims/scoop bucket add ${bucket}`)); } diff --git a/packages/rnv/src/core/systemManager/fileutils.ts b/packages/rnv/src/core/systemManager/fileutils.ts index a6982c9ea7..0554f3601d 100755 --- a/packages/rnv/src/core/systemManager/fileutils.ts +++ b/packages/rnv/src/core/systemManager/fileutils.ts @@ -49,13 +49,13 @@ export const fsSymlinkSync = (arg1: fs.PathLike, arg2: fs.PathLike) => { fs.symlinkSync(arg1, arg2); }; -export const fsReadFile = (arg1: fs.PathLike, arg2) => { +export const fsReadFile = (arg1: fs.PathLike, arg2: any) => { fs.readFile(arg1, arg2); }; -export const fsReaddir = (arg1: fs.PathLike, arg2) => fs.readdir(arg1, arg2); +export const fsReaddir = (arg1: fs.PathLike, arg2: any) => fs.readdir(arg1, arg2); -const _getSanitizedPath = (origPath: fs.PathLike, timestampPathsConfig: TimestampPathsConfig) => { +const _getSanitizedPath = (origPath: string, timestampPathsConfig: TimestampPathsConfig) => { if (timestampPathsConfig?.paths?.length && timestampPathsConfig?.timestamp) { const pths = timestampPathsConfig.paths; if (pths.includes(origPath)) { diff --git a/packages/rnv/src/core/systemManager/logger.ts b/packages/rnv/src/core/systemManager/logger.ts index 0dbc16eea5..2724c3f835 100644 --- a/packages/rnv/src/core/systemManager/logger.ts +++ b/packages/rnv/src/core/systemManager/logger.ts @@ -101,7 +101,7 @@ const cnf = () => { return _c; }; -const _configureLogger = (c: RnvConfig, analytics) => { +const _configureLogger = (c: RnvConfig, analytics: AnalyticsApi) => { global._messages = []; _c = c; if (!global.timeStart) global.timeStart = new Date(); @@ -143,7 +143,7 @@ export const getCurrentCommand = (excludeDollar = false) => { const argArr = cnf().process.argv.slice(2); let hideNext = false; const output = argArr - .map((v) => { + .map((v: string) => { if (hideNext) { hideNext = false; return '********'; diff --git a/packages/rnv/src/core/systemManager/npmUtils.ts b/packages/rnv/src/core/systemManager/npmUtils.ts index 7c4881c0e1..828dd6b7d0 100644 --- a/packages/rnv/src/core/systemManager/npmUtils.ts +++ b/packages/rnv/src/core/systemManager/npmUtils.ts @@ -92,7 +92,7 @@ export const checkAndCreateProjectPackage = async (c: RnvConfig) => { export const areNodeModulesInstalled = () => !!doResolve('resolve', false); -export const listAndSelectNpmVersion = async (c: RnvConfig, npmPackage) => { +export const listAndSelectNpmVersion = async (c: RnvConfig, npmPackage: string) => { const templateVersionsStr = await executeAsync(c, `npm view ${npmPackage} versions`); const versionArr = templateVersionsStr.replace(/\r?\n|\r|\s|'|\[|\]/g, '').split(','); @@ -297,13 +297,17 @@ export const cleanNodeModules = () => 'react-native-safe-area-view/.git', '@react-navigation/native/node_modules/react-native-safe-area-view/.git', 'react-navigation/node_modules/react-native-safe-area-view/.git', - ].reduce((acc, dir) => { - const [_all, aPackage, aPath] = dir.match(/([^/]+)\/(.*)/); - logDebug(`Cleaning: ${_all}`); - const resolved = doResolve(aPackage, false); - if (resolved) { - acc.push(`${resolved}/${aPath}`); + ].reduce>((acc, dir) => { + const res = dir.match(/([^/]+)\/(.*)/); + if (res) { + const [_all, aPackage, aPath] = res; + logDebug(`Cleaning: ${_all}`); + const resolved = doResolve(aPackage, false); + if (resolved) { + acc.push(`${resolved}/${aPath}`); + } } + return acc; }, []); removeDirs(dirs) diff --git a/packages/rnv/src/core/systemManager/types.ts b/packages/rnv/src/core/systemManager/types.ts index b05620dfda..7b1c412ff9 100644 --- a/packages/rnv/src/core/systemManager/types.ts +++ b/packages/rnv/src/core/systemManager/types.ts @@ -42,6 +42,7 @@ export type OverridesOptions = Array<{ export type TimestampPathsConfig = { timestamp: Array; + paths: Array; }; export type RnvCLI = Record; @@ -49,8 +50,8 @@ export type RnvCLI = Record; export type FileUtilsPropConfig = { props: Record; configProps?: Record; - runtimeProps?: Record; - files: Array; + runtimeProps?: Record; + files: Record; }; export type FileUtilsUpdateConfig = { From a548e025f8e3f6c97b8331574dec88cf60826dec Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Wed, 30 Aug 2023 04:45:18 +0200 Subject: [PATCH 20/83] more ts refactor, 553 togo --- packages/rnv/src/cli/prompt.ts | 7 ++-- packages/rnv/src/cli/types.ts | 2 +- packages/rnv/src/core/configManager/index.ts | 33 +++++++++++-------- .../src/core/configManager/packageParser.ts | 6 ++-- packages/rnv/src/core/configManager/types.ts | 23 +++++++++++-- packages/rnv/src/core/engineManager/types.ts | 6 ++++ .../rnv/src/core/platformManager/index.ts | 4 +-- packages/rnv/src/core/pluginManager/index.ts | 4 +-- .../rnv/src/core/projectManager/buildHooks.ts | 3 +- packages/rnv/src/core/systemManager/exec.ts | 18 ++++++---- .../rnv/src/core/systemManager/fileutils.ts | 17 +++++++--- .../rnv/src/core/systemManager/npmUtils.ts | 4 +-- packages/rnv/src/core/systemManager/types.ts | 2 +- packages/rnv/src/core/systemManager/utils.ts | 10 ++++-- packages/rnv/src/core/taskManager/index.ts | 29 ++++++++++++---- packages/rnv/src/core/taskManager/types.ts | 1 + .../rnv/src/core/templateManager/index.ts | 30 +++++++++-------- .../rnv/src/engine-core/tasks/task.rnv.pkg.ts | 3 +- .../tasks/task.rnv.platform.configure.ts | 2 +- .../tasks/task.rnv.platform.connect.ts | 5 +-- .../tasks/task.rnv.workspace.add.ts | 2 +- .../tasks/task.rnv.workspace.connect.ts | 3 +- packages/rnv/src/typings/modules.d.ts | 1 + 23 files changed, 144 insertions(+), 71 deletions(-) diff --git a/packages/rnv/src/cli/prompt.ts b/packages/rnv/src/cli/prompt.ts index 61e0f13541..e445f4e247 100644 --- a/packages/rnv/src/cli/prompt.ts +++ b/packages/rnv/src/cli/prompt.ts @@ -3,9 +3,9 @@ import { chalk, logWarning, logTask, logDebug } from '../core/systemManager/logg import Config from '../core/configManager/config'; import { PromptOptions, PromptParams, PromptRenderFn } from './types'; -export const inquirerPrompt = async (params: PromptParams): Promise => { +export const inquirerPrompt = async (params: PromptParams): Promise> => { const c = Config.getConfig(); - if (c.program?.yes) return true; + if (c.program?.yes) return {}; const msg = params.logMessage || params.warningMessage || params.message; if (c.program?.ci) { @@ -15,7 +15,8 @@ export const inquirerPrompt = async (params: PromptParams): Promise => { params.choices.includes(params.default) ) { logDebug(`defaulting to choice '${params.default}' for prompt '${params.name}'`); - return Promise.resolve({ [params.name]: params.default }); + + if (params.name) return Promise.resolve({ [params.name]: params.default }); } return Promise.reject(`--ci option does not allow prompts. question: ${msg}.`); } diff --git a/packages/rnv/src/cli/types.ts b/packages/rnv/src/cli/types.ts index d7e7390b5a..d0bacdfd11 100644 --- a/packages/rnv/src/cli/types.ts +++ b/packages/rnv/src/cli/types.ts @@ -16,7 +16,7 @@ export type PromptParams = { name?: string; type: string; pageSize?: number; - validate?: (i: string) => string; + validate?: (i: string) => string | boolean; }; export type PromptRenderFn = (i: number, obj: any, mapping: any, defaultVal: string) => string; diff --git a/packages/rnv/src/core/configManager/index.ts b/packages/rnv/src/core/configManager/index.ts index 61778e1442..5265374cf6 100644 --- a/packages/rnv/src/core/configManager/index.ts +++ b/packages/rnv/src/core/configManager/index.ts @@ -89,7 +89,7 @@ const getEnginesPluginDelta = (c: RnvConfig) => { return enginePlugins; }; -export const writeRenativeConfigFile = (c: RnvConfig, configPath: string, configData: string) => { +export const writeRenativeConfigFile = (c: RnvConfig, configPath: string, configData: string | object) => { logDebug(`writeRenativeConfigFile:${configPath}`); writeFileSync(configPath, configData); generateBuildConfig(c); @@ -241,22 +241,27 @@ export const loadFileExtended = ( } } if (currTemplate) { - let extendsPath; - if (extendsTemplate.startsWith(currTemplate)) { - extendsPath = path.join(doResolve(currTemplate), extendsTemplate.replace(currTemplate, '')); - } else { - extendsPath = path.join(doResolve(currTemplate), extendsTemplate); - } + const currTemplateRes = doResolve(currTemplate); + if (currTemplateRes) { + let extendsPath; + if (extendsTemplate.startsWith(currTemplate)) { + extendsPath = path.join(currTemplateRes, extendsTemplate.replace(currTemplate, '')); + } else { + extendsPath = path.join(currTemplateRes, extendsTemplate); + } - if (fsExistsSync(extendsPath)) { - const extendsFile = readObjectSync(extendsPath); + if (fsExistsSync(extendsPath)) { + const extendsFile = readObjectSync(extendsPath); - fileObj[key] = mergeObjects(c, extendsFile, fileObj[key], false, true); - // CLEAN props which should not be inherited - delete fileObj[key].isTemplate; - delete fileObj[key].tasks; + fileObj[key] = mergeObjects(c, extendsFile, fileObj[key], false, true); + // CLEAN props which should not be inherited + delete fileObj[key].isTemplate; + delete fileObj[key].tasks; + } else { + logWarning(`You are trying to extend config file with ${extendsPath} does not exists. SKIPPING.`); + } } else { - logWarning(`You are trying to extend config file with ${extendsPath} does not exists. SKIPPING.`); + logWarning(`Cannot resolve currentTemplate ${currTemplate} `); } } } diff --git a/packages/rnv/src/core/configManager/packageParser.ts b/packages/rnv/src/core/configManager/packageParser.ts index ba2b97ca47..206dc07726 100644 --- a/packages/rnv/src/core/configManager/packageParser.ts +++ b/packages/rnv/src/core/configManager/packageParser.ts @@ -37,7 +37,7 @@ const injectProjectDependency = async ( export const checkRequiredPackage = async ( c: RnvConfig, pkg: string, - version = false, + version = '', type: DependencyType = 'dependencies', skipAsking = false, skipInstall = false, @@ -61,7 +61,7 @@ export const checkRequiredPackage = async ( if (confirm) { let latestVersion = 'latest'; - if (!version && !skipVersionCheck) { + if (version === '' && !skipVersionCheck) { try { latestVersion = await executeAsync(`npm show ${pkg} version`); // eslint-disable-next-line no-empty @@ -69,7 +69,7 @@ export const checkRequiredPackage = async ( } return injectProjectDependency(c, pkg, version || latestVersion, type, skipInstall); } - } else if (!version) { + } else if (version === '') { // package exists, checking version only if version is not const currentVersion = projectConfig.package[type][pkg]; let latestVersion; diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index 8cffb6d827..b9bdb1abe7 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -1,4 +1,5 @@ import { RnvEngine } from '../engineManager/types'; +import { OverridesOptions } from '../systemManager/types'; import { RnvPlatform } from '../types'; export interface RnvConfig { @@ -11,6 +12,7 @@ export interface RnvConfig { }; _refs: any; }; + assetConfig: object; platform: RnvPlatform; process: any; rnvVersion: string; @@ -19,6 +21,8 @@ export interface RnvConfig { _requiresNpmInstall?: boolean; buildPipes: Record Promise>>; isBuildHooksReady: boolean; + supportedPlatforms: Array; + runtimePropsInjects: OverridesOptions; //======= _renativePluginCache: any; cli: any; @@ -39,7 +43,9 @@ export interface RnvConfig { enginesById: Record; missingEnginePlugins: Record; localhost: string; - scheme: string; + scheme: { + bundleAssets: boolean; + }; bundleAssets: boolean; activeTemplate: string; engine: any; @@ -65,16 +71,20 @@ export interface RnvConfig { forceBuildHookRebuild: boolean; disableReset: boolean; skipActiveServerCheck: boolean; - port: number; + port: string; rnvVersionRunner: string; rnvVersionProject: string; versionCheckCompleted: boolean; currentPlatform: { isWebHosted: boolean; + defaultPort: string; }; _skipPluginScopeWarnings: boolean; skipBuildHooks: boolean; isFirstRunAfterNew: boolean; + currentEngine: RnvEngine; + hosted: boolean; + task: string; }; paths: { GLOBAL_RNV_CONFIG: string; @@ -206,7 +216,7 @@ export interface RnvConfig { appConfigsDir: string; configTemplate: string; config: string; - dir?: string; + dir: string; }; appConfigBase: string; }; @@ -322,16 +332,19 @@ export type RenativeConfigFile = { workspaceID: string; common: { buildSchemes: Record; + runtime: Record; }; defaults: { ports: Record; supportedPlatforms: Array; + portOffset: number; }; platforms: Record< string, { buildSchemes: Record; entryFile?: string; + runtime: Record; } >; templates: Record< @@ -349,14 +362,18 @@ export type RenativeConfigFile = { >; currentTemplate: string; projectTemplates: object; + platformTemplatesDirs: Record; paths: { appConfigsDirs: Array; + platformTemplatesDirs: Record; }; integrations: Record; tasks: Array | Record; engineTemplates: Record; engines: Record; pluginTemplates: Record; + runtime: Record; + defaultTargets: Record; }; export type RenativeConfigBuildScheme = Record; diff --git a/packages/rnv/src/core/engineManager/types.ts b/packages/rnv/src/core/engineManager/types.ts index 8cd7015669..4048805745 100644 --- a/packages/rnv/src/core/engineManager/types.ts +++ b/packages/rnv/src/core/engineManager/types.ts @@ -1,11 +1,17 @@ +import { RnvTaskMap } from '../taskManager/types'; + export type RnvEngine = { + originalTemplatePlatformsDir: string; + platforms: any; config: RnvEngineConfig; + tasks: RnvTaskMap; }; export type RnvEngineConfig = { id: string; platforms: any; npm: any; + plugins: any; }; export type RnvEngineConfigMap = Record; diff --git a/packages/rnv/src/core/platformManager/index.ts b/packages/rnv/src/core/platformManager/index.ts index d41f62a0c8..1ed2570199 100644 --- a/packages/rnv/src/core/platformManager/index.ts +++ b/packages/rnv/src/core/platformManager/index.ts @@ -63,7 +63,7 @@ export const createPlatformBuild = (c: RnvConfig, platform: string) => new Promise((resolve, reject) => { logTask('createPlatformBuild'); - if (!isPlatformSupportedSync(c, platform, null, reject)) return; + if (!isPlatformSupportedSync(c, platform, undefined, reject)) return; const pPath = getAppFolder(c); const ptPath = path.join(c.paths.project.platformTemplatesDirs[platform], `${platform}`); @@ -183,7 +183,7 @@ export const isPlatformActive = (c: RnvConfig, platform: string, resolve?: () => } return true; }; -export const copySharedPlatforms = (c) => +export const copySharedPlatforms = (c: RnvConfig) => new Promise((resolve) => { logTask('copySharedPlatforms'); diff --git a/packages/rnv/src/core/pluginManager/index.ts b/packages/rnv/src/core/pluginManager/index.ts index 763cc9dbfd..7f11aaa305 100644 --- a/packages/rnv/src/core/pluginManager/index.ts +++ b/packages/rnv/src/core/pluginManager/index.ts @@ -111,7 +111,7 @@ const _getPluginScope = (plugin) => { return { scope: 'rnv' }; }; -export const getMergedPlugin = (c: RnvConfig, key) => { +export const getMergedPlugin = (c: RnvConfig, key: string) => { logDebug(`getMergedPlugin:${key}`); const plugin = c.buildConfig.plugins?.[key]; @@ -327,7 +327,7 @@ ${ovMsg}` return true; }; -const _updatePackage = (c: RnvConfig, override) => { +const _updatePackage = (c: RnvConfig, override: any) => { const newPackage = merge(c.files.project.package, override); writeRenativeConfigFile(c, c.paths.project.package, newPackage); c.files.project.package = newPackage; diff --git a/packages/rnv/src/core/projectManager/buildHooks.ts b/packages/rnv/src/core/projectManager/buildHooks.ts index 510d94f412..9116eadabd 100644 --- a/packages/rnv/src/core/projectManager/buildHooks.ts +++ b/packages/rnv/src/core/projectManager/buildHooks.ts @@ -5,8 +5,9 @@ import { logDebug, logHook, logInfo } from '../systemManager/logger'; import { fsExistsSync, copyFolderContentsRecursiveSync } from '../systemManager/fileutils'; import { getConfigProp } from '../common'; import { doResolve } from '../systemManager/resolve'; +import { RnvConfig } from '../configManager/types'; -export const executePipe = async (c: RnvConfig, key) => { +export const executePipe = async (c: RnvConfig, key: string) => { logHook('executePipe', c?.program?.json ? key : `('${key}')`); await buildHooks(c); diff --git a/packages/rnv/src/core/systemManager/exec.ts b/packages/rnv/src/core/systemManager/exec.ts index 75e9e1da82..9a0544b6c4 100755 --- a/packages/rnv/src/core/systemManager/exec.ts +++ b/packages/rnv/src/core/systemManager/exec.ts @@ -12,6 +12,7 @@ import { fsExistsSync } from './fileutils'; import { replaceOverridesInString } from './utils'; import { RnvConfig } from '../configManager/types'; import { ExecCallback, ExecCallback2, ExecOptions } from './types'; +import { RnvError } from '../types'; const { exec, execSync } = require('child_process'); @@ -68,7 +69,7 @@ const _execute = (c: RnvConfig, command: string, opts: ExecOptions = {}) => { cleanCommand += cleanRawCmd.join(' '); let logMessage = cleanCommand; - const { privateParams } = mergedOpts; + const privateParams = mergedOpts.privateParams || []; if (privateParams && Array.isArray(privateParams)) { logMessage = replaceOverridesInString(command, privateParams, privateMask); } @@ -99,11 +100,11 @@ const _execute = (c: RnvConfig, command: string, opts: ExecOptions = {}) => { const printLastLine = (buffer: WithImplicitCoercion) => { const text = Buffer.from(buffer).toString().trim(); - const lastLine = text.split('\n').pop(); + const lastLine = text.split('\n').pop() || ''; if (spinner !== false) { spinner.text = replaceOverridesInString( lastLine?.substring(0, MAX_OUTPUT_LENGTH), - privateParams, + privateParams || [], privateMask ); } @@ -144,7 +145,7 @@ const _execute = (c: RnvConfig, command: string, opts: ExecOptions = {}) => { // logDebug(err); if (ignoreErrors && !silent && !mono && !!spinner) { spinner.succeed(`Executing: ${logMessage}`); - return true; + return ''; } let errMessage = parseErrorMessage(err.all, maxErrorLength); @@ -216,7 +217,12 @@ const execCLI = (c: RnvConfig, cli: string, command: string, opts: ExecOptions = * @returns {Promise} * */ -const executeAsync = async (_c: RnvConfig | string, _cmd?: string | ExecOptions, _opts?: ExecOptions) => { + +const executeAsync = async ( + _c: RnvConfig | string, + _cmd?: string | ExecOptions, + _opts?: ExecOptions +): Promise => { // swap values if c is not specified and get it from it's rightful place, config :) let c: RnvConfig; let cmd = ''; @@ -284,7 +290,7 @@ const executeTelnet = (c: RnvConfig, port: string, command: string) => if (output.includes('OK')) nc2.close(); }); nc2.on('close', () => resolve(output)); - } catch (e) { + } catch (e: RnvError) { logError(e); resolve(true); } diff --git a/packages/rnv/src/core/systemManager/fileutils.ts b/packages/rnv/src/core/systemManager/fileutils.ts index 0554f3601d..f468e3ce63 100755 --- a/packages/rnv/src/core/systemManager/fileutils.ts +++ b/packages/rnv/src/core/systemManager/fileutils.ts @@ -8,6 +8,7 @@ import ncp from 'ncp'; import { chalk, logDebug, logError, logWarning } from './logger'; import { RnvConfig } from '../configManager/types'; import { FileUtilsPropConfig, FileUtilsUpdateConfig, OverridesOptions, TimestampPathsConfig } from './types'; +import type { RnvError } from '../types'; export const configureFilesystem = (_getConfigProp: () => string, _doResolve: () => any, _isSystemWin: boolean) => { global.getConfigProp = _getConfigProp; @@ -55,7 +56,7 @@ export const fsReadFile = (arg1: fs.PathLike, arg2: any) => { export const fsReaddir = (arg1: fs.PathLike, arg2: any) => fs.readdir(arg1, arg2); -const _getSanitizedPath = (origPath: string, timestampPathsConfig: TimestampPathsConfig) => { +const _getSanitizedPath = (origPath: string, timestampPathsConfig?: TimestampPathsConfig) => { if (timestampPathsConfig?.paths?.length && timestampPathsConfig?.timestamp) { const pths = timestampPathsConfig.paths; if (pths.includes(origPath)) { @@ -101,7 +102,13 @@ export const copyFileSync = ( }; const SKIP_INJECT_EXTENSIONS = ['.jpg', '.jpeg', '.png', '.svg', '.jar', '.zip', '.ico']; -export const writeCleanFile = (source: string, destination: string, overrides, timestampPathsConfig, c) => { +export const writeCleanFile = ( + source: string, + destination: string, + overrides?: OverridesOptions, + timestampPathsConfig?: TimestampPathsConfig, + c?: RnvConfig +) => { // logTask(`writeCleanFile`) // console.log('writeCleanFile', destination); if (!fs.existsSync(source)) { @@ -374,7 +381,7 @@ export const removeFilesSync = (filePaths: Array) => { } else { logDebug(`Path ${filePath} does not exist`); } - } catch (e) { + } catch (e: RnvError) { logError(e); } }); @@ -605,7 +612,7 @@ export const resolvePackage = (text: string) => { return newText; }; -export const sanitizeDynamicProps = (obj: Record, propConfig: FileUtilsPropConfig) => { +export const sanitizeDynamicProps = (obj: any, propConfig: FileUtilsPropConfig): any => { if (!obj) { return obj; } @@ -730,7 +737,7 @@ export const getFileListSync = (dir: fs.PathLike) => { return results; }; -export const loadFile = (fileObj: any, pathObj: Record, key: string) => { +export const loadFile = (fileObj: any, pathObj: Record, key: string) => { const pKey = `${key}Exists`; const pth = pathObj[key]; diff --git a/packages/rnv/src/core/systemManager/npmUtils.ts b/packages/rnv/src/core/systemManager/npmUtils.ts index 828dd6b7d0..aeaa69acad 100644 --- a/packages/rnv/src/core/systemManager/npmUtils.ts +++ b/packages/rnv/src/core/systemManager/npmUtils.ts @@ -20,7 +20,7 @@ import { getConfigProp } from '../common'; import { RnvConfig } from '../configManager/types'; import { RnvError } from '../types'; -const packageJsonIsValid = (c) => { +const packageJsonIsValid = (c: RnvConfig) => { if (!fsExistsSync(c.paths.project.package)) return false; const pkg = readObjectSync(c.paths.project.package); if (!pkg) return false; @@ -34,7 +34,7 @@ export const checkNpxIsInstalled = async () => { if (!commandExistsSync('npx')) { logWarning('npx is not installed, please install it before running this command'); - const { confirm } = inquirerPrompt({ + const { confirm } = await inquirerPrompt({ type: 'confirm', message: 'Do you want to install npx it now?', }); diff --git a/packages/rnv/src/core/systemManager/types.ts b/packages/rnv/src/core/systemManager/types.ts index 7b1c412ff9..eb2df0bb50 100644 --- a/packages/rnv/src/core/systemManager/types.ts +++ b/packages/rnv/src/core/systemManager/types.ts @@ -51,7 +51,7 @@ export type FileUtilsPropConfig = { props: Record; configProps?: Record; runtimeProps?: Record; - files: Record; + files?: Record; }; export type FileUtilsUpdateConfig = { diff --git a/packages/rnv/src/core/systemManager/utils.ts b/packages/rnv/src/core/systemManager/utils.ts index 294ed048f2..3d1f2f9a4f 100644 --- a/packages/rnv/src/core/systemManager/utils.ts +++ b/packages/rnv/src/core/systemManager/utils.ts @@ -7,7 +7,8 @@ export const isSystemLinux = process.platform === 'linux'; export const isSystemWin = process.platform === 'win32'; -export const replaceOverridesInString = (string: string, overrides: Array, mask: string) => { +export const replaceOverridesInString = (string: string | undefined, overrides: Array, mask: string) => { + if (!string) return ''; let replacedString = string; if (overrides?.length && replacedString?.replace) { overrides.forEach((v) => { @@ -39,7 +40,12 @@ export const isUrlLocalhost = (value: string) => { return false; }; -export const getScopedVersion = (c: RnvConfig, key: string, val: RenativeConfigVersion, sourceObjKey: string) => { +export const getScopedVersion = ( + c: RnvConfig, + key: string, + val: RenativeConfigVersion, + sourceObjKey: 'engineTemplates' | 'plugins' +) => { if (typeof val === 'string') { if (val.startsWith('source:')) { const sourceObj = c.buildConfig?.[sourceObjKey]; diff --git a/packages/rnv/src/core/taskManager/index.ts b/packages/rnv/src/core/taskManager/index.ts index 48f87b342a..d5b91bc5cf 100644 --- a/packages/rnv/src/core/taskManager/index.ts +++ b/packages/rnv/src/core/taskManager/index.ts @@ -25,7 +25,7 @@ export const registerCustomTask = async (_c: RnvConfig, task: RnvTask) => { } }; -export const initializeTask = async (c: RnvConfig, task) => { +export const initializeTask = async (c: RnvConfig, task: string) => { logTask('initializeTask', task); c.runtime.task = task; executedTasks = {}; @@ -39,7 +39,13 @@ export const initializeTask = async (c: RnvConfig, task) => { return true; }; -const _getTaskOption = ({ taskInstance, hasMultipleSubTasks }) => { +const _getTaskOption = ({ + taskInstance, + hasMultipleSubTasks, +}: { + taskInstance: RnvTask; + hasMultipleSubTasks: boolean; +}) => { if (hasMultipleSubTasks) { return `${taskInstance.task.split(' ')[0]}...`; } @@ -49,7 +55,7 @@ const _getTaskOption = ({ taskInstance, hasMultipleSubTasks }) => { return `${taskInstance.task.split(' ')[0]}`; }; -const _getTaskObj = (taskInstance) => { +const _getTaskObj = (taskInstance: RnvTask) => { const key = taskInstance.task.split(' ')[0]; let hasMultipleSubTasks = false; if (taskInstance.task.includes(' ')) hasMultipleSubTasks = true; @@ -63,7 +69,7 @@ const _getTaskObj = (taskInstance) => { export const findSuitableTask = async (c: RnvConfig, specificTask?: string) => { logTask('findSuitableTask'); const REGISTERED_ENGINES = getRegisteredEngines(c); - let task: string; + let task: string = ''; if (!specificTask) { if (!c.command) { const suitableTaskInstances = {}; @@ -106,7 +112,7 @@ export const findSuitableTask = async (c: RnvConfig, specificTask?: string) => { }); c.command = tasksCommands[tasks.indexOf(command)]; } - task = c.command; + if (c.command) task = c.command; if (c.subCommand) task += ` ${c.subCommand}`; let suitableEngines = REGISTERED_ENGINES.filter((engine) => @@ -124,7 +130,10 @@ export const findSuitableTask = async (c: RnvConfig, specificTask?: string) => { if (!suitableEngines.length) { // Get all supported tasks - const supportedSubtasksArr = []; + const supportedSubtasksArr: Array<{ + desc: string; + taskKey: string; + }> = []; REGISTERED_ENGINES.forEach((engine) => { getEngineSubTasks(task, engine.tasks).forEach((taskInstance) => { const isNotViable = !c.paths.project.configExists && !taskInstance.isGlobalScope; @@ -151,7 +160,13 @@ export const findSuitableTask = async (c: RnvConfig, specificTask?: string) => { }); const supportedSubtasks = {}; // Normalize task options - const supportedSubtasksFilter = {}; + const supportedSubtasksFilter: Record< + string, + { + desc: string; + taskKey: string; + } + > = {}; supportedSubtasksArr.forEach((tsk) => { const mergedTask = supportedSubtasksFilter[tsk.taskKey]; if (!mergedTask) { diff --git a/packages/rnv/src/core/taskManager/types.ts b/packages/rnv/src/core/taskManager/types.ts index da718aca60..af6e78e79b 100644 --- a/packages/rnv/src/core/taskManager/types.ts +++ b/packages/rnv/src/core/taskManager/types.ts @@ -5,6 +5,7 @@ export type RnvTask = { params: Array; isGlobalScope: boolean; platforms: Array; + description: string; }; export type RnvTaskParameter = { diff --git a/packages/rnv/src/core/templateManager/index.ts b/packages/rnv/src/core/templateManager/index.ts index a09bd35b54..e7e7272ae6 100644 --- a/packages/rnv/src/core/templateManager/index.ts +++ b/packages/rnv/src/core/templateManager/index.ts @@ -22,6 +22,7 @@ import { doResolve } from '../systemManager/resolve'; import { checkIfProjectAndNodeModulesExists } from '../systemManager/npmUtils'; import { RnvConfig } from '../configManager/types'; import { RnvError } from '../types'; +import { PromptOptions } from '../../cli/types'; export const checkIfTemplateConfigured = async (c: RnvConfig) => { logTask('checkIfTemplateConfigured'); @@ -326,13 +327,13 @@ export const getTemplateOptions = (c: RnvConfig, isGlobalScope?: boolean) => { }); }; -export const getInstalledTemplateOptions = (c: RnvConfig) => { - if (c.files.project.config.isTemplate) return []; +export const getInstalledTemplateOptions = (c: RnvConfig): PromptOptions | null => { + if (c.files.project.config.isTemplate) return null; if (c.buildConfig.templates) { return generateOptions(c.buildConfig.templates); } logError("You don't have any local templates installed", false, true); - return []; + return null; }; export const isTemplateInstalled = (c: RnvConfig) => @@ -348,16 +349,19 @@ export const applyTemplate = async (c: RnvConfig, selectedTemplate?: string) => logWarning("You don't have any current template selected"); const opts = getInstalledTemplateOptions(c); - const { template } = await inquirer.prompt({ - type: 'list', - name: 'template', - message: 'Pick which template to apply', - choices: opts.keysAsArray, - }); - - c.buildConfig.currentTemplate = template; - c.files.project.config.currentTemplate = template; - _writeObjectSync(c, c.paths.project.config, c.files.project.config); + if (opts) { + const { template } = await inquirer.prompt({ + type: 'list', + name: 'template', + message: 'Pick which template to apply', + choices: opts.keysAsArray, + }); + c.buildConfig.currentTemplate = template; + c.files.project.config.currentTemplate = template; + _writeObjectSync(c, c.paths.project.config, c.files.project.config); + } else { + logError('Could not find any installed templates'); + } } const templateIsInstalled = doResolve(c.buildConfig.currentTemplate); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.pkg.ts b/packages/rnv/src/engine-core/tasks/task.rnv.pkg.ts index 9e1e39501c..0389e2199b 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.pkg.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.pkg.ts @@ -14,6 +14,7 @@ import { import { PARAMS, TASK_PKG, TASK_PROJECT_CONFIGURE } from '../../core/constants'; import { logError, logTask } from '../../core/systemManager/logger'; import { executeTask } from '../../core/taskManager'; +import { RnvTaskFn } from '../../core/taskManager/types'; const bumpVersions = (version: string) => { const { @@ -66,7 +67,7 @@ const publishAll = () => { return true; }; -export const taskRnvPkg = async (c: RnvConfig, parentTask, originTask) => { +export const taskRnvPkg: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvPkg'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_PKG, originTask); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.platform.configure.ts b/packages/rnv/src/engine-core/tasks/task.rnv.platform.configure.ts index e8ec0b87a8..275eed055a 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.platform.configure.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.platform.configure.ts @@ -33,7 +33,7 @@ export const taskRnvPlatformConfigure: RnvTaskFn = async (c, parentTask, originT if ((c.program.reset || c.program.resetHard) && !c.runtime.disableReset) { logInfo( `You passed ${chalk().white(c.program.reset ? '-r' : '-R')} argument. "${chalk().white( - getAppFolder(c, c.platform) + getAppFolder(c) )}" CLEANING...DONE` ); await cleanPlatformBuild(c, c.platform); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.platform.connect.ts b/packages/rnv/src/engine-core/tasks/task.rnv.platform.connect.ts index 5700017299..58970caf53 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.platform.connect.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.platform.connect.ts @@ -6,8 +6,9 @@ import { writeFileSync, removeDirs } from '../../core/systemManager/fileutils'; import { generatePlatformChoices } from '../../core/platformManager'; import { executeTask } from '../../core/taskManager'; import { TASK_PROJECT_CONFIGURE, TASK_PLATFORM_CONNECT, PARAMS } from '../../core/constants'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvPlatformConnect = async (c: RnvConfig, parentTask, originTask) => { +export const taskRnvPlatformConnect: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvPlatformConnect'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_PLATFORM_CONNECT, originTask); @@ -55,7 +56,7 @@ export const taskRnvPlatformConnect = async (c: RnvConfig, parentTask, originTas }); if (deletePlatformFolder) { - const pathsToRemove = []; + const pathsToRemove: Array = []; selectedPlatforms.forEach((platform) => { pathsToRemove.push(path.join(c.paths.project.platformTemplatesDirs[platform], platform)); }); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.workspace.add.ts b/packages/rnv/src/engine-core/tasks/task.rnv.workspace.add.ts index 304a5488c4..70c6c2ffe1 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.workspace.add.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.workspace.add.ts @@ -30,7 +30,7 @@ export const taskRnvWorkspaceAdd: RnvTaskFn = async (c, _parentTask, originTask) if (!confirm) return false; } - let workspaceID = workspacePath.split('/').pop().replace(/@|\./g, ''); + let workspaceID = workspacePath.split('/').pop()?.replace(/@|\./g, ''); const { workspaceIDInput } = await inquirerPrompt({ name: 'workspaceIDInput', diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.workspace.connect.ts b/packages/rnv/src/engine-core/tasks/task.rnv.workspace.connect.ts index a65957b210..a956e49811 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.workspace.connect.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.workspace.connect.ts @@ -3,8 +3,9 @@ import { logTask, logRaw } from '../../core/systemManager/logger'; import { getWorkspaceConnectionString } from '../../core/projectManager/workspace'; import { executeTask } from '../../core/taskManager'; import { TASK_WORKSPACE_CONNECT, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvWorkspaceConnect = async (c: RnvConfig, parentTask, originTask) => { +export const taskRnvWorkspaceConnect: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvWorkspaceConnect'); if (!c.paths.project.configExists) { diff --git a/packages/rnv/src/typings/modules.d.ts b/packages/rnv/src/typings/modules.d.ts index 6cec241c6e..040a199752 100644 --- a/packages/rnv/src/typings/modules.d.ts +++ b/packages/rnv/src/typings/modules.d.ts @@ -5,5 +5,6 @@ declare module 'detect-port'; declare module 'ip'; declare module 'get-installed-path' declare module 'color-string'; +declare module 'svg2js'; export {} \ No newline at end of file From 5e32eff4a2b988eda2d1561a84380906a832db49 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Wed, 30 Aug 2023 05:24:25 +0200 Subject: [PATCH 21/83] more migrations, 471 togo --- packages/rnv/src/core/configManager/types.ts | 1 + packages/rnv/src/core/pluginManager/index.ts | 2 +- packages/rnv/src/core/pluginManager/types.ts | 1 + packages/rnv/src/core/projectManager/index.ts | 8 +-- packages/rnv/src/core/systemManager/types.ts | 2 +- .../engine-core/tasks/task.rnv.fastlane.ts | 5 +- .../src/engine-core/tasks/task.rnv.help.ts | 2 +- .../engine-core/tasks/task.rnv.hooks.pipes.ts | 3 +- .../rnv/src/engine-core/tasks/task.rnv.new.ts | 71 ++++++++++++++----- .../tasks/task.rnv.platform.connect.ts | 2 +- .../tasks/task.rnv.plugin.update.ts | 7 +- .../tasks/task.rnv.project.configure.ts | 2 +- .../tasks/task.rnv.project.upgrade.ts | 5 +- .../src/engine-core/tasks/task.rnv.switch.ts | 3 +- .../tasks/task.rnv.target.launch.ts | 4 +- packages/rnv/src/index.ts | 4 +- packages/rnv/src/typings/global.d.ts | 2 + 17 files changed, 83 insertions(+), 41 deletions(-) create mode 100644 packages/rnv/src/core/pluginManager/types.ts diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index b9bdb1abe7..6761a60243 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -85,6 +85,7 @@ export interface RnvConfig { currentEngine: RnvEngine; hosted: boolean; task: string; + selectedWorkspace: string; }; paths: { GLOBAL_RNV_CONFIG: string; diff --git a/packages/rnv/src/core/pluginManager/index.ts b/packages/rnv/src/core/pluginManager/index.ts index 7f11aaa305..ada04a6984 100644 --- a/packages/rnv/src/core/pluginManager/index.ts +++ b/packages/rnv/src/core/pluginManager/index.ts @@ -328,7 +328,7 @@ ${ovMsg}` }; const _updatePackage = (c: RnvConfig, override: any) => { - const newPackage = merge(c.files.project.package, override); + const newPackage: any = merge(c.files.project.package, override); writeRenativeConfigFile(c, c.paths.project.package, newPackage); c.files.project.package = newPackage; c._requiresNpmInstall = true; diff --git a/packages/rnv/src/core/pluginManager/types.ts b/packages/rnv/src/core/pluginManager/types.ts new file mode 100644 index 0000000000..83a2bd7c9c --- /dev/null +++ b/packages/rnv/src/core/pluginManager/types.ts @@ -0,0 +1 @@ +export type PluginCallback = () => void; diff --git a/packages/rnv/src/core/projectManager/index.ts b/packages/rnv/src/core/projectManager/index.ts index 913cd85b49..f7ad0ef70c 100644 --- a/packages/rnv/src/core/projectManager/index.ts +++ b/packages/rnv/src/core/projectManager/index.ts @@ -499,11 +499,11 @@ export const copyAssetsFolder = async (c: RnvConfig, platform: RnvPlatform, subP if (c.paths.appConfig.dirs) { c.paths.appConfig.dirs.forEach((v) => { const sourcePath = path.join(v, `assets/${assetFolderPlatform}`); - copyFolderContentsRecursiveSync(sourcePath, destPath, true, false, false, {}, tsPathsConfig, c); + copyFolderContentsRecursiveSync(sourcePath, destPath, true, undefined, false, {}, tsPathsConfig, c); }); } else { const sourcePath = path.join(c.paths.appConfig.dir, `assets/${assetFolderPlatform}`); - copyFolderContentsRecursiveSync(sourcePath, destPath, true, false, false, {}, tsPathsConfig, c); + copyFolderContentsRecursiveSync(sourcePath, destPath, true, undefined, false, {}, tsPathsConfig, c); } }; @@ -691,8 +691,8 @@ export const upgradeProjectDependencies = (c: RnvConfig, version: string) => { export const upgradeDependencies = ( packageFile: NpmPackageFile, packagesPath: string, - configFile: RenativeConfigFile, - configPath: string, + configFile: RenativeConfigFile | null, + configPath: string | null, version: string ) => { // logTask('upgradeDependencies'); diff --git a/packages/rnv/src/core/systemManager/types.ts b/packages/rnv/src/core/systemManager/types.ts index eb2df0bb50..5cff619576 100644 --- a/packages/rnv/src/core/systemManager/types.ts +++ b/packages/rnv/src/core/systemManager/types.ts @@ -12,7 +12,7 @@ export type ExecOptions = { args: Array; }; privateParams?: Array; - env?: Record; + env?: NodeJS.Process['env']; ignoreErrors?: boolean; detached?: boolean; cwd?: string; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.fastlane.ts b/packages/rnv/src/engine-core/tasks/task.rnv.fastlane.ts index 94df561639..6b2ea9042b 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.fastlane.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.fastlane.ts @@ -2,17 +2,18 @@ import { executeAsync, commandExistsSync } from '../../core/systemManager/exec'; import { getAppFolder, getCliArguments } from '../../core/common'; import { IOS, TVOS, ANDROID, ANDROID_TV, FIRE_TV, ANDROID_WEAR, PARAMS } from '../../core/constants'; import PlatformSetup from '../../core/setupManager'; +import { RnvConfig } from '../../core/configManager/types'; export const taskRnvFastlane = async (c: RnvConfig) => { const args = getCliArguments(c); args.shift(); // we know the first one is fastlane, trash it if (!commandExistsSync('fastlane')) { - const setupInstance = PlatformSetup(); + const setupInstance = PlatformSetup(c); await setupInstance.askToInstallSDK('fastlane'); } - const appFolder = getAppFolder(c, c.platform); + const appFolder = getAppFolder(c); let fastlaneArgs = [...c.program.rawArgs]; fastlaneArgs = fastlaneArgs.slice(3); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.help.ts b/packages/rnv/src/engine-core/tasks/task.rnv.help.ts index dfbce1f94f..8b1b9aad11 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.help.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.help.ts @@ -26,7 +26,7 @@ export const taskRnvHelp: RnvTaskFn = async (c) => { }); // TASKS - const commands = []; + const commands: Array = []; const engines = getRegisteredEngines(c); engines.forEach((engine) => { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.hooks.pipes.ts b/packages/rnv/src/engine-core/tasks/task.rnv.hooks.pipes.ts index 4781b0c439..8a0030aa1a 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.hooks.pipes.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.hooks.pipes.ts @@ -3,8 +3,9 @@ import { generateOptions } from '../../cli/prompt'; import { buildHooks } from '../../core/projectManager/buildHooks'; import { executeTask } from '../../core/taskManager'; import { TASK_HOOKS_PIPES, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvHooksPipes = async (c: RnvConfig, parentTask, originTask) => { +export const taskRnvHooksPipes: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvHooksPipes'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_HOOKS_PIPES, originTask); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.new.ts b/packages/rnv/src/engine-core/tasks/task.rnv.new.ts index 7e746a015e..5926e13e5d 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.new.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.new.ts @@ -37,7 +37,44 @@ import { RnvConfig } from '../../core/configManager/types'; const highlight = chalk().green; -const _prepareProjectOverview = (c: RnvConfig, data) => { +type NewProjectData = { + appTitle: string; + inputAppTitle: string; + packageName: string; + defaultAppTitle: string; + defaultTemplate: string; + inputProjectName: string; + teamID: string; + appID: string; + inputAppID: string; + inputVersion: string; + defaultVersion: string; + inputTemplate: string; + version: string; + optionTemplates: { + selectedOption?: string; + selectedVersion?: string; + valuesAsObject?: any; + valuesAsArray?: Array; + keysAsArray?: Array; + }; + projectName: string; + optionWorkspaces: { + selectedOption: string; + valuesAsObject?: any; + valuesAsArray?: Array; + keysAsArray?: Array; + }; + gitEnabled: boolean; + optionPlatforms: { + selectedOptions: Array; + }; + confirmString: string; + defaultProjectName: string; + defaultWorkspace: string; +}; + +const _prepareProjectOverview = (c: RnvConfig, data: NewProjectData) => { data.appTitle = data.inputAppTitle || data.defaultAppTitle; data.teamID = ''; data.appID = data.inputAppID ? data.inputAppID.replace(/\s+/g, '-').toLowerCase() : data.appID; @@ -46,13 +83,13 @@ const _prepareProjectOverview = (c: RnvConfig, data) => { let str = printBoxStart('🚀 ReNative Project Generator'); str += printIntoBox(''); - str += printIntoBox(`Project Name (folder): ${highlight(data.projectName)}`, 1); - str += printIntoBox(`Workspace: ${highlight(data.optionWorkspaces.selectedOption)}`, 1); - str += printIntoBox(`Project Title: ${highlight(data.appTitle)}`, 1); - str += printIntoBox(`Project Version: ${highlight(data.version)}`, 1); - str += printIntoBox(`App ID: ${highlight(data.appID)}`, 1); - str += printIntoBox(`Project Template: ${highlight(tempString)}`, 1); - str += printIntoBox(`Git Enabled: ${highlight(data.gitEnabled)}`, 1); + str += printIntoBox(`Project Name (folder): ${highlight(data.projectName)}`); + str += printIntoBox(`Workspace: ${highlight(data.optionWorkspaces.selectedOption)}`); + str += printIntoBox(`Project Title: ${highlight(data.appTitle)}`); + str += printIntoBox(`Project Version: ${highlight(data.version)}`); + str += printIntoBox(`App ID: ${highlight(data.appID)}`); + str += printIntoBox(`Project Template: ${highlight(tempString)}`); + str += printIntoBox(`Git Enabled: ${highlight(data.gitEnabled)}`); str += printIntoBox(''); str += printIntoBox('Project Platforms:'); str += printArrIntoBox(data.optionPlatforms.selectedOptions); @@ -88,7 +125,7 @@ const interactiveQuestion = async (results, bootstrapQuestions, providedAnswers) // inquirer will nest them if they look like an object const qKeyClean = qKey.replace('.', '__'); - const choicesObj = {}; + const choicesObj: Record = {}; if (q.options) { q.options.forEach((opt) => { choicesObj[opt.title] = opt; @@ -180,7 +217,7 @@ export const taskRnvNew = async (c: RnvConfig) => { } } - let data = { + let data: NewProjectData = { defaultVersion: '0.1.0', defaultTemplate: '@rnv/template-starter', defaultProjectName: 'helloRenative', @@ -195,7 +232,7 @@ export const taskRnvNew = async (c: RnvConfig) => { // INPUT: Project Name // ================================================== - let inputProjectName; + let inputProjectName: string; if (projectName && projectName !== '') { inputProjectName = projectName; @@ -313,7 +350,7 @@ export const taskRnvNew = async (c: RnvConfig) => { options.push(val.title); }); - const getTemplateKey = (val) => data.optionTemplates.valuesAsArray.find((v) => v.title === val)?.key; + const getTemplateKey = (val: string) => data.optionTemplates.valuesAsArray.find((v) => v.title === val)?.key; // ================================================== // INPUT: Template @@ -352,11 +389,7 @@ export const taskRnvNew = async (c: RnvConfig) => { if (templateVersion && templateVersion !== '') { inputTemplateVersion = templateVersion; } else { - inputTemplateVersion = await listAndSelectNpmVersion( - c, - data.optionTemplates.selectedOption, - Object.keys(c.files.rnv.projectTemplates.config.projectTemplates) - ); + inputTemplateVersion = await listAndSelectNpmVersion(c, data.optionTemplates.selectedOption); } data.optionTemplates.selectedVersion = inputTemplateVersion; @@ -439,10 +472,10 @@ export const taskRnvNew = async (c: RnvConfig) => { const renativeTemplateConfigExt = {}; const bootstrapQuestions = renativeTemplateConfig?.templateConfig?.bootstrapQuestions; const results = {}; - const providedAnswers = {}; + const providedAnswers: Record = {}; if (c.program.answer) { - c.program.answer.forEach((a) => { + c.program.answer.forEach((a: string) => { const key = a.split('=')[0]; let value; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.platform.connect.ts b/packages/rnv/src/engine-core/tasks/task.rnv.platform.connect.ts index 58970caf53..939bb03df3 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.platform.connect.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.platform.connect.ts @@ -18,7 +18,7 @@ export const taskRnvPlatformConnect: RnvTaskFn = async (c, _parentTask, originTa return; } - let selectedPlatforms; + let selectedPlatforms: Array; if (c.platform) { selectedPlatforms = [c.platform]; } else { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.plugin.update.ts b/packages/rnv/src/engine-core/tasks/task.rnv.plugin.update.ts index 6a20cf8910..29e4e53574 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.plugin.update.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.plugin.update.ts @@ -4,13 +4,14 @@ import { logSuccess, logTask } from '../../core/systemManager/logger'; import { getPluginList } from '../../core/pluginManager'; import { executeTask } from '../../core/taskManager'; import { TASK_PLUGIN_UPDATE, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvPluginUpdate = async (c: RnvConfig, parentTask, originTask) => { +export const taskRnvPluginUpdate: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvPluginUpdate'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_PLUGIN_UPDATE, originTask); - const o = getPluginList(c, true); + const pluginList = getPluginList(c, true); // console.log(o.asString); @@ -24,7 +25,7 @@ export const taskRnvPluginUpdate = async (c: RnvConfig, parentTask, originTask) const { plugins } = c.buildConfig; Object.keys(plugins).forEach((key) => { // c.buildConfig.plugins[key] = o.json[key]; - c.files.project.config_original.plugins[key] = o.json[key]; + c.files.project.config_original.plugins[key] = pluginList.json[key]; }); writeFileSync(c.paths.project.config, c.files.project.config_original); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.project.configure.ts b/packages/rnv/src/engine-core/tasks/task.rnv.project.configure.ts index 10db91effc..41beef9794 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.project.configure.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.project.configure.ts @@ -43,7 +43,7 @@ export const taskRnvProjectConfigure: RnvTaskFn = async (c, parentTask, originTa logInfo(`Creating folder ${c.paths.project.builds.dir} ...DONE`); fsMkdirSync(c.paths.project.builds.dir); } - await checkAndMigrateProject(c); + await checkAndMigrateProject(); await updateRenativeConfigs(c); await checkIsRenativeProject(c); // await checkAndCreateProjectPackage(c); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.project.upgrade.ts b/packages/rnv/src/engine-core/tasks/task.rnv.project.upgrade.ts index cf0d434ed5..f6e9f48e2a 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.project.upgrade.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.project.upgrade.ts @@ -7,8 +7,9 @@ import { executeTask } from '../../core/taskManager'; import { listAndSelectNpmVersion } from '../../core/systemManager/npmUtils'; import { installPackageDependenciesAndPlugins } from '../../core/pluginManager'; import { fsExistsSync, readObjectSync } from '../../core/systemManager/fileutils'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvProjectUpgrade = async (c: RnvConfig, parentTask, originTask) => { +export const taskRnvProjectUpgrade: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvProjectUpgrade'); const upgradedPaths = []; if (fsExistsSync(c.paths.project.config)) { @@ -50,7 +51,7 @@ export const taskRnvProjectUpgrade = async (c: RnvConfig, parentTask, originTask } } - logToSummary(`Upgraded following files:\n${upgradedPaths.join('\n')}`, true); + logToSummary(`Upgraded following files:\n${upgradedPaths.join('\n')}`); return true; }; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.switch.ts b/packages/rnv/src/engine-core/tasks/task.rnv.switch.ts index d7c02843ac..4e85774306 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.switch.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.switch.ts @@ -3,8 +3,9 @@ import { configureFonts, copyRuntimeAssets } from '../../core/projectManager'; import { generateRuntimeConfig } from '../../core/configManager'; import { executeTask } from '../../core/taskManager'; import { TASK_SWITCH, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvSwitch = async (c: RnvConfig, parentTask, originTask) => { +export const taskRnvSwitch: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvSwitch'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_SWITCH, originTask); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.target.launch.ts b/packages/rnv/src/engine-core/tasks/task.rnv.target.launch.ts index 1c50348f29..76af54901b 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.target.launch.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.target.launch.ts @@ -47,9 +47,9 @@ export const taskRnvTargetLaunch: RnvTaskFn = async (c, parentTask, originTask) case TIZEN: return launchTizenSimulator(c, target); case WEBOS: - return launchWebOSimulator(c, target); + return launchWebOSimulator(c); case KAIOS: - return launchKaiOSSimulator(c, target); + return launchKaiOSSimulator(c); default: return Promise.reject( `"target launch" command does not support ${chalk().white.bold( diff --git a/packages/rnv/src/index.ts b/packages/rnv/src/index.ts index 0593eaec4e..cc3e0578a3 100755 --- a/packages/rnv/src/index.ts +++ b/packages/rnv/src/index.ts @@ -35,7 +35,7 @@ import Config from './core/configManager/config'; global.RNV_ANALYTICS = Analytics; -export const initializeBuilder = async (cmd, subCmd, process, program) => { +export const initializeBuilder = async (cmd: string, subCmd: string, process: any, program: any) => { // set mono and ci if json is enabled if (program.json) { program.mono = true; @@ -53,7 +53,7 @@ export const initializeBuilder = async (cmd, subCmd, process, program) => { return c; }; -const run = (cmd, subCmd, program, process) => { +const run = (cmd: string, subCmd: string, program: any, process: any) => { initializeBuilder(cmd, subCmd, process, program) .then((c) => Config.initializeConfig(c)) .then((c) => CLI(c)) diff --git a/packages/rnv/src/typings/global.d.ts b/packages/rnv/src/typings/global.d.ts index 8e746947e0..4f7a2b8a65 100644 --- a/packages/rnv/src/typings/global.d.ts +++ b/packages/rnv/src/typings/global.d.ts @@ -17,4 +17,6 @@ declare global { var doResolve; //eslint-disable-next-line no-var var getConfigProp + //eslint-disable-next-line no-var + var fetch; } From f5abce12976c120aa65c0986cc2adbcd5b3ee9e5 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Wed, 30 Aug 2023 05:47:45 +0200 Subject: [PATCH 22/83] more refactor, 399 togo --- packages/rnv/src/core/configManager/types.ts | 2 + packages/rnv/src/core/engineManager/index.ts | 17 +++++--- packages/rnv/src/core/pluginManager/index.ts | 42 ++++++++++++------- packages/rnv/src/core/pluginManager/types.ts | 2 +- .../rnv/src/core/projectManager/workspace.ts | 5 ++- packages/rnv/src/core/sdkManager/installer.ts | 5 ++- packages/rnv/src/core/taskManager/types.ts | 2 +- .../tasks/task.rnv.app.configure.ts | 8 ++-- .../engine-core/tasks/task.rnv.app.create.ts | 18 +++++--- .../src/engine-core/tasks/task.rnv.clean.ts | 1 + .../engine-core/tasks/task.rnv.plugin.add.ts | 2 +- .../src/engine-core/tasks/task.rnv.publish.ts | 3 +- 12 files changed, 68 insertions(+), 39 deletions(-) diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index 6761a60243..47ce4a99a8 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -86,6 +86,7 @@ export interface RnvConfig { hosted: boolean; task: string; selectedWorkspace: string; + isWSConfirmed: boolean; }; paths: { GLOBAL_RNV_CONFIG: string; @@ -367,6 +368,7 @@ export type RenativeConfigFile = { paths: { appConfigsDirs: Array; platformTemplatesDirs: Record; + globalConfigDir: string; }; integrations: Record; tasks: Array | Record; diff --git a/packages/rnv/src/core/engineManager/index.ts b/packages/rnv/src/core/engineManager/index.ts index b6f9312f94..30371361ed 100644 --- a/packages/rnv/src/core/engineManager/index.ts +++ b/packages/rnv/src/core/engineManager/index.ts @@ -12,11 +12,16 @@ import { inquirerPrompt } from '../../cli/prompt'; import { RnvConfig } from '../configManager/types'; import { RnvTask, RnvTaskMap } from '../taskManager/types'; import { RnvModuleConfig, RnvNextJSConfig, RnvPlatform } from '../types'; -import { RnvEngineConfig, RnvEngineConfigMap, RnvEngineInstallConfig } from './types'; +import { RnvEngine, RnvEngineConfig, RnvEngineConfigMap, RnvEngineInstallConfig } from './types'; const ENGINE_CORE = 'engine-core'; -export const registerEngine = async (c: RnvConfig, engine, platform: RnvPlatform, engConfig) => { +export const registerEngine = async ( + c: RnvConfig, + engine: RnvEngine, + platform?: RnvPlatform, + engConfig?: RnvEngineConfig +) => { logTask(`registerEngine:${engine.config.id}`); c.runtime.enginesById[engine.config.id] = engine; engine.initializeRuntimeConfig(c); @@ -33,7 +38,7 @@ export const registerEngine = async (c: RnvConfig, engine, platform: RnvPlatform _registerEnginePlatform(c, platform, engine); }; -const _registerEnginePlatform = (c: RnvConfig, platform: RnvPlatform, engine) => { +const _registerEnginePlatform = (c: RnvConfig, platform: RnvPlatform, engine: RnvEngine) => { if (platform) { c.runtime.enginesByPlatform[platform] = engine; } @@ -114,7 +119,7 @@ export const configureEngines = async (c: RnvConfig) => { return true; }; -export const registerMissingPlatformEngines = async (c: RnvConfig, taskInstance) => { +export const registerMissingPlatformEngines = async (c: RnvConfig, taskInstance?: RnvTask) => { logTask('registerMissingPlatformEngines'); if ( !taskInstance || @@ -319,11 +324,11 @@ const _getFilteredEngines = (c: RnvConfig) => { return filteredEngines; }; -export const loadEngines = async (c: RnvConfig, failOnMissingDeps: boolean): Promise => { +export const loadEngines = async (c: RnvConfig, failOnMissingDeps?: boolean): Promise => { logTask('loadEngines'); if (!fsExistsSync(c.paths.project.config)) return true; - const filteredEngines = _getFilteredEngines(c); + const filteredEngines: Record = _getFilteredEngines(c); const enginesToInstall: Array = []; const readyEngines: Array = []; const engineConfigs: Array = []; diff --git a/packages/rnv/src/core/pluginManager/index.ts b/packages/rnv/src/core/pluginManager/index.ts index ada04a6984..052e3248a1 100644 --- a/packages/rnv/src/core/pluginManager/index.ts +++ b/packages/rnv/src/core/pluginManager/index.ts @@ -22,6 +22,7 @@ import { doResolve, doResolvePath } from '../systemManager/resolve'; import { RnvConfig } from '../configManager/types'; import { RnvPlatform } from '../types'; import { ResolveOptions } from '../systemManager/types'; +import { PluginCallback } from './types'; export const getPluginList = (c: RnvConfig, isUpdate = false) => { const output = { @@ -129,7 +130,14 @@ export const getMergedPlugin = (c: RnvConfig, key: string) => { return mergedPlugin; }; -const _getMergedPlugin = (c: RnvConfig, plugin, pluginKey, parentScope, scopes, skipSanitize) => { +const _getMergedPlugin = ( + c: RnvConfig, + plugin, + pluginKey: string, + parentScope?: string, + scopes?: Array, + skipSanitize?: boolean +) => { if (!plugin) { return {}; } @@ -149,11 +157,11 @@ const _getMergedPlugin = (c: RnvConfig, plugin, pluginKey, parentScope, scopes, !c.runtime._skipPluginScopeWarnings ) { logWarning(`Plugin ${pluginKey} is not recognized plugin in ${scope} scope`); - } else if (scope) { + } else if (scope && parentScope) { const skipRnvOverrides = c.buildConfig.pluginTemplates?.[parentScope]?.disableRnvDefaultOverrides; if (skipRnvOverrides && scope === 'rnv') { // Merges down to RNV defaults will be skipped - } else { + } else if (scopes) { scopes.push(scope); } } @@ -402,7 +410,7 @@ const _resolvePluginDependencies = async (c: RnvConfig, key: string, keyScope: s export const parsePlugins = ( c: RnvConfig, platform: RnvPlatform, - pluginCallback, + pluginCallback: PluginCallback, ignorePlatformObjectCheck?: boolean ) => { logTask('parsePlugins'); @@ -526,7 +534,11 @@ export const loadPluginTemplates = async (c: RnvConfig) => { return true; }; -const _parsePluginTemplateDependencies = (c: RnvConfig, customPluginTemplates, scope = 'root') => { +const _parsePluginTemplateDependencies = ( + c: RnvConfig, + customPluginTemplates: Record, + scope = 'root' +) => { logTask('_parsePluginTemplateDependencies', `scope:${scope}`); const missingDeps: Array = []; if (customPluginTemplates) { @@ -666,7 +678,7 @@ export const overrideFileContents = (dest: string, override, overridePath = '') if (fsExistsSync(dest)) { let fileToFix = fsReadFileSync(dest).toString(); let foundRegEx = false; - const failTerms = []; + const failTerms: Array = []; Object.keys(override).forEach((fk) => { const regEx = new RegExp(`${getCleanRegExString(fk)}`, 'g'); const count = (fileToFix.match(regEx) || []).length; @@ -843,7 +855,7 @@ export const copyTemplatePluginsSync = (c) => { } // FOLDER MERGES FROM PROJECT CONFIG PLUGIN const sourcePathRnvPlugin = getBuildsFolder(c, platform, path.join(c.paths.rnv.pluginTemplates.dir, key)); - copyFolderContentsRecursiveSync(sourcePathRnvPlugin, destPath, true, false, false, objectInject); + copyFolderContentsRecursiveSync(sourcePathRnvPlugin, destPath, true, undefined, false, objectInject); // FOLDER MERGES FROM PROJECT CONFIG PLUGIN const sourcePath3 = getBuildsFolder( @@ -851,7 +863,7 @@ export const copyTemplatePluginsSync = (c) => { platform, path.join(c.paths.project.appConfigBase.dir, `plugins/${key}`) ); - copyFolderContentsRecursiveSync(sourcePath3, destPath, true, false, false, objectInject); + copyFolderContentsRecursiveSync(sourcePath3, destPath, true, undefined, false, objectInject); // FOLDER MERGERS FROM PROJECT CONFIG (PRIVATE) const sourcePath3secLegacy = getBuildsFolder( @@ -859,7 +871,7 @@ export const copyTemplatePluginsSync = (c) => { platform, path.join(c.paths.workspace.project.appConfigBase.dir_LEGACY, `plugins/${key}`) ); - copyFolderContentsRecursiveSync(sourcePath3secLegacy, destPath, true, false, false, objectInject); + copyFolderContentsRecursiveSync(sourcePath3secLegacy, destPath, true, undefined, false, objectInject); // FOLDER MERGES FROM PROJECT CONFIG PLUGIN (PRIVATE) const sourcePath3sec = getBuildsFolder( @@ -867,7 +879,7 @@ export const copyTemplatePluginsSync = (c) => { platform, path.join(c.paths.workspace.project.appConfigBase.dir, `plugins/${key}`) ); - copyFolderContentsRecursiveSync(sourcePath3sec, destPath, true, false, false, objectInject); + copyFolderContentsRecursiveSync(sourcePath3sec, destPath, true, undefined, false, objectInject); if (fsExistsSync(sourcePath3secLegacy)) { logWarning(`Path: ${chalk().red(sourcePath3secLegacy)} is DEPRECATED. @@ -876,7 +888,7 @@ export const copyTemplatePluginsSync = (c) => { // FOLDER MERGES FROM APP CONFIG PLUGIN const sourcePath2 = getBuildsFolder(c, platform, path.join(c.paths.appConfig.dir, `plugins/${key}`)); - copyFolderContentsRecursiveSync(sourcePath2, destPath, true, false, false, objectInject); + copyFolderContentsRecursiveSync(sourcePath2, destPath, true, undefined, false, objectInject); // FOLDER MERGES FROM APP CONFIG PLUGIN (PRIVATE) const sourcePath2sec = getBuildsFolder( @@ -884,7 +896,7 @@ export const copyTemplatePluginsSync = (c) => { platform, path.join(c.paths.workspace.appConfig.dir, `plugins/${key}`) ); - copyFolderContentsRecursiveSync(sourcePath2sec, destPath, true, false, false, objectInject); + copyFolderContentsRecursiveSync(sourcePath2sec, destPath, true, undefined, false, objectInject); // FOLDER MERGES FROM SCOPED PLUGIN TEMPLATES Object.keys(c.paths.rnv.pluginTemplates.dirs).forEach((pathKey) => { @@ -892,7 +904,7 @@ export const copyTemplatePluginsSync = (c) => { const pluginTemplatePath = c.paths.rnv.pluginTemplates.dirs[pathKey]; const sourcePath4sec = getBuildsFolder(c, platform, path.join(pluginTemplatePath, key)); - copyFolderContentsRecursiveSync(sourcePath4sec, destPath, true, false, false, objectInject); + copyFolderContentsRecursiveSync(sourcePath4sec, destPath, true, undefined, false, objectInject); } }); }); @@ -930,10 +942,10 @@ export const getLocalRenativePlugin = () => ({ }); export const getModuleConfigs = (c: RnvConfig, primaryKey: string) => { - let modulePaths = []; + let modulePaths: Array = []; const moduleAliases: Record = {}; - const doNotResolveModulePaths = []; + const doNotResolveModulePaths: Array = []; // PLUGINS parsePlugins( diff --git a/packages/rnv/src/core/pluginManager/types.ts b/packages/rnv/src/core/pluginManager/types.ts index 83a2bd7c9c..1c9669e549 100644 --- a/packages/rnv/src/core/pluginManager/types.ts +++ b/packages/rnv/src/core/pluginManager/types.ts @@ -1 +1 @@ -export type PluginCallback = () => void; +export type PluginCallback = (plugin, pluginPlat, key: string) => void; diff --git a/packages/rnv/src/core/projectManager/workspace.ts b/packages/rnv/src/core/projectManager/workspace.ts index 134f996ccf..7ae2fd5725 100644 --- a/packages/rnv/src/core/projectManager/workspace.ts +++ b/packages/rnv/src/core/projectManager/workspace.ts @@ -2,8 +2,9 @@ import path from 'path'; import { generateOptions, inquirerPrompt } from '../../cli/prompt'; import { chalk, logTask, logWarning, logDebug, logInfo } from '../systemManager/logger'; import { writeFileSync, mkdirSync, fsExistsSync } from '../systemManager/fileutils'; +import { RnvConfig } from '../configManager/types'; -export const createWorkspace = async (c: RnvConfig, workspaceID, workspacePath) => { +export const createWorkspace = async (c: RnvConfig, workspaceID: string, workspacePath: string) => { c.files.rnv.configWorkspaces.workspaces[workspaceID] = { path: workspacePath, }; @@ -70,7 +71,7 @@ export const getWorkspaceDirPath = async (c: RnvConfig) => { return dirPath; }; -export const getWorkspaceConnectionString = (obj) => { +export const getWorkspaceConnectionString = (obj: any) => { const remoteUrl = obj.remote?.url; const connectMsg = remoteUrl ? chalk().green(`(${obj.remote.type}:${remoteUrl})`) : ''; return connectMsg; diff --git a/packages/rnv/src/core/sdkManager/installer.ts b/packages/rnv/src/core/sdkManager/installer.ts index 2d1dc06598..a6b4d5a5f2 100644 --- a/packages/rnv/src/core/sdkManager/installer.ts +++ b/packages/rnv/src/core/sdkManager/installer.ts @@ -36,6 +36,7 @@ import { chalk, logTask, logWarning, logSuccess, logError, logInfo } from '../sy import PlatformSetup from '../setupManager'; import { generateBuildConfig } from '../configManager'; import { RnvConfig } from '../configManager/types'; +import { RnvError } from '../types'; const SDK_LOCATIONS: Record> = { android: [ @@ -198,7 +199,7 @@ const _findFolderWithFile = (dir, fileToFind) => { return foundDir; }; -const _attemptAutoFix = async (c: RnvConfig, sdkPlatform: string, sdkKey: string, traverseUntilFoundFile: boolean) => { +const _attemptAutoFix = async (c: RnvConfig, sdkPlatform: string, sdkKey: string, traverseUntilFoundFile?: boolean) => { logTask('_attemptAutoFix'); if (c.program.hosted) { @@ -249,7 +250,7 @@ const _attemptAutoFix = async (c: RnvConfig, sdkPlatform: string, sdkKey: string writeFileSync(c.paths.workspace.config, c.files.workspace.config); generateBuildConfig(c); await checkAndConfigureSdks(c); - } catch (e) { + } catch (e: RnvError) { logError(e); } diff --git a/packages/rnv/src/core/taskManager/types.ts b/packages/rnv/src/core/taskManager/types.ts index af6e78e79b..ec44b2140e 100644 --- a/packages/rnv/src/core/taskManager/types.ts +++ b/packages/rnv/src/core/taskManager/types.ts @@ -3,7 +3,7 @@ import { RnvConfig } from '../configManager/types'; export type RnvTask = { task: string; params: Array; - isGlobalScope: boolean; + isGlobalScope?: boolean; platforms: Array; description: string; }; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.app.configure.ts b/packages/rnv/src/engine-core/tasks/task.rnv.app.configure.ts index a66d88de44..e4b99ac331 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.app.configure.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.app.configure.ts @@ -13,7 +13,7 @@ const _loadAppConfigIDfromDir = (dirName: string, appConfigsDir: string) => { const filePath = path.join(appConfigsDir, 'renative.json'); if (fsExistsSync(filePath)) { try { - const renativeConf = JSON.parse(fsReadFileSync(filePath)); + const renativeConf = JSON.parse(fsReadFileSync(filePath).toString()); return { dir: dirName, id: renativeConf.id }; } catch (e) { logError(`File ${filePath} is MALFORMED:\n${e}`); @@ -22,7 +22,7 @@ const _loadAppConfigIDfromDir = (dirName: string, appConfigsDir: string) => { return { dir: dirName, id: null }; }; -const _askUserAboutConfigs = async (c: RnvConfig, dir, id, basePath) => { +const _askUserAboutConfigs = async (c: RnvConfig, dir: string, id: string, basePath: string) => { logTask('_askUserAboutConfigs'); logWarning( `AppConfig error - It seems you have a mismatch between appConfig folder name (${dir}) and the id defined in renative.json (${id}). They must match.` @@ -64,7 +64,7 @@ const _askUserAboutConfigs = async (c: RnvConfig, dir, id, basePath) => { if (choice === 'keepFolder') { const filePath = path.join(basePath, dir, 'renative.json'); - const fileContents = JSON.parse(fsReadFileSync(filePath)); + const fileContents = JSON.parse(fsReadFileSync(filePath).toString()); fileContents.id = dir; conf.id = dir; @@ -75,7 +75,7 @@ const _askUserAboutConfigs = async (c: RnvConfig, dir, id, basePath) => { }; /* eslint-disable no-await-in-loop */ -const matchAppConfigID = async (c: RnvConfig, appConfigID) => { +const matchAppConfigID = async (c: RnvConfig, appConfigID: string) => { logTask('matchAppConfigID', `appId:${appConfigID}`); if (!appConfigID) return false; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.app.create.ts b/packages/rnv/src/engine-core/tasks/task.rnv.app.create.ts index 77df416413..3a88d15fdd 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.app.create.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.app.create.ts @@ -12,13 +12,14 @@ import { writeFileSync, } from '../../core/systemManager/fileutils'; import { doResolve } from '../../core/systemManager/resolve'; +import { RnvTaskFn } from '../../core/taskManager/types'; -export const taskRnvAppCreate = async (c: RnvConfig) => { +export const taskRnvAppCreate: RnvTaskFn = async (c) => { logTask('taskRnvAppCreate'); await configureRuntimeDefaults(c); - let sourcePath; + let sourcePath: string; if (c.program.sourceAppConfigID) { const sourceAppConfigDirPath = path.join(c.paths.project.appConfigsDir, c.program.sourceAppConfigID); @@ -28,7 +29,7 @@ export const taskRnvAppCreate = async (c: RnvConfig) => { } } else if (c.program.ci) { const tacPath = doResolve(c.buildConfig.currentTemplate); - if (fsExistsSync(tacPath)) { + if (tacPath && fsExistsSync(tacPath)) { const tacDirsPath = path.join(tacPath, 'appConfigs'); const tacDirs = fsReaddirSync(tacDirsPath); tacDirs.forEach((v) => { @@ -41,8 +42,13 @@ export const taskRnvAppCreate = async (c: RnvConfig) => { }); } } else { - const appConfigChoicesObj = {}; - const appConfigChoices = []; + const appConfigChoicesObj: Record< + string, + { + path: string; + } + > = {}; + const appConfigChoices: Array = []; // Project Configs const acDirs = fsReaddirSync(c.paths.project.appConfigsDir); acDirs.forEach((v) => { @@ -60,7 +66,7 @@ export const taskRnvAppCreate = async (c: RnvConfig) => { // Template Configs const tacPath = doResolve(c.buildConfig.currentTemplate); - if (fsExistsSync(tacPath)) { + if (tacPath && fsExistsSync(tacPath)) { const tacDirsPath = path.join(tacPath, 'appConfigs'); const tacDirs = fsReaddirSync(tacDirsPath); tacDirs.forEach((v) => { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.clean.ts b/packages/rnv/src/engine-core/tasks/task.rnv.clean.ts index 5da9ec5838..5a69747cad 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.clean.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.clean.ts @@ -106,6 +106,7 @@ export const taskRnvClean = async (c: RnvConfig, skipQuestionParam = false) => { builds: false, cache: false, nothingToClean: !skipQuestion, + locals: false, }; if (pathsToRemove.length) { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.plugin.add.ts b/packages/rnv/src/engine-core/tasks/task.rnv.plugin.add.ts index f93aea6c5a..7ea1c913a7 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.plugin.add.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.plugin.add.ts @@ -37,7 +37,7 @@ export const taskRnvPluginAdd: RnvTaskFn = async (c, _parentTask, originTask) => installMessage.push(`${chalk().white(selPluginKey)} v(${chalk().green(selPlugin.version)})`); } - const questionPlugins = {}; + const questionPlugins: Record = {}; Object.keys(selectedPlugins).forEach((key) => { // c.buildConfig.plugins[key] = 'source:rnv'; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.publish.ts b/packages/rnv/src/engine-core/tasks/task.rnv.publish.ts index 61163cb5eb..cfb55d0da8 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.publish.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.publish.ts @@ -6,6 +6,7 @@ import { writeFileSync } from '../../core/systemManager/fileutils'; import { executeTask } from '../../core/taskManager'; import { TASK_PUBLISH, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; import { RnvTaskFn } from '../../core/taskManager/types'; +import { checkRequiredPackage } from '../../core/configManager/packageParser'; const includesPre = (version: string) => { if (version.includes('alpha')) return 'alpha'; @@ -34,7 +35,7 @@ export const taskRnvPublish: RnvTaskFn = async (c, _parentTask, originTask) => { await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_PUBLISH, originTask); // make sure release-it is installed - await Config.checkRequiredPackage(c, 'release-it', '12.4.3', 'devDependencies'); + await checkRequiredPackage(c, 'release-it', '12.4.3', 'devDependencies'); // make sure required object is present in package.json const pkgJson = c.files.project.package; const existingPath = c.paths.project.package; From 79bd35d04bbaca62317d7d59756bde1ae66f3e13 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Wed, 30 Aug 2023 15:43:52 +0200 Subject: [PATCH 23/83] more ts migrations, 354 togo --- .../src/core/configManager/packageParser.ts | 6 ++--- packages/rnv/src/core/configManager/types.ts | 5 +++- packages/rnv/src/core/pluginManager/index.ts | 6 ++--- .../rnv/src/core/projectManager/workspace.ts | 2 +- .../src/core/sdkManager/deviceUtils/apple.ts | 2 +- .../src/core/sdkManager/deviceUtils/kaios.ts | 7 +++-- .../src/core/sdkManager/deviceUtils/tizen.ts | 22 +++++++++------- .../src/core/sdkManager/deviceUtils/webos.ts | 8 +++--- packages/rnv/src/core/sdkManager/installer.ts | 8 +++--- packages/rnv/src/core/sdkManager/types.ts | 24 +++++++++++++++++ .../rnv/src/core/systemManager/fileutils.ts | 26 +++++++++---------- packages/rnv/src/core/systemManager/types.ts | 2 +- 12 files changed, 74 insertions(+), 44 deletions(-) diff --git a/packages/rnv/src/core/configManager/packageParser.ts b/packages/rnv/src/core/configManager/packageParser.ts index 206dc07726..f898d52b88 100644 --- a/packages/rnv/src/core/configManager/packageParser.ts +++ b/packages/rnv/src/core/configManager/packageParser.ts @@ -10,13 +10,13 @@ import { writeRenativeConfigFile } from './index'; import { overrideTemplatePlugins } from '../pluginManager'; import { configureFonts } from '../projectManager'; import { getConfigProp } from '../common'; -import { DependencyType, RnvConfig } from './types'; +import { RnvConfig } from './types'; const injectProjectDependency = async ( c: RnvConfig, dependency: string, version: string, - type: DependencyType, + type: string, skipInstall = false ) => { logTask('injectProjectDependency'); @@ -38,7 +38,7 @@ export const checkRequiredPackage = async ( c: RnvConfig, pkg: string, version = '', - type: DependencyType = 'dependencies', + type: string, skipAsking = false, skipInstall = false, skipVersionCheck = false diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index 47ce4a99a8..ae5da941f1 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -99,7 +99,7 @@ export interface RnvConfig { //ADDON dir?: string; config?: string; - dirs: Array; + dirs: Record; }; platformTemplates: Record; projectTemplates: Record; @@ -347,6 +347,9 @@ export type RenativeConfigFile = { buildSchemes: Record; entryFile?: string; runtime: Record; + appName: string; + id: string; + certificateProfile: string; } >; templates: Record< diff --git a/packages/rnv/src/core/pluginManager/index.ts b/packages/rnv/src/core/pluginManager/index.ts index 052e3248a1..dd3e002c5d 100644 --- a/packages/rnv/src/core/pluginManager/index.ts +++ b/packages/rnv/src/core/pluginManager/index.ts @@ -536,7 +536,7 @@ export const loadPluginTemplates = async (c: RnvConfig) => { const _parsePluginTemplateDependencies = ( c: RnvConfig, - customPluginTemplates: Record, + customPluginTemplates: Record, scope = 'root' ) => { logTask('_parsePluginTemplateDependencies', `scope:${scope}`); @@ -738,7 +738,7 @@ export const installPackageDependenciesAndPlugins = async (c: RnvConfig) => { await checkForPluginDependencies(c); }; -const _getPluginConfiguration = (c: RnvConfig, pluginName) => { +const _getPluginConfiguration = (c: RnvConfig, pluginName: string) => { let renativePluginPath; try { renativePluginPath = require.resolve(`${pluginName}/renative.plugin.json`, { paths: [c.paths.project.dir] }); @@ -837,7 +837,7 @@ export const overrideTemplatePlugins = async (c: RnvConfig) => { return true; }; -export const copyTemplatePluginsSync = (c) => { +export const copyTemplatePluginsSync = (c: RnvConfig) => { const { platform } = c; const destPath = path.join(getAppFolder(c)); diff --git a/packages/rnv/src/core/projectManager/workspace.ts b/packages/rnv/src/core/projectManager/workspace.ts index 7ae2fd5725..5ceb92c410 100644 --- a/packages/rnv/src/core/projectManager/workspace.ts +++ b/packages/rnv/src/core/projectManager/workspace.ts @@ -77,7 +77,7 @@ export const getWorkspaceConnectionString = (obj: any) => { return connectMsg; }; -export const getWorkspaceOptions = (c) => +export const getWorkspaceOptions = (c: RnvConfig) => generateOptions(c.files.rnv.configWorkspaces?.workspaces, false, null, (i, obj, mapping, defaultVal) => { logDebug('getWorkspaceOptions'); diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts b/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts index 74b96f2c23..e9917efaa0 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts @@ -27,7 +27,7 @@ export const getAppleDevices = async (c: RnvConfig, ignoreDevices?: boolean, ign } const res = await executeAsync('xcrun simctl list --json'); const simctl = JSON.parse(res.toString()); - const availableSims = []; + const availableSims: Array = []; Object.keys(simctl.devices).forEach((runtime) => { logDebug('runtime', runtime); simctl.devices[runtime].forEach((device) => { diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/kaios.ts b/packages/rnv/src/core/sdkManager/deviceUtils/kaios.ts index 6f7e8e7109..8d9e1d3d5e 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/kaios.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/kaios.ts @@ -1,9 +1,8 @@ -import path from 'path'; - import { fsExistsSync, getRealPath } from '../../systemManager/fileutils'; import { chalk, logTask } from '../../systemManager/logger'; import { KAIOS_SDK } from '../../constants'; import { RnvConfig } from '../../configManager/types'; +import { RnvError } from '../../types'; const childProcess = require('child_process'); @@ -22,14 +21,14 @@ export const launchKaiOSSimulator = (c: RnvConfig) => return; } - const ePath = getRealPath(path.join(c.buildConfig?.sdks?.KAIOS_SDK)); + const ePath = getRealPath(c, c.buildConfig?.sdks?.KAIOS_SDK); if (ePath && !fsExistsSync(ePath)) { reject(`Can't find emulator at path: ${ePath}`); return; } - childProcess.exec(`open ${ePath}`, (err) => { + childProcess.exec(`open ${ePath}`, (err: RnvError) => { if (err) { reject(err); return; diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts index 7ff366441c..f4cdbce721 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts @@ -7,6 +7,8 @@ import { CLI_SDB_TIZEN, CLI_TIZEN, CLI_TIZEN_EMULATOR, RENATIVE_CONFIG_NAME } fr import { execCLI } from '../../systemManager/exec'; import { fsRenameSync } from '../../systemManager/fileutils'; import { chalk, logDebug, logError, logInfo, logTask, logToSummary, logWarning } from '../../systemManager/logger'; +import { RnvError } from '../../types'; +import { TizenDevice, TizenSecurityConfig } from '../types'; import { waitForEmulator } from './common'; const xml2js = require('xml2js'); @@ -55,8 +57,8 @@ export const listTizenTargets = async (c: RnvConfig) => { logToSummary(`Tizen Targets:\n${targetStr}`); }; -export const createDevelopTizenCertificate = (c) => - new Promise((resolve) => { +export const createDevelopTizenCertificate = (c: RnvConfig) => + new Promise((resolve) => { logTask('createDevelopTizenCertificate'); const certDirPath = c.paths.workspace.dir; @@ -83,7 +85,7 @@ export const createDevelopTizenCertificate = (c) => }); }); -export const addDevelopTizenCertificate = (c: RnvConfig, secureProfileConfig) => +export const addDevelopTizenCertificate = (c: RnvConfig, secureProfileConfig: TizenSecurityConfig) => new Promise((resolve) => { logTask('addDevelopTizenCertificate'); @@ -105,7 +107,7 @@ const _getDeviceID = async (c: RnvConfig, target: string) => { let connectResponse: string; try { connectResponse = await execCLI(c, CLI_SDB_TIZEN, `connect ${target}`); - } catch (e) { + } catch (e: RnvError) { connectResponse = e; } if (connectResponse.includes('EPERM')) { @@ -143,7 +145,7 @@ const _getRunningDevices = async (c: RnvConfig) => { .trim() .split(/\r?\n/) .filter((line) => !line.includes('List of devices')); - const devices = []; + const devices: Array = []; await Promise.all( lines.map(async (line) => { @@ -188,7 +190,7 @@ const _getRunningDevices = async (c: RnvConfig) => { return devices; }; -const _waitForEmulatorToBeReady = (c: RnvConfig, target) => +const _waitForEmulatorToBeReady = (c: RnvConfig, target: string) => waitForEmulator(c, CLI_SDB_TIZEN, 'devices', (res) => { const lines = res.trim().split(/\r?\n/); const devices = lines.filter((line) => line.includes(target) && line.includes('device')); @@ -241,7 +243,7 @@ export const runTizenSimOrDevice = async (c: RnvConfig, buildCoreWebpackProject: const wgtClean = `${platformConfig.appName.replace(/[^a-z0-9]/gi, '_')}.wgt`; const certProfile = platformConfig.certificateProfile ?? DEFAULT_SECURITY_PROFILE_NAME; - let deviceID; + let deviceID: string; const askForEmulator = async () => { const { startEmulator } = await inquirer.prompt([ @@ -292,7 +294,7 @@ Please create one and then edit the default target from ${c.paths.workspace.dir} const packageID = platform === 'tizenwatch' || platform === 'tizenmobile' ? tId.split('.')[0] : tId; await execCLI(c, CLI_TIZEN, `uninstall -p ${packageID} -t ${deviceID}`, { ignoreErrors: true }); hasDevice = true; - } catch (e) { + } catch (e: RnvError) { if (e && e.includes && e.includes('No device matching')) { await launchTizenSimulator(c, target); hasDevice = await _waitForEmulatorToBeReady(c, target); @@ -305,13 +307,13 @@ Please create one and then edit the default target from ${c.paths.workspace.dir} ); fsRenameSync(path.join(tOut, wgt), path.join(tOut, wgtClean)); } - } catch (err) { + } catch (err: RnvError) { logError(err); } try { await execCLI(c, CLI_TIZEN, `install -- ${tOut} -n ${wgtClean} -t ${deviceID}`); hasDevice = true; - } catch (err) { + } catch (err: RnvError) { logError(err); logWarning( `There is no emulator or device connected! Let's try to launch it. "${chalk().white.bold( diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts b/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts index 06a3362bd0..17d901d893 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts @@ -17,6 +17,8 @@ import { } from '../../constants'; import { isSystemWin, isUrlLocalhost } from '../../systemManager/utils'; import { RnvConfig } from '../../configManager/types'; +import { WebosDevice } from '../types'; +import { RnvError } from '../../types'; export const launchWebOSimulator = (c: RnvConfig) => { logTask('launchWebOSimulator'); @@ -47,7 +49,7 @@ export const launchWebOSimulator = (c: RnvConfig) => { // } // }; -const parseDevices = (c: RnvConfig, devicesResponse: string) => { +const parseDevices = (c: RnvConfig, devicesResponse: string): Promise> => { const linesArray = devicesResponse .split('\n') .slice(2) @@ -65,7 +67,7 @@ const parseDevices = (c: RnvConfig, devicesResponse: string) => { silent: true, timeout: 10000, }); - } catch (e) { + } catch (e: RnvError) { deviceInfo = e; } @@ -101,7 +103,7 @@ const installAndLaunchApp = async (c: RnvConfig, target: string, appPath: string return toReturn; }; -const buildDeviceChoices = (devices) => +const buildDeviceChoices = (devices: Array) => devices.map((device) => ({ key: device.name, name: `${device.name} - ${device.device}`, diff --git a/packages/rnv/src/core/sdkManager/installer.ts b/packages/rnv/src/core/sdkManager/installer.ts index a6b4d5a5f2..be7404d097 100644 --- a/packages/rnv/src/core/sdkManager/installer.ts +++ b/packages/rnv/src/core/sdkManager/installer.ts @@ -66,7 +66,7 @@ const SDK_LOCATIONS: Record> = { webos: [path.join('/opt/webOS_TV_SDK'), path.join('C:\\webOS_TV_SDK')], }; -const _logSdkWarning = (c) => { +const _logSdkWarning = (c: RnvConfig) => { logWarning(`Your ${c.paths.workspace.config} is missing SDK configuration object`); }; @@ -169,9 +169,9 @@ export const checkAndConfigureSdks = async (c: RnvConfig) => { } }; -const _getCurrentSdkPath = (c) => c.buildConfig?.sdks?.[SDK_PLATFORMS[c.platform]]; +const _getCurrentSdkPath = (c: RnvConfig) => c.buildConfig?.sdks?.[SDK_PLATFORMS[c.platform]]; -const _isSdkInstalled = (c) => { +const _isSdkInstalled = (c: RnvConfig) => { logTask('_isSdkInstalled'); if (!SDK_PLATFORMS[c.platform]) return true; @@ -199,7 +199,7 @@ const _findFolderWithFile = (dir, fileToFind) => { return foundDir; }; -const _attemptAutoFix = async (c: RnvConfig, sdkPlatform: string, sdkKey: string, traverseUntilFoundFile?: boolean) => { +const _attemptAutoFix = async (c: RnvConfig, sdkPlatform: string, sdkKey: string, traverseUntilFoundFile?: string) => { logTask('_attemptAutoFix'); if (c.program.hosted) { diff --git a/packages/rnv/src/core/sdkManager/types.ts b/packages/rnv/src/core/sdkManager/types.ts index 2a2308d7b0..65900e2820 100644 --- a/packages/rnv/src/core/sdkManager/types.ts +++ b/packages/rnv/src/core/sdkManager/types.ts @@ -16,3 +16,27 @@ export type AndroidDevice = { avdConfig: any; isNotEligibleAndroid: boolean; }; + +export type WebosDevice = { + key?: string; + name: string; + value?: string; + device: string; + connection: string; + profile: string; + isDevice: boolean; + active: boolean; +}; + +export type TizenDevice = { + name: string; + type: string; + id: string; + deviceType: string; +}; + +export type TizenSecurityConfig = { + profileName: string; + certPath: string; + certPassword: string; +}; diff --git a/packages/rnv/src/core/systemManager/fileutils.ts b/packages/rnv/src/core/systemManager/fileutils.ts index f468e3ce63..1a422a6007 100755 --- a/packages/rnv/src/core/systemManager/fileutils.ts +++ b/packages/rnv/src/core/systemManager/fileutils.ts @@ -28,26 +28,26 @@ export const fsCopyFileSync = (source: string, dest: string) => { fs.copyFileSync(source, dest); }; -export const fsExistsSync = (dest: fs.PathLike) => fs.existsSync(dest); +export const fsExistsSync = (dest: fs.PathLike | undefined) => fs.existsSync(dest!); -export const fsReaddirSync = (dest: fs.PathLike) => fs.readdirSync(dest); +export const fsReaddirSync = (dest: fs.PathLike | undefined) => fs.readdirSync(dest!); -export const fsLstatSync = (dest: fs.PathLike) => fs.lstatSync(dest); +export const fsLstatSync = (dest: fs.PathLike | undefined) => fs.lstatSync(dest!); -export const fsReadFileSync = (dest: fs.PathLike) => fs.readFileSync(dest); +export const fsReadFileSync = (dest: fs.PathLike | undefined) => fs.readFileSync(dest!); -export const fsChmodSync = (dest: fs.PathLike, flag: fs.Mode) => fs.chmodSync(dest, flag); +export const fsChmodSync = (dest: fs.PathLike | undefined, flag: fs.Mode) => fs.chmodSync(dest!, flag); -export const fsRenameSync = (arg1: fs.PathLike, arg2: fs.PathLike) => fs.renameSync(arg1, arg2); +export const fsRenameSync = (arg1: fs.PathLike | undefined, arg2: fs.PathLike) => fs.renameSync(arg1!, arg2); -export const fsStatSync = (arg1: fs.PathLike) => fs.statSync(arg1); +export const fsStatSync = (arg1: fs.PathLike | undefined) => fs.statSync(arg1!); -export const fsMkdirSync = (arg1: fs.PathLike) => fs.mkdirSync(arg1); +export const fsMkdirSync = (arg1: fs.PathLike | undefined) => fs.mkdirSync(arg1!); -export const fsUnlinkSync = (arg1: fs.PathLike) => fs.unlinkSync(arg1); +export const fsUnlinkSync = (arg1: fs.PathLike | undefined) => fs.unlinkSync(arg1!); -export const fsSymlinkSync = (arg1: fs.PathLike, arg2: fs.PathLike) => { - fs.symlinkSync(arg1, arg2); +export const fsSymlinkSync = (arg1: fs.PathLike | undefined, arg2: fs.PathLike) => { + fs.symlinkSync(arg1!, arg2); }; export const fsReadFile = (arg1: fs.PathLike, arg2: any) => { @@ -267,7 +267,7 @@ export const copyFolderRecursiveSync = ( }; export const copyFolderContentsRecursiveSync = ( - source: string | null, + source: string | null | undefined, target: string, convertSvg = true, skipPaths?: Array, @@ -475,7 +475,7 @@ export const writeObjectSync = (filePath: string, obj: string | object, spaces: return writeFileSync(filePath, obj, spaces, addNewLine); }; -export const readObjectSync = (filePath: string, sanitize?: boolean, c?: RnvConfig) => { +export const readObjectSync = (filePath?: string, sanitize?: boolean, c?: RnvConfig) => { logDebug(`readObjectSync:${sanitize}:${filePath}`); if (!filePath) { logDebug('readObjectSync: filePath is undefined'); diff --git a/packages/rnv/src/core/systemManager/types.ts b/packages/rnv/src/core/systemManager/types.ts index 5cff619576..387594ebbd 100644 --- a/packages/rnv/src/core/systemManager/types.ts +++ b/packages/rnv/src/core/systemManager/types.ts @@ -1,7 +1,7 @@ export type ExecOptions = { interactive?: boolean; silent?: boolean; - stdio?: 'pipe' | 'inherit'; + stdio?: 'pipe' | 'inherit' | 'ignore'; shell?: boolean; localDir?: string; preferLocal?: boolean; From 73104def1edaec7fbf387c057e664aad812afc72 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Wed, 30 Aug 2023 21:31:26 +0200 Subject: [PATCH 24/83] plugin types, 343 togo --- packages/rnv/src/core/configManager/types.ts | 27 ++++++--- packages/rnv/src/core/pluginManager/index.ts | 59 +++++++++++-------- packages/rnv/src/core/pluginManager/types.ts | 29 ++++++++- packages/rnv/src/core/systemManager/logger.ts | 7 ++- .../engine-core/tasks/task.rnv.plugin.add.ts | 2 +- 5 files changed, 88 insertions(+), 36 deletions(-) diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index ae5da941f1..ac12f91118 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -201,6 +201,7 @@ export interface RnvConfig { configsLocal: Array; dir: string; dirs: Array; + pluginDirs: Array; }; // EXTRA buildHooks: { @@ -358,13 +359,7 @@ export type RenativeConfigFile = { version: string; } >; - plugins: Record< - string, - { - 'no-npm': boolean; - version: string; - } - >; + plugins: Record; currentTemplate: string; projectTemplates: object; platformTemplatesDirs: Record; @@ -382,6 +377,24 @@ export type RenativeConfigFile = { defaultTargets: Record; }; +export type RenativeConfigPlugin = { + source?: string; + 'no-npm'?: boolean; + 'no-active'?: boolean; + version?: string; + pluginDependencies?: Record; + ios?: any; + android?: any; + tvos?: any; + androidtv?: any; + web?: any; + webpack?: any; + npm?: Record; + enabled?: boolean; + deprecated?: boolean; + plugins?: Record; +}; + export type RenativeConfigBuildScheme = Record; export type NpmPackageFile = { diff --git a/packages/rnv/src/core/pluginManager/index.ts b/packages/rnv/src/core/pluginManager/index.ts index dd3e002c5d..5cc6b03802 100644 --- a/packages/rnv/src/core/pluginManager/index.ts +++ b/packages/rnv/src/core/pluginManager/index.ts @@ -19,13 +19,12 @@ import { import { chalk, logDebug, logError, logInfo, logSuccess, logTask, logWarning } from '../systemManager/logger'; import { installPackageDependencies } from '../systemManager/npmUtils'; import { doResolve, doResolvePath } from '../systemManager/resolve'; -import { RnvConfig } from '../configManager/types'; -import { RnvPlatform } from '../types'; +import { RenativeConfigPlugin, RnvConfig } from '../configManager/types'; import { ResolveOptions } from '../systemManager/types'; -import { PluginCallback } from './types'; +import { PluginCallback, PluginListResponse, RnvPlugin, RnvPluginPlatform, RnvPluginScope } from './types'; export const getPluginList = (c: RnvConfig, isUpdate = false) => { - const output = { + const output: PluginListResponse = { asString: '', asArray: [], plugins: [], @@ -55,10 +54,12 @@ export const getPluginList = (c: RnvConfig, isUpdate = false) => { if (isUpdate && installedPlugin) { output.plugins.push(k); let versionString; - if (installedPlugin.version !== p.version) { - versionString = `(${chalk().yellow(installedPlugin.version)}) => (${chalk().green(p.version)})`; + const installedPluginVersion = + typeof installedPlugin !== 'string' ? installedPlugin.version : installedPlugin; + if (installedPluginVersion !== p.version) { + versionString = `(${chalk().yellow(installedPluginVersion)}) => (${chalk().green(p.version)})`; } else { - versionString = `(${chalk().green(installedPlugin.version)})`; + versionString = `(${chalk().green(installedPluginVersion)})`; } output.asString += ` [${i}]> ${chalk().bold(k)} ${versionString}\n`; output.asArray.push({ @@ -99,12 +100,12 @@ export const getPluginList = (c: RnvConfig, isUpdate = false) => { return output; }; -const _getPluginScope = (plugin) => { - if (typeof plugin === 'string' || plugin instanceof String) { +const _getPluginScope = (plugin: RenativeConfigPlugin | string): RnvPluginScope => { + if (typeof plugin === 'string') { if (plugin.startsWith('source:')) { - return { scope: plugin.split(':').pop() }; + return { scope: plugin.split(':').pop() || 'rnv' }; } - return { npmVersion: plugin }; + return { npmVersion: plugin, scope: 'rnv' }; } if (plugin?.source) { return { scope: plugin?.source }; @@ -118,8 +119,8 @@ export const getMergedPlugin = (c: RnvConfig, key: string) => { const plugin = c.buildConfig.plugins?.[key]; if (!plugin) return null; - const scopes = []; - const mergedPlugin = _getMergedPlugin(c, plugin, key, null, scopes); + const scopes: Array = []; + const mergedPlugin = _getMergedPlugin(c, plugin, key, undefined, scopes); scopes.reverse(); // if (!mergedPlugin.version) { // logWarning(`Plugin ${key} has no version`); @@ -132,18 +133,19 @@ export const getMergedPlugin = (c: RnvConfig, key: string) => { const _getMergedPlugin = ( c: RnvConfig, - plugin, + plugin: RenativeConfigPlugin | string, pluginKey: string, parentScope?: string, scopes?: Array, skipSanitize?: boolean -) => { +): RnvPlugin => { if (!plugin) { return {}; } const { scope, npmVersion } = _getPluginScope(plugin); - if (scope === parentScope) return plugin; + const mergedPlgn: RnvPlugin = typeof plugin !== 'string' ? plugin : {}; + if (scope === parentScope) return mergedPlgn; if (npmVersion) { return { @@ -174,16 +176,18 @@ const _getMergedPlugin = ( scopes, true ); - let currentPlugin = plugin; + let currentPlugin: RenativeConfigPlugin; if (typeof plugin === 'string' || plugin instanceof String) { currentPlugin = {}; + } else { + currentPlugin = plugin; } INJECTABLE_CONFIG_PROPS.forEach((v) => { c.configPropsInjects[v] = getConfigProp(c, c.platform, v); }); if (currentPlugin.pluginDependencies) { Object.keys(currentPlugin.pluginDependencies).forEach((plugDepKey) => { - if (currentPlugin.pluginDependencies[plugDepKey] === 'source:self') { + if (currentPlugin.pluginDependencies?.[plugDepKey] === 'source:self') { currentPlugin.pluginDependencies[plugDepKey] = `source:${parentScope}`; } }); @@ -204,7 +208,7 @@ const _getMergedPlugin = ( }); // IMPORTANT: only final top level merge should be sanitized - const mergedPlugin = skipSanitize + const mergedPlugin: RnvPlugin = skipSanitize ? obj : sanitizeDynamicProps(obj, { files: c.files, @@ -350,14 +354,19 @@ export const resolvePluginDependants = async (c: RnvConfig) => { const pluginKeys = Object.keys(plugins); for (let i = 0; i < pluginKeys.length; i++) { const key = pluginKeys[i]; - await _resolvePluginDependencies(c, key, plugins[key], null); + await _resolvePluginDependencies(c, key, plugins[key]); } } return true; }; -const _resolvePluginDependencies = async (c: RnvConfig, key: string, keyScope: string | null, parentKey: string) => { +const _resolvePluginDependencies = async ( + c: RnvConfig, + key: string, + keyScope: RenativeConfigPlugin | string, + parentKey?: string +) => { // IMPORTANT: Do not cache this valuse as they need to be refreshed every // round in case new plugin has been installed and c.buildConfig generated if (keyScope === null) { @@ -409,7 +418,7 @@ const _resolvePluginDependencies = async (c: RnvConfig, key: string, keyScope: s export const parsePlugins = ( c: RnvConfig, - platform: RnvPlatform, + platform: RnvPluginPlatform, pluginCallback: PluginCallback, ignorePlatformObjectCheck?: boolean ) => { @@ -632,7 +641,7 @@ const _overridePlugin = (c: RnvConfig, pluginsPath: string, dir: string) => { } let overridePath: string; - if (plugin.version) { + if (plugin?.version) { const pluginVerArr = plugin.version.split('.'); const pluginVersions: Array = []; let prevVersion: string; @@ -804,6 +813,8 @@ export const checkForPluginDependencies = async (c: RnvConfig) => { } }; +// const getPluginPlatformFromString = (p: string): RnvPluginPlatform => p as RnvPluginPlatform; + export const overrideTemplatePlugins = async (c: RnvConfig) => { logTask('overrideTemplatePlugins'); @@ -812,7 +823,7 @@ export const overrideTemplatePlugins = async (c: RnvConfig) => { const appBasePluginDir = c.paths.project.appConfigBase.pluginsDir; parsePlugins( c, - c.platform, + c.platform as RnvPluginPlatform, (plugin, pluginPlat, key) => { if (plugin?._scopes?.length) { plugin._scopes.forEach((pluginScope) => { diff --git a/packages/rnv/src/core/pluginManager/types.ts b/packages/rnv/src/core/pluginManager/types.ts index 1c9669e549..dedeb0debf 100644 --- a/packages/rnv/src/core/pluginManager/types.ts +++ b/packages/rnv/src/core/pluginManager/types.ts @@ -1 +1,28 @@ -export type PluginCallback = (plugin, pluginPlat, key: string) => void; +import { RenativeConfigPlugin } from '../configManager/types'; + +export type PluginCallback = (plugin: RnvPlugin, pluginPlat: any, key: string) => void; + +export type PluginListResponse = { + asString: string; + asArray: PluginListResponseItem[]; + plugins: PluginListResponseItem[]; + allPlugins: Record; +}; + +export type PluginListResponseItem = { + name: string; + value: string; +}; + +export type RnvPluginScope = { + npmVersion?: string; + scope: string; +}; + +export type RnvPlugin = RenativeConfigPlugin & { + scope?: string; + _scopes?: Array; + _id?: string; +}; + +export type RnvPluginPlatform = 'ios' | 'android' | 'webpack'; diff --git a/packages/rnv/src/core/systemManager/logger.ts b/packages/rnv/src/core/systemManager/logger.ts index 2724c3f835..ac0712b664 100644 --- a/packages/rnv/src/core/systemManager/logger.ts +++ b/packages/rnv/src/core/systemManager/logger.ts @@ -388,16 +388,17 @@ export const logHook = (hook = '', msg = '') => { ); }; -export const logWarning = (msg: string) => { +export const logWarning = (msg: string | boolean) => { + const msgSn = typeof msg === 'string' ? _sanitizePaths(msg) : String(msg); if (_jsonOnly) { return _printJson({ type: 'log', level: 'warning', task: stripAnsi(_getCurrentTask()), - message: stripAnsi(_sanitizePaths(msg)), + message: stripAnsi(msgSn), }); } - logAndSave(currentChalk.yellow(`[ warn ]${_getCurrentTask()} ${_sanitizePaths(msg)}`)); + logAndSave(currentChalk.yellow(`[ warn ]${_getCurrentTask()} ${msgSn}`)); }; export const logInfo = (msg: string) => { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.plugin.add.ts b/packages/rnv/src/engine-core/tasks/task.rnv.plugin.add.ts index 7ea1c913a7..6fb10389c0 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.plugin.add.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.plugin.add.ts @@ -18,7 +18,7 @@ export const taskRnvPluginAdd: RnvTaskFn = async (c, _parentTask, originTask) => const o = getPluginList(c); const selPlugin = selPluginKey && o.allPlugins[selPluginKey]; - const selectedPlugins: Record = {}; + const selectedPlugins: Record = {}; const installMessage = []; if (!selPlugin) { From 945388fe8391bcb8a641b6919731f73c2e00906f Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Wed, 30 Aug 2023 22:42:47 +0200 Subject: [PATCH 25/83] more ts migrations, 298 togo --- packages/rnv/src/core/configManager/types.ts | 29 +++++++- packages/rnv/src/core/pluginManager/index.ts | 68 +++++++++++-------- packages/rnv/src/core/pluginManager/types.ts | 7 +- .../src/core/sdkManager/deviceUtils/webos.ts | 10 ++- packages/rnv/src/core/sdkManager/installer.ts | 6 +- packages/rnv/src/core/taskManager/index.ts | 20 ++++-- packages/rnv/src/core/taskManager/types.ts | 3 + .../rnv/src/core/templateManager/index.ts | 4 +- .../rnv/src/engine-core/tasks/task.rnv.new.ts | 32 ++++----- 9 files changed, 119 insertions(+), 60 deletions(-) diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index ac12f91118..7ece7f3c96 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -36,6 +36,7 @@ export interface RnvConfig { }; configPropsInjects: any; runtime: { + platform: string; appId: string | null; appDir: string; enginesByPlatform: Record; @@ -53,7 +54,7 @@ export interface RnvConfig { supportedPlatforms: Array<{ platform: string; isConnected: boolean; - engine: any; + engine?: any; }>; keepSessionActive: boolean; platformBuildsProjectPath: string; @@ -388,11 +389,35 @@ export type RenativeConfigPlugin = { tvos?: any; androidtv?: any; web?: any; - webpack?: any; + webpack?: RenativeWebpackConfig; //DEPRECATED + webpackConfig?: RenativeWebpackConfig; npm?: Record; enabled?: boolean; deprecated?: boolean; plugins?: Record; + props?: Record; +}; + +export type RenativeWebpackConfig = { + modulePaths?: + | Array< + | { + projectPath: string; + } + | string + > + | boolean; + + moduleAliases?: + | Record< + string, + | string + | { + path: string; + projectPath: string; + } + > + | boolean; }; export type RenativeConfigBuildScheme = Record; diff --git a/packages/rnv/src/core/pluginManager/index.ts b/packages/rnv/src/core/pluginManager/index.ts index 5cc6b03802..91c93e1c7d 100644 --- a/packages/rnv/src/core/pluginManager/index.ts +++ b/packages/rnv/src/core/pluginManager/index.ts @@ -19,7 +19,7 @@ import { import { chalk, logDebug, logError, logInfo, logSuccess, logTask, logWarning } from '../systemManager/logger'; import { installPackageDependencies } from '../systemManager/npmUtils'; import { doResolve, doResolvePath } from '../systemManager/resolve'; -import { RenativeConfigPlugin, RnvConfig } from '../configManager/types'; +import { RenativeConfigPlugin, RenativeWebpackConfig, RnvConfig } from '../configManager/types'; import { ResolveOptions } from '../systemManager/types'; import { PluginCallback, PluginListResponse, RnvPlugin, RnvPluginPlatform, RnvPluginScope } from './types'; @@ -236,7 +236,7 @@ export const configurePlugins = async (c: RnvConfig) => { } const { isTemplate } = c.files.project.config; - const newDeps: Record = {}; + const newDeps: Record = {}; const newDevDeps: Record = {}; const { dependencies, devDependencies } = c.files.project.package; const ovMsg = isTemplate ? 'This is template. NO ACTION' : 'package.json will be overriden'; @@ -303,7 +303,7 @@ ${ovMsg}` if (plugin && plugin.npm) { Object.keys(plugin.npm).forEach((npmKey) => { - const npmDep = plugin.npm[npmKey]; + const npmDep = plugin.npm?.[npmKey]; // IMPORTANT: Do not override top level override with plugin.npm ones const topLevelPlugin = getMergedPlugin(c, npmKey); if (topLevelPlugin && topLevelPlugin?.version !== npmDep) { @@ -640,7 +640,7 @@ const _overridePlugin = (c: RnvConfig, pluginsPath: string, dir: string) => { ); } - let overridePath: string; + let overridePath: string | undefined; if (plugin?.version) { const pluginVerArr = plugin.version.split('.'); const pluginVersions: Array = []; @@ -663,10 +663,10 @@ const _overridePlugin = (c: RnvConfig, pluginsPath: string, dir: string) => { } } - if (!fsExistsSync(overridePath)) { + if (overridePath && !fsExistsSync(overridePath)) { overridePath = path.resolve(pluginsPath, dir, 'overrides.json'); } - const overrideConfig = readObjectSync(overridePath); + const overrideConfig = overridePath ? readObjectSync(overridePath) : null; const overrides = overrideConfig?.overrides; if (overrides) { Object.keys(overrides).forEach((k) => { @@ -683,7 +683,7 @@ const _overridePlugin = (c: RnvConfig, pluginsPath: string, dir: string) => { } }; -export const overrideFileContents = (dest: string, override, overridePath = '') => { +export const overrideFileContents = (dest: string, override: Record, overridePath = '') => { if (fsExistsSync(dest)) { let fileToFix = fsReadFileSync(dest).toString(); let foundRegEx = false; @@ -762,7 +762,7 @@ const _getPluginConfiguration = (c: RnvConfig, pluginName: string) => { }; export const checkForPluginDependencies = async (c: RnvConfig) => { - const toAdd = {}; + const toAdd: Record = {}; Object.keys(c.buildConfig.plugins).forEach((pluginName) => { const renativePluginConfig = _getPluginConfiguration(c, pluginName); @@ -773,7 +773,8 @@ export const checkForPluginDependencies = async (c: RnvConfig) => { if (renativePluginConfig?.plugins) { // we have dependencies for this plugin Object.keys(renativePluginConfig.plugins).forEach((p) => { - if (!c.buildConfig.plugins[p] && c.buildConfig.plugins[pluginName].plugins?.[p] !== null) { + const plg = c.buildConfig.plugins[pluginName]; + if (!c.buildConfig.plugins[p] && typeof plg !== 'string' && plg.plugins?.[p] !== null) { logWarning(`Plugin ${p} is not installed yet.`); toAdd[p] = renativePluginConfig.plugins[p]; c.buildConfig.plugins[p] = renativePluginConfig.plugins[p]; @@ -854,19 +855,21 @@ export const copyTemplatePluginsSync = (c: RnvConfig) => { logTask('copyTemplatePluginsSync', `(${destPath})`); - parsePlugins(c, platform, (plugin, pluginPlat, key) => { + parsePlugins(c, platform as RnvPluginPlatform, (plugin, pluginPlat, key) => { const objectInject = [...c.configPropsInjects]; if (plugin.props) { Object.keys(plugin.props).forEach((v) => { objectInject.push({ pattern: `{{props.${v}}}`, - override: plugin.props[v], + override: plugin.props?.[v], }); }); } // FOLDER MERGES FROM PROJECT CONFIG PLUGIN - const sourcePathRnvPlugin = getBuildsFolder(c, platform, path.join(c.paths.rnv.pluginTemplates.dir, key)); - copyFolderContentsRecursiveSync(sourcePathRnvPlugin, destPath, true, undefined, false, objectInject); + if (c.paths.rnv.pluginTemplates.dir) { + const sourcePathRnvPlugin = getBuildsFolder(c, platform, path.join(c.paths.rnv.pluginTemplates.dir, key)); + copyFolderContentsRecursiveSync(sourcePathRnvPlugin, destPath, true, undefined, false, objectInject); + } // FOLDER MERGES FROM PROJECT CONFIG PLUGIN const sourcePath3 = getBuildsFolder( @@ -892,7 +895,7 @@ export const copyTemplatePluginsSync = (c: RnvConfig) => { ); copyFolderContentsRecursiveSync(sourcePath3sec, destPath, true, undefined, false, objectInject); - if (fsExistsSync(sourcePath3secLegacy)) { + if (sourcePath3secLegacy && fsExistsSync(sourcePath3secLegacy)) { logWarning(`Path: ${chalk().red(sourcePath3secLegacy)} is DEPRECATED. Move your files to: ${chalk().white(sourcePath3sec)} instead`); } @@ -921,11 +924,11 @@ export const copyTemplatePluginsSync = (c: RnvConfig) => { }); }; -export const sanitizePluginPath = (str: string, name: string, mandatory: boolean, options: ResolveOptions) => { +export const sanitizePluginPath = (str: string, name: string, mandatory?: boolean, options?: ResolveOptions) => { let newStr = str; try { if (str?.replace) { - newStr = str.replace('{{PLUGIN_ROOT}}', doResolve(name, mandatory, options)); + newStr = str.replace('{{PLUGIN_ROOT}}', doResolve(name, mandatory, options) || ''); } } catch (e) { // Ignore @@ -952,8 +955,8 @@ export const getLocalRenativePlugin = () => ({ }, }); -export const getModuleConfigs = (c: RnvConfig, primaryKey: string) => { - let modulePaths: Array = []; +export const getModuleConfigs = (c: RnvConfig, primaryKey?: RnvPluginPlatform) => { + let modulePaths: Array = []; const moduleAliases: Record = {}; const doNotResolveModulePaths: Array = []; @@ -961,16 +964,22 @@ export const getModuleConfigs = (c: RnvConfig, primaryKey: string) => { // PLUGINS parsePlugins( c, - c.platform, + c.platform as RnvPluginPlatform, (plugin, pluginPlat, key) => { - const webpackConfig = plugin[primaryKey] || plugin.webpack || plugin.webpackConfig; + let webpackConfig: RenativeWebpackConfig | undefined; + + if (primaryKey && plugin[primaryKey]) { + webpackConfig = plugin[primaryKey]; + } else { + webpackConfig = plugin.webpack || plugin.webpackConfig; + } if (webpackConfig) { if (webpackConfig.modulePaths) { - if (webpackConfig.modulePaths === false) { - // ignore - } else if (webpackConfig.modulePaths === true) { - modulePaths.push(`node_modules/${key}`); + if (typeof webpackConfig.modulePaths === 'boolean') { + if (webpackConfig.modulePaths) { + modulePaths.push(`node_modules/${key}`); + } } else { webpackConfig.modulePaths.forEach((v) => { if (typeof v === 'string') { @@ -983,12 +992,13 @@ export const getModuleConfigs = (c: RnvConfig, primaryKey: string) => { }); } } - if (webpackConfig.moduleAliases) { - if (webpackConfig.moduleAliases === true) { + const wpMa = webpackConfig.moduleAliases; + if (wpMa) { + if (typeof wpMa === 'boolean') { moduleAliases[key] = doResolvePath(key, true, {}, c.paths.project.nodeModulesDir); } else { - Object.keys(webpackConfig.moduleAliases).forEach((aKey) => { - const mAlias = webpackConfig.moduleAliases[aKey]; + Object.keys(wpMa).forEach((aKey) => { + const mAlias = wpMa[aKey]; if (typeof mAlias === 'string') { moduleAliases[key] = doResolvePath(mAlias, true, {}, c.paths.project.nodeModulesDir); } else if (mAlias.path) { @@ -1012,7 +1022,7 @@ export const getModuleConfigs = (c: RnvConfig, primaryKey: string) => { }); modulePaths = modulePaths - .map((v) => doResolvePath(v, true, {}, c.paths.project.dir)) + .map((v) => v && doResolvePath(v, true, {}, c.paths.project.dir)) .concat(doNotResolveModulePaths) .concat([c.paths.project.assets.dir]) .filter(Boolean); diff --git a/packages/rnv/src/core/pluginManager/types.ts b/packages/rnv/src/core/pluginManager/types.ts index dedeb0debf..87110eac55 100644 --- a/packages/rnv/src/core/pluginManager/types.ts +++ b/packages/rnv/src/core/pluginManager/types.ts @@ -6,7 +6,12 @@ export type PluginListResponse = { asString: string; asArray: PluginListResponseItem[]; plugins: PluginListResponseItem[]; - allPlugins: Record; + allPlugins: Record< + string, + { + version: string; + } + >; }; export type PluginListResponseItem = { diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts b/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts index 17d901d893..92154fde38 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts @@ -133,8 +133,16 @@ const waitForEmulatorToBeReady = async (c: RnvConfig) => { export const runWebosSimOrDevice = async (c: RnvConfig) => { const { device } = c.program; + const platDir = getPlatformBuildDir(c); + if (!platDir) { + return Promise.reject(`Cannot determine getPlatformBuildDir value`); + } + const tDir = getPlatformProjectDir(c); - const tOut = path.join(getPlatformBuildDir(c), 'output'); + if (!tDir) { + return Promise.reject(`Cannot determine getPlatformProjectDir value`); + } + const tOut = path.join(platDir, 'output'); const tSim = c.program.target || 'emulator'; const configFilePath = path.join(tDir, 'appinfo.json'); diff --git a/packages/rnv/src/core/sdkManager/installer.ts b/packages/rnv/src/core/sdkManager/installer.ts index be7404d097..d72b4c51dc 100644 --- a/packages/rnv/src/core/sdkManager/installer.ts +++ b/packages/rnv/src/core/sdkManager/installer.ts @@ -181,7 +181,7 @@ const _isSdkInstalled = (c: RnvConfig) => { return fsExistsSync(getRealPath(c, sdkPath)); }; -const _findFolderWithFile = (dir, fileToFind) => { +const _findFolderWithFile = (dir: string, fileToFind: string) => { const opt = path.join(dir, fileToFind); if (fsExistsSync(opt)) { return dir; @@ -207,7 +207,7 @@ const _attemptAutoFix = async (c: RnvConfig, sdkPlatform: string, sdkKey: string return true; } - let locations = SDK_LOCATIONS[sdkPlatform]; + let locations: Array = SDK_LOCATIONS[sdkPlatform]; // try common Android SDK env variables if (sdkKey === ANDROID_SDK) { @@ -227,7 +227,7 @@ const _attemptAutoFix = async (c: RnvConfig, sdkPlatform: string, sdkKey: string if (subResult) { result = subResult; } else { - result = null; + // result = null; } } diff --git a/packages/rnv/src/core/taskManager/index.ts b/packages/rnv/src/core/taskManager/index.ts index d5b91bc5cf..6c0529264b 100644 --- a/packages/rnv/src/core/taskManager/index.ts +++ b/packages/rnv/src/core/taskManager/index.ts @@ -14,6 +14,7 @@ import { import { TASK_CONFIGURE_SOFT } from '../constants'; import { RnvConfig } from '../configManager/types'; import { RnvTask, RnvTaskMap } from './types'; +import { RnvEngine } from '../engineManager/types'; let executedTasks = {}; @@ -280,8 +281,8 @@ const _populateExtraParameters = (c: RnvConfig, task: RnvTask) => { } }; -const _selectPlatform = async (c: RnvConfig, suitableEngines, task: string) => { - const supportedPlatforms = {}; +const _selectPlatform = async (c: RnvConfig, suitableEngines: Array, task: string) => { + const supportedPlatforms: Record = {}; suitableEngines.forEach((engine) => { getEngineTask(task, engine.tasks).platforms.forEach((plat) => { supportedPlatforms[plat] = true; @@ -344,11 +345,11 @@ export const executeOrSkipTask = async (c: RnvConfig, task, parentTask, originTa const ACCEPTED_CONDITIONS = ['platform', 'target', 'appId', 'scheme']; -const _logSkip = (task) => { +const _logSkip = (task: string) => { logInfo(`Original RNV task ${chalk().white(task)} marked to ignore. SKIPPING...`); }; -export const shouldSkipTask = (c: RnvConfig, task, originTask) => { +export const shouldSkipTask = (c: RnvConfig, task: string, originTask: string) => { const tasks = c.buildConfig?.tasks; c.runtime.platform = c.platform; if (!tasks) return; @@ -407,7 +408,14 @@ export const shouldSkipTask = (c: RnvConfig, task, originTask) => { return false; }; -export const executeEngineTask = async (c: RnvConfig, task, parentTask, originTask, tasks, isFirstTask) => { +export const executeEngineTask = async ( + c: RnvConfig, + task: string, + parentTask: string, + originTask: string, + tasks: Record, + isFirstTask: boolean +) => { const needsHelp = Object.prototype.hasOwnProperty.call(c.program, 'help'); const t = getEngineTask(task, tasks, CUSTOM_TASKS); @@ -444,7 +452,7 @@ ${t.params } } if (isFirstTask) { - c.runtime.forceBuildHookRebuild = t.forceBuildHookRebuild; + c.runtime.forceBuildHookRebuild = !!t.forceBuildHookRebuild; } const inOnlyMode = c.program.only; const doPipe = !t.isGlobalScope && (!inOnlyMode || (inOnlyMode && isFirstTask)); diff --git a/packages/rnv/src/core/taskManager/types.ts b/packages/rnv/src/core/taskManager/types.ts index ec44b2140e..f62b093f3d 100644 --- a/packages/rnv/src/core/taskManager/types.ts +++ b/packages/rnv/src/core/taskManager/types.ts @@ -6,6 +6,9 @@ export type RnvTask = { isGlobalScope?: boolean; platforms: Array; description: string; + forceBuildHookRebuild?: boolean; + fn?: RnvTaskFn; + fnHelp?: RnvTaskFn; }; export type RnvTaskParameter = { diff --git a/packages/rnv/src/core/templateManager/index.ts b/packages/rnv/src/core/templateManager/index.ts index e7e7272ae6..e40f62f0a6 100644 --- a/packages/rnv/src/core/templateManager/index.ts +++ b/packages/rnv/src/core/templateManager/index.ts @@ -88,11 +88,11 @@ const _applyTemplate = async (c: RnvConfig) => { // c.runtime.selectedTemplate // ); // } else { - c.paths.template.dir = doResolve(c.runtime.selectedTemplate); + c.paths.template.dir = doResolve(c.runtime.selectedTemplate) || 'Error: unresolved'; // c.paths.template.dir = path.join(c.paths.project.nodeModulesDir, c.runtime.selectedTemplate); // } } else { - c.paths.template.dir = doResolve(c.buildConfig.currentTemplate); + c.paths.template.dir = doResolve(c.buildConfig.currentTemplate) || 'Error: unresolved'; // c.paths.template.dir = path.join(c.paths.project.nodeModulesDir, c.buildConfig.currentTemplate); } diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.new.ts b/packages/rnv/src/engine-core/tasks/task.rnv.new.ts index 5926e13e5d..3dc2512052 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.new.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.new.ts @@ -38,19 +38,19 @@ import { RnvConfig } from '../../core/configManager/types'; const highlight = chalk().green; type NewProjectData = { - appTitle: string; - inputAppTitle: string; - packageName: string; - defaultAppTitle: string; - defaultTemplate: string; - inputProjectName: string; - teamID: string; - appID: string; - inputAppID: string; - inputVersion: string; + appTitle?: string; + inputAppTitle?: string; + packageName?: string; + defaultAppTitle?: string; + defaultTemplate?: string; + inputProjectName?: string; + teamID?: string; + appID?: string; + inputAppID?: string; + inputVersion?: string; defaultVersion: string; - inputTemplate: string; - version: string; + inputTemplate?: string; + version?: string; optionTemplates: { selectedOption?: string; selectedVersion?: string; @@ -60,14 +60,14 @@ type NewProjectData = { }; projectName: string; optionWorkspaces: { - selectedOption: string; + selectedOption?: string; valuesAsObject?: any; valuesAsArray?: Array; keysAsArray?: Array; }; gitEnabled: boolean; optionPlatforms: { - selectedOptions: Array; + selectedOptions?: Array; }; confirmString: string; defaultProjectName: string; @@ -92,7 +92,7 @@ const _prepareProjectOverview = (c: RnvConfig, data: NewProjectData) => { str += printIntoBox(`Git Enabled: ${highlight(data.gitEnabled)}`); str += printIntoBox(''); str += printIntoBox('Project Platforms:'); - str += printArrIntoBox(data.optionPlatforms.selectedOptions); + str += printArrIntoBox(data.optionPlatforms.selectedOptions || []); str += printIntoBox(''); str += printIntoBox('Project Structure:'); str += printIntoBox(''); @@ -408,7 +408,7 @@ export const taskRnvNew = async (c: RnvConfig) => { return; } - if (!data.optionTemplates.keysAsArray.includes(selectedInputTemplate)) { + if (!data.optionTemplates.keysAsArray?.includes(selectedInputTemplate)) { const { confirmAddTemplate } = await inquirer.prompt({ name: 'confirmAddTemplate', type: 'confirm', From e7f107ee95c0feef2b227f327728ce23c3fb07a1 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Wed, 30 Aug 2023 23:51:04 +0200 Subject: [PATCH 26/83] engine ts migration, 279 togo --- packages/rnv/src/core/configManager/types.ts | 4 +- packages/rnv/src/core/engineManager/index.ts | 40 ++++++++++---------- packages/rnv/src/core/engineManager/types.ts | 39 ++++++++++++++++++- packages/rnv/src/core/taskManager/index.ts | 13 +++++-- 4 files changed, 69 insertions(+), 27 deletions(-) diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index 7ece7f3c96..1c7e06656f 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -49,7 +49,7 @@ export interface RnvConfig { }; bundleAssets: boolean; activeTemplate: string; - engine: any; + engine?: RnvEngine; target: string; supportedPlatforms: Array<{ platform: string; @@ -372,7 +372,7 @@ export type RenativeConfigFile = { integrations: Record; tasks: Array | Record; engineTemplates: Record; - engines: Record; + engines: Record; pluginTemplates: Record; runtime: Record; defaultTargets: Record; diff --git a/packages/rnv/src/core/engineManager/index.ts b/packages/rnv/src/core/engineManager/index.ts index 30371361ed..6a9c4c194c 100644 --- a/packages/rnv/src/core/engineManager/index.ts +++ b/packages/rnv/src/core/engineManager/index.ts @@ -12,7 +12,7 @@ import { inquirerPrompt } from '../../cli/prompt'; import { RnvConfig } from '../configManager/types'; import { RnvTask, RnvTaskMap } from '../taskManager/types'; import { RnvModuleConfig, RnvNextJSConfig, RnvPlatform } from '../types'; -import { RnvEngine, RnvEngineConfig, RnvEngineConfigMap, RnvEngineInstallConfig } from './types'; +import { RenativeEngineConfig, RnvEngine, RnvEngineConfig, RnvEngineConfigMap, RnvEngineInstallConfig } from './types'; const ENGINE_CORE = 'engine-core'; @@ -38,13 +38,13 @@ export const registerEngine = async ( _registerEnginePlatform(c, platform, engine); }; -const _registerEnginePlatform = (c: RnvConfig, platform: RnvPlatform, engine: RnvEngine) => { - if (platform) { +const _registerEnginePlatform = (c: RnvConfig, platform?: RnvPlatform, engine?: RnvEngine) => { + if (platform && engine) { c.runtime.enginesByPlatform[platform] = engine; } }; -export const registerEngineExtension = (ext: string | null, eExt: string | null, extras: Array = []) => { +export const registerEngineExtension = (ext: string | null, eExt?: string | null, extras: Array = []) => { const e1 = ext ? `${ext}.` : ''; const e2 = eExt ? `${eExt}.` : ''; let extArr; @@ -67,7 +67,7 @@ export const registerEngineExtension = (ext: string | null, eExt: string | null, return extArr; }; -export const generateEngineExtensions = (exts: Array, config) => { +export const generateEngineExtensions = (exts: Array, config: RenativeEngineConfig) => { const { id, engineExtension } = config; let extArr = [...registerEngineExtension(id)]; exts.forEach((ext) => { @@ -126,7 +126,7 @@ export const registerMissingPlatformEngines = async (c: RnvConfig, taskInstance? (!taskInstance.isGlobalScope && taskInstance?.platforms?.length === 0) || c.program.platform === 'all' ) { - const registerEngineList = []; + const registerEngineList: Array> = []; c.buildConfig.defaults.supportedPlatforms.forEach((platform) => { registerEngineList.push(_registerPlatformEngine(c, platform)); }); @@ -157,7 +157,7 @@ export const registerAllPlatformEngines = async (c: RnvConfig) => { return true; }; -export const loadEnginePluginDeps = async (c: RnvConfig, engineConfigs) => { +export const loadEnginePluginDeps = async (c: RnvConfig, engineConfigs: Array) => { logTask('loadEnginePluginDeps'); if (c.files.project.config.isTemplate) return 0; @@ -207,7 +207,7 @@ If you don't want to use this dependency make sure you remove platform which req return Object.keys(addedPlugins).length; }; -export const loadEnginePackageDeps = async (c: RnvConfig, engineConfigs) => { +export const loadEnginePackageDeps = async (c: RnvConfig, engineConfigs: Array) => { logTask('loadEnginePackageDeps'); if (c.program.skipDependencyCheck || c.files.project.config.isTemplate) return 0; // Check engine dependencies @@ -305,7 +305,7 @@ const _getFilteredEngines = (c: RnvConfig) => { const rnvPlatforms = c.files.rnv.projectTemplates?.config?.platforms; const supportedPlatforms = c.files.project.config.defaults?.supportedPlatforms || []; - const filteredEngines = {}; + const filteredEngines: Record = {}; supportedPlatforms.forEach((v: string) => { const platforms = c.files.project.config.platforms || {}; const engineKey = platforms[v]?.engine || rnvPlatforms[v]?.engine; @@ -328,9 +328,9 @@ export const loadEngines = async (c: RnvConfig, failOnMissingDeps?: boolean): Pr logTask('loadEngines'); if (!fsExistsSync(c.paths.project.config)) return true; - const filteredEngines: Record = _getFilteredEngines(c); + const filteredEngines: Record = _getFilteredEngines(c); const enginesToInstall: Array = []; - const readyEngines: Array = []; + const readyEngines: Array = []; const engineConfigs: Array = []; // if (filteredEngines) { Object.keys(filteredEngines).forEach((k) => { @@ -422,9 +422,10 @@ const _getMergedEngineConfigs = (c: RnvConfig) => { if (!engineTemplatesKeys.includes(enginePackageName)) { logWarning(`Engine ${enginePackageName} not found in default engineTemplates`); } - } else { - mergedEngineConfigs[enginePackageName] = engineVal; } + // else { + // mergedEngineConfigs[enginePackageName] = engineVal; + // } }); } return mergedEngineConfigs; @@ -468,7 +469,7 @@ const _resolvePkgPath = (c: RnvConfig, packageName: string) => { return pkgPath; }; -const _registerPlatformEngine = async (c: RnvConfig, platform: RnvPlatform): Promise => { +const _registerPlatformEngine = async (c: RnvConfig, platform: RnvPlatform | boolean): Promise => { // Only register active platform engine to be faster if (platform === true || !platform) return; const selectedEngineConfig = _getEngineConfigByPlatform(c, platform); @@ -484,7 +485,7 @@ const _registerPlatformEngine = async (c: RnvConfig, platform: RnvPlatform): Pro } else { _registerEnginePlatform(c, platform, existingEngine); } - } else if (platform !== true && platform) { + } else if (platform) { logWarning(`Could not find suitable engine for platform ${platform} Maybe you forgot to define platforms.${platform}.engine in your renative.json?`); } @@ -495,7 +496,7 @@ export const generateEnvVars = (c: RnvConfig, moduleConfig: RnvModuleConfig, nex const monoRoot = getConfigProp(c, c.platform, 'monoRoot'); return { RNV_EXTENSIONS: getPlatformExtensions(c), - RNV_ENGINE_PATH: c.runtime.engine.rootPath, + RNV_ENGINE_PATH: c.runtime.engine?.rootPath, RNV_MODULE_PATHS: moduleConfig?.modulePaths || [], RNV_MODULE_ALIASES: moduleConfig?.moduleAliasesArray || [], RNV_NEXT_TRANSPILE_MODULES: nextConfig, @@ -503,14 +504,15 @@ export const generateEnvVars = (c: RnvConfig, moduleConfig: RnvModuleConfig, nex RNV_APP_BUILD_DIR: getAppFolder(c), RNV_IS_MONOREPO: isMonorepo, RNV_MONO_ROOT: isMonorepo ? path.join(c.paths.project.dir, monoRoot || '../..') : c.paths.project.dir, - RNV_ENGINE: c.runtime.engine.config.id, + RNV_ENGINE: c.runtime.engine?.config.id, RNV_IS_NATIVE_TV: [TVOS, ANDROID_TV, FIRE_TV].includes(c.platform), }; }; -export const getPlatformExtensions = (c: RnvConfig, excludeServer = false, addDotPrefix = false) => { +export const getPlatformExtensions = (c: RnvConfig, excludeServer = false, addDotPrefix = false): Array => { const { engine } = c.runtime; let output; + if (!engine) return []; const { platforms } = engine; if (addDotPrefix) { @@ -551,7 +553,7 @@ export const getEngineTask = ( export const hasEngineTask = (task: string, tasks: RnvTaskMap, isProjectScope: boolean) => isProjectScope ? !!getEngineTask(task, tasks) : getEngineTask(task, tasks)?.isGlobalScope; -export const getEngineSubTasks = (task: string, tasks: RnvTaskMap, exactMatch: boolean) => +export const getEngineSubTasks = (task: string, tasks: RnvTaskMap, exactMatch?: boolean) => Object.values(tasks).filter((v) => (exactMatch ? v.task.split(' ')[0] === task : v.task.startsWith(task))); export const getEngineRunner = (c: RnvConfig, task: string, customTasks?: RnvTaskMap, failOnMissingEngine = true) => { diff --git a/packages/rnv/src/core/engineManager/types.ts b/packages/rnv/src/core/engineManager/types.ts index 4048805745..b12bbfcf8a 100644 --- a/packages/rnv/src/core/engineManager/types.ts +++ b/packages/rnv/src/core/engineManager/types.ts @@ -1,10 +1,19 @@ +import { RnvConfig } from '../configManager/types'; import { RnvTaskMap } from '../taskManager/types'; export type RnvEngine = { originalTemplatePlatformsDir: string; - platforms: any; + platforms: Record; config: RnvEngineConfig; tasks: RnvTaskMap; + initializeRuntimeConfig: (c: RnvConfig) => void; + rootPath: string; + originalTemplatePlatformProjectDir: string; + projectDirName: string; +}; + +export type RnvEnginePlatform = { + extensions: Array; }; export type RnvEngineConfig = { @@ -12,6 +21,7 @@ export type RnvEngineConfig = { platforms: any; npm: any; plugins: any; + packageName: string; }; export type RnvEngineConfigMap = Record; @@ -19,6 +29,31 @@ export type RnvEngineConfigMap = Record; export type RnvEngineInstallConfig = { key: string; version?: string; - engineRootPath: string; + engineRootPath?: string; configPath?: string; }; + +export type RenativeEngineConfig = { + id: string; + engineExtension: string; + overview: string; + plugins: Record; + npm: Record>; + platforms: { + ios: RenativeEngineConfigPlatform; + macos: RenativeEngineConfigPlatform; + android: RenativeEngineConfigPlatform; + androidwear: RenativeEngineConfigPlatform; + androidtv: RenativeEngineConfigPlatform; + firetv: RenativeEngineConfigPlatform; + }; +}; + +export type RenativeEngineConfigPlatform = { + engine: string; + npm: { + dependencies?: Record; + devDependencies?: Record; + peerDependencies?: Record; + }; +}; diff --git a/packages/rnv/src/core/taskManager/index.ts b/packages/rnv/src/core/taskManager/index.ts index 6c0529264b..76cb4e7014 100644 --- a/packages/rnv/src/core/taskManager/index.ts +++ b/packages/rnv/src/core/taskManager/index.ts @@ -67,13 +67,18 @@ const _getTaskObj = (taskInstance: RnvTask) => { }; }; -export const findSuitableTask = async (c: RnvConfig, specificTask?: string) => { +type TaskObj = { + key: string; + taskInstance: RnvTask; +}; + +export const findSuitableTask = async (c: RnvConfig, specificTask?: string): Promise => { logTask('findSuitableTask'); const REGISTERED_ENGINES = getRegisteredEngines(c); - let task: string = ''; + let task = ''; if (!specificTask) { if (!c.command) { - const suitableTaskInstances = {}; + const suitableTaskInstances: Record = {}; REGISTERED_ENGINES.forEach((engine) => { Object.values(engine.tasks).forEach((taskInstance) => { const taskObj = _getTaskObj(taskInstance); @@ -87,7 +92,7 @@ export const findSuitableTask = async (c: RnvConfig, specificTask?: string) => { const taskInstances = Object.values(suitableTaskInstances); let tasks; - let defaultCmd = 'new'; + let defaultCmd: string | undefined = 'new'; let tasksCommands; let filteredTasks; let addendum = ''; From 5c62db04e033113c85787d56eead0273dd943894 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Thu, 31 Aug 2023 00:07:22 +0200 Subject: [PATCH 27/83] more ts migrations, 268 togo --- packages/rnv/src/core/configManager/types.ts | 2 + .../core/sdkManager/deviceUtils/android.ts | 8 +- .../rnv/src/engine-core/tasks/task.rnv.new.ts | 77 +++++++++++++++---- 3 files changed, 68 insertions(+), 19 deletions(-) diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index 1c7e06656f..844f948d63 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -352,6 +352,7 @@ export type RenativeConfigFile = { appName: string; id: string; certificateProfile: string; + engine: string; } >; templates: Record< @@ -376,6 +377,7 @@ export type RenativeConfigFile = { pluginTemplates: Record; runtime: Record; defaultTargets: Record; + templateConfig: any; }; export type RenativeConfigPlugin = { diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/android.ts b/packages/rnv/src/core/sdkManager/deviceUtils/android.ts index 9ded1a2e7a..d023f003ec 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/android.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/android.ts @@ -35,7 +35,7 @@ const CHECK_INTEVAL = 5000; const currentDeviceProps = {}; -export const composeDevicesString = (devices, returnArray) => { +export const composeDevicesString = (devices, returnArray?: boolean) => { logTask('composeDevicesString', `numDevices:${devices ? devices.length : null}`); const devicesArray = []; devices.forEach((v, i) => devicesArray.push(_getDeviceString(v, !returnArray ? i : null))); @@ -43,7 +43,11 @@ export const composeDevicesString = (devices, returnArray) => { return `\n${devicesArray.join('')}`; }; -export const launchAndroidSimulator = async (c: RnvConfig, target, isIndependentThread = false) => { +export const launchAndroidSimulator = async ( + c: RnvConfig, + target: boolean | { name: string } | string, + isIndependentThread = false +) => { logTask('launchAndroidSimulator', `target:${target} independentThread:${!!isIndependentThread}`); let newTarget = target; if (target === true) { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.new.ts b/packages/rnv/src/engine-core/tasks/task.rnv.new.ts index 3dc2512052..fc80a9e0af 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.new.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.new.ts @@ -33,7 +33,7 @@ import { printIntoBox, } from '../../core/systemManager/logger'; import { isYarnInstalled, listAndSelectNpmVersion } from '../../core/systemManager/npmUtils'; -import { RnvConfig } from '../../core/configManager/types'; +import { RenativeConfigFile, RnvConfig } from '../../core/configManager/types'; const highlight = chalk().green; @@ -55,23 +55,26 @@ type NewProjectData = { selectedOption?: string; selectedVersion?: string; valuesAsObject?: any; - valuesAsArray?: Array; + valuesAsArray?: Array<{ + title: string; + key: string; + }>; keysAsArray?: Array; }; - projectName: string; + projectName?: string; optionWorkspaces: { selectedOption?: string; valuesAsObject?: any; valuesAsArray?: Array; keysAsArray?: Array; }; - gitEnabled: boolean; + gitEnabled?: boolean; optionPlatforms: { selectedOptions?: Array; }; - confirmString: string; - defaultProjectName: string; - defaultWorkspace: string; + confirmString?: string; + defaultProjectName?: string; + defaultWorkspace?: string; }; const _prepareProjectOverview = (c: RnvConfig, data: NewProjectData) => { @@ -117,7 +120,32 @@ const _prepareProjectOverview = (c: RnvConfig, data: NewProjectData) => { data.confirmString = str; }; -const interactiveQuestion = async (results, bootstrapQuestions, providedAnswers) => { +type QuestionResults = Record< + string, + { + answer: string; + configProp: any; + value: any; + } +>; + +type BootstrapQuestions = Array<{ + options: Array<{ + title: string; + }>; + configProp: { + prop: string; + key: string; + }; + type: string; + title: string; +}>; + +const interactiveQuestion = async ( + results: QuestionResults, + bootstrapQuestions: BootstrapQuestions, + providedAnswers +) => { if (bootstrapQuestions?.length) { for (let i = 0; i < bootstrapQuestions.length; i++) { const q = bootstrapQuestions[i]; @@ -223,6 +251,9 @@ export const taskRnvNew = async (c: RnvConfig) => { defaultProjectName: 'helloRenative', defaultAppTitle: 'Hello Renative', defaultWorkspace: 'rnv', + optionPlatforms: {}, + optionTemplates: {}, + optionWorkspaces: {}, }; data.optionPlatforms = {}; data.optionTemplates = {}; @@ -350,7 +381,7 @@ export const taskRnvNew = async (c: RnvConfig) => { options.push(val.title); }); - const getTemplateKey = (val: string) => data.optionTemplates.valuesAsArray.find((v) => v.title === val)?.key; + const getTemplateKey = (val: string) => data.optionTemplates.valuesAsArray?.find((v) => v.title === val)?.key; // ================================================== // INPUT: Template @@ -389,7 +420,7 @@ export const taskRnvNew = async (c: RnvConfig) => { if (templateVersion && templateVersion !== '') { inputTemplateVersion = templateVersion; } else { - inputTemplateVersion = await listAndSelectNpmVersion(c, data.optionTemplates.selectedOption); + inputTemplateVersion = await listAndSelectNpmVersion(c, data.optionTemplates.selectedOption || ''); } data.optionTemplates.selectedVersion = inputTemplateVersion; @@ -471,7 +502,12 @@ export const taskRnvNew = async (c: RnvConfig) => { // ================================================== const renativeTemplateConfigExt = {}; const bootstrapQuestions = renativeTemplateConfig?.templateConfig?.bootstrapQuestions; - const results = {}; + const results: Record< + string, + { + value: string; + } + > = {}; const providedAnswers: Record = {}; if (c.program.answer) { @@ -562,20 +598,27 @@ export const taskRnvNew = async (c: RnvConfig) => { c.paths.project.package = path.join(c.paths.project.dir, 'package.json'); c.paths.project.config = path.join(c.paths.project.dir, RENATIVE_CONFIG_NAME); - data.packageName = data.appTitle.replace(/\s+/g, '-').toLowerCase(); + data.packageName = data?.appTitle?.replace(/\s+/g, '-').toLowerCase(); - const templates = {}; + const templates: Record< + string, + { + version?: string; + } + > = {}; logTask( `_generateProject:${data.optionTemplates.selectedOption}:${data.optionTemplates.selectedVersion}`, chalk().grey ); - templates[data.optionTemplates.selectedOption] = { - version: data.optionTemplates.selectedVersion, - }; + if (data.optionTemplates.selectedOption) { + templates[data.optionTemplates.selectedOption] = { + version: data.optionTemplates.selectedVersion, + }; + } - const config = { + const config: RenativeConfigFile = { platforms: {}, ...renativeTemplateConfig, ...renativeTemplateConfigExt, From b1485f01eb64a6f06a85574f5d62ee42aab3b1c6 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Thu, 31 Aug 2023 18:51:28 +0200 Subject: [PATCH 28/83] more ts refactor, 190 togo --- packages/rnv/src/core/configManager/types.ts | 14 ++-- packages/rnv/src/core/engineManager/index.ts | 19 +++-- packages/rnv/src/core/engineManager/types.ts | 3 + packages/rnv/src/core/pluginManager/types.ts | 9 +-- packages/rnv/src/core/runtimeManager/index.ts | 4 +- .../core/sdkManager/deviceUtils/android.ts | 80 +++++++++++-------- .../src/core/sdkManager/deviceUtils/apple.ts | 67 +++++++++------- packages/rnv/src/core/sdkManager/types.ts | 38 ++++++--- packages/rnv/src/core/systemManager/exec.ts | 4 +- packages/rnv/src/core/systemManager/logger.ts | 4 +- packages/rnv/src/core/taskManager/index.ts | 64 +++++++-------- packages/rnv/src/core/taskManager/types.ts | 17 +++- .../src/engine-core/tasks/task.rnv.doctor.ts | 20 ++--- .../rnv/src/engine-core/tasks/task.rnv.new.ts | 15 ++-- .../engine-core/tasks/task.rnv.plugin.add.ts | 7 +- 15 files changed, 201 insertions(+), 164 deletions(-) diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index 844f948d63..763e052631 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -1,4 +1,4 @@ -import { RnvEngine } from '../engineManager/types'; +import { RnvEngine, RnvEnginePlatform } from '../engineManager/types'; import { OverridesOptions } from '../systemManager/types'; import { RnvPlatform } from '../types'; @@ -44,9 +44,10 @@ export interface RnvConfig { enginesById: Record; missingEnginePlugins: Record; localhost: string; - scheme: { - bundleAssets: boolean; - }; + scheme: string; + // scheme: { + // bundleAssets: boolean; + // }; bundleAssets: boolean; activeTemplate: string; engine?: RnvEngine; @@ -76,10 +77,7 @@ export interface RnvConfig { rnvVersionRunner: string; rnvVersionProject: string; versionCheckCompleted: boolean; - currentPlatform: { - isWebHosted: boolean; - defaultPort: string; - }; + currentPlatform: RnvEnginePlatform; _skipPluginScopeWarnings: boolean; skipBuildHooks: boolean; isFirstRunAfterNew: boolean; diff --git a/packages/rnv/src/core/engineManager/index.ts b/packages/rnv/src/core/engineManager/index.ts index 6a9c4c194c..3486785a14 100644 --- a/packages/rnv/src/core/engineManager/index.ts +++ b/packages/rnv/src/core/engineManager/index.ts @@ -534,19 +534,18 @@ export const getEngineRunnerByPlatform = (c: RnvConfig, platform: string, ignore return selectedEngine; }; -export const getEngineTask = ( - task: string, - tasks: Record, - customTasks?: Record -): RnvTask => { +export const getEngineTask = (task: string, tasks?: RnvTaskMap, customTasks?: RnvTaskMap): RnvTask | undefined => { const customTask = customTasks?.[task]; if (customTask) return customTask; let tsk; const taskCleaned = task.split(' ')[0]; - tsk = tasks[task]; - if (!tsk) { - tsk = tasks[taskCleaned]; + if (tasks) { + tsk = tasks[task]; + if (!tsk) { + tsk = tasks[taskCleaned]; + } } + return tsk; }; @@ -575,14 +574,14 @@ export const getEngineRunner = (c: RnvConfig, task: string, customTasks?: RnvTas throw new Error(`Cound not find active engine for platform ${c.platform}. Available engines: ${c.runtime.enginesByIndex.map((v) => v.config.id).join(', ')}`); } - return null; + return undefined; } if (hasEngineTask(task, engine.tasks, configExists)) return engine; if (hasEngineTask(task, c.runtime.enginesById[ENGINE_CORE].tasks, configExists)) { return c.runtime.enginesById[ENGINE_CORE]; } if (failOnMissingEngine) throw new Error(`Cound not find suitable executor for task ${chalk().white(task)}`); - return null; + return undefined; }; export const getRegisteredEngines = (c: RnvConfig) => c.runtime.enginesByIndex; diff --git a/packages/rnv/src/core/engineManager/types.ts b/packages/rnv/src/core/engineManager/types.ts index b12bbfcf8a..41fd60deb8 100644 --- a/packages/rnv/src/core/engineManager/types.ts +++ b/packages/rnv/src/core/engineManager/types.ts @@ -10,10 +10,13 @@ export type RnvEngine = { rootPath: string; originalTemplatePlatformProjectDir: string; projectDirName: string; + runtimeExtraProps: any; }; export type RnvEnginePlatform = { extensions: Array; + isWebHosted: boolean; + defaultPort: string; }; export type RnvEngineConfig = { diff --git a/packages/rnv/src/core/pluginManager/types.ts b/packages/rnv/src/core/pluginManager/types.ts index 87110eac55..4dd1b3efd3 100644 --- a/packages/rnv/src/core/pluginManager/types.ts +++ b/packages/rnv/src/core/pluginManager/types.ts @@ -6,17 +6,14 @@ export type PluginListResponse = { asString: string; asArray: PluginListResponseItem[]; plugins: PluginListResponseItem[]; - allPlugins: Record< - string, - { - version: string; - } - >; + allPlugins: Record; }; export type PluginListResponseItem = { name: string; value: string; + props: any; + version: string; }; export type RnvPluginScope = { diff --git a/packages/rnv/src/core/runtimeManager/index.ts b/packages/rnv/src/core/runtimeManager/index.ts index 8cfdd1c2cf..08fbf2cde4 100644 --- a/packages/rnv/src/core/runtimeManager/index.ts +++ b/packages/rnv/src/core/runtimeManager/index.ts @@ -53,7 +53,7 @@ export const configureRuntimeDefaults = async (c: RnvConfig) => { if (c.buildConfig) { c.runtime.bundleAssets = getConfigProp(c, c.platform, 'bundleAssets', false); const { hosted } = c.program; - c.runtime.hosted = (hosted || !c.runtime.scheme.bundleAssets) && c.runtime.currentPlatform?.isWebHosted; + c.runtime.hosted = hosted && c.runtime.currentPlatform?.isWebHosted; // c.runtime.devServer = `http://${ip.address()}:${c.runtime.port}`; if (c.buildConfig.defaults?.supportedPlatforms) { @@ -68,7 +68,7 @@ export const configureRuntimeDefaults = async (c: RnvConfig) => { const pDir = c.paths.project.platformTemplatesDirs?.[platform]; if (pDir) { isValid = true; - isConnected = pDir?.includes?.(getRealPath(c, dir)); + isConnected = pDir?.includes?.(getRealPath(c, dir) || 'UNDEFINED'); } const port = c.buildConfig.defaults?.[platform] || c.runtime.currentPlatform?.defaultPort; return { diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/android.ts b/packages/rnv/src/core/sdkManager/deviceUtils/android.ts index d023f003ec..965ff6e88d 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/android.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/android.ts @@ -30,14 +30,15 @@ import { } from '../../constants'; import { RnvConfig } from '../../configManager/types'; import { AndroidDevice } from '../types'; +import { RnvError } from '../../types'; const CHECK_INTEVAL = 5000; -const currentDeviceProps = {}; +const currentDeviceProps: Record> = {}; -export const composeDevicesString = (devices, returnArray?: boolean) => { +export const composeDevicesString = (devices: Array, returnArray?: boolean) => { logTask('composeDevicesString', `numDevices:${devices ? devices.length : null}`); - const devicesArray = []; + const devicesArray: Array = []; devices.forEach((v, i) => devicesArray.push(_getDeviceString(v, !returnArray ? i : null))); if (returnArray) return devicesArray; return `\n${devicesArray.join('')}`; @@ -45,11 +46,11 @@ export const composeDevicesString = (devices, returnArray?: boolean) => { export const launchAndroidSimulator = async ( c: RnvConfig, - target: boolean | { name: string } | string, + target: true | { name: string } | string, isIndependentThread = false ) => { logTask('launchAndroidSimulator', `target:${target} independentThread:${!!isIndependentThread}`); - let newTarget = target; + let newTarget: { name: string } | string; if (target === true) { const { program: { device }, @@ -67,10 +68,12 @@ export const launchAndroidSimulator = async ( }, ]); newTarget = response.chosenEmulator; + } else { + newTarget = target; } if (newTarget) { - const actualTarget = newTarget.name || newTarget; + const actualTarget = typeof newTarget === 'string' ? newTarget : newTarget.name; if (isIndependentThread) { execCLI(c, CLI_ANDROID_EMULATOR, `-avd "${actualTarget}"`, { detached: isIndependentThread, @@ -103,13 +106,14 @@ export const listAndroidTargets = async (c: RnvConfig) => { const list = await getAndroidTargets(c, false, device, device); const devices = await composeDevicesString(list); logToSummary(`Android Targets:\n${devices}`); - if (devices.trim() === '') { + if (typeof devices === 'string' && devices.trim() === '') { logToSummary('Android Targets: No devices found'); } return devices; }; -const _getDeviceString = (device, i) => { +//Fuck it, I just any this return until complete refactor +const _getDeviceString = (device: AndroidDevice, i: number | null): any => { const { isTV, isTablet, name, udid, isDevice, isActive, avdConfig, isWear, arch } = device; let deviceIcon = ''; if (isTablet) deviceIcon = 'Tablet 💊 '; @@ -153,8 +157,8 @@ export const getAndroidTargets = async (c: RnvConfig, skipDevices: boolean, skip await new Promise((r) => setTimeout(r, 1000)); try { - let devicesResult; - let avdResult; + let devicesResult: any; + let avdResult: any; if (!skipDevices) { devicesResult = await execCLI(c, CLI_ANDROID_ADB, 'devices -l'); @@ -175,24 +179,26 @@ const calculateDeviceDiagonal = (width: number, height: number, density: number) return Math.sqrt(widthInches * widthInches + heightInches * heightInches); }; -const getRunningDeviceProp = async (c: RnvConfig, udid: string, prop) => { +const getRunningDeviceProp = async (c: RnvConfig, udid: string, prop: string): Promise => { // avoid multiple calls to the same device if (currentDeviceProps[udid]) { - if (!prop) return currentDeviceProps[udid]; + // if (!prop) return currentDeviceProps[udid]; return currentDeviceProps[udid][prop]; } const rawProps = await execCLI(c, CLI_ANDROID_ADB, `-s ${udid} shell getprop`); const reg = /\[.+\]: \[.*\n?[^[]*\]/gm; const lines = rawProps.match(reg); - lines.forEach((line) => { - const words = line.split(']: ['); - const key = words[0].slice(1); - const value = words[1].slice(0, words[1].length - 1); + if (lines) { + lines.forEach((line) => { + const words = line.split(']: ['); + const key = words[0].slice(1); + const value = words[1].slice(0, words[1].length - 1); - if (!currentDeviceProps[udid]) currentDeviceProps[udid] = {}; - currentDeviceProps[udid][key] = value; - }); + if (!currentDeviceProps[udid]) currentDeviceProps[udid] = {}; + currentDeviceProps[udid][key] = value; + }); + } return getRunningDeviceProp(c, udid, prop); }; @@ -214,7 +220,7 @@ const decideIfTVRunning = async (c: RnvConfig, device: AndroidDevice) => { if (string && string.toLowerCase().includes('tv')) isTV = true; }); - if (model.includes('SHIELD')) isTV = true; + if (model?.includes('SHIELD')) isTV = true; if (hdmi) isTV = true; if (modelGroup && modelGroup.toLowerCase().includes('firetv')) isTV = true; if (configuration === 'tv') isTV = true; @@ -246,13 +252,18 @@ const getDeviceType = async (device: AndroidDevice, c: RnvConfig) => { const screenSizeResult = await execCLI(c, CLI_ANDROID_ADB, `-s ${device.udid} shell wm size`); const screenDensityResult = await execCLI(c, CLI_ANDROID_ADB, `-s ${device.udid} shell wm density`); const arch = await getRunningDeviceProp(c, device.udid, 'ro.product.cpu.abi'); - let screenProps; + let screenProps = { + width: 0, + height: 0, + density: 0, + }; if (screenSizeResult) { const [width, height] = screenSizeResult.split('Physical size: ')[1].split('x'); screenProps = { - width: parseInt(width, 10), - height: parseInt(height, 10), + width: parseInt(width, 10) || 0, + height: parseInt(height, 10) || 0, + density: 0, }; } @@ -263,11 +274,11 @@ const getDeviceType = async (device: AndroidDevice, c: RnvConfig) => { device.isTV = await decideIfTVRunning(c, device); - if (screenSizeResult && screenDensityResult) { + if (screenSizeResult && screenDensityResult && screenProps) { const { width, height, density } = screenProps; const diagonalInches = calculateDeviceDiagonal(width, height, density); - screenProps = { ...screenProps, diagonalInches }; + screenProps = { ...screenProps }; device.isTablet = !device.isTV && diagonalInches > IS_TABLET_ABOVE_INCH && diagonalInches <= 15; device.isWear = await decideIfWearRunning(c, device); } @@ -326,7 +337,7 @@ const getAvdDetails = (c: RnvConfig, deviceName: string) => { // .avd dir might be in other place than homedir. (https://developer.android.com/studio/command-line/variables) const avdConfigPaths = [`${ANDROID_AVD_HOME}`, `${ANDROID_SDK_HOME}/.android/avd`, `${USER_HOME_DIR}/.android/avd`]; - const results = {}; + const results: { avdConfig?: Record } = {}; avdConfigPaths.forEach((cPath) => { if (fsExistsSync(cPath)) { @@ -343,7 +354,7 @@ const getAvdDetails = (c: RnvConfig, deviceName: string) => { if (key === 'path') { const initData = fsReadFileSync(`${value}/config.ini`).toString(); const initLines = initData.trim().split(/\r?\n/); - const avdConfig = {}; + const avdConfig: Record = {}; initLines.forEach((initLine) => { const [iniKey, iniValue] = initLine.split('='); // also remove the white space @@ -370,7 +381,7 @@ const getEmulatorName = async (c: RnvConfig, words: Array) => { return emulatorName; }; -export const connectToWifiDevice = async (c: RnvConfig, target) => { +export const connectToWifiDevice = async (c: RnvConfig, target: string) => { let connect_str = `connect ${target}`; if (!target.includes(':')) { @@ -440,7 +451,7 @@ const _parseDevicesResult = async (c: RnvConfig, devicesString: string, avdsStri try { avdDetails = getAvdDetails(c, line); - } catch (e) { + } catch (e: RnvError) { logError(e); } @@ -493,7 +504,7 @@ const _parseDevicesResult = async (c: RnvConfig, devicesString: string, avdsStri ); }; -const _getDeviceProp = (arr, prop) => { +const _getDeviceProp = (arr: Array, prop: string) => { for (let i = 0; i < arr.length; i++) { const v = arr[i]; if (v && v.includes(prop)) return v.replace(prop, ''); @@ -553,9 +564,12 @@ const _createEmulator = (c: RnvConfig, apiVersion: string, emuPlatform: string, }; const waitForEmulatorToBeReady = (c: RnvConfig, emulator: string) => - waitForEmulator(c, CLI_ANDROID_ADB, `-s ${emulator} shell getprop init.svc.bootanim`, (res) => - res.includes('stopped') - ); + waitForEmulator(c, CLI_ANDROID_ADB, `-s ${emulator} shell getprop init.svc.bootanim`, (res) => { + if (typeof res === 'string') { + return res.includes('stopped'); + } + return res; + }); export const checkForActiveEmulator = (c: RnvConfig) => new Promise((resolve, reject) => { diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts b/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts index e9917efaa0..ed44e89d91 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts @@ -30,7 +30,7 @@ export const getAppleDevices = async (c: RnvConfig, ignoreDevices?: boolean, ign const availableSims: Array = []; Object.keys(simctl.devices).forEach((runtime) => { logDebug('runtime', runtime); - simctl.devices[runtime].forEach((device) => { + simctl.devices[runtime].forEach((device: AppleDevice) => { if (device.isAvailable) { availableSims.push({ ...device, @@ -64,70 +64,77 @@ export const getAppleDevices = async (c: RnvConfig, ignoreDevices?: boolean, ign return allDevices; }; -const _parseNewIOSDevicesList = (rawDevices, platform, ignoreDevices = false) => { - const devices = []; +const _parseNewIOSDevicesList = (rawDevices: string | Array, platform: string, ignoreDevices = false) => { + const devices: Array = []; if (ignoreDevices) return devices; - const decideIcon = (device) => { + const decideIcon = (device: AppleDevice) => { const { name, isDevice } = device; switch (platform) { case IOS: - if (name.includes('iPhone') || name.includes('iPad') || name.includes('iPod')) { + if (name?.includes('iPhone') || name?.includes('iPad') || name?.includes('iPod')) { let icon = 'Phone 📱'; if (name.includes('iPad')) icon = 'Tablet 💊'; return icon; } - return null; + return undefined; case TVOS: - if (name.includes('TV') && !name.includes('iPhone') && !name.includes('iPad')) { + if (name?.includes('TV') && !name?.includes('iPhone') && !name?.includes('iPad')) { return 'TV 📺'; } - return null; + return undefined; default: if (isDevice) { return 'Apple Device'; } - return null; + return undefined; } }; - const lines = rawDevices.split('\n'); - const devicesOnly = lines.slice(1, lines.indexOf('')); - devicesOnly.forEach((device) => { - const udid = device.match(/\(([^()]*)\)$/)[1]; - const name = device.split(' (').slice(0, -1).join(' ('); - const icon = decideIcon({ name, isDevice: true }); - devices.push({ - udid, - name, - icon, - isDevice: true, + if (typeof rawDevices === 'string') { + const lines = rawDevices.split('\n'); + const devicesOnly: Array = lines.slice(1, lines.indexOf('')); + devicesOnly.forEach((device) => { + const udid = device.match(/\(([^()]*)\)$/)?.[1]; + const name = device.split(' (').slice(0, -1).join(' ('); + const icon = decideIcon({ name, isDevice: true }); + devices.push({ + udid, + name, + icon, + isDevice: true, + }); }); - }); + } return devices; }; -const _parseIOSDevicesList = (rawDevices, platform, ignoreDevices = false, ignoreSimulators = false) => { - const devices = []; - const decideIcon = (device) => { +const _parseIOSDevicesList = ( + rawDevices: string | Array, + platform: string, + ignoreDevices = false, + ignoreSimulators = false +) => { + const devices: Array = []; + const decideIcon = (device: AppleDevice) => { const { name, isDevice } = device; switch (platform) { case IOS: - if (name.includes('iPhone') || name.includes('iPad') || name.includes('iPod')) { + if (name?.includes('iPhone') || name?.includes('iPad') || name?.includes('iPod')) { let icon = 'Phone 📱'; if (name.includes('iPad')) icon = 'Tablet 💊'; return icon; } - return null; + return undefined; case TVOS: - if (name.includes('TV') && !name.includes('iPhone') && !name.includes('iPad')) { + if (name?.includes('TV') && !name?.includes('iPhone') && !name?.includes('iPad')) { return 'TV 📺'; } - return null; + return undefined; default: if (isDevice) { return 'Apple Device'; } - return null; + return undefined; } }; if (typeof rawDevices === 'string' && !ignoreDevices) { @@ -211,7 +218,7 @@ export const launchAppleSimulator = async (c: RnvConfig, target: string) => { const _launchSimulator = async (selectedDevice: AppleDevice) => { try { - child_process.spawnSync('xcrun', ['simctl', 'boot', selectedDevice.udid]); + if (selectedDevice.udid) child_process.spawnSync('xcrun', ['simctl', 'boot', selectedDevice.udid]); } catch (e) { // instruments always fail with 255 because it expects more arguments, // but we want it to only launch the simulator diff --git a/packages/rnv/src/core/sdkManager/types.ts b/packages/rnv/src/core/sdkManager/types.ts index 65900e2820..b707c32027 100644 --- a/packages/rnv/src/core/sdkManager/types.ts +++ b/packages/rnv/src/core/sdkManager/types.ts @@ -1,22 +1,36 @@ export type AppleDevice = { - udid: string; + udid?: string; + version?: string; + isAvailable?: boolean; + name?: string; + icon?: string; + isDevice?: boolean; }; export type AndroidDevice = { udid: string; - model: string; - product: string; - isPhone: boolean; - isTablet: boolean; - isWear: boolean; - isTV: boolean; - isMobile: boolean; - screenProps: any; - arch: string; - avdConfig: any; - isNotEligibleAndroid: boolean; + model?: string; + product?: string; + isPhone?: boolean; + isTablet?: boolean; + isWear?: boolean; + isTV?: boolean; + isMobile?: boolean; + screenProps?: any; + arch?: string; + avdConfig?: any; + isNotEligibleAndroid?: boolean; + name: string; + isDevice?: boolean; + isActive: boolean; }; +// export type ScreenProps = { +// width: 0; +// height: 0; +// density: 0; +// }; + export type WebosDevice = { key?: string; name: string; diff --git a/packages/rnv/src/core/systemManager/exec.ts b/packages/rnv/src/core/systemManager/exec.ts index 9a0544b6c4..14ef1c8b6b 100755 --- a/packages/rnv/src/core/systemManager/exec.ts +++ b/packages/rnv/src/core/systemManager/exec.ts @@ -278,7 +278,7 @@ const executeAsync = async ( * */ const executeTelnet = (c: RnvConfig, port: string, command: string) => - new Promise((resolve) => { + new Promise((resolve) => { logDebug(`execTelnet: ${port} ${command}`); try { let output = ''; @@ -292,7 +292,7 @@ const executeTelnet = (c: RnvConfig, port: string, command: string) => nc2.on('close', () => resolve(output)); } catch (e: RnvError) { logError(e); - resolve(true); + resolve(''); } }); diff --git a/packages/rnv/src/core/systemManager/logger.ts b/packages/rnv/src/core/systemManager/logger.ts index ac0712b664..affe2931cf 100644 --- a/packages/rnv/src/core/systemManager/logger.ts +++ b/packages/rnv/src/core/systemManager/logger.ts @@ -210,7 +210,7 @@ export const logSummary = (header = 'SUMMARY') => { if (cnf().platform) { addon = ` ($.platforms.${cnf().platform}.engine)`; } - str += printIntoBox(`Engine${addon}: ${_highlightColor(cnf().runtime?.engine?.config?.id)}`); + str += printIntoBox(`Engine${addon}: ${_highlightColor(cnf().runtime?.engine?.config?.id || '')}`); } if (cnf().runtime?.activeTemplate) { str += printIntoBox(`Template: ${_highlightColor(cnf().runtime?.activeTemplate)}`); @@ -355,7 +355,7 @@ type PrintJsonPayload = { level?: string; }; -export const logExitTask = (task: string, customChalk: (s: string) => string) => { +export const logExitTask = (task: string, customChalk?: (s: string) => string) => { if (_jsonOnly) { return _printJson({ type: 'taskExit', diff --git a/packages/rnv/src/core/taskManager/index.ts b/packages/rnv/src/core/taskManager/index.ts index 76cb4e7014..6fa14b8d20 100644 --- a/packages/rnv/src/core/taskManager/index.ts +++ b/packages/rnv/src/core/taskManager/index.ts @@ -13,10 +13,10 @@ import { } from '../engineManager'; import { TASK_CONFIGURE_SOFT } from '../constants'; import { RnvConfig } from '../configManager/types'; -import { RnvTask, RnvTaskMap } from './types'; +import { RnvTask, RnvTaskMap, TaskItemMap, TaskObj } from './types'; import { RnvEngine } from '../engineManager/types'; -let executedTasks = {}; +let executedTasks: Record = {}; const CUSTOM_TASKS: RnvTaskMap = {}; @@ -40,13 +40,7 @@ export const initializeTask = async (c: RnvConfig, task: string) => { return true; }; -const _getTaskOption = ({ - taskInstance, - hasMultipleSubTasks, -}: { - taskInstance: RnvTask; - hasMultipleSubTasks: boolean; -}) => { +const _getTaskOption = ({ taskInstance, hasMultipleSubTasks }: TaskObj) => { if (hasMultipleSubTasks) { return `${taskInstance.task.split(' ')[0]}...`; } @@ -67,12 +61,7 @@ const _getTaskObj = (taskInstance: RnvTask) => { }; }; -type TaskObj = { - key: string; - taskInstance: RnvTask; -}; - -export const findSuitableTask = async (c: RnvConfig, specificTask?: string): Promise => { +export const findSuitableTask = async (c: RnvConfig, specificTask?: string): Promise => { logTask('findSuitableTask'); const REGISTERED_ENGINES = getRegisteredEngines(c); let task = ''; @@ -164,20 +153,14 @@ export const findSuitableTask = async (c: RnvConfig, specificTask?: string): Pro }); } }); - const supportedSubtasks = {}; + const supportedSubtasks: TaskItemMap = {}; // Normalize task options - const supportedSubtasksFilter: Record< - string, - { - desc: string; - taskKey: string; - } - > = {}; + const supportedSubtasksFilter: TaskItemMap = {}; supportedSubtasksArr.forEach((tsk) => { const mergedTask = supportedSubtasksFilter[tsk.taskKey]; if (!mergedTask) { supportedSubtasksFilter[tsk.taskKey] = tsk; - } else if (!mergedTask.desc.includes(tsk.desc)) { + } else if (!mergedTask.desc?.includes(tsk.desc)) { mergedTask.desc += `, ${tsk.desc}`; } }); @@ -243,12 +226,12 @@ export const findSuitableTask = async (c: RnvConfig, specificTask?: string): Pro await _selectPlatform(c, suitableEngines, task); c.runtime.engine = getEngineRunner(c, task, CUSTOM_TASKS); } - if (c.runtime.engine.runtimeExtraProps) { + if (c.runtime.engine?.runtimeExtraProps) { c.runtime.runtimeExtraProps = c.runtime.engine.runtimeExtraProps; } logInfo( - `Current Engine: ${chalk().bold.white(c.runtime.engine.config.id)} path: ${chalk().grey( - c.runtime.engine.rootPath + `Current Engine: ${chalk().bold.white(c.runtime.engine?.config.id)} path: ${chalk().grey( + c.runtime.engine?.rootPath )}` ); const customTask = CUSTOM_TASKS[task]; @@ -261,8 +244,8 @@ export const findSuitableTask = async (c: RnvConfig, specificTask?: string): Pro task = specificTask; c.runtime.engine = getEngineRunner(c, task); } - c.runtime.availablePlatforms = Object.keys(c.runtime.engine.platforms || []); - return getEngineTask(task, c.runtime.engine.tasks); + c.runtime.availablePlatforms = Object.keys(c.runtime.engine?.platforms || []); + return getEngineTask(task, c.runtime.engine?.tasks); }; const _populateExtraParameters = (c: RnvConfig, task: RnvTask) => { @@ -289,7 +272,7 @@ const _populateExtraParameters = (c: RnvConfig, task: RnvTask) => { const _selectPlatform = async (c: RnvConfig, suitableEngines: Array, task: string) => { const supportedPlatforms: Record = {}; suitableEngines.forEach((engine) => { - getEngineTask(task, engine.tasks).platforms.forEach((plat) => { + getEngineTask(task, engine.tasks)?.platforms.forEach((plat) => { supportedPlatforms[plat] = true; }); }); @@ -314,7 +297,7 @@ const TASK_LIMIT = 20; export const executeTask = async ( c: RnvConfig, task: string, - parentTask?: string | null, + parentTask?: string, originTask?: string, isFirstTask?: boolean ) => { @@ -331,7 +314,14 @@ but issue migh not be necessarily with this task To avoid that test your task code against parentTask and avoid executing same task X from within task X`); } - await executeEngineTask(c, task, parentTask, originTask, getEngineRunner(c, task, CUSTOM_TASKS).tasks, isFirstTask); + await executeEngineTask( + c, + task, + parentTask, + originTask, + getEngineRunner(c, task, CUSTOM_TASKS)?.tasks, + isFirstTask + ); // await getEngineRunner(c, task, CUSTOM_TASKS).executeTask(c, task, parentTask, originTask, isFirstTask); executedTasks[task]++; @@ -416,16 +406,16 @@ export const shouldSkipTask = (c: RnvConfig, task: string, originTask: string) = export const executeEngineTask = async ( c: RnvConfig, task: string, - parentTask: string, - originTask: string, - tasks: Record, - isFirstTask: boolean + parentTask?: string, + originTask?: string, + tasks?: Record, + isFirstTask?: boolean ) => { const needsHelp = Object.prototype.hasOwnProperty.call(c.program, 'help'); const t = getEngineTask(task, tasks, CUSTOM_TASKS); - if (needsHelp && !parentTask) { + if (needsHelp && !parentTask && t) { logRaw(` ======================================================= INTERACTIVE HELP FOR TASK: ${chalk().green(t.task)} diff --git a/packages/rnv/src/core/taskManager/types.ts b/packages/rnv/src/core/taskManager/types.ts index f62b093f3d..2a24143bb9 100644 --- a/packages/rnv/src/core/taskManager/types.ts +++ b/packages/rnv/src/core/taskManager/types.ts @@ -24,4 +24,19 @@ export type RnvTaskParameter = { export type RnvTaskMap = Record; -export type RnvTaskFn = (c: RnvConfig, parentTask: string, originTask: string) => Promise; +//Too many choices of return types +export type RnvTaskFn = (c: RnvConfig, parentTask?: string, originTask?: string) => Promise; // Promise; + +export type TaskItemMap = Record< + string, + { + desc?: string; + taskKey: string; + } +>; + +export type TaskObj = { + key: string; + taskInstance: RnvTask; + hasMultipleSubTasks?: boolean; +}; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.doctor.ts b/packages/rnv/src/engine-core/tasks/task.rnv.doctor.ts index f34d94b469..42726d1234 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.doctor.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.doctor.ts @@ -55,15 +55,17 @@ export const taskRnvDoctor: RnvTaskFn = async (c, parentTask, originTask) => { cPath }. ISSUES:\n\n` ); - ajv.errors.forEach((err) => { - errMsg += chalk().yellow( - `${chalk().grey(err.dataPath === '' ? '/' : err.dataPath)}: ${err.message} ${Object.keys( - err.params - ) - .map((k) => `=> ${chalk().red(err.params[k])}`) - .join('\n')}\n` - ); - }); + if (typeof ajv !== 'boolean' && ajv) { + ajv.errors?.forEach((err) => { + errMsg += chalk().yellow( + `${chalk().grey(err.dataPath === '' ? '/' : err.dataPath)}: ${err.message} ${Object.keys( + err.params + ) + .map((k) => `=> ${chalk().red(err.params[k])}`) + .join('\n')}\n` + ); + }); + } } } }); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.new.ts b/packages/rnv/src/engine-core/tasks/task.rnv.new.ts index fc80a9e0af..689531e84c 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.new.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.new.ts @@ -75,6 +75,8 @@ type NewProjectData = { confirmString?: string; defaultProjectName?: string; defaultWorkspace?: string; + inputSupportedPlatforms?: Array; + inputWorkspace?: string; }; const _prepareProjectOverview = (c: RnvConfig, data: NewProjectData) => { @@ -99,7 +101,7 @@ const _prepareProjectOverview = (c: RnvConfig, data: NewProjectData) => { str += printIntoBox(''); str += printIntoBox('Project Structure:'); str += printIntoBox(''); - str += printIntoBox(data.projectName); + str += printIntoBox(data.projectName || 'UNKNOWN'); str += chalk().gray(`│ ├── appConfigs # Application flavour configuration files/assets │ │ │ └── [APP_ID] # Example application flavour │ │ │ ├── assets # Platform assets injected to ./platformAssets │ @@ -144,7 +146,7 @@ type BootstrapQuestions = Array<{ const interactiveQuestion = async ( results: QuestionResults, bootstrapQuestions: BootstrapQuestions, - providedAnswers + providedAnswers: Record ) => { if (bootstrapQuestions?.length) { for (let i = 0; i < bootstrapQuestions.length; i++) { @@ -176,7 +178,7 @@ const interactiveQuestion = async ( value, }; } else { - const inqQuestion = { + const inqQuestion: any = { name: qKeyClean, type: q.type, message: q.title, @@ -502,12 +504,7 @@ export const taskRnvNew = async (c: RnvConfig) => { // ================================================== const renativeTemplateConfigExt = {}; const bootstrapQuestions = renativeTemplateConfig?.templateConfig?.bootstrapQuestions; - const results: Record< - string, - { - value: string; - } - > = {}; + const results: QuestionResults = {}; const providedAnswers: Record = {}; if (c.program.answer) { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.plugin.add.ts b/packages/rnv/src/engine-core/tasks/task.rnv.plugin.add.ts index 6fb10389c0..6e3de432c3 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.plugin.add.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.plugin.add.ts @@ -6,6 +6,7 @@ import { chalk, logSuccess, logTask } from '../../core/systemManager/logger'; import { getPluginList, resolvePluginDependants } from '../../core/pluginManager'; import { executeTask } from '../../core/taskManager'; import { RnvTaskFn } from '../../core/taskManager/types'; +import { PluginListResponseItem } from '../../core/pluginManager/types'; /* eslint-disable no-await-in-loop */ export const taskRnvPluginAdd: RnvTaskFn = async (c, _parentTask, originTask) => { @@ -18,7 +19,7 @@ export const taskRnvPluginAdd: RnvTaskFn = async (c, _parentTask, originTask) => const o = getPluginList(c); const selPlugin = selPluginKey && o.allPlugins[selPluginKey]; - const selectedPlugins: Record = {}; + const selectedPlugins: Record = {}; const installMessage = []; if (!selPlugin) { @@ -37,7 +38,7 @@ export const taskRnvPluginAdd: RnvTaskFn = async (c, _parentTask, originTask) => installMessage.push(`${chalk().white(selPluginKey)} v(${chalk().green(selPlugin.version)})`); } - const questionPlugins: Record = {}; + const questionPlugins: Record = {}; Object.keys(selectedPlugins).forEach((key) => { // c.buildConfig.plugins[key] = 'source:rnv'; @@ -54,7 +55,7 @@ export const taskRnvPluginAdd: RnvTaskFn = async (c, _parentTask, originTask) => const pluginKey = pluginKeys[i]; const plugin = questionPlugins[pluginKey]; const pluginProps = Object.keys(plugin.props); - const finalProps = {}; + const finalProps: Record = {}; for (let i2 = 0; i2 < pluginProps.length; i2++) { const { propValue } = await inquirer.prompt({ name: 'propValue', From 68bac36c44ebddec0ca4eb83c5d99a4a35bf780a Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Thu, 31 Aug 2023 19:27:28 +0200 Subject: [PATCH 29/83] more ts refactor, 107 togo --- packages/rnv/src/core/common.ts | 7 ++--- packages/rnv/src/core/configManager/types.ts | 5 +++- packages/rnv/src/core/engineManager/types.ts | 2 ++ packages/rnv/src/core/pluginManager/types.ts | 3 +++ packages/rnv/src/core/projectManager/index.ts | 27 ++++++++++++------- packages/rnv/src/core/projectManager/types.ts | 1 + .../src/core/sdkManager/deviceUtils/common.ts | 2 +- .../src/core/sdkManager/deviceUtils/tizen.ts | 21 ++++++++------- packages/rnv/src/core/setupManager/base.ts | 5 ++-- .../rnv/src/core/systemManager/analytics.ts | 5 ++-- packages/rnv/src/core/systemManager/logger.ts | 2 +- packages/rnv/src/core/systemManager/types.ts | 6 ++--- packages/rnv/src/core/taskManager/index.ts | 14 +++++----- .../engine-core/tasks/task.rnv.app.create.ts | 4 +-- .../src/engine-core/tasks/task.rnv.kill.ts | 10 +++---- .../tasks/task.rnv.template.apply.ts | 2 +- 16 files changed, 68 insertions(+), 48 deletions(-) create mode 100644 packages/rnv/src/core/projectManager/types.ts diff --git a/packages/rnv/src/core/common.ts b/packages/rnv/src/core/common.ts index 49853408f9..a31e0a8bfc 100755 --- a/packages/rnv/src/core/common.ts +++ b/packages/rnv/src/core/common.ts @@ -138,7 +138,8 @@ export const existBuildsOverrideForTargetPathSync = (c: RnvConfig, destPath: str if (c.paths.appConfig.dirs) { c.paths.appConfig.dirs.forEach((v) => { - pathsToCheck.push(getBuildsFolder(c, c.platform, v)); + const bf = getBuildsFolder(c, c.platform, v); + if (bf) pathsToCheck.push(); }); } @@ -155,7 +156,7 @@ export const confirmActiveBundler = async (c: RnvConfig) => { if (c.runtime.skipActiveServerCheck) return true; if (c.program.ci) { - return killPort(c.runtime.port); + return killPort(parseInt(c.runtime.port)); } const choices = ['Restart the server (recommended)', 'Use existing session']; @@ -168,7 +169,7 @@ export const confirmActiveBundler = async (c: RnvConfig) => { }); if (choices[0] === selectedOption) { - await killPort(c.runtime.port); + await killPort(parseInt(c.runtime.port)); } else { return false; } diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index 763e052631..dfff22d174 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -56,6 +56,7 @@ export interface RnvConfig { platform: string; isConnected: boolean; engine?: any; + port?: string; }>; keepSessionActive: boolean; platformBuildsProjectPath: string; @@ -165,7 +166,7 @@ export interface RnvConfig { configsLocal: Array; }; }; - project: { + project: RnvConfigPathObj & { config: string; configExists: boolean; appConfigBase: Record; @@ -201,6 +202,8 @@ export interface RnvConfig { dir: string; dirs: Array; pluginDirs: Array; + fontsDirs: Array; + fontsDir: string; }; // EXTRA buildHooks: { diff --git a/packages/rnv/src/core/engineManager/types.ts b/packages/rnv/src/core/engineManager/types.ts index 41fd60deb8..e3f315f529 100644 --- a/packages/rnv/src/core/engineManager/types.ts +++ b/packages/rnv/src/core/engineManager/types.ts @@ -11,6 +11,8 @@ export type RnvEngine = { originalTemplatePlatformProjectDir: string; projectDirName: string; runtimeExtraProps: any; + outputDirName?: string; + serverDirName?: string; }; export type RnvEnginePlatform = { diff --git a/packages/rnv/src/core/pluginManager/types.ts b/packages/rnv/src/core/pluginManager/types.ts index 4dd1b3efd3..160dc5548e 100644 --- a/packages/rnv/src/core/pluginManager/types.ts +++ b/packages/rnv/src/core/pluginManager/types.ts @@ -25,6 +25,9 @@ export type RnvPlugin = RenativeConfigPlugin & { scope?: string; _scopes?: Array; _id?: string; + config?: { + fontSources: Array; + }; }; export type RnvPluginPlatform = 'ios' | 'android' | 'webpack'; diff --git a/packages/rnv/src/core/projectManager/index.ts b/packages/rnv/src/core/projectManager/index.ts index f7ad0ef70c..dc2c551919 100644 --- a/packages/rnv/src/core/projectManager/index.ts +++ b/packages/rnv/src/core/projectManager/index.ts @@ -34,6 +34,8 @@ import { configureTemplateFiles, configureEntryPoint } from '../templateManager' import { parseRenativeConfigs } from '../configManager'; import { NpmPackageFile, RenativeConfigFile, RnvConfig } from '../configManager/types'; import { RnvPlatform } from '../types'; +import { ParseFontsCallback } from './types'; +import { RnvPluginPlatform } from '../pluginManager/types'; export const checkAndBootstrapIfRequired = async (c: RnvConfig) => { logTask('checkAndBootstrapIfRequired'); @@ -52,11 +54,11 @@ export const checkAndBootstrapIfRequired = async (c: RnvConfig) => { const templateObj = readObjectSync(c.paths.template.configTemplate); const appConfigPath = path.join(c.paths.project.appConfigsDir, c.program.appConfigID, 'renative.json'); - const appConfigObj = readObjectSync(appConfigPath); + const appConfigObj: RenativeConfigFile = readObjectSync(appConfigPath); const supportedPlatforms = appConfigObj?.defaults?.supportedPlatforms; const engineTemplates = c.files.rnv.projectTemplates?.config?.engineTemplates; const rnvPlatforms = c.files.rnv.projectTemplates?.config?.platforms; - const activeEngineKeys = []; + const activeEngineKeys: Array = []; supportedPlatforms.forEach((supPlat) => { Object.keys(engineTemplates).forEach((eKey) => { @@ -83,7 +85,7 @@ export const checkAndBootstrapIfRequired = async (c: RnvConfig) => { if (!pkgJson.dependencies) pkgJson.dependencies = {}; c.files.project.package = pkgJson; - const installPromises = []; + const installPromises: Array> = []; Object.keys(pkgJson.devDependencies).forEach((devDepKey) => { if (activeEngineKeys.includes(devDepKey)) { installPromises.push( @@ -171,7 +173,7 @@ export const checkAndBootstrapIfRequired = async (c: RnvConfig) => { await parseRenativeConfigs(c); await configureTemplateFiles(c); - await configureEntryPoint(c); + await configureEntryPoint(c, c.platform); // await applyTemplate(c); // copyFolderContentsRecursiveSync(templatePath, c.paths.project.dir); @@ -209,7 +211,7 @@ export const configureFonts = async (c: RnvConfig) => { // FONTS let fontsObj = 'export default ['; - const duplicateFontCheck = []; + const duplicateFontCheck: Array = []; parseFonts(c, (font, dir) => { if (font.includes('.ttf') || font.includes('.otf') || font.includes('.woff')) { const keOriginal = font.split('.')[0]; @@ -308,7 +310,7 @@ export const copyRuntimeAssets = async (c: RnvConfig) => { return true; }; -export const parseFonts = (c: RnvConfig, callback) => { +export const parseFonts = (c: RnvConfig, callback: ParseFontsCallback) => { logTask('parseFonts'); if (c.buildConfig) { @@ -338,7 +340,7 @@ export const parseFonts = (c: RnvConfig, callback) => { // PLUGIN FONTS parsePlugins( c, - c.platform, + c.platform as RnvPluginPlatform, (plugin) => { if (plugin.config?.fontSources) { _parseFontSources(c, plugin.config?.fontSources, callback); @@ -349,7 +351,7 @@ export const parseFonts = (c: RnvConfig, callback) => { } }; -const _parseFontSources = (c: RnvConfig, fontSourcesArr, callback) => { +const _parseFontSources = (c: RnvConfig, fontSourcesArr: Array, callback: ParseFontsCallback) => { const fontSources = fontSourcesArr.map((v) => _resolvePackage(c, v)); fontSources.forEach((fontSourceDir) => { if (fsExistsSync(fontSourceDir)) { @@ -360,7 +362,7 @@ const _parseFontSources = (c: RnvConfig, fontSourcesArr, callback) => { }); }; -const _resolvePackage = (c: RnvConfig, v) => { +const _resolvePackage = (c: RnvConfig, v: string) => { if (v?.startsWith?.('./')) { return path.join(c.paths.project.dir, v); } @@ -426,7 +428,12 @@ const _resolvePackage = (c: RnvConfig, v) => { // return false; // }; -export const copyAssetsFolder = async (c: RnvConfig, platform: RnvPlatform, subPath: string, customFn) => { +export const copyAssetsFolder = async ( + c: RnvConfig, + platform: RnvPlatform, + subPath: string, + customFn: (c: RnvConfig, platform: string) => void +) => { logTask('copyAssetsFolder'); if (!isPlatformActive(c, platform)) return; diff --git a/packages/rnv/src/core/projectManager/types.ts b/packages/rnv/src/core/projectManager/types.ts new file mode 100644 index 0000000000..2cd2fda11a --- /dev/null +++ b/packages/rnv/src/core/projectManager/types.ts @@ -0,0 +1 @@ +export type ParseFontsCallback = (font: string, dir: string) => void; diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/common.ts b/packages/rnv/src/core/sdkManager/deviceUtils/common.ts index f5e237554e..9f2bd2ecb3 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/common.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/common.ts @@ -7,7 +7,7 @@ export const waitForEmulator = async ( cli: string, command: string, callback: (resp: string | true) => boolean -) => { +): Promise => { let attempts = 0; const maxAttempts = 30; const CHECK_INTEVAL = 2000; diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts index f4cdbce721..0fbe47d61c 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts @@ -51,7 +51,7 @@ export const listTizenTargets = async (c: RnvConfig) => { }); const targetArr = targets.split('\n'); let targetStr = ''; - Object.keys(targetArr).forEach((i) => { + targetArr.forEach((_, i) => { targetStr += `[${i}]> ${targetArr[i]}\n`; }); logToSummary(`Tizen Targets:\n${targetStr}`); @@ -162,7 +162,7 @@ const _getRunningDevices = async (c: RnvConfig) => { let deviceInfo; let deviceType; - if (deviceInfoXML !== true && deviceInfoXML !== '') { + if (deviceInfoXML !== '') { // for some reason the tv does not connect through sdb const parseObj = await parser.parseStringPromise(deviceInfoXML); @@ -190,11 +190,14 @@ const _getRunningDevices = async (c: RnvConfig) => { return devices; }; -const _waitForEmulatorToBeReady = (c: RnvConfig, target: string) => +const _waitForEmulatorToBeReady = (c: RnvConfig, target: string): Promise => waitForEmulator(c, CLI_SDB_TIZEN, 'devices', (res) => { - const lines = res.trim().split(/\r?\n/); - const devices = lines.filter((line) => line.includes(target) && line.includes('device')); - return devices.length > 0; + if (typeof res === 'string') { + const lines = res.trim().split(/\r?\n/); + const devices = lines.filter((line) => line.includes(target) && line.includes('device')); + return devices.length > 0; + } + return res; }); const _composeDevicesString = (devices: Array) => @@ -218,7 +221,7 @@ export const runTizenSimOrDevice = async (c: RnvConfig, buildCoreWebpackProject: const platformConfig = c.buildConfig.platforms[platform]; const bundleAssets = getConfigProp(c, platform, 'bundleAssets'); const isHosted = hosted ?? !bundleAssets; - const isLightningEngine = engine.config.id === 'engine-lightning'; + const isLightningEngine = engine?.config.id === 'engine-lightning'; if (!bundleAssets && !hosted) { // console.log('RUN WEINRE'); } @@ -234,7 +237,7 @@ export const runTizenSimOrDevice = async (c: RnvConfig, buildCoreWebpackProject: ); } - const tDir = getPlatformProjectDir(c); + const tDir = getPlatformProjectDir(c) || 'UNDEFINED'; const tBuild = path.join(tDir, 'build'); const tOut = path.join(tDir, 'output'); const tId = platformConfig.id; @@ -285,7 +288,7 @@ Please create one and then edit the default target from ${c.paths.workspace.dir} if (!isLightningEngine && buildCoreWebpackProject) { // lightning engine handles the build and packaging - !isHosted && (await buildCoreWebpackProject(c)); + !isHosted && (await buildCoreWebpackProject()); await execCLI(c, CLI_TIZEN, `build-web -- ${tDir} -out ${tBuild}`); await execCLI(c, CLI_TIZEN, `package -- ${tBuild} -s ${certProfile} -t wgt -o ${tOut}`); } diff --git a/packages/rnv/src/core/setupManager/base.ts b/packages/rnv/src/core/setupManager/base.ts index 3926f45599..62d4dfa154 100644 --- a/packages/rnv/src/core/setupManager/base.ts +++ b/packages/rnv/src/core/setupManager/base.ts @@ -6,11 +6,12 @@ import { commandExistsSync } from '../systemManager/exec'; import { TASK_WORKSPACE_CONFIGURE } from '../constants'; import { executeTask } from '../taskManager'; import { replaceHomeFolder, updateConfigFile } from '../systemManager/fileutils'; -import setupConfig from './config'; +import _setupConfig from './config'; import Config from '../configManager/config'; import { logTask, logError, logInfo, logDebug, logSuccess } from '../systemManager/logger'; import { RnvConfig } from '../configManager/types'; +const setupConfig: any = _setupConfig; class BasePlatformSetup { os: string; c: RnvConfig; @@ -112,7 +113,7 @@ class BasePlatformSetup { logSuccess(`SDK succefully installed at: ${setupConfig.android.location}`); } - async installSdk(sdk, skipPrereq) { + async installSdk(sdk: string, skipPrereq: boolean) { logTask(`installSdk:${sdk}`); !skipPrereq && this.checkPrereqs(); !skipPrereq && (await this.installPrereqs()); diff --git a/packages/rnv/src/core/systemManager/analytics.ts b/packages/rnv/src/core/systemManager/analytics.ts index 6aeb8ef6bd..e62ee18c88 100644 --- a/packages/rnv/src/core/systemManager/analytics.ts +++ b/packages/rnv/src/core/systemManager/analytics.ts @@ -5,6 +5,7 @@ import os from 'os'; import path from 'path'; import Config from '../configManager/config'; +//@ts-ignore import pkg from '../../../package.json'; import { REDASH_KEY, REDASH_URL, SENTRY_ENDPOINT } from '../constants'; @@ -90,9 +91,9 @@ export class Analytics { } } - captureException(e: any, context = {}) { + captureException(e: any, context: any = {}) { if (Config.isAnalyticsEnabled && this.errorFixer) { - this.errorFixer.withScope((scope) => { + this.errorFixer.withScope((scope: any) => { const { extra = {}, tags = {} } = context; scope.setTags({ ...tags, os: os.platform() }); scope.setExtras({ ...extra, fingerprint: machineIdSync() }); diff --git a/packages/rnv/src/core/systemManager/logger.ts b/packages/rnv/src/core/systemManager/logger.ts index affe2931cf..e62054d20c 100644 --- a/packages/rnv/src/core/systemManager/logger.ts +++ b/packages/rnv/src/core/systemManager/logger.ts @@ -26,7 +26,7 @@ const ICN_UNICORN = isSystemWin ? 'unicorn' : '🦄'; const _chalkPass = (v: string | boolean): string => (typeof v === 'string' ? v : String(v)); -const _chalkCols = { +const _chalkCols: any = { white: (v: string | boolean) => _chalkPass(v), green: (v: string) => _chalkPass(v), red: (v: string) => _chalkPass(v), diff --git a/packages/rnv/src/core/systemManager/types.ts b/packages/rnv/src/core/systemManager/types.ts index 387594ebbd..b579ee613e 100644 --- a/packages/rnv/src/core/systemManager/types.ts +++ b/packages/rnv/src/core/systemManager/types.ts @@ -55,7 +55,7 @@ export type FileUtilsPropConfig = { }; export type FileUtilsUpdateConfig = { - androidSdk: string; - tizenSdk: string; - webosSdk: string; + androidSdk?: string; + tizenSdk?: string; + webosSdk?: string; }; diff --git a/packages/rnv/src/core/taskManager/index.ts b/packages/rnv/src/core/taskManager/index.ts index 6fa14b8d20..6da403f882 100644 --- a/packages/rnv/src/core/taskManager/index.ts +++ b/packages/rnv/src/core/taskManager/index.ts @@ -36,7 +36,7 @@ export const initializeTask = async (c: RnvConfig, task: string) => { platform: c.platform, }); - await executeTask(c, task, null, task, true); + await executeTask(c, task, undefined, task, true); return true; }; @@ -330,7 +330,7 @@ To avoid that test your task code against parentTask and avoid executing same ta logExitTask(`${prt}<= ${task}`); }; -export const executeOrSkipTask = async (c: RnvConfig, task, parentTask, originTask) => { +export const executeOrSkipTask = async (c: RnvConfig, task: string, parentTask: string, originTask: string) => { if (!c.program.only) { return executeTask(c, task, parentTask, originTask); } @@ -361,7 +361,7 @@ export const shouldSkipTask = (c: RnvConfig, task: string, originTask: string) = if (t.filter) { const conditions = t.filter.split('&'); let conditionsToMatch = conditions.length; - conditions.forEach((con) => { + conditions.forEach((con: string) => { const conArr = con.split('='); if (ACCEPTED_CONDITIONS.includes(conArr[0])) { if (c.runtime[conArr[0]] === conArr[1]) { @@ -440,18 +440,18 @@ ${t.params logRaw(` =======================================================`); } - if (!t.isGlobalScope && isFirstTask) { + if (t && !t.isGlobalScope && isFirstTask) { if (c.files.project.package) { // This has to happen in order for hooks to be able to run await checkIfProjectAndNodeModulesExists(c); } } if (isFirstTask) { - c.runtime.forceBuildHookRebuild = !!t.forceBuildHookRebuild; + c.runtime.forceBuildHookRebuild = !!t?.forceBuildHookRebuild; } const inOnlyMode = c.program.only; - const doPipe = !t.isGlobalScope && (!inOnlyMode || (inOnlyMode && isFirstTask)); + const doPipe = t && !t.isGlobalScope && (!inOnlyMode || (inOnlyMode && isFirstTask)); if (doPipe) await _executePipe(c, task, 'before'); - await t.fn(c, parentTask, originTask); + if (t && t.fn) await t.fn(c, parentTask, originTask); if (doPipe) await _executePipe(c, task, 'after'); }; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.app.create.ts b/packages/rnv/src/engine-core/tasks/task.rnv.app.create.ts index 3a88d15fdd..a10d5f34e6 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.app.create.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.app.create.ts @@ -19,7 +19,7 @@ export const taskRnvAppCreate: RnvTaskFn = async (c) => { await configureRuntimeDefaults(c); - let sourcePath: string; + let sourcePath: string | undefined; if (c.program.sourceAppConfigID) { const sourceAppConfigDirPath = path.join(c.paths.project.appConfigsDir, c.program.sourceAppConfigID); @@ -109,7 +109,7 @@ export const taskRnvAppCreate: RnvTaskFn = async (c) => { } logInfo('Copying new app config...'); - await copyFolderContentsRecursive(sourcePath, destPath); + if (sourcePath) await copyFolderContentsRecursive(sourcePath, destPath); logInfo('Copying new app config...DONE'); const confObjPath = path.join(destPath, 'renative.json'); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts b/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts index 85986d4599..70ca37793e 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts @@ -7,15 +7,13 @@ import { configureRuntimeDefaults } from '../../core/runtimeManager'; import { PARAMS, TASK_KILL, TASK_APP_CONFIGURE } from '../../core/constants'; import { RnvTaskFn } from '../../core/taskManager/types'; +import { RnvConfig } from '../../core/configManager/types'; export const taskRnvKill: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvKill'); - const usedPorts: Array = []; - let platArray: Array<{ - platform: string; - port: string; - }> = []; + const usedPorts: RnvConfig['runtime']['supportedPlatforms'] = []; + let platArray: RnvConfig['runtime']['supportedPlatforms'] = []; const results = []; let ports: Record = {}; @@ -52,7 +50,7 @@ ${usedPorts.map((v) => chalk().white(`> ${v.port} (${v.platform})`)).join('\n')} if (confirm) { const killPromise = []; usedPorts.forEach((v) => { - killPromise.push(killPort(v.port)); + if (v.port) killPromise.push(killPort(parseInt(v.port))); }); await Promise.all(usedPorts); logSuccess('Processes KILLED'); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.template.apply.ts b/packages/rnv/src/engine-core/tasks/task.rnv.template.apply.ts index 47b76fb07f..1cd0bad3c2 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.template.apply.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.template.apply.ts @@ -28,7 +28,7 @@ export const taskRnvTemplateApply: RnvTaskFn = async (c, _parentTask, originTask type: 'list', message: 'Pick which template to install', name: 'template', - choices: opts.keysAsArray, + choices: opts?.keysAsArray, }); await applyTemplate(c, template); From cb867d3afef3801e0bb49f27d58fda865d9be10b Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Thu, 31 Aug 2023 21:44:46 +0200 Subject: [PATCH 30/83] more ts refactor, 98 togo --- packages/rnv/src/core/configManager/config.ts | 10 +--------- packages/rnv/src/core/configManager/types.ts | 1 + packages/rnv/src/core/setupManager/base.ts | 2 +- packages/rnv/src/core/systemManager/fileutils.ts | 10 +++------- packages/rnv/src/core/templateManager/index.ts | 2 +- packages/rnv/src/engine-core/tasks/task.rnv.clean.ts | 6 +++--- packages/rnv/src/engine-core/tasks/task.rnv.config.ts | 3 ++- .../src/engine-core/tasks/task.rnv.workspace.add.ts | 2 +- 8 files changed, 13 insertions(+), 23 deletions(-) diff --git a/packages/rnv/src/core/configManager/config.ts b/packages/rnv/src/core/configManager/config.ts index 3eace80f1e..8c3a30429a 100644 --- a/packages/rnv/src/core/configManager/config.ts +++ b/packages/rnv/src/core/configManager/config.ts @@ -33,14 +33,6 @@ class Config { return value; } - getMergedConfigValue(key: string) { - let value = this.config.buildConfig?.[configSchema[key].key]; - if (value === undefined && configSchema[key].default) { - value = configSchema[key].default; - } - return value; - } - listConfigValue(key: string) { let localVal = this.getConfigValueSeparate(key).toString(); let globalVal = this.getConfigValueSeparate(key, true).toString(); @@ -102,7 +94,7 @@ class Config { } get isAnalyticsEnabled() { - return this.getMergedConfigValue('analytics'); + return this.config.buildConfig?.enableAnalytics; } } diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index dfff22d174..4af62ae4f4 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -379,6 +379,7 @@ export type RenativeConfigFile = { runtime: Record; defaultTargets: Record; templateConfig: any; + enableAnalytics: boolean; }; export type RenativeConfigPlugin = { diff --git a/packages/rnv/src/core/setupManager/base.ts b/packages/rnv/src/core/setupManager/base.ts index 62d4dfa154..fc796d0040 100644 --- a/packages/rnv/src/core/setupManager/base.ts +++ b/packages/rnv/src/core/setupManager/base.ts @@ -162,7 +162,7 @@ class BasePlatformSetup { return true; } - async installFastlane() { + async installFastlane(): Promise { // to be overwritten logError( 'Install fastlane not supported yet. Follow https://docs.fastlane.tools/getting-started/ios/setup/ to install it manually' diff --git a/packages/rnv/src/core/systemManager/fileutils.ts b/packages/rnv/src/core/systemManager/fileutils.ts index 1a422a6007..1aa3fd562e 100755 --- a/packages/rnv/src/core/systemManager/fileutils.ts +++ b/packages/rnv/src/core/systemManager/fileutils.ts @@ -653,17 +653,13 @@ const BIND_CONFIG_PROPS = '{{configProps.'; const BIND_RUNTIME_PROPS = '{{runtimeProps.'; const BIND_ENV = '{{env.'; -const _bindStringVals = ( - obj: Record, - _val: string, - newKey: string, - propConfig: FileUtilsPropConfig -) => { +const _bindStringVals = (obj: any, _val: string, newKey: string | number, propConfig: FileUtilsPropConfig) => { const { props = {}, configProps = {}, runtimeProps = {} } = propConfig; let val = _val; if (val.includes(BIND_FILES)) { const key = val.replace(BIND_FILES, '').replace('}}', ''); - const nVal = key.split('.').reduce((o, i) => o?.[i], propConfig.files); + //TODO: this any not good + const nVal: any = key.split('.').reduce((o, i) => o?.[i], propConfig.files); obj[newKey] = resolvePackage(nVal); } else if (val.includes(BIND_PROPS)) { Object.keys(props).forEach((pk) => { diff --git a/packages/rnv/src/core/templateManager/index.ts b/packages/rnv/src/core/templateManager/index.ts index e40f62f0a6..a953eeb7e6 100644 --- a/packages/rnv/src/core/templateManager/index.ts +++ b/packages/rnv/src/core/templateManager/index.ts @@ -37,7 +37,7 @@ export const checkIfTemplateConfigured = async (c: RnvConfig) => { } Object.keys(c.buildConfig.templates).forEach((k) => { const obj = c.buildConfig.templates[k]; - if (!doResolve(k.version, false, { basedir: '../' }) && !doResolve(k, false)) { + if (!doResolve(k, false, { basedir: '../' }) && !doResolve(k, false)) { logInfo( `Your ${chalk().white(`${k}@${obj.version}`)} template is missing in renative.json. CONFIGURING...DONE` ); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.clean.ts b/packages/rnv/src/engine-core/tasks/task.rnv.clean.ts index 5a69747cad..13033100fc 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.clean.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.clean.ts @@ -6,7 +6,7 @@ import { chalk, logTask, logToSummary, logDebug } from '../../core/systemManager import { executeAsync } from '../../core/systemManager/exec'; import { PARAMS } from '../../core/constants'; import { isSystemWin } from '../../core/systemManager/utils'; -import { RnvConfig } from '../../core/configManager/types'; +import { RnvTaskFn } from '../../core/taskManager/types'; function clearWindowsCacheFiles() { const opts = { @@ -34,9 +34,9 @@ function clearWindowsCacheFiles() { return true; } -export const taskRnvClean = async (c: RnvConfig, skipQuestionParam = false) => { +export const taskRnvClean: RnvTaskFn = async (c) => { logTask('taskRnvClean'); - const skipQuestion = c.program.ci ? true : skipQuestionParam; + const skipQuestion = c.program.ci; const pathsToRemove = []; const localFiles = []; const immediateNodeModuleDir = path.join(c.paths.project.dir, 'node_modules'); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.config.ts b/packages/rnv/src/engine-core/tasks/task.rnv.config.ts index e8e5b6e276..a081da4ec8 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.config.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.config.ts @@ -11,7 +11,8 @@ export const taskRnvConfig: RnvTaskFn = async (c) => { const [, key, value] = getCliArguments(c); // first arg is config so it's useless if (key === 'list') { - const rows: Array = []; + const rows: Array = []; + //TODO: is this really needed? Object.keys(configSchema).forEach((k) => rows.push(Config.listConfigValue(k))); printTable([].concat(...rows)); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.workspace.add.ts b/packages/rnv/src/engine-core/tasks/task.rnv.workspace.add.ts index 70c6c2ffe1..2aab5e3019 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.workspace.add.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.workspace.add.ts @@ -30,7 +30,7 @@ export const taskRnvWorkspaceAdd: RnvTaskFn = async (c, _parentTask, originTask) if (!confirm) return false; } - let workspaceID = workspacePath.split('/').pop()?.replace(/@|\./g, ''); + let workspaceID = workspacePath.split('/').pop()?.replace(/@|\./g, '') || 'rnv'; const { workspaceIDInput } = await inquirerPrompt({ name: 'workspaceIDInput', From e27ec10e64bd4a33cb423a69a0863d431f8a97cf Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Thu, 31 Aug 2023 21:53:02 +0200 Subject: [PATCH 31/83] typings --- packages/rnv/tsconfig.json | 6 ++---- packages/rnv/{src => }/typings/global.d.ts | 0 packages/rnv/{src => }/typings/modules.d.ts | 0 3 files changed, 2 insertions(+), 4 deletions(-) rename packages/rnv/{src => }/typings/global.d.ts (100%) rename packages/rnv/{src => }/typings/modules.d.ts (100%) diff --git a/packages/rnv/tsconfig.json b/packages/rnv/tsconfig.json index 9d2faec89d..677a4576fe 100644 --- a/packages/rnv/tsconfig.json +++ b/packages/rnv/tsconfig.json @@ -1,11 +1,9 @@ { "extends": "@flexn/typescript-config/tsconfig.lib.node.json", "compilerOptions": { - "outDir": "./dist", + "outDir": "./lib", "rootDir": "./src", - "allowJs": true, "resolveJsonModule": false }, - "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"], - "exclude": ["node_modules", "./src/__tests__"] + "exclude": ["**/__tests__/*", "./lib/**/*"] } diff --git a/packages/rnv/src/typings/global.d.ts b/packages/rnv/typings/global.d.ts similarity index 100% rename from packages/rnv/src/typings/global.d.ts rename to packages/rnv/typings/global.d.ts diff --git a/packages/rnv/src/typings/modules.d.ts b/packages/rnv/typings/modules.d.ts similarity index 100% rename from packages/rnv/src/typings/modules.d.ts rename to packages/rnv/typings/modules.d.ts From 32e897319dd023155a0e79133f2e9457599a2cd9 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Thu, 31 Aug 2023 22:06:41 +0200 Subject: [PATCH 32/83] switch to lib output --- packages/rnv/.gitignore | 1 + packages/rnv/bin/index.js | 4 ++-- packages/rnv/package.json | 8 ++++---- packages/rnv/src/cli/{ora.js => ora.ts} | 1 + packages/rnv/typings/color-string.d.ts | 1 + packages/rnv/typings/detect-port.d.ts | 1 + packages/rnv/typings/get-installed-path.d.ts | 1 + packages/rnv/typings/ip.d.ts | 1 + packages/rnv/typings/modules.d.ts | 10 ---------- packages/rnv/typings/netcat.d.ts | 1 + packages/rnv/typings/rimraf.d.ts | 1 + packages/rnv/typings/svg2js.d.ts | 1 + packages/rnv/typings/svgs.d.ts | 1 + 13 files changed, 16 insertions(+), 16 deletions(-) rename packages/rnv/src/cli/{ora.js => ora.ts} (99%) create mode 100644 packages/rnv/typings/color-string.d.ts create mode 100644 packages/rnv/typings/detect-port.d.ts create mode 100644 packages/rnv/typings/get-installed-path.d.ts create mode 100644 packages/rnv/typings/ip.d.ts delete mode 100644 packages/rnv/typings/modules.d.ts create mode 100644 packages/rnv/typings/netcat.d.ts create mode 100644 packages/rnv/typings/rimraf.d.ts create mode 100644 packages/rnv/typings/svg2js.d.ts create mode 100644 packages/rnv/typings/svgs.d.ts diff --git a/packages/rnv/.gitignore b/packages/rnv/.gitignore index 4b15278a7a..b1df6575cc 100644 --- a/packages/rnv/.gitignore +++ b/packages/rnv/.gitignore @@ -48,4 +48,5 @@ buck-out/ package-lock.json dist/ +lib/ !pluginTemplates/**/dist diff --git a/packages/rnv/bin/index.js b/packages/rnv/bin/index.js index ca3a4faef7..a07b4d597d 100755 --- a/packages/rnv/bin/index.js +++ b/packages/rnv/bin/index.js @@ -8,8 +8,8 @@ const path = require('path'); // global.Headers = global.fetch.Headers; -const cli = require('../dist/index.js'); -const CONSTANTS = require('../dist/core/constants.js'); +const cli = require('../lib/index.js'); +const CONSTANTS = require('../lib/core/constants.js'); const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'))); let cmdValue; diff --git a/packages/rnv/package.json b/packages/rnv/package.json index c7e3641930..c235582e1e 100644 --- a/packages/rnv/package.json +++ b/packages/rnv/package.json @@ -52,10 +52,10 @@ "files": [ "bin", "coreTemplateFiles", - "dist", + "lib", "pluginTemplates" ], - "main": "dist/index.js", + "main": "lib/index.js", "bin": { "rnv": "./bin/index.js" }, @@ -65,11 +65,11 @@ }, "scripts": { "build": "yarn clean && yarn compile", - "clean": "rm -rf ./dist && rm -rf tsconfig.tsbuildinfo", + "clean": "rm -rf ./lib && rm -rf tsconfig.tsbuildinfo", "compile": "tsc -b tsconfig.json", "compile:prod": "tsc -b tsconfig.json", "prepublishOnly": "yarn clean && yarn compile:prod", - "watch": "tsc --watch --preserveWatchOutput --allowJs" + "watch": "tsc --watch --preserveWatchOutput" }, "dependencies": { "@babel/cli": "7.17.6", diff --git a/packages/rnv/src/cli/ora.js b/packages/rnv/src/cli/ora.ts similarity index 99% rename from packages/rnv/src/cli/ora.js rename to packages/rnv/src/cli/ora.ts index 26e901dcd2..90c35a5605 100644 --- a/packages/rnv/src/cli/ora.js +++ b/packages/rnv/src/cli/ora.ts @@ -1,3 +1,4 @@ +//@ts-nocheck import readline from 'readline'; import chalk from 'chalk'; import cliCursor from 'cli-cursor'; diff --git a/packages/rnv/typings/color-string.d.ts b/packages/rnv/typings/color-string.d.ts new file mode 100644 index 0000000000..dc8cf438b7 --- /dev/null +++ b/packages/rnv/typings/color-string.d.ts @@ -0,0 +1 @@ +declare module 'color-string'; diff --git a/packages/rnv/typings/detect-port.d.ts b/packages/rnv/typings/detect-port.d.ts new file mode 100644 index 0000000000..4151391cab --- /dev/null +++ b/packages/rnv/typings/detect-port.d.ts @@ -0,0 +1 @@ +declare module 'detect-port'; diff --git a/packages/rnv/typings/get-installed-path.d.ts b/packages/rnv/typings/get-installed-path.d.ts new file mode 100644 index 0000000000..1e0b0316d5 --- /dev/null +++ b/packages/rnv/typings/get-installed-path.d.ts @@ -0,0 +1 @@ +declare module 'get-installed-path'; diff --git a/packages/rnv/typings/ip.d.ts b/packages/rnv/typings/ip.d.ts new file mode 100644 index 0000000000..197890f41d --- /dev/null +++ b/packages/rnv/typings/ip.d.ts @@ -0,0 +1 @@ +declare module 'ip'; diff --git a/packages/rnv/typings/modules.d.ts b/packages/rnv/typings/modules.d.ts deleted file mode 100644 index 040a199752..0000000000 --- a/packages/rnv/typings/modules.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -declare module 'netcat'; -declare module 'netcat/client'; -declare module 'color-string'; -declare module 'detect-port'; -declare module 'ip'; -declare module 'get-installed-path' -declare module 'color-string'; -declare module 'svg2js'; - -export {} \ No newline at end of file diff --git a/packages/rnv/typings/netcat.d.ts b/packages/rnv/typings/netcat.d.ts new file mode 100644 index 0000000000..174b180400 --- /dev/null +++ b/packages/rnv/typings/netcat.d.ts @@ -0,0 +1 @@ +declare module 'netcat/client'; diff --git a/packages/rnv/typings/rimraf.d.ts b/packages/rnv/typings/rimraf.d.ts new file mode 100644 index 0000000000..be0a3b56b3 --- /dev/null +++ b/packages/rnv/typings/rimraf.d.ts @@ -0,0 +1 @@ +declare module 'rimraf'; diff --git a/packages/rnv/typings/svg2js.d.ts b/packages/rnv/typings/svg2js.d.ts new file mode 100644 index 0000000000..90c98bd02a --- /dev/null +++ b/packages/rnv/typings/svg2js.d.ts @@ -0,0 +1 @@ +declare module 'svg2js'; diff --git a/packages/rnv/typings/svgs.d.ts b/packages/rnv/typings/svgs.d.ts new file mode 100644 index 0000000000..a18f6d5b91 --- /dev/null +++ b/packages/rnv/typings/svgs.d.ts @@ -0,0 +1 @@ +declare module 'svgs'; From 08cd22ee5e1e517e5415b8ee35f6706ed7c03191 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Thu, 31 Aug 2023 23:14:08 +0200 Subject: [PATCH 33/83] more ts migrations 61 togo --- packages/rnv/src/core/common.ts | 20 +++++++++------- .../rnv/src/core/platformManager/index.ts | 6 ++--- packages/rnv/src/core/pluginManager/types.ts | 7 +++--- .../src/core/sdkManager/deviceUtils/common.ts | 4 ++-- .../src/core/sdkManager/deviceUtils/webos.ts | 18 ++++++++------ packages/rnv/src/core/setupManager/base.ts | 4 ++-- packages/rnv/src/core/setupManager/windows.ts | 10 ++++---- packages/rnv/src/core/systemManager/crypto.ts | 2 +- packages/rnv/src/core/systemManager/exec.ts | 5 ++-- .../rnv/src/core/systemManager/fileutils.ts | 24 +++++++++++++------ .../rnv/src/core/systemManager/resolve.ts | 4 ++-- packages/rnv/src/core/systemManager/types.ts | 4 +++- packages/rnv/src/core/taskManager/index.ts | 11 ++++++--- packages/rnv/src/core/types.ts | 6 ++++- .../engine-core/tasks/task.rnv.plugin.add.ts | 2 +- .../tasks/task.rnv.project.configure.ts | 4 +++- 16 files changed, 81 insertions(+), 50 deletions(-) diff --git a/packages/rnv/src/core/common.ts b/packages/rnv/src/core/common.ts index a31e0a8bfc..680288faef 100755 --- a/packages/rnv/src/core/common.ts +++ b/packages/rnv/src/core/common.ts @@ -11,17 +11,21 @@ import { fsExistsSync, writeCleanFile } from './systemManager/fileutils'; import { chalk, logError, logTask, logWarning } from './systemManager/logger'; import { getValidLocalhost } from './systemManager/utils'; import { RenativeConfigBuildScheme, RenativeConfigFile, RnvConfig } from './configManager/types'; +import { GetConfigPropFn } from './types'; +import { TimestampPathsConfig } from './systemManager/types'; -export const getTimestampPathsConfig = (c: RnvConfig, platform: string) => { - let timestampBuildFiles; +export const getTimestampPathsConfig = (c: RnvConfig, platform: string): TimestampPathsConfig | undefined => { + let timestampBuildFiles: Array = []; const pPath = path.join(c.paths.project.builds.dir, `${c.runtime.appId}_${platform}`); if (platform === 'web') { - timestampBuildFiles = getConfigProp(c, platform, 'timestampBuildFiles', []).map((v) => path.join(pPath, v)); + timestampBuildFiles = getConfigProp>(c, platform, 'timestampBuildFiles', []).map((v) => + path.join(pPath, v) + ); } if (timestampBuildFiles?.length) { return { paths: timestampBuildFiles, timestamp: c.runtime.timestamp }; } - return null; + return undefined; }; export const getCliArguments = (c: RnvConfig) => { @@ -255,7 +259,7 @@ const _getValueOrMergedObject = (resultCli: any, resultScheme: any, resultPlatfo return resultCommon; }; -export const getConfigProp = (c: RnvConfig, platform: string, key: string, defaultVal?: any) => { +export const getConfigProp: GetConfigPropFn = (c, platform, key, defaultVal?) => { if (!c.buildConfig) { logError('getConfigProp: c.buildConfig is undefined!'); return null; @@ -343,12 +347,12 @@ export const getConfigPropArray = (c: RnvConfig, platform: string, key: string) }; export const getAppId = (c: RnvConfig, platform: string) => { - const id = getConfigProp(c, platform, 'id'); - const idSuffix = getConfigProp(c, platform, 'idSuffix'); + const id = getConfigProp(c, platform, 'id'); + const idSuffix = getConfigProp(c, platform, 'idSuffix'); return idSuffix ? `${id}${idSuffix}` : id; }; -export const getAppTitle = (c: RnvConfig, platform: string) => getConfigProp(c, platform, 'title'); +export const getAppTitle = (c: RnvConfig, platform: string) => getConfigProp(c, platform, 'title'); export const getAppAuthor = (c: RnvConfig, platform: string) => getConfigProp(c, platform, 'author') || c.files.project.package?.author; diff --git a/packages/rnv/src/core/platformManager/index.ts b/packages/rnv/src/core/platformManager/index.ts index 1ed2570199..cb1931fbb0 100644 --- a/packages/rnv/src/core/platformManager/index.ts +++ b/packages/rnv/src/core/platformManager/index.ts @@ -74,7 +74,7 @@ export const createPlatformBuild = (c: RnvConfig, platform: string) => false, [path.join(ptPath, '_privateConfig')], false, - {}, + [], getTimestampPathsConfig(c, platform), c ); @@ -85,7 +85,7 @@ export const createPlatformBuild = (c: RnvConfig, platform: string) => export const isPlatformSupported = async (c: RnvConfig, isGlobalScope = false) => { logTask('isPlatformSupported'); - if (c.platform && c.platform !== true && isGlobalScope) { + if (c.platform && c.program.platform !== true && isGlobalScope) { return c.platform; } @@ -99,7 +99,7 @@ export const isPlatformSupported = async (c: RnvConfig, isGlobalScope = false) = if (!platformsAsObj) platformsAsObj = c.runtime.availablePlatforms; const opts = generateOptions(platformsAsObj); - if (!c.platform || c.platform === true || !c.runtime.availablePlatforms?.includes?.(c.platform)) { + if (!c.platform || c.program.platform === true || !c.runtime.availablePlatforms?.includes?.(c.platform)) { const { platform } = await inquirerPrompt({ name: 'platform', type: 'list', diff --git a/packages/rnv/src/core/pluginManager/types.ts b/packages/rnv/src/core/pluginManager/types.ts index 160dc5548e..8146b3906d 100644 --- a/packages/rnv/src/core/pluginManager/types.ts +++ b/packages/rnv/src/core/pluginManager/types.ts @@ -5,15 +5,16 @@ export type PluginCallback = (plugin: RnvPlugin, pluginPlat: any, key: string) = export type PluginListResponse = { asString: string; asArray: PluginListResponseItem[]; - plugins: PluginListResponseItem[]; + plugins: string[]; allPlugins: Record; + json?: any; }; export type PluginListResponseItem = { name: string; value: string; - props: any; - version: string; + props?: any; + version?: string; }; export type RnvPluginScope = { diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/common.ts b/packages/rnv/src/core/sdkManager/deviceUtils/common.ts index 9f2bd2ecb3..ff6ff9e231 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/common.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/common.ts @@ -12,7 +12,7 @@ export const waitForEmulator = async ( const maxAttempts = 30; const CHECK_INTEVAL = 2000; const { maxErrorLength } = c.program; - const spinner = ora('Waiting for emulator to boot...').start(); + const spinner = ora('Waiting for emulator to boot...').start(''); return new Promise((resolve, reject) => { const interval = setInterval(() => { @@ -24,7 +24,7 @@ export const waitForEmulator = async ( .then((resp) => { if (callback(resp)) { clearInterval(interval); - spinner.succeed(); + spinner.succeed(''); return resolve(true); } attempts++; diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts b/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts index 92154fde38..8dafdd9c71 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts @@ -18,17 +18,19 @@ import { import { isSystemWin, isUrlLocalhost } from '../../systemManager/utils'; import { RnvConfig } from '../../configManager/types'; import { WebosDevice } from '../types'; -import { RnvError } from '../../types'; export const launchWebOSimulator = (c: RnvConfig) => { logTask('launchWebOSimulator'); - const availableEmulatorVersions = getDirectories( - path.join(getRealPath(c, c.buildConfig?.sdks?.WEBOS_SDK), 'Emulator') - ); + const webosSdkPath = getRealPath(c, c.buildConfig?.sdks?.WEBOS_SDK); + if (!webosSdkPath) { + return Promise.reject(`c.buildConfig.sdks.WEBOS_SDK undefined`); + } + + const availableEmulatorVersions = getDirectories(path.join(webosSdkPath, 'Emulator')); const ePath = path.join( - getRealPath(c, c.buildConfig?.sdks?.WEBOS_SDK), + webosSdkPath, `Emulator/${availableEmulatorVersions?.[0] || 'v4.0.0'}/LG_webOS_TV_Emulator${ isSystemWin ? '.exe' : '_RCU.app' }` @@ -67,7 +69,7 @@ const parseDevices = (c: RnvConfig, devicesResponse: string): Promise { const emulator = devices.filter((d) => !d.isDevice)[0]; if (!emulator) throw new Error('No WebOS emulator configured'); - return waitForEmulator(c, CLI_WEBOS_ARES_DEVICE_INFO, `-d ${emulator.name}`, (res) => res.includes('modelName')); + return waitForEmulator(c, CLI_WEBOS_ARES_DEVICE_INFO, `-d ${emulator.name}`, (res) => + typeof res === 'string' ? res.includes('modelName') : res + ); }; export const runWebosSimOrDevice = async (c: RnvConfig) => { diff --git a/packages/rnv/src/core/setupManager/base.ts b/packages/rnv/src/core/setupManager/base.ts index fc796d0040..9710127ee7 100644 --- a/packages/rnv/src/core/setupManager/base.ts +++ b/packages/rnv/src/core/setupManager/base.ts @@ -146,7 +146,7 @@ class BasePlatformSetup { this.postInstall(sdk); } - async installTizenSdk() { + async installTizenSdk(): Promise { // to be overwritten logError( 'Install webos sdk not supported yet. Follow https://developer.tizen.org/development/tizen-studio/download to install it manually' @@ -154,7 +154,7 @@ class BasePlatformSetup { return true; } - async installWebosSdk() { + async installWebosSdk(): Promise { // to be overwritten logError( 'Install webos sdk not supported yet. Follow http://webostv.developer.lge.com/sdk/installation/ to install it manually' diff --git a/packages/rnv/src/core/setupManager/windows.ts b/packages/rnv/src/core/setupManager/windows.ts index 98873d47ce..642c4187d4 100644 --- a/packages/rnv/src/core/setupManager/windows.ts +++ b/packages/rnv/src/core/setupManager/windows.ts @@ -81,15 +81,15 @@ class LinuxPlatformSetup extends BasePlatformSetup { async installSdksAndEmulator() { logDebug('Accepting licenses'); - await executeAsync({}, `${this.androidSdkLocation}/tools/bin/sdkmanager.bat --licenses`); + await executeAsync(`${this.androidSdkLocation}/tools/bin/sdkmanager.bat --licenses`); logDebug('Installing SDKs', this.sdksToInstall); - await executeAsync({}, `${this.androidSdkLocation}/tools/bin/sdkmanager.bat ${this.sdksToInstall}`); + await executeAsync(`${this.androidSdkLocation}/tools/bin/sdkmanager.bat ${this.sdksToInstall}`); } async installTizenSdk() { - let downloadDir = setupConfig.tizen.downloadLocation.split('/'); - downloadDir.pop(); - downloadDir = downloadDir.join('/'); + const _downloadDir = setupConfig.tizen.downloadLocation.split('/'); + _downloadDir.pop(); + const downloadDir = _downloadDir.join('/'); logInfo(`Opening ${downloadDir}. Please install the SDK then continue after it finished installing.`); exec(`start "" "${downloadDir}"`); diff --git a/packages/rnv/src/core/systemManager/crypto.ts b/packages/rnv/src/core/systemManager/crypto.ts index 52a9158969..9da4ca6555 100644 --- a/packages/rnv/src/core/systemManager/crypto.ts +++ b/packages/rnv/src/core/systemManager/crypto.ts @@ -21,7 +21,7 @@ export const getEnvVar = (c: RnvConfig) => { return envVar; }; -export const checkCrypto = async (c: RnvConfig, parentTask: string, originTask: string) => { +export const checkCrypto = async (c: RnvConfig, parentTask?: string, originTask?: string) => { logTask('checkCrypto'); if (c.program.ci || c.files.project.config?.crypto?.optional) return; diff --git a/packages/rnv/src/core/systemManager/exec.ts b/packages/rnv/src/core/systemManager/exec.ts index 14ef1c8b6b..8f45469018 100755 --- a/packages/rnv/src/core/systemManager/exec.ts +++ b/packages/rnv/src/core/systemManager/exec.ts @@ -12,7 +12,6 @@ import { fsExistsSync } from './fileutils'; import { replaceOverridesInString } from './utils'; import { RnvConfig } from '../configManager/types'; import { ExecCallback, ExecCallback2, ExecOptions } from './types'; -import { RnvError } from '../types'; const { exec, execSync } = require('child_process'); @@ -77,7 +76,7 @@ const _execute = (c: RnvConfig, command: string, opts: ExecOptions = {}) => { logMessage = `${env ? `${env} ` : ''}${logMessage}`; logDebug(`_execute: ${logMessage}`); const { silent, mono, maxErrorLength, ignoreErrors } = mergedOpts; - const spinner = !silent && !mono && ora({ text: `Executing: ${logMessage}` }).start(); + const spinner = !silent && !mono && ora({ text: `Executing: ${logMessage}` }).start(''); if (opts.interactive) { logRaw(`${chalk().green('✔')} Executing: ${logMessage}\n`); } @@ -290,7 +289,7 @@ const executeTelnet = (c: RnvConfig, port: string, command: string) => if (output.includes('OK')) nc2.close(); }); nc2.on('close', () => resolve(output)); - } catch (e: RnvError) { + } catch (e: any) { logError(e); resolve(''); } diff --git a/packages/rnv/src/core/systemManager/fileutils.ts b/packages/rnv/src/core/systemManager/fileutils.ts index 1aa3fd562e..22c7595fc2 100755 --- a/packages/rnv/src/core/systemManager/fileutils.ts +++ b/packages/rnv/src/core/systemManager/fileutils.ts @@ -7,10 +7,20 @@ import merge from 'deepmerge'; import ncp from 'ncp'; import { chalk, logDebug, logError, logWarning } from './logger'; import { RnvConfig } from '../configManager/types'; -import { FileUtilsPropConfig, FileUtilsUpdateConfig, OverridesOptions, TimestampPathsConfig } from './types'; -import type { RnvError } from '../types'; - -export const configureFilesystem = (_getConfigProp: () => string, _doResolve: () => any, _isSystemWin: boolean) => { +import { + DoResolveFn, + FileUtilsPropConfig, + FileUtilsUpdateConfig, + OverridesOptions, + TimestampPathsConfig, +} from './types'; +import type { GetConfigPropFn } from '../types'; + +export const configureFilesystem = ( + _getConfigProp: GetConfigPropFn, + _doResolve: DoResolveFn, + _isSystemWin: boolean +) => { global.getConfigProp = _getConfigProp; global.doResolve = _doResolve; global.isSystemWin = _isSystemWin; @@ -268,7 +278,7 @@ export const copyFolderRecursiveSync = ( export const copyFolderContentsRecursiveSync = ( source: string | null | undefined, - target: string, + target: string | null | undefined, convertSvg = true, skipPaths?: Array, skipOverride?: boolean, @@ -278,7 +288,7 @@ export const copyFolderContentsRecursiveSync = ( extFilter?: Array ) => { logDebug('copyFolderContentsRecursiveSync', source, target, skipPaths); - if (!source) return; + if (!source || !target) return; if (!fs.existsSync(source)) return; let files = []; const targetFolder = path.join(target); @@ -381,7 +391,7 @@ export const removeFilesSync = (filePaths: Array) => { } else { logDebug(`Path ${filePath} does not exist`); } - } catch (e: RnvError) { + } catch (e: any) { logError(e); } }); diff --git a/packages/rnv/src/core/systemManager/resolve.ts b/packages/rnv/src/core/systemManager/resolve.ts index deff87836c..3e433e9f4f 100644 --- a/packages/rnv/src/core/systemManager/resolve.ts +++ b/packages/rnv/src/core/systemManager/resolve.ts @@ -1,7 +1,7 @@ import resolve from 'resolve'; import fs from 'fs'; import path from 'path'; -import { ResolveOptions } from './types'; +import { DoResolveFn, ResolveOptions } from './types'; /** * An attempt at drying out filesystem references to [external packages](https://tinyurl.com/mao2dy6). * @@ -18,7 +18,7 @@ import { ResolveOptions } from './types'; * @param {*} mandatory - whether it throws * @param {*} options - docs - https://tinyurl.com/r9sfpf7 && {keepSuffix: boolean} */ -export const doResolve = (aPath: string, mandatory = true, options: ResolveOptions = {}) => { +export const doResolve: DoResolveFn = (aPath, mandatory = true, options = {}) => { options.basedir = options.basedir ?? process.cwd(); try { if (aPath.startsWith('file:')) { diff --git a/packages/rnv/src/core/systemManager/types.ts b/packages/rnv/src/core/systemManager/types.ts index b579ee613e..e30d51f326 100644 --- a/packages/rnv/src/core/systemManager/types.ts +++ b/packages/rnv/src/core/systemManager/types.ts @@ -41,7 +41,7 @@ export type OverridesOptions = Array<{ }>; export type TimestampPathsConfig = { - timestamp: Array; + timestamp: number; paths: Array; }; @@ -59,3 +59,5 @@ export type FileUtilsUpdateConfig = { tizenSdk?: string; webosSdk?: string; }; + +export type DoResolveFn = (aPath: string, mandatory?: boolean, options?: ResolveOptions) => string | undefined; diff --git a/packages/rnv/src/core/taskManager/index.ts b/packages/rnv/src/core/taskManager/index.ts index 6da403f882..8ef7e4a490 100644 --- a/packages/rnv/src/core/taskManager/index.ts +++ b/packages/rnv/src/core/taskManager/index.ts @@ -217,7 +217,8 @@ export const findSuitableTask = async (c: RnvConfig, specificTask?: string): Pro c.subCommand = null; return findSuitableTask(c); } - if (!c.platform || c.platform === true) { + //TODO: special type case for c.platform + if (!c.platform || c.program.platform === true) { await _selectPlatform(c, suitableEngines, task); } c.runtime.engine = getEngineRunner(c, task, CUSTOM_TASKS, false); @@ -344,7 +345,7 @@ const _logSkip = (task: string) => { logInfo(`Original RNV task ${chalk().white(task)} marked to ignore. SKIPPING...`); }; -export const shouldSkipTask = (c: RnvConfig, task: string, originTask: string) => { +export const shouldSkipTask = (c: RnvConfig, task: string, originTask?: string) => { const tasks = c.buildConfig?.tasks; c.runtime.platform = c.platform; if (!tasks) return; @@ -364,7 +365,8 @@ export const shouldSkipTask = (c: RnvConfig, task: string, originTask: string) = conditions.forEach((con: string) => { const conArr = con.split('='); if (ACCEPTED_CONDITIONS.includes(conArr[0])) { - if (c.runtime[conArr[0]] === conArr[1]) { + const rt: any = c.runtime; + if (rt[conArr[0]] === conArr[1]) { conditionsToMatch--; } } else { @@ -393,6 +395,9 @@ export const shouldSkipTask = (c: RnvConfig, task: string, originTask: string) = _logSkip(task); return true; } + if (!originTask) { + return false; + } const ignoreTasks = tasks[originTask]?.platform?.[c.platform]?.ignoreTasks || []; if (ignoreTasks.includes(task)) { logInfo(`Task ${task} marked to skip during rnv ${originTask}. SKIPPING...`); diff --git a/packages/rnv/src/core/types.ts b/packages/rnv/src/core/types.ts index af603c7840..9de47a6f15 100644 --- a/packages/rnv/src/core/types.ts +++ b/packages/rnv/src/core/types.ts @@ -1,3 +1,5 @@ +import { RnvConfig } from './configManager/types'; + export type RnvPlatform = string; export type RnvModuleConfig = { @@ -5,8 +7,10 @@ export type RnvModuleConfig = { moduleAliasesArray: Array; }; -export type RnvNextJSConfig = {}; +export type RnvNextJSConfig = any; export type RenativeConfigVersion = string | { version: string }; export type RnvError = any; + +export type GetConfigPropFn = (c: RnvConfig, platform: string, key: string, defaultVal?: any) => T; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.plugin.add.ts b/packages/rnv/src/engine-core/tasks/task.rnv.plugin.add.ts index 6e3de432c3..b164b1b970 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.plugin.add.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.plugin.add.ts @@ -68,7 +68,7 @@ export const taskRnvPluginAdd: RnvTaskFn = async (c, _parentTask, originTask) => c.files.project.config.config_original[pluginKey].props = finalProps; } - const spinner = ora(`Installing: ${installMessage.join(', ')}`).start(); + const spinner = ora(`Installing: ${installMessage.join(', ')}`).start(''); writeRenativeConfigFile(c, c.paths.project.config, c.files.project.config_original); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.project.configure.ts b/packages/rnv/src/engine-core/tasks/task.rnv.project.configure.ts index 41beef9794..8811378de8 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.project.configure.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.project.configure.ts @@ -69,7 +69,9 @@ export const taskRnvProjectConfigure: RnvTaskFn = async (c, parentTask, originTa const taskInstance = await findSuitableTask(c); c.runtime.requiresBootstrap = false; - return initializeTask(c, taskInstance.task); + if (taskInstance?.task) { + return initializeTask(c, taskInstance?.task); + } } await applyTemplate(c); await configureRuntimeDefaults(c); From facc357f301d257b6db46799f06334fdd238f634 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Fri, 1 Sep 2023 00:02:39 +0200 Subject: [PATCH 34/83] more ts refactor, 38 togo --- packages/rnv/src/__tests__/startup.test.ts | 2 +- packages/rnv/src/core/configManager/index.ts | 27 ++++-- packages/rnv/src/core/configManager/types.ts | 85 ++++--------------- .../rnv/src/core/projectManager/buildHooks.ts | 13 ++- packages/rnv/src/core/projectManager/index.ts | 23 +++-- packages/rnv/src/core/runtimeManager/index.ts | 50 +++++------ .../rnv/src/core/systemManager/fileutils.ts | 2 +- 7 files changed, 85 insertions(+), 117 deletions(-) diff --git a/packages/rnv/src/__tests__/startup.test.ts b/packages/rnv/src/__tests__/startup.test.ts index 1ffae78775..b273a4f970 100644 --- a/packages/rnv/src/__tests__/startup.test.ts +++ b/packages/rnv/src/__tests__/startup.test.ts @@ -35,7 +35,7 @@ let c; describe('Bootstrapping the CLI', () => { beforeAll(() => { - c = createRnvConfig({ program: true }, { process: true }, { cmd: true }, { subCmd: true }); + c = createRnvConfig({ program: true }, { process: true }, 'command', 'subcommand'); generateBuildConfig(c); }); diff --git a/packages/rnv/src/core/configManager/index.ts b/packages/rnv/src/core/configManager/index.ts index 5265374cf6..c83608fa88 100644 --- a/packages/rnv/src/core/configManager/index.ts +++ b/packages/rnv/src/core/configManager/index.ts @@ -429,9 +429,11 @@ const _generatePlatformTemplatePaths = (c: RnvConfig) => { if (originalPath) { if (!pt[platform]) { - result[platform] = getRealPath(c, originalPath, 'platformTemplatesDir', originalPath); + const pt1 = getRealPath(c, originalPath, 'platformTemplatesDir', originalPath); + if (pt1) result[platform] = pt1; } else { - result[platform] = getRealPath(c, pt[platform], 'platformTemplatesDir', originalPath); + const pt2 = getRealPath(c, pt[platform], 'platformTemplatesDir', originalPath); + if (pt2) result[platform] = pt2; } } else { logWarning(`Platform ${chalk().red(platform)} not supported by any registered engine. SKIPPING...`); @@ -528,8 +530,11 @@ export const parseRenativeConfigs = async (c: RnvConfig) => { loadFile(c.files.project.builds, c.paths.project.builds, 'config'); // LOAD WORKSPACE /RENATIVE.*.JSON - _generateConfigPaths(c.paths.workspace, getRealPath(c, await getWorkspaceDirPath(c))); - _loadConfigFiles(c, c.files.workspace, c.paths.workspace); + const wsDir = getRealPath(c, await getWorkspaceDirPath(c)); + if (wsDir) { + _generateConfigPaths(c.paths.workspace, wsDir); + _loadConfigFiles(c, c.files.workspace, c.paths.workspace); + } // LOAD DEFAULT WORKSPACE _generateConfigPaths(c.paths.defaultWorkspace, c.paths.GLOBAL_RNV_DIR); @@ -586,15 +591,21 @@ export const parseRenativeConfigs = async (c: RnvConfig) => { loadFile(c.files.project.assets, c.paths.project.assets, 'config'); // LOAD WORKSPACE /RENATIVE.*.JSON - _generateConfigPaths(c.paths.workspace, getRealPath(c, await getWorkspaceDirPath(c))); - _loadConfigFiles(c, c.files.workspace, c.paths.workspace); + const wsPath = await getWorkspaceDirPath(c); + if (wsPath) { + const wsPathReal = getRealPath(c, wsPath); + if (wsPathReal) { + _generateConfigPaths(c.paths.workspace, wsPathReal); + _loadConfigFiles(c, c.files.workspace, c.paths.workspace); + } + } generateLocalConfig(c); generateBuildConfig(c); } }; -export const createRnvConfig = (program: any, process: any, cmd: string, subCmd: string, { projectRoot } = {}) => { +export const createRnvConfig = (program: any, process: any, cmd: string, subCmd: string) => { const c: RnvConfig = generateConfigBase(); global.RNV_CONFIG = c; @@ -628,7 +639,7 @@ export const createRnvConfig = (program: any, process: any, cmd: string, subCmd: mkdirSync(c.paths.GLOBAL_RNV_DIR); } - _generateConfigPaths(c.paths.project, projectRoot || CURRENT_DIR, c.program.configName); + _generateConfigPaths(c.paths.project, CURRENT_DIR, c.program.configName); c.paths.buildHooks.dir = path.join(c.paths.project.dir, 'buildHooks/src'); c.paths.buildHooks.dist.dir = path.join(c.paths.project.dir, 'buildHooks/dist'); diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index 4af62ae4f4..d73e854fd2 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -52,12 +52,7 @@ export interface RnvConfig { activeTemplate: string; engine?: RnvEngine; target: string; - supportedPlatforms: Array<{ - platform: string; - isConnected: boolean; - engine?: any; - port?: string; - }>; + supportedPlatforms: Array; keepSessionActive: boolean; platformBuildsProjectPath: string; availablePlatforms: Array; @@ -110,48 +105,19 @@ export interface RnvConfig { //ADDON dir: string; package: string; - // config: string; - // configLocal: string; - // configPrivate: string; - // appConfigsDir: string; - // dirs: Array; - // fontsDirs: Array; - // pluginDirs: Array; - // configs: Array; - // configsLocal: Array; - // configsPrivate: Array; }; - workspace: { - project: { + workspace: RnvConfigPathObj & { + project: RnvConfigPathObj & { appConfigBase: Record; builds: Record; assets: Record; platformTemplates: Record; appConfigsDirs: Array; appConfigsDirNames: Array; - //ADDON - dir?: string; - config?: string; - configExists?: boolean; - configLocal?: string; - configPrivate?: string; - appConfigsDir?: string; }; - appConfig: { - configs: Array; - configsPrivate: Array; - configsLocal: Array; - dir: string; - }; - //ADDON - config: string; - configLocal?: string; - configPrivate?: string; - dir: string; + appConfig: RnvConfigPathObj; }; - defaultWorkspace: { - //ADDON - config: string; + defaultWorkspace: RnvConfigPathObj & { project: { appConfigBase: Record; builds: Record; @@ -167,8 +133,6 @@ export interface RnvConfig { }; }; project: RnvConfigPathObj & { - config: string; - configExists: boolean; appConfigBase: Record; builds: Record; assets: Record; @@ -179,32 +143,12 @@ export interface RnvConfig { dir: string; nodeModulesDir: string; srcDir: string; - appConfigsDir: string; package: string; rnCliConfig: string; babelConfig: string; - configLocal: string; - configPrivate: string; platformTemplatesDirs: Record; - // appConfigsDir: string; - // dirs: Array; - // fontsDirs: Array; - // pluginDirs: Array; - // configs: Array; - // configsLocal: Array; - // configsPrivate: Array; - }; - appConfig: { - config: string; - configs: Array; - configsPrivate: Array; - configsLocal: Array; - dir: string; - dirs: Array; - pluginDirs: Array; - fontsDirs: Array; - fontsDir: string; }; + appConfig: RnvConfigPathObj; // EXTRA buildHooks: { dist: Record; @@ -239,15 +183,11 @@ export interface RnvConfig { package: any; }; workspace: { - project: { + project: RnvConfigPathObj & { appConfigBase: Record; builds: Record; assets: Record; platformTemplates: Record; - //ADDON - config: any; - configLocal: any; - configPrivate: any; }; appConfig: { configs: Array; @@ -309,12 +249,14 @@ export interface RnvConfigPathObj { configLocal: string; configPrivate: string; appConfigsDir: string; + fontsDir: string; dirs: Array; fontsDirs: Array; pluginDirs: Array; configs: Array; configsLocal: Array; configsPrivate: Array; + configExists?: boolean; // appConfigBase: Record; // builds: Record; // assets: Record; @@ -380,6 +322,7 @@ export type RenativeConfigFile = { defaultTargets: Record; templateConfig: any; enableAnalytics: boolean; + workspaceAppConfigsDir: string; }; export type RenativeConfigPlugin = { @@ -402,6 +345,14 @@ export type RenativeConfigPlugin = { props?: Record; }; +export type RnvConfigPlatform = { + platform: string; + isConnected: boolean; + engine?: any; + port?: string; + isValid?: boolean; +}; + export type RenativeWebpackConfig = { modulePaths?: | Array< diff --git a/packages/rnv/src/core/projectManager/buildHooks.ts b/packages/rnv/src/core/projectManager/buildHooks.ts index 9116eadabd..1aa363214a 100644 --- a/packages/rnv/src/core/projectManager/buildHooks.ts +++ b/packages/rnv/src/core/projectManager/buildHooks.ts @@ -1,7 +1,7 @@ import inquirer from 'inquirer'; import path from 'path'; import { build } from 'esbuild'; -import { logDebug, logHook, logInfo } from '../systemManager/logger'; +import { logDebug, logError, logHook, logInfo } from '../systemManager/logger'; import { fsExistsSync, copyFolderContentsRecursiveSync } from '../systemManager/fileutils'; import { getConfigProp } from '../common'; import { doResolve } from '../systemManager/resolve'; @@ -12,16 +12,15 @@ export const executePipe = async (c: RnvConfig, key: string) => { await buildHooks(c); - const pipe = c.buildPipes ? c.buildPipes[key] : null; + const pipes = c.buildPipes ? c.buildPipes[key] : null; - if (Array.isArray(pipe)) { - await pipe.reduce((accumulatorPromise, next) => { + if (Array.isArray(pipes)) { + await pipes.reduce((accumulatorPromise: Promise, next) => { logHook(`buildHook.${next?.name}`, '(EXECUTING)'); return accumulatorPromise.then(() => next(c)); }, Promise.resolve()); - } else if (pipe) { - logHook(`buildHook.${pipe?.name}`, '(EXECUTING)'); - await pipe(c); + } else if (pipes) { + logError(`buildPipes is not an Array!`); } }; diff --git a/packages/rnv/src/core/projectManager/index.ts b/packages/rnv/src/core/projectManager/index.ts index dc2c551919..b704edde41 100644 --- a/packages/rnv/src/core/projectManager/index.ts +++ b/packages/rnv/src/core/projectManager/index.ts @@ -39,7 +39,7 @@ import { RnvPluginPlatform } from '../pluginManager/types'; export const checkAndBootstrapIfRequired = async (c: RnvConfig) => { logTask('checkAndBootstrapIfRequired'); - const { template } = c.program; + const template: string = c.program?.template; if (!c.paths.project.configExists && template) { await executeAsync(`${isYarnInstalled() ? 'yarn' : 'npm'} add ${template}`, { cwd: c.paths.project.dir, @@ -450,7 +450,7 @@ export const copyAssetsFolder = async ( const tsPathsConfig = getTimestampPathsConfig(c, platform); - const assetSources = getConfigProp(c, platform, 'assetSources', []); + const assetSources = getConfigProp>(c, platform, 'assetSources', []); const validAssetSources: Array = []; assetSources.forEach((v) => { @@ -460,7 +460,7 @@ export const copyAssetsFolder = async ( } }); - const destPath = path.join(getPlatformProjectDir(c, platform), subPath || ''); + const destPath = path.join(getPlatformProjectDir(c) || '', subPath || ''); // FOLDER MERGERS FROM EXTERNAL SOURCES if (validAssetSources.length > 0) { @@ -470,7 +470,7 @@ export const copyAssetsFolder = async ( )}. Will be used to generate assets.` ); validAssetSources.forEach((sourcePath) => { - copyFolderContentsRecursiveSync(sourcePath, destPath, true, undefined, false, {}, tsPathsConfig, c); + copyFolderContentsRecursiveSync(sourcePath, destPath, true, undefined, false, undefined, tsPathsConfig, c); }); return; } @@ -506,11 +506,11 @@ export const copyAssetsFolder = async ( if (c.paths.appConfig.dirs) { c.paths.appConfig.dirs.forEach((v) => { const sourcePath = path.join(v, `assets/${assetFolderPlatform}`); - copyFolderContentsRecursiveSync(sourcePath, destPath, true, undefined, false, {}, tsPathsConfig, c); + copyFolderContentsRecursiveSync(sourcePath, destPath, true, undefined, false, undefined, tsPathsConfig, c); }); } else { const sourcePath = path.join(c.paths.appConfig.dir, `assets/${assetFolderPlatform}`); - copyFolderContentsRecursiveSync(sourcePath, destPath, true, undefined, false, {}, tsPathsConfig, c); + copyFolderContentsRecursiveSync(sourcePath, destPath, true, undefined, false, undefined, tsPathsConfig, c); } }; @@ -588,7 +588,14 @@ Move your files to: ${chalk().white(sourcePath1sec)} instead`); if (fsExistsSync(sourcePathShared)) { logWarning('Folder builds/_shared is DEPRECATED. use builds/ instead '); } - copyFolderContentsRecursiveSync(sourcePathShared, getPlatformBuildDir(c), true, false, false, allInjects); + copyFolderContentsRecursiveSync( + sourcePathShared, + getPlatformBuildDir(c), + true, + undefined, + false, + allInjects + ); } // FOLDER MERGERS FROM APP CONFIG + EXTEND @@ -719,7 +726,7 @@ export const upgradeDependencies = ( writeFileSync(packagesPath, packageFile); result.push(packagesPath); } - if (configFile) { + if (configFile && configPath) { writeFileSync(configPath, configFile); result.push(configPath); } diff --git a/packages/rnv/src/core/runtimeManager/index.ts b/packages/rnv/src/core/runtimeManager/index.ts index 08fbf2cde4..e8757d1432 100644 --- a/packages/rnv/src/core/runtimeManager/index.ts +++ b/packages/rnv/src/core/runtimeManager/index.ts @@ -6,7 +6,7 @@ import { getConfigProp } from '../common'; import { logTask } from '../systemManager/logger'; import { loadPluginTemplates } from '../pluginManager'; import { parseRenativeConfigs } from '../configManager/index'; -import { RnvConfig } from '../configManager/types'; +import { RnvConfig, RnvConfigPlatform } from '../configManager/types'; export const updateRenativeConfigs = async (c: RnvConfig) => { await loadPluginTemplates(c); @@ -44,10 +44,11 @@ export const configureRuntimeDefaults = async (c: RnvConfig) => { c.systemPropsInjects = c.systemPropsInjects || []; c.runtimePropsInjects = []; + const rt: any = c.runtime; INJECTABLE_RUNTIME_PROPS.forEach((key) => { c.runtimePropsInjects.push({ pattern: `{{runtimeProps.${key}}}`, - override: c.runtime[key], + override: rt[key], }); }); if (c.buildConfig) { @@ -57,31 +58,30 @@ export const configureRuntimeDefaults = async (c: RnvConfig) => { // c.runtime.devServer = `http://${ip.address()}:${c.runtime.port}`; if (c.buildConfig.defaults?.supportedPlatforms) { - c.runtime.supportedPlatforms = c.buildConfig.defaults.supportedPlatforms - .map((platform) => { - const engine = getEngineRunnerByPlatform(c, platform); - if (engine) { - const dir = engine.originalTemplatePlatformsDir; + c.runtime.supportedPlatforms = []; + c.buildConfig.defaults.supportedPlatforms.forEach((platform) => { + const engine = getEngineRunnerByPlatform(c, platform); + if (engine) { + const dir = engine.originalTemplatePlatformsDir; - let isConnected = false; - let isValid = false; - const pDir = c.paths.project.platformTemplatesDirs?.[platform]; - if (pDir) { - isValid = true; - isConnected = pDir?.includes?.(getRealPath(c, dir) || 'UNDEFINED'); - } - const port = c.buildConfig.defaults?.[platform] || c.runtime.currentPlatform?.defaultPort; - return { - engine, - platform, - isConnected, - port, - isValid, - }; + let isConnected = false; + let isValid = false; + const pDir = c.paths.project.platformTemplatesDirs?.[platform]; + if (pDir) { + isValid = true; + isConnected = pDir?.includes?.(getRealPath(c, dir) || 'UNDEFINED'); } - return null; - }) - .filter((v) => v); + const port = c.buildConfig.defaults?.ports?.[platform] || c.runtime.currentPlatform?.defaultPort; + const cp: RnvConfigPlatform = { + engine, + platform, + isConnected, + port, + isValid, + }; + c.runtime.supportedPlatforms.push(cp); + } + }); } } return true; diff --git a/packages/rnv/src/core/systemManager/fileutils.ts b/packages/rnv/src/core/systemManager/fileutils.ts index 22c7595fc2..fe31e76377 100755 --- a/packages/rnv/src/core/systemManager/fileutils.ts +++ b/packages/rnv/src/core/systemManager/fileutils.ts @@ -531,7 +531,7 @@ export const updateObjectSync = (filePath: string, updateObj: object) => { return output; }; -export const getRealPath = (c: RnvConfig, p: string, key = 'undefined', original?: string) => { +export const getRealPath = (c: RnvConfig, p: string | undefined, key = 'undefined', original?: string) => { if (!p) { if (original) { logDebug(`Path ${chalk().white(key)} is not defined. using default: ${chalk().white(original)}`); From ed67f7da5a5ec23627ca899ca731d7d6f972293b Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Fri, 1 Sep 2023 00:21:31 +0200 Subject: [PATCH 35/83] more ts migrations, 21 togo --- packages/rnv/src/core/configManager/index.ts | 22 +++++-- .../src/core/configManager/schemeParser.ts | 2 +- packages/rnv/src/core/configManager/types.ts | 62 ++++++------------- packages/rnv/src/core/engineManager/index.ts | 2 +- .../rnv/src/core/projectManager/buildHooks.ts | 2 +- .../src/core/sdkManager/deviceUtils/tizen.ts | 11 ++-- 6 files changed, 46 insertions(+), 55 deletions(-) diff --git a/packages/rnv/src/core/configManager/index.ts b/packages/rnv/src/core/configManager/index.ts index c83608fa88..0f22e3f17e 100644 --- a/packages/rnv/src/core/configManager/index.ts +++ b/packages/rnv/src/core/configManager/index.ts @@ -302,11 +302,18 @@ const _loadConfigFiles = ( fileObj.configs = []; fileObj.configsLocal = []; fileObj.configsPrivate = []; - const fileObj1: RnvConfigFileObj = {}; + const fileObj1: RnvConfigFileObj = { + configs: [], + configsLocal: [], + configsPrivate: [], + }; // PATH1: appConfigs/base const path1 = path.join(pathObj.appConfigsDir, 'base'); const pathObj1: RnvConfigPathObj = { + configs: [], + configsLocal: [], + configsPrivate: [], config: path.join(path1, RENATIVE_CONFIG_NAME), configLocal: path.join(path1, RENATIVE_CONFIG_LOCAL_NAME), configPrivate: path.join(path1, RENATIVE_CONFIG_PRIVATE_NAME), @@ -334,7 +341,11 @@ const _loadConfigFiles = ( configLocal: path.join(path2, RENATIVE_CONFIG_LOCAL_NAME), configPrivate: path.join(path2, RENATIVE_CONFIG_PRIVATE_NAME), }; - const fileObj2: RnvConfigFileObj = {}; + const fileObj2: RnvConfigFileObj = { + configs: [], + configsLocal: [], + configsPrivate: [], + }; // PATH2: appConfigs/ pathObj.dirs.push(path2); pathObj.fontsDirs.push(path.join(path2, 'fonts')); @@ -415,7 +426,10 @@ const _generatePlatformTemplatePaths = (c: RnvConfig) => { logTask('_generatePlatformTemplatePaths'); if (!c.buildConfig.paths) { logWarning(`You're missing paths object in your ${chalk().red(c.paths.project.config)}`); - c.buildConfig.paths = {}; + c.buildConfig.paths = { + appConfigsDirs: [], + platformTemplatesDirs: {}, + }; } const pt = c.buildConfig.paths.platformTemplatesDirs || c.buildConfig.platformTemplatesDirs || {}; @@ -669,7 +683,7 @@ export const createRnvConfig = (program: any, process: any, cmd: string, subCmd: // LOAD WORKSPACES try { _loadWorkspacesSync(c); - } catch (e) { + } catch (e: any) { logError(e); } diff --git a/packages/rnv/src/core/configManager/schemeParser.ts b/packages/rnv/src/core/configManager/schemeParser.ts index a774053faa..535d9273d5 100644 --- a/packages/rnv/src/core/configManager/schemeParser.ts +++ b/packages/rnv/src/core/configManager/schemeParser.ts @@ -15,7 +15,7 @@ export const isBuildSchemeSupported = async (c: RnvConfig) => { } const baseBuildSchemes = c.buildConfig.common?.buildSchemes || {}; - const platformBuildSchemes = c.buildConfig.platforms[c.platform]?.buildSchemes; + const platformBuildSchemes = c.buildConfig.platforms[c.platform]?.buildSchemes || {}; const buildSchemes = merge(baseBuildSchemes, platformBuildSchemes); diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index d73e854fd2..3aa16b313f 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -182,58 +182,33 @@ export interface RnvConfig { configWorkspaces: any; package: any; }; - workspace: { - project: RnvConfigPathObj & { + workspace: RnvConfigFileObj & { + project: RnvConfigFileObj & { appConfigBase: Record; builds: Record; assets: Record; platformTemplates: Record; }; - appConfig: { - configs: Array; - configsPrivate: Array; - configsLocal: Array; - }; - //ADDON - config: any; - configLocal: any; - configPrivate: any; + appConfig: RnvConfigFileObj; }; - defaultWorkspace: { - project: { + defaultWorkspace: RnvConfigFileObj & { + project: RnvConfigFileObj & { appConfigBase: Record; builds: Record; assets: Record; platformTemplates: Record; }; - appConfig: { - configs: Array; - configsPrivate: Array; - configsLocal: Array; - }; - //ADDON - config: any; - configLocal: any; - configPrivate: any; + appConfig: RnvConfigFileObj; }; - project: { + project: RnvConfigFileObj & { appConfigBase: Record; builds: Record; assets: Record; platformTemplates: Record; //ADDON - config: any; - config_original: any; - configLocal: any; - configPrivate: any; package: any; }; - appConfig: { - config?: any; - configs: Array; - configsPrivate: Array; - configsLocal: Array; - }; + appConfig: RnvConfigFileObj; }; } @@ -266,9 +241,10 @@ export interface RnvConfigPathObj { } export interface RnvConfigFileObj { - config: any; - configLocal: any; - configPrivate: any; + config?: any; + config_original?: any; + configLocal?: any; + configPrivate?: any; configs: Array; configsLocal: Array; configsPrivate: Array; @@ -289,13 +265,13 @@ export type RenativeConfigFile = { platforms: Record< string, { - buildSchemes: Record; + buildSchemes?: Record; entryFile?: string; - runtime: Record; - appName: string; - id: string; - certificateProfile: string; - engine: string; + runtime?: Record; + appName?: string; + id?: string; + certificateProfile?: string; + engine?: string; } >; templates: Record< @@ -311,7 +287,7 @@ export type RenativeConfigFile = { paths: { appConfigsDirs: Array; platformTemplatesDirs: Record; - globalConfigDir: string; + globalConfigDir?: string; }; integrations: Record; tasks: Array | Record; diff --git a/packages/rnv/src/core/engineManager/index.ts b/packages/rnv/src/core/engineManager/index.ts index 3486785a14..cae5a4c8b2 100644 --- a/packages/rnv/src/core/engineManager/index.ts +++ b/packages/rnv/src/core/engineManager/index.ts @@ -549,7 +549,7 @@ export const getEngineTask = (task: string, tasks?: RnvTaskMap, customTasks?: Rn return tsk; }; -export const hasEngineTask = (task: string, tasks: RnvTaskMap, isProjectScope: boolean) => +export const hasEngineTask = (task: string, tasks: RnvTaskMap, isProjectScope?: boolean) => isProjectScope ? !!getEngineTask(task, tasks) : getEngineTask(task, tasks)?.isGlobalScope; export const getEngineSubTasks = (task: string, tasks: RnvTaskMap, exactMatch?: boolean) => diff --git a/packages/rnv/src/core/projectManager/buildHooks.ts b/packages/rnv/src/core/projectManager/buildHooks.ts index 1aa363214a..92dc615274 100644 --- a/packages/rnv/src/core/projectManager/buildHooks.ts +++ b/packages/rnv/src/core/projectManager/buildHooks.ts @@ -15,7 +15,7 @@ export const executePipe = async (c: RnvConfig, key: string) => { const pipes = c.buildPipes ? c.buildPipes[key] : null; if (Array.isArray(pipes)) { - await pipes.reduce((accumulatorPromise: Promise, next) => { + await pipes.reduce((accumulatorPromise: any, next) => { logHook(`buildHook.${next?.name}`, '(EXECUTING)'); return accumulatorPromise.then(() => next(c)); }, Promise.resolve()); diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts index 0fbe47d61c..ee4cc89100 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts @@ -7,7 +7,6 @@ import { CLI_SDB_TIZEN, CLI_TIZEN, CLI_TIZEN_EMULATOR, RENATIVE_CONFIG_NAME } fr import { execCLI } from '../../systemManager/exec'; import { fsRenameSync } from '../../systemManager/fileutils'; import { chalk, logDebug, logError, logInfo, logTask, logToSummary, logWarning } from '../../systemManager/logger'; -import { RnvError } from '../../types'; import { TizenDevice, TizenSecurityConfig } from '../types'; import { waitForEmulator } from './common'; @@ -107,7 +106,7 @@ const _getDeviceID = async (c: RnvConfig, target: string) => { let connectResponse: string; try { connectResponse = await execCLI(c, CLI_SDB_TIZEN, `connect ${target}`); - } catch (e: RnvError) { + } catch (e: any) { connectResponse = e; } if (connectResponse.includes('EPERM')) { @@ -248,6 +247,8 @@ export const runTizenSimOrDevice = async (c: RnvConfig, buildCoreWebpackProject: let deviceID: string; + if (!tId) return Promise.reject(`Tizen platform requires "id" filed in platforms.tizen`); + const askForEmulator = async () => { const { startEmulator } = await inquirer.prompt([ { @@ -297,7 +298,7 @@ Please create one and then edit the default target from ${c.paths.workspace.dir} const packageID = platform === 'tizenwatch' || platform === 'tizenmobile' ? tId.split('.')[0] : tId; await execCLI(c, CLI_TIZEN, `uninstall -p ${packageID} -t ${deviceID}`, { ignoreErrors: true }); hasDevice = true; - } catch (e: RnvError) { + } catch (e: any) { if (e && e.includes && e.includes('No device matching')) { await launchTizenSimulator(c, target); hasDevice = await _waitForEmulatorToBeReady(c, target); @@ -310,13 +311,13 @@ Please create one and then edit the default target from ${c.paths.workspace.dir} ); fsRenameSync(path.join(tOut, wgt), path.join(tOut, wgtClean)); } - } catch (err: RnvError) { + } catch (err: any) { logError(err); } try { await execCLI(c, CLI_TIZEN, `install -- ${tOut} -n ${wgtClean} -t ${deviceID}`); hasDevice = true; - } catch (err: RnvError) { + } catch (err: any) { logError(err); logWarning( `There is no emulator or device connected! Let's try to launch it. "${chalk().white.bold( From 0280b186df59754c76a53eaf9d5024177870e5f9 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Fri, 1 Sep 2023 00:45:45 +0200 Subject: [PATCH 36/83] more ts migrations, 16 togo --- packages/rnv/src/cli/index.ts | 2 +- packages/rnv/src/core/common.ts | 4 ++++ packages/rnv/src/core/configManager/configBase.ts | 4 +++- packages/rnv/src/core/configManager/types.ts | 4 ++-- packages/rnv/src/core/engineManager/index.ts | 14 ++++++++------ packages/rnv/src/core/engineManager/types.ts | 15 +++++++++------ packages/rnv/src/core/platformManager/index.ts | 10 +++++++--- .../src/core/schemaManager/schemaRenativeJson.ts | 4 ++-- packages/rnv/src/engine-core/index.ts | 9 +++++++-- packages/rnv/src/index.ts | 2 ++ 10 files changed, 45 insertions(+), 23 deletions(-) diff --git a/packages/rnv/src/cli/index.ts b/packages/rnv/src/cli/index.ts index 78233a64cf..328f451bdc 100644 --- a/packages/rnv/src/cli/index.ts +++ b/packages/rnv/src/cli/index.ts @@ -37,7 +37,7 @@ const run = async (c: RnvConfig) => { } // Skip babel.config creation until template check // await checkAndCreateBabelConfig(c); - await initializeTask(c, taskInstance.task); + if (taskInstance?.task) await initializeTask(c, taskInstance?.task); }; export default run; diff --git a/packages/rnv/src/core/common.ts b/packages/rnv/src/core/common.ts index 680288faef..76c4bd845b 100755 --- a/packages/rnv/src/core/common.ts +++ b/packages/rnv/src/core/common.ts @@ -220,6 +220,10 @@ export const getTemplateProjectDir = (c: RnvConfig) => { logError('getTemplateProjectDir not available without specific engine'); return null; } + if (!c.runtime.engine.projectDirName) { + logError('c.runtime.engine.projectDirName missing'); + return null; + } return path.join(getTemplateDir(c), c.runtime.engine.projectDirName); }; diff --git a/packages/rnv/src/core/configManager/configBase.ts b/packages/rnv/src/core/configManager/configBase.ts index 759b383e1a..d1c5ca74dc 100644 --- a/packages/rnv/src/core/configManager/configBase.ts +++ b/packages/rnv/src/core/configManager/configBase.ts @@ -5,7 +5,9 @@ import { RnvConfig } from './types'; export const generateConfigBase = (): RnvConfig => ({ program: {}, - buildConfig: {}, + buildConfig: { + _meta: {}, + }, command: '', subCommand: '', platform: '', diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index 3aa16b313f..1896f2a3b8 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -7,10 +7,10 @@ export interface RnvConfig { command: string | null; subCommand: string | null; buildConfig: RenativeConfigFile & { - _meta: { + _meta?: { currentAppConfigId: string; }; - _refs: any; + _refs?: any; }; assetConfig: object; platform: RnvPlatform; diff --git a/packages/rnv/src/core/engineManager/index.ts b/packages/rnv/src/core/engineManager/index.ts index cae5a4c8b2..29149bf690 100644 --- a/packages/rnv/src/core/engineManager/index.ts +++ b/packages/rnv/src/core/engineManager/index.ts @@ -476,12 +476,14 @@ const _registerPlatformEngine = async (c: RnvConfig, platform: RnvPlatform | boo if (selectedEngineConfig) { const existingEngine = c.runtime.enginesById[selectedEngineConfig.id]; if (!existingEngine) { - registerEngine( - c, - require(_resolvePkgPath(c, selectedEngineConfig.packageName))?.default, - platform, - selectedEngineConfig - ); + if (selectedEngineConfig.packageName) { + registerEngine( + c, + require(_resolvePkgPath(c, selectedEngineConfig.packageName))?.default, + platform, + selectedEngineConfig + ); + } } else { _registerEnginePlatform(c, platform, existingEngine); } diff --git a/packages/rnv/src/core/engineManager/types.ts b/packages/rnv/src/core/engineManager/types.ts index e3f315f529..b2376e83a7 100644 --- a/packages/rnv/src/core/engineManager/types.ts +++ b/packages/rnv/src/core/engineManager/types.ts @@ -2,17 +2,19 @@ import { RnvConfig } from '../configManager/types'; import { RnvTaskMap } from '../taskManager/types'; export type RnvEngine = { - originalTemplatePlatformsDir: string; + originalTemplatePlatformsDir?: string; platforms: Record; config: RnvEngineConfig; tasks: RnvTaskMap; initializeRuntimeConfig: (c: RnvConfig) => void; - rootPath: string; - originalTemplatePlatformProjectDir: string; + rootPath?: string; + originalTemplatePlatformProjectDir?: string; projectDirName: string; runtimeExtraProps: any; outputDirName?: string; - serverDirName?: string; + serverDirName: string; + package: any; + ejectPlatform: any; }; export type RnvEnginePlatform = { @@ -22,11 +24,12 @@ export type RnvEnginePlatform = { }; export type RnvEngineConfig = { + title: string; id: string; platforms: any; npm: any; - plugins: any; - packageName: string; + plugins?: any; + packageName?: string; }; export type RnvEngineConfigMap = Record; diff --git a/packages/rnv/src/core/platformManager/index.ts b/packages/rnv/src/core/platformManager/index.ts index cb1931fbb0..2312813379 100644 --- a/packages/rnv/src/core/platformManager/index.ts +++ b/packages/rnv/src/core/platformManager/index.ts @@ -201,7 +201,11 @@ export const ejectPlatform = (c: RnvConfig, platform: string) => { const engine = c.runtime.enginesByPlatform[platform]; const destDir = path.join(c.paths.project.dir, 'platformTemplates', platform); const sourcePlatformDir = engine.originalTemplatePlatformsDir; - copyFolderContentsRecursiveSync(path.join(sourcePlatformDir, platform), destDir); - // DEPRECATED: only for legacy support - copyFolderContentsRecursiveSync(path.join(sourcePlatformDir, '_shared'), destDir); + if (sourcePlatformDir) { + copyFolderContentsRecursiveSync(path.join(sourcePlatformDir, platform), destDir); + // DEPRECATED: only for legacy support + copyFolderContentsRecursiveSync(path.join(sourcePlatformDir, '_shared'), destDir); + } else { + logError(`engine.originalTemplatePlatformsDir is undefined`); + } }; diff --git a/packages/rnv/src/core/schemaManager/schemaRenativeJson.ts b/packages/rnv/src/core/schemaManager/schemaRenativeJson.ts index 0d53c14f08..d775f30c7c 100644 --- a/packages/rnv/src/core/schemaManager/schemaRenativeJson.ts +++ b/packages/rnv/src/core/schemaManager/schemaRenativeJson.ts @@ -962,6 +962,8 @@ const generateBuildSchemeProps = (obj: any) => ({ type: 'object', additionalProperties: false, properties: { + ...platformCommonProps, + ...obj, enabled: { type: 'boolean', }, @@ -971,8 +973,6 @@ const generateBuildSchemeProps = (obj: any) => ({ 'Custom description of the buildScheme will be displayed directly in cli if you run rnv with an empty paramener `-s`', examples: ['This is some build scheme'], }, - ...platformCommonProps, - ...obj, }, }, type: 'object', diff --git a/packages/rnv/src/engine-core/index.ts b/packages/rnv/src/engine-core/index.ts index b7ffa8eb62..7981c05258 100644 --- a/packages/rnv/src/engine-core/index.ts +++ b/packages/rnv/src/engine-core/index.ts @@ -41,11 +41,14 @@ import taskRnvTargetList from './tasks/task.rnv.target.list'; import taskRnvTargetLaunch from './tasks/task.rnv.target.launch'; import taskRnvLink from './tasks/task.rnv.link'; import taskRnvUnlink from './tasks/task.rnv.unlink'; +import { RnvEngine } from '../core/engineManager/types'; -export default { +const engine: RnvEngine = { initializeRuntimeConfig: () => { //Do nothing }, + runtimeExtraProps: {}, + serverDirName: '', tasks: generateEngineTasks([ taskRnvCryptoDecrypt, taskRnvCryptoEncrypt, @@ -98,5 +101,7 @@ export default { package: {}, projectDirName: '', ejectPlatform: null, - platforms: null, + platforms: {}, }; + +export default engine; diff --git a/packages/rnv/src/index.ts b/packages/rnv/src/index.ts index cc3e0578a3..57a65b5da1 100755 --- a/packages/rnv/src/index.ts +++ b/packages/rnv/src/index.ts @@ -47,7 +47,9 @@ export const initializeBuilder = async (cmd: string, subCmd: string, process: an const c = ConfigManager.createRnvConfig(program, process, cmd, subCmd); Logger.logInitialize(); + //@ts-ignore global.fetch = await import('node-fetch'); + //@ts-ignore global.Headers = global.fetch.Headers; return c; From 85f7d59e28333df15fa9dbb5d52c841320f9ef85 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Fri, 1 Sep 2023 01:22:51 +0200 Subject: [PATCH 37/83] refactor object optionals, 7 togo --- .../rnv/src/core/configManager/configBase.ts | 65 ++++++++++++++----- packages/rnv/src/core/configManager/index.ts | 2 +- .../src/core/configManager/schemeParser.ts | 10 ++- packages/rnv/src/core/configManager/types.ts | 26 ++++---- packages/rnv/src/core/engineManager/index.ts | 6 +- .../rnv/src/core/platformManager/index.ts | 3 +- packages/rnv/src/core/pluginManager/index.ts | 12 ++-- packages/rnv/src/core/projectManager/index.ts | 2 +- .../src/core/sdkManager/deviceUtils/tizen.ts | 2 +- .../rnv/src/core/systemManager/resolve.ts | 1 + packages/rnv/src/core/systemManager/types.ts | 2 +- .../rnv/src/core/templateManager/index.ts | 9 ++- .../engine-core/tasks/task.rnv.app.create.ts | 56 ++++++++-------- .../rnv/src/engine-core/tasks/task.rnv.new.ts | 2 +- .../tasks/task.rnv.plugin.update.ts | 22 ++++--- 15 files changed, 135 insertions(+), 85 deletions(-) diff --git a/packages/rnv/src/core/configManager/configBase.ts b/packages/rnv/src/core/configManager/configBase.ts index d1c5ca74dc..d3b8d44b28 100644 --- a/packages/rnv/src/core/configManager/configBase.ts +++ b/packages/rnv/src/core/configManager/configBase.ts @@ -1,13 +1,36 @@ import { fsExistsSync, fsReadFileSync, fsReaddirSync, fsWriteFileSync } from '../systemManager/fileutils'; import path from 'path'; -import { RnvConfig } from './types'; +import { RnvConfig, RnvConfigFileObj, RnvConfigPathObj } from './types'; + +const generateRnvConfigPathObj = (): RnvConfigPathObj => { + return { + configs: [], + configsPrivate: [], + configsLocal: [], + appConfigsDir: '', + config: '', + configLocal: '', + configPrivate: '', + dir: '', + dirs: [], + fontsDir: '', + fontsDirs: [], + pluginDirs: [], + }; +}; + +const generateRnvConfigFileObj = (): RnvConfigFileObj => { + return { + configs: [], + configsLocal: [], + configsPrivate: [], + }; +}; export const generateConfigBase = (): RnvConfig => ({ program: {}, - buildConfig: { - _meta: {}, - }, + buildConfig: {}, command: '', subCommand: '', platform: '', @@ -31,8 +54,12 @@ export const generateConfigBase = (): RnvConfig => ({ paths: { GLOBAL_RNV_CONFIG: '', rnv: { + configWorkspaces: {}, + dir: '', + package: '', pluginTemplates: { configs: {}, + dirs: {}, }, platformTemplates: {}, projectTemplates: {}, @@ -42,7 +69,9 @@ export const generateConfigBase = (): RnvConfig => ({ projectTemplate: {}, }, workspace: { + ...generateRnvConfigPathObj(), project: { + ...generateRnvConfigPathObj(), appConfigBase: {}, builds: {}, assets: {}, @@ -51,12 +80,11 @@ export const generateConfigBase = (): RnvConfig => ({ appConfigsDirNames: [], }, appConfig: { - configs: [], - configsPrivate: [], - configsLocal: [], + ...generateRnvConfigPathObj(), }, }, defaultWorkspace: { + ...generateRnvConfigPathObj(), project: { appConfigBase: {}, builds: {}, @@ -72,6 +100,7 @@ export const generateConfigBase = (): RnvConfig => ({ }, }, project: { + ...generateRnvConfigPathObj(), config: '', appConfigBase: {}, builds: {}, @@ -81,17 +110,19 @@ export const generateConfigBase = (): RnvConfig => ({ appConfigsDirNames: [], }, appConfig: { - configs: [], - configsPrivate: [], - configsLocal: [], + ...generateRnvConfigPathObj(), }, // EXTRA GLOBAL_RNV_DIR: '', buildHooks: { dist: {}, + dir: '', + index: '', }, home: {}, template: { + ...generateRnvConfigPathObj(), + configTemplate: '', appConfigBase: {}, builds: {}, assets: {}, @@ -109,20 +140,23 @@ export const generateConfigBase = (): RnvConfig => ({ projectTemplate: {}, }, workspace: { + ...generateRnvConfigFileObj(), project: { + ...generateRnvConfigFileObj(), + configs: [], appConfigBase: {}, builds: {}, assets: {}, platformTemplates: {}, }, appConfig: { - configs: [], - configsPrivate: [], - configsLocal: [], + ...generateRnvConfigFileObj(), }, }, defaultWorkspace: { + ...generateRnvConfigPathObj(), project: { + ...generateRnvConfigPathObj(), appConfigBase: {}, builds: {}, assets: {}, @@ -135,15 +169,14 @@ export const generateConfigBase = (): RnvConfig => ({ }, }, project: { + ...generateRnvConfigFileObj(), appConfigBase: {}, builds: {}, assets: {}, platformTemplates: {}, }, appConfig: { - configs: [], - configsPrivate: [], - configsLocal: [], + ...generateRnvConfigFileObj(), }, }, }); diff --git a/packages/rnv/src/core/configManager/index.ts b/packages/rnv/src/core/configManager/index.ts index 0f22e3f17e..27037b3b44 100644 --- a/packages/rnv/src/core/configManager/index.ts +++ b/packages/rnv/src/core/configManager/index.ts @@ -436,7 +436,7 @@ const _generatePlatformTemplatePaths = (c: RnvConfig) => { const result: Record = {}; if (c.buildConfig.defaults) { - c.buildConfig.defaults.supportedPlatforms.forEach((platform: string) => { + c.buildConfig.defaults?.supportedPlatforms?.forEach((platform: string) => { const engine = c.runtime.enginesByPlatform[platform]; if (engine) { const originalPath = engine.originalTemplatePlatformsDir; diff --git a/packages/rnv/src/core/configManager/schemeParser.ts b/packages/rnv/src/core/configManager/schemeParser.ts index 535d9273d5..b287eaa977 100644 --- a/packages/rnv/src/core/configManager/schemeParser.ts +++ b/packages/rnv/src/core/configManager/schemeParser.ts @@ -8,17 +8,21 @@ export const isBuildSchemeSupported = async (c: RnvConfig) => { const { scheme } = c.program; - if (!c.buildConfig.platforms[c.platform]) { - c.buildConfig.platforms[c.platform] = { + const platforms = c.buildConfig.platforms || {}; + + if (!platforms[c.platform]) { + platforms[c.platform] = { buildSchemes: {}, }; } const baseBuildSchemes = c.buildConfig.common?.buildSchemes || {}; - const platformBuildSchemes = c.buildConfig.platforms[c.platform]?.buildSchemes || {}; + const platformBuildSchemes = platforms[c.platform]?.buildSchemes || {}; const buildSchemes = merge(baseBuildSchemes, platformBuildSchemes); + c.buildConfig.platforms = platforms; + if (!buildSchemes) { logWarning(`Your appConfig for platform ${c.platform} has no buildSchemes. Will continue with defaults`); return false; diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index 1896f2a3b8..3d98da37c4 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -6,7 +6,7 @@ export interface RnvConfig { program: any; command: string | null; subCommand: string | null; - buildConfig: RenativeConfigFile & { + buildConfig: Partial & { _meta?: { currentAppConfigId: string; }; @@ -251,16 +251,16 @@ export interface RnvConfigFileObj { } export type RenativeConfigFile = { - sdks: Record; + sdks?: Record; workspaceID: string; common: { - buildSchemes: Record; - runtime: Record; + buildSchemes?: Record; + runtime?: Record; }; defaults: { - ports: Record; - supportedPlatforms: Array; - portOffset: number; + ports?: Record; + supportedPlatforms?: Array; + portOffset?: number; }; platforms: Record< string, @@ -281,8 +281,8 @@ export type RenativeConfigFile = { } >; plugins: Record; - currentTemplate: string; - projectTemplates: object; + currentTemplate?: string; + projectTemplates?: object; platformTemplatesDirs: Record; paths: { appConfigsDirs: Array; @@ -293,12 +293,12 @@ export type RenativeConfigFile = { tasks: Array | Record; engineTemplates: Record; engines: Record; - pluginTemplates: Record; + pluginTemplates?: Record; runtime: Record; defaultTargets: Record; - templateConfig: any; - enableAnalytics: boolean; - workspaceAppConfigsDir: string; + templateConfig?: any; + enableAnalytics?: boolean; + workspaceAppConfigsDir?: string; }; export type RenativeConfigPlugin = { diff --git a/packages/rnv/src/core/engineManager/index.ts b/packages/rnv/src/core/engineManager/index.ts index 29149bf690..9c3075a58b 100644 --- a/packages/rnv/src/core/engineManager/index.ts +++ b/packages/rnv/src/core/engineManager/index.ts @@ -127,7 +127,7 @@ export const registerMissingPlatformEngines = async (c: RnvConfig, taskInstance? c.program.platform === 'all' ) { const registerEngineList: Array> = []; - c.buildConfig.defaults.supportedPlatforms.forEach((platform) => { + c.buildConfig.defaults?.supportedPlatforms?.forEach((platform) => { registerEngineList.push(_registerPlatformEngine(c, platform)); }); @@ -214,7 +214,7 @@ export const loadEnginePackageDeps = async (c: RnvConfig, engineConfigs: Array { const engineConfig = readObjectSync(ecf.configPath); - c.buildConfig.defaults.supportedPlatforms.forEach((platform) => { + c.buildConfig.defaults?.supportedPlatforms?.forEach((platform) => { const npm = engineConfig?.platforms?.[platform]?.npm; if (npm) { if (npm.devDependencies) { @@ -405,7 +405,7 @@ ${enginesToInstall.map((v) => `> ${v.key}@${v.version}`).join('\n')} const _getMergedEngineConfigs = (c: RnvConfig) => { const engines = c.buildConfig?.engines; - const engineTemplates = c.buildConfig?.engineTemplates; + const engineTemplates = c.buildConfig?.engineTemplates || {}; const mergedEngineConfigs: RnvEngineConfigMap = {}; Object.keys(engineTemplates).forEach((packageName) => { mergedEngineConfigs[packageName] = { diff --git a/packages/rnv/src/core/platformManager/index.ts b/packages/rnv/src/core/platformManager/index.ts index 2312813379..31947ae006 100644 --- a/packages/rnv/src/core/platformManager/index.ts +++ b/packages/rnv/src/core/platformManager/index.ts @@ -42,7 +42,7 @@ export const cleanPlatformBuild = (c: RnvConfig, platform: string) => const cleanTasks = []; - if (platform === 'all') { + if (platform === 'all' && c.buildConfig.platforms) { Object.keys(c.buildConfig.platforms).forEach((k) => { if (isPlatformSupportedSync(c, k)) { const pPath = path.join(c.paths.project.builds.dir, `${c.runtime.appId}_${k}`); @@ -122,6 +122,7 @@ export const isPlatformSupported = async (c: RnvConfig, isGlobalScope = false) = if (confirm) { const newPlatforms = [...configuredPlatforms, c.platform]; updateProjectPlatforms(c, newPlatforms); + c.buildConfig.defaults = c.buildConfig.defaults || {}; c.buildConfig.defaults.supportedPlatforms = newPlatforms; // await configureEntryPoints(c); } else { diff --git a/packages/rnv/src/core/pluginManager/index.ts b/packages/rnv/src/core/pluginManager/index.ts index 91c93e1c7d..413a83c7fa 100644 --- a/packages/rnv/src/core/pluginManager/index.ts +++ b/packages/rnv/src/core/pluginManager/index.ts @@ -379,7 +379,7 @@ const _resolvePluginDependencies = async ( const { scope } = _getPluginScope(keyScope); if (!plugin) { - const depPlugin = pluginTemplates[scope]?.pluginTemplates?.[key]; + const depPlugin = pluginTemplates?.[scope]?.pluginTemplates?.[key]; if (depPlugin) { // console.log('INSTALL PLUGIN???', key, depPlugin.source); const { confirm } = await inquirerPrompt({ @@ -763,6 +763,10 @@ const _getPluginConfiguration = (c: RnvConfig, pluginName: string) => { export const checkForPluginDependencies = async (c: RnvConfig) => { const toAdd: Record = {}; + if (!c.buildConfig.plugins) return; + + const bcPlugins = c.buildConfig.plugins; + Object.keys(c.buildConfig.plugins).forEach((pluginName) => { const renativePluginConfig = _getPluginConfiguration(c, pluginName); @@ -773,11 +777,11 @@ export const checkForPluginDependencies = async (c: RnvConfig) => { if (renativePluginConfig?.plugins) { // we have dependencies for this plugin Object.keys(renativePluginConfig.plugins).forEach((p) => { - const plg = c.buildConfig.plugins[pluginName]; - if (!c.buildConfig.plugins[p] && typeof plg !== 'string' && plg.plugins?.[p] !== null) { + const plg = bcPlugins[pluginName]; + if (!bcPlugins[p] && typeof plg !== 'string' && plg.plugins?.[p] !== null) { logWarning(`Plugin ${p} is not installed yet.`); toAdd[p] = renativePluginConfig.plugins[p]; - c.buildConfig.plugins[p] = renativePluginConfig.plugins[p]; + bcPlugins[p] = renativePluginConfig.plugins[p]; } }); } diff --git a/packages/rnv/src/core/projectManager/index.ts b/packages/rnv/src/core/projectManager/index.ts index b704edde41..092ae9c125 100644 --- a/packages/rnv/src/core/projectManager/index.ts +++ b/packages/rnv/src/core/projectManager/index.ts @@ -55,7 +55,7 @@ export const checkAndBootstrapIfRequired = async (c: RnvConfig) => { const templateObj = readObjectSync(c.paths.template.configTemplate); const appConfigPath = path.join(c.paths.project.appConfigsDir, c.program.appConfigID, 'renative.json'); const appConfigObj: RenativeConfigFile = readObjectSync(appConfigPath); - const supportedPlatforms = appConfigObj?.defaults?.supportedPlatforms; + const supportedPlatforms = appConfigObj?.defaults?.supportedPlatforms || []; const engineTemplates = c.files.rnv.projectTemplates?.config?.engineTemplates; const rnvPlatforms = c.files.rnv.projectTemplates?.config?.platforms; const activeEngineKeys: Array = []; diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts index ee4cc89100..08a8c14a35 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts @@ -217,7 +217,7 @@ export const runTizenSimOrDevice = async (c: RnvConfig, buildCoreWebpackProject: const { target, engine } = c.runtime; const { platform } = c; - const platformConfig = c.buildConfig.platforms[platform]; + const platformConfig = c.buildConfig.platforms?.[platform]; const bundleAssets = getConfigProp(c, platform, 'bundleAssets'); const isHosted = hosted ?? !bundleAssets; const isLightningEngine = engine?.config.id === 'engine-lightning'; diff --git a/packages/rnv/src/core/systemManager/resolve.ts b/packages/rnv/src/core/systemManager/resolve.ts index 3e433e9f4f..317bad343b 100644 --- a/packages/rnv/src/core/systemManager/resolve.ts +++ b/packages/rnv/src/core/systemManager/resolve.ts @@ -19,6 +19,7 @@ import { DoResolveFn, ResolveOptions } from './types'; * @param {*} options - docs - https://tinyurl.com/r9sfpf7 && {keepSuffix: boolean} */ export const doResolve: DoResolveFn = (aPath, mandatory = true, options = {}) => { + if (!aPath) return undefined; options.basedir = options.basedir ?? process.cwd(); try { if (aPath.startsWith('file:')) { diff --git a/packages/rnv/src/core/systemManager/types.ts b/packages/rnv/src/core/systemManager/types.ts index e30d51f326..a227c206e3 100644 --- a/packages/rnv/src/core/systemManager/types.ts +++ b/packages/rnv/src/core/systemManager/types.ts @@ -60,4 +60,4 @@ export type FileUtilsUpdateConfig = { webosSdk?: string; }; -export type DoResolveFn = (aPath: string, mandatory?: boolean, options?: ResolveOptions) => string | undefined; +export type DoResolveFn = (aPath?: string, mandatory?: boolean, options?: ResolveOptions) => string | undefined; diff --git a/packages/rnv/src/core/templateManager/index.ts b/packages/rnv/src/core/templateManager/index.ts index a953eeb7e6..dde56677b7 100644 --- a/packages/rnv/src/core/templateManager/index.ts +++ b/packages/rnv/src/core/templateManager/index.ts @@ -21,7 +21,6 @@ import { listAppConfigsFoldersSync, generateBuildConfig, loadFileExtended } from import { doResolve } from '../systemManager/resolve'; import { checkIfProjectAndNodeModulesExists } from '../systemManager/npmUtils'; import { RnvConfig } from '../configManager/types'; -import { RnvError } from '../types'; import { PromptOptions } from '../../cli/types'; export const checkIfTemplateConfigured = async (c: RnvConfig) => { @@ -36,7 +35,7 @@ export const checkIfTemplateConfigured = async (c: RnvConfig) => { return false; } Object.keys(c.buildConfig.templates).forEach((k) => { - const obj = c.buildConfig.templates[k]; + const obj = c.buildConfig.templates?.[k] || { version: 'unknown template version' }; if (!doResolve(k, false, { basedir: '../' }) && !doResolve(k, false)) { logInfo( `Your ${chalk().white(`${k}@${obj.version}`)} template is missing in renative.json. CONFIGURING...DONE` @@ -66,13 +65,13 @@ const _cleanProjectTemplateSync = (c: RnvConfig) => { path.join(c.paths.project.appConfigsDir), ]; - const filesToRemove = c.buildConfig.defaults.supportedPlatforms.map((p) => + const filesToRemove = c.buildConfig.defaults?.supportedPlatforms?.map((p) => path.join(c.paths.project.dir, `index.${p}.js`) ); removeDirsSync(dirsToRemove); // TODO: NOT SERVED FROM TEMPLATE YET - removeFilesSync(filesToRemove); + if (filesToRemove) removeFilesSync(filesToRemove); }; const _applyTemplate = async (c: RnvConfig) => { @@ -190,7 +189,7 @@ const _configureAppConfigs = async (c: RnvConfig) => { } } }); - } catch (e: RnvError) { + } catch (e: any) { logError(e); } } diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.app.create.ts b/packages/rnv/src/engine-core/tasks/task.rnv.app.create.ts index a10d5f34e6..bbdd45e149 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.app.create.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.app.create.ts @@ -28,18 +28,20 @@ export const taskRnvAppCreate: RnvTaskFn = async (c) => { sourcePath = sourceAppConfigDirPath; } } else if (c.program.ci) { - const tacPath = doResolve(c.buildConfig.currentTemplate); - if (tacPath && fsExistsSync(tacPath)) { - const tacDirsPath = path.join(tacPath, 'appConfigs'); - const tacDirs = fsReaddirSync(tacDirsPath); - tacDirs.forEach((v) => { - if (v !== 'base') { - const pth = path.join(tacDirsPath, v); - if (fsLstatSync(pth).isDirectory()) { - sourcePath = pth; + if (c.buildConfig.currentTemplate) { + const tacPath = doResolve(c.buildConfig.currentTemplate); + if (tacPath && fsExistsSync(tacPath)) { + const tacDirsPath = path.join(tacPath, 'appConfigs'); + const tacDirs = fsReaddirSync(tacDirsPath); + tacDirs.forEach((v) => { + if (v !== 'base') { + const pth = path.join(tacDirsPath, v); + if (fsLstatSync(pth).isDirectory()) { + sourcePath = pth; + } } - } - }); + }); + } } } else { const appConfigChoicesObj: Record< @@ -65,22 +67,24 @@ export const taskRnvAppCreate: RnvTaskFn = async (c) => { }); // Template Configs - const tacPath = doResolve(c.buildConfig.currentTemplate); - if (tacPath && fsExistsSync(tacPath)) { - const tacDirsPath = path.join(tacPath, 'appConfigs'); - const tacDirs = fsReaddirSync(tacDirsPath); - tacDirs.forEach((v) => { - if (v !== 'base') { - const pth = path.join(tacDirsPath, v); - if (fsLstatSync(pth).isDirectory()) { - const key = `template>${v}`; - appConfigChoices.push(key); - appConfigChoicesObj[key] = { - path: pth, - }; + if (c.buildConfig.currentTemplate) { + const tacPath = doResolve(c.buildConfig.currentTemplate); + if (tacPath && fsExistsSync(tacPath)) { + const tacDirsPath = path.join(tacPath, 'appConfigs'); + const tacDirs = fsReaddirSync(tacDirsPath); + tacDirs.forEach((v) => { + if (v !== 'base') { + const pth = path.join(tacDirsPath, v); + if (fsLstatSync(pth).isDirectory()) { + const key = `template>${v}`; + appConfigChoices.push(key); + appConfigChoicesObj[key] = { + path: pth, + }; + } } - } - }); + }); + } } const { sourceAppConfig } = await inquirerPrompt({ diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.new.ts b/packages/rnv/src/engine-core/tasks/task.rnv.new.ts index 689531e84c..b98c166e44 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.new.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.new.ts @@ -639,7 +639,7 @@ export const taskRnvNew = async (c: RnvConfig) => { isMonorepo: false, }; - const { supportedPlatforms: supPlats } = config.defaults; + const supPlats = config.defaults.supportedPlatforms || []; // Remove unused platforms Object.keys(config.platforms).forEach((k) => { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.plugin.update.ts b/packages/rnv/src/engine-core/tasks/task.rnv.plugin.update.ts index 29e4e53574..54287c51bb 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.plugin.update.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.plugin.update.ts @@ -1,6 +1,6 @@ import inquirer from 'inquirer'; import { writeFileSync } from '../../core/systemManager/fileutils'; -import { logSuccess, logTask } from '../../core/systemManager/logger'; +import { logSuccess, logTask, logWarning } from '../../core/systemManager/logger'; import { getPluginList } from '../../core/pluginManager'; import { executeTask } from '../../core/taskManager'; import { TASK_PLUGIN_UPDATE, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; @@ -23,14 +23,18 @@ export const taskRnvPluginUpdate: RnvTaskFn = async (c, _parentTask, originTask) if (confirm) { const { plugins } = c.buildConfig; - Object.keys(plugins).forEach((key) => { - // c.buildConfig.plugins[key] = o.json[key]; - c.files.project.config_original.plugins[key] = pluginList.json[key]; - }); - - writeFileSync(c.paths.project.config, c.files.project.config_original); - - logSuccess('Plugins updated successfully!'); + if (plugins) { + Object.keys(plugins).forEach((key) => { + // c.buildConfig.plugins[key] = o.json[key]; + c.files.project.config_original.plugins[key] = pluginList.json[key]; + }); + + writeFileSync(c.paths.project.config, c.files.project.config_original); + + logSuccess('Plugins updated successfully!'); + } else { + logWarning(`No plugins found in renative.json`); + } } }; From aa9cdb6a6b5c2db4af9c9f1bb57644d3f16ce652 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Fri, 1 Sep 2023 01:46:24 +0200 Subject: [PATCH 38/83] ts migration part one completed --- packages/rnv/src/core/common.ts | 6 ++-- .../rnv/src/core/configManager/configBase.ts | 31 ++++++++++++++----- packages/rnv/src/core/configManager/index.ts | 10 +++--- packages/rnv/src/core/configManager/types.ts | 8 ++--- packages/rnv/src/core/projectManager/index.ts | 2 +- .../rnv/src/core/systemManager/fileutils.ts | 9 ++++-- .../rnv/src/core/systemManager/npmUtils.ts | 7 ++--- .../rnv/src/core/templateManager/index.ts | 8 ++--- 8 files changed, 48 insertions(+), 33 deletions(-) diff --git a/packages/rnv/src/core/common.ts b/packages/rnv/src/core/common.ts index 76c4bd845b..1b9edd49b8 100755 --- a/packages/rnv/src/core/common.ts +++ b/packages/rnv/src/core/common.ts @@ -276,7 +276,7 @@ export const _getConfigProp = ( platform: string, key: string, defaultVal?: any, - sourceObj?: RenativeConfigFile + sourceObj?: Partial ) => { if (!sourceObj) return null; @@ -294,14 +294,14 @@ export const _getConfigProp = ( let scheme: RenativeConfigBuildScheme; if (p) { scheme = p.buildSchemes?.[ps] || {}; - resultPlatforms = getFlavouredProp(c, sourceObj.platforms[platform], baseKey); + resultPlatforms = getFlavouredProp(c, sourceObj.platforms?.[platform] || {}, baseKey); } else { scheme = {}; } const resultCli = baseKey && CLI_PROPS.includes(baseKey) ? c.program[baseKey] : undefined; const resultScheme = baseKey && scheme[baseKey]; - const resultCommonRoot = getFlavouredProp(c, sourceObj.common, baseKey); + const resultCommonRoot = getFlavouredProp(c, sourceObj.common || {}, baseKey); const resultCommonScheme = getFlavouredProp(c, sourceObj.common?.buildSchemes?.[c.runtime.scheme] || {}, baseKey); const resultCommon = resultCommonScheme || resultCommonRoot; diff --git a/packages/rnv/src/core/configManager/configBase.ts b/packages/rnv/src/core/configManager/configBase.ts index d3b8d44b28..2797403311 100644 --- a/packages/rnv/src/core/configManager/configBase.ts +++ b/packages/rnv/src/core/configManager/configBase.ts @@ -3,7 +3,7 @@ import { fsExistsSync, fsReadFileSync, fsReaddirSync, fsWriteFileSync } from '.. import path from 'path'; import { RnvConfig, RnvConfigFileObj, RnvConfigPathObj } from './types'; -const generateRnvConfigPathObj = (): RnvConfigPathObj => { +export const generateRnvConfigPathObj = (): RnvConfigPathObj => { return { configs: [], configsPrivate: [], @@ -20,7 +20,7 @@ const generateRnvConfigPathObj = (): RnvConfigPathObj => { }; }; -const generateRnvConfigFileObj = (): RnvConfigFileObj => { +export const generateRnvConfigFileObj = (): RnvConfigFileObj => { return { configs: [], configsLocal: [], @@ -28,7 +28,21 @@ const generateRnvConfigFileObj = (): RnvConfigFileObj => { }; }; +const runtime: any = { + enginesByPlatform: {}, + enginesByIndex: [], + enginesById: {}, +}; + export const generateConfigBase = (): RnvConfig => ({ + assetConfig: {}, + rnvVersion: '', + buildHooks: {}, + buildPipes: {}, + isBuildHooksReady: false, + runtimePropsInjects: [], + supportedPlatforms: [], + systemPropsInjects: [], program: {}, buildConfig: {}, command: '', @@ -46,12 +60,9 @@ export const generateConfigBase = (): RnvConfig => ({ path, }, configPropsInjects: {}, - runtime: { - enginesByPlatform: {}, - enginesByIndex: [], - enginesById: {}, - }, + runtime, paths: { + appConfigBase: '', GLOBAL_RNV_CONFIG: '', rnv: { configWorkspaces: {}, @@ -108,6 +119,9 @@ export const generateConfigBase = (): RnvConfig => ({ platformTemplates: {}, appConfigsDirs: [], appConfigsDirNames: [], + dir: '', + platformTemplatesDirs: {}, + nodeModulesDir: '', }, appConfig: { ...generateRnvConfigPathObj(), @@ -138,6 +152,8 @@ export const generateConfigBase = (): RnvConfig => ({ plugins: {}, engines: {}, projectTemplate: {}, + configWorkspaces: {}, + package: {}, }, workspace: { ...generateRnvConfigFileObj(), @@ -174,6 +190,7 @@ export const generateConfigBase = (): RnvConfig => ({ builds: {}, assets: {}, platformTemplates: {}, + package: {}, }, appConfig: { ...generateRnvConfigFileObj(), diff --git a/packages/rnv/src/core/configManager/index.ts b/packages/rnv/src/core/configManager/index.ts index 27037b3b44..aebfde9062 100644 --- a/packages/rnv/src/core/configManager/index.ts +++ b/packages/rnv/src/core/configManager/index.ts @@ -36,7 +36,7 @@ import { getWorkspaceDirPath } from '../projectManager/workspace'; import { chalk, logError, logTask, logWarning, logDebug } from '../systemManager/logger'; import { doResolve } from '../systemManager/resolve'; import { RnvConfigFileObj, RnvConfigPathObj, RnvConfig, RnvFileKey } from './types'; -import { generateConfigBase } from './configBase'; +import { generateConfigBase, generateRnvConfigPathObj } from './configBase'; // import { loadPluginTemplates } from '../pluginManager'; const IGNORE_FOLDERS = ['.git']; @@ -89,7 +89,7 @@ const getEnginesPluginDelta = (c: RnvConfig) => { return enginePlugins; }; -export const writeRenativeConfigFile = (c: RnvConfig, configPath: string, configData: string | object) => { +export const writeRenativeConfigFile = (c: RnvConfig, configPath: string | undefined, configData: string | object) => { logDebug(`writeRenativeConfigFile:${configPath}`); writeFileSync(configPath, configData); generateBuildConfig(c); @@ -310,10 +310,9 @@ const _loadConfigFiles = ( // PATH1: appConfigs/base const path1 = path.join(pathObj.appConfigsDir, 'base'); + const pathObj1: RnvConfigPathObj = { - configs: [], - configsLocal: [], - configsPrivate: [], + ...generateRnvConfigPathObj(), config: path.join(path1, RENATIVE_CONFIG_NAME), configLocal: path.join(path1, RENATIVE_CONFIG_LOCAL_NAME), configPrivate: path.join(path1, RENATIVE_CONFIG_PRIVATE_NAME), @@ -337,6 +336,7 @@ const _loadConfigFiles = ( if (parseAppConfigs && extendAppId && appConfigsDirNames.includes(extendAppId)) { const path2 = path.join(pathObj.appConfigsDir, extendAppId); const pathObj2: RnvConfigPathObj = { + ...generateRnvConfigPathObj(), config: path.join(path2, RENATIVE_CONFIG_NAME), configLocal: path.join(path2, RENATIVE_CONFIG_LOCAL_NAME), configPrivate: path.join(path2, RENATIVE_CONFIG_PRIVATE_NAME), diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index 3d98da37c4..0cd7f642cd 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -142,10 +142,10 @@ export interface RnvConfig { //ADDON dir: string; nodeModulesDir: string; - srcDir: string; - package: string; - rnCliConfig: string; - babelConfig: string; + srcDir?: string; + package?: string; + rnCliConfig?: string; + babelConfig?: string; platformTemplatesDirs: Record; }; appConfig: RnvConfigPathObj; diff --git a/packages/rnv/src/core/projectManager/index.ts b/packages/rnv/src/core/projectManager/index.ts index 092ae9c125..b21d21a194 100644 --- a/packages/rnv/src/core/projectManager/index.ts +++ b/packages/rnv/src/core/projectManager/index.ts @@ -704,7 +704,7 @@ export const upgradeProjectDependencies = (c: RnvConfig, version: string) => { export const upgradeDependencies = ( packageFile: NpmPackageFile, - packagesPath: string, + packagesPath: string | undefined, configFile: RenativeConfigFile | null, configPath: string | null, version: string diff --git a/packages/rnv/src/core/systemManager/fileutils.ts b/packages/rnv/src/core/systemManager/fileutils.ts index fe31e76377..4c8154c73f 100755 --- a/packages/rnv/src/core/systemManager/fileutils.ts +++ b/packages/rnv/src/core/systemManager/fileutils.ts @@ -26,10 +26,11 @@ export const configureFilesystem = ( global.isSystemWin = _isSystemWin; }; -export const fsWriteFileSync = (dest: string, data: string, options?: fs.WriteFileOptions) => { +export const fsWriteFileSync = (dest: string | undefined, data: string, options?: fs.WriteFileOptions) => { // if (dest && dest.includes('renative.json')) { // console.log('FS_WRITE', dest, data.length); // } + if (!dest) return; fs.writeFileSync(dest, data, options); }; @@ -82,10 +83,11 @@ const _getSanitizedPath = (origPath: string, timestampPathsConfig?: TimestampPat export const copyFileSync = ( source: string, - target: string, + target: string | undefined, skipOverride?: boolean, timestampPathsConfig?: TimestampPathsConfig ) => { + if (!target) return; logDebug('copyFileSync', source); let targetFile = target; // if target is a directory a new file with the same name will be created @@ -462,7 +464,8 @@ export const removeDirSync = (_dir: string, _rmSelf?: boolean) => { } }; -export const writeFileSync = (filePath: string, obj: string | object, spaces = 4, addNewLine = true) => { +export const writeFileSync = (filePath: string | undefined, obj: string | object, spaces = 4, addNewLine = true) => { + if (!filePath) return; logDebug('writeFileSync', filePath); if (filePath.includes('?') || filePath.includes('undefined')) return; let output; diff --git a/packages/rnv/src/core/systemManager/npmUtils.ts b/packages/rnv/src/core/systemManager/npmUtils.ts index aeaa69acad..66bccf8120 100644 --- a/packages/rnv/src/core/systemManager/npmUtils.ts +++ b/packages/rnv/src/core/systemManager/npmUtils.ts @@ -18,7 +18,6 @@ import { doResolve } from './resolve'; import { inquirerPrompt } from '../../cli/prompt'; import { getConfigProp } from '../common'; import { RnvConfig } from '../configManager/types'; -import { RnvError } from '../types'; const packageJsonIsValid = (c: RnvConfig) => { if (!fsExistsSync(c.paths.project.package)) return false; @@ -233,7 +232,7 @@ export const installPackageDependencies = async (c: RnvConfig, failOnError = fal try { await executeAsync(command); await invalidatePodsChecksum(c); - } catch (e: RnvError) { + } catch (e: any) { if (failOnError) { logError(e); throw e; @@ -244,7 +243,7 @@ export const installPackageDependencies = async (c: RnvConfig, failOnError = fal try { await cleanNodeModules(); await installPackageDependencies(c, true); - } catch (npmErr: RnvError) { + } catch (npmErr: any) { logError(npmErr); throw npmErr; } @@ -269,7 +268,7 @@ export const installPackageDependencies = async (c: RnvConfig, failOnError = fal } c._requiresNpmInstall = false; return true; - } catch (jetErr: RnvError) { + } catch (jetErr: any) { logError(jetErr); return false; } diff --git a/packages/rnv/src/core/templateManager/index.ts b/packages/rnv/src/core/templateManager/index.ts index dde56677b7..c737224842 100644 --- a/packages/rnv/src/core/templateManager/index.ts +++ b/packages/rnv/src/core/templateManager/index.ts @@ -59,11 +59,7 @@ export const checkIfTemplateConfigured = async (c: RnvConfig) => { const _cleanProjectTemplateSync = (c: RnvConfig) => { logTask('_cleanProjectTemplateSync'); - const dirsToRemove = [ - path.join(c.paths.project.appConfigBase.dir), - path.join(c.paths.project.srcDir), - path.join(c.paths.project.appConfigsDir), - ]; + const dirsToRemove = [c.paths.project.appConfigBase.dir, c.paths.project.srcDir, c.paths.project.appConfigsDir]; const filesToRemove = c.buildConfig.defaults?.supportedPlatforms?.map((p) => path.join(c.paths.project.dir, `index.${p}.js`) @@ -306,7 +302,7 @@ export const configureEntryPoint = async (c: RnvConfig, platform: string) => { return true; }; -const _writeObjectSync = (c: RnvConfig, p: string, s: string) => { +const _writeObjectSync = (c: RnvConfig, p: string | undefined, s: string) => { writeFileSync(p, s); generateBuildConfig(c); }; From e9db00b944a18efdedd75d859234aa0dd021574e Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Fri, 1 Sep 2023 03:01:59 +0200 Subject: [PATCH 39/83] post refactor fixes, add default rnv scope to plugin --- packages/rnv/src/core/pluginManager/index.ts | 5 +++-- packages/rnv/src/core/sdkManager/deviceUtils/android.ts | 3 +-- packages/rnv/src/core/sdkManager/installer.ts | 3 +-- packages/rnv/src/core/systemManager/exec.ts | 2 +- packages/template-starter/package.json | 8 ++++++-- packages/template-starter/renative.json | 4 +++- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/rnv/src/core/pluginManager/index.ts b/packages/rnv/src/core/pluginManager/index.ts index 413a83c7fa..b4c2f1d5f1 100644 --- a/packages/rnv/src/core/pluginManager/index.ts +++ b/packages/rnv/src/core/pluginManager/index.ts @@ -119,7 +119,7 @@ export const getMergedPlugin = (c: RnvConfig, key: string) => { const plugin = c.buildConfig.plugins?.[key]; if (!plugin) return null; - const scopes: Array = []; + const scopes: Array = ['rnv']; const mergedPlugin = _getMergedPlugin(c, plugin, key, undefined, scopes); scopes.reverse(); // if (!mergedPlugin.version) { @@ -161,6 +161,7 @@ const _getMergedPlugin = ( logWarning(`Plugin ${pluginKey} is not recognized plugin in ${scope} scope`); } else if (scope && parentScope) { const skipRnvOverrides = c.buildConfig.pluginTemplates?.[parentScope]?.disableRnvDefaultOverrides; + if (skipRnvOverrides && scope === 'rnv') { // Merges down to RNV defaults will be skipped } else if (scopes) { @@ -486,7 +487,7 @@ export const loadPluginTemplates = async (c: RnvConfig) => { //This comes from project dependency let flexnPluginsPath = doResolve('@flexn/plugins'); - if (flexnPluginsPath && !fsExistsSync(flexnPluginsPath)) { + if (!fsExistsSync(flexnPluginsPath)) { //This comes from rnv built-in dependency (installed via npm) flexnPluginsPath = path.resolve(__dirname, '../../../node_modules/@flexn/plugins'); if (!fsExistsSync(flexnPluginsPath)) { diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/android.ts b/packages/rnv/src/core/sdkManager/deviceUtils/android.ts index 965ff6e88d..ec41046610 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/android.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/android.ts @@ -30,7 +30,6 @@ import { } from '../../constants'; import { RnvConfig } from '../../configManager/types'; import { AndroidDevice } from '../types'; -import { RnvError } from '../../types'; const CHECK_INTEVAL = 5000; @@ -451,7 +450,7 @@ const _parseDevicesResult = async (c: RnvConfig, devicesString: string, avdsStri try { avdDetails = getAvdDetails(c, line); - } catch (e: RnvError) { + } catch (e: any) { logError(e); } diff --git a/packages/rnv/src/core/sdkManager/installer.ts b/packages/rnv/src/core/sdkManager/installer.ts index d72b4c51dc..170460693d 100644 --- a/packages/rnv/src/core/sdkManager/installer.ts +++ b/packages/rnv/src/core/sdkManager/installer.ts @@ -36,7 +36,6 @@ import { chalk, logTask, logWarning, logSuccess, logError, logInfo } from '../sy import PlatformSetup from '../setupManager'; import { generateBuildConfig } from '../configManager'; import { RnvConfig } from '../configManager/types'; -import { RnvError } from '../types'; const SDK_LOCATIONS: Record> = { android: [ @@ -250,7 +249,7 @@ const _attemptAutoFix = async (c: RnvConfig, sdkPlatform: string, sdkKey: string writeFileSync(c.paths.workspace.config, c.files.workspace.config); generateBuildConfig(c); await checkAndConfigureSdks(c); - } catch (e: RnvError) { + } catch (e: any) { logError(e); } diff --git a/packages/rnv/src/core/systemManager/exec.ts b/packages/rnv/src/core/systemManager/exec.ts index 8f45469018..d2aed5473a 100755 --- a/packages/rnv/src/core/systemManager/exec.ts +++ b/packages/rnv/src/core/systemManager/exec.ts @@ -225,7 +225,7 @@ const executeAsync = async ( // swap values if c is not specified and get it from it's rightful place, config :) let c: RnvConfig; let cmd = ''; - let opts: ExecOptions = {}; + let opts: ExecOptions = _opts || {}; if (typeof _c === 'string') { cmd = _c; c = Config.getConfig(); diff --git a/packages/template-starter/package.json b/packages/template-starter/package.json index 6375af26fd..a781501c42 100644 --- a/packages/template-starter/package.json +++ b/packages/template-starter/package.json @@ -100,7 +100,10 @@ "react-dom": "18.2.0", "react-native": "0.67.2", "react-native-gesture-handler": "2.9.0", - "rnv": "0.37.3" + "rnv": "0.37.3", + "xcode": "2.1.0", + "@react-native-community/cli-platform-ios": "^6.0.0", + "@react-native-community/cli": "^6.0.0" }, "private": false, "publishConfig": { @@ -117,5 +120,6 @@ "last 1 firefox version", "last 1 safari version" ] - } + }, + "dependencies": {} } diff --git a/packages/template-starter/renative.json b/packages/template-starter/renative.json index 5c79bcf193..0976fc7d42 100644 --- a/packages/template-starter/renative.json +++ b/packages/template-starter/renative.json @@ -194,7 +194,9 @@ "react-art": "source:rnv", "react-dom": "source:rnv", "react-native": "source:rnv", - "react-native-gesture-handler": "source:rnv" + "react-native-gesture-handler": "source:rnv", + "@react-native-community/cli-platform-ios": "source:rnv", + "@react-native-community/cli": "source:rnv" }, "permissions": { "ios": {}, From fa32df4f24715fa94625c48b0d77ff5c7e49a2da Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Sun, 3 Sep 2023 01:27:38 +0200 Subject: [PATCH 40/83] fix UTs --- packages/rnv/src/__tests__/cli.test.ts | 37 +-- packages/rnv/src/__tests__/common.test.ts | 269 ++++++++++++------ packages/rnv/src/__tests__/exec.test.ts | 42 +-- packages/rnv/src/__tests__/fileutils.test.ts | 30 +- packages/rnv/src/__tests__/startup.test.ts | 38 +-- packages/rnv/src/__tests__/tasks.test.ts | 70 ++--- packages/rnv/src/core/configManager/types.ts | 1 + packages/rnv/src/core/engineManager/index.ts | 1 + .../core/systemManager/__mocks__/logger.ts | 62 ++++ packages/rnv/src/core/systemManager/chalk.ts | 21 ++ packages/rnv/src/core/systemManager/exec.ts | 48 ++-- packages/rnv/src/core/systemManager/logger.ts | 27 +- packages/rnv/src/core/systemManager/types.ts | 15 + .../src/engine-core/tasks/task.rnv.clean.ts | 2 +- 14 files changed, 357 insertions(+), 306 deletions(-) create mode 100644 packages/rnv/src/core/systemManager/__mocks__/logger.ts create mode 100644 packages/rnv/src/core/systemManager/chalk.ts diff --git a/packages/rnv/src/__tests__/cli.test.ts b/packages/rnv/src/__tests__/cli.test.ts index 97aec6385c..c4fb20593e 100644 --- a/packages/rnv/src/__tests__/cli.test.ts +++ b/packages/rnv/src/__tests__/cli.test.ts @@ -2,38 +2,9 @@ // import { configureFilesystem } from '../../src/core/systemManager/fileutils'; // import cli from '../../src/cli'; -jest.mock('../../src/core/systemManager/logger.js', () => { - const _chalkCols: any = { - white: (v) => v, - green: (v) => v, - red: (v) => v, - yellow: (v) => v, - default: (v) => v, - gray: (v) => v, - grey: (v) => v, - blue: (v) => v, - cyan: (v) => v, - magenta: (v) => v, - rgb: () => (v) => v, - }; - _chalkCols.bold = _chalkCols; - const _chalkMono = { - ..._chalkCols, - }; - return { - logToSummary: jest.fn(), - logTask: jest.fn(), - logDebug: jest.fn(), - logInfo: jest.fn(), - logError: jest.fn(), - logWarning: jest.fn(), - logSuccess: jest.fn(), - logInitTask: jest.fn(), - chalk: () => _chalkMono, - }; -}); - -jest.mock('../../src/core/taskManager/index.js', () => ({ +jest.mock('../../src/core/systemManager/logger.ts'); + +jest.mock('../../src/core/taskManager/index.ts', () => ({ initializeTask: jest.fn(), findSuitableTask: () => { //Do nothing @@ -41,7 +12,7 @@ jest.mock('../../src/core/taskManager/index.js', () => ({ })); const itShouldResolve = (cmd) => { - it(`${cmd} should resolve`, () => shouldResolve(cmd)); + it(`${cmd} should resolve`, () => shouldResolve()); }; // const itShouldReject = (cmd, reject) => { diff --git a/packages/rnv/src/__tests__/common.test.ts b/packages/rnv/src/__tests__/common.test.ts index be384a0ebb..fb0af787eb 100644 --- a/packages/rnv/src/__tests__/common.test.ts +++ b/packages/rnv/src/__tests__/common.test.ts @@ -1,34 +1,7 @@ import { getAppVersionCode } from '../../src/core/common'; +import { generateConfigBase } from '../core/configManager/configBase'; -jest.mock('../../src/core/systemManager/logger.js', () => { - const _chalkCols = { - white: (v) => v, - green: (v) => v, - red: (v) => v, - yellow: (v) => v, - default: (v) => v, - gray: (v) => v, - grey: (v) => v, - blue: (v) => v, - cyan: (v) => v, - magenta: (v) => v, - }; - _chalkCols.rgb = () => (v) => v; - _chalkCols.bold = _chalkCols; - const _chalkMono = { - ..._chalkCols, - }; - return { - logToSummary: jest.fn(), - logTask: jest.fn(), - logDebug: jest.fn(), - logInfo: jest.fn(), - logError: jest.fn(), - logWarning: jest.fn(), - logSuccess: jest.fn(), - chalk: () => _chalkMono, - }; -}); +jest.mock('../../src/core/systemManager/logger.ts'); // TO TEST: // 0.0.4 @@ -63,119 +36,233 @@ jest.mock('../../src/core/systemManager/logger.js', () => { // 99999999999999999999999.999999999999999999.99999999999999999 // 1.0.0-0A.is.legal -const BUILD_CONF = { - runtime: { - scheme: 'debug', - }, - buildConfig: { - common: {}, - }, -}; +const BUILD_CONF = generateConfigBase(); +BUILD_CONF.runtime.scheme = 'debug'; describe('Testing getAppVersionCode functions', () => { it('should evaluate 1.2.3', async () => { - const result = getAppVersionCode({ ...BUILD_CONF, files: { project: { package: { version: '1.2.3' } } } }); + const result = getAppVersionCode( + { + ...BUILD_CONF, + files: { + ...BUILD_CONF.files, + project: { + ...BUILD_CONF.files.project, + package: { version: '1.2.3' }, + }, + }, + }, + 'ios' + ); expect(result).toEqual('10203'); }); it('should evaluate 1.2.3 with 00.00.00.00.00', async () => { - const result = getAppVersionCode({ - ...BUILD_CONF, - buildConfig: { common: { versionCodeFormat: '00.00.00.00.00' } }, - files: { project: { package: { version: '1.2.3' } } }, - }); + const result = getAppVersionCode( + { + ...BUILD_CONF, + buildConfig: { common: { versionCodeFormat: '00.00.00.00.00' } }, + files: { + ...BUILD_CONF.files, + project: { + ...BUILD_CONF.files.project, + package: { version: '1.2.3' }, + }, + }, + }, + 'ios' + ); expect(result).toEqual('102030000'); }); it('should evaluate 2.0.0+build.1848', async () => { - const result = getAppVersionCode({ - ...BUILD_CONF, - files: { project: { package: { version: '2.0.0+build.1848' } } }, - }); + const result = getAppVersionCode( + { + ...BUILD_CONF, + files: { + ...BUILD_CONF.files, + project: { + ...BUILD_CONF.files.project, + package: { version: '2.0.0+build.1848' }, + }, + }, + }, + 'ios' + ); expect(result).toEqual('2000018'); }); it('should evaluate 2.0.0+build.1848 with 00.00.0000', async () => { - const result = getAppVersionCode({ - ...BUILD_CONF, - buildConfig: { common: { versionCodeFormat: '00.00.00.0000' } }, - files: { project: { package: { version: '2.0.0+build.1848' } } }, - }); + const result = getAppVersionCode( + { + ...BUILD_CONF, + buildConfig: { common: { versionCodeFormat: '00.00.00.0000' } }, + files: { + ...BUILD_CONF.files, + project: { + ...BUILD_CONF.files.project, + package: { version: '2.0.0+build.1848' }, + }, + }, + }, + 'ios' + ); expect(result).toEqual('200001848'); }); it('should evaluate 1.0.0-alpha+beta', async () => { - const result = getAppVersionCode({ - ...BUILD_CONF, - files: { project: { package: { version: '1.0.0-alpha+beta' } } }, - }); + const result = getAppVersionCode( + { + ...BUILD_CONF, + files: { + ...BUILD_CONF.files, + project: { + ...BUILD_CONF.files.project, + package: { version: '1.0.0-alpha+beta' }, + }, + }, + }, + 'ios' + ); expect(result).toEqual('10000'); }); it('should evaluate 999999999999.99999999999.9999999', async () => { - const result = getAppVersionCode({ - ...BUILD_CONF, - files: { project: { package: { version: '999999999999.99999999999.9999999' } } }, - }); + const result = getAppVersionCode( + { + ...BUILD_CONF, + files: { + ...BUILD_CONF.files, + project: { + ...BUILD_CONF.files.project, + package: { version: '999999999999.99999999999.9999999' }, + }, + }, + }, + 'ios' + ); expect(result).toEqual('999999'); }); it('should evaluate 2.0.1-alpha.1227', async () => { - const result = getAppVersionCode({ - ...BUILD_CONF, - files: { project: { package: { version: '2.0.1-alpha.1227' } } }, - }); + const result = getAppVersionCode( + { + ...BUILD_CONF, + files: { + ...BUILD_CONF.files, + project: { + ...BUILD_CONF.files.project, + package: { version: '2.0.1-alpha.1227' }, + }, + }, + }, + 'ios' + ); expect(result).toEqual('2000112'); }); it('should evaluate 2.0.1-alpha.1227', async () => { - const result = getAppVersionCode({ - ...BUILD_CONF, - buildConfig: { common: { versionCodeFormat: '00.00.00.0000' } }, - files: { project: { package: { version: '2.0.1-alpha.1227' } } }, - }); + const result = getAppVersionCode( + { + ...BUILD_CONF, + buildConfig: { common: { versionCodeFormat: '00.00.00.0000' } }, + files: { + ...BUILD_CONF.files, + project: { + ...BUILD_CONF.files.project, + package: { version: '2.0.1-alpha.1227' }, + }, + }, + }, + 'ios' + ); expect(result).toEqual('200011227'); }); it('should evaluate 1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay', async () => { - const result = getAppVersionCode({ - ...BUILD_CONF, - files: { project: { package: { version: '1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay' } } }, - }); + const result = getAppVersionCode( + { + ...BUILD_CONF, + files: { + ...BUILD_CONF.files, + project: { + ...BUILD_CONF.files.project, + package: { version: '1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay' }, + }, + }, + }, + 'ios' + ); expect(result).toEqual('100000101'); }); it('should evaluate 1.0.1-beta+exp.sha.5114f85', async () => { - const result = getAppVersionCode({ - ...BUILD_CONF, - files: { project: { package: { version: '1.0.1-beta+exp.sha.5114f85' } } }, - }); + const result = getAppVersionCode( + { + ...BUILD_CONF, + files: { + ...BUILD_CONF.files, + project: { + ...BUILD_CONF.files.project, + package: { version: '1.0.1-beta+exp.sha.5114f85' }, + }, + }, + }, + 'ios' + ); expect(result).toEqual('10001'); }); it('should evaluate 1.0.1-beta+exp.sha.5114f85 with 00.00.00.00.00.00', async () => { - const result = getAppVersionCode({ - ...BUILD_CONF, - buildConfig: { common: { versionCodeFormat: '00.00.00.00.00.00' } }, - files: { project: { package: { version: '1.0.1-beta+exp.sha.5114f85' } } }, - }); + const result = getAppVersionCode( + { + ...BUILD_CONF, + buildConfig: { common: { versionCodeFormat: '00.00.00.00.00.00' } }, + files: { + ...BUILD_CONF.files, + project: { + ...BUILD_CONF.files.project, + package: { version: '1.0.1-beta+exp.sha.5114f85' }, + }, + }, + }, + 'ios' + ); expect(result).toEqual('10001000000'); }); it('should evaluate 1.0.1-beta+exp.sha.5114f85 with 00.00.00.000000', async () => { - const result = getAppVersionCode({ - ...BUILD_CONF, - buildConfig: { common: { versionCodeFormat: '00.00.00.000000' } }, - files: { project: { package: { version: '1.0.1-beta+exp.sha.5114f85' } } }, - }); + const result = getAppVersionCode( + { + ...BUILD_CONF, + buildConfig: { common: { versionCodeFormat: '00.00.00.000000' } }, + files: { + ...BUILD_CONF.files, + project: { + ...BUILD_CONF.files.project, + package: { version: '1.0.1-beta+exp.sha.5114f85' }, + }, + }, + }, + 'ios' + ); expect(result).toEqual('10001000000'); }); it('should evaluate 1', async () => { - const result = getAppVersionCode({ - ...BUILD_CONF, - files: { project: { package: { version: '1' } } }, - }); + const result = getAppVersionCode( + { + ...BUILD_CONF, + files: { + ...BUILD_CONF.files, + project: { + ...BUILD_CONF.files.project, + package: { version: '1' }, + }, + }, + }, + 'ios' + ); expect(result).toEqual('10000'); }); }); diff --git a/packages/rnv/src/__tests__/exec.test.ts b/packages/rnv/src/__tests__/exec.test.ts index dae65a6206..050fc8541b 100644 --- a/packages/rnv/src/__tests__/exec.test.ts +++ b/packages/rnv/src/__tests__/exec.test.ts @@ -1,57 +1,31 @@ import { executeAsync, commandExistsSync, commandExists } from '../../src/core/systemManager/exec'; +import { generateConfigBase } from '../core/configManager/configBase'; -jest.mock('../../src/core/systemManager/logger.js', () => { - const _chalkCols = { - white: (v) => v, - green: (v) => v, - red: (v) => v, - yellow: (v) => v, - default: (v) => v, - gray: (v) => v, - grey: (v) => v, - blue: (v) => v, - cyan: (v) => v, - magenta: (v) => v, - }; - _chalkCols.rgb = () => (v) => v; - _chalkCols.bold = _chalkCols; - const _chalkMono = { - ..._chalkCols, - }; - return { - logToSummary: jest.fn(), - logTask: jest.fn(), - logDebug: jest.fn(), - logInfo: jest.fn(), - logError: jest.fn(), - logWarning: jest.fn(), - logSuccess: jest.fn(), - chalk: () => _chalkMono, - stripAnsi: (v: any) => v, - }; -}); +jest.mock('../../src/core/systemManager/logger.ts'); describe('Testing exec functions', () => { it('should execute command', async () => { expect.assertions(1); - await expect(executeAsync({ program: {} }, 'node -v').then((data) => typeof data)).resolves.toBe('string'); + await expect(executeAsync(generateConfigBase(), 'node -v').then((data) => typeof data)).resolves.toBe('string'); }); it('should execute array command', async () => { expect.assertions(1); - await expect(executeAsync({ program: {} }, ['node', '-v']).then((data) => typeof data)).resolves.toBe('string'); + await expect(executeAsync(generateConfigBase(), ['node', '-v']).then((data) => typeof data)).resolves.toBe( + 'string' + ); }); it('should execute command with privateParams', async () => { expect.assertions(1); await expect( - executeAsync({ program: {} }, 'node -v 1234', { privateParams: ['1234'] }).then((data) => typeof data) + executeAsync(generateConfigBase(), 'node -v 1234', { privateParams: ['1234'] }).then((data) => typeof data) ).resolves.toBe('string'); }); it('should execute with error', async () => { expect.assertions(1); - await expect(executeAsync({ program: {} }, 'shouldTrow')).rejects.toBeDefined(); + await expect(executeAsync(generateConfigBase(), 'shouldTrow')).rejects.toBeDefined(); }); it('should recognize command sync', () => { diff --git a/packages/rnv/src/__tests__/fileutils.test.ts b/packages/rnv/src/__tests__/fileutils.test.ts index 4d710f8162..b2a474e35b 100644 --- a/packages/rnv/src/__tests__/fileutils.test.ts +++ b/packages/rnv/src/__tests__/fileutils.test.ts @@ -1,34 +1,6 @@ import { sanitizeDynamicProps } from '../../src/core/systemManager/fileutils'; -jest.mock('../../src/core/systemManager/logger.js', () => { - const _chalkCols = { - white: (v) => v, - green: (v) => v, - red: (v) => v, - yellow: (v) => v, - default: (v) => v, - gray: (v) => v, - grey: (v) => v, - blue: (v) => v, - cyan: (v) => v, - magenta: (v) => v, - }; - _chalkCols.rgb = () => (v) => v; - _chalkCols.bold = _chalkCols; - const _chalkMono = { - ..._chalkCols, - }; - return { - logToSummary: jest.fn(), - logTask: jest.fn(), - logDebug: jest.fn(), - logInfo: jest.fn(), - logError: jest.fn(), - logWarning: jest.fn(), - logSuccess: jest.fn(), - chalk: () => _chalkMono, - }; -}); +jest.mock('../../src/core/systemManager/logger.ts'); describe('sanitizeDynamicProps', () => { it('sanitize {{props.XXX}}', async () => { diff --git a/packages/rnv/src/__tests__/startup.test.ts b/packages/rnv/src/__tests__/startup.test.ts index b273a4f970..8c270d75d8 100644 --- a/packages/rnv/src/__tests__/startup.test.ts +++ b/packages/rnv/src/__tests__/startup.test.ts @@ -1,35 +1,7 @@ import { createRnvConfig, generateBuildConfig } from '../../src/core/configManager'; import { getAppVersionCode } from '../../src/core/common'; -jest.mock('../../src/core/systemManager/logger.js', () => { - const _chalkCols = { - white: (v) => v, - green: (v) => v, - red: (v) => v, - yellow: (v) => v, - default: (v) => v, - gray: (v) => v, - grey: (v) => v, - blue: (v) => v, - cyan: (v) => v, - magenta: (v) => v, - }; - _chalkCols.rgb = () => (v) => v; - _chalkCols.bold = _chalkCols; - const _chalkMono = { - ..._chalkCols, - }; - return { - logToSummary: jest.fn(), - logTask: jest.fn(), - logDebug: jest.fn(), - logInfo: jest.fn(), - logError: jest.fn(), - logWarning: jest.fn(), - logSuccess: jest.fn(), - chalk: () => _chalkMono, - }; -}); +jest.mock('../../src/core/systemManager/logger.ts'); let c; @@ -44,17 +16,25 @@ describe('Bootstrapping the CLI', () => { const expectKeys = [ '_renativePluginCache', 'api', + 'assetConfig', 'buildConfig', + 'buildHooks', + 'buildPipes', 'cli', 'command', 'configPropsInjects', 'files', + 'isBuildHooksReady', 'paths', 'platform', 'process', 'program', + 'rnvVersion', 'runtime', + 'runtimePropsInjects', 'subCommand', + 'supportedPlatforms', + 'systemPropsInjects', ]; expect(cKeys).toEqual(expectKeys); }); diff --git a/packages/rnv/src/__tests__/tasks.test.ts b/packages/rnv/src/__tests__/tasks.test.ts index 4dd42827a9..7b67944170 100644 --- a/packages/rnv/src/__tests__/tasks.test.ts +++ b/packages/rnv/src/__tests__/tasks.test.ts @@ -14,7 +14,7 @@ jest.mock('inquirer', () => ({ prompt: () => true, })); -jest.mock('../../src/core/engineManager/index.js', () => ({ +jest.mock('../../src/core/engineManager/index.ts', () => ({ // getEngineConfigByPlatform: () => ({ // platforms: { // ios: { @@ -31,50 +31,22 @@ jest.mock('child_process', () => ({ spawn: jest.fn(), })); -jest.mock('../../src/core/taskManager/index.js', () => ({ +jest.mock('../../src/core/taskManager/index.ts', () => ({ executeTask: jest.fn(), shouldSkipTask: () => false, })); -jest.mock('../../src/core/configManager/config.js', () => ({ +jest.mock('../../src/core/configManager/config.ts', () => ({ getConfig: () => null, })); -jest.mock('../../src/core/systemManager/utils.js', () => ({ +jest.mock('../../src/core/systemManager/utils.ts', () => ({ isSystemWin: false, })); -jest.mock('../../src/core/systemManager/logger.js', () => { - const _chalkCols: any = { - white: (v) => v, - green: (v) => v, - red: (v) => v, - yellow: (v) => v, - default: (v) => v, - gray: (v) => v, - grey: (v) => v, - blue: (v) => v, - cyan: (v) => v, - magenta: (v) => v, - rgb: () => (v) => v, - }; - _chalkCols.bold = _chalkCols; - const _chalkMono = { - ..._chalkCols, - }; - return { - logToSummary: jest.fn(), - logTask: jest.fn(), - logDebug: jest.fn(), - logInfo: jest.fn(), - logError: jest.fn(), - logWarning: jest.fn(), - logSuccess: jest.fn(), - chalk: () => _chalkMono, - }; -}); +jest.mock('../../src/core/systemManager/logger.ts'); -jest.mock('../../src/core/systemManager/fileutils.js', () => ({ +jest.mock('../../src/core/systemManager/fileutils.ts', () => ({ removeDirs: jest.fn(), fsExistsSync: () => true, fsReaddirSync: () => [], @@ -82,7 +54,7 @@ jest.mock('../../src/core/systemManager/fileutils.js', () => ({ copyFolderContentsRecursiveSync: jest.fn(), })); -jest.mock('../../src/core/systemManager/exec.js', () => ({ +jest.mock('../../src/core/systemManager/exec.ts', () => ({ executeAsync: jest.fn(), })); @@ -95,7 +67,7 @@ const c = generateMockConfig({ }); // const parentTask = null; -const originTask = {}; +const originTask = undefined; beforeEach(() => { //Do nothing @@ -106,29 +78,29 @@ afterEach(() => { }); test('Execute task.rnv.platform.list', async () => { - const taskManager = require('../../src/core/taskManager/index.js'); - await expect(taskRnvPlatformList.fn(c, null, originTask)).resolves.toEqual(true); + const taskManager = require('../../src/core/taskManager/index.ts'); + await expect(taskRnvPlatformList.fn(c, undefined, originTask)).resolves.toEqual(true); expect(taskManager.executeTask).toHaveBeenCalledWith(c, 'project configure', 'platform list', originTask); }); test('Execute task.rnv.platform.configure', async () => { - const taskManager = require('../../src/core/taskManager/index.js'); - await expect(taskRnvPlatformConfigure.fn(c, null, originTask)).resolves.toEqual(true); + const taskManager = require('../../src/core/taskManager/index.ts'); + await expect(taskRnvPlatformConfigure.fn(c, undefined, originTask)).resolves.toEqual(true); expect(taskManager.executeTask).toHaveBeenCalledWith(c, 'project configure', 'platform configure', originTask); }); test('Execute task.rnv.kill', async () => { - const taskManager = require('../../src/core/taskManager/index.js'); - await expect(taskRnvKill.fn(c, null, originTask)).resolves.toEqual(true); + const taskManager = require('../../src/core/taskManager/index.ts'); + await expect(taskRnvKill.fn(c, undefined, originTask)).resolves.toEqual(true); expect(taskManager.executeTask).toHaveBeenCalledWith(c, 'app configure', 'kill', originTask); }); test('Execute task.rnv.clean', async () => { - const configure = generateMockConfig({}); - const systemManager = require('../../src/core/systemManager/exec.js'); - const fileUtils = require('../../src/core/systemManager/fileutils.js'); + const configure = generateMockConfig({ program: { ci: true } }); + const systemManager = require('../../src/core/systemManager/exec.ts'); + const fileUtils = require('../../src/core/systemManager/fileutils.ts'); - await expect(taskRnvClean.fn(configure, true)).resolves.toEqual(true); + await expect(taskRnvClean.fn(configure)).resolves.toEqual(true); expect(fileUtils.removeDirs).toHaveBeenCalledTimes(3); expect(systemManager.executeAsync).toHaveBeenCalledWith(configure, 'watchman watch-del-all'); expect(systemManager.executeAsync).toHaveBeenCalledWith( @@ -145,7 +117,7 @@ test('Execute task.rnv.clean', async () => { // }; // const configure = generateMockConfig({}); // const child_process = require('child_process'); -// jest.doMock('../../src/core/systemManager/utils.js', () => ({ +// jest.doMock('../../src/core/systemManager/utils.ts', () => ({ // isSystemWin: true // })); @@ -157,7 +129,7 @@ test('Execute task.rnv.clean', async () => { // }); // describe('Test task.rnv.platform.list', () => { // // const MOCK_FILE_INFO = { -// // '/path/to/file1.js': 'console.log("file1 contents");', +// // '/path/to/file1.ts': 'console.log("file1 contents");', // // '/path/to/file2.txt': 'file2 contents', // // }; // // @@ -169,7 +141,7 @@ test('Execute task.rnv.clean', async () => { // // it('should execute task', async () => { // task.fn(c); -// const engineManager = require('../../core/engineManager/index.js'); +// const engineManager = require('../../core/engineManager/index.ts'); // await expect(task.fn(c, null, originTask)).resolves.toEqual(true); // expect(engineManager.executeTask).toHaveBeenCalledWith(c, 'project configure', 'platform list', originTask); // diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index 0cd7f642cd..e659ad592a 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -256,6 +256,7 @@ export type RenativeConfigFile = { common: { buildSchemes?: Record; runtime?: Record; + versionCodeFormat?: string; }; defaults: { ports?: Record; diff --git a/packages/rnv/src/core/engineManager/index.ts b/packages/rnv/src/core/engineManager/index.ts index 9c3075a58b..2ce83ed8cb 100644 --- a/packages/rnv/src/core/engineManager/index.ts +++ b/packages/rnv/src/core/engineManager/index.ts @@ -449,6 +449,7 @@ const _resolvePkgPath = (c: RnvConfig, packageName: string) => { // In the instances of running linked rnv instead of installed one load local packages try { let pkgPathLocal = require.resolve(packageName, { paths: [path.join(RNV_HOME_DIR, '..')] }); + //TODO: this needs to be changed to support ts libs pkgPathLocal = pkgPathLocal.replace('/dist/index.js', '').replace('\\dist\\index.js', ''); return pkgPathLocal; } catch { diff --git a/packages/rnv/src/core/systemManager/__mocks__/logger.ts b/packages/rnv/src/core/systemManager/__mocks__/logger.ts new file mode 100644 index 0000000000..ea68772290 --- /dev/null +++ b/packages/rnv/src/core/systemManager/__mocks__/logger.ts @@ -0,0 +1,62 @@ +const _chalkPass = (v: string | boolean): string => (typeof v === 'string' ? v : String(v)); + +const getChalk = (): any => { + const chalk: any = { + white: (v: string | boolean) => _chalkPass(v), + green: (v: string) => _chalkPass(v), + red: (v: string) => _chalkPass(v), + yellow: (v: string) => _chalkPass(v), + default: (v: string) => _chalkPass(v), + gray: (v: string) => _chalkPass(v), + grey: (v: string) => _chalkPass(v), + blue: (v: string) => _chalkPass(v), + cyan: (v: string) => _chalkPass(v), + magenta: (v: string) => _chalkPass(v), + rgb: () => (v: string) => _chalkPass(v), + }; + chalk.bold = chalk; + return chalk; +}; + +// const loggerMock = { +// logToSummary= jest.fn(), +// logTask= jest.fn(), +// logDebug= jest.fn(), +// logInfo= jest.fn(), +// logError= jest.fn(), +// logWarning= jest.fn(), +// logSuccess= jest.fn(), +// chalk: () => getChalk(), +// }; + +export const logToSummary = jest.fn(); +export const logTask = jest.fn(); +export const logDebug = jest.fn(); +export const logInfo = jest.fn(); +export const logError = jest.fn(); +export const logWarning = jest.fn(); +export const logSuccess = jest.fn(); +export const chalk = () => getChalk(); +export const logHook = jest.fn(); +export const logEnd = jest.fn(); +export const logAppInfo = jest.fn(); +export const logWelcome = jest.fn(); +export const logComplete = jest.fn(); +export const logInitialize = jest.fn(); +export const stripAnsi = (v: any) => v; + +export default { + chalk, + logHook, + logEnd, + logInfo, + logTask, + logError, + logDebug, + logAppInfo, + logWarning, + logSuccess, + logWelcome, + logComplete, + logInitialize, +}; diff --git a/packages/rnv/src/core/systemManager/chalk.ts b/packages/rnv/src/core/systemManager/chalk.ts new file mode 100644 index 0000000000..03c2843628 --- /dev/null +++ b/packages/rnv/src/core/systemManager/chalk.ts @@ -0,0 +1,21 @@ +import { ChalkApi as ChalkMock } from './types'; + +const _chalkPass = (v: string | boolean): string => (typeof v === 'string' ? v : String(v)); + +export const getChalk = (): ChalkMock => { + const chalk: any = { + white: (v: string | boolean) => _chalkPass(v), + green: (v: string) => _chalkPass(v), + red: (v: string) => _chalkPass(v), + yellow: (v: string) => _chalkPass(v), + default: (v: string) => _chalkPass(v), + gray: (v: string) => _chalkPass(v), + grey: (v: string) => _chalkPass(v), + blue: (v: string) => _chalkPass(v), + cyan: (v: string) => _chalkPass(v), + magenta: (v: string) => _chalkPass(v), + rgb: () => (v: string) => _chalkPass(v), + }; + chalk.bold = chalk; + return chalk; +}; diff --git a/packages/rnv/src/core/systemManager/exec.ts b/packages/rnv/src/core/systemManager/exec.ts index d2aed5473a..a9938d84c3 100755 --- a/packages/rnv/src/core/systemManager/exec.ts +++ b/packages/rnv/src/core/systemManager/exec.ts @@ -33,7 +33,7 @@ const { exec, execSync } = require('child_process'); * @returns {Promise} * */ -const _execute = (c: RnvConfig, command: string, opts: ExecOptions = {}) => { +const _execute = (c: RnvConfig, command: string | Array, opts: ExecOptions = {}) => { const defaultOpts: ExecOptions = { stdio: 'pipe', localDir: path.resolve('./node_modules/.bin'), @@ -58,19 +58,20 @@ const _execute = (c: RnvConfig, command: string, opts: ExecOptions = {}) => { .join(' ') : null; - let cleanCommand = command; + const commandAsString = Array.isArray(command) ? command.join(' ') : command; + let cleanCommand = commandAsString; + let interval: NodeJS.Timer; const intervalTimer = 30000; // 30s let timer = intervalTimer; const privateMask = '*******'; const cleanRawCmd = opts.rawCommand?.args || []; - if (Array.isArray(command)) cleanCommand = command.join(' '); cleanCommand += cleanRawCmd.join(' '); let logMessage = cleanCommand; const privateParams = mergedOpts.privateParams || []; if (privateParams && Array.isArray(privateParams)) { - logMessage = replaceOverridesInString(command, privateParams, privateMask); + logMessage = replaceOverridesInString(commandAsString, privateParams, privateMask); } logMessage = `${env ? `${env} ` : ''}${logMessage}`; @@ -90,7 +91,7 @@ const _execute = (c: RnvConfig, command: string, opts: ExecOptions = {}) => { let child: ExecaChildProcess; if (opts.rawCommand) { const { args } = opts.rawCommand; - child = execa(command, args, mergedOpts); + child = execa(commandAsString, args, mergedOpts); } else { child = execa.command(cleanCommand, mergedOpts); } @@ -218,29 +219,36 @@ const execCLI = (c: RnvConfig, cli: string, command: string, opts: ExecOptions = */ const executeAsync = async ( - _c: RnvConfig | string, - _cmd?: string | ExecOptions, + _c: RnvConfig | string | Array, + _cmd?: string | Array | ExecOptions, _opts?: ExecOptions ): Promise => { // swap values if c is not specified and get it from it's rightful place, config :) let c: RnvConfig; - let cmd = ''; + let cmd: string | Array = ''; let opts: ExecOptions = _opts || {}; - if (typeof _c === 'string') { + const isArg1Command = typeof _c === 'string' || Array.isArray(_c); + if (isArg1Command) { cmd = _c; c = Config.getConfig(); } else { c = _c; } - if (typeof _cmd === 'string') { + const isArg2Command = typeof _cmd === 'string' || Array.isArray(_cmd); + if (isArg2Command) { cmd = _cmd; } else if (_cmd) { opts = _cmd; } if (cmd.includes('npm') && process.platform === 'win32') { - cmd.replace('npm', 'npm.cmd'); + if (typeof cmd === 'string') { + cmd.replace('npm', 'npm.cmd'); + } else { + cmd = cmd.join(' ').replace('npm', 'npm.cmd'); + cmd = cmd.split(' '); + } } // let cmdArr; // if (typeof cmd === 'string') { @@ -401,9 +409,9 @@ const fileNotExistsSync = (commandName: string) => { } }; -const localExecutable = (commandName: string, callback: ExecCallback2) => { +const localExecutable = (commandName: string, callback?: ExecCallback2) => { access(commandName, constants.F_OK | constants.X_OK, (err) => { - callback(null, !err); + callback && callback(null, !err); }); }; @@ -416,13 +424,13 @@ const localExecutableSync = (commandName: string) => { } }; -const commandExistsUnix = (commandName: string, cleanedCommandName: string, callback: ExecCallback2) => { +const commandExistsUnix = (commandName: string, cleanedCommandName: string, callback?: ExecCallback2) => { fileNotExists(commandName, (isFile: boolean) => { if (!isFile) { exec( `command -v ${cleanedCommandName} 2>/dev/null` + ` && { echo >&1 ${cleanedCommandName}; exit 0; }`, (_error: any, stdout: any) => { - callback(null, !!stdout); + callback && callback(null, !!stdout); } ); return; @@ -432,16 +440,16 @@ const commandExistsUnix = (commandName: string, cleanedCommandName: string, call }); }; -const commandExistsWindows = (commandName: string, cleanedCommandName: string, callback: ExecCallback2) => { +const commandExistsWindows = (commandName: string, cleanedCommandName: string, callback?: ExecCallback2) => { if (/[\x00-\x1f<>:"|?*]/.test(commandName)) { - callback(null, false); + callback && callback(null, false); return; } exec(`where ${cleanedCommandName}`, (error: any) => { if (error !== null) { - callback(null, false); + callback && callback(null, false); } else { - callback(null, true); + callback && callback(null, true); } }); }; @@ -495,7 +503,7 @@ if (isUsingWindows) { }; } -const commandExists = (commandName: string, callback: ExecCallback2) => { +const commandExists = (commandName: string, callback?: ExecCallback2) => { const cleanedCommandName = cleanInput(commandName); if (!callback && typeof Promise !== 'undefined') { return new Promise((resolve, reject) => { diff --git a/packages/rnv/src/core/systemManager/logger.ts b/packages/rnv/src/core/systemManager/logger.ts index e62054d20c..8430246117 100644 --- a/packages/rnv/src/core/systemManager/logger.ts +++ b/packages/rnv/src/core/systemManager/logger.ts @@ -1,6 +1,7 @@ /* eslint-disable no-console */ -import _chalk from 'chalk'; +import _chalk, { Chalk } from 'chalk'; import { RnvConfig } from '../configManager/types'; +import { getChalk } from './chalk'; import { AnalyticsApi } from './types'; import { isSystemWin } from './utils'; @@ -24,31 +25,17 @@ export function stripAnsi(string: string) { const ICN_ROCKET = isSystemWin ? 'RNV' : '🚀'; const ICN_UNICORN = isSystemWin ? 'unicorn' : '🦄'; -const _chalkPass = (v: string | boolean): string => (typeof v === 'string' ? v : String(v)); - -const _chalkCols: any = { - white: (v: string | boolean) => _chalkPass(v), - green: (v: string) => _chalkPass(v), - red: (v: string) => _chalkPass(v), - yellow: (v: string) => _chalkPass(v), - default: (v: string) => _chalkPass(v), - gray: (v: string) => _chalkPass(v), - grey: (v: string) => _chalkPass(v), - blue: (v: string) => _chalkPass(v), - cyan: (v: string) => _chalkPass(v), - magenta: (v: string) => _chalkPass(v), - rgb: () => (v: string) => _chalkPass(v), -}; -_chalkCols.bold = _chalkCols; -const _chalkMono = { +const _chalkCols = getChalk(); + +const _chalkMono: any = { ..._chalkCols, }; -let currentChalk = _chalk; +let currentChalk: Chalk = _chalk; let RNV = 'ReNative'; -export const chalk = () => currentChalk || _chalk; +export const chalk = (): Chalk => currentChalk || _chalk; export const logWelcome = () => { // prettier-ignore diff --git a/packages/rnv/src/core/systemManager/types.ts b/packages/rnv/src/core/systemManager/types.ts index a227c206e3..46a9c77fde 100644 --- a/packages/rnv/src/core/systemManager/types.ts +++ b/packages/rnv/src/core/systemManager/types.ts @@ -61,3 +61,18 @@ export type FileUtilsUpdateConfig = { }; export type DoResolveFn = (aPath?: string, mandatory?: boolean, options?: ResolveOptions) => string | undefined; + +export type ChalkApi = { + white: (v: any) => any; + green: (v: any) => any; + red: (v: any) => any; + yellow: (v: any) => any; + default: (v: any) => any; + gray: (v: any) => any; + grey: (v: any) => any; + blue: (v: any) => any; + cyan: (v: any) => any; + magenta: (v: any) => any; + rgb: () => (v: any) => any; + bold: ChalkApi; +}; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.clean.ts b/packages/rnv/src/engine-core/tasks/task.rnv.clean.ts index 13033100fc..738bc85632 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.clean.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.clean.ts @@ -169,7 +169,7 @@ export const taskRnvClean: RnvTaskFn = async (c) => { if (answers.nothingToClean) { logToSummary('Nothing to clean'); - return Promise.resolve(); + return true; } if (answers.modules) { From 166114286fcfcbe05a24539baabdfecb8299e333 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Sun, 3 Sep 2023 01:59:59 +0200 Subject: [PATCH 41/83] switch android sdk to typed rnv --- packages/engine-rn-macos/src/adapter.js | 2 +- packages/engine-rn-tvos/src/adapter.js | 2 +- packages/engine-rn-windows/src/adapter.js | 2 +- packages/engine-rn/src/adapter.js | 2 +- packages/rnv/src/core/common.ts | 4 ++-- packages/rnv/src/core/configManager/types.ts | 2 +- packages/rnv/src/core/engineManager/index.ts | 2 +- packages/rnv/src/core/projectManager/index.ts | 2 +- packages/rnv/src/core/systemManager/types.ts | 2 +- packages/sdk-android/src/ejector.ts | 15 ++++++++++++++- packages/sdk-android/src/index.ts | 7 ++++++- packages/sdk-android/src/kotlinParser.ts | 12 +++++++++--- packages/sdk-android/tsconfig.json | 3 ++- packages/sdk-android/types.d.ts | 1 - 14 files changed, 41 insertions(+), 17 deletions(-) diff --git a/packages/engine-rn-macos/src/adapter.js b/packages/engine-rn-macos/src/adapter.js index da68d7b9b3..ea98438259 100644 --- a/packages/engine-rn-macos/src/adapter.js +++ b/packages/engine-rn-macos/src/adapter.js @@ -38,7 +38,7 @@ export const withRNV = (config) => { watchFolders.push(...config.watchFolders); } - const exts = process.env.RNV_EXTENSIONS || ''; + const exts = process.env.RNV_EXTENSIONS || []; const cnf = { ...config, diff --git a/packages/engine-rn-tvos/src/adapter.js b/packages/engine-rn-tvos/src/adapter.js index b62858b396..854c247f94 100644 --- a/packages/engine-rn-tvos/src/adapter.js +++ b/packages/engine-rn-tvos/src/adapter.js @@ -44,7 +44,7 @@ export const withRNVMetro = (config) => { watchFolders.push(...config.watchFolders); } - const exts = process.env.RNV_EXTENSIONS || ''; + const exts = process.env.RNV_EXTENSIONS || []; const cnf = { ...config, diff --git a/packages/engine-rn-windows/src/adapter.js b/packages/engine-rn-windows/src/adapter.js index ca41683a78..f1ed04da68 100644 --- a/packages/engine-rn-windows/src/adapter.js +++ b/packages/engine-rn-windows/src/adapter.js @@ -41,7 +41,7 @@ export const withRNV = (config) => { watchFolders.push(...config.watchFolders); } - const exts = process.env.RNV_EXTENSIONS || ''; + const exts = process.env.RNV_EXTENSIONS || []; const cnf = { ...config, diff --git a/packages/engine-rn/src/adapter.js b/packages/engine-rn/src/adapter.js index a744678573..f3285dba04 100644 --- a/packages/engine-rn/src/adapter.js +++ b/packages/engine-rn/src/adapter.js @@ -38,7 +38,7 @@ export const withRNVMetro = (config) => { watchFolders.push(...config.watchFolders); } - const exts = process.env.RNV_EXTENSIONS || ''; + const exts = process.env.RNV_EXTENSIONS || []; const cnf = { ...config, diff --git a/packages/rnv/src/core/common.ts b/packages/rnv/src/core/common.ts index 1b9edd49b8..8288c37a03 100755 --- a/packages/rnv/src/core/common.ts +++ b/packages/rnv/src/core/common.ts @@ -12,7 +12,7 @@ import { chalk, logError, logTask, logWarning } from './systemManager/logger'; import { getValidLocalhost } from './systemManager/utils'; import { RenativeConfigBuildScheme, RenativeConfigFile, RnvConfig } from './configManager/types'; import { GetConfigPropFn } from './types'; -import { TimestampPathsConfig } from './systemManager/types'; +import { OverridesOptions, TimestampPathsConfig } from './systemManager/types'; export const getTimestampPathsConfig = (c: RnvConfig, platform: string): TimestampPathsConfig | undefined => { let timestampBuildFiles: Array = []; @@ -44,7 +44,7 @@ export const getCliArguments = (c: RnvConfig) => { return argsCopy.filter((arg) => !!arg); }; -export const addSystemInjects = (c: RnvConfig, injects: Array) => { +export const addSystemInjects = (c: RnvConfig, injects: OverridesOptions) => { if (!c.systemPropsInjects) c.systemPropsInjects = []; if (injects) { injects.forEach((item) => { diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index e659ad592a..799df4a7e3 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -17,7 +17,7 @@ export interface RnvConfig { process: any; rnvVersion: string; _currentTask?: string; - systemPropsInjects: Array; + systemPropsInjects: OverridesOptions; _requiresNpmInstall?: boolean; buildPipes: Record Promise>>; isBuildHooksReady: boolean; diff --git a/packages/rnv/src/core/engineManager/index.ts b/packages/rnv/src/core/engineManager/index.ts index 2ce83ed8cb..6d668ccc61 100644 --- a/packages/rnv/src/core/engineManager/index.ts +++ b/packages/rnv/src/core/engineManager/index.ts @@ -494,7 +494,7 @@ Maybe you forgot to define platforms.${platform}.engine in your renative.json?`) } }; -export const generateEnvVars = (c: RnvConfig, moduleConfig: RnvModuleConfig, nextConfig: RnvNextJSConfig) => { +export const generateEnvVars = (c: RnvConfig, moduleConfig?: RnvModuleConfig, nextConfig?: RnvNextJSConfig) => { const isMonorepo = getConfigProp(c, c.platform, 'isMonorepo'); const monoRoot = getConfigProp(c, c.platform, 'monoRoot'); return { diff --git a/packages/rnv/src/core/projectManager/index.ts b/packages/rnv/src/core/projectManager/index.ts index b21d21a194..320b8b3191 100644 --- a/packages/rnv/src/core/projectManager/index.ts +++ b/packages/rnv/src/core/projectManager/index.ts @@ -432,7 +432,7 @@ export const copyAssetsFolder = async ( c: RnvConfig, platform: RnvPlatform, subPath: string, - customFn: (c: RnvConfig, platform: string) => void + customFn?: (c: RnvConfig, platform: string) => void ) => { logTask('copyAssetsFolder'); diff --git a/packages/rnv/src/core/systemManager/types.ts b/packages/rnv/src/core/systemManager/types.ts index 46a9c77fde..a09f214122 100644 --- a/packages/rnv/src/core/systemManager/types.ts +++ b/packages/rnv/src/core/systemManager/types.ts @@ -12,7 +12,7 @@ export type ExecOptions = { args: Array; }; privateParams?: Array; - env?: NodeJS.Process['env']; + env?: Record; // NodeJS.Process['env']; ignoreErrors?: boolean; detached?: boolean; cwd?: string; diff --git a/packages/sdk-android/src/ejector.ts b/packages/sdk-android/src/ejector.ts index b2866d9a88..9f9ffaf1d3 100644 --- a/packages/sdk-android/src/ejector.ts +++ b/packages/sdk-android/src/ejector.ts @@ -122,6 +122,9 @@ export const ejectGradleProject = async (c: any) => { parsePlugins(c, c.platform, (_plugin: any, pluginPlat: any, key: string) => { const pluginPath = doResolvePath(key); + + if (!pluginPath) return; + const extensionsFilter = [ '.java', '.gradle', @@ -147,7 +150,17 @@ export const ejectGradleProject = async (c: any) => { } const destPath = path.join(appFolder, 'node_modules', key); - copyFolderContentsRecursiveSync(pluginPath, destPath, false, null, false, null, null, c, extensionsFilter); + copyFolderContentsRecursiveSync( + pluginPath, + destPath, + false, + undefined, + false, + undefined, + undefined, + c, + extensionsFilter + ); copyFileSync(path.join(pluginPath, 'package.json'), path.join(destPath, 'package.json')); }); diff --git a/packages/sdk-android/src/index.ts b/packages/sdk-android/src/index.ts index 4eba30e87e..253b3694b6 100644 --- a/packages/sdk-android/src/index.ts +++ b/packages/sdk-android/src/index.ts @@ -58,7 +58,7 @@ const { generateEnvVars } = EngineManager; const { isSystemWin } = Utils; const { inquirerPrompt } = Prompt; const { updateRenativeConfigs } = RuntimeManager; -const { chalk, logTask, logWarning, logDebug, logInfo, logSuccess, logRaw } = Logger; +const { chalk, logTask, logWarning, logDebug, logInfo, logSuccess, logRaw, logError } = Logger; const { ANDROID_WEAR, ANDROID, ANDROID_TV, FIRE_TV, CLI_ANDROID_ADB } = Constants; export const packageAndroid = async (c: any) => { @@ -445,6 +445,11 @@ export const configureAndroidProperties = async (c: any) => { let ndkString = `ndk.dir=${getRealPath(c, c.buildConfig?.sdks?.ANDROID_NDK)}`; let sdkDir = getRealPath(c, c.buildConfig?.sdks?.ANDROID_SDK); + if (!sdkDir) { + logError(`Cannot resolve c.buildConfig?.sdks?.ANDROID_SDK: ${c.buildConfig?.sdks?.ANDROID_SDK}`); + return false; + } + if (isSystemWin) { sdkDir = sdkDir.replace(/\\/g, '/'); ndkString = ndkString.replace(/\\/g, '/'); diff --git a/packages/sdk-android/src/kotlinParser.ts b/packages/sdk-android/src/kotlinParser.ts index c753b7ba26..df7b618c6d 100644 --- a/packages/sdk-android/src/kotlinParser.ts +++ b/packages/sdk-android/src/kotlinParser.ts @@ -72,7 +72,7 @@ export const parseMainApplicationSync = (c: any) => { getBuildFilePath(c, platform, applicationPath), path.join(appFolder, applicationPath), injects, - null, + undefined, c ); }; @@ -112,7 +112,13 @@ export const parseMainActivitySync = (c: any) => { addSystemInjects(c, injects); - writeCleanFile(getBuildFilePath(c, platform, activityPath), path.join(appFolder, activityPath), injects, null, c); + writeCleanFile( + getBuildFilePath(c, platform, activityPath), + path.join(appFolder, activityPath), + injects, + undefined, + c + ); }; export const parseSplashActivitySync = (c: any) => { @@ -138,7 +144,7 @@ export const parseSplashActivitySync = (c: any) => { addSystemInjects(c, injects); - writeCleanFile(getBuildFilePath(c, platform, splashPath), path.join(appFolder, splashPath), injects, null, c); + writeCleanFile(getBuildFilePath(c, platform, splashPath), path.join(appFolder, splashPath), injects, undefined, c); }; export const injectPluginKotlinSync = (c: any, plugin: any, key: any, pkg: any) => { diff --git a/packages/sdk-android/tsconfig.json b/packages/sdk-android/tsconfig.json index 9d2faec89d..432e693d6c 100644 --- a/packages/sdk-android/tsconfig.json +++ b/packages/sdk-android/tsconfig.json @@ -4,7 +4,8 @@ "outDir": "./dist", "rootDir": "./src", "allowJs": true, - "resolveJsonModule": false + "resolveJsonModule": false, + "lib": ["ES2021.String"] }, "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"], "exclude": ["node_modules", "./src/__tests__"] diff --git a/packages/sdk-android/types.d.ts b/packages/sdk-android/types.d.ts index dc0ce3731e..fc585f91fd 100644 --- a/packages/sdk-android/types.d.ts +++ b/packages/sdk-android/types.d.ts @@ -1,4 +1,3 @@ -declare module 'rnv'; declare module 'inquirer'; declare module 'shelljs'; declare module 'execa'; From a0823467e55d86e7fcad623a45e292651fa38cb3 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Sun, 3 Sep 2023 02:04:20 +0200 Subject: [PATCH 42/83] rename rnvConfig to rnvContext --- packages/rnv/src/cli/index.ts | 4 +- packages/rnv/src/core/common.ts | 62 +++++++++---------- packages/rnv/src/core/configManager/config.ts | 6 +- .../rnv/src/core/configManager/configBase.ts | 4 +- packages/rnv/src/core/configManager/index.ts | 28 ++++----- .../src/core/configManager/packageParser.ts | 8 +-- .../src/core/configManager/schemeParser.ts | 4 +- packages/rnv/src/core/configManager/types.ts | 6 +- packages/rnv/src/core/context/types.ts | 0 packages/rnv/src/core/engineManager/index.ts | 38 ++++++------ packages/rnv/src/core/engineManager/types.ts | 4 +- .../rnv/src/core/integrationManager/index.ts | 4 +- .../rnv/src/core/platformManager/index.ts | 22 +++---- packages/rnv/src/core/pluginManager/index.ts | 36 +++++------ .../rnv/src/core/projectManager/buildHooks.ts | 6 +- packages/rnv/src/core/projectManager/index.ts | 30 ++++----- .../rnv/src/core/projectManager/workspace.ts | 8 +-- packages/rnv/src/core/runtimeManager/index.ts | 6 +- packages/rnv/src/core/schemaManager/types.ts | 0 .../core/sdkManager/deviceUtils/android.ts | 34 +++++----- .../src/core/sdkManager/deviceUtils/apple.ts | 8 +-- .../src/core/sdkManager/deviceUtils/common.ts | 4 +- .../src/core/sdkManager/deviceUtils/kaios.ts | 4 +- .../src/core/sdkManager/deviceUtils/tizen.ts | 18 +++--- .../src/core/sdkManager/deviceUtils/webos.ts | 14 ++--- packages/rnv/src/core/sdkManager/installer.ts | 20 +++--- packages/rnv/src/core/setupManager/base.ts | 6 +- packages/rnv/src/core/setupManager/index.ts | 4 +- packages/rnv/src/core/setupManager/linux.ts | 4 +- packages/rnv/src/core/setupManager/windows.ts | 4 +- packages/rnv/src/core/systemManager/crypto.ts | 6 +- packages/rnv/src/core/systemManager/doctor.ts | 4 +- packages/rnv/src/core/systemManager/exec.ts | 12 ++-- .../rnv/src/core/systemManager/fileutils.ts | 22 +++---- .../rnv/src/core/systemManager/gitUtils.ts | 4 +- packages/rnv/src/core/systemManager/logger.ts | 8 +-- .../rnv/src/core/systemManager/npmUtils.ts | 16 ++--- packages/rnv/src/core/systemManager/utils.ts | 4 +- packages/rnv/src/core/taskManager/index.ts | 22 +++---- packages/rnv/src/core/taskManager/types.ts | 4 +- .../rnv/src/core/templateManager/index.ts | 30 ++++----- packages/rnv/src/core/types.ts | 4 +- .../tasks/task.rnv.app.configure.ts | 12 ++-- .../tasks/task.rnv.crypto.decrypt.ts | 4 +- .../tasks/task.rnv.crypto.encrypt.ts | 4 +- .../engine-core/tasks/task.rnv.fastlane.ts | 4 +- .../src/engine-core/tasks/task.rnv.kill.ts | 6 +- .../src/engine-core/tasks/task.rnv.link.ts | 4 +- .../rnv/src/engine-core/tasks/task.rnv.new.ts | 8 +-- .../tasks/task.rnv.template.add.ts | 6 +- .../src/engine-core/tasks/task.rnv.unlink.ts | 4 +- 51 files changed, 292 insertions(+), 292 deletions(-) create mode 100644 packages/rnv/src/core/context/types.ts create mode 100644 packages/rnv/src/core/schemaManager/types.ts diff --git a/packages/rnv/src/cli/index.ts b/packages/rnv/src/cli/index.ts index 328f451bdc..d8159ef01c 100644 --- a/packages/rnv/src/cli/index.ts +++ b/packages/rnv/src/cli/index.ts @@ -7,11 +7,11 @@ import { loadIntegrations } from '../core/integrationManager'; import { initializeTask, findSuitableTask } from '../core/taskManager'; import EngineCore from '../engine-core'; -import { RnvConfig } from '../core/configManager/types'; +import { RnvContext } from '../core/configManager/types'; const IGNORE_MISSING_ENGINES_TASKS = ['link', 'unlink']; -const run = async (c: RnvConfig) => { +const run = async (c: RnvContext) => { await registerEngine(c, EngineCore); await configureRuntimeDefaults(c); await checkAndMigrateProject(); diff --git a/packages/rnv/src/core/common.ts b/packages/rnv/src/core/common.ts index 8288c37a03..625e45557e 100755 --- a/packages/rnv/src/core/common.ts +++ b/packages/rnv/src/core/common.ts @@ -10,11 +10,11 @@ import { CLI_PROPS } from './constants'; import { fsExistsSync, writeCleanFile } from './systemManager/fileutils'; import { chalk, logError, logTask, logWarning } from './systemManager/logger'; import { getValidLocalhost } from './systemManager/utils'; -import { RenativeConfigBuildScheme, RenativeConfigFile, RnvConfig } from './configManager/types'; +import { RenativeConfigBuildScheme, RenativeConfigFile, RnvContext } from './configManager/types'; import { GetConfigPropFn } from './types'; import { OverridesOptions, TimestampPathsConfig } from './systemManager/types'; -export const getTimestampPathsConfig = (c: RnvConfig, platform: string): TimestampPathsConfig | undefined => { +export const getTimestampPathsConfig = (c: RnvContext, platform: string): TimestampPathsConfig | undefined => { let timestampBuildFiles: Array = []; const pPath = path.join(c.paths.project.builds.dir, `${c.runtime.appId}_${platform}`); if (platform === 'web') { @@ -28,7 +28,7 @@ export const getTimestampPathsConfig = (c: RnvConfig, platform: string): Timesta return undefined; }; -export const getCliArguments = (c: RnvConfig) => { +export const getCliArguments = (c: RnvContext) => { const { args, rawArgs } = c.program; const argsCopy = [...args]; let missingArg = rawArgs[rawArgs.indexOf(argsCopy[1]) + 1]; @@ -44,7 +44,7 @@ export const getCliArguments = (c: RnvConfig) => { return argsCopy.filter((arg) => !!arg); }; -export const addSystemInjects = (c: RnvConfig, injects: OverridesOptions) => { +export const addSystemInjects = (c: RnvContext, injects: OverridesOptions) => { if (!c.systemPropsInjects) c.systemPropsInjects = []; if (injects) { injects.forEach((item) => { @@ -73,7 +73,7 @@ export const sanitizeColor = (val: string, key: string) => { }; }; -export const getDevServerHost = (c: RnvConfig) => { +export const getDevServerHost = (c: RnvContext) => { let devServerHostOrig = getConfigProp(c, c.platform, 'devServerHost'); if (!devServerHostOrig) { devServerHostOrig = getConfigProp(c, c.platform, 'webpack', {}).devServerHost; @@ -94,7 +94,7 @@ export const getDevServerHost = (c: RnvConfig) => { return devServerHostFixed; }; -export const waitForHost = async (c: RnvConfig, suffix = 'assets/bundle.js') => { +export const waitForHost = async (c: RnvContext, suffix = 'assets/bundle.js') => { logTask('waitForHost', `port:${c.runtime.port}`); let attempts = 0; const maxAttempts = 10; @@ -133,7 +133,7 @@ export const waitForHost = async (c: RnvConfig, suffix = 'assets/bundle.js') => }); }; -export const existBuildsOverrideForTargetPathSync = (c: RnvConfig, destPath: string) => { +export const existBuildsOverrideForTargetPathSync = (c: RnvContext, destPath: string) => { const appFolder = getAppFolder(c); const relativePath = path.relative(appFolder, destPath); let result = false; @@ -156,7 +156,7 @@ export const existBuildsOverrideForTargetPathSync = (c: RnvConfig, destPath: str return result; }; -export const confirmActiveBundler = async (c: RnvConfig) => { +export const confirmActiveBundler = async (c: RnvContext) => { if (c.runtime.skipActiveServerCheck) return true; if (c.program.ci) { @@ -180,7 +180,7 @@ export const confirmActiveBundler = async (c: RnvConfig) => { return true; }; -export const getPlatformBuildDir = (c: RnvConfig, isRelativePath?: boolean) => { +export const getPlatformBuildDir = (c: RnvContext, isRelativePath?: boolean) => { if (!c.runtime.engine) { logError('getPlatformBuildDir not available without specific engine'); return null; @@ -188,7 +188,7 @@ export const getPlatformBuildDir = (c: RnvConfig, isRelativePath?: boolean) => { return getAppFolder(c, isRelativePath); }; -export const getPlatformOutputDir = (c: RnvConfig) => { +export const getPlatformOutputDir = (c: RnvContext) => { if (!c.runtime.engine) { logError('getPlatformOutputDir not available without specific engine'); return null; @@ -196,7 +196,7 @@ export const getPlatformOutputDir = (c: RnvConfig) => { return path.join(getAppFolder(c), c.runtime.engine.outputDirName || ''); }; -export const getPlatformProjectDir = (c: RnvConfig) => { +export const getPlatformProjectDir = (c: RnvContext) => { if (!c.runtime.engine) { logError('getPlatformProjectDir not available without specific engine'); return null; @@ -204,7 +204,7 @@ export const getPlatformProjectDir = (c: RnvConfig) => { return path.join(getAppFolder(c), c.runtime.engine.projectDirName || ''); }; -export const getPlatformServerDir = (c: RnvConfig) => { +export const getPlatformServerDir = (c: RnvContext) => { if (!c.runtime.engine) { logError('getPlatformProjectDir not available without specific engine'); return null; @@ -212,10 +212,10 @@ export const getPlatformServerDir = (c: RnvConfig) => { return path.join(getAppFolder(c), c.runtime.engine.serverDirName || ''); }; -export const getTemplateDir = (c: RnvConfig) => +export const getTemplateDir = (c: RnvContext) => path.join(c.paths.project.platformTemplatesDirs[c.platform], `${c.platform}`); -export const getTemplateProjectDir = (c: RnvConfig) => { +export const getTemplateProjectDir = (c: RnvContext) => { if (!c.runtime.engine) { logError('getTemplateProjectDir not available without specific engine'); return null; @@ -228,7 +228,7 @@ export const getTemplateProjectDir = (c: RnvConfig) => { }; // DEPRECATED -export const getAppFolder = (c: RnvConfig, isRelativePath?: boolean) => { +export const getAppFolder = (c: RnvContext, isRelativePath?: boolean) => { if (isRelativePath) { return `platformBuilds/${c.runtime.appId}_${c.platform}${c.runtime._platformBuildsSuffix || ''}`; } @@ -239,7 +239,7 @@ export const getAppFolder = (c: RnvConfig, isRelativePath?: boolean) => { }; // DEPRECATED -export const getAppTemplateFolder = (c: RnvConfig, platform: string) => +export const getAppTemplateFolder = (c: RnvContext, platform: string) => path.join(c.paths.project.platformTemplatesDirs[platform], `${platform}`); const _getValueOrMergedObject = (resultCli: any, resultScheme: any, resultPlatforms: any, resultCommon: any) => { @@ -272,7 +272,7 @@ export const getConfigProp: GetConfigPropFn = (c, platform, key, defaultVal?) => }; export const _getConfigProp = ( - c: RnvConfig, + c: RnvContext, platform: string, key: string, defaultVal?: any, @@ -317,7 +317,7 @@ export const _getConfigProp = ( return result; }; -export const getConfigPropArray = (c: RnvConfig, platform: string, key: string) => { +export const getConfigPropArray = (c: RnvContext, platform: string, key: string) => { const result: Array = []; const configArr = [ c.files.defaultWorkspace.config, @@ -350,28 +350,28 @@ export const getConfigPropArray = (c: RnvConfig, platform: string, key: string) return result; }; -export const getAppId = (c: RnvConfig, platform: string) => { +export const getAppId = (c: RnvContext, platform: string) => { const id = getConfigProp(c, platform, 'id'); const idSuffix = getConfigProp(c, platform, 'idSuffix'); return idSuffix ? `${id}${idSuffix}` : id; }; -export const getAppTitle = (c: RnvConfig, platform: string) => getConfigProp(c, platform, 'title'); +export const getAppTitle = (c: RnvContext, platform: string) => getConfigProp(c, platform, 'title'); -export const getAppAuthor = (c: RnvConfig, platform: string) => +export const getAppAuthor = (c: RnvContext, platform: string) => getConfigProp(c, platform, 'author') || c.files.project.package?.author; -export const getAppLicense = (c: RnvConfig, platform: string) => +export const getAppLicense = (c: RnvContext, platform: string) => getConfigProp(c, platform, 'license') || c.files.project.package?.license; -export const getEntryFile = (c: RnvConfig, platform: string) => c.buildConfig.platforms?.[platform]?.entryFile; +export const getEntryFile = (c: RnvContext, platform: string) => c.buildConfig.platforms?.[platform]?.entryFile; -export const getGetJsBundleFile = (c: RnvConfig, platform: string) => getConfigProp(c, platform, 'getJsBundleFile'); +export const getGetJsBundleFile = (c: RnvContext, platform: string) => getConfigProp(c, platform, 'getJsBundleFile'); -export const getAppDescription = (c: RnvConfig, platform: string) => +export const getAppDescription = (c: RnvContext, platform: string) => getConfigProp(c, platform, 'description') || c.files.project.package?.description; -export const getAppVersion = (c: RnvConfig, platform: string) => { +export const getAppVersion = (c: RnvContext, platform: string) => { const version = getConfigProp(c, platform, 'version') || c.files.project.package?.version; if (!version) { logWarning('You are missing version prop in your config. will default to 0'); @@ -408,7 +408,7 @@ export const getAppVersion = (c: RnvConfig, platform: string) => { return output; }; -export const getAppVersionCode = (c: RnvConfig, platform: string) => { +export const getAppVersionCode = (c: RnvContext, platform: string) => { const versionCode = getConfigProp(c, platform, 'versionCode'); if (versionCode) return versionCode; const version = getConfigProp(c, platform, 'version') || c.files.project.package?.version; @@ -478,7 +478,7 @@ export const getMonorepoRoot = () => { } }; -export const getBuildsFolder = (c: RnvConfig, platform: string, customPath?: string) => { +export const getBuildsFolder = (c: RnvContext, platform: string, customPath?: string) => { const pp = customPath || c.paths.appConfig.dir; // if (!fsExistsSync(pp)) { // logWarning(`Path ${chalk().white(pp)} does not exist! creating one for you..`); @@ -498,7 +498,7 @@ export const getBuildsFolder = (c: RnvConfig, platform: string, customPath?: str export const getIP = () => ip.address(); -export const checkPortInUse = (c: RnvConfig, platform: string, port: string) => +export const checkPortInUse = (c: RnvContext, platform: string, port: string) => new Promise((resolve, reject) => { if (port === undefined || port === null) { resolve(false); @@ -514,14 +514,14 @@ export const checkPortInUse = (c: RnvConfig, platform: string, port: string) => }); }); -export const getFlavouredProp = (c: RnvConfig, obj: Record, key: string) => { +export const getFlavouredProp = (c: RnvContext, obj: Record, key: string) => { if (!key || !obj) return null; const val1 = obj[`${key}@${c.runtime.scheme}`]; if (val1) return val1; return obj[key]; }; -export const getBuildFilePath = (c: RnvConfig, platform: string, filePath: string) => { +export const getBuildFilePath = (c: RnvContext, platform: string, filePath: string) => { // P1 => platformTemplates let sp = path.join(getAppTemplateFolder(c, platform), filePath); // P2 => appConfigs/base + @buildSchemes diff --git a/packages/rnv/src/core/configManager/config.ts b/packages/rnv/src/core/configManager/config.ts index 8c3a30429a..f7799d8bf3 100644 --- a/packages/rnv/src/core/configManager/config.ts +++ b/packages/rnv/src/core/configManager/config.ts @@ -1,17 +1,17 @@ import { writeFileSync, fsExistsSync } from '../systemManager/fileutils'; import { logWarning } from '../systemManager/logger'; import { configSchema } from '../constants'; -import { RnvConfig } from './types'; +import { RnvContext } from './types'; import { generateConfigBase } from './configBase'; class Config { - config: RnvConfig; + config: RnvContext; constructor() { this.config = generateConfigBase(); } - initializeConfig(c: RnvConfig) { + initializeConfig(c: RnvContext) { this.config = c; return c; } diff --git a/packages/rnv/src/core/configManager/configBase.ts b/packages/rnv/src/core/configManager/configBase.ts index 2797403311..3c393bdc49 100644 --- a/packages/rnv/src/core/configManager/configBase.ts +++ b/packages/rnv/src/core/configManager/configBase.ts @@ -1,7 +1,7 @@ import { fsExistsSync, fsReadFileSync, fsReaddirSync, fsWriteFileSync } from '../systemManager/fileutils'; import path from 'path'; -import { RnvConfig, RnvConfigFileObj, RnvConfigPathObj } from './types'; +import { RnvContext, RnvConfigFileObj, RnvConfigPathObj } from './types'; export const generateRnvConfigPathObj = (): RnvConfigPathObj => { return { @@ -34,7 +34,7 @@ const runtime: any = { enginesById: {}, }; -export const generateConfigBase = (): RnvConfig => ({ +export const generateConfigBase = (): RnvContext => ({ assetConfig: {}, rnvVersion: '', buildHooks: {}, diff --git a/packages/rnv/src/core/configManager/index.ts b/packages/rnv/src/core/configManager/index.ts index aebfde9062..1f4dc97476 100644 --- a/packages/rnv/src/core/configManager/index.ts +++ b/packages/rnv/src/core/configManager/index.ts @@ -35,13 +35,13 @@ import { getConfigProp } from '../common'; import { getWorkspaceDirPath } from '../projectManager/workspace'; import { chalk, logError, logTask, logWarning, logDebug } from '../systemManager/logger'; import { doResolve } from '../systemManager/resolve'; -import { RnvConfigFileObj, RnvConfigPathObj, RnvConfig, RnvFileKey } from './types'; +import { RnvConfigFileObj, RnvConfigPathObj, RnvContext, RnvFileKey } from './types'; import { generateConfigBase, generateRnvConfigPathObj } from './configBase'; // import { loadPluginTemplates } from '../pluginManager'; const IGNORE_FOLDERS = ['.git']; -export const checkIsRenativeProject = (c: RnvConfig) => +export const checkIsRenativeProject = (c: RnvContext) => new Promise((resolve, reject) => { if (!c.paths.project.configExists) { return reject( @@ -64,7 +64,7 @@ const _generateConfigPaths = (pathObj: RnvConfigPathObj, dir: string, configName const _arrayMergeOverride = (_destinationArray: Array, sourceArray: Array) => sourceArray; -const getEnginesPluginDelta = (c: RnvConfig) => { +const getEnginesPluginDelta = (c: RnvContext) => { logDebug('getEnginesPluginDelta'); if (!c.buildConfig) return; @@ -89,13 +89,13 @@ const getEnginesPluginDelta = (c: RnvConfig) => { return enginePlugins; }; -export const writeRenativeConfigFile = (c: RnvConfig, configPath: string | undefined, configData: string | object) => { +export const writeRenativeConfigFile = (c: RnvContext, configPath: string | undefined, configData: string | object) => { logDebug(`writeRenativeConfigFile:${configPath}`); writeFileSync(configPath, configData); generateBuildConfig(c); }; -export const generateBuildConfig = (c: RnvConfig) => { +export const generateBuildConfig = (c: RnvContext) => { logDebug('generateBuildConfig'); const mergeOrder = [ @@ -221,7 +221,7 @@ export const generateBuildConfig = (c: RnvConfig) => { }; export const loadFileExtended = ( - c: RnvConfig, + c: RnvContext, fileObj: Record, pathObj: RnvConfigPathObj, key: RnvFileKey @@ -269,7 +269,7 @@ export const loadFileExtended = ( }; const _loadConfigFiles = ( - c: RnvConfig, + c: RnvContext, fileObj: RnvConfigFileObj, pathObj: RnvConfigPathObj, parseAppConfigs?: boolean @@ -385,7 +385,7 @@ const _loadConfigFiles = ( return result; }; -export const generateRuntimeConfig = async (c: RnvConfig) => { +export const generateRuntimeConfig = async (c: RnvContext) => { logTask('generateRuntimeConfig'); // c.assetConfig = { // common: c.buildConfig.common, @@ -409,7 +409,7 @@ export const generateRuntimeConfig = async (c: RnvConfig) => { return true; }; -export const generateLocalConfig = (c: RnvConfig, resetAppId?: boolean) => { +export const generateLocalConfig = (c: RnvContext, resetAppId?: boolean) => { logTask('generateLocalConfig', `resetAppId:${!!resetAppId}`); const configLocal = c.files.project.configLocal || {}; configLocal._meta = configLocal._meta || {}; @@ -422,7 +422,7 @@ export const generateLocalConfig = (c: RnvConfig, resetAppId?: boolean) => { writeFileSync(c.paths.project.configLocal, configLocal); }; -const _generatePlatformTemplatePaths = (c: RnvConfig) => { +const _generatePlatformTemplatePaths = (c: RnvContext) => { logTask('_generatePlatformTemplatePaths'); if (!c.buildConfig.paths) { logWarning(`You're missing paths object in your ${chalk().red(c.paths.project.config)}`); @@ -461,7 +461,7 @@ const _generatePlatformTemplatePaths = (c: RnvConfig) => { return result; }; -export const listAppConfigsFoldersSync = (c: RnvConfig, ignoreHiddenConfigs: boolean, appConfigsDirPath?: string) => { +export const listAppConfigsFoldersSync = (c: RnvContext, ignoreHiddenConfigs: boolean, appConfigsDirPath?: string) => { logTask('listAppConfigsFoldersSync', `ignoreHiddenConfigs:${!!ignoreHiddenConfigs}`); if (!c.paths?.project) return []; @@ -493,7 +493,7 @@ export const listAppConfigsFoldersSync = (c: RnvConfig, ignoreHiddenConfigs: boo return appConfigsDirs; }; -const _loadWorkspacesSync = (c: RnvConfig) => { +const _loadWorkspacesSync = (c: RnvContext) => { // CHECK WORKSPACES if (fsExistsSync(c.paths.rnv.configWorkspaces)) { logDebug(`${c.paths.rnv.configWorkspaces} file exists!`); @@ -526,7 +526,7 @@ const _loadWorkspacesSync = (c: RnvConfig) => { } }; -export const parseRenativeConfigs = async (c: RnvConfig) => { +export const parseRenativeConfigs = async (c: RnvContext) => { logTask('parseRenativeConfigs'); // LOAD ./package.json loadFile(c.files.project, c.paths.project, 'package'); @@ -620,7 +620,7 @@ export const parseRenativeConfigs = async (c: RnvConfig) => { }; export const createRnvConfig = (program: any, process: any, cmd: string, subCmd: string) => { - const c: RnvConfig = generateConfigBase(); + const c: RnvContext = generateConfigBase(); global.RNV_CONFIG = c; diff --git a/packages/rnv/src/core/configManager/packageParser.ts b/packages/rnv/src/core/configManager/packageParser.ts index f898d52b88..bf4809b792 100644 --- a/packages/rnv/src/core/configManager/packageParser.ts +++ b/packages/rnv/src/core/configManager/packageParser.ts @@ -10,10 +10,10 @@ import { writeRenativeConfigFile } from './index'; import { overrideTemplatePlugins } from '../pluginManager'; import { configureFonts } from '../projectManager'; import { getConfigProp } from '../common'; -import { RnvConfig } from './types'; +import { RnvContext } from './types'; const injectProjectDependency = async ( - c: RnvConfig, + c: RnvContext, dependency: string, version: string, type: string, @@ -35,7 +35,7 @@ const injectProjectDependency = async ( }; export const checkRequiredPackage = async ( - c: RnvConfig, + c: RnvContext, pkg: string, version = '', type: string, @@ -107,7 +107,7 @@ export const checkRequiredPackage = async ( return false; }; -export const injectPlatformDependencies = async (c: RnvConfig) => { +export const injectPlatformDependencies = async (c: RnvContext) => { logTask('injectPlatformDependencies'); const { platform } = c; const engine = getEngineRunnerByPlatform(c, platform); diff --git a/packages/rnv/src/core/configManager/schemeParser.ts b/packages/rnv/src/core/configManager/schemeParser.ts index b287eaa977..7d940b21f4 100644 --- a/packages/rnv/src/core/configManager/schemeParser.ts +++ b/packages/rnv/src/core/configManager/schemeParser.ts @@ -1,9 +1,9 @@ import merge from 'deepmerge'; import { logError, logTask, logWarning, chalk, logInfo } from '../systemManager/logger'; import { inquirerPrompt } from '../../cli/prompt'; -import { RnvConfig } from './types'; +import { RnvContext } from './types'; -export const isBuildSchemeSupported = async (c: RnvConfig) => { +export const isBuildSchemeSupported = async (c: RnvContext) => { logTask('isBuildSchemeSupported'); const { scheme } = c.program; diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index 799df4a7e3..ee8749fc43 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -2,7 +2,7 @@ import { RnvEngine, RnvEnginePlatform } from '../engineManager/types'; import { OverridesOptions } from '../systemManager/types'; import { RnvPlatform } from '../types'; -export interface RnvConfig { +export interface RnvContext { program: any; command: string | null; subCommand: string | null; @@ -19,14 +19,14 @@ export interface RnvConfig { _currentTask?: string; systemPropsInjects: OverridesOptions; _requiresNpmInstall?: boolean; - buildPipes: Record Promise>>; + buildPipes: Record Promise>>; isBuildHooksReady: boolean; supportedPlatforms: Array; runtimePropsInjects: OverridesOptions; //======= _renativePluginCache: any; cli: any; - buildHooks: Record Promise>; + buildHooks: Record Promise>; api: { fsExistsSync: any; fsReadFileSync: any; diff --git a/packages/rnv/src/core/context/types.ts b/packages/rnv/src/core/context/types.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/rnv/src/core/engineManager/index.ts b/packages/rnv/src/core/engineManager/index.ts index 6d668ccc61..4b01aaa999 100644 --- a/packages/rnv/src/core/engineManager/index.ts +++ b/packages/rnv/src/core/engineManager/index.ts @@ -9,7 +9,7 @@ import { getScopedVersion } from '../systemManager/utils'; import { writeRenativeConfigFile } from '../configManager'; import { configurePlugins } from '../pluginManager'; import { inquirerPrompt } from '../../cli/prompt'; -import { RnvConfig } from '../configManager/types'; +import { RnvContext } from '../configManager/types'; import { RnvTask, RnvTaskMap } from '../taskManager/types'; import { RnvModuleConfig, RnvNextJSConfig, RnvPlatform } from '../types'; import { RenativeEngineConfig, RnvEngine, RnvEngineConfig, RnvEngineConfigMap, RnvEngineInstallConfig } from './types'; @@ -17,7 +17,7 @@ import { RenativeEngineConfig, RnvEngine, RnvEngineConfig, RnvEngineConfigMap, R const ENGINE_CORE = 'engine-core'; export const registerEngine = async ( - c: RnvConfig, + c: RnvContext, engine: RnvEngine, platform?: RnvPlatform, engConfig?: RnvEngineConfig @@ -38,7 +38,7 @@ export const registerEngine = async ( _registerEnginePlatform(c, platform, engine); }; -const _registerEnginePlatform = (c: RnvConfig, platform?: RnvPlatform, engine?: RnvEngine) => { +const _registerEnginePlatform = (c: RnvContext, platform?: RnvPlatform, engine?: RnvEngine) => { if (platform && engine) { c.runtime.enginesByPlatform[platform] = engine; } @@ -85,7 +85,7 @@ export const generateEngineTasks = (taskArr: Array) => { return tasks; }; -export const configureEngines = async (c: RnvConfig) => { +export const configureEngines = async (c: RnvContext) => { logTask('configureEngines'); // const { engines } = c.files.project.config; const engines = _getFilteredEngines(c); @@ -119,7 +119,7 @@ export const configureEngines = async (c: RnvConfig) => { return true; }; -export const registerMissingPlatformEngines = async (c: RnvConfig, taskInstance?: RnvTask) => { +export const registerMissingPlatformEngines = async (c: RnvContext, taskInstance?: RnvTask) => { logTask('registerMissingPlatformEngines'); if ( !taskInstance || @@ -139,7 +139,7 @@ export const registerMissingPlatformEngines = async (c: RnvConfig, taskInstance? return true; }; -export const registerAllPlatformEngines = async (c: RnvConfig) => { +export const registerAllPlatformEngines = async (c: RnvContext) => { logTask('registerAllPlatformEngines'); if (!c.buildConfig?.defaults?.supportedPlatforms?.forEach) { c.runtime.hasAllEnginesRegistered = true; @@ -157,7 +157,7 @@ export const registerAllPlatformEngines = async (c: RnvConfig) => { return true; }; -export const loadEnginePluginDeps = async (c: RnvConfig, engineConfigs: Array) => { +export const loadEnginePluginDeps = async (c: RnvContext, engineConfigs: Array) => { logTask('loadEnginePluginDeps'); if (c.files.project.config.isTemplate) return 0; @@ -207,7 +207,7 @@ If you don't want to use this dependency make sure you remove platform which req return Object.keys(addedPlugins).length; }; -export const loadEnginePackageDeps = async (c: RnvConfig, engineConfigs: Array) => { +export const loadEnginePackageDeps = async (c: RnvContext, engineConfigs: Array) => { logTask('loadEnginePackageDeps'); if (c.program.skipDependencyCheck || c.files.project.config.isTemplate) return 0; // Check engine dependencies @@ -296,7 +296,7 @@ const ENGINE_ID_MAP: Record = { 'engine-rn-windows': '@rnv/engine-rn-windows', }; -const _getFilteredEngines = (c: RnvConfig) => { +const _getFilteredEngines = (c: RnvContext) => { const engines = c.buildConfig?.engines; if (!engines) { logError('Engine configs missing in your renative.json. FIXING...DONE'); @@ -324,7 +324,7 @@ const _getFilteredEngines = (c: RnvConfig) => { return filteredEngines; }; -export const loadEngines = async (c: RnvConfig, failOnMissingDeps?: boolean): Promise => { +export const loadEngines = async (c: RnvContext, failOnMissingDeps?: boolean): Promise => { logTask('loadEngines'); if (!fsExistsSync(c.paths.project.config)) return true; @@ -403,7 +403,7 @@ ${enginesToInstall.map((v) => `> ${v.key}@${v.version}`).join('\n')} return true; }; -const _getMergedEngineConfigs = (c: RnvConfig) => { +const _getMergedEngineConfigs = (c: RnvContext) => { const engines = c.buildConfig?.engines; const engineTemplates = c.buildConfig?.engineTemplates || {}; const mergedEngineConfigs: RnvEngineConfigMap = {}; @@ -431,7 +431,7 @@ const _getMergedEngineConfigs = (c: RnvConfig) => { return mergedEngineConfigs; }; -const _getEngineConfigByPlatform = (c: RnvConfig, platform: string): RnvEngineConfig | null => { +const _getEngineConfigByPlatform = (c: RnvContext, platform: string): RnvEngineConfig | null => { const mergedEngineConfigs = _getMergedEngineConfigs(c); const engineId = c.program.engine || getConfigProp(c, platform, 'engine'); let selectedEngineConfig: RnvEngineConfig | null = null; @@ -444,7 +444,7 @@ const _getEngineConfigByPlatform = (c: RnvConfig, platform: string): RnvEngineCo return selectedEngineConfig; }; -const _resolvePkgPath = (c: RnvConfig, packageName: string) => { +const _resolvePkgPath = (c: RnvContext, packageName: string) => { if (IS_LINKED && !c.program.unlinked) { // In the instances of running linked rnv instead of installed one load local packages try { @@ -470,7 +470,7 @@ const _resolvePkgPath = (c: RnvConfig, packageName: string) => { return pkgPath; }; -const _registerPlatformEngine = async (c: RnvConfig, platform: RnvPlatform | boolean): Promise => { +const _registerPlatformEngine = async (c: RnvContext, platform: RnvPlatform | boolean): Promise => { // Only register active platform engine to be faster if (platform === true || !platform) return; const selectedEngineConfig = _getEngineConfigByPlatform(c, platform); @@ -494,7 +494,7 @@ Maybe you forgot to define platforms.${platform}.engine in your renative.json?`) } }; -export const generateEnvVars = (c: RnvConfig, moduleConfig?: RnvModuleConfig, nextConfig?: RnvNextJSConfig) => { +export const generateEnvVars = (c: RnvContext, moduleConfig?: RnvModuleConfig, nextConfig?: RnvNextJSConfig) => { const isMonorepo = getConfigProp(c, c.platform, 'isMonorepo'); const monoRoot = getConfigProp(c, c.platform, 'monoRoot'); return { @@ -512,7 +512,7 @@ export const generateEnvVars = (c: RnvConfig, moduleConfig?: RnvModuleConfig, ne }; }; -export const getPlatformExtensions = (c: RnvConfig, excludeServer = false, addDotPrefix = false): Array => { +export const getPlatformExtensions = (c: RnvContext, excludeServer = false, addDotPrefix = false): Array => { const { engine } = c.runtime; let output; if (!engine) return []; @@ -528,7 +528,7 @@ export const getPlatformExtensions = (c: RnvConfig, excludeServer = false, addDo return output; }; -export const getEngineRunnerByPlatform = (c: RnvConfig, platform: string, ignoreMissingError?: boolean) => { +export const getEngineRunnerByPlatform = (c: RnvContext, platform: string, ignoreMissingError?: boolean) => { const selectedEngine = c.runtime.enginesByPlatform[platform]; if (!selectedEngine && !ignoreMissingError) { logDebug(`ERROR: Engine for platform: ${platform} does not exists or is not registered ${new Error()}`); @@ -558,7 +558,7 @@ export const hasEngineTask = (task: string, tasks: RnvTaskMap, isProjectScope?: export const getEngineSubTasks = (task: string, tasks: RnvTaskMap, exactMatch?: boolean) => Object.values(tasks).filter((v) => (exactMatch ? v.task.split(' ')[0] === task : v.task.startsWith(task))); -export const getEngineRunner = (c: RnvConfig, task: string, customTasks?: RnvTaskMap, failOnMissingEngine = true) => { +export const getEngineRunner = (c: RnvContext, task: string, customTasks?: RnvTaskMap, failOnMissingEngine = true) => { if (customTasks?.[task]) { return c.runtime.enginesById[ENGINE_CORE]; } @@ -587,4 +587,4 @@ export const getEngineRunner = (c: RnvConfig, task: string, customTasks?: RnvTas return undefined; }; -export const getRegisteredEngines = (c: RnvConfig) => c.runtime.enginesByIndex; +export const getRegisteredEngines = (c: RnvContext) => c.runtime.enginesByIndex; diff --git a/packages/rnv/src/core/engineManager/types.ts b/packages/rnv/src/core/engineManager/types.ts index b2376e83a7..64ff6a5582 100644 --- a/packages/rnv/src/core/engineManager/types.ts +++ b/packages/rnv/src/core/engineManager/types.ts @@ -1,4 +1,4 @@ -import { RnvConfig } from '../configManager/types'; +import { RnvContext } from '../configManager/types'; import { RnvTaskMap } from '../taskManager/types'; export type RnvEngine = { @@ -6,7 +6,7 @@ export type RnvEngine = { platforms: Record; config: RnvEngineConfig; tasks: RnvTaskMap; - initializeRuntimeConfig: (c: RnvConfig) => void; + initializeRuntimeConfig: (c: RnvContext) => void; rootPath?: string; originalTemplatePlatformProjectDir?: string; projectDirName: string; diff --git a/packages/rnv/src/core/integrationManager/index.ts b/packages/rnv/src/core/integrationManager/index.ts index f49b77b05e..e3a7f57107 100644 --- a/packages/rnv/src/core/integrationManager/index.ts +++ b/packages/rnv/src/core/integrationManager/index.ts @@ -1,11 +1,11 @@ import path from 'path'; -import { RnvConfig } from '../configManager/types'; +import { RnvContext } from '../configManager/types'; import { fsExistsSync } from '../systemManager/fileutils'; // import { getScopedVersion } from '../systemManager/utils'; import { logTask, logWarning } from '../systemManager/logger'; import { registerCustomTask } from '../taskManager'; -export const loadIntegrations = async (c: RnvConfig) => { +export const loadIntegrations = async (c: RnvContext) => { logTask('loadIntegrations'); const integrations = c.buildConfig?.integrations; diff --git a/packages/rnv/src/core/platformManager/index.ts b/packages/rnv/src/core/platformManager/index.ts index 31947ae006..71c8987c90 100644 --- a/packages/rnv/src/core/platformManager/index.ts +++ b/packages/rnv/src/core/platformManager/index.ts @@ -5,9 +5,9 @@ import { cleanFolder, copyFolderContentsRecursiveSync, writeFileSync } from '../ import { checkAndConfigureSdks } from '../sdkManager/installer'; import { getTimestampPathsConfig, getPlatformBuildDir, getAppFolder } from '../common'; import { SUPPORTED_PLATFORMS } from '../constants'; -import { RnvConfig } from '../configManager/types'; +import { RnvContext } from '../configManager/types'; -export const logErrorPlatform = (c: RnvConfig) => { +export const logErrorPlatform = (c: RnvContext) => { logError( `Platform: ${chalk().white(c.platform)} doesn't support command: ${chalk().white(c.command)}`, true // kill it if we're not supporting this @@ -15,7 +15,7 @@ export const logErrorPlatform = (c: RnvConfig) => { return false; }; -export const updateProjectPlatforms = (c: RnvConfig, platforms: Array) => { +export const updateProjectPlatforms = (c: RnvContext, platforms: Array) => { const { project: { config }, } = c.paths; @@ -25,7 +25,7 @@ export const updateProjectPlatforms = (c: RnvConfig, platforms: Array) = writeFileSync(config, currentConfig); }; -export const generatePlatformChoices = (c: RnvConfig) => { +export const generatePlatformChoices = (c: RnvContext) => { const options = c.runtime.supportedPlatforms.map((v) => ({ name: `${v.platform} - ${ v.isConnected ? chalk().green('(connected)') : chalk().yellow('(ejected)') @@ -36,7 +36,7 @@ export const generatePlatformChoices = (c: RnvConfig) => { return options; }; -export const cleanPlatformBuild = (c: RnvConfig, platform: string) => +export const cleanPlatformBuild = (c: RnvContext, platform: string) => new Promise((resolve) => { logTask('cleanPlatformBuild'); @@ -59,7 +59,7 @@ export const cleanPlatformBuild = (c: RnvConfig, platform: string) => }); }); -export const createPlatformBuild = (c: RnvConfig, platform: string) => +export const createPlatformBuild = (c: RnvContext, platform: string) => new Promise((resolve, reject) => { logTask('createPlatformBuild'); @@ -82,7 +82,7 @@ export const createPlatformBuild = (c: RnvConfig, platform: string) => resolve(); }); -export const isPlatformSupported = async (c: RnvConfig, isGlobalScope = false) => { +export const isPlatformSupported = async (c: RnvContext, isGlobalScope = false) => { logTask('isPlatformSupported'); if (c.platform && c.program.platform !== true && isGlobalScope) { @@ -136,7 +136,7 @@ export const isPlatformSupported = async (c: RnvConfig, isGlobalScope = false) = }; export const isPlatformSupportedSync = ( - c: RnvConfig, + c: RnvContext, platform: string, resolve?: () => void, reject?: (e: string) => void @@ -169,7 +169,7 @@ export const isPlatformSupportedSync = ( return true; }; -export const isPlatformActive = (c: RnvConfig, platform: string, resolve?: () => void) => { +export const isPlatformActive = (c: RnvContext, platform: string, resolve?: () => void) => { if (!c.buildConfig || !c.buildConfig.platforms) { logError( `Your appConfigFile is not configured properly! check ${chalk().white(c.paths.appConfig.config)} location.` @@ -184,7 +184,7 @@ export const isPlatformActive = (c: RnvConfig, platform: string, resolve?: () => } return true; }; -export const copySharedPlatforms = (c: RnvConfig) => +export const copySharedPlatforms = (c: RnvContext) => new Promise((resolve) => { logTask('copySharedPlatforms'); @@ -198,7 +198,7 @@ export const copySharedPlatforms = (c: RnvConfig) => resolve(); }); -export const ejectPlatform = (c: RnvConfig, platform: string) => { +export const ejectPlatform = (c: RnvContext, platform: string) => { const engine = c.runtime.enginesByPlatform[platform]; const destDir = path.join(c.paths.project.dir, 'platformTemplates', platform); const sourcePlatformDir = engine.originalTemplatePlatformsDir; diff --git a/packages/rnv/src/core/pluginManager/index.ts b/packages/rnv/src/core/pluginManager/index.ts index b4c2f1d5f1..7dc8871b2e 100644 --- a/packages/rnv/src/core/pluginManager/index.ts +++ b/packages/rnv/src/core/pluginManager/index.ts @@ -19,11 +19,11 @@ import { import { chalk, logDebug, logError, logInfo, logSuccess, logTask, logWarning } from '../systemManager/logger'; import { installPackageDependencies } from '../systemManager/npmUtils'; import { doResolve, doResolvePath } from '../systemManager/resolve'; -import { RenativeConfigPlugin, RenativeWebpackConfig, RnvConfig } from '../configManager/types'; +import { RenativeConfigPlugin, RenativeWebpackConfig, RnvContext } from '../configManager/types'; import { ResolveOptions } from '../systemManager/types'; import { PluginCallback, PluginListResponse, RnvPlugin, RnvPluginPlatform, RnvPluginScope } from './types'; -export const getPluginList = (c: RnvConfig, isUpdate = false) => { +export const getPluginList = (c: RnvContext, isUpdate = false) => { const output: PluginListResponse = { asString: '', asArray: [], @@ -113,7 +113,7 @@ const _getPluginScope = (plugin: RenativeConfigPlugin | string): RnvPluginScope return { scope: 'rnv' }; }; -export const getMergedPlugin = (c: RnvConfig, key: string) => { +export const getMergedPlugin = (c: RnvContext, key: string) => { logDebug(`getMergedPlugin:${key}`); const plugin = c.buildConfig.plugins?.[key]; @@ -132,7 +132,7 @@ export const getMergedPlugin = (c: RnvConfig, key: string) => { }; const _getMergedPlugin = ( - c: RnvConfig, + c: RnvContext, plugin: RenativeConfigPlugin | string, pluginKey: string, parentScope?: string, @@ -221,7 +221,7 @@ const _getMergedPlugin = ( return mergedPlugin; }; -export const configurePlugins = async (c: RnvConfig) => { +export const configurePlugins = async (c: RnvContext) => { logTask('configurePlugins'); if (c.program.skipDependencyCheck) return true; @@ -340,14 +340,14 @@ ${ovMsg}` return true; }; -const _updatePackage = (c: RnvConfig, override: any) => { +const _updatePackage = (c: RnvContext, override: any) => { const newPackage: any = merge(c.files.project.package, override); writeRenativeConfigFile(c, c.paths.project.package, newPackage); c.files.project.package = newPackage; c._requiresNpmInstall = true; }; -export const resolvePluginDependants = async (c: RnvConfig) => { +export const resolvePluginDependants = async (c: RnvContext) => { logTask('resolvePluginDependants'); const { plugins } = c.buildConfig; @@ -363,7 +363,7 @@ export const resolvePluginDependants = async (c: RnvConfig) => { }; const _resolvePluginDependencies = async ( - c: RnvConfig, + c: RnvContext, key: string, keyScope: RenativeConfigPlugin | string, parentKey?: string @@ -418,7 +418,7 @@ const _resolvePluginDependencies = async ( }; export const parsePlugins = ( - c: RnvConfig, + c: RnvContext, platform: RnvPluginPlatform, pluginCallback: PluginCallback, ignorePlatformObjectCheck?: boolean @@ -482,7 +482,7 @@ export const parsePlugins = ( } }; -export const loadPluginTemplates = async (c: RnvConfig) => { +export const loadPluginTemplates = async (c: RnvContext) => { logTask('loadPluginTemplates'); //This comes from project dependency @@ -545,7 +545,7 @@ export const loadPluginTemplates = async (c: RnvConfig) => { }; const _parsePluginTemplateDependencies = ( - c: RnvConfig, + c: RnvContext, customPluginTemplates: Record, scope = 'root' ) => { @@ -607,7 +607,7 @@ const _parsePluginTemplateDependencies = ( // Alternative Regex seem more accurate const getCleanRegExString = (str: string) => str.replace(/[-\\.,_*+?^$[\](){}!=|`]/gi, '\\$&'); -const _overridePlugin = (c: RnvConfig, pluginsPath: string, dir: string) => { +const _overridePlugin = (c: RnvContext, pluginsPath: string, dir: string) => { const source = path.resolve(pluginsPath, dir, 'overrides'); const dest = doResolve(dir, false); if (!dest) return; @@ -739,7 +739,7 @@ export const overrideFileContents = (dest: string, override: Record { +export const installPackageDependenciesAndPlugins = async (c: RnvContext) => { logTask('installPackageDependenciesAndPlugins'); await installPackageDependencies(c); @@ -748,7 +748,7 @@ export const installPackageDependenciesAndPlugins = async (c: RnvConfig) => { await checkForPluginDependencies(c); }; -const _getPluginConfiguration = (c: RnvConfig, pluginName: string) => { +const _getPluginConfiguration = (c: RnvContext, pluginName: string) => { let renativePluginPath; try { renativePluginPath = require.resolve(`${pluginName}/renative.plugin.json`, { paths: [c.paths.project.dir] }); @@ -762,7 +762,7 @@ const _getPluginConfiguration = (c: RnvConfig, pluginName: string) => { return null; }; -export const checkForPluginDependencies = async (c: RnvConfig) => { +export const checkForPluginDependencies = async (c: RnvContext) => { const toAdd: Record = {}; if (!c.buildConfig.plugins) return; @@ -821,7 +821,7 @@ export const checkForPluginDependencies = async (c: RnvConfig) => { // const getPluginPlatformFromString = (p: string): RnvPluginPlatform => p as RnvPluginPlatform; -export const overrideTemplatePlugins = async (c: RnvConfig) => { +export const overrideTemplatePlugins = async (c: RnvContext) => { logTask('overrideTemplatePlugins'); const rnvPluginsDirs = c.paths.rnv.pluginTemplates.dirs; @@ -854,7 +854,7 @@ export const overrideTemplatePlugins = async (c: RnvConfig) => { return true; }; -export const copyTemplatePluginsSync = (c: RnvConfig) => { +export const copyTemplatePluginsSync = (c: RnvContext) => { const { platform } = c; const destPath = path.join(getAppFolder(c)); @@ -960,7 +960,7 @@ export const getLocalRenativePlugin = () => ({ }, }); -export const getModuleConfigs = (c: RnvConfig, primaryKey?: RnvPluginPlatform) => { +export const getModuleConfigs = (c: RnvContext, primaryKey?: RnvPluginPlatform) => { let modulePaths: Array = []; const moduleAliases: Record = {}; diff --git a/packages/rnv/src/core/projectManager/buildHooks.ts b/packages/rnv/src/core/projectManager/buildHooks.ts index 92dc615274..28e18ce13f 100644 --- a/packages/rnv/src/core/projectManager/buildHooks.ts +++ b/packages/rnv/src/core/projectManager/buildHooks.ts @@ -5,9 +5,9 @@ import { logDebug, logError, logHook, logInfo } from '../systemManager/logger'; import { fsExistsSync, copyFolderContentsRecursiveSync } from '../systemManager/fileutils'; import { getConfigProp } from '../common'; import { doResolve } from '../systemManager/resolve'; -import { RnvConfig } from '../configManager/types'; +import { RnvContext } from '../configManager/types'; -export const executePipe = async (c: RnvConfig, key: string) => { +export const executePipe = async (c: RnvContext, key: string) => { logHook('executePipe', c?.program?.json ? key : `('${key}')`); await buildHooks(c); @@ -24,7 +24,7 @@ export const executePipe = async (c: RnvConfig, key: string) => { } }; -export const buildHooks = async (c: RnvConfig) => { +export const buildHooks = async (c: RnvContext) => { logDebug('buildHooks'); const enableHookRebuild = getConfigProp(c, c.platform, 'enableHookRebuild'); diff --git a/packages/rnv/src/core/projectManager/index.ts b/packages/rnv/src/core/projectManager/index.ts index 320b8b3191..01261afc58 100644 --- a/packages/rnv/src/core/projectManager/index.ts +++ b/packages/rnv/src/core/projectManager/index.ts @@ -32,12 +32,12 @@ import { chalk, logTask, logWarning, logDebug, logInfo, getCurrentCommand } from import { configureTemplateFiles, configureEntryPoint } from '../templateManager'; import { parseRenativeConfigs } from '../configManager'; -import { NpmPackageFile, RenativeConfigFile, RnvConfig } from '../configManager/types'; +import { NpmPackageFile, RenativeConfigFile, RnvContext } from '../configManager/types'; import { RnvPlatform } from '../types'; import { ParseFontsCallback } from './types'; import { RnvPluginPlatform } from '../pluginManager/types'; -export const checkAndBootstrapIfRequired = async (c: RnvConfig) => { +export const checkAndBootstrapIfRequired = async (c: RnvContext) => { logTask('checkAndBootstrapIfRequired'); const template: string = c.program?.template; if (!c.paths.project.configExists && template) { @@ -181,7 +181,7 @@ export const checkAndBootstrapIfRequired = async (c: RnvConfig) => { return true; }; -export const checkAndCreateGitignore = async (c: RnvConfig) => { +export const checkAndCreateGitignore = async (c: RnvContext) => { logTask('checkAndCreateGitignore'); const ignrPath = path.join(c.paths.project.dir, '.gitignore'); if (!fsExistsSync(ignrPath)) { @@ -192,7 +192,7 @@ export const checkAndCreateGitignore = async (c: RnvConfig) => { return true; }; -export const checkAndCreateBabelConfig = async (c: RnvConfig) => { +export const checkAndCreateBabelConfig = async (c: RnvContext) => { logTask('checkAndCreateBabelConfig'); if (!c.paths.project.configExists) return false; @@ -207,7 +207,7 @@ export const checkAndCreateBabelConfig = async (c: RnvConfig) => { return true; }; -export const configureFonts = async (c: RnvConfig) => { +export const configureFonts = async (c: RnvContext) => { // FONTS let fontsObj = 'export default ['; @@ -278,7 +278,7 @@ export const configureFonts = async (c: RnvConfig) => { return true; }; -export const copyRuntimeAssets = async (c: RnvConfig) => { +export const copyRuntimeAssets = async (c: RnvContext) => { logTask('copyRuntimeAssets'); const destPath = path.join(c.paths.project.assets.dir, 'runtime'); @@ -310,7 +310,7 @@ export const copyRuntimeAssets = async (c: RnvConfig) => { return true; }; -export const parseFonts = (c: RnvConfig, callback: ParseFontsCallback) => { +export const parseFonts = (c: RnvContext, callback: ParseFontsCallback) => { logTask('parseFonts'); if (c.buildConfig) { @@ -351,7 +351,7 @@ export const parseFonts = (c: RnvConfig, callback: ParseFontsCallback) => { } }; -const _parseFontSources = (c: RnvConfig, fontSourcesArr: Array, callback: ParseFontsCallback) => { +const _parseFontSources = (c: RnvContext, fontSourcesArr: Array, callback: ParseFontsCallback) => { const fontSources = fontSourcesArr.map((v) => _resolvePackage(c, v)); fontSources.forEach((fontSourceDir) => { if (fsExistsSync(fontSourceDir)) { @@ -362,7 +362,7 @@ const _parseFontSources = (c: RnvConfig, fontSourcesArr: Array, callback }); }; -const _resolvePackage = (c: RnvConfig, v: string) => { +const _resolvePackage = (c: RnvContext, v: string) => { if (v?.startsWith?.('./')) { return path.join(c.paths.project.dir, v); } @@ -429,10 +429,10 @@ const _resolvePackage = (c: RnvConfig, v: string) => { // }; export const copyAssetsFolder = async ( - c: RnvConfig, + c: RnvContext, platform: RnvPlatform, subPath: string, - customFn?: (c: RnvConfig, platform: string) => void + customFn?: (c: RnvContext, platform: string) => void ) => { logTask('copyAssetsFolder'); @@ -539,7 +539,7 @@ export const copyAssetsFolder = async ( // } // }; -export const copyBuildsFolder = (c: RnvConfig, platform: string) => +export const copyBuildsFolder = (c: RnvContext, platform: string) => new Promise((resolve) => { logTask('copyBuildsFolder'); if (!isPlatformActive(c, platform, resolve)) return; @@ -641,7 +641,7 @@ const SYNCED_DEPS = [ const SYNCED_TEMPLATES = ['@rnv/template-starter']; -export const versionCheck = async (c: RnvConfig) => { +export const versionCheck = async (c: RnvContext) => { logTask('versionCheck'); if (c.runtime.versionCheckCompleted || c.files.project?.config?.skipAutoUpdate || c.program.skipDependencyCheck) { @@ -685,7 +685,7 @@ It is recommended that you run your rnv command with npx prefix: ${recCmd} . or return true; }; -export const upgradeProjectDependencies = (c: RnvConfig, version: string) => { +export const upgradeProjectDependencies = (c: RnvContext, version: string) => { logTask('upgradeProjectDependencies'); // const templates = c.files.project.config?.templates; @@ -743,7 +743,7 @@ const _fixDeps = (deps: Record, version: string) => { }); }; -export const cleanPlaformAssets = async (c: RnvConfig) => { +export const cleanPlaformAssets = async (c: RnvContext) => { logTask('cleanPlaformAssets'); await cleanFolder(c.paths.project.assets.dir); diff --git a/packages/rnv/src/core/projectManager/workspace.ts b/packages/rnv/src/core/projectManager/workspace.ts index 5ceb92c410..a94a47458d 100644 --- a/packages/rnv/src/core/projectManager/workspace.ts +++ b/packages/rnv/src/core/projectManager/workspace.ts @@ -2,9 +2,9 @@ import path from 'path'; import { generateOptions, inquirerPrompt } from '../../cli/prompt'; import { chalk, logTask, logWarning, logDebug, logInfo } from '../systemManager/logger'; import { writeFileSync, mkdirSync, fsExistsSync } from '../systemManager/fileutils'; -import { RnvConfig } from '../configManager/types'; +import { RnvContext } from '../configManager/types'; -export const createWorkspace = async (c: RnvConfig, workspaceID: string, workspacePath: string) => { +export const createWorkspace = async (c: RnvContext, workspaceID: string, workspacePath: string) => { c.files.rnv.configWorkspaces.workspaces[workspaceID] = { path: workspacePath, }; @@ -21,7 +21,7 @@ export const createWorkspace = async (c: RnvConfig, workspaceID: string, workspa return true; }; -export const getWorkspaceDirPath = async (c: RnvConfig) => { +export const getWorkspaceDirPath = async (c: RnvContext) => { logTask('getWorkspaceDirPath'); const wss = c.files.rnv.configWorkspaces; const ws = c.runtime.selectedWorkspace || c.buildConfig?.workspaceID; @@ -77,7 +77,7 @@ export const getWorkspaceConnectionString = (obj: any) => { return connectMsg; }; -export const getWorkspaceOptions = (c: RnvConfig) => +export const getWorkspaceOptions = (c: RnvContext) => generateOptions(c.files.rnv.configWorkspaces?.workspaces, false, null, (i, obj, mapping, defaultVal) => { logDebug('getWorkspaceOptions'); diff --git a/packages/rnv/src/core/runtimeManager/index.ts b/packages/rnv/src/core/runtimeManager/index.ts index e8757d1432..1a3568bdad 100644 --- a/packages/rnv/src/core/runtimeManager/index.ts +++ b/packages/rnv/src/core/runtimeManager/index.ts @@ -6,15 +6,15 @@ import { getConfigProp } from '../common'; import { logTask } from '../systemManager/logger'; import { loadPluginTemplates } from '../pluginManager'; import { parseRenativeConfigs } from '../configManager/index'; -import { RnvConfig, RnvConfigPlatform } from '../configManager/types'; +import { RnvContext, RnvConfigPlatform } from '../configManager/types'; -export const updateRenativeConfigs = async (c: RnvConfig) => { +export const updateRenativeConfigs = async (c: RnvContext) => { await loadPluginTemplates(c); await parseRenativeConfigs(c); return true; }; -export const configureRuntimeDefaults = async (c: RnvConfig) => { +export const configureRuntimeDefaults = async (c: RnvContext) => { c.runtime.appId = c.files.project?.configLocal?._meta?.currentAppConfigId || null; // c.runtime.appConfigDir = c.files.project?.configLocal?._meta?.currentAppConfigDir || null; diff --git a/packages/rnv/src/core/schemaManager/types.ts b/packages/rnv/src/core/schemaManager/types.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/android.ts b/packages/rnv/src/core/sdkManager/deviceUtils/android.ts index ec41046610..00d3aea39b 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/android.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/android.ts @@ -28,7 +28,7 @@ import { CLI_ANDROID_SDKMANAGER, USER_HOME_DIR, } from '../../constants'; -import { RnvConfig } from '../../configManager/types'; +import { RnvContext } from '../../configManager/types'; import { AndroidDevice } from '../types'; const CHECK_INTEVAL = 5000; @@ -44,7 +44,7 @@ export const composeDevicesString = (devices: Array, returnArray? }; export const launchAndroidSimulator = async ( - c: RnvConfig, + c: RnvContext, target: true | { name: string } | string, isIndependentThread = false ) => { @@ -95,7 +95,7 @@ export const launchAndroidSimulator = async ( return Promise.reject('No simulator -t target name specified!'); }; -export const listAndroidTargets = async (c: RnvConfig) => { +export const listAndroidTargets = async (c: RnvContext) => { logTask('listAndroidTargets'); const { program: { device }, @@ -133,7 +133,7 @@ const _getDeviceString = (device: AndroidDevice, i: number | null): any => { return ` [${i + 1}]> ${deviceString}\n`; }; -export const resetAdb = async (c: RnvConfig, ranBefore?: boolean) => { +export const resetAdb = async (c: RnvContext, ranBefore?: boolean) => { try { if (!ranBefore) await execCLI(c, CLI_ANDROID_ADB, 'kill-server'); } catch (e: any) { @@ -150,7 +150,7 @@ export const resetAdb = async (c: RnvConfig, ranBefore?: boolean) => { } }; -export const getAndroidTargets = async (c: RnvConfig, skipDevices: boolean, skipAvds: boolean, deviceOnly = false) => { +export const getAndroidTargets = async (c: RnvContext, skipDevices: boolean, skipAvds: boolean, deviceOnly = false) => { logTask('getAndroidTargets', `skipDevices:${!!skipDevices} skipAvds:${!!skipAvds} deviceOnly:${!!deviceOnly}`); // Temp workaround for race conditions receiving devices with offline status await new Promise((r) => setTimeout(r, 1000)); @@ -178,7 +178,7 @@ const calculateDeviceDiagonal = (width: number, height: number, density: number) return Math.sqrt(widthInches * widthInches + heightInches * heightInches); }; -const getRunningDeviceProp = async (c: RnvConfig, udid: string, prop: string): Promise => { +const getRunningDeviceProp = async (c: RnvContext, udid: string, prop: string): Promise => { // avoid multiple calls to the same device if (currentDeviceProps[udid]) { // if (!prop) return currentDeviceProps[udid]; @@ -202,7 +202,7 @@ const getRunningDeviceProp = async (c: RnvConfig, udid: string, prop: string): P return getRunningDeviceProp(c, udid, prop); }; -const decideIfTVRunning = async (c: RnvConfig, device: AndroidDevice) => { +const decideIfTVRunning = async (c: RnvContext, device: AndroidDevice) => { const { udid, model, product } = device; const mod = await getRunningDeviceProp(c, udid, 'ro.product.model'); const name = await getRunningDeviceProp(c, udid, 'ro.product.name'); @@ -228,7 +228,7 @@ const decideIfTVRunning = async (c: RnvConfig, device: AndroidDevice) => { return isTV; }; -const decideIfWearRunning = async (c: RnvConfig, device: AndroidDevice) => { +const decideIfWearRunning = async (c: RnvContext, device: AndroidDevice) => { const { udid, model, product } = device; const fingerprint = await getRunningDeviceProp(c, udid, 'ro.vendor.build.fingerprint'); const name = await getRunningDeviceProp(c, udid, 'ro.product.vendor.name'); @@ -244,7 +244,7 @@ const decideIfWearRunning = async (c: RnvConfig, device: AndroidDevice) => { return isWear; }; -const getDeviceType = async (device: AndroidDevice, c: RnvConfig) => { +const getDeviceType = async (device: AndroidDevice, c: RnvContext) => { logDebug('getDeviceType - in', { device }); if (device.udid !== 'unknown') { @@ -330,7 +330,7 @@ const getDeviceType = async (device: AndroidDevice, c: RnvConfig) => { return device; }; -const getAvdDetails = (c: RnvConfig, deviceName: string) => { +const getAvdDetails = (c: RnvContext, deviceName: string) => { const { ANDROID_SDK_HOME, ANDROID_AVD_HOME } = process.env; // .avd dir might be in other place than homedir. (https://developer.android.com/studio/command-line/variables) @@ -369,7 +369,7 @@ const getAvdDetails = (c: RnvConfig, deviceName: string) => { return results; }; -const getEmulatorName = async (c: RnvConfig, words: Array) => { +const getEmulatorName = async (c: RnvContext, words: Array) => { const emulator = words[0]; const port = emulator.split('-')[1]; @@ -380,7 +380,7 @@ const getEmulatorName = async (c: RnvConfig, words: Array) => { return emulatorName; }; -export const connectToWifiDevice = async (c: RnvConfig, target: string) => { +export const connectToWifiDevice = async (c: RnvContext, target: string) => { let connect_str = `connect ${target}`; if (!target.includes(':')) { @@ -393,7 +393,7 @@ export const connectToWifiDevice = async (c: RnvConfig, target: string) => { return false; }; -const _parseDevicesResult = async (c: RnvConfig, devicesString: string, avdsString: string, deviceOnly: boolean) => { +const _parseDevicesResult = async (c: RnvContext, devicesString: string, avdsString: string, deviceOnly: boolean) => { logDebug(`_parseDevicesResult:${devicesString}:${avdsString}:${deviceOnly}`); const devices: Array = []; const { skipTargetCheck } = c.program; @@ -511,7 +511,7 @@ const _getDeviceProp = (arr: Array, prop: string) => { return ''; }; -export const askForNewEmulator = async (c: RnvConfig, platform: string) => { +export const askForNewEmulator = async (c: RnvContext, platform: string) => { logTask('askForNewEmulator'); const emuName = c.files.workspace.config.defaultTargets[platform]; @@ -545,7 +545,7 @@ export const askForNewEmulator = async (c: RnvConfig, platform: string) => { return Promise.reject('Action canceled!'); }; -const _createEmulator = (c: RnvConfig, apiVersion: string, emuPlatform: string, emuName: string, arch = 'x86') => { +const _createEmulator = (c: RnvContext, apiVersion: string, emuPlatform: string, emuName: string, arch = 'x86') => { logTask('_createEmulator'); return execCLI(c, CLI_ANDROID_SDKMANAGER, `"system-images;android-${apiVersion};${emuPlatform};${arch}"`) @@ -562,7 +562,7 @@ const _createEmulator = (c: RnvConfig, apiVersion: string, emuPlatform: string, .catch((e) => logError(e, true)); }; -const waitForEmulatorToBeReady = (c: RnvConfig, emulator: string) => +const waitForEmulatorToBeReady = (c: RnvContext, emulator: string) => waitForEmulator(c, CLI_ANDROID_ADB, `-s ${emulator} shell getprop init.svc.bootanim`, (res) => { if (typeof res === 'string') { return res.includes('stopped'); @@ -570,7 +570,7 @@ const waitForEmulatorToBeReady = (c: RnvConfig, emulator: string) => return res; }); -export const checkForActiveEmulator = (c: RnvConfig) => +export const checkForActiveEmulator = (c: RnvContext) => new Promise((resolve, reject) => { logTask('checkForActiveEmulator'); const { platform } = c; diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts b/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts index ed44e89d91..89992ba884 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts @@ -4,9 +4,9 @@ import { chalk, logToSummary, logTask, logWarning, logDebug } from '../../system import { IOS, TVOS } from '../../constants'; import { executeAsync } from '../../systemManager/exec'; import { AppleDevice } from '../types'; -import { RnvConfig } from '../../configManager/types'; +import { RnvContext } from '../../configManager/types'; -export const getAppleDevices = async (c: RnvConfig, ignoreDevices?: boolean, ignoreSimulators?: boolean) => { +export const getAppleDevices = async (c: RnvContext, ignoreDevices?: boolean, ignoreSimulators?: boolean) => { const { platform } = c; logTask('getAppleDevices', `ignoreDevices:${ignoreDevices} ignoreSimulators${ignoreSimulators}`); @@ -178,7 +178,7 @@ const _parseIOSDevicesList = ( return devices; }; -export const launchAppleSimulator = async (c: RnvConfig, target: string) => { +export const launchAppleSimulator = async (c: RnvContext, target: string) => { logTask('launchAppleSimulator', `${target}`); const devicesArr = await getAppleDevices(c, true); @@ -227,7 +227,7 @@ const _launchSimulator = async (selectedDevice: AppleDevice) => { return true; }; -export const listAppleDevices = async (c: RnvConfig) => { +export const listAppleDevices = async (c: RnvContext) => { logTask('listAppleDevices'); const { platform } = c; const devicesArr = await getAppleDevices(c); diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/common.ts b/packages/rnv/src/core/sdkManager/deviceUtils/common.ts index ff6ff9e231..8d3b81dce9 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/common.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/common.ts @@ -1,9 +1,9 @@ import ora from '../../../cli/ora'; -import { RnvConfig } from '../../configManager/types'; +import { RnvContext } from '../../configManager/types'; import { execCLI } from '../../systemManager/exec'; export const waitForEmulator = async ( - c: RnvConfig, + c: RnvContext, cli: string, command: string, callback: (resp: string | true) => boolean diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/kaios.ts b/packages/rnv/src/core/sdkManager/deviceUtils/kaios.ts index 8d9e1d3d5e..e5e8881f90 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/kaios.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/kaios.ts @@ -1,12 +1,12 @@ import { fsExistsSync, getRealPath } from '../../systemManager/fileutils'; import { chalk, logTask } from '../../systemManager/logger'; import { KAIOS_SDK } from '../../constants'; -import { RnvConfig } from '../../configManager/types'; +import { RnvContext } from '../../configManager/types'; import { RnvError } from '../../types'; const childProcess = require('child_process'); -export const launchKaiOSSimulator = (c: RnvConfig) => +export const launchKaiOSSimulator = (c: RnvContext) => new Promise((resolve, reject) => { logTask('launchKaiOSSimulator'); diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts index 08a8c14a35..92c61a2abc 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts @@ -2,7 +2,7 @@ import inquirer from 'inquirer'; import net from 'net'; import path from 'path'; import { getConfigProp, getPlatformProjectDir } from '../../common'; -import { RnvConfig } from '../../configManager/types'; +import { RnvContext } from '../../configManager/types'; import { CLI_SDB_TIZEN, CLI_TIZEN, CLI_TIZEN_EMULATOR, RENATIVE_CONFIG_NAME } from '../../constants'; import { execCLI } from '../../systemManager/exec'; import { fsRenameSync } from '../../systemManager/fileutils'; @@ -33,7 +33,7 @@ const formatXMLObject = (obj: Record) => { export const DEFAULT_SECURITY_PROFILE_NAME = 'RNVanillaCert'; -export const launchTizenSimulator = (c: RnvConfig, name: string) => { +export const launchTizenSimulator = (c: RnvContext, name: string) => { logTask(`launchTizenSimulator:${name}`); if (name) { @@ -44,7 +44,7 @@ export const launchTizenSimulator = (c: RnvConfig, name: string) => { return Promise.reject('No simulator -t target name specified!'); }; -export const listTizenTargets = async (c: RnvConfig) => { +export const listTizenTargets = async (c: RnvContext) => { const targets = await execCLI(c, CLI_TIZEN_EMULATOR, 'list-vm', { detached: true, }); @@ -56,7 +56,7 @@ export const listTizenTargets = async (c: RnvConfig) => { logToSummary(`Tizen Targets:\n${targetStr}`); }; -export const createDevelopTizenCertificate = (c: RnvConfig) => +export const createDevelopTizenCertificate = (c: RnvContext) => new Promise((resolve) => { logTask('createDevelopTizenCertificate'); @@ -84,7 +84,7 @@ export const createDevelopTizenCertificate = (c: RnvConfig) => }); }); -export const addDevelopTizenCertificate = (c: RnvConfig, secureProfileConfig: TizenSecurityConfig) => +export const addDevelopTizenCertificate = (c: RnvContext, secureProfileConfig: TizenSecurityConfig) => new Promise((resolve) => { logTask('addDevelopTizenCertificate'); @@ -99,7 +99,7 @@ export const addDevelopTizenCertificate = (c: RnvConfig, secureProfileConfig: Ti }); }); -const _getDeviceID = async (c: RnvConfig, target: string) => { +const _getDeviceID = async (c: RnvContext, target: string) => { const { device } = c.program; if (device) { @@ -137,7 +137,7 @@ const _getDeviceID = async (c: RnvConfig, target: string) => { return Promise.reject(`No device matching ${target} could be found.`); }; -const _getRunningDevices = async (c: RnvConfig) => { +const _getRunningDevices = async (c: RnvContext) => { const { platform } = c.program; const devicesList = await execCLI(c, CLI_SDB_TIZEN, 'devices'); const lines = devicesList @@ -189,7 +189,7 @@ const _getRunningDevices = async (c: RnvConfig) => { return devices; }; -const _waitForEmulatorToBeReady = (c: RnvConfig, target: string): Promise => +const _waitForEmulatorToBeReady = (c: RnvContext, target: string): Promise => waitForEmulator(c, CLI_SDB_TIZEN, 'devices', (res) => { if (typeof res === 'string') { const lines = res.trim().split(/\r?\n/); @@ -212,7 +212,7 @@ const _composeDevicesString = (devices: Array) => // } // }; -export const runTizenSimOrDevice = async (c: RnvConfig, buildCoreWebpackProject: () => Promise) => { +export const runTizenSimOrDevice = async (c: RnvContext, buildCoreWebpackProject: () => Promise) => { const { hosted } = c.program; const { target, engine } = c.runtime; const { platform } = c; diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts b/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts index 8dafdd9c71..9d91c0ac9a 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts @@ -16,10 +16,10 @@ import { CLI_WEBOS_ARES_SETUP_DEVICE, } from '../../constants'; import { isSystemWin, isUrlLocalhost } from '../../systemManager/utils'; -import { RnvConfig } from '../../configManager/types'; +import { RnvContext } from '../../configManager/types'; import { WebosDevice } from '../types'; -export const launchWebOSimulator = (c: RnvConfig) => { +export const launchWebOSimulator = (c: RnvContext) => { logTask('launchWebOSimulator'); const webosSdkPath = getRealPath(c, c.buildConfig?.sdks?.WEBOS_SDK); @@ -51,7 +51,7 @@ export const launchWebOSimulator = (c: RnvConfig) => { // } // }; -const parseDevices = (c: RnvConfig, devicesResponse: string): Promise> => { +const parseDevices = (c: RnvContext, devicesResponse: string): Promise> => { const linesArray = devicesResponse .split('\n') .slice(2) @@ -85,7 +85,7 @@ const parseDevices = (c: RnvConfig, devicesResponse: string): Promise { +const installAndLaunchApp = async (c: RnvContext, target: string, appPath: string, tId: string) => { try { await execCLI(c, CLI_WEBOS_ARES_INSTALL, `--device ${target} ${appPath}`); } catch (e) { @@ -112,7 +112,7 @@ const buildDeviceChoices = (devices: Array) => value: device.name, })); -export const listWebOSTargets = async (c: RnvConfig) => { +export const listWebOSTargets = async (c: RnvContext) => { const devicesResponse = await execCLI(c, CLI_WEBOS_ARES_DEVICE_INFO, '-D'); const devices = await parseDevices(c, devicesResponse); @@ -123,7 +123,7 @@ export const listWebOSTargets = async (c: RnvConfig) => { return true; }; -const waitForEmulatorToBeReady = async (c: RnvConfig) => { +const waitForEmulatorToBeReady = async (c: RnvContext) => { const devicesResponse = await execCLI(c, CLI_WEBOS_ARES_DEVICE_INFO, '-D'); const devices = await parseDevices(c, devicesResponse); const emulator = devices.filter((d) => !d.isDevice)[0]; @@ -134,7 +134,7 @@ const waitForEmulatorToBeReady = async (c: RnvConfig) => { ); }; -export const runWebosSimOrDevice = async (c: RnvConfig) => { +export const runWebosSimOrDevice = async (c: RnvContext) => { const { device } = c.program; const platDir = getPlatformBuildDir(c); diff --git a/packages/rnv/src/core/sdkManager/installer.ts b/packages/rnv/src/core/sdkManager/installer.ts index 170460693d..9ee4225cc3 100644 --- a/packages/rnv/src/core/sdkManager/installer.ts +++ b/packages/rnv/src/core/sdkManager/installer.ts @@ -35,7 +35,7 @@ import { getRealPath, writeFileSync, fsExistsSync, fsReaddirSync, fsLstatSync } import { chalk, logTask, logWarning, logSuccess, logError, logInfo } from '../systemManager/logger'; import PlatformSetup from '../setupManager'; import { generateBuildConfig } from '../configManager'; -import { RnvConfig } from '../configManager/types'; +import { RnvContext } from '../configManager/types'; const SDK_LOCATIONS: Record> = { android: [ @@ -65,11 +65,11 @@ const SDK_LOCATIONS: Record> = { webos: [path.join('/opt/webOS_TV_SDK'), path.join('C:\\webOS_TV_SDK')], }; -const _logSdkWarning = (c: RnvConfig) => { +const _logSdkWarning = (c: RnvContext) => { logWarning(`Your ${c.paths.workspace.config} is missing SDK configuration object`); }; -export const checkAndConfigureAndroidSdks = async (c: RnvConfig) => { +export const checkAndConfigureAndroidSdks = async (c: RnvContext) => { const sdk = c.buildConfig?.sdks?.ANDROID_SDK; logTask('checkAndConfigureAndroidSdks', `(${sdk})`); @@ -99,7 +99,7 @@ export const checkAndConfigureAndroidSdks = async (c: RnvConfig) => { c.cli[CLI_ANDROID_SDKMANAGER] = sdkManagerPath; }; -export const checkAndConfigureTizenSdks = async (c: RnvConfig) => { +export const checkAndConfigureTizenSdks = async (c: RnvContext) => { logTask(`checkAndConfigureTizenSdks:${c.platform}`); const sdk = c.buildConfig?.sdks?.TIZEN_SDK; if (sdk) { @@ -114,7 +114,7 @@ export const checkAndConfigureTizenSdks = async (c: RnvConfig) => { } }; -export const checkAndConfigureWebosSdks = async (c: RnvConfig) => { +export const checkAndConfigureWebosSdks = async (c: RnvContext) => { logTask(`checkAndConfigureWebosSdks:${c.platform}`); const sdk = c.buildConfig?.sdks?.WEBOS_SDK; if (sdk) { @@ -148,7 +148,7 @@ export const checkAndConfigureWebosSdks = async (c: RnvConfig) => { } }; -export const checkAndConfigureSdks = async (c: RnvConfig) => { +export const checkAndConfigureSdks = async (c: RnvContext) => { logTask('checkAndConfigureSdks'); switch (c.platform) { @@ -168,9 +168,9 @@ export const checkAndConfigureSdks = async (c: RnvConfig) => { } }; -const _getCurrentSdkPath = (c: RnvConfig) => c.buildConfig?.sdks?.[SDK_PLATFORMS[c.platform]]; +const _getCurrentSdkPath = (c: RnvContext) => c.buildConfig?.sdks?.[SDK_PLATFORMS[c.platform]]; -const _isSdkInstalled = (c: RnvConfig) => { +const _isSdkInstalled = (c: RnvContext) => { logTask('_isSdkInstalled'); if (!SDK_PLATFORMS[c.platform]) return true; @@ -198,7 +198,7 @@ const _findFolderWithFile = (dir: string, fileToFind: string) => { return foundDir; }; -const _attemptAutoFix = async (c: RnvConfig, sdkPlatform: string, sdkKey: string, traverseUntilFoundFile?: string) => { +const _attemptAutoFix = async (c: RnvContext, sdkPlatform: string, sdkKey: string, traverseUntilFoundFile?: string) => { logTask('_attemptAutoFix'); if (c.program.hosted) { @@ -265,7 +265,7 @@ const _attemptAutoFix = async (c: RnvConfig, sdkPlatform: string, sdkKey: string return true; }; -export const checkSdk = async (c: RnvConfig) => { +export const checkSdk = async (c: RnvContext) => { logTask('checkSdk'); if (!_isSdkInstalled(c)) { logWarning( diff --git a/packages/rnv/src/core/setupManager/base.ts b/packages/rnv/src/core/setupManager/base.ts index 9710127ee7..1338cf2163 100644 --- a/packages/rnv/src/core/setupManager/base.ts +++ b/packages/rnv/src/core/setupManager/base.ts @@ -9,12 +9,12 @@ import { replaceHomeFolder, updateConfigFile } from '../systemManager/fileutils' import _setupConfig from './config'; import Config from '../configManager/config'; import { logTask, logError, logInfo, logDebug, logSuccess } from '../systemManager/logger'; -import { RnvConfig } from '../configManager/types'; +import { RnvContext } from '../configManager/types'; const setupConfig: any = _setupConfig; class BasePlatformSetup { os: string; - c: RnvConfig; + c: RnvContext; globalConfigPath: string; availableDownloader: string | null; androidSdkLocation: string; @@ -22,7 +22,7 @@ class BasePlatformSetup { webosSdkPath?: string; tizenSdkPath?: string; - constructor(os: string, c?: RnvConfig) { + constructor(os: string, c?: RnvContext) { // eslint-disable-next-line no-param-reassign if (!c) c = Config.getConfig(); const { paths } = c; diff --git a/packages/rnv/src/core/setupManager/index.ts b/packages/rnv/src/core/setupManager/index.ts index 6f3c8f6cd6..df6ffdf96d 100644 --- a/packages/rnv/src/core/setupManager/index.ts +++ b/packages/rnv/src/core/setupManager/index.ts @@ -2,9 +2,9 @@ import LinuxPlatformSetup from './linux'; import WindowsPlatformSetup from './windows'; import DarwinPlatformSetup from './darwin'; import Config from '../configManager/config'; -import { RnvConfig } from '../configManager/types'; +import { RnvContext } from '../configManager/types'; -export default (_c: RnvConfig) => { +export default (_c: RnvContext) => { let c = _c; if (!c) c = Config.getConfig(); const { diff --git a/packages/rnv/src/core/setupManager/linux.ts b/packages/rnv/src/core/setupManager/linux.ts index f7eeaaa864..727a2b2567 100644 --- a/packages/rnv/src/core/setupManager/linux.ts +++ b/packages/rnv/src/core/setupManager/linux.ts @@ -7,10 +7,10 @@ import BasePlatformSetup from './base'; import { updateConfigFile, getRealPath } from '../systemManager/fileutils'; import setupConfig from './config'; import { CLI_ANDROID_ADB, CLI_ANDROID_AVDMANAGER, CLI_ANDROID_EMULATOR, CLI_ANDROID_SDKMANAGER } from '../constants'; -import { RnvConfig } from '../configManager/types'; +import { RnvContext } from '../configManager/types'; class LinuxPlatformSetup extends BasePlatformSetup { - constructor(c: RnvConfig) { + constructor(c: RnvContext) { super('linux', c); } diff --git a/packages/rnv/src/core/setupManager/windows.ts b/packages/rnv/src/core/setupManager/windows.ts index 642c4187d4..151dbf4994 100644 --- a/packages/rnv/src/core/setupManager/windows.ts +++ b/packages/rnv/src/core/setupManager/windows.ts @@ -9,12 +9,12 @@ import { logInfo, logDebug } from '../systemManager/logger'; import { replaceHomeFolder, fsExistsSync } from '../systemManager/fileutils'; import BasePlatformSetup from './base'; import setupConfig from './config'; -import { RnvConfig } from '../configManager/types'; +import { RnvContext } from '../configManager/types'; class LinuxPlatformSetup extends BasePlatformSetup { scoopInstalled: boolean; - constructor(c: RnvConfig) { + constructor(c: RnvContext) { super('win32', c); this.scoopInstalled = false; } diff --git a/packages/rnv/src/core/systemManager/crypto.ts b/packages/rnv/src/core/systemManager/crypto.ts index 9da4ca6555..bcae7e420c 100644 --- a/packages/rnv/src/core/systemManager/crypto.ts +++ b/packages/rnv/src/core/systemManager/crypto.ts @@ -4,7 +4,7 @@ import { isSystemWin } from './utils'; import { getRealPath, fsExistsSync, fsReadFileSync } from './fileutils'; import { TASK_CRYPTO_DECRYPT } from '../constants'; import { executeTask } from '../taskManager'; -import { RnvConfig } from '../configManager/types'; +import { RnvContext } from '../configManager/types'; export const getEnvExportCmd = (envVar: string, key: string) => { if (isSystemWin) { @@ -13,7 +13,7 @@ export const getEnvExportCmd = (envVar: string, key: string) => { return `${chalk().white(`export ${envVar}="${key}"`)}`; }; -export const getEnvVar = (c: RnvConfig) => { +export const getEnvVar = (c: RnvContext) => { const p1 = c.paths.workspace.dir.split('/').pop()?.replace?.('.', ''); const p2 = c.files.project.package.name.replace('@', '').replace('/', '_').replace(/-/g, '_'); const envVar = `CRYPTO_${p1}_${p2}`.toUpperCase(); @@ -21,7 +21,7 @@ export const getEnvVar = (c: RnvConfig) => { return envVar; }; -export const checkCrypto = async (c: RnvConfig, parentTask?: string, originTask?: string) => { +export const checkCrypto = async (c: RnvContext, parentTask?: string, originTask?: string) => { logTask('checkCrypto'); if (c.program.ci || c.files.project.config?.crypto?.optional) return; diff --git a/packages/rnv/src/core/systemManager/doctor.ts b/packages/rnv/src/core/systemManager/doctor.ts index f94e9de73c..154356745b 100644 --- a/packages/rnv/src/core/systemManager/doctor.ts +++ b/packages/rnv/src/core/systemManager/doctor.ts @@ -1,7 +1,7 @@ import { writeFileSync, readObjectSync } from './fileutils'; import { PACKAGE_JSON_FILEDS } from '../constants'; import { chalk, logWarning } from './logger'; -import { RnvConfig } from '../configManager/types'; +import { RnvContext } from '../configManager/types'; const getSortedObject = (obj: any) => { if (obj !== null && typeof obj === 'object' && !Array.isArray(obj)) { @@ -36,7 +36,7 @@ const checkForDuplicates = (arr: Array) => { }); }; -const fixPackageJson = (c: RnvConfig, pkgPath: string) => +const fixPackageJson = (c: RnvContext, pkgPath: string) => new Promise((resolve) => { const pth = pkgPath || c.paths.project.package; const pp = readObjectSync(pth); diff --git a/packages/rnv/src/core/systemManager/exec.ts b/packages/rnv/src/core/systemManager/exec.ts index a9938d84c3..42ff6f14e9 100755 --- a/packages/rnv/src/core/systemManager/exec.ts +++ b/packages/rnv/src/core/systemManager/exec.ts @@ -10,7 +10,7 @@ import Config from '../configManager/config'; import { chalk, logDebug, logRaw, logError } from './logger'; import { fsExistsSync } from './fileutils'; import { replaceOverridesInString } from './utils'; -import { RnvConfig } from '../configManager/types'; +import { RnvContext } from '../configManager/types'; import { ExecCallback, ExecCallback2, ExecOptions } from './types'; const { exec, execSync } = require('child_process'); @@ -33,7 +33,7 @@ const { exec, execSync } = require('child_process'); * @returns {Promise} * */ -const _execute = (c: RnvConfig, command: string | Array, opts: ExecOptions = {}) => { +const _execute = (c: RnvContext, command: string | Array, opts: ExecOptions = {}) => { const defaultOpts: ExecOptions = { stdio: 'pipe', localDir: path.resolve('./node_modules/.bin'), @@ -185,7 +185,7 @@ const _execute = (c: RnvConfig, command: string | Array, opts: ExecOptio * @returns {Promise} * */ -const execCLI = (c: RnvConfig, cli: string, command: string, opts: ExecOptions = {}) => { +const execCLI = (c: RnvContext, cli: string, command: string, opts: ExecOptions = {}) => { if (!c.program) { return Promise.reject('You need to pass c object as first parameter to execCLI()'); } @@ -219,12 +219,12 @@ const execCLI = (c: RnvConfig, cli: string, command: string, opts: ExecOptions = */ const executeAsync = async ( - _c: RnvConfig | string | Array, + _c: RnvContext | string | Array, _cmd?: string | Array | ExecOptions, _opts?: ExecOptions ): Promise => { // swap values if c is not specified and get it from it's rightful place, config :) - let c: RnvConfig; + let c: RnvContext; let cmd: string | Array = ''; let opts: ExecOptions = _opts || {}; const isArg1Command = typeof _c === 'string' || Array.isArray(_c); @@ -284,7 +284,7 @@ const executeAsync = async ( * @returns {Promise} * */ -const executeTelnet = (c: RnvConfig, port: string, command: string) => +const executeTelnet = (c: RnvContext, port: string, command: string) => new Promise((resolve) => { logDebug(`execTelnet: ${port} ${command}`); try { diff --git a/packages/rnv/src/core/systemManager/fileutils.ts b/packages/rnv/src/core/systemManager/fileutils.ts index 4c8154c73f..e1695bd17c 100755 --- a/packages/rnv/src/core/systemManager/fileutils.ts +++ b/packages/rnv/src/core/systemManager/fileutils.ts @@ -6,7 +6,7 @@ import shelljs from 'shelljs'; import merge from 'deepmerge'; import ncp from 'ncp'; import { chalk, logDebug, logError, logWarning } from './logger'; -import { RnvConfig } from '../configManager/types'; +import { RnvContext } from '../configManager/types'; import { DoResolveFn, FileUtilsPropConfig, @@ -119,7 +119,7 @@ export const writeCleanFile = ( destination: string, overrides?: OverridesOptions, timestampPathsConfig?: TimestampPathsConfig, - c?: RnvConfig + c?: RnvContext ) => { // logTask(`writeCleanFile`) // console.log('writeCleanFile', destination); @@ -189,7 +189,7 @@ export const copyFileWithInjectSync = ( skipOverride: boolean, injectObject?: OverridesOptions, timestampPathsConfig?: TimestampPathsConfig, - c?: RnvConfig + c?: RnvContext ) => { logDebug('copyFileWithInjectSync', source); @@ -218,7 +218,7 @@ export const copyFileWithInjectSync = ( } }; -export const invalidatePodsChecksum = (c: RnvConfig) => { +export const invalidatePodsChecksum = (c: RnvContext) => { const appFolder = path.join(c.paths.project.builds.dir, `${c.runtime.appId}_${c.platform}`); const podChecksumPath = path.join(appFolder, 'Podfile.checksum'); if (fs.existsSync(podChecksumPath)) { @@ -233,7 +233,7 @@ export const copyFolderRecursiveSync = ( skipOverride: boolean, injectObject?: OverridesOptions, timestampPathsConfig?: TimestampPathsConfig, - c?: RnvConfig, + c?: RnvContext, extFilter?: Array ) => { logDebug('copyFolderRecursiveSync', source, target); @@ -286,7 +286,7 @@ export const copyFolderContentsRecursiveSync = ( skipOverride?: boolean, injectObject?: OverridesOptions, timestampPathsConfig?: TimestampPathsConfig, - c?: RnvConfig, + c?: RnvContext, extFilter?: Array ) => { logDebug('copyFolderContentsRecursiveSync', source, target, skipPaths); @@ -488,7 +488,7 @@ export const writeObjectSync = (filePath: string, obj: string | object, spaces: return writeFileSync(filePath, obj, spaces, addNewLine); }; -export const readObjectSync = (filePath?: string, sanitize?: boolean, c?: RnvConfig) => { +export const readObjectSync = (filePath?: string, sanitize?: boolean, c?: RnvContext) => { logDebug(`readObjectSync:${sanitize}:${filePath}`); if (!filePath) { logDebug('readObjectSync: filePath is undefined'); @@ -534,7 +534,7 @@ export const updateObjectSync = (filePath: string, updateObj: object) => { return output; }; -export const getRealPath = (c: RnvConfig, p: string | undefined, key = 'undefined', original?: string) => { +export const getRealPath = (c: RnvContext, p: string | undefined, key = 'undefined', original?: string) => { if (!p) { if (original) { logDebug(`Path ${chalk().white(key)} is not defined. using default: ${chalk().white(original)}`); @@ -556,7 +556,7 @@ export const getRealPath = (c: RnvConfig, p: string | undefined, key = 'undefine return output; }; -const _refToValue = (c: RnvConfig, ref: string, key: string) => { +const _refToValue = (c: RnvContext, ref: string, key: string) => { const val = ref.replace('$REF$:', '').split('$...'); const realPath = getRealPath(c, val[0], key); @@ -586,7 +586,7 @@ export const arrayMerge = (destinationArray: Array, sourceArray: Array, sourceArray: Array) => sourceArray; -export const sanitizeDynamicRefs = (c: RnvConfig, obj: any) => { +export const sanitizeDynamicRefs = (c: RnvContext, obj: any) => { if (!obj) return obj; if (Array.isArray(obj)) { obj.forEach((v) => { @@ -695,7 +695,7 @@ const _bindStringVals = (obj: any, _val: string, newKey: string | number, propCo } }; -export const mergeObjects = (c: RnvConfig, obj1: any, obj2: any, dynamicRefs = true, replaceArrays = false) => { +export const mergeObjects = (c: RnvContext, obj1: any, obj2: any, dynamicRefs = true, replaceArrays = false) => { if (!obj2) return obj1; if (!obj1) return obj2; const obj = merge(obj1, obj2, { diff --git a/packages/rnv/src/core/systemManager/gitUtils.ts b/packages/rnv/src/core/systemManager/gitUtils.ts index dc459dfc22..6390038183 100644 --- a/packages/rnv/src/core/systemManager/gitUtils.ts +++ b/packages/rnv/src/core/systemManager/gitUtils.ts @@ -1,10 +1,10 @@ import path from 'path'; -import { RnvConfig } from '../configManager/types'; +import { RnvContext } from '../configManager/types'; import { executeAsync, commandExistsSync } from './exec'; import { fsExistsSync } from './fileutils'; import { logTask, logWarning, logInfo } from './logger'; -export const configureGit = async (c: RnvConfig) => { +export const configureGit = async (c: RnvContext) => { const projectPath = c.paths.project.dir; logTask(`configureGit:${projectPath}`); diff --git a/packages/rnv/src/core/systemManager/logger.ts b/packages/rnv/src/core/systemManager/logger.ts index 8430246117..c66941e7f9 100644 --- a/packages/rnv/src/core/systemManager/logger.ts +++ b/packages/rnv/src/core/systemManager/logger.ts @@ -1,6 +1,6 @@ /* eslint-disable no-console */ import _chalk, { Chalk } from 'chalk'; -import { RnvConfig } from '../configManager/types'; +import { RnvContext } from '../configManager/types'; import { getChalk } from './chalk'; import { AnalyticsApi } from './types'; import { isSystemWin } from './utils'; @@ -74,7 +74,7 @@ export const logWelcome = () => { let _currentProcess: any; let _isInfoEnabled = false; let _infoFilter: Array = []; -let _c: RnvConfig; +let _c: RnvContext; let _isMono = false; let _defaultColor = _chalkCols.white; let _highlightColor = _chalkCols.white; @@ -88,7 +88,7 @@ const cnf = () => { return _c; }; -const _configureLogger = (c: RnvConfig, analytics: AnalyticsApi) => { +const _configureLogger = (c: RnvContext, analytics: AnalyticsApi) => { global._messages = []; _c = c; if (!global.timeStart) global.timeStart = new Date(); @@ -490,7 +490,7 @@ export const logInitialize = () => { if (!_jsonOnly) logWelcome(); }; -export const logAppInfo = (c: RnvConfig) => { +export const logAppInfo = (c: RnvContext) => { if (!_jsonOnly) { logInfo(`Current App Config: ${currentChalk.bold.white(c.runtime.appId)}`); } diff --git a/packages/rnv/src/core/systemManager/npmUtils.ts b/packages/rnv/src/core/systemManager/npmUtils.ts index 66bccf8120..31fed01c7e 100644 --- a/packages/rnv/src/core/systemManager/npmUtils.ts +++ b/packages/rnv/src/core/systemManager/npmUtils.ts @@ -17,9 +17,9 @@ import { doResolve } from './resolve'; import { inquirerPrompt } from '../../cli/prompt'; import { getConfigProp } from '../common'; -import { RnvConfig } from '../configManager/types'; +import { RnvContext } from '../configManager/types'; -const packageJsonIsValid = (c: RnvConfig) => { +const packageJsonIsValid = (c: RnvContext) => { if (!fsExistsSync(c.paths.project.package)) return false; const pkg = readObjectSync(c.paths.project.package); if (!pkg) return false; @@ -47,7 +47,7 @@ export const checkNpxIsInstalled = async () => { } }; -export const checkAndCreateProjectPackage = async (c: RnvConfig) => { +export const checkAndCreateProjectPackage = async (c: RnvContext) => { logTask('checkAndCreateProjectPackage'); if (!packageJsonIsValid(c)) { @@ -91,7 +91,7 @@ export const checkAndCreateProjectPackage = async (c: RnvConfig) => { export const areNodeModulesInstalled = () => !!doResolve('resolve', false); -export const listAndSelectNpmVersion = async (c: RnvConfig, npmPackage: string) => { +export const listAndSelectNpmVersion = async (c: RnvContext, npmPackage: string) => { const templateVersionsStr = await executeAsync(c, `npm view ${npmPackage} versions`); const versionArr = templateVersionsStr.replace(/\r?\n|\r|\s|'|\[|\]/g, '').split(','); @@ -144,7 +144,7 @@ export const listAndSelectNpmVersion = async (c: RnvConfig, npmPackage: string) return inputTemplateVersion; }; -export const checkIfProjectAndNodeModulesExists = async (c: RnvConfig) => { +export const checkIfProjectAndNodeModulesExists = async (c: RnvContext) => { logTask('checkIfProjectAndNodeModulesExists'); if (c.paths.project.configExists && !fsExistsSync(c.paths.project.nodeModulesDir)) { @@ -154,7 +154,7 @@ export const checkIfProjectAndNodeModulesExists = async (c: RnvConfig) => { } }; -const _getInstallScript = (c: RnvConfig) => { +const _getInstallScript = (c: RnvContext) => { const tasks = c.buildConfig?.tasks; if (!tasks) return null; if (Array.isArray(tasks)) { @@ -170,7 +170,7 @@ const _getInstallScript = (c: RnvConfig) => { export const isYarnInstalled = () => commandExistsSync('yarn') || doResolve('yarn', false); -export const installPackageDependencies = async (c: RnvConfig, failOnError = false) => { +export const installPackageDependencies = async (c: RnvContext, failOnError = false) => { c.runtime.forceBuildHookRebuild = true; const customScript = _getInstallScript(c); @@ -274,7 +274,7 @@ export const installPackageDependencies = async (c: RnvConfig, failOnError = fal } }; -export const jetifyIfRequired = async (c: RnvConfig) => { +export const jetifyIfRequired = async (c: RnvContext) => { logTask('jetifyIfRequired'); if (c.files.project.configLocal?._meta?.requiresJetify) { if (doResolve('jetifier')) { diff --git a/packages/rnv/src/core/systemManager/utils.ts b/packages/rnv/src/core/systemManager/utils.ts index 3d1f2f9a4f..d484192cc9 100644 --- a/packages/rnv/src/core/systemManager/utils.ts +++ b/packages/rnv/src/core/systemManager/utils.ts @@ -1,4 +1,4 @@ -import { RnvConfig } from '../configManager/types'; +import { RnvContext } from '../configManager/types'; import { RenativeConfigVersion } from '../types'; export const isSystemMac = process.platform === 'darwin'; @@ -41,7 +41,7 @@ export const isUrlLocalhost = (value: string) => { }; export const getScopedVersion = ( - c: RnvConfig, + c: RnvContext, key: string, val: RenativeConfigVersion, sourceObjKey: 'engineTemplates' | 'plugins' diff --git a/packages/rnv/src/core/taskManager/index.ts b/packages/rnv/src/core/taskManager/index.ts index 8ef7e4a490..c5575390e1 100644 --- a/packages/rnv/src/core/taskManager/index.ts +++ b/packages/rnv/src/core/taskManager/index.ts @@ -12,7 +12,7 @@ import { registerAllPlatformEngines, } from '../engineManager'; import { TASK_CONFIGURE_SOFT } from '../constants'; -import { RnvConfig } from '../configManager/types'; +import { RnvContext } from '../configManager/types'; import { RnvTask, RnvTaskMap, TaskItemMap, TaskObj } from './types'; import { RnvEngine } from '../engineManager/types'; @@ -20,13 +20,13 @@ let executedTasks: Record = {}; const CUSTOM_TASKS: RnvTaskMap = {}; -export const registerCustomTask = async (_c: RnvConfig, task: RnvTask) => { +export const registerCustomTask = async (_c: RnvContext, task: RnvTask) => { if (task.task) { CUSTOM_TASKS[task.task] = task; } }; -export const initializeTask = async (c: RnvConfig, task: string) => { +export const initializeTask = async (c: RnvContext, task: string) => { logTask('initializeTask', task); c.runtime.task = task; executedTasks = {}; @@ -61,7 +61,7 @@ const _getTaskObj = (taskInstance: RnvTask) => { }; }; -export const findSuitableTask = async (c: RnvConfig, specificTask?: string): Promise => { +export const findSuitableTask = async (c: RnvContext, specificTask?: string): Promise => { logTask('findSuitableTask'); const REGISTERED_ENGINES = getRegisteredEngines(c); let task = ''; @@ -249,7 +249,7 @@ export const findSuitableTask = async (c: RnvConfig, specificTask?: string): Pro return getEngineTask(task, c.runtime.engine?.tasks); }; -const _populateExtraParameters = (c: RnvConfig, task: RnvTask) => { +const _populateExtraParameters = (c: RnvContext, task: RnvTask) => { if (task.params) { task.params.forEach((param) => { let cmd = ''; @@ -270,7 +270,7 @@ const _populateExtraParameters = (c: RnvConfig, task: RnvTask) => { } }; -const _selectPlatform = async (c: RnvConfig, suitableEngines: Array, task: string) => { +const _selectPlatform = async (c: RnvContext, suitableEngines: Array, task: string) => { const supportedPlatforms: Record = {}; suitableEngines.forEach((engine) => { getEngineTask(task, engine.tasks)?.platforms.forEach((plat) => { @@ -290,13 +290,13 @@ const _selectPlatform = async (c: RnvConfig, suitableEngines: Array, } }; -const _executePipe = async (c: RnvConfig, task: string, phase: string) => +const _executePipe = async (c: RnvContext, task: string, phase: string) => executePipe(c, `${task.split(' ').join(':')}:${phase}`); const TASK_LIMIT = 20; export const executeTask = async ( - c: RnvConfig, + c: RnvContext, task: string, parentTask?: string, originTask?: string, @@ -331,7 +331,7 @@ To avoid that test your task code against parentTask and avoid executing same ta logExitTask(`${prt}<= ${task}`); }; -export const executeOrSkipTask = async (c: RnvConfig, task: string, parentTask: string, originTask: string) => { +export const executeOrSkipTask = async (c: RnvContext, task: string, parentTask: string, originTask: string) => { if (!c.program.only) { return executeTask(c, task, parentTask, originTask); } @@ -345,7 +345,7 @@ const _logSkip = (task: string) => { logInfo(`Original RNV task ${chalk().white(task)} marked to ignore. SKIPPING...`); }; -export const shouldSkipTask = (c: RnvConfig, task: string, originTask?: string) => { +export const shouldSkipTask = (c: RnvContext, task: string, originTask?: string) => { const tasks = c.buildConfig?.tasks; c.runtime.platform = c.platform; if (!tasks) return; @@ -409,7 +409,7 @@ export const shouldSkipTask = (c: RnvConfig, task: string, originTask?: string) }; export const executeEngineTask = async ( - c: RnvConfig, + c: RnvContext, task: string, parentTask?: string, originTask?: string, diff --git a/packages/rnv/src/core/taskManager/types.ts b/packages/rnv/src/core/taskManager/types.ts index 2a24143bb9..c5dc8ba01d 100644 --- a/packages/rnv/src/core/taskManager/types.ts +++ b/packages/rnv/src/core/taskManager/types.ts @@ -1,4 +1,4 @@ -import { RnvConfig } from '../configManager/types'; +import { RnvContext } from '../configManager/types'; export type RnvTask = { task: string; @@ -25,7 +25,7 @@ export type RnvTaskParameter = { export type RnvTaskMap = Record; //Too many choices of return types -export type RnvTaskFn = (c: RnvConfig, parentTask?: string, originTask?: string) => Promise; // Promise; +export type RnvTaskFn = (c: RnvContext, parentTask?: string, originTask?: string) => Promise; // Promise; export type TaskItemMap = Record< string, diff --git a/packages/rnv/src/core/templateManager/index.ts b/packages/rnv/src/core/templateManager/index.ts index c737224842..8eb848de13 100644 --- a/packages/rnv/src/core/templateManager/index.ts +++ b/packages/rnv/src/core/templateManager/index.ts @@ -20,10 +20,10 @@ import { getConfigProp } from '../common'; import { listAppConfigsFoldersSync, generateBuildConfig, loadFileExtended } from '../configManager'; import { doResolve } from '../systemManager/resolve'; import { checkIfProjectAndNodeModulesExists } from '../systemManager/npmUtils'; -import { RnvConfig } from '../configManager/types'; +import { RnvContext } from '../configManager/types'; import { PromptOptions } from '../../cli/types'; -export const checkIfTemplateConfigured = async (c: RnvConfig) => { +export const checkIfTemplateConfigured = async (c: RnvContext) => { logTask('checkIfTemplateConfigured'); if (c.program.skipDependencyCheck || c.files.project.config.isTemplate) return true; if (!c.buildConfig.templates) { @@ -57,7 +57,7 @@ export const checkIfTemplateConfigured = async (c: RnvConfig) => { return true; }; -const _cleanProjectTemplateSync = (c: RnvConfig) => { +const _cleanProjectTemplateSync = (c: RnvContext) => { logTask('_cleanProjectTemplateSync'); const dirsToRemove = [c.paths.project.appConfigBase.dir, c.paths.project.srcDir, c.paths.project.appConfigsDir]; @@ -70,7 +70,7 @@ const _cleanProjectTemplateSync = (c: RnvConfig) => { if (filesToRemove) removeFilesSync(filesToRemove); }; -const _applyTemplate = async (c: RnvConfig) => { +const _applyTemplate = async (c: RnvContext) => { logTask('_applyTemplate', `current:${c.buildConfig.currentTemplate} selected:${c.runtime.selectedTemplate}`); if (c.runtime.selectedTemplate) { @@ -129,7 +129,7 @@ const _applyTemplate = async (c: RnvConfig) => { return true; }; -const _configureSrc = (c: RnvConfig) => +const _configureSrc = (c: RnvContext) => new Promise((resolve) => { // Check src logDebug('configureProject:check src'); @@ -140,7 +140,7 @@ const _configureSrc = (c: RnvConfig) => resolve(); }); -const _configureAppConfigs = async (c: RnvConfig) => { +const _configureAppConfigs = async (c: RnvContext) => { // Check appConfigs logDebug('configureProject:check appConfigs'); // @@ -191,7 +191,7 @@ const _configureAppConfigs = async (c: RnvConfig) => { } }; -const _configureProjectConfig = (c: RnvConfig) => +const _configureProjectConfig = (c: RnvContext) => new Promise((resolve) => { // Check projectConfigs logDebug('configureProject:check projectConfigs'); @@ -206,7 +206,7 @@ const _configureProjectConfig = (c: RnvConfig) => resolve(); }); -const _configureRenativeConfig = async (c: RnvConfig) => { +const _configureRenativeConfig = async (c: RnvContext) => { // renative.json const templateConfig = readObjectSync(c.paths.template.configTemplate); logDebug('configureProject:check renative.json'); @@ -236,7 +236,7 @@ const _configureRenativeConfig = async (c: RnvConfig) => { return true; }; -export const configureTemplateFiles = async (c: RnvConfig) => { +export const configureTemplateFiles = async (c: RnvContext) => { logTask('configureTemplateFiles'); const templateConfig = readObjectSync(c.paths.template.configTemplate); @@ -267,7 +267,7 @@ export const configureTemplateFiles = async (c: RnvConfig) => { } }; -export const configureEntryPoint = async (c: RnvConfig, platform: string) => { +export const configureEntryPoint = async (c: RnvContext, platform: string) => { logTask('configureEntryPoint'); if (c.files.project.config.isTemplate) return true; @@ -302,12 +302,12 @@ export const configureEntryPoint = async (c: RnvConfig, platform: string) => { return true; }; -const _writeObjectSync = (c: RnvConfig, p: string | undefined, s: string) => { +const _writeObjectSync = (c: RnvContext, p: string | undefined, s: string) => { writeFileSync(p, s); generateBuildConfig(c); }; -export const getTemplateOptions = (c: RnvConfig, isGlobalScope?: boolean) => { +export const getTemplateOptions = (c: RnvContext, isGlobalScope?: boolean) => { let defaultProjectTemplates; if (isGlobalScope) { defaultProjectTemplates = c.files.rnv.projectTemplates.config.projectTemplates; @@ -322,7 +322,7 @@ export const getTemplateOptions = (c: RnvConfig, isGlobalScope?: boolean) => { }); }; -export const getInstalledTemplateOptions = (c: RnvConfig): PromptOptions | null => { +export const getInstalledTemplateOptions = (c: RnvContext): PromptOptions | null => { if (c.files.project.config.isTemplate) return null; if (c.buildConfig.templates) { return generateOptions(c.buildConfig.templates); @@ -331,10 +331,10 @@ export const getInstalledTemplateOptions = (c: RnvConfig): PromptOptions | null return null; }; -export const isTemplateInstalled = (c: RnvConfig) => +export const isTemplateInstalled = (c: RnvContext) => c.buildConfig.currentTemplate ? doResolve(c.buildConfig.currentTemplate) : false; -export const applyTemplate = async (c: RnvConfig, selectedTemplate?: string) => { +export const applyTemplate = async (c: RnvContext, selectedTemplate?: string) => { logTask('applyTemplate', `${c.buildConfig.currentTemplate}=>${selectedTemplate}`); if (c.files.project.config.isTemplate) return true; diff --git a/packages/rnv/src/core/types.ts b/packages/rnv/src/core/types.ts index 9de47a6f15..ec730d7696 100644 --- a/packages/rnv/src/core/types.ts +++ b/packages/rnv/src/core/types.ts @@ -1,4 +1,4 @@ -import { RnvConfig } from './configManager/types'; +import { RnvContext } from './configManager/types'; export type RnvPlatform = string; @@ -13,4 +13,4 @@ export type RenativeConfigVersion = string | { version: string }; export type RnvError = any; -export type GetConfigPropFn = (c: RnvConfig, platform: string, key: string, defaultVal?: any) => T; +export type GetConfigPropFn = (c: RnvContext, platform: string, key: string, defaultVal?: any) => T; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.app.configure.ts b/packages/rnv/src/engine-core/tasks/task.rnv.app.configure.ts index e4b99ac331..61b65641b6 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.app.configure.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.app.configure.ts @@ -6,7 +6,7 @@ import { TASK_APP_CONFIGURE, PARAMS } from '../../core/constants'; import { writeFileSync, fsExistsSync, fsReadFileSync, fsRenameSync } from '../../core/systemManager/fileutils'; import { chalk, logError, logTask, logWarning, logDebug, logInfo, logAppInfo } from '../../core/systemManager/logger'; import { inquirerPrompt } from '../../cli/prompt'; -import { RnvConfig } from '../../core/configManager/types'; +import { RnvContext } from '../../core/configManager/types'; const _loadAppConfigIDfromDir = (dirName: string, appConfigsDir: string) => { logDebug(`_loadAppConfigIDfromDir:${dirName}:${appConfigsDir}`, chalk().grey); @@ -22,7 +22,7 @@ const _loadAppConfigIDfromDir = (dirName: string, appConfigsDir: string) => { return { dir: dirName, id: null }; }; -const _askUserAboutConfigs = async (c: RnvConfig, dir: string, id: string, basePath: string) => { +const _askUserAboutConfigs = async (c: RnvContext, dir: string, id: string, basePath: string) => { logTask('_askUserAboutConfigs'); logWarning( `AppConfig error - It seems you have a mismatch between appConfig folder name (${dir}) and the id defined in renative.json (${id}). They must match.` @@ -75,7 +75,7 @@ const _askUserAboutConfigs = async (c: RnvConfig, dir: string, id: string, baseP }; /* eslint-disable no-await-in-loop */ -const matchAppConfigID = async (c: RnvConfig, appConfigID: string) => { +const matchAppConfigID = async (c: RnvContext, appConfigID: string) => { logTask('matchAppConfigID', `appId:${appConfigID}`); if (!appConfigID) return false; @@ -95,7 +95,7 @@ const matchAppConfigID = async (c: RnvConfig, appConfigID: string) => { return false; }; -const _findAndSwitchAppConfigDir = async (c: RnvConfig) => { +const _findAndSwitchAppConfigDir = async (c: RnvContext) => { logTask('_findAndSwitchAppConfigDir'); const { appConfigsDirNames } = c.paths.project; if (appConfigsDirNames.length) { @@ -124,7 +124,7 @@ const _findAndSwitchAppConfigDir = async (c: RnvConfig) => { return false; }; -const _setAppId = (c: RnvConfig, appId: string) => { +const _setAppId = (c: RnvContext, appId: string) => { const currentAppConfigId = c.files.project?.configLocal?._meta?.currentAppConfigId; logTask('_setAppId', `appId:${appId} runtime.appId:${c.runtime.appId} _meta.appId:${currentAppConfigId}`); @@ -132,7 +132,7 @@ const _setAppId = (c: RnvConfig, appId: string) => { c.runtime.appDir = path.join(c.paths.project.builds.dir, `${c.runtime.appId}_${c.platform}`); }; -export const taskRnvAppConfigure = async (c: RnvConfig) => { +export const taskRnvAppConfigure = async (c: RnvContext) => { logTask('taskRnvAppConfigure'); c.paths.project.appConfigsDirNames = listAppConfigsFoldersSync(c, true); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.crypto.decrypt.ts b/packages/rnv/src/engine-core/tasks/task.rnv.crypto.decrypt.ts index 01780e904b..c33e77b92f 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.crypto.decrypt.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.crypto.decrypt.ts @@ -14,13 +14,13 @@ import { inquirerPrompt } from '../../cli/prompt'; import { getEnvVar, getEnvExportCmd } from '../../core/systemManager/crypto'; import { executeTask } from '../../core/taskManager'; import { TASK_CRYPTO_DECRYPT, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; -import { RnvConfig } from '../../core/configManager/types'; +import { RnvContext } from '../../core/configManager/types'; import { RnvTaskFn } from '../../core/taskManager/types'; const iocane = require('iocane'); const _unzipAndCopy = async ( - c: RnvConfig, + c: RnvContext, shouldCleanFolder: boolean, destTemp: string, wsPath: string, diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts b/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts index d955545c22..267fb4f7e4 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts @@ -16,7 +16,7 @@ import { inquirerPrompt } from '../../cli/prompt'; import { getEnvVar, getEnvExportCmd } from '../../core/systemManager/crypto'; import { executeTask } from '../../core/taskManager'; import { TASK_CRYPTO_ENCRYPT, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; -import { RnvConfig } from '../../core/configManager/types'; +import { RnvContext } from '../../core/configManager/types'; import { RnvTaskFn } from '../../core/taskManager/types'; const iocane = require('iocane'); @@ -29,7 +29,7 @@ const generateRandomKey = (length: number) => .map((x) => x[Math.floor(Math.random() * x.length)]) .join(''); -const _checkAndConfigureCrypto = async (c: RnvConfig) => { +const _checkAndConfigureCrypto = async (c: RnvContext) => { // handle missing config const source = `./${c.files.project.package.name}`; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.fastlane.ts b/packages/rnv/src/engine-core/tasks/task.rnv.fastlane.ts index 6b2ea9042b..7f195ecbe1 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.fastlane.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.fastlane.ts @@ -2,9 +2,9 @@ import { executeAsync, commandExistsSync } from '../../core/systemManager/exec'; import { getAppFolder, getCliArguments } from '../../core/common'; import { IOS, TVOS, ANDROID, ANDROID_TV, FIRE_TV, ANDROID_WEAR, PARAMS } from '../../core/constants'; import PlatformSetup from '../../core/setupManager'; -import { RnvConfig } from '../../core/configManager/types'; +import { RnvContext } from '../../core/configManager/types'; -export const taskRnvFastlane = async (c: RnvConfig) => { +export const taskRnvFastlane = async (c: RnvContext) => { const args = getCliArguments(c); args.shift(); // we know the first one is fastlane, trash it diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts b/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts index 70ca37793e..3d44b7c804 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts @@ -7,13 +7,13 @@ import { configureRuntimeDefaults } from '../../core/runtimeManager'; import { PARAMS, TASK_KILL, TASK_APP_CONFIGURE } from '../../core/constants'; import { RnvTaskFn } from '../../core/taskManager/types'; -import { RnvConfig } from '../../core/configManager/types'; +import { RnvContext } from '../../core/configManager/types'; export const taskRnvKill: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvKill'); - const usedPorts: RnvConfig['runtime']['supportedPlatforms'] = []; - let platArray: RnvConfig['runtime']['supportedPlatforms'] = []; + const usedPorts: RnvContext['runtime']['supportedPlatforms'] = []; + let platArray: RnvContext['runtime']['supportedPlatforms'] = []; const results = []; let ports: Record = {}; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.link.ts b/packages/rnv/src/engine-core/tasks/task.rnv.link.ts index e98cd9c269..3565fc4ee1 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.link.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.link.ts @@ -3,9 +3,9 @@ import { logInfo, logTask, logSuccess } from '../../core/systemManager/logger'; import { PARAMS, RNV_PACKAGES } from '../../core/constants'; import { fsExistsSync, fsRenameSync, fsSymlinkSync } from '../../core/systemManager/fileutils'; import { RnvTaskFn } from '../../core/taskManager/types'; -import { RnvConfig } from '../../core/configManager/types'; +import { RnvContext } from '../../core/configManager/types'; -const _linkPackage = (c: RnvConfig, key: string, folder: string) => { +const _linkPackage = (c: RnvContext, key: string, folder: string) => { const rnvPath = path.join(c.paths.project.nodeModulesDir, key); const rnvPathUnlinked = path.join(c.paths.project.nodeModulesDir, `${key}_unlinked`); const pkgDir = path.join(c.paths.rnv.dir, '../', folder); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.new.ts b/packages/rnv/src/engine-core/tasks/task.rnv.new.ts index b98c166e44..5d0a81cbec 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.new.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.new.ts @@ -33,7 +33,7 @@ import { printIntoBox, } from '../../core/systemManager/logger'; import { isYarnInstalled, listAndSelectNpmVersion } from '../../core/systemManager/npmUtils'; -import { RenativeConfigFile, RnvConfig } from '../../core/configManager/types'; +import { RenativeConfigFile, RnvContext } from '../../core/configManager/types'; const highlight = chalk().green; @@ -79,7 +79,7 @@ type NewProjectData = { inputWorkspace?: string; }; -const _prepareProjectOverview = (c: RnvConfig, data: NewProjectData) => { +const _prepareProjectOverview = (c: RnvContext, data: NewProjectData) => { data.appTitle = data.inputAppTitle || data.defaultAppTitle; data.teamID = ''; data.appID = data.inputAppID ? data.inputAppID.replace(/\s+/g, '-').toLowerCase() : data.appID; @@ -206,7 +206,7 @@ const interactiveQuestion = async ( } }; -export const taskRnvNew = async (c: RnvConfig) => { +export const taskRnvNew = async (c: RnvContext) => { logTask('taskRnvNew'); const { ci, @@ -678,7 +678,7 @@ export const taskRnvNew = async (c: RnvConfig) => { ); }; -const findEngineKeyById = (c: RnvConfig, id: string) => { +const findEngineKeyById = (c: RnvContext, id: string) => { const { engineTemplates } = c.files.rnv.projectTemplates.config; const etk = Object.keys(engineTemplates); for (let i = 0; i < etk.length; i++) { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.template.add.ts b/packages/rnv/src/engine-core/tasks/task.rnv.template.add.ts index 34a4f96e6e..51d0379eb3 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.template.add.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.template.add.ts @@ -6,15 +6,15 @@ import { executeTask } from '../../core/taskManager'; import { TASK_PROJECT_CONFIGURE, TASK_TEMPLATE_ADD, PARAMS } from '../../core/constants'; import { getTemplateOptions } from '../../core/templateManager'; -import { RnvConfig } from '../../core/configManager/types'; +import { RnvContext } from '../../core/configManager/types'; import { RnvTaskFn } from '../../core/taskManager/types'; -const _writeObjectSync = (c: RnvConfig, p: string, s: string) => { +const _writeObjectSync = (c: RnvContext, p: string, s: string) => { writeFileSync(p, s); generateBuildConfig(c); }; -export const _addTemplate = (c: RnvConfig, template: string) => { +export const _addTemplate = (c: RnvContext, template: string) => { logTask('addTemplate'); c.files.project.config.templates = c.files.project.config.templates || {}; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.unlink.ts b/packages/rnv/src/engine-core/tasks/task.rnv.unlink.ts index df4e32c7c2..ac54af014d 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.unlink.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.unlink.ts @@ -3,9 +3,9 @@ import { logInfo, logTask, logSuccess } from '../../core/systemManager/logger'; import { PARAMS, RNV_PACKAGES } from '../../core/constants'; import { fsExistsSync, fsRenameSync, fsUnlinkSync, fsLstatSync } from '../../core/systemManager/fileutils'; import { RnvTaskFn } from '../../core/taskManager/types'; -import { RnvConfig } from '../../core/configManager/types'; +import { RnvContext } from '../../core/configManager/types'; -const _unlinkPackage = (c: RnvConfig, key: string) => { +const _unlinkPackage = (c: RnvContext, key: string) => { const rnvPath = path.join(c.paths.project.nodeModulesDir, key); const rnvPathUnlinked = path.join(c.paths.project.nodeModulesDir, `${key}_unlinked`); From e83b73a5cc23e67b1ef117cf788bb0e81124b65f Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Sun, 3 Sep 2023 02:16:34 +0200 Subject: [PATCH 43/83] split config and context types --- packages/rnv/src/cli/index.ts | 2 +- packages/rnv/src/cli/prompt.ts | 2 +- packages/rnv/src/core/common.ts | 3 +- packages/rnv/src/core/configManager/index.ts | 21 +- .../src/core/configManager/packageParser.ts | 2 +- .../src/core/configManager/schemeParser.ts | 2 +- packages/rnv/src/core/configManager/types.ts | 262 +----------------- packages/rnv/src/core/constants.ts | 3 +- .../config.ts => context/context.ts} | 2 +- .../configBase.ts => context/contextBase.ts} | 6 +- packages/rnv/src/core/context/types.ts | 248 +++++++++++++++++ packages/rnv/src/core/engineManager/index.ts | 2 +- packages/rnv/src/core/engineManager/types.ts | 2 +- .../rnv/src/core/integrationManager/index.ts | 2 +- .../rnv/src/core/platformManager/index.ts | 2 +- packages/rnv/src/core/pluginManager/index.ts | 3 +- .../rnv/src/core/projectManager/buildHooks.ts | 2 +- packages/rnv/src/core/projectManager/index.ts | 3 +- .../rnv/src/core/projectManager/package.ts | 2 +- .../rnv/src/core/projectManager/workspace.ts | 2 +- packages/rnv/src/core/runtimeManager/index.ts | 4 +- .../core/sdkManager/deviceUtils/android.ts | 2 +- .../src/core/sdkManager/deviceUtils/apple.ts | 2 +- .../src/core/sdkManager/deviceUtils/common.ts | 2 +- .../src/core/sdkManager/deviceUtils/kaios.ts | 2 +- .../src/core/sdkManager/deviceUtils/tizen.ts | 2 +- .../src/core/sdkManager/deviceUtils/webos.ts | 2 +- packages/rnv/src/core/sdkManager/installer.ts | 2 +- packages/rnv/src/core/setupManager/base.ts | 4 +- packages/rnv/src/core/setupManager/darwin.ts | 2 +- packages/rnv/src/core/setupManager/index.ts | 4 +- packages/rnv/src/core/setupManager/linux.ts | 2 +- packages/rnv/src/core/setupManager/windows.ts | 2 +- .../rnv/src/core/systemManager/analytics.ts | 2 +- packages/rnv/src/core/systemManager/crypto.ts | 2 +- packages/rnv/src/core/systemManager/doctor.ts | 2 +- packages/rnv/src/core/systemManager/exec.ts | 4 +- .../rnv/src/core/systemManager/fileutils.ts | 2 +- .../rnv/src/core/systemManager/gitUtils.ts | 2 +- packages/rnv/src/core/systemManager/logger.ts | 2 +- .../rnv/src/core/systemManager/npmUtils.ts | 2 +- packages/rnv/src/core/systemManager/utils.ts | 2 +- packages/rnv/src/core/taskManager/index.ts | 2 +- packages/rnv/src/core/taskManager/types.ts | 2 +- .../rnv/src/core/templateManager/index.ts | 2 +- packages/rnv/src/core/types.ts | 2 +- .../tasks/task.rnv.app.configure.ts | 2 +- .../src/engine-core/tasks/task.rnv.config.ts | 2 +- .../tasks/task.rnv.crypto.decrypt.ts | 2 +- .../tasks/task.rnv.crypto.encrypt.ts | 2 +- .../engine-core/tasks/task.rnv.fastlane.ts | 2 +- .../src/engine-core/tasks/task.rnv.kill.ts | 2 +- .../src/engine-core/tasks/task.rnv.link.ts | 2 +- .../rnv/src/engine-core/tasks/task.rnv.new.ts | 3 +- .../rnv/src/engine-core/tasks/task.rnv.pkg.ts | 2 +- .../src/engine-core/tasks/task.rnv.publish.ts | 2 +- .../tasks/task.rnv.template.add.ts | 2 +- .../src/engine-core/tasks/task.rnv.unlink.ts | 2 +- packages/rnv/src/index.ts | 2 +- 59 files changed, 327 insertions(+), 333 deletions(-) rename packages/rnv/src/core/{configManager/config.ts => context/context.ts} (98%) rename packages/rnv/src/core/{configManager/configBase.ts => context/contextBase.ts} (95%) diff --git a/packages/rnv/src/cli/index.ts b/packages/rnv/src/cli/index.ts index d8159ef01c..b6da202962 100644 --- a/packages/rnv/src/cli/index.ts +++ b/packages/rnv/src/cli/index.ts @@ -7,7 +7,7 @@ import { loadIntegrations } from '../core/integrationManager'; import { initializeTask, findSuitableTask } from '../core/taskManager'; import EngineCore from '../engine-core'; -import { RnvContext } from '../core/configManager/types'; +import { RnvContext } from '../core/context/types'; const IGNORE_MISSING_ENGINES_TASKS = ['link', 'unlink']; diff --git a/packages/rnv/src/cli/prompt.ts b/packages/rnv/src/cli/prompt.ts index e445f4e247..65d37394bb 100644 --- a/packages/rnv/src/cli/prompt.ts +++ b/packages/rnv/src/cli/prompt.ts @@ -1,6 +1,6 @@ import inquirer from 'inquirer'; import { chalk, logWarning, logTask, logDebug } from '../core/systemManager/logger'; -import Config from '../core/configManager/config'; +import Config from '../core/context/context'; import { PromptOptions, PromptParams, PromptRenderFn } from './types'; export const inquirerPrompt = async (params: PromptParams): Promise> => { diff --git a/packages/rnv/src/core/common.ts b/packages/rnv/src/core/common.ts index 625e45557e..9763531fe3 100755 --- a/packages/rnv/src/core/common.ts +++ b/packages/rnv/src/core/common.ts @@ -10,9 +10,10 @@ import { CLI_PROPS } from './constants'; import { fsExistsSync, writeCleanFile } from './systemManager/fileutils'; import { chalk, logError, logTask, logWarning } from './systemManager/logger'; import { getValidLocalhost } from './systemManager/utils'; -import { RenativeConfigBuildScheme, RenativeConfigFile, RnvContext } from './configManager/types'; +import { RnvContext } from './context/types'; import { GetConfigPropFn } from './types'; import { OverridesOptions, TimestampPathsConfig } from './systemManager/types'; +import { RenativeConfigBuildScheme, RenativeConfigFile } from './configManager/types'; export const getTimestampPathsConfig = (c: RnvContext, platform: string): TimestampPathsConfig | undefined => { let timestampBuildFiles: Array = []; diff --git a/packages/rnv/src/core/configManager/index.ts b/packages/rnv/src/core/configManager/index.ts index 1f4dc97476..7c2908c6be 100644 --- a/packages/rnv/src/core/configManager/index.ts +++ b/packages/rnv/src/core/configManager/index.ts @@ -35,8 +35,9 @@ import { getConfigProp } from '../common'; import { getWorkspaceDirPath } from '../projectManager/workspace'; import { chalk, logError, logTask, logWarning, logDebug } from '../systemManager/logger'; import { doResolve } from '../systemManager/resolve'; -import { RnvConfigFileObj, RnvConfigPathObj, RnvContext, RnvFileKey } from './types'; -import { generateConfigBase, generateRnvConfigPathObj } from './configBase'; +import { RnvContextFileObj, RnvContextPathObj, RnvContext } from '../context/types'; +import { generateConfigBase, generateRnvConfigPathObj } from '../context/contextBase'; +import { RnvFileKey } from './types'; // import { loadPluginTemplates } from '../pluginManager'; const IGNORE_FOLDERS = ['.git']; @@ -54,7 +55,7 @@ export const checkIsRenativeProject = (c: RnvContext) => return resolve(true); }); -const _generateConfigPaths = (pathObj: RnvConfigPathObj, dir: string, configName?: string) => { +const _generateConfigPaths = (pathObj: RnvContextPathObj, dir: string, configName?: string) => { pathObj.dir = dir; pathObj.config = path.join(dir, configName || RENATIVE_CONFIG_NAME); pathObj.configLocal = path.join(dir, RENATIVE_CONFIG_LOCAL_NAME); @@ -223,7 +224,7 @@ export const generateBuildConfig = (c: RnvContext) => { export const loadFileExtended = ( c: RnvContext, fileObj: Record, - pathObj: RnvConfigPathObj, + pathObj: RnvContextPathObj, key: RnvFileKey ) => { const result = loadFile(fileObj, pathObj, key); @@ -270,8 +271,8 @@ export const loadFileExtended = ( const _loadConfigFiles = ( c: RnvContext, - fileObj: RnvConfigFileObj, - pathObj: RnvConfigPathObj, + fileObj: RnvContextFileObj, + pathObj: RnvContextPathObj, parseAppConfigs?: boolean ) => { let result = false; @@ -302,7 +303,7 @@ const _loadConfigFiles = ( fileObj.configs = []; fileObj.configsLocal = []; fileObj.configsPrivate = []; - const fileObj1: RnvConfigFileObj = { + const fileObj1: RnvContextFileObj = { configs: [], configsLocal: [], configsPrivate: [], @@ -311,7 +312,7 @@ const _loadConfigFiles = ( // PATH1: appConfigs/base const path1 = path.join(pathObj.appConfigsDir, 'base'); - const pathObj1: RnvConfigPathObj = { + const pathObj1: RnvContextPathObj = { ...generateRnvConfigPathObj(), config: path.join(path1, RENATIVE_CONFIG_NAME), configLocal: path.join(path1, RENATIVE_CONFIG_LOCAL_NAME), @@ -335,13 +336,13 @@ const _loadConfigFiles = ( const appConfigsDirNames = fsReaddirSync(pathObj.appConfigsDir); if (parseAppConfigs && extendAppId && appConfigsDirNames.includes(extendAppId)) { const path2 = path.join(pathObj.appConfigsDir, extendAppId); - const pathObj2: RnvConfigPathObj = { + const pathObj2: RnvContextPathObj = { ...generateRnvConfigPathObj(), config: path.join(path2, RENATIVE_CONFIG_NAME), configLocal: path.join(path2, RENATIVE_CONFIG_LOCAL_NAME), configPrivate: path.join(path2, RENATIVE_CONFIG_PRIVATE_NAME), }; - const fileObj2: RnvConfigFileObj = { + const fileObj2: RnvContextFileObj = { configs: [], configsLocal: [], configsPrivate: [], diff --git a/packages/rnv/src/core/configManager/packageParser.ts b/packages/rnv/src/core/configManager/packageParser.ts index bf4809b792..023cb20a84 100644 --- a/packages/rnv/src/core/configManager/packageParser.ts +++ b/packages/rnv/src/core/configManager/packageParser.ts @@ -10,7 +10,7 @@ import { writeRenativeConfigFile } from './index'; import { overrideTemplatePlugins } from '../pluginManager'; import { configureFonts } from '../projectManager'; import { getConfigProp } from '../common'; -import { RnvContext } from './types'; +import { RnvContext } from '../context/types'; const injectProjectDependency = async ( c: RnvContext, diff --git a/packages/rnv/src/core/configManager/schemeParser.ts b/packages/rnv/src/core/configManager/schemeParser.ts index 7d940b21f4..bdf7deba3e 100644 --- a/packages/rnv/src/core/configManager/schemeParser.ts +++ b/packages/rnv/src/core/configManager/schemeParser.ts @@ -1,7 +1,7 @@ import merge from 'deepmerge'; import { logError, logTask, logWarning, chalk, logInfo } from '../systemManager/logger'; import { inquirerPrompt } from '../../cli/prompt'; -import { RnvContext } from './types'; +import { RnvContext } from '../context/types'; export const isBuildSchemeSupported = async (c: RnvContext) => { logTask('isBuildSchemeSupported'); diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index ee8749fc43..d047dac310 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -1,255 +1,3 @@ -import { RnvEngine, RnvEnginePlatform } from '../engineManager/types'; -import { OverridesOptions } from '../systemManager/types'; -import { RnvPlatform } from '../types'; - -export interface RnvContext { - program: any; - command: string | null; - subCommand: string | null; - buildConfig: Partial & { - _meta?: { - currentAppConfigId: string; - }; - _refs?: any; - }; - assetConfig: object; - platform: RnvPlatform; - process: any; - rnvVersion: string; - _currentTask?: string; - systemPropsInjects: OverridesOptions; - _requiresNpmInstall?: boolean; - buildPipes: Record Promise>>; - isBuildHooksReady: boolean; - supportedPlatforms: Array; - runtimePropsInjects: OverridesOptions; - //======= - _renativePluginCache: any; - cli: any; - buildHooks: Record Promise>; - api: { - fsExistsSync: any; - fsReadFileSync: any; - fsReaddirSync: any; - fsWriteFileSync: any; - path: any; - }; - configPropsInjects: any; - runtime: { - platform: string; - appId: string | null; - appDir: string; - enginesByPlatform: Record; - enginesByIndex: Array; - enginesById: Record; - missingEnginePlugins: Record; - localhost: string; - scheme: string; - // scheme: { - // bundleAssets: boolean; - // }; - bundleAssets: boolean; - activeTemplate: string; - engine?: RnvEngine; - target: string; - supportedPlatforms: Array; - keepSessionActive: boolean; - platformBuildsProjectPath: string; - availablePlatforms: Array; - _platformBuildsSuffix?: string; - timestamp: number; - appConfigDir: string; - hasAllEnginesRegistered: boolean; - skipPackageUpdate?: boolean; - selectedTemplate?: string; - runtimeExtraProps: string; - requiresBootstrap: boolean; - currentTemplate: string; - requiresForcedTemplateApply: boolean; - forceBuildHookRebuild: boolean; - disableReset: boolean; - skipActiveServerCheck: boolean; - port: string; - rnvVersionRunner: string; - rnvVersionProject: string; - versionCheckCompleted: boolean; - currentPlatform: RnvEnginePlatform; - _skipPluginScopeWarnings: boolean; - skipBuildHooks: boolean; - isFirstRunAfterNew: boolean; - currentEngine: RnvEngine; - hosted: boolean; - task: string; - selectedWorkspace: string; - isWSConfirmed: boolean; - }; - paths: { - GLOBAL_RNV_CONFIG: string; - GLOBAL_RNV_DIR: string; - //======= - rnv: { - configWorkspaces: any; - pluginTemplates: { - configs: Record; - //ADDON - dir?: string; - config?: string; - dirs: Record; - }; - platformTemplates: Record; - projectTemplates: Record; - platformTemplate: Record; - plugins: Record; - engines: Record; - projectTemplate: Record; - //ADDON - dir: string; - package: string; - }; - workspace: RnvConfigPathObj & { - project: RnvConfigPathObj & { - appConfigBase: Record; - builds: Record; - assets: Record; - platformTemplates: Record; - appConfigsDirs: Array; - appConfigsDirNames: Array; - }; - appConfig: RnvConfigPathObj; - }; - defaultWorkspace: RnvConfigPathObj & { - project: { - appConfigBase: Record; - builds: Record; - assets: Record; - platformTemplates: Record; - appConfigsDirs: Array; - appConfigsDirNames: Array; - }; - appConfig: { - configs: Array; - configsPrivate: Array; - configsLocal: Array; - }; - }; - project: RnvConfigPathObj & { - appConfigBase: Record; - builds: Record; - assets: Record; - platformTemplates: Record; - appConfigsDirs: Array; - appConfigsDirNames: Array; - //ADDON - dir: string; - nodeModulesDir: string; - srcDir?: string; - package?: string; - rnCliConfig?: string; - babelConfig?: string; - platformTemplatesDirs: Record; - }; - appConfig: RnvConfigPathObj; - // EXTRA - buildHooks: { - dist: Record; - //ADDON - dir: string; - index: string; - }; - home: Record; - template: { - appConfigBase: Record; - builds: Record; - assets: Record; - platformTemplates: Record; - appConfigsDir: string; - configTemplate: string; - config: string; - dir: string; - }; - appConfigBase: string; - }; - files: { - rnv: { - pluginTemplates: Record; - platformTemplates: Record; - projectTemplates: Record; - platformTemplate: Record; - plugins: Record; - engines: Record; - projectTemplate: Record; - //ADDON - configWorkspaces: any; - package: any; - }; - workspace: RnvConfigFileObj & { - project: RnvConfigFileObj & { - appConfigBase: Record; - builds: Record; - assets: Record; - platformTemplates: Record; - }; - appConfig: RnvConfigFileObj; - }; - defaultWorkspace: RnvConfigFileObj & { - project: RnvConfigFileObj & { - appConfigBase: Record; - builds: Record; - assets: Record; - platformTemplates: Record; - }; - appConfig: RnvConfigFileObj; - }; - project: RnvConfigFileObj & { - appConfigBase: Record; - builds: Record; - assets: Record; - platformTemplates: Record; - //ADDON - package: any; - }; - appConfig: RnvConfigFileObj; - }; -} - -export type RnvFileKey = 'config' | 'configLocal' | 'configPrivate'; - -export type DependencyType = 'devDependencies' | 'dependencies' | 'peerDependencies'; - -export type RnvConfigSchema = Record; - -export interface RnvConfigPathObj { - dir: string; - config: string; - configLocal: string; - configPrivate: string; - appConfigsDir: string; - fontsDir: string; - dirs: Array; - fontsDirs: Array; - pluginDirs: Array; - configs: Array; - configsLocal: Array; - configsPrivate: Array; - configExists?: boolean; - // appConfigBase: Record; - // builds: Record; - // assets: Record; - // platformTemplates: Record; - // appConfigsDirs: Array; - // appConfigsDirNames: Array; -} - -export interface RnvConfigFileObj { - config?: any; - config_original?: any; - configLocal?: any; - configPrivate?: any; - configs: Array; - configsLocal: Array; - configsPrivate: Array; -} - export type RenativeConfigFile = { sdks?: Record; workspaceID: string; @@ -322,14 +70,6 @@ export type RenativeConfigPlugin = { props?: Record; }; -export type RnvConfigPlatform = { - platform: string; - isConnected: boolean; - engine?: any; - port?: string; - isValid?: boolean; -}; - export type RenativeWebpackConfig = { modulePaths?: | Array< @@ -354,6 +94,8 @@ export type RenativeWebpackConfig = { export type RenativeConfigBuildScheme = Record; +export type RnvFileKey = 'config' | 'configLocal' | 'configPrivate'; + export type NpmPackageFile = { devDependencies: Record; dependencies: Record; diff --git a/packages/rnv/src/core/constants.ts b/packages/rnv/src/core/constants.ts index 8fe818479f..1dcd25ab94 100644 --- a/packages/rnv/src/core/constants.ts +++ b/packages/rnv/src/core/constants.ts @@ -1,7 +1,6 @@ // PLATFORM import { homedir } from 'os'; import path from 'path'; -import { RnvConfigSchema } from './configManager/types'; import { RnvTaskParameter } from './taskManager/types'; export const USER_HOME_DIR = homedir(); @@ -541,7 +540,7 @@ export const PARAMS = { all: Object.keys(PARAM_KEYS), }; -export const configSchema: RnvConfigSchema = { +export const configSchema: Record = { analytics: { values: ['true', 'false'], key: 'enableAnalytics', diff --git a/packages/rnv/src/core/configManager/config.ts b/packages/rnv/src/core/context/context.ts similarity index 98% rename from packages/rnv/src/core/configManager/config.ts rename to packages/rnv/src/core/context/context.ts index f7799d8bf3..65f14e8c66 100644 --- a/packages/rnv/src/core/configManager/config.ts +++ b/packages/rnv/src/core/context/context.ts @@ -2,7 +2,7 @@ import { writeFileSync, fsExistsSync } from '../systemManager/fileutils'; import { logWarning } from '../systemManager/logger'; import { configSchema } from '../constants'; import { RnvContext } from './types'; -import { generateConfigBase } from './configBase'; +import { generateConfigBase } from './contextBase'; class Config { config: RnvContext; diff --git a/packages/rnv/src/core/configManager/configBase.ts b/packages/rnv/src/core/context/contextBase.ts similarity index 95% rename from packages/rnv/src/core/configManager/configBase.ts rename to packages/rnv/src/core/context/contextBase.ts index 3c393bdc49..cb6b35e4b7 100644 --- a/packages/rnv/src/core/configManager/configBase.ts +++ b/packages/rnv/src/core/context/contextBase.ts @@ -1,9 +1,9 @@ import { fsExistsSync, fsReadFileSync, fsReaddirSync, fsWriteFileSync } from '../systemManager/fileutils'; import path from 'path'; -import { RnvContext, RnvConfigFileObj, RnvConfigPathObj } from './types'; +import { RnvContext, RnvContextFileObj, RnvContextPathObj } from './types'; -export const generateRnvConfigPathObj = (): RnvConfigPathObj => { +export const generateRnvConfigPathObj = (): RnvContextPathObj => { return { configs: [], configsPrivate: [], @@ -20,7 +20,7 @@ export const generateRnvConfigPathObj = (): RnvConfigPathObj => { }; }; -export const generateRnvConfigFileObj = (): RnvConfigFileObj => { +export const generateRnvConfigFileObj = (): RnvContextFileObj => { return { configs: [], configsLocal: [], diff --git a/packages/rnv/src/core/context/types.ts b/packages/rnv/src/core/context/types.ts index e69de29bb2..e4613874f7 100644 --- a/packages/rnv/src/core/context/types.ts +++ b/packages/rnv/src/core/context/types.ts @@ -0,0 +1,248 @@ +import { RenativeConfigFile } from '../configManager/types'; +import { RnvEngine, RnvEnginePlatform } from '../engineManager/types'; +import { OverridesOptions } from '../systemManager/types'; +import { RnvPlatform } from '../types'; + +export interface RnvContext { + program: any; + command: string | null; + subCommand: string | null; + buildConfig: Partial & { + _meta?: { + currentAppConfigId: string; + }; + _refs?: any; + }; + assetConfig: object; + platform: RnvPlatform; + process: any; + rnvVersion: string; + _currentTask?: string; + systemPropsInjects: OverridesOptions; + _requiresNpmInstall?: boolean; + buildPipes: Record Promise>>; + isBuildHooksReady: boolean; + supportedPlatforms: Array; + runtimePropsInjects: OverridesOptions; + //======= + _renativePluginCache: any; + cli: any; + buildHooks: Record Promise>; + api: { + fsExistsSync: any; + fsReadFileSync: any; + fsReaddirSync: any; + fsWriteFileSync: any; + path: any; + }; + configPropsInjects: any; + runtime: { + platform: string; + appId: string | null; + appDir: string; + enginesByPlatform: Record; + enginesByIndex: Array; + enginesById: Record; + missingEnginePlugins: Record; + localhost: string; + scheme: string; + // scheme: { + // bundleAssets: boolean; + // }; + bundleAssets: boolean; + activeTemplate: string; + engine?: RnvEngine; + target: string; + supportedPlatforms: Array; + keepSessionActive: boolean; + platformBuildsProjectPath: string; + availablePlatforms: Array; + _platformBuildsSuffix?: string; + timestamp: number; + appConfigDir: string; + hasAllEnginesRegistered: boolean; + skipPackageUpdate?: boolean; + selectedTemplate?: string; + runtimeExtraProps: string; + requiresBootstrap: boolean; + currentTemplate: string; + requiresForcedTemplateApply: boolean; + forceBuildHookRebuild: boolean; + disableReset: boolean; + skipActiveServerCheck: boolean; + port: string; + rnvVersionRunner: string; + rnvVersionProject: string; + versionCheckCompleted: boolean; + currentPlatform: RnvEnginePlatform; + _skipPluginScopeWarnings: boolean; + skipBuildHooks: boolean; + isFirstRunAfterNew: boolean; + currentEngine: RnvEngine; + hosted: boolean; + task: string; + selectedWorkspace: string; + isWSConfirmed: boolean; + }; + paths: { + GLOBAL_RNV_CONFIG: string; + GLOBAL_RNV_DIR: string; + //======= + rnv: { + configWorkspaces: any; + pluginTemplates: { + configs: Record; + //ADDON + dir?: string; + config?: string; + dirs: Record; + }; + platformTemplates: Record; + projectTemplates: Record; + platformTemplate: Record; + plugins: Record; + engines: Record; + projectTemplate: Record; + //ADDON + dir: string; + package: string; + }; + workspace: RnvContextPathObj & { + project: RnvContextPathObj & { + appConfigBase: Record; + builds: Record; + assets: Record; + platformTemplates: Record; + appConfigsDirs: Array; + appConfigsDirNames: Array; + }; + appConfig: RnvContextPathObj; + }; + defaultWorkspace: RnvContextPathObj & { + project: { + appConfigBase: Record; + builds: Record; + assets: Record; + platformTemplates: Record; + appConfigsDirs: Array; + appConfigsDirNames: Array; + }; + appConfig: { + configs: Array; + configsPrivate: Array; + configsLocal: Array; + }; + }; + project: RnvContextPathObj & { + appConfigBase: Record; + builds: Record; + assets: Record; + platformTemplates: Record; + appConfigsDirs: Array; + appConfigsDirNames: Array; + //ADDON + dir: string; + nodeModulesDir: string; + srcDir?: string; + package?: string; + rnCliConfig?: string; + babelConfig?: string; + platformTemplatesDirs: Record; + }; + appConfig: RnvContextPathObj; + // EXTRA + buildHooks: { + dist: Record; + //ADDON + dir: string; + index: string; + }; + home: Record; + template: { + appConfigBase: Record; + builds: Record; + assets: Record; + platformTemplates: Record; + appConfigsDir: string; + configTemplate: string; + config: string; + dir: string; + }; + appConfigBase: string; + }; + files: { + rnv: { + pluginTemplates: Record; + platformTemplates: Record; + projectTemplates: Record; + platformTemplate: Record; + plugins: Record; + engines: Record; + projectTemplate: Record; + //ADDON + configWorkspaces: any; + package: any; + }; + workspace: RnvContextFileObj & { + project: RnvContextFileObj & { + appConfigBase: Record; + builds: Record; + assets: Record; + platformTemplates: Record; + }; + appConfig: RnvContextFileObj; + }; + defaultWorkspace: RnvContextFileObj & { + project: RnvContextFileObj & { + appConfigBase: Record; + builds: Record; + assets: Record; + platformTemplates: Record; + }; + appConfig: RnvContextFileObj; + }; + project: RnvContextFileObj & { + appConfigBase: Record; + builds: Record; + assets: Record; + platformTemplates: Record; + //ADDON + package: any; + }; + appConfig: RnvContextFileObj; + }; +} + +export interface RnvContextPathObj { + dir: string; + config: string; + configLocal: string; + configPrivate: string; + appConfigsDir: string; + fontsDir: string; + dirs: Array; + fontsDirs: Array; + pluginDirs: Array; + configs: Array; + configsLocal: Array; + configsPrivate: Array; + configExists?: boolean; +} + +export interface RnvContextFileObj { + config?: any; + config_original?: any; + configLocal?: any; + configPrivate?: any; + configs: Array; + configsLocal: Array; + configsPrivate: Array; +} + +export interface RnvContextPlatform { + platform: string; + isConnected: boolean; + engine?: any; + port?: string; + isValid?: boolean; +} diff --git a/packages/rnv/src/core/engineManager/index.ts b/packages/rnv/src/core/engineManager/index.ts index 4b01aaa999..04b981a4ad 100644 --- a/packages/rnv/src/core/engineManager/index.ts +++ b/packages/rnv/src/core/engineManager/index.ts @@ -9,7 +9,7 @@ import { getScopedVersion } from '../systemManager/utils'; import { writeRenativeConfigFile } from '../configManager'; import { configurePlugins } from '../pluginManager'; import { inquirerPrompt } from '../../cli/prompt'; -import { RnvContext } from '../configManager/types'; +import { RnvContext } from '../context/types'; import { RnvTask, RnvTaskMap } from '../taskManager/types'; import { RnvModuleConfig, RnvNextJSConfig, RnvPlatform } from '../types'; import { RenativeEngineConfig, RnvEngine, RnvEngineConfig, RnvEngineConfigMap, RnvEngineInstallConfig } from './types'; diff --git a/packages/rnv/src/core/engineManager/types.ts b/packages/rnv/src/core/engineManager/types.ts index 64ff6a5582..b828d2b664 100644 --- a/packages/rnv/src/core/engineManager/types.ts +++ b/packages/rnv/src/core/engineManager/types.ts @@ -1,4 +1,4 @@ -import { RnvContext } from '../configManager/types'; +import { RnvContext } from '../context/types'; import { RnvTaskMap } from '../taskManager/types'; export type RnvEngine = { diff --git a/packages/rnv/src/core/integrationManager/index.ts b/packages/rnv/src/core/integrationManager/index.ts index e3a7f57107..e1c7fa8ebe 100644 --- a/packages/rnv/src/core/integrationManager/index.ts +++ b/packages/rnv/src/core/integrationManager/index.ts @@ -1,5 +1,5 @@ import path from 'path'; -import { RnvContext } from '../configManager/types'; +import { RnvContext } from '../context/types'; import { fsExistsSync } from '../systemManager/fileutils'; // import { getScopedVersion } from '../systemManager/utils'; import { logTask, logWarning } from '../systemManager/logger'; diff --git a/packages/rnv/src/core/platformManager/index.ts b/packages/rnv/src/core/platformManager/index.ts index 71c8987c90..c0fcb8a4b9 100644 --- a/packages/rnv/src/core/platformManager/index.ts +++ b/packages/rnv/src/core/platformManager/index.ts @@ -5,7 +5,7 @@ import { cleanFolder, copyFolderContentsRecursiveSync, writeFileSync } from '../ import { checkAndConfigureSdks } from '../sdkManager/installer'; import { getTimestampPathsConfig, getPlatformBuildDir, getAppFolder } from '../common'; import { SUPPORTED_PLATFORMS } from '../constants'; -import { RnvContext } from '../configManager/types'; +import { RnvContext } from '../context/types'; export const logErrorPlatform = (c: RnvContext) => { logError( diff --git a/packages/rnv/src/core/pluginManager/index.ts b/packages/rnv/src/core/pluginManager/index.ts index 7dc8871b2e..82fbfdc388 100644 --- a/packages/rnv/src/core/pluginManager/index.ts +++ b/packages/rnv/src/core/pluginManager/index.ts @@ -19,9 +19,10 @@ import { import { chalk, logDebug, logError, logInfo, logSuccess, logTask, logWarning } from '../systemManager/logger'; import { installPackageDependencies } from '../systemManager/npmUtils'; import { doResolve, doResolvePath } from '../systemManager/resolve'; -import { RenativeConfigPlugin, RenativeWebpackConfig, RnvContext } from '../configManager/types'; +import { RnvContext } from '../context/types'; import { ResolveOptions } from '../systemManager/types'; import { PluginCallback, PluginListResponse, RnvPlugin, RnvPluginPlatform, RnvPluginScope } from './types'; +import { RenativeConfigPlugin, RenativeWebpackConfig } from '../configManager/types'; export const getPluginList = (c: RnvContext, isUpdate = false) => { const output: PluginListResponse = { diff --git a/packages/rnv/src/core/projectManager/buildHooks.ts b/packages/rnv/src/core/projectManager/buildHooks.ts index 28e18ce13f..9fe2b93d7f 100644 --- a/packages/rnv/src/core/projectManager/buildHooks.ts +++ b/packages/rnv/src/core/projectManager/buildHooks.ts @@ -5,7 +5,7 @@ import { logDebug, logError, logHook, logInfo } from '../systemManager/logger'; import { fsExistsSync, copyFolderContentsRecursiveSync } from '../systemManager/fileutils'; import { getConfigProp } from '../common'; import { doResolve } from '../systemManager/resolve'; -import { RnvContext } from '../configManager/types'; +import { RnvContext } from '../context/types'; export const executePipe = async (c: RnvContext, key: string) => { logHook('executePipe', c?.program?.json ? key : `('${key}')`); diff --git a/packages/rnv/src/core/projectManager/index.ts b/packages/rnv/src/core/projectManager/index.ts index 01261afc58..6105c00411 100644 --- a/packages/rnv/src/core/projectManager/index.ts +++ b/packages/rnv/src/core/projectManager/index.ts @@ -32,10 +32,11 @@ import { chalk, logTask, logWarning, logDebug, logInfo, getCurrentCommand } from import { configureTemplateFiles, configureEntryPoint } from '../templateManager'; import { parseRenativeConfigs } from '../configManager'; -import { NpmPackageFile, RenativeConfigFile, RnvContext } from '../configManager/types'; +import { RnvContext } from '../context/types'; import { RnvPlatform } from '../types'; import { ParseFontsCallback } from './types'; import { RnvPluginPlatform } from '../pluginManager/types'; +import { NpmPackageFile, RenativeConfigFile } from '../configManager/types'; export const checkAndBootstrapIfRequired = async (c: RnvContext) => { logTask('checkAndBootstrapIfRequired'); diff --git a/packages/rnv/src/core/projectManager/package.ts b/packages/rnv/src/core/projectManager/package.ts index 4416a0b351..dda873d040 100644 --- a/packages/rnv/src/core/projectManager/package.ts +++ b/packages/rnv/src/core/projectManager/package.ts @@ -1,7 +1,7 @@ import path from 'path'; import semver from 'semver'; -import Config from '../configManager/config'; +import Config from '../context/context'; import { executeAsync } from '../systemManager/exec'; import { copyFileSync, diff --git a/packages/rnv/src/core/projectManager/workspace.ts b/packages/rnv/src/core/projectManager/workspace.ts index a94a47458d..3b95db69c4 100644 --- a/packages/rnv/src/core/projectManager/workspace.ts +++ b/packages/rnv/src/core/projectManager/workspace.ts @@ -2,7 +2,7 @@ import path from 'path'; import { generateOptions, inquirerPrompt } from '../../cli/prompt'; import { chalk, logTask, logWarning, logDebug, logInfo } from '../systemManager/logger'; import { writeFileSync, mkdirSync, fsExistsSync } from '../systemManager/fileutils'; -import { RnvContext } from '../configManager/types'; +import { RnvContext } from '../context/types'; export const createWorkspace = async (c: RnvContext, workspaceID: string, workspacePath: string) => { c.files.rnv.configWorkspaces.workspaces[workspaceID] = { diff --git a/packages/rnv/src/core/runtimeManager/index.ts b/packages/rnv/src/core/runtimeManager/index.ts index 1a3568bdad..68d435a8d8 100644 --- a/packages/rnv/src/core/runtimeManager/index.ts +++ b/packages/rnv/src/core/runtimeManager/index.ts @@ -6,7 +6,7 @@ import { getConfigProp } from '../common'; import { logTask } from '../systemManager/logger'; import { loadPluginTemplates } from '../pluginManager'; import { parseRenativeConfigs } from '../configManager/index'; -import { RnvContext, RnvConfigPlatform } from '../configManager/types'; +import { RnvContext, RnvContextPlatform } from '../context/types'; export const updateRenativeConfigs = async (c: RnvContext) => { await loadPluginTemplates(c); @@ -72,7 +72,7 @@ export const configureRuntimeDefaults = async (c: RnvContext) => { isConnected = pDir?.includes?.(getRealPath(c, dir) || 'UNDEFINED'); } const port = c.buildConfig.defaults?.ports?.[platform] || c.runtime.currentPlatform?.defaultPort; - const cp: RnvConfigPlatform = { + const cp: RnvContextPlatform = { engine, platform, isConnected, diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/android.ts b/packages/rnv/src/core/sdkManager/deviceUtils/android.ts index 00d3aea39b..ca30658d07 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/android.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/android.ts @@ -28,7 +28,7 @@ import { CLI_ANDROID_SDKMANAGER, USER_HOME_DIR, } from '../../constants'; -import { RnvContext } from '../../configManager/types'; +import { RnvContext } from '../../context/types'; import { AndroidDevice } from '../types'; const CHECK_INTEVAL = 5000; diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts b/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts index 89992ba884..4446421340 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/apple.ts @@ -4,7 +4,7 @@ import { chalk, logToSummary, logTask, logWarning, logDebug } from '../../system import { IOS, TVOS } from '../../constants'; import { executeAsync } from '../../systemManager/exec'; import { AppleDevice } from '../types'; -import { RnvContext } from '../../configManager/types'; +import { RnvContext } from '../../context/types'; export const getAppleDevices = async (c: RnvContext, ignoreDevices?: boolean, ignoreSimulators?: boolean) => { const { platform } = c; diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/common.ts b/packages/rnv/src/core/sdkManager/deviceUtils/common.ts index 8d3b81dce9..ad94892aed 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/common.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/common.ts @@ -1,5 +1,5 @@ import ora from '../../../cli/ora'; -import { RnvContext } from '../../configManager/types'; +import { RnvContext } from '../../context/types'; import { execCLI } from '../../systemManager/exec'; export const waitForEmulator = async ( diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/kaios.ts b/packages/rnv/src/core/sdkManager/deviceUtils/kaios.ts index e5e8881f90..9c66c9e884 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/kaios.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/kaios.ts @@ -1,7 +1,7 @@ import { fsExistsSync, getRealPath } from '../../systemManager/fileutils'; import { chalk, logTask } from '../../systemManager/logger'; import { KAIOS_SDK } from '../../constants'; -import { RnvContext } from '../../configManager/types'; +import { RnvContext } from '../../context/types'; import { RnvError } from '../../types'; const childProcess = require('child_process'); diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts index 92c61a2abc..03c33f9d9a 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts @@ -2,7 +2,7 @@ import inquirer from 'inquirer'; import net from 'net'; import path from 'path'; import { getConfigProp, getPlatformProjectDir } from '../../common'; -import { RnvContext } from '../../configManager/types'; +import { RnvContext } from '../../context/types'; import { CLI_SDB_TIZEN, CLI_TIZEN, CLI_TIZEN_EMULATOR, RENATIVE_CONFIG_NAME } from '../../constants'; import { execCLI } from '../../systemManager/exec'; import { fsRenameSync } from '../../systemManager/fileutils'; diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts b/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts index 9d91c0ac9a..7da7778f0f 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/webos.ts @@ -16,7 +16,7 @@ import { CLI_WEBOS_ARES_SETUP_DEVICE, } from '../../constants'; import { isSystemWin, isUrlLocalhost } from '../../systemManager/utils'; -import { RnvContext } from '../../configManager/types'; +import { RnvContext } from '../../context/types'; import { WebosDevice } from '../types'; export const launchWebOSimulator = (c: RnvContext) => { diff --git a/packages/rnv/src/core/sdkManager/installer.ts b/packages/rnv/src/core/sdkManager/installer.ts index 9ee4225cc3..5a6516ca4c 100644 --- a/packages/rnv/src/core/sdkManager/installer.ts +++ b/packages/rnv/src/core/sdkManager/installer.ts @@ -35,7 +35,7 @@ import { getRealPath, writeFileSync, fsExistsSync, fsReaddirSync, fsLstatSync } import { chalk, logTask, logWarning, logSuccess, logError, logInfo } from '../systemManager/logger'; import PlatformSetup from '../setupManager'; import { generateBuildConfig } from '../configManager'; -import { RnvContext } from '../configManager/types'; +import { RnvContext } from '../context/types'; const SDK_LOCATIONS: Record> = { android: [ diff --git a/packages/rnv/src/core/setupManager/base.ts b/packages/rnv/src/core/setupManager/base.ts index 1338cf2163..a640389c2e 100644 --- a/packages/rnv/src/core/setupManager/base.ts +++ b/packages/rnv/src/core/setupManager/base.ts @@ -7,9 +7,9 @@ import { TASK_WORKSPACE_CONFIGURE } from '../constants'; import { executeTask } from '../taskManager'; import { replaceHomeFolder, updateConfigFile } from '../systemManager/fileutils'; import _setupConfig from './config'; -import Config from '../configManager/config'; +import Config from '../context/context'; import { logTask, logError, logInfo, logDebug, logSuccess } from '../systemManager/logger'; -import { RnvContext } from '../configManager/types'; +import { RnvContext } from '../context/types'; const setupConfig: any = _setupConfig; class BasePlatformSetup { diff --git a/packages/rnv/src/core/setupManager/darwin.ts b/packages/rnv/src/core/setupManager/darwin.ts index 61951d9b8b..170aa8bcda 100644 --- a/packages/rnv/src/core/setupManager/darwin.ts +++ b/packages/rnv/src/core/setupManager/darwin.ts @@ -1,6 +1,6 @@ import { commandExistsSync, executeAsync } from '../systemManager/exec'; import BasePlatformSetup from './base'; -import Config from '../configManager/config'; +import Config from '../context/context'; class LinuxPlatformSetup extends BasePlatformSetup { constructor() { diff --git a/packages/rnv/src/core/setupManager/index.ts b/packages/rnv/src/core/setupManager/index.ts index df6ffdf96d..557e5407c4 100644 --- a/packages/rnv/src/core/setupManager/index.ts +++ b/packages/rnv/src/core/setupManager/index.ts @@ -1,8 +1,8 @@ import LinuxPlatformSetup from './linux'; import WindowsPlatformSetup from './windows'; import DarwinPlatformSetup from './darwin'; -import Config from '../configManager/config'; -import { RnvContext } from '../configManager/types'; +import Config from '../context/context'; +import { RnvContext } from '../context/types'; export default (_c: RnvContext) => { let c = _c; diff --git a/packages/rnv/src/core/setupManager/linux.ts b/packages/rnv/src/core/setupManager/linux.ts index 727a2b2567..be49f31bfa 100644 --- a/packages/rnv/src/core/setupManager/linux.ts +++ b/packages/rnv/src/core/setupManager/linux.ts @@ -7,7 +7,7 @@ import BasePlatformSetup from './base'; import { updateConfigFile, getRealPath } from '../systemManager/fileutils'; import setupConfig from './config'; import { CLI_ANDROID_ADB, CLI_ANDROID_AVDMANAGER, CLI_ANDROID_EMULATOR, CLI_ANDROID_SDKMANAGER } from '../constants'; -import { RnvContext } from '../configManager/types'; +import { RnvContext } from '../context/types'; class LinuxPlatformSetup extends BasePlatformSetup { constructor(c: RnvContext) { diff --git a/packages/rnv/src/core/setupManager/windows.ts b/packages/rnv/src/core/setupManager/windows.ts index 151dbf4994..fe68333c8f 100644 --- a/packages/rnv/src/core/setupManager/windows.ts +++ b/packages/rnv/src/core/setupManager/windows.ts @@ -9,7 +9,7 @@ import { logInfo, logDebug } from '../systemManager/logger'; import { replaceHomeFolder, fsExistsSync } from '../systemManager/fileutils'; import BasePlatformSetup from './base'; import setupConfig from './config'; -import { RnvContext } from '../configManager/types'; +import { RnvContext } from '../context/types'; class LinuxPlatformSetup extends BasePlatformSetup { scoopInstalled: boolean; diff --git a/packages/rnv/src/core/systemManager/analytics.ts b/packages/rnv/src/core/systemManager/analytics.ts index e62ee18c88..b4e6e861e9 100644 --- a/packages/rnv/src/core/systemManager/analytics.ts +++ b/packages/rnv/src/core/systemManager/analytics.ts @@ -4,7 +4,7 @@ import axios from 'axios'; import os from 'os'; import path from 'path'; -import Config from '../configManager/config'; +import Config from '../context/context'; //@ts-ignore import pkg from '../../../package.json'; import { REDASH_KEY, REDASH_URL, SENTRY_ENDPOINT } from '../constants'; diff --git a/packages/rnv/src/core/systemManager/crypto.ts b/packages/rnv/src/core/systemManager/crypto.ts index bcae7e420c..e587b984b5 100644 --- a/packages/rnv/src/core/systemManager/crypto.ts +++ b/packages/rnv/src/core/systemManager/crypto.ts @@ -4,7 +4,7 @@ import { isSystemWin } from './utils'; import { getRealPath, fsExistsSync, fsReadFileSync } from './fileutils'; import { TASK_CRYPTO_DECRYPT } from '../constants'; import { executeTask } from '../taskManager'; -import { RnvContext } from '../configManager/types'; +import { RnvContext } from '../context/types'; export const getEnvExportCmd = (envVar: string, key: string) => { if (isSystemWin) { diff --git a/packages/rnv/src/core/systemManager/doctor.ts b/packages/rnv/src/core/systemManager/doctor.ts index 154356745b..afb2cdc365 100644 --- a/packages/rnv/src/core/systemManager/doctor.ts +++ b/packages/rnv/src/core/systemManager/doctor.ts @@ -1,7 +1,7 @@ import { writeFileSync, readObjectSync } from './fileutils'; import { PACKAGE_JSON_FILEDS } from '../constants'; import { chalk, logWarning } from './logger'; -import { RnvContext } from '../configManager/types'; +import { RnvContext } from '../context/types'; const getSortedObject = (obj: any) => { if (obj !== null && typeof obj === 'object' && !Array.isArray(obj)) { diff --git a/packages/rnv/src/core/systemManager/exec.ts b/packages/rnv/src/core/systemManager/exec.ts index 42ff6f14e9..1932a0fcfd 100755 --- a/packages/rnv/src/core/systemManager/exec.ts +++ b/packages/rnv/src/core/systemManager/exec.ts @@ -5,12 +5,12 @@ import { access, accessSync, constants } from 'fs'; import execa, { ExecaChildProcess } from 'execa'; import NClient from 'netcat/client'; import ora from '../../cli/ora'; -import Config from '../configManager/config'; +import Config from '../context/context'; import { chalk, logDebug, logRaw, logError } from './logger'; import { fsExistsSync } from './fileutils'; import { replaceOverridesInString } from './utils'; -import { RnvContext } from '../configManager/types'; +import { RnvContext } from '../context/types'; import { ExecCallback, ExecCallback2, ExecOptions } from './types'; const { exec, execSync } = require('child_process'); diff --git a/packages/rnv/src/core/systemManager/fileutils.ts b/packages/rnv/src/core/systemManager/fileutils.ts index e1695bd17c..5fd6d50acb 100755 --- a/packages/rnv/src/core/systemManager/fileutils.ts +++ b/packages/rnv/src/core/systemManager/fileutils.ts @@ -6,7 +6,7 @@ import shelljs from 'shelljs'; import merge from 'deepmerge'; import ncp from 'ncp'; import { chalk, logDebug, logError, logWarning } from './logger'; -import { RnvContext } from '../configManager/types'; +import { RnvContext } from '../context/types'; import { DoResolveFn, FileUtilsPropConfig, diff --git a/packages/rnv/src/core/systemManager/gitUtils.ts b/packages/rnv/src/core/systemManager/gitUtils.ts index 6390038183..77f01522d5 100644 --- a/packages/rnv/src/core/systemManager/gitUtils.ts +++ b/packages/rnv/src/core/systemManager/gitUtils.ts @@ -1,5 +1,5 @@ import path from 'path'; -import { RnvContext } from '../configManager/types'; +import { RnvContext } from '../context/types'; import { executeAsync, commandExistsSync } from './exec'; import { fsExistsSync } from './fileutils'; import { logTask, logWarning, logInfo } from './logger'; diff --git a/packages/rnv/src/core/systemManager/logger.ts b/packages/rnv/src/core/systemManager/logger.ts index c66941e7f9..8206c8c7a9 100644 --- a/packages/rnv/src/core/systemManager/logger.ts +++ b/packages/rnv/src/core/systemManager/logger.ts @@ -1,6 +1,6 @@ /* eslint-disable no-console */ import _chalk, { Chalk } from 'chalk'; -import { RnvContext } from '../configManager/types'; +import { RnvContext } from '../context/types'; import { getChalk } from './chalk'; import { AnalyticsApi } from './types'; import { isSystemWin } from './utils'; diff --git a/packages/rnv/src/core/systemManager/npmUtils.ts b/packages/rnv/src/core/systemManager/npmUtils.ts index 31fed01c7e..ad308bb9c5 100644 --- a/packages/rnv/src/core/systemManager/npmUtils.ts +++ b/packages/rnv/src/core/systemManager/npmUtils.ts @@ -17,7 +17,7 @@ import { doResolve } from './resolve'; import { inquirerPrompt } from '../../cli/prompt'; import { getConfigProp } from '../common'; -import { RnvContext } from '../configManager/types'; +import { RnvContext } from '../context/types'; const packageJsonIsValid = (c: RnvContext) => { if (!fsExistsSync(c.paths.project.package)) return false; diff --git a/packages/rnv/src/core/systemManager/utils.ts b/packages/rnv/src/core/systemManager/utils.ts index d484192cc9..f0401c29ab 100644 --- a/packages/rnv/src/core/systemManager/utils.ts +++ b/packages/rnv/src/core/systemManager/utils.ts @@ -1,4 +1,4 @@ -import { RnvContext } from '../configManager/types'; +import { RnvContext } from '../context/types'; import { RenativeConfigVersion } from '../types'; export const isSystemMac = process.platform === 'darwin'; diff --git a/packages/rnv/src/core/taskManager/index.ts b/packages/rnv/src/core/taskManager/index.ts index c5575390e1..88af2eacff 100644 --- a/packages/rnv/src/core/taskManager/index.ts +++ b/packages/rnv/src/core/taskManager/index.ts @@ -12,7 +12,7 @@ import { registerAllPlatformEngines, } from '../engineManager'; import { TASK_CONFIGURE_SOFT } from '../constants'; -import { RnvContext } from '../configManager/types'; +import { RnvContext } from '../context/types'; import { RnvTask, RnvTaskMap, TaskItemMap, TaskObj } from './types'; import { RnvEngine } from '../engineManager/types'; diff --git a/packages/rnv/src/core/taskManager/types.ts b/packages/rnv/src/core/taskManager/types.ts index c5dc8ba01d..3bd9b089e8 100644 --- a/packages/rnv/src/core/taskManager/types.ts +++ b/packages/rnv/src/core/taskManager/types.ts @@ -1,4 +1,4 @@ -import { RnvContext } from '../configManager/types'; +import { RnvContext } from '../context/types'; export type RnvTask = { task: string; diff --git a/packages/rnv/src/core/templateManager/index.ts b/packages/rnv/src/core/templateManager/index.ts index 8eb848de13..257f3e3e19 100644 --- a/packages/rnv/src/core/templateManager/index.ts +++ b/packages/rnv/src/core/templateManager/index.ts @@ -20,7 +20,7 @@ import { getConfigProp } from '../common'; import { listAppConfigsFoldersSync, generateBuildConfig, loadFileExtended } from '../configManager'; import { doResolve } from '../systemManager/resolve'; import { checkIfProjectAndNodeModulesExists } from '../systemManager/npmUtils'; -import { RnvContext } from '../configManager/types'; +import { RnvContext } from '../context/types'; import { PromptOptions } from '../../cli/types'; export const checkIfTemplateConfigured = async (c: RnvContext) => { diff --git a/packages/rnv/src/core/types.ts b/packages/rnv/src/core/types.ts index ec730d7696..14e1631d86 100644 --- a/packages/rnv/src/core/types.ts +++ b/packages/rnv/src/core/types.ts @@ -1,4 +1,4 @@ -import { RnvContext } from './configManager/types'; +import { RnvContext } from './context/types'; export type RnvPlatform = string; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.app.configure.ts b/packages/rnv/src/engine-core/tasks/task.rnv.app.configure.ts index 61b65641b6..8526d46e3c 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.app.configure.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.app.configure.ts @@ -6,7 +6,7 @@ import { TASK_APP_CONFIGURE, PARAMS } from '../../core/constants'; import { writeFileSync, fsExistsSync, fsReadFileSync, fsRenameSync } from '../../core/systemManager/fileutils'; import { chalk, logError, logTask, logWarning, logDebug, logInfo, logAppInfo } from '../../core/systemManager/logger'; import { inquirerPrompt } from '../../cli/prompt'; -import { RnvContext } from '../../core/configManager/types'; +import { RnvContext } from '../../core/context/types'; const _loadAppConfigIDfromDir = (dirName: string, appConfigsDir: string) => { logDebug(`_loadAppConfigIDfromDir:${dirName}:${appConfigsDir}`, chalk().grey); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.config.ts b/packages/rnv/src/engine-core/tasks/task.rnv.config.ts index a081da4ec8..a15c5c2ea8 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.config.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.config.ts @@ -2,7 +2,7 @@ import { printTable } from 'console-table-printer'; import { logWarning, logTask } from '../../core/systemManager/logger'; import { configSchema, PARAMS } from '../../core/constants'; -import Config from '../../core/configManager/config'; +import Config from '../../core/context/context'; import { getCliArguments } from '../../core/common'; import { RnvTaskFn } from '../../core/taskManager/types'; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.crypto.decrypt.ts b/packages/rnv/src/engine-core/tasks/task.rnv.crypto.decrypt.ts index c33e77b92f..463b845c10 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.crypto.decrypt.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.crypto.decrypt.ts @@ -14,7 +14,7 @@ import { inquirerPrompt } from '../../cli/prompt'; import { getEnvVar, getEnvExportCmd } from '../../core/systemManager/crypto'; import { executeTask } from '../../core/taskManager'; import { TASK_CRYPTO_DECRYPT, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; -import { RnvContext } from '../../core/configManager/types'; +import { RnvContext } from '../../core/context/types'; import { RnvTaskFn } from '../../core/taskManager/types'; const iocane = require('iocane'); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts b/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts index 267fb4f7e4..d0bb8825d4 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.crypto.encrypt.ts @@ -16,7 +16,7 @@ import { inquirerPrompt } from '../../cli/prompt'; import { getEnvVar, getEnvExportCmd } from '../../core/systemManager/crypto'; import { executeTask } from '../../core/taskManager'; import { TASK_CRYPTO_ENCRYPT, TASK_PROJECT_CONFIGURE, PARAMS } from '../../core/constants'; -import { RnvContext } from '../../core/configManager/types'; +import { RnvContext } from '../../core/context/types'; import { RnvTaskFn } from '../../core/taskManager/types'; const iocane = require('iocane'); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.fastlane.ts b/packages/rnv/src/engine-core/tasks/task.rnv.fastlane.ts index 7f195ecbe1..a7a408648a 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.fastlane.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.fastlane.ts @@ -2,7 +2,7 @@ import { executeAsync, commandExistsSync } from '../../core/systemManager/exec'; import { getAppFolder, getCliArguments } from '../../core/common'; import { IOS, TVOS, ANDROID, ANDROID_TV, FIRE_TV, ANDROID_WEAR, PARAMS } from '../../core/constants'; import PlatformSetup from '../../core/setupManager'; -import { RnvContext } from '../../core/configManager/types'; +import { RnvContext } from '../../core/context/types'; export const taskRnvFastlane = async (c: RnvContext) => { const args = getCliArguments(c); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts b/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts index 3d44b7c804..ec77758eb9 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts @@ -7,7 +7,7 @@ import { configureRuntimeDefaults } from '../../core/runtimeManager'; import { PARAMS, TASK_KILL, TASK_APP_CONFIGURE } from '../../core/constants'; import { RnvTaskFn } from '../../core/taskManager/types'; -import { RnvContext } from '../../core/configManager/types'; +import { RnvContext } from '../../core/context/types'; export const taskRnvKill: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvKill'); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.link.ts b/packages/rnv/src/engine-core/tasks/task.rnv.link.ts index 3565fc4ee1..32172db6a0 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.link.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.link.ts @@ -3,7 +3,7 @@ import { logInfo, logTask, logSuccess } from '../../core/systemManager/logger'; import { PARAMS, RNV_PACKAGES } from '../../core/constants'; import { fsExistsSync, fsRenameSync, fsSymlinkSync } from '../../core/systemManager/fileutils'; import { RnvTaskFn } from '../../core/taskManager/types'; -import { RnvContext } from '../../core/configManager/types'; +import { RnvContext } from '../../core/context/types'; const _linkPackage = (c: RnvContext, key: string, folder: string) => { const rnvPath = path.join(c.paths.project.nodeModulesDir, key); diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.new.ts b/packages/rnv/src/engine-core/tasks/task.rnv.new.ts index 5d0a81cbec..b63a18eacf 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.new.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.new.ts @@ -33,7 +33,8 @@ import { printIntoBox, } from '../../core/systemManager/logger'; import { isYarnInstalled, listAndSelectNpmVersion } from '../../core/systemManager/npmUtils'; -import { RenativeConfigFile, RnvContext } from '../../core/configManager/types'; +import { RnvContext } from '../../core/context/types'; +import { RenativeConfigFile } from '../../core/configManager/types'; const highlight = chalk().green; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.pkg.ts b/packages/rnv/src/engine-core/tasks/task.rnv.pkg.ts index 0389e2199b..dc1a4e2941 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.pkg.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.pkg.ts @@ -1,7 +1,7 @@ import path from 'path'; import semver from 'semver'; -import Config from '../../core/configManager/config'; +import Config from '../../core/context/context'; import { executeAsync } from '../../core/systemManager/exec'; import { copyFileSync, diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.publish.ts b/packages/rnv/src/engine-core/tasks/task.rnv.publish.ts index cfb55d0da8..7195d033ef 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.publish.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.publish.ts @@ -1,5 +1,5 @@ import semver from 'semver'; -import Config from '../../core/configManager/config'; +import Config from '../../core/context/context'; import { executeAsync } from '../../core/systemManager/exec'; import { logWarning, logTask } from '../../core/systemManager/logger'; import { writeFileSync } from '../../core/systemManager/fileutils'; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.template.add.ts b/packages/rnv/src/engine-core/tasks/task.rnv.template.add.ts index 51d0379eb3..146e0c42bb 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.template.add.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.template.add.ts @@ -6,7 +6,7 @@ import { executeTask } from '../../core/taskManager'; import { TASK_PROJECT_CONFIGURE, TASK_TEMPLATE_ADD, PARAMS } from '../../core/constants'; import { getTemplateOptions } from '../../core/templateManager'; -import { RnvContext } from '../../core/configManager/types'; +import { RnvContext } from '../../core/context/types'; import { RnvTaskFn } from '../../core/taskManager/types'; const _writeObjectSync = (c: RnvContext, p: string, s: string) => { diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.unlink.ts b/packages/rnv/src/engine-core/tasks/task.rnv.unlink.ts index ac54af014d..e839060ded 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.unlink.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.unlink.ts @@ -3,7 +3,7 @@ import { logInfo, logTask, logSuccess } from '../../core/systemManager/logger'; import { PARAMS, RNV_PACKAGES } from '../../core/constants'; import { fsExistsSync, fsRenameSync, fsUnlinkSync, fsLstatSync } from '../../core/systemManager/fileutils'; import { RnvTaskFn } from '../../core/taskManager/types'; -import { RnvContext } from '../../core/configManager/types'; +import { RnvContext } from '../../core/context/types'; const _unlinkPackage = (c: RnvContext, key: string) => { const rnvPath = path.join(c.paths.project.nodeModulesDir, key); diff --git a/packages/rnv/src/index.ts b/packages/rnv/src/index.ts index 57a65b5da1..6b5c3fb9c7 100755 --- a/packages/rnv/src/index.ts +++ b/packages/rnv/src/index.ts @@ -31,7 +31,7 @@ import * as Doctor from './core/systemManager/doctor'; import * as Logger from './core/systemManager/logger'; import * as Resolver from './core/systemManager/resolve'; import Analytics from './core/systemManager/analytics'; -import Config from './core/configManager/config'; +import Config from './core/context/context'; global.RNV_ANALYTICS = Analytics; From 126723c2eedb3c3ffcde016f838b183037d3c72f Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Sun, 3 Sep 2023 03:58:52 +0200 Subject: [PATCH 44/83] refactor sdk android to ts --- packages/rnv/src/core/configManager/types.ts | 65 ++++- packages/rnv/src/core/context/types.ts | 5 +- packages/rnv/src/core/systemManager/types.ts | 2 +- packages/rnv/src/index.ts | 139 +++------- packages/rnv/src/modules.ts | 58 ++++ packages/rnv/src/runner.ts | 36 +++ packages/sdk-android/src/ejector.ts | 6 +- .../src/{gradleParser.js => gradleParser.ts} | 257 ++++++++++-------- ...rapperParser.js => gradleWrapperParser.ts} | 11 +- packages/sdk-android/src/index.ts | 31 ++- packages/sdk-android/src/kotlinParser.ts | 86 +++--- .../{manifestParser.js => manifestParser.ts} | 0 packages/sdk-android/src/types.ts | 51 ++++ ...{xmlValuesParser.js => xmlValuesParser.ts} | 25 +- packages/sdk-android/tsconfig.json | 1 - 15 files changed, 472 insertions(+), 301 deletions(-) create mode 100644 packages/rnv/src/modules.ts create mode 100644 packages/rnv/src/runner.ts rename packages/sdk-android/src/{gradleParser.js => gradleParser.ts} (68%) rename packages/sdk-android/src/{gradleWrapperParser.js => gradleWrapperParser.ts} (63%) rename packages/sdk-android/src/{manifestParser.js => manifestParser.ts} (100%) create mode 100644 packages/sdk-android/src/types.ts rename packages/sdk-android/src/{xmlValuesParser.js => xmlValuesParser.ts} (57%) diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index d047dac310..5146d2490b 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -11,18 +11,7 @@ export type RenativeConfigFile = { supportedPlatforms?: Array; portOffset?: number; }; - platforms: Record< - string, - { - buildSchemes?: Record; - entryFile?: string; - runtime?: Record; - appName?: string; - id?: string; - certificateProfile?: string; - engine?: string; - } - >; + platforms: Record; templates: Record< string, { @@ -50,6 +39,20 @@ export type RenativeConfigFile = { workspaceAppConfigsDir?: string; }; +export type RenativeConfigPlatform = { + buildSchemes?: Record; + entryFile?: string; + runtime?: Record; + appName?: string; + id?: string; + certificateProfile?: string; + engine?: string; + gradle?: { + buildTypes: Record; + }; + 'gradle.properties'?: Record; +}; + export type RenativeConfigPlugin = { source?: string; 'no-npm'?: boolean; @@ -70,6 +73,44 @@ export type RenativeConfigPlugin = { props?: Record; }; +export type RenativeConfigPluginPlatform = { + package?: string; + path?: string; + //IOS + + //ANDROID + projectName?: string; + skipLinking?: boolean; + skipImplementation?: boolean; + implementation?: string; + afterEvaluate?: string[]; + implementations?: string[]; + 'app/build.gradle'?: { + apply: string[]; + defaultConfig: string[]; + }; + 'build.gradle'?: { + allprojects?: { + repositories: Record; + }; + plugins?: string[]; + buildscript: { + repositories: Record; + dependencies: Record; + }; + injectAfterAll: string[]; + dexOptions: Record; + }; + BuildGradle?: RenativeConfigPluginPlatform['build.gradle']; + ResourceStrings: { + children: Array<{ + tag: string; + name: string; + child_value: string; + }>; + }; +}; + export type RenativeWebpackConfig = { modulePaths?: | Array< diff --git a/packages/rnv/src/core/context/types.ts b/packages/rnv/src/core/context/types.ts index e4613874f7..65762a24fd 100644 --- a/packages/rnv/src/core/context/types.ts +++ b/packages/rnv/src/core/context/types.ts @@ -3,8 +3,9 @@ import { RnvEngine, RnvEnginePlatform } from '../engineManager/types'; import { OverridesOptions } from '../systemManager/types'; import { RnvPlatform } from '../types'; -export interface RnvContext { +export interface RnvContext { program: any; + payload: Payload; command: string | null; subCommand: string | null; buildConfig: Partial & { @@ -63,7 +64,7 @@ export interface RnvContext { hasAllEnginesRegistered: boolean; skipPackageUpdate?: boolean; selectedTemplate?: string; - runtimeExtraProps: string; + runtimeExtraProps: any; requiresBootstrap: boolean; currentTemplate: string; requiresForcedTemplateApply: boolean; diff --git a/packages/rnv/src/core/systemManager/types.ts b/packages/rnv/src/core/systemManager/types.ts index a09f214122..a26ad22d9c 100644 --- a/packages/rnv/src/core/systemManager/types.ts +++ b/packages/rnv/src/core/systemManager/types.ts @@ -37,7 +37,7 @@ export type AnalyticsApi = { export type OverridesOptions = Array<{ pattern: string; - override: string; + override: string | undefined; }>; export type TimestampPathsConfig = { diff --git a/packages/rnv/src/index.ts b/packages/rnv/src/index.ts index 6b5c3fb9c7..c78d9c0f06 100755 --- a/packages/rnv/src/index.ts +++ b/packages/rnv/src/index.ts @@ -1,103 +1,48 @@ import 'regenerator-runtime/runtime'; -import * as Common from './core/common'; -import * as Utils from './core/systemManager/utils'; -import * as Prompt from './cli/prompt'; -import * as Constants from './core/constants'; -import Spinner from './cli/ora'; -import { withRNVBabel, withRNVMetro } from './core/adapter'; -import CLI from './cli'; - import 'source-map-support/register'; -// MANAGERS -import * as EngineManager from './core/engineManager'; -import * as SetupManager from './core/setupManager'; -import * as PlatformManager from './core/platformManager'; -import * as PluginManager from './core/pluginManager'; -import * as ProjectManager from './core/projectManager'; -import * as ConfigManager from './core/configManager'; -import * as SchemaManager from './core/schemaManager'; -import * as RuntimeManager from './core/runtimeManager'; -import * as SDKManager from './core/sdkManager'; -import * as TemplateManager from './core/templateManager'; -import * as TaskManager from './core/taskManager'; - -// SUB-MODULES -import * as NPMUtils from './core/systemManager/npmUtils'; -import * as ObjectUtils from './core/systemManager/objectUtils'; -import * as Exec from './core/systemManager/exec'; -import * as FileUtils from './core/systemManager/fileutils'; -import * as Doctor from './core/systemManager/doctor'; -import * as Logger from './core/systemManager/logger'; -import * as Resolver from './core/systemManager/resolve'; -import Analytics from './core/systemManager/analytics'; +import Spinner from './cli/ora'; +import CLI from './cli'; import Config from './core/context/context'; - -global.RNV_ANALYTICS = Analytics; - -export const initializeBuilder = async (cmd: string, subCmd: string, process: any, program: any) => { - // set mono and ci if json is enabled - if (program.json) { - program.mono = true; - program.ci = true; - } - - Analytics.initialize(); - FileUtils.configureFilesystem(Common.getConfigProp, Resolver.doResolve, Utils.isSystemWin); - const c = ConfigManager.createRnvConfig(program, process, cmd, subCmd); - Logger.logInitialize(); - - //@ts-ignore - global.fetch = await import('node-fetch'); - //@ts-ignore - global.Headers = global.fetch.Headers; - - return c; -}; - -const run = (cmd: string, subCmd: string, program: any, process: any) => { - initializeBuilder(cmd, subCmd, process, program) - .then((c) => Config.initializeConfig(c)) - .then((c) => CLI(c)) - .then(() => Logger.logComplete(!Config.getConfig().runtime.keepSessionActive)) - .catch((e) => Logger.logError(e, true)); -}; - -export const { doResolve } = Resolver; -export const { doResolvePath } = Resolver; -// END LEGACY - -export { - Constants, - Common, - Prompt, - // MANAGERS - EngineManager, - PlatformManager, - SetupManager, - PluginManager, - ProjectManager, - ConfigManager, - SchemaManager, - SDKManager, - TemplateManager, - TaskManager, - RuntimeManager, - // SUBMODULES - Exec, - FileUtils, - ObjectUtils, - Doctor, - Config, - Logger, - NPMUtils, - Resolver, - Utils, - withRNVBabel, - withRNVMetro, - run, - CLI, - Spinner, -}; +import { run } from './runner'; + +export * from './modules'; +export * from './core/adapter'; + +export * from './core/engineManager'; +export * from './core/setupManager'; +export * from './core/platformManager'; +export * from './core/pluginManager'; +export * from './core/projectManager'; +export * from './core/configManager'; +export * from './core/schemaManager'; +export * from './core/runtimeManager'; +export * from './core/sdkManager'; +export * from './core/templateManager'; +export * from './core/taskManager'; +export * from './core/systemManager/npmUtils'; +export * from './core/systemManager/objectUtils'; +export * from './core/systemManager/exec'; +export * from './core/systemManager/fileutils'; +export * from './core/systemManager/doctor'; +export * from './core/systemManager/logger'; +export * from './core/systemManager/resolve'; +export * from './core/common'; +export * from './core/systemManager/utils'; +export * from './cli/prompt'; +export * from './core/constants'; + +export * from './core/engineManager/types'; +export * from './core/context/types'; +export * from './core/pluginManager/types'; +export * from './core/projectManager/types'; +export * from './core/configManager/types'; +export * from './core/sdkManager/types'; +export * from './core/taskManager/types'; +export * from './core/systemManager/types'; +export * from './cli/types'; +export * from './core/types'; + +export { CLI, Spinner }; export default { run, Config }; diff --git a/packages/rnv/src/modules.ts b/packages/rnv/src/modules.ts new file mode 100644 index 0000000000..ad854a5479 --- /dev/null +++ b/packages/rnv/src/modules.ts @@ -0,0 +1,58 @@ +// MANAGERS +import * as EngineManager from './core/engineManager'; +import * as SetupManager from './core/setupManager'; +import * as PlatformManager from './core/platformManager'; +import * as PluginManager from './core/pluginManager'; +import * as ProjectManager from './core/projectManager'; +import * as ConfigManager from './core/configManager'; +import * as SchemaManager from './core/schemaManager'; +import * as RuntimeManager from './core/runtimeManager'; +import * as SDKManager from './core/sdkManager'; +import * as TemplateManager from './core/templateManager'; +import * as TaskManager from './core/taskManager'; +// SUB-MODULES +import * as NPMUtils from './core/systemManager/npmUtils'; +import * as ObjectUtils from './core/systemManager/objectUtils'; +import * as Exec from './core/systemManager/exec'; +import * as FileUtils from './core/systemManager/fileutils'; +import * as Doctor from './core/systemManager/doctor'; +import * as Logger from './core/systemManager/logger'; +import * as Resolver from './core/systemManager/resolve'; +import * as Common from './core/common'; +import * as Utils from './core/systemManager/utils'; +import * as Prompt from './cli/prompt'; +import * as Constants from './core/constants'; +import Spinner from './cli/ora'; +import CLI from './cli'; +import Config from './core/context/context'; + +export { + // MANAGERS + EngineManager, + PlatformManager, + SetupManager, + PluginManager, + ProjectManager, + ConfigManager, + SchemaManager, + SDKManager, + TemplateManager, + TaskManager, + RuntimeManager, + // SUBMODULES + // MANAGERS + Constants, + Common, + Prompt, + Exec, + FileUtils, + ObjectUtils, + Doctor, + Config, + Logger, + NPMUtils, + Resolver, + Utils, + CLI, + Spinner, +}; diff --git a/packages/rnv/src/runner.ts b/packages/rnv/src/runner.ts new file mode 100644 index 0000000000..914d0ef962 --- /dev/null +++ b/packages/rnv/src/runner.ts @@ -0,0 +1,36 @@ +import Analytics from './core/systemManager/analytics'; +import Config from './core/context/context'; +import { configureFilesystem } from './core/systemManager/fileutils'; +import { createRnvConfig } from './core/configManager'; +import { logComplete, logError, logInitialize } from './core/systemManager/logger'; +import CLI from './cli'; + +global.RNV_ANALYTICS = Analytics; + +export const initializeBuilder = async (cmd: string, subCmd: string, process: any, program: any) => { + // set mono and ci if json is enabled + if (program.json) { + program.mono = true; + program.ci = true; + } + + Analytics.initialize(); + configureFilesystem(getConfigProp, doResolve, isSystemWin); + const c = createRnvConfig(program, process, cmd, subCmd); + logInitialize(); + + //@ts-ignore + global.fetch = await import('node-fetch'); + //@ts-ignore + global.Headers = global.fetch.Headers; + + return c; +}; + +export const run = (cmd: string, subCmd: string, program: any, process: any) => { + initializeBuilder(cmd, subCmd, process, program) + .then((c) => Config.initializeConfig(c)) + .then((c) => CLI(c)) + .then(() => logComplete(!Config.getConfig().runtime.keepSessionActive)) + .catch((e) => logError(e, true)); +}; diff --git a/packages/sdk-android/src/ejector.ts b/packages/sdk-android/src/ejector.ts index 9f9ffaf1d3..3593ec81fb 100644 --- a/packages/sdk-android/src/ejector.ts +++ b/packages/sdk-android/src/ejector.ts @@ -1,5 +1,5 @@ import path from 'path'; -import { Common, FileUtils, PluginManager, Resolver } from 'rnv'; +import { Common, FileUtils, PluginManager, Resolver, RnvContext, RnvPluginPlatform } from 'rnv'; // import { logWarning } from 'rnv/dist/core/systemManager/logger'; const { @@ -19,7 +19,7 @@ const { // sanitizePluginPath, includesPluginPath } = PluginManager; -export const ejectGradleProject = async (c: any) => { +export const ejectGradleProject = async (c: RnvContext) => { const isMonorepo = getConfigProp(c, c.platform, 'isMonorepo'); const monoRoot = getConfigProp(c, c.platform, 'monoRoot'); @@ -120,7 +120,7 @@ export const ejectGradleProject = async (c: any) => { const afterEvaluateFix: Array<{ match: string; replace: string }> = []; - parsePlugins(c, c.platform, (_plugin: any, pluginPlat: any, key: string) => { + parsePlugins(c, c.platform as RnvPluginPlatform, (_plugin: any, pluginPlat: any, key: string) => { const pluginPath = doResolvePath(key); if (!pluginPath) return; diff --git a/packages/sdk-android/src/gradleParser.js b/packages/sdk-android/src/gradleParser.ts similarity index 68% rename from packages/sdk-android/src/gradleParser.js rename to packages/sdk-android/src/gradleParser.ts index 56923a72bb..d4b83a857a 100644 --- a/packages/sdk-android/src/gradleParser.js +++ b/packages/sdk-android/src/gradleParser.ts @@ -1,5 +1,16 @@ import path from 'path'; -import { Common, FileUtils, Logger, PluginManager, Resolver, Utils } from 'rnv'; +import { + Common, + FileUtils, + Logger, + PluginManager, + RenativeConfigPlatform, + RenativeConfigPluginPlatform, + Resolver, + RnvContext, + Utils, +} from 'rnv'; +import { Payload } from './types'; const { getAppFolder, getAppVersion, getAppVersionCode, getAppId, getBuildFilePath, getConfigProp, addSystemInjects } = Common; @@ -9,65 +20,65 @@ const { chalk, logTask, logWarning, logDebug } = Logger; const { sanitizePluginPath, includesPluginPath } = PluginManager; const { isSystemWin } = Utils; -export const parseBuildGradleSync = (c) => { +export const parseBuildGradleSync = (c: RnvContext) => { const appFolder = getAppFolder(c); const { platform } = c; let dexOptions = ''; - if (c.pluginConfigAndroid.buildGradleBuildScriptDexOptions) { + if (c.payload.pluginConfigAndroid.buildGradleBuildScriptDexOptions) { dexOptions = `dexOptions() { - ${c.pluginConfigAndroid.buildGradleBuildScriptDexOptions} + ${c.payload.pluginConfigAndroid.buildGradleBuildScriptDexOptions} }`; } const injects = [ { pattern: '{{COMPILE_SDK_VERSION}}', - override: c.pluginConfigAndroid.compileSdkVersion, + override: c.payload.pluginConfigAndroid.compileSdkVersion, }, { pattern: '{{INJECT_BUILD_TOOLS_VERSION}}', - override: c.pluginConfigAndroid.gradleBuildToolsVersion, + override: c.payload.pluginConfigAndroid.gradleBuildToolsVersion, }, { pattern: '{{SUPPORT_LIB_VERSION}}', - override: c.pluginConfigAndroid.supportLibVersion, + override: c.payload.pluginConfigAndroid.supportLibVersion, }, { pattern: '{{BUILD_TOOLS_VERSION}}', - override: c.pluginConfigAndroid.buildToolsVersion, + override: c.payload.pluginConfigAndroid.buildToolsVersion, }, { pattern: '{{PLUGIN_INJECT_ALLPROJECTS_REPOSITORIES}}', - override: c.pluginConfigAndroid.buildGradleAllProjectsRepositories, + override: c.payload.pluginConfigAndroid.buildGradleAllProjectsRepositories, }, { pattern: '{{PLUGIN_INJECT_BUILDSCRIPT_REPOSITORIES}}', - override: c.pluginConfigAndroid.buildGradleBuildScriptRepositories, + override: c.payload.pluginConfigAndroid.buildGradleBuildScriptRepositories, }, { pattern: '{{INJECT_KOTLIN_VERSION}}', - override: c.pluginConfigAndroid.kotlinVersion, + override: c.payload.pluginConfigAndroid.kotlinVersion, }, { pattern: '{{INJECT_GOOGLE_SERVICES_VERSION}}', - override: c.pluginConfigAndroid.googleServicesVersion, + override: c.payload.pluginConfigAndroid.googleServicesVersion, }, { pattern: '{{INJECT_PLUGINS}}', - override: c.pluginConfigAndroid.buildGradlePlugins, + override: c.payload.pluginConfigAndroid.buildGradlePlugins, }, { pattern: '{{MIN_SDK_VERSION}}', - override: c.pluginConfigAndroid.minSdkVersion, + override: c.payload.pluginConfigAndroid.minSdkVersion, }, { pattern: '{{INJECT_AFTER_ALL}}', - override: c.pluginConfigAndroid.buildGradleAfterAll, + override: c.payload.pluginConfigAndroid.buildGradleAfterAll, }, { pattern: '{{PLUGIN_INJECT_BUILDSCRIPT_DEPENDENCIES}}', - override: c.pluginConfigAndroid.buildGradleBuildScriptDependencies, + override: c.payload.pluginConfigAndroid.buildGradleBuildScriptDependencies, }, { pattern: '{{PLUGIN_INJECT_DEXOPTIONS}}', @@ -75,7 +86,7 @@ export const parseBuildGradleSync = (c) => { }, { pattern: '{{INJECT_REACT_NATIVE_ENGINE}}', - override: c.pluginConfigAndroid.injectReactNativeEngine, + override: c.payload.pluginConfigAndroid.injectReactNativeEngine, }, { pattern: '{{PATH_REACT_NATIVE}}', @@ -90,56 +101,56 @@ export const parseBuildGradleSync = (c) => { getBuildFilePath(c, platform, 'build.gradle'), path.join(appFolder, 'build.gradle'), injects, - null, + undefined, c ); }; -const setReactNativeEngineDefault = (c) => { - c.pluginConfigAndroid.injectReactNativeEngine = ` +const setReactNativeEngineDefault = (c: RnvContext) => { + c.payload.pluginConfigAndroid.injectReactNativeEngine = ` maven { url "${doResolve('react-native', true, { forceForwardPaths: true })}/android" } maven { url("${doResolve('jsc-android', true, { forceForwardPaths: true })}/dist") } `; - c.pluginConfigAndroid.appBuildGradleImplementations += " implementation 'org.webkit:android-jsc:+'\n"; + c.payload.pluginConfigAndroid.appBuildGradleImplementations += " implementation 'org.webkit:android-jsc:+'\n"; - c.pluginConfigAndroid.injectHermes = ' enableHermes: false,'; + c.payload.pluginConfigAndroid.injectHermes = ' enableHermes: false,'; }; -const setReactNativeEngineHermes = (c) => { - c.pluginConfigAndroid.injectReactNativeEngine = ` +const setReactNativeEngineHermes = (c: RnvContext) => { + c.payload.pluginConfigAndroid.injectReactNativeEngine = ` maven { url "${doResolve('react-native', true, { forceForwardPaths: true })}/android" } maven { url("${doResolve('jsc-android', true, { forceForwardPaths: true })}/dist") } `; - c.pluginConfigAndroid.appBuildGradleImplementations += ` debugImplementation files("${doResolve( + c.payload.pluginConfigAndroid.appBuildGradleImplementations += ` debugImplementation files("${doResolve( 'hermes-engine', true, { forceForwardPaths: true } )}/android/hermes-debug.aar")\n`; - c.pluginConfigAndroid.appBuildGradleImplementations += ` releaseImplementation files("${doResolve( + c.payload.pluginConfigAndroid.appBuildGradleImplementations += ` releaseImplementation files("${doResolve( 'hermes-engine', true, { forceForwardPaths: true } )}/android/hermes-release.aar")\n`; - c.pluginConfigAndroid.injectHermes = ` enableHermes: true, + c.payload.pluginConfigAndroid.injectHermes = ` enableHermes: true, hermesCommand: "{{PATH_HERMES_ENGINE}}/%OS-BIN%/hermes", deleteDebugFilesForVariant: { false }, `; }; -const setReactNativeEngineV8 = (c) => { - c.pluginConfigAndroid.injectReactNativeEngine = ` +const setReactNativeEngineV8 = (c: RnvContext) => { + c.payload.pluginConfigAndroid.injectReactNativeEngine = ` maven { url "${doResolve('react-native', true, { forceForwardPaths: true })}/android" } maven { url("${doResolve('jsc-android', true, { forceForwardPaths: true })}/dist") } `; - c.pluginConfigAndroid.pluginApplicationImports += `import com.facebook.react.bridge.JavaScriptExecutorFactory + c.payload.pluginConfigAndroid.pluginApplicationImports += `import com.facebook.react.bridge.JavaScriptExecutorFactory import com.facebook.react.modules.systeminfo.AndroidInfoHelpers import io.csie.kudo.reactnative.v8.executor.V8ExecutorFactory`; - c.pluginConfigAndroid.reactNativeHostMethods += `override fun getJavaScriptExecutorFactory(): JavaScriptExecutorFactory { + c.payload.pluginConfigAndroid.reactNativeHostMethods += `override fun getJavaScriptExecutorFactory(): JavaScriptExecutorFactory { return V8ExecutorFactory( applicationContext, packageName, @@ -148,26 +159,31 @@ const setReactNativeEngineV8 = (c) => { ) }`; - c.pluginConfigAndroid.injectHermes = ' enableHermes: false,'; + c.payload.pluginConfigAndroid.injectHermes = ' enableHermes: false,'; - c.pluginConfigAndroid.packagingOptions += ` + c.payload.pluginConfigAndroid.packagingOptions += ` exclude '**/libjsc.so'`; }; -export const parseAppBuildGradleSync = (c) => { +export const parseAppBuildGradleSync = (c: RnvContext) => { logTask('parseAppBuildGradleSync'); const appFolder = getAppFolder(c); const { platform } = c; // ANDROID PROPS - c.pluginConfigAndroid.minSdkVersion = getConfigProp(c, platform, 'minSdkVersion', 24); - c.pluginConfigAndroid.targetSdkVersion = getConfigProp(c, platform, 'targetSdkVersion', 28); - c.pluginConfigAndroid.compileSdkVersion = getConfigProp(c, platform, 'compileSdkVersion', 28); - c.pluginConfigAndroid.gradleBuildToolsVersion = getConfigProp(c, platform, 'gradleBuildToolsVersion', '4.2.2'); - c.pluginConfigAndroid.supportLibVersion = getConfigProp(c, platform, 'supportLibVersion', '28.0.0'); - c.pluginConfigAndroid.buildToolsVersion = getConfigProp(c, platform, 'buildToolsVersion', '28.0.0'); - c.pluginConfigAndroid.kotlinVersion = getConfigProp(c, platform, 'kotlinVersion', '1.4.20'); - c.pluginConfigAndroid.googleServicesVersion = getConfigProp(c, platform, 'googleServicesVersion', '4.2.0'); + c.payload.pluginConfigAndroid.minSdkVersion = getConfigProp(c, platform, 'minSdkVersion', 24); + c.payload.pluginConfigAndroid.targetSdkVersion = getConfigProp(c, platform, 'targetSdkVersion', 28); + c.payload.pluginConfigAndroid.compileSdkVersion = getConfigProp(c, platform, 'compileSdkVersion', 28); + c.payload.pluginConfigAndroid.gradleBuildToolsVersion = getConfigProp( + c, + platform, + 'gradleBuildToolsVersion', + '4.2.2' + ); + c.payload.pluginConfigAndroid.supportLibVersion = getConfigProp(c, platform, 'supportLibVersion', '28.0.0'); + c.payload.pluginConfigAndroid.buildToolsVersion = getConfigProp(c, platform, 'buildToolsVersion', '28.0.0'); + c.payload.pluginConfigAndroid.kotlinVersion = getConfigProp(c, platform, 'kotlinVersion', '1.4.20'); + c.payload.pluginConfigAndroid.googleServicesVersion = getConfigProp(c, platform, 'googleServicesVersion', '4.2.0'); // REACT NATIVE ENGINE const enableHermes = getConfigProp(c, platform, 'enableHermes'); @@ -183,23 +199,23 @@ export const parseAppBuildGradleSync = (c) => { break; } case 'v8-android': { - setReactNativeEngineV8(c, reactNativeEngine); + setReactNativeEngineV8(c); break; } case 'v8-android-nointl': { - setReactNativeEngineV8(c, reactNativeEngine); + setReactNativeEngineV8(c); break; } case 'v8-android-jit': { - setReactNativeEngineV8(c, reactNativeEngine); + setReactNativeEngineV8(c); break; } case 'v8-android-jit-nointl': { - setReactNativeEngineV8(c, reactNativeEngine); + setReactNativeEngineV8(c); break; } case 'hermes': { - setReactNativeEngineHermes(c, reactNativeEngine); + setReactNativeEngineHermes(c); break; } default: { @@ -217,9 +233,9 @@ export const parseAppBuildGradleSync = (c) => { keyPassword "android" }`; - c.pluginConfigAndroid.appBuildGradleSigningConfigs = `${debugSigning} + c.payload.pluginConfigAndroid.appBuildGradleSigningConfigs = `${debugSigning} release`; - c.pluginConfigAndroid.localProperties = ''; + c.payload.pluginConfigAndroid.localProperties = ''; const obj = c.files.workspace?.appConfig?.configPrivate?.[platform]; if (obj) { @@ -233,7 +249,7 @@ Your ${chalk().red(platform)} object needs to be located under ${chalk().green(' const keyPassword = getConfigProp(c, c.platform, 'keyPassword') || obj?.keyPassword; const minifyEnabled = getConfigProp(c, c.platform, 'minifyEnabled', false); - c.pluginConfigAndroid.store = { + c.payload.pluginConfigAndroid.store = { storeFile, keyAlias, storePassword, @@ -264,7 +280,7 @@ Your ${chalk().red(platform)} object needs to be located under ${chalk().green(' keyPassword=${keyPassword}` ); - c.pluginConfigAndroid.appBuildGradleSigningConfigs = `${debugSigning} + c.payload.pluginConfigAndroid.appBuildGradleSigningConfigs = `${debugSigning} release { storeFile file(keystoreProps['storeFile']) storePassword keystoreProps['storePassword'] @@ -272,7 +288,7 @@ Your ${chalk().red(platform)} object needs to be located under ${chalk().green(' keyPassword keystoreProps['keyPassword'] }`; - c.pluginConfigAndroid.localProperties = ` + c.payload.pluginConfigAndroid.localProperties = ` def keystorePropsFile = rootProject.file("keystore.properties") def keystoreProps = new Properties() keystoreProps.load(new FileInputStream(keystorePropsFile))`; @@ -297,10 +313,10 @@ ${chalk().white(c.paths.workspace?.appConfig?.configsPrivate?.join('\n'))}`); // BUILD_TYPES const pluginConfig = c.buildConfig ?? {}; - const debugBuildTypes = pluginConfig?.platforms[platform]?.gradle?.buildTypes?.debug ?? []; - const releaseBuildTypes = pluginConfig?.platforms[platform]?.gradle?.buildTypes?.release ?? []; + const debugBuildTypes = pluginConfig?.platforms?.[platform]?.gradle?.buildTypes?.debug ?? []; + const releaseBuildTypes: string[] = pluginConfig?.platforms?.[platform]?.gradle?.buildTypes?.release ?? []; const isSigningDisabled = getConfigProp(c, platform, 'disableSigning') === true; - c.pluginConfigAndroid.buildTypes = ` + c.payload.pluginConfigAndroid.buildTypes = ` debug { minifyEnabled ${minifyEnabled} proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' @@ -316,10 +332,10 @@ ${chalk().white(c.paths.workspace?.appConfig?.configsPrivate?.join('\n'))}`); // MULTI APK const versionCodeOffset = getConfigProp(c, platform, 'versionCodeOffset', 0); const isMultiApk = getConfigProp(c, platform, 'multipleAPKs', false) === true; - c.pluginConfigAndroid.multiAPKs = ''; + c.payload.pluginConfigAndroid.multiAPKs = ''; if (isMultiApk) { const multiSet = 'Integer.parseInt(Integer.toString(variant.versionCode) + Integer.toString(bavc))'; - c.pluginConfigAndroid.multiAPKs = ` + c.payload.pluginConfigAndroid.multiAPKs = ` ext.abiCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4] import com.android.build.OutputFile @@ -334,9 +350,9 @@ ${chalk().white(c.paths.workspace?.appConfig?.configsPrivate?.join('\n'))}`); } // SPLITS - c.pluginConfigAndroid.splits = ''; + c.payload.pluginConfigAndroid.splits = ''; if (isMultiApk) { - c.pluginConfigAndroid.splits = ` + c.payload.pluginConfigAndroid.splits = ` splits { abi { reset() @@ -349,7 +365,7 @@ ${chalk().white(c.paths.workspace?.appConfig?.configsPrivate?.join('\n'))}`); } // PACKAGING OPTIONS - c.pluginConfigAndroid.packagingOptions += ` + c.payload.pluginConfigAndroid.packagingOptions += ` exclude 'META-INF/DEPENDENCIES.txt' exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/dependencies.txt' @@ -368,7 +384,7 @@ ${chalk().white(c.paths.workspace?.appConfig?.configsPrivate?.join('\n'))}`); pickFirst 'lib/x86_64/libjsc.so'`; // COMPILE OPTIONS - c.pluginConfigAndroid.compileOptions = ` + c.payload.pluginConfigAndroid.compileOptions = ` sourceCompatibility 1.8 targetCompatibility 1.8`; @@ -379,19 +395,19 @@ ${chalk().white(c.paths.workspace?.appConfig?.configsPrivate?.join('\n'))}`); } if (enableAndroidX !== false) { - c.pluginConfigAndroid.appBuildGradleImplementations += ` implementation "${enableAndroidX}"\n`; + c.payload.pluginConfigAndroid.appBuildGradleImplementations += ` implementation "${enableAndroidX}"\n`; } else { - c.pluginConfigAndroid.appBuildGradleImplementations += + c.payload.pluginConfigAndroid.appBuildGradleImplementations += " implementation 'com.android.support:appcompat-v7:27.0.2'\n"; } - c.pluginConfigAndroid.appBuildGradleImplementations += + c.payload.pluginConfigAndroid.appBuildGradleImplementations += ' implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02"\n'; const injects = [ { pattern: '{{PLUGIN_APPLY}}', - override: c.pluginConfigAndroid.applyPlugin, + override: c.payload.pluginConfigAndroid.applyPlugin, }, { pattern: '{{APPLICATION_ID}}', override: getAppId(c, platform) }, { @@ -404,59 +420,59 @@ ${chalk().white(c.paths.workspace?.appConfig?.configsPrivate?.join('\n'))}`); }, { pattern: '{{PLUGIN_IMPLEMENTATIONS}}', - override: c.pluginConfigAndroid.appBuildGradleImplementations, + override: c.payload.pluginConfigAndroid.appBuildGradleImplementations, }, { pattern: '{{PLUGIN_AFTER_EVALUATE}}', - override: c.pluginConfigAndroid.appBuildGradleAfterEvaluate, + override: c.payload.pluginConfigAndroid.appBuildGradleAfterEvaluate, }, { pattern: '{{PLUGIN_SIGNING_CONFIGS}}', - override: c.pluginConfigAndroid.appBuildGradleSigningConfigs, + override: c.payload.pluginConfigAndroid.appBuildGradleSigningConfigs, }, { pattern: '{{PLUGIN_SPLITS}}', - override: c.pluginConfigAndroid.splits, + override: c.payload.pluginConfigAndroid.splits, }, { pattern: '{{PLUGIN_ANDROID_DEFAULT_CONFIG}}', - override: c.pluginConfigAndroid.defaultConfig, + override: c.payload.pluginConfigAndroid.defaultConfig, }, { pattern: '{{PLUGIN_PACKAGING_OPTIONS}}', - override: c.pluginConfigAndroid.packagingOptions, + override: c.payload.pluginConfigAndroid.packagingOptions, }, { pattern: '{{PLUGIN_BUILD_TYPES}}', - override: c.pluginConfigAndroid.buildTypes, + override: c.payload.pluginConfigAndroid.buildTypes, }, { pattern: '{{PLUGIN_MULTI_APKS}}', - override: c.pluginConfigAndroid.multiAPKs, + override: c.payload.pluginConfigAndroid.multiAPKs, }, { pattern: '{{MIN_SDK_VERSION}}', - override: c.pluginConfigAndroid.minSdkVersion, + override: c.payload.pluginConfigAndroid.minSdkVersion, }, { pattern: '{{TARGET_SDK_VERSION}}', - override: c.pluginConfigAndroid.targetSdkVersion, + override: c.payload.pluginConfigAndroid.targetSdkVersion, }, { pattern: '{{COMPILE_SDK_VERSION}}', - override: c.pluginConfigAndroid.compileSdkVersion, + override: c.payload.pluginConfigAndroid.compileSdkVersion, }, { pattern: '{{PLUGIN_COMPILE_OPTIONS}}', - override: c.pluginConfigAndroid.compileOptions, + override: c.payload.pluginConfigAndroid.compileOptions, }, { pattern: '{{PLUGIN_LOCAL_PROPERTIES}}', - override: c.pluginConfigAndroid.localProperties, + override: c.payload.pluginConfigAndroid.localProperties, }, { pattern: '{{INJECT_HERMES}}', - override: c.pluginConfigAndroid.injectHermes, + override: c.payload.pluginConfigAndroid.injectHermes, }, { pattern: '{{PATH_REACT_NATIVE}}', @@ -470,7 +486,7 @@ ${chalk().white(c.paths.workspace?.appConfig?.configsPrivate?.join('\n'))}`); }, { pattern: '{{INJECT_KOTLIN_VERSION}}', - override: c.pluginConfigAndroid.kotlinVersion, + override: c.payload.pluginConfigAndroid.kotlinVersion, }, ]; @@ -480,22 +496,22 @@ ${chalk().white(c.paths.workspace?.appConfig?.configsPrivate?.join('\n'))}`); getBuildFilePath(c, platform, 'app/build.gradle'), path.join(appFolder, 'app/build.gradle'), injects, - null, + undefined, c ); }; -export const parseSettingsGradleSync = (c) => { +export const parseSettingsGradleSync = (c: RnvContext) => { const appFolder = getAppFolder(c); const { platform } = c; const injects = [ { pattern: '{{PLUGIN_INCLUDES}}', - override: c.pluginConfigAndroid.pluginIncludes, + override: c.payload.pluginConfigAndroid.pluginIncludes, }, { pattern: '{{PLUGIN_PATHS}}', - override: c.pluginConfigAndroid.pluginPaths, + override: c.payload.pluginConfigAndroid.pluginPaths, }, ]; @@ -505,17 +521,17 @@ export const parseSettingsGradleSync = (c) => { getBuildFilePath(c, platform, 'settings.gradle'), path.join(appFolder, 'settings.gradle'), injects, - null, + undefined, c ); }; -export const parseGradlePropertiesSync = (c) => { +export const parseGradlePropertiesSync = (c: RnvContext) => { const appFolder = getAppFolder(c); const { platform } = c; // GRADLE.PROPERTIES let pluginGradleProperties = ''; - const pluginConfigAndroid = c.buildConfig?.platforms?.[platform] || {}; + const pluginConfigAndroid: RenativeConfigPlatform = c.buildConfig?.platforms?.[platform] || {}; const gradleProps = pluginConfigAndroid['gradle.properties']; @@ -546,12 +562,18 @@ export const parseGradlePropertiesSync = (c) => { getBuildFilePath(c, platform, gradleProperties), path.join(appFolder, gradleProperties), injects, - null, + undefined, c ); }; -export const injectPluginGradleSync = (c, plugin, key, pkg, pluginRoot) => { +export const injectPluginGradleSync = ( + c: RnvContext, + plugin: RenativeConfigPluginPlatform, + key: string, + _pkg: string, + pluginRoot +) => { // const keyFixed = key.replace(/\//g, '-').replace(/@/g, ''); // const packagePath = plugin.path ?? `${key}/android`; // let pathAbsolute; @@ -587,39 +609,39 @@ export const injectPluginGradleSync = (c, plugin, key, pkg, pluginRoot) => { // APP/BUILD.GRADLE if (plugin.projectName) { if (!plugin.skipLinking && !skipPathResolutions) { - c.pluginConfigAndroid.pluginIncludes += `, ':${plugin.projectName}'`; + c.payload.pluginConfigAndroid.pluginIncludes += `, ':${plugin.projectName}'`; // }').projectDir = new File(rootProject.projectDir, '${modulePath}')\n`; - c.pluginConfigAndroid.pluginPaths += `project(':${plugin.projectName}').projectDir = new File('${pathAbsolute}')\n`; + c.payload.pluginConfigAndroid.pluginPaths += `project(':${plugin.projectName}').projectDir = new File('${pathAbsolute}')\n`; } if (!plugin.skipImplementation) { if (plugin.implementation) { - c.pluginConfigAndroid.appBuildGradleImplementations += `${plugin.implementation}\n`; + c.payload.pluginConfigAndroid.appBuildGradleImplementations += `${plugin.implementation}\n`; } else { - c.pluginConfigAndroid.appBuildGradleImplementations += ` implementation project(':${plugin.projectName}')\n`; + c.payload.pluginConfigAndroid.appBuildGradleImplementations += ` implementation project(':${plugin.projectName}')\n`; } } } else { if (!plugin.skipLinking && !skipPathResolutions) { - c.pluginConfigAndroid.pluginIncludes += `, ':${keyFixed}'`; - c.pluginConfigAndroid.pluginPaths += `project(':${keyFixed}').projectDir = new File('${pathAbsolute}')\n`; + c.payload.pluginConfigAndroid.pluginIncludes += `, ':${keyFixed}'`; + c.payload.pluginConfigAndroid.pluginPaths += `project(':${keyFixed}').projectDir = new File('${pathAbsolute}')\n`; } if (!plugin.skipImplementation) { if (plugin.implementation) { - c.pluginConfigAndroid.appBuildGradleImplementations += `${plugin.implementation}\n`; + c.payload.pluginConfigAndroid.appBuildGradleImplementations += `${plugin.implementation}\n`; } else { - c.pluginConfigAndroid.appBuildGradleImplementations += ` implementation project(':${keyFixed}')\n`; + c.payload.pluginConfigAndroid.appBuildGradleImplementations += ` implementation project(':${keyFixed}')\n`; } } } parseAndroidConfigObject(c, plugin, key); - if (!skipPathResolutions) { + if (!skipPathResolutions && pathAbsolute) { _fixAndroidLegacy(c, pathAbsolute); } }; -const getObj = (c, obj, keys) => { +const getObj = (c: RnvContext, obj: any, keys: Array): T | undefined => { for (let i = 0; i < keys.length; i++) { const key = keys[i]; const val = obj ? obj[key] : getConfigProp(c, c.platform, key); @@ -627,45 +649,48 @@ const getObj = (c, obj, keys) => { } }; -export const parseAndroidConfigObject = (c, obj, key) => { - const implementations = getObj(c, obj, ['implementations']); +export const parseAndroidConfigObject = (c: RnvContext, obj?: any, key = '') => { + const implementations = getObj(c, obj, ['implementations']); if (implementations) { implementations.forEach((v) => { - c.pluginConfigAndroid.appBuildGradleImplementations += ` implementation ${sanitizePluginPath(v, key)}\n`; + c.payload.pluginConfigAndroid.appBuildGradleImplementations += ` implementation ${sanitizePluginPath( + v, + key + )}\n`; }); } // APP/BUILD.GRADLE - const appBuildGradle = getObj(c, obj, ['app/build.gradle']); + const appBuildGradle = getObj(c, obj, ['app/build.gradle']); if (appBuildGradle) { if (appBuildGradle.apply) { appBuildGradle.apply.forEach((v) => { - c.pluginConfigAndroid.applyPlugin += `apply ${sanitizePluginPath(v, key)}\n`; + c.payload.pluginConfigAndroid.applyPlugin += `apply ${sanitizePluginPath(v, key)}\n`; }); } if (appBuildGradle.defaultConfig) { appBuildGradle.defaultConfig.forEach((v) => { - c.pluginConfigAndroid.defaultConfig += `${sanitizePluginPath(v, key)}\n`; + c.payload.pluginConfigAndroid.defaultConfig += `${sanitizePluginPath(v, key)}\n`; }); } } - const afterEvaluate = getObj(c, obj, ['afterEvaluate']); + const afterEvaluate = getObj(c, obj, ['afterEvaluate']); if (afterEvaluate) { afterEvaluate.forEach((v) => { - c.pluginConfigAndroid.appBuildGradleAfterEvaluate += ` ${sanitizePluginPath(v, key)}\n`; + c.payload.pluginConfigAndroid.appBuildGradleAfterEvaluate += ` ${sanitizePluginPath(v, key)}\n`; }); } // BUILD.GRADLE - const buildGradle = getObj(c, obj, ['BuildGradle', 'build.gradle']); + const buildGradle = getObj(c, obj, ['BuildGradle', 'build.gradle']); const allProjRepos = buildGradle?.allprojects?.repositories; if (allProjRepos) { Object.keys(allProjRepos).forEach((k) => { if (allProjRepos[k] === true) { - c.pluginConfigAndroid.buildGradleAllProjectsRepositories += `${sanitizePluginPath(k, key)}\n`; + c.payload.pluginConfigAndroid.buildGradleAllProjectsRepositories += `${sanitizePluginPath(k, key)}\n`; } }); } @@ -673,14 +698,14 @@ export const parseAndroidConfigObject = (c, obj, key) => { const plugins = buildGradle?.plugins; if (plugins?.forEach) { plugins.forEach((k) => { - c.pluginConfigAndroid.buildGradlePlugins += `${k}\n`; + c.payload.pluginConfigAndroid.buildGradlePlugins += `${k}\n`; }); } const buildscriptRepos = buildGradle?.buildscript?.repositories; if (buildscriptRepos) { Object.keys(buildscriptRepos).forEach((k) => { if (buildscriptRepos[k] === true) { - c.pluginConfigAndroid.buildGradleBuildScriptRepositories += `${k}\n`; + c.payload.pluginConfigAndroid.buildGradleBuildScriptRepositories += `${k}\n`; } }); } @@ -689,7 +714,7 @@ export const parseAndroidConfigObject = (c, obj, key) => { if (buildscriptDeps) { Object.keys(buildscriptDeps).forEach((k) => { if (buildscriptDeps[k] === true) { - c.pluginConfigAndroid.buildGradleBuildScriptDependencies += `${k}\n`; + c.payload.pluginConfigAndroid.buildGradleBuildScriptDependencies += `${k}\n`; } }); } @@ -698,7 +723,7 @@ export const parseAndroidConfigObject = (c, obj, key) => { if (buildscriptDexOptions) { Object.keys(buildscriptDexOptions).forEach((k) => { if (buildscriptDexOptions[k] === true) { - c.pluginConfigAndroid.buildGradleBuildScriptDexOptions += `${k}\n`; + c.payload.pluginConfigAndroid.buildGradleBuildScriptDexOptions += `${k}\n`; } }); } @@ -706,12 +731,12 @@ export const parseAndroidConfigObject = (c, obj, key) => { const injectAfterAll = buildGradle?.injectAfterAll; if (injectAfterAll?.forEach) { injectAfterAll.forEach((k) => { - c.pluginConfigAndroid.buildGradleAfterAll += `${sanitizePluginPath(k, key)}\n`; + c.payload.pluginConfigAndroid.buildGradleAfterAll += `${sanitizePluginPath(k, key)}\n`; }); } }; -const _fixAndroidLegacy = (c, modulePath) => { +const _fixAndroidLegacy = (c: RnvContext, modulePath: string) => { const buildGradle = path.join(c.paths.project.dir, modulePath, 'build.gradle'); if (fsExistsSync(buildGradle)) { @@ -730,7 +755,7 @@ const _fixAndroidLegacy = (c, modulePath) => { override: ' implementation fileTree', }, ], - null, + undefined, c ); } diff --git a/packages/sdk-android/src/gradleWrapperParser.js b/packages/sdk-android/src/gradleWrapperParser.ts similarity index 63% rename from packages/sdk-android/src/gradleWrapperParser.js rename to packages/sdk-android/src/gradleWrapperParser.ts index 04fcb334ef..044e60a032 100644 --- a/packages/sdk-android/src/gradleWrapperParser.js +++ b/packages/sdk-android/src/gradleWrapperParser.ts @@ -1,21 +1,22 @@ import path from 'path'; -import { FileUtils, Logger, Common } from 'rnv'; +import { FileUtils, Logger, Common, RnvContext } from 'rnv'; +import { Payload } from './types'; const { getAppFolder, getBuildFilePath, getConfigProp, addSystemInjects } = Common; const { writeCleanFile } = FileUtils; const { logTask } = Logger; -export const parseGradleWrapperSync = (c) => { +export const parseGradleWrapperSync = (c: RnvContext) => { logTask('parseGradleWrapperSync'); const appFolder = getAppFolder(c); const { platform } = c; - c.pluginConfigAndroid.gradleWrapperVersion = getConfigProp(c, platform, 'gradleWrapperVersion', '6.9.1'); + c.payload.pluginConfigAndroid.gradleWrapperVersion = getConfigProp(c, platform, 'gradleWrapperVersion', '6.9.1'); const injects = [ { pattern: '{{INJECT_GRADLE_WRAPPER_VERSION}}', - override: c.pluginConfigAndroid.gradleWrapperVersion, + override: c.payload.pluginConfigAndroid.gradleWrapperVersion, }, ]; addSystemInjects(c, injects); @@ -24,7 +25,7 @@ export const parseGradleWrapperSync = (c) => { getBuildFilePath(c, platform, 'gradle/wrapper/gradle-wrapper.properties'), path.join(appFolder, 'gradle/wrapper/gradle-wrapper.properties'), injects, - null, + undefined, c ); }; diff --git a/packages/sdk-android/src/index.ts b/packages/sdk-android/src/index.ts index 253b3694b6..41aa3413df 100644 --- a/packages/sdk-android/src/index.ts +++ b/packages/sdk-android/src/index.ts @@ -17,6 +17,7 @@ import { Prompt, SDKManager, RuntimeManager, + RnvContext, } from 'rnv'; import { parseAndroidManifestSync, injectPluginManifestSync } from './manifestParser'; import { @@ -36,6 +37,7 @@ import { import { parseGradleWrapperSync } from './gradleWrapperParser'; import { parseValuesStringsSync, injectPluginXmlValuesSync, parseValuesColorsSync } from './xmlValuesParser'; import { ejectGradleProject } from './ejector'; +import { Payload } from './types'; const { resetAdb, @@ -61,7 +63,7 @@ const { updateRenativeConfigs } = RuntimeManager; const { chalk, logTask, logWarning, logDebug, logInfo, logSuccess, logRaw, logError } = Logger; const { ANDROID_WEAR, ANDROID, ANDROID_TV, FIRE_TV, CLI_ANDROID_ADB } = Constants; -export const packageAndroid = async (c: any) => { +export const packageAndroid = async (c: RnvContext) => { logTask('packageAndroid'); const { platform } = c; @@ -119,7 +121,7 @@ export const packageAndroid = async (c: any) => { } }; -export const runAndroid = async (c: any) => { +export const runAndroid = async (c: RnvContext) => { const { target } = c.program; const { platform } = c; const defaultTarget = c.runtime.target; @@ -222,12 +224,12 @@ export const runAndroid = async (c: any) => { } }; -const _checkSigningCerts = async (c: any) => { +const _checkSigningCerts = async (c: RnvContext) => { logTask('_checkSigningCerts'); const signingConfig = getConfigProp(c, c.platform, 'signingConfig', 'Debug'); const isRelease = signingConfig === 'Release'; - if (isRelease && !c.pluginConfigAndroid?.store?.storeFile) { + if (isRelease && !c.payload.pluginConfigAndroid?.store?.storeFile) { const msg = `You're attempting to ${ c.command } app in release mode but you have't configured your ${chalk().white( @@ -348,7 +350,7 @@ const _checkSigningCerts = async (c: any) => { } }; -const _runGradleApp = async (c: any, platform: any, device: any) => { +const _runGradleApp = async (c: RnvContext, platform: any, device: any) => { logTask('_runGradleApp'); const signingConfig = getConfigProp(c, platform, 'signingConfig', 'Debug'); @@ -404,7 +406,7 @@ const _runGradleApp = async (c: any, platform: any, device: any) => { } }; -export const buildAndroid = async (c: any) => { +export const buildAndroid = async (c: RnvContext) => { logTask('buildAndroid'); const { platform } = c; @@ -434,7 +436,7 @@ export const buildAndroid = async (c: any) => { return true; }; -export const configureAndroidProperties = async (c: any) => { +export const configureAndroidProperties = async (c: RnvContext) => { logTask('configureAndroidProperties'); const appFolder = getAppFolder(c); @@ -465,7 +467,7 @@ sdk.dir=${sdkDir}` return true; }; -export const configureGradleProject = async (c: any) => { +export const configureGradleProject = async (c: RnvContext) => { const { platform } = c; logTask('configureGradleProject'); @@ -477,7 +479,7 @@ export const configureGradleProject = async (c: any) => { return true; }; -export const configureProject = async (c: any) => { +export const configureProject = async (c: RnvContext) => { logTask('configureProject'); const { platform } = c; @@ -500,10 +502,9 @@ export const configureProject = async (c: any) => { fsChmodSync(gradlew, '755'); // INJECTORS - c.pluginConfigAndroid = { + c.payload.pluginConfigAndroid = { pluginIncludes: "include ':app'", pluginPaths: '', - pluginImports: '', pluginPackages: 'MainReactPackage(),\n', pluginActivityImports: '', pluginActivityMethods: '', @@ -536,16 +537,16 @@ export const configureProject = async (c: any) => { }; // PLUGINS - parsePlugins(c, platform, (plugin: any, pluginPlat: any, key: any) => { + parsePlugins(c, platform, (plugin, pluginPlat, key) => { injectPluginGradleSync(c, pluginPlat, key, pluginPlat.package, plugin); injectPluginKotlinSync(c, pluginPlat, key, pluginPlat.package); injectPluginManifestSync(); injectPluginXmlValuesSync(c, pluginPlat); }); - c.pluginConfigAndroid.pluginPackages = c.pluginConfigAndroid.pluginPackages.substring( + c.payload.pluginConfigAndroid.pluginPackages = c.payload.pluginConfigAndroid.pluginPackages.substring( 0, - c.pluginConfigAndroid.pluginPackages.length - 2 + c.payload.pluginConfigAndroid.pluginPackages.length - 2 ); // FONTS @@ -590,7 +591,7 @@ export const configureProject = async (c: any) => { }; // Resolve or reject will not be called so this will keep running -export const runAndroidLog = async (c: any) => { +export const runAndroidLog = async (c: RnvContext) => { logTask('runAndroidLog'); const filter = c.program.filter || ''; const child = execa.command(`${c.cli[CLI_ANDROID_ADB]} logcat`); diff --git a/packages/sdk-android/src/kotlinParser.ts b/packages/sdk-android/src/kotlinParser.ts index df7b618c6d..ba18f9f2ca 100644 --- a/packages/sdk-android/src/kotlinParser.ts +++ b/packages/sdk-android/src/kotlinParser.ts @@ -1,5 +1,6 @@ import path from 'path'; -import { Common, FileUtils, Logger } from 'rnv'; +import { Common, FileUtils, Logger, RnvContext } from 'rnv'; +import { Payload } from './types'; const { getAppFolder, @@ -19,7 +20,7 @@ const JS_BUNDLE_DEFAULTS: any = { androidwear: '"assets://index.androidwear.bundle"', }; -export const parseMainApplicationSync = (c: any) => { +export const parseMainApplicationSync = (c: RnvContext) => { const appFolder = getAppFolder(c); const { platform } = c; const applicationPath = 'app/src/main/java/rnv/MainApplication.kt'; @@ -31,9 +32,9 @@ export const parseMainApplicationSync = (c: any) => { : bundleDefault || '"super.getJSBundleFile()"'; const bundlerIp = getIP() || '10.0.2.2'; if (!bundleAssets) { - c.pluginConfigAndroid.pluginApplicationDebugServer += + c.payload.pluginConfigAndroid.pluginApplicationDebugServer += ' var mPreferences: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)\n'; - c.pluginConfigAndroid.pluginApplicationDebugServer += ` mPreferences?.edit()?.putString("debug_http_host", "${bundlerIp}:${c.runtime.port}")?.apply()\n`; + c.payload.pluginConfigAndroid.pluginApplicationDebugServer += ` mPreferences?.edit()?.putString("debug_http_host", "${bundlerIp}:${c.runtime.port}")?.apply()\n`; } const injects = [ @@ -42,27 +43,27 @@ export const parseMainApplicationSync = (c: any) => { { pattern: '{{GET_JS_BUNDLE_FILE}}', override: bundleFile }, { pattern: '{{PLUGIN_IMPORTS}}', - override: c.pluginConfigAndroid.pluginApplicationImports, + override: c.payload.pluginConfigAndroid.pluginApplicationImports, }, { pattern: '{{PLUGIN_PACKAGES}}', - override: c.pluginConfigAndroid.pluginPackages, + override: c.payload.pluginConfigAndroid.pluginPackages, }, { pattern: '{{PLUGIN_METHODS}}', - override: c.pluginConfigAndroid.pluginApplicationMethods, + override: c.payload.pluginConfigAndroid.pluginApplicationMethods, }, { pattern: '{{RN_HOST_METHODS}}', - override: c.pluginConfigAndroid.reactNativeHostMethods, + override: c.payload.pluginConfigAndroid.reactNativeHostMethods, }, { pattern: '{{PLUGIN_ON_CREATE}}', - override: c.pluginConfigAndroid.pluginApplicationCreateMethods, + override: c.payload.pluginConfigAndroid.pluginApplicationCreateMethods, }, { pattern: '{{PLUGIN_DEBUG_SERVER}}', - override: c.pluginConfigAndroid.pluginApplicationDebugServer, + override: c.payload.pluginConfigAndroid.pluginApplicationDebugServer, }, ]; @@ -84,29 +85,30 @@ export const parseMainActivitySync = (c: any) => { const mainActivity = getConfigProp(c, platform, 'mainActivity', {}); - c.pluginConfigAndroid.injectActivityOnCreate = mainActivity.onCreate || 'super.onCreate(savedInstanceState)'; + c.payload.pluginConfigAndroid.injectActivityOnCreate = + mainActivity.onCreate || 'super.onCreate(savedInstanceState)'; const injects = [ { pattern: '{{APPLICATION_ID}}', override: getAppId(c, platform) }, { pattern: '{{PLUGIN_ACTIVITY_IMPORTS}}', - override: c.pluginConfigAndroid.pluginActivityImports, + override: c.payload.pluginConfigAndroid.pluginActivityImports, }, { pattern: '{{PLUGIN_ACTIVITY_METHODS}}', - override: c.pluginConfigAndroid.pluginActivityMethods, + override: c.payload.pluginConfigAndroid.pluginActivityMethods, }, { pattern: '{{PLUGIN_ON_CREATE}}', - override: c.pluginConfigAndroid.pluginActivityCreateMethods, + override: c.payload.pluginConfigAndroid.pluginActivityCreateMethods, }, { pattern: '{{INJECT_ON_CREATE}}', - override: c.pluginConfigAndroid.injectActivityOnCreate, + override: c.payload.pluginConfigAndroid.injectActivityOnCreate, }, { pattern: '{{PLUGIN_ON_ACTIVITY_RESULT}}', - override: c.pluginConfigAndroid.pluginActivityResultMethods, + override: c.payload.pluginConfigAndroid.pluginActivityResultMethods, }, ]; @@ -121,7 +123,7 @@ export const parseMainActivitySync = (c: any) => { ); }; -export const parseSplashActivitySync = (c: any) => { +export const parseSplashActivitySync = (c: RnvContext) => { const appFolder = getAppFolder(c); const { platform } = c; const splashPath = 'app/src/main/java/rnv/SplashActivity.kt'; @@ -129,16 +131,18 @@ export const parseSplashActivitySync = (c: any) => { // TODO This is temporary ANDROIDX support. whole kotlin parser will be refactored in the near future const enableAndroidX = getConfigProp(c, platform, 'enableAndroidX', true); if (enableAndroidX === true) { - c.pluginConfigAndroid.pluginSplashActivityImports += 'import androidx.appcompat.app.AppCompatActivity\n'; + c.payload.pluginConfigAndroid.pluginSplashActivityImports += + 'import androidx.appcompat.app.AppCompatActivity\n'; } else { - c.pluginConfigAndroid.pluginSplashActivityImports += 'import android.support.v7.app.AppCompatActivity\n'; + c.payload.pluginConfigAndroid.pluginSplashActivityImports += + 'import android.support.v7.app.AppCompatActivity\n'; } const injects = [ { pattern: '{{APPLICATION_ID}}', override: getAppId(c, platform) }, { pattern: '{{PLUGIN_SPLASH_ACTIVITY_IMPORTS}}', - override: c.pluginConfigAndroid.pluginSplashActivityImports, + override: c.payload.pluginConfigAndroid.pluginSplashActivityImports, }, ]; @@ -151,44 +155,44 @@ export const injectPluginKotlinSync = (c: any, plugin: any, key: any, pkg: any) if (plugin.activityImports instanceof Array) { plugin.activityImports.forEach((activityImport: any) => { // Avoid duplicate imports - if (c.pluginConfigAndroid.pluginActivityImports.indexOf(activityImport) === -1) { - c.pluginConfigAndroid.pluginActivityImports += `import ${activityImport}\n`; + if (c.payload.pluginConfigAndroid.pluginActivityImports.indexOf(activityImport) === -1) { + c.payload.pluginConfigAndroid.pluginActivityImports += `import ${activityImport}\n`; } }); } if (plugin.activityMethods instanceof Array) { - c.pluginConfigAndroid.pluginActivityMethods += '\n'; - c.pluginConfigAndroid.pluginActivityMethods += `${plugin.activityMethods.join('\n ')}`; + c.payload.pluginConfigAndroid.pluginActivityMethods += '\n'; + c.payload.pluginConfigAndroid.pluginActivityMethods += `${plugin.activityMethods.join('\n ')}`; } const { mainActivity } = plugin; if (mainActivity) { if (mainActivity.createMethods instanceof Array) { - c.pluginConfigAndroid.pluginActivityCreateMethods += '\n'; - c.pluginConfigAndroid.pluginActivityCreateMethods += `${mainActivity.createMethods.join('\n ')}`; + c.payload.pluginConfigAndroid.pluginActivityCreateMethods += '\n'; + c.payload.pluginConfigAndroid.pluginActivityCreateMethods += `${mainActivity.createMethods.join('\n ')}`; } if (mainActivity.resultMethods instanceof Array) { - c.pluginConfigAndroid.pluginActivityResultMethods += '\n'; - c.pluginConfigAndroid.pluginActivityResultMethods += `${mainActivity.resultMethods.join('\n ')}`; + c.payload.pluginConfigAndroid.pluginActivityResultMethods += '\n'; + c.payload.pluginConfigAndroid.pluginActivityResultMethods += `${mainActivity.resultMethods.join('\n ')}`; } if (mainActivity.imports instanceof Array) { mainActivity.imports.forEach((v: any) => { - c.pluginConfigAndroid.pluginActivityImports += `import ${v}\n`; + c.payload.pluginConfigAndroid.pluginActivityImports += `import ${v}\n`; }); } if (mainActivity.methods instanceof Array) { - c.pluginConfigAndroid.pluginActivityMethods += '\n'; - c.pluginConfigAndroid.pluginActivityMethods += `${mainActivity.methods.join('\n ')}`; + c.payload.pluginConfigAndroid.pluginActivityMethods += '\n'; + c.payload.pluginConfigAndroid.pluginActivityMethods += `${mainActivity.methods.join('\n ')}`; } } if (plugin.imports) { plugin.imports.forEach((v: any) => { - c.pluginConfigAndroid.pluginApplicationImports += `import ${v}\n`; + c.payload.pluginConfigAndroid.pluginApplicationImports += `import ${v}\n`; }); } @@ -205,19 +209,21 @@ export const injectPluginKotlinSync = (c: any, plugin: any, key: any, pkg: any) const { mainApplication } = plugin; if (mainApplication) { if (mainApplication.createMethods instanceof Array) { - c.pluginConfigAndroid.pluginApplicationCreateMethods += '\n'; - c.pluginConfigAndroid.pluginApplicationCreateMethods += `${mainApplication.createMethods.join('\n ')}`; + c.payload.pluginConfigAndroid.pluginApplicationCreateMethods += '\n'; + c.payload.pluginConfigAndroid.pluginApplicationCreateMethods += `${mainApplication.createMethods.join( + '\n ' + )}`; } if (mainApplication.imports instanceof Array) { mainApplication.imports.forEach((v: any) => { - c.pluginConfigAndroid.pluginApplicationImports += `import ${v}\n`; + c.payload.pluginConfigAndroid.pluginApplicationImports += `import ${v}\n`; }); } if (mainApplication.methods instanceof Array) { - c.pluginConfigAndroid.pluginApplicationMethods += '\n'; - c.pluginConfigAndroid.pluginApplicationMethods += `${mainApplication.methods.join('\n ')}`; + c.payload.pluginConfigAndroid.pluginApplicationMethods += '\n'; + c.payload.pluginConfigAndroid.pluginApplicationMethods += `${mainApplication.methods.join('\n ')}`; } } @@ -225,13 +231,13 @@ export const injectPluginKotlinSync = (c: any, plugin: any, key: any, pkg: any) logWarning( `Plugin ${key} in ${c.paths.project.config} is using DEPRECATED "${c.platform}": { MainApplicationMethods }. Use "${c.platform}": { "mainApplication": { "methods": []}} instead` ); - c.pluginConfigAndroid.pluginApplicationMethods += `\n${plugin.mainApplicationMethods}\n`; + c.payload.pluginConfigAndroid.pluginApplicationMethods += `\n${plugin.mainApplicationMethods}\n`; } }; const _injectPackage = (c: any, plugin: any, pkg: any) => { if (pkg) { - c.pluginConfigAndroid.pluginApplicationImports += `import ${pkg}\n`; + c.payload.pluginConfigAndroid.pluginApplicationImports += `import ${pkg}\n`; } let packageParams = ''; if (plugin.packageParams) { @@ -240,7 +246,7 @@ const _injectPackage = (c: any, plugin: any, pkg: any) => { const className = _extractClassName(pkg); if (className) { - c.pluginConfigAndroid.pluginPackages += `${className}(${packageParams}),\n`; + c.payload.pluginConfigAndroid.pluginPackages += `${className}(${packageParams}),\n`; } }; diff --git a/packages/sdk-android/src/manifestParser.js b/packages/sdk-android/src/manifestParser.ts similarity index 100% rename from packages/sdk-android/src/manifestParser.js rename to packages/sdk-android/src/manifestParser.ts diff --git a/packages/sdk-android/src/types.ts b/packages/sdk-android/src/types.ts new file mode 100644 index 0000000000..73ff746a36 --- /dev/null +++ b/packages/sdk-android/src/types.ts @@ -0,0 +1,51 @@ +import { RenativeConfigPluginPlatform } from 'rnv'; + +export type Payload = { + pluginConfigAndroid: { + gradleWrapperVersion: string; + injectReactNativeEngine: string; + appBuildGradleImplementations: string; + injectHermes: string; + pluginApplicationImports: string; + reactNativeHostMethods: string; + packagingOptions: string; + defaultConfig: string; + appBuildGradleSigningConfigs: string; + appBuildGradleAfterEvaluate: string; + buildTypes: string; + multiAPKs: string; + minSdkVersion: string; + targetSdkVersion: string; + compileSdkVersion: string; + compileOptions: string; + localProperties: string; + kotlinVersion: string; + pluginIncludes: string; + pluginPaths: string; + buildGradleBuildScriptDexOptions: string; + gradleBuildToolsVersion: string; + supportLibVersion: string; + buildToolsVersion: string; + buildGradleAllProjectsRepositories: string; + buildGradleBuildScriptRepositories: string; + googleServicesVersion: string; + pluginActivityImports: string; + buildGradlePlugins: string; + buildGradleAfterAll: string; + buildGradleBuildScriptDependencies: string; + applyPlugin: string; + splits: string; + pluginApplicationDebugServer: string; + pluginPackages: string; + pluginApplicationMethods: string; + pluginApplicationCreateMethods: string; + pluginSplashActivityImports: string; + resourceStrings: RenativeConfigPluginPlatform['ResourceStrings']['children']; + store: { + storeFile: string; + keyAlias: string; + storePassword: string; + keyPassword: string; + }; + }; +}; diff --git a/packages/sdk-android/src/xmlValuesParser.js b/packages/sdk-android/src/xmlValuesParser.ts similarity index 57% rename from packages/sdk-android/src/xmlValuesParser.js rename to packages/sdk-android/src/xmlValuesParser.ts index 948dce50c4..239bd9d161 100644 --- a/packages/sdk-android/src/xmlValuesParser.js +++ b/packages/sdk-android/src/xmlValuesParser.ts @@ -1,23 +1,24 @@ import path from 'path'; -import { FileUtils, Common } from 'rnv'; +import { FileUtils, Common, RnvContext, RenativeConfigPluginPlatform } from 'rnv'; +import { Payload } from './types'; const { getAppFolder, getAppTitle, getBuildFilePath, getConfigProp, sanitizeColor, addSystemInjects } = Common; const { writeFileSync, writeCleanFile } = FileUtils; -export const parseValuesStringsSync = (c) => { - const appFolder = getAppFolder(c, c.platform); +export const parseValuesStringsSync = (c: RnvContext) => { + const appFolder = getAppFolder(c); const stringsPath = 'app/src/main/res/values/strings.xml'; let strings = '\n'; strings += ` ${getAppTitle(c, c.platform)}\n`; - c.pluginConfigAndroid.resourceStrings.forEach((v) => { + c.payload.pluginConfigAndroid.resourceStrings.forEach((v) => { strings += ` <${v.tag} name="${v.name}">${v.child_value}\n`; }); strings += ''; writeFileSync(path.join(appFolder, stringsPath), strings); }; -export const parseValuesColorsSync = (c) => { - const appFolder = getAppFolder(c, c.platform); +export const parseValuesColorsSync = (c: RnvContext) => { + const appFolder = getAppFolder(c); const stringsPath = 'app/src/main/res/values/colors.xml'; const injects = [ @@ -29,14 +30,20 @@ export const parseValuesColorsSync = (c) => { addSystemInjects(c, injects); - writeCleanFile(getBuildFilePath(c, c.platform, stringsPath), path.join(appFolder, stringsPath), injects, null, c); + writeCleanFile( + getBuildFilePath(c, c.platform, stringsPath), + path.join(appFolder, stringsPath), + injects, + undefined, + c + ); }; -export const injectPluginXmlValuesSync = (c, plugin) => { +export const injectPluginXmlValuesSync = (c: RnvContext, plugin: RenativeConfigPluginPlatform) => { const rStrings = plugin.ResourceStrings?.children; if (rStrings) { rStrings.forEach((obj) => { - c.pluginConfigAndroid.resourceStrings.push(obj); + c.payload.pluginConfigAndroid.resourceStrings.push(obj); }); } }; diff --git a/packages/sdk-android/tsconfig.json b/packages/sdk-android/tsconfig.json index 432e693d6c..dbb2990bf5 100644 --- a/packages/sdk-android/tsconfig.json +++ b/packages/sdk-android/tsconfig.json @@ -3,7 +3,6 @@ "compilerOptions": { "outDir": "./dist", "rootDir": "./src", - "allowJs": true, "resolveJsonModule": false, "lib": ["ES2021.String"] }, From de58473fe01f38f831e8cd0414130d91a687ffa0 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Sun, 3 Sep 2023 04:27:10 +0200 Subject: [PATCH 45/83] ts fixes, refactor sdk android --- packages/rnv/src/core/common.ts | 4 +- packages/rnv/src/core/configManager/types.ts | 10 ++++ packages/rnv/src/core/context/contextBase.ts | 1 + packages/rnv/src/core/systemManager/types.ts | 2 +- packages/sdk-android/src/gradleParser.ts | 13 +++-- packages/sdk-android/src/index.ts | 20 ++++++-- packages/sdk-android/src/kotlinParser.ts | 6 +-- packages/sdk-android/src/manifestParser.ts | 54 ++++++++++++++------ packages/sdk-android/src/types.ts | 5 +- 9 files changed, 82 insertions(+), 33 deletions(-) diff --git a/packages/rnv/src/core/common.ts b/packages/rnv/src/core/common.ts index 9763531fe3..bfc7e06e62 100755 --- a/packages/rnv/src/core/common.ts +++ b/packages/rnv/src/core/common.ts @@ -318,8 +318,8 @@ export const _getConfigProp = ( return result; }; -export const getConfigPropArray = (c: RnvContext, platform: string, key: string) => { - const result: Array = []; +export const getConfigPropArray = (c: RnvContext, platform: string, key: string) => { + const result: Array = []; const configArr = [ c.files.defaultWorkspace.config, c.files.rnv.projectTemplates.config, diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index 5146d2490b..1c37f2af5e 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -5,6 +5,9 @@ export type RenativeConfigFile = { buildSchemes?: Record; runtime?: Record; versionCodeFormat?: string; + includedFonts: Array; + includedPermissions: RenativeConfigPermissionsList; + excludedPermissions: RenativeConfigPermissionsList; }; defaults: { ports?: Record; @@ -37,8 +40,11 @@ export type RenativeConfigFile = { templateConfig?: any; enableAnalytics?: boolean; workspaceAppConfigsDir?: string; + permissions: Record; }; +export type RenativeConfigPermission = Record>; + export type RenativeConfigPlatform = { buildSchemes?: Record; entryFile?: string; @@ -51,8 +57,12 @@ export type RenativeConfigPlatform = { buildTypes: Record; }; 'gradle.properties'?: Record; + includedPermissions?: RenativeConfigPermissionsList; + excludedPermissions?: RenativeConfigPermissionsList; }; +export type RenativeConfigPermissionsList = Array; + export type RenativeConfigPlugin = { source?: string; 'no-npm'?: boolean; diff --git a/packages/rnv/src/core/context/contextBase.ts b/packages/rnv/src/core/context/contextBase.ts index cb6b35e4b7..630313fe9a 100644 --- a/packages/rnv/src/core/context/contextBase.ts +++ b/packages/rnv/src/core/context/contextBase.ts @@ -35,6 +35,7 @@ const runtime: any = { }; export const generateConfigBase = (): RnvContext => ({ + payload: {}, assetConfig: {}, rnvVersion: '', buildHooks: {}, diff --git a/packages/rnv/src/core/systemManager/types.ts b/packages/rnv/src/core/systemManager/types.ts index a26ad22d9c..a09f214122 100644 --- a/packages/rnv/src/core/systemManager/types.ts +++ b/packages/rnv/src/core/systemManager/types.ts @@ -37,7 +37,7 @@ export type AnalyticsApi = { export type OverridesOptions = Array<{ pattern: string; - override: string | undefined; + override: string; }>; export type TimestampPathsConfig = { diff --git a/packages/sdk-android/src/gradleParser.ts b/packages/sdk-android/src/gradleParser.ts index d4b83a857a..026b33a353 100644 --- a/packages/sdk-android/src/gradleParser.ts +++ b/packages/sdk-android/src/gradleParser.ts @@ -3,11 +3,13 @@ import { Common, FileUtils, Logger, + OverridesOptions, PluginManager, RenativeConfigPlatform, RenativeConfigPluginPlatform, Resolver, RnvContext, + RnvPlugin, Utils, } from 'rnv'; import { Payload } from './types'; @@ -31,7 +33,7 @@ export const parseBuildGradleSync = (c: RnvContext) => { ${c.payload.pluginConfigAndroid.buildGradleBuildScriptDexOptions} }`; } - const injects = [ + const injects: OverridesOptions = [ { pattern: '{{COMPILE_SDK_VERSION}}', override: c.payload.pluginConfigAndroid.compileSdkVersion, @@ -90,9 +92,10 @@ export const parseBuildGradleSync = (c: RnvContext) => { }, { pattern: '{{PATH_REACT_NATIVE}}', - override: doResolve(c.runtime.runtimeExtraProps?.reactNativePackageName || 'react-native', true, { - forceForwardPaths: true, - }), + override: + doResolve(c.runtime.runtimeExtraProps?.reactNativePackageName || 'react-native', true, { + forceForwardPaths: true, + }) || '', }, ]; addSystemInjects(c, injects); @@ -572,7 +575,7 @@ export const injectPluginGradleSync = ( plugin: RenativeConfigPluginPlatform, key: string, _pkg: string, - pluginRoot + pluginRoot: RnvPlugin ) => { // const keyFixed = key.replace(/\//g, '-').replace(/@/g, ''); // const packagePath = plugin.path ?? `${key}/android`; diff --git a/packages/sdk-android/src/index.ts b/packages/sdk-android/src/index.ts index 41aa3413df..b3be04d97f 100644 --- a/packages/sdk-android/src/index.ts +++ b/packages/sdk-android/src/index.ts @@ -18,6 +18,7 @@ import { SDKManager, RuntimeManager, RnvContext, + RnvPluginPlatform, } from 'rnv'; import { parseAndroidManifestSync, injectPluginManifestSync } from './manifestParser'; import { @@ -92,7 +93,7 @@ export const packageAndroid = async (c: RnvContext) => { 'src', 'main', 'res' - )} --entry-file ${c.buildConfig.platforms[c.platform]?.entryFile}.js --bundle-output ${path.join( + )} --entry-file ${c.buildConfig.platforms?.[c.platform]?.entryFile}.js --bundle-output ${path.join( appFolder, 'app', 'src', @@ -518,7 +519,6 @@ export const configureProject = async (c: RnvContext) => { pluginActivityCreateMethods: '', pluginActivityResultMethods: '', pluginSplashActivityImports: '', - manifestApplication: '', buildGradleAllProjectsRepositories: '', buildGradleBuildScriptRepositories: '', buildGradlePlugins: '', @@ -534,10 +534,22 @@ export const configureProject = async (c: RnvContext) => { injectHermes: '', kotlinVersion: '', googleServicesVersion: '', + buildToolsVersion: '', + buildTypes: '', + compileOptions: '', + compileSdkVersion: '', + gradleBuildToolsVersion: '', + gradleWrapperVersion: '', + localProperties: '', + minSdkVersion: '', + multiAPKs: '', + splits: '', + supportLibVersion: '', + targetSdkVersion: '', }; // PLUGINS - parsePlugins(c, platform, (plugin, pluginPlat, key) => { + parsePlugins(c, platform as RnvPluginPlatform, (plugin, pluginPlat, key) => { injectPluginGradleSync(c, pluginPlat, key, pluginPlat.package, plugin); injectPluginKotlinSync(c, pluginPlat, key, pluginPlat.package); injectPluginManifestSync(); @@ -554,7 +566,7 @@ export const configureProject = async (c: RnvContext) => { if (font.includes('.ttf') || font.includes('.otf')) { const key = font.split('.')[0]; - const { includedFonts } = c.buildConfig.common; + const { includedFonts } = c.buildConfig.common || {}; if (includedFonts) { if (includedFonts.includes('*') || includedFonts.includes(key)) { if (font) { diff --git a/packages/sdk-android/src/kotlinParser.ts b/packages/sdk-android/src/kotlinParser.ts index ba18f9f2ca..87673c399e 100644 --- a/packages/sdk-android/src/kotlinParser.ts +++ b/packages/sdk-android/src/kotlinParser.ts @@ -1,5 +1,5 @@ import path from 'path'; -import { Common, FileUtils, Logger, RnvContext } from 'rnv'; +import { Common, FileUtils, Logger, OverridesOptions, RnvContext } from 'rnv'; import { Payload } from './types'; const { @@ -37,9 +37,9 @@ export const parseMainApplicationSync = (c: RnvContext) => { c.payload.pluginConfigAndroid.pluginApplicationDebugServer += ` mPreferences?.edit()?.putString("debug_http_host", "${bundlerIp}:${c.runtime.port}")?.apply()\n`; } - const injects = [ + const injects: OverridesOptions = [ { pattern: '{{APPLICATION_ID}}', override: getAppId(c, platform) }, - { pattern: '{{ENTRY_FILE}}', override: getEntryFile(c, platform) }, + { pattern: '{{ENTRY_FILE}}', override: getEntryFile(c, platform) || '' }, { pattern: '{{GET_JS_BUNDLE_FILE}}', override: bundleFile }, { pattern: '{{PLUGIN_IMPORTS}}', diff --git a/packages/sdk-android/src/manifestParser.ts b/packages/sdk-android/src/manifestParser.ts index 44febf6534..d22ce0e30b 100644 --- a/packages/sdk-android/src/manifestParser.ts +++ b/packages/sdk-android/src/manifestParser.ts @@ -1,5 +1,14 @@ import path from 'path'; -import { FileUtils, Common, Logger, PluginManager } from 'rnv'; +import { + FileUtils, + Common, + Logger, + PluginManager, + RnvContext, + RenativeConfigPermissionsList, + RnvPluginPlatform, +} from 'rnv'; +import { Payload } from './types'; const { getAppFolder, @@ -17,7 +26,7 @@ const { parsePlugins } = PluginManager; const PROHIBITED_DUPLICATE_TAGS = ['intent-filter']; const SYSTEM_TAGS = ['tag', 'children']; -const _findChildNode = (tag, name, node) => { +const _findChildNode = (tag: string, name: string, node: any) => { if (!node) { logWarning('_findChildNode: Node is undefined'); return; @@ -34,9 +43,9 @@ const _findChildNode = (tag, name, node) => { return null; }; -const _convertToXML = (manifestObj) => _parseNode(manifestObj, 0); +const _convertToXML = (manifestObj: any) => _parseNode(manifestObj, 0); -const _parseNode = (n, level) => { +const _parseNode = (n: any, level: number) => { let output = ''; let space = ''; for (let i = 0; i < level; i++) { @@ -73,7 +82,7 @@ const _parseNode = (n, level) => { } const nextLevel = level + 1; - n.children.forEach((v) => { + n.children.forEach((v: any) => { output += _parseNode(v, nextLevel); }); output += `${space}\n`; @@ -83,7 +92,7 @@ const _parseNode = (n, level) => { return output; }; -const _mergeNodeParameters = (node, nodeParamsExt) => { +const _mergeNodeParameters = (node: any, nodeParamsExt: any) => { if (!nodeParamsExt) { logWarning('_mergeNodeParameters: nodeParamsExt value is null'); return; @@ -98,7 +107,7 @@ const _mergeNodeParameters = (node, nodeParamsExt) => { }); }; -const _mergeNodeChildren = (node, nodeChildrenExt = []) => { +const _mergeNodeChildren = (node: any, nodeChildrenExt: Array = []) => { // console.log('_mergeNodeChildren', node, 'OVERRIDE', nodeChildrenExt); if (!node) { logWarning('_mergeNodeChildren: Node is undefined'); @@ -121,11 +130,22 @@ const _mergeNodeChildren = (node, nodeChildrenExt = []) => { }); }; -const _mergeFeatures = (c, baseManifestFile, configKey, value) => { - const features = getConfigProp(c, c.platform, configKey); +type ManifestFeature = { + tag: string; + 'android:name': string; + 'android:required': boolean; + children?: Array; +}; + +// type ManufestNode = { +// children: +// } + +const _mergeFeatures = (c: RnvContext, baseManifestFile: any, configKey: string, value: boolean) => { + const features = getConfigProp(c, c.platform, configKey); if (features) { - const featuresObj = []; + const featuresObj: Array = []; features.forEach((key) => { featuresObj.push({ tag: 'uses-feature', @@ -137,7 +157,7 @@ const _mergeFeatures = (c, baseManifestFile, configKey, value) => { } }; -export const parseAndroidManifestSync = (c) => { +export const parseAndroidManifestSync = (c: RnvContext) => { logTask('parseAndroidManifestSync'); const { platform } = c; @@ -157,7 +177,7 @@ export const parseAndroidManifestSync = (c) => { }); // appConfigs/base/plugins.json PLUGIN CONFIG OVERRIDES - parsePlugins(c, platform, (plugin, pluginPlat) => { + parsePlugins(c, platform as RnvPluginPlatform, (_plugin, pluginPlat) => { const androidManifestPlugin = getFlavouredProp(c, pluginPlat, 'AndroidManifest'); if (androidManifestPlugin) { _mergeNodeChildren(baseManifestFile, androidManifestPlugin.children); @@ -170,8 +190,8 @@ export const parseAndroidManifestSync = (c) => { // appConfig PERMISSIONS OVERRIDES const configPermissions = c.buildConfig?.permissions; - const includedPermissions = getConfigProp(c, platform, 'includedPermissions'); - const excludedPermissions = getConfigProp(c, platform, 'excludedPermissions'); + const includedPermissions = getConfigProp(c, platform, 'includedPermissions'); + const excludedPermissions = getConfigProp(c, platform, 'excludedPermissions'); if (includedPermissions?.forEach && configPermissions) { const platPerm = configPermissions[platform] ? platform : 'android'; const pc = configPermissions[platPerm]; @@ -208,7 +228,7 @@ export const parseAndroidManifestSync = (c) => { // get correct source of manifest const manifestFile = 'app/src/main/AndroidManifest.xml'; - const injects = [{ pattern: '{{PLUGIN_MANIFEST_FILE}}', override: manifestXml }]; + const injects = [{ pattern: '{{PLUGIN_MANIFEST_FILE}}', override: manifestXml || '' }]; addSystemInjects(c, injects); @@ -218,12 +238,12 @@ export const parseAndroidManifestSync = (c) => { getBuildFilePath(c, platform, manifestFile), path.join(appFolder, manifestFile), injects, - null, + undefined, c ); return; - } catch (e) { + } catch (e: any) { logError(e); } }; diff --git a/packages/sdk-android/src/types.ts b/packages/sdk-android/src/types.ts index 73ff746a36..605e540bbb 100644 --- a/packages/sdk-android/src/types.ts +++ b/packages/sdk-android/src/types.ts @@ -32,16 +32,19 @@ export type Payload = { pluginActivityImports: string; buildGradlePlugins: string; buildGradleAfterAll: string; + pluginActivityCreateMethods: string; buildGradleBuildScriptDependencies: string; applyPlugin: string; splits: string; + pluginActivityMethods: string; pluginApplicationDebugServer: string; pluginPackages: string; pluginApplicationMethods: string; + pluginActivityResultMethods: string; pluginApplicationCreateMethods: string; pluginSplashActivityImports: string; resourceStrings: RenativeConfigPluginPlatform['ResourceStrings']['children']; - store: { + store?: { storeFile: string; keyAlias: string; storePassword: string; From 7a347a42954f1eb7ed111c660d5af7c337fd4a64 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Sun, 3 Sep 2023 17:02:01 +0200 Subject: [PATCH 46/83] refactor apple sdk to TS --- packages/rnv/src/core/configManager/types.ts | 5 ++ packages/rnv/src/core/context/types.ts | 2 + .../rnv/src/core/systemManager/fileutils.ts | 3 +- .../sdk-apple/src/{common.js => common.ts} | 5 +- .../sdk-apple/src/{ejector.js => ejector.ts} | 25 ++++-- .../src/{fastlane.js => fastlane.ts} | 11 +-- packages/sdk-apple/src/{index.js => index.ts} | 90 ++++++++++--------- .../src/{plistParser.js => plistParser.ts} | 47 ++++++---- .../{podfileParser.js => podfileParser.ts} | 44 ++++----- ...{provisionParser.js => provisionParser.ts} | 0 .../src/{swiftParser.js => swiftParser.ts} | 22 ++--- packages/sdk-apple/src/types.ts | 43 +++++++++ .../src/{xcodeParser.js => xcodeParser.ts} | 2 +- .../{xcschemeParser.js => xcschemeParser.ts} | 0 packages/sdk-apple/tsconfig.json | 3 +- packages/sdk-apple/types.d.ts | 1 - 16 files changed, 194 insertions(+), 109 deletions(-) rename packages/sdk-apple/src/{common.js => common.ts} (75%) rename packages/sdk-apple/src/{ejector.js => ejector.ts} (86%) rename packages/sdk-apple/src/{fastlane.js => fastlane.ts} (89%) rename packages/sdk-apple/src/{index.js => index.ts} (92%) rename packages/sdk-apple/src/{plistParser.js => plistParser.ts} (83%) rename packages/sdk-apple/src/{podfileParser.js => podfileParser.ts} (79%) rename packages/sdk-apple/src/{provisionParser.js => provisionParser.ts} (100%) rename packages/sdk-apple/src/{swiftParser.js => swiftParser.ts} (91%) create mode 100644 packages/sdk-apple/src/types.ts rename packages/sdk-apple/src/{xcodeParser.js => xcodeParser.ts} (99%) rename packages/sdk-apple/src/{xcschemeParser.js => xcschemeParser.ts} (100%) diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index 1c37f2af5e..c9882c629d 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -59,6 +59,11 @@ export type RenativeConfigPlatform = { 'gradle.properties'?: Record; includedPermissions?: RenativeConfigPermissionsList; excludedPermissions?: RenativeConfigPermissionsList; + orientationSupport?: { + phone: string; + tab: string; + }; + urlScheme?: string; }; export type RenativeConfigPermissionsList = Array; diff --git a/packages/rnv/src/core/context/types.ts b/packages/rnv/src/core/context/types.ts index 65762a24fd..929fcc2b3c 100644 --- a/packages/rnv/src/core/context/types.ts +++ b/packages/rnv/src/core/context/types.ts @@ -84,6 +84,8 @@ export interface RnvContext { task: string; selectedWorkspace: string; isWSConfirmed: boolean; + _skipNativeDepResolutions: boolean; + targetUDID?: string; }; paths: { GLOBAL_RNV_CONFIG: string; diff --git a/packages/rnv/src/core/systemManager/fileutils.ts b/packages/rnv/src/core/systemManager/fileutils.ts index 5fd6d50acb..0259280483 100755 --- a/packages/rnv/src/core/systemManager/fileutils.ts +++ b/packages/rnv/src/core/systemManager/fileutils.ts @@ -82,12 +82,13 @@ const _getSanitizedPath = (origPath: string, timestampPathsConfig?: TimestampPat }; export const copyFileSync = ( - source: string, + source: string | undefined, target: string | undefined, skipOverride?: boolean, timestampPathsConfig?: TimestampPathsConfig ) => { if (!target) return; + if (!source) return; logDebug('copyFileSync', source); let targetFile = target; // if target is a directory a new file with the same name will be created diff --git a/packages/sdk-apple/src/common.js b/packages/sdk-apple/src/common.ts similarity index 75% rename from packages/sdk-apple/src/common.js rename to packages/sdk-apple/src/common.ts index 99487b507d..a37251002f 100644 --- a/packages/sdk-apple/src/common.js +++ b/packages/sdk-apple/src/common.ts @@ -1,8 +1,9 @@ -import { Common } from 'rnv'; +import { Common, RnvContext } from 'rnv'; +import { Payload } from './types'; const { getConfigProp } = Common; -export const getAppFolderName = (c, platform) => { +export const getAppFolderName = (c: RnvContext, platform: string) => { // NOTE: DEPRECATED let projectFolder = getConfigProp(c, platform, 'projectFolder'); if (projectFolder) { diff --git a/packages/sdk-apple/src/ejector.js b/packages/sdk-apple/src/ejector.ts similarity index 86% rename from packages/sdk-apple/src/ejector.js rename to packages/sdk-apple/src/ejector.ts index 009f6883f5..cd0e4b641d 100644 --- a/packages/sdk-apple/src/ejector.js +++ b/packages/sdk-apple/src/ejector.ts @@ -1,7 +1,8 @@ import path from 'path'; -import { Common, FileUtils, PluginManager, ProjectManager, Resolver } from 'rnv'; +import { Common, FileUtils, PluginManager, ProjectManager, Resolver, RnvPluginPlatform } from 'rnv'; // import { logWarning } from 'rnv/dist/core/systemManager/logger'; import { getAppFolderName } from './common'; +import { Context } from './types'; const { fsExistsSync, @@ -22,7 +23,7 @@ const { // sanitizePluginPath, includesPluginPath } = PluginManager; -export const ejectXcodeProject = async (c) => { +export const ejectXcodeProject = async (c: Context) => { const isMonorepo = getConfigProp(c, c.platform, 'isMonorepo'); const monoRoot = getConfigProp(c, c.platform, 'monoRoot'); @@ -86,14 +87,26 @@ export const ejectXcodeProject = async (c) => { // Plugins //= ========== - parsePlugins(c, c.platform, (_plugin, pluginPlat, key) => { + parsePlugins(c, c.platform as RnvPluginPlatform, (_plugin, pluginPlat, key) => { const podPath = doResolvePath(key); const extensionsFilter = ['.h', '.m', '.swift', '.c', '.podspec', '.rb', '.mm']; // const excludeFolders = ['node_modules', 'android']; - const destPath = path.join(appFolder, 'rn_modules', key); - copyFolderContentsRecursiveSync(podPath, destPath, false, null, false, null, null, c, extensionsFilter); - copyFileSync(path.join(podPath, 'package.json'), path.join(destPath, 'package.json')); + if (podPath) { + const destPath = path.join(appFolder, 'rn_modules', key); + copyFolderContentsRecursiveSync( + podPath, + destPath, + false, + undefined, + false, + undefined, + undefined, + c, + extensionsFilter + ); + copyFileSync(path.join(podPath, 'package.json'), path.join(destPath, 'package.json')); + } }); // try { diff --git a/packages/sdk-apple/src/fastlane.js b/packages/sdk-apple/src/fastlane.ts similarity index 89% rename from packages/sdk-apple/src/fastlane.js rename to packages/sdk-apple/src/fastlane.ts index 958941df5d..0ddbad22c5 100644 --- a/packages/sdk-apple/src/fastlane.js +++ b/packages/sdk-apple/src/fastlane.ts @@ -1,12 +1,13 @@ import path from 'path'; -import { Exec, Logger, Constants, Common } from 'rnv'; +import { Exec, Logger, Constants, Common, RnvContext } from 'rnv'; +import { Payload } from './types'; const { getConfigProp, getAppId } = Common; const { chalk, logTask, logWarning, logSuccess } = Logger; const { executeAsync } = Exec; const { IOS } = Constants; -export const registerDevice = async (c) => { +export const registerDevice = async (c: RnvContext) => { logTask(`registerDevice:${c.platform}`); const teamID = getConfigProp(c, c.platform, 'teamID'); @@ -23,13 +24,13 @@ export const registerDevice = async (c) => { }); logSuccess(`Succesfully registered device ${deviceName}:${udid}:${teamID}`); return true; - } catch (e) { + } catch (e: any) { logWarning(e); return true; } }; -export const updateProfile = async (c, appConfigId) => { +export const updateProfile = async (c: RnvContext, appConfigId: string) => { logTask(`updateProfile:${appConfigId}`, chalk().grey); // TODO: run trough all schemes @@ -89,7 +90,7 @@ export const updateProfile = async (c, appConfigId) => { }); logSuccess(`Succesfully updated provisioning profile for ${appId}:${scheme}:${id}`); return true; - } catch (e) { + } catch (e: any) { logWarning(e); return true; } diff --git a/packages/sdk-apple/src/index.js b/packages/sdk-apple/src/index.ts similarity index 92% rename from packages/sdk-apple/src/index.js rename to packages/sdk-apple/src/index.ts index 3390a60849..9d5e5a7590 100644 --- a/packages/sdk-apple/src/index.js +++ b/packages/sdk-apple/src/index.ts @@ -3,6 +3,7 @@ import crypto from 'crypto'; import inquirer from 'inquirer'; import path from 'path'; import { + AppleDevice, Common, Constants, EngineManager, @@ -22,6 +23,7 @@ import { parseAppDelegate } from './swiftParser'; import { parseXcodeProject } from './xcodeParser'; import { parseXcscheme } from './xcschemeParser'; import { ejectXcodeProject } from './ejector'; +import { Context } from './types'; const { getAppleDevices, launchAppleSimulator } = SDKManager.Apple; @@ -36,13 +38,13 @@ const { copyAssetsFolder, copyBuildsFolder, parseFonts } = ProjectManager; const { IOS, MACOS, TVOS } = Constants; const { chalk, logInfo, logTask, logError, logWarning, logDebug, logSuccess, logRaw } = Logger; -export const generateChecksum = (str, algorithm, encoding) => +export const generateChecksum = (str: string, algorithm?: string, encoding?: string) => crypto .createHash(algorithm || 'md5') .update(str, 'utf8') .digest(encoding || 'hex'); -const checkIfPodsIsRequired = async (c) => { +const checkIfPodsIsRequired = async (c: Context) => { const appFolder = getAppFolder(c, c.platform); const podChecksumPath = path.join(appFolder, 'Podfile.checksum'); if (!fsExistsSync(podChecksumPath)) return true; @@ -59,9 +61,9 @@ const checkIfPodsIsRequired = async (c) => { return false; }; -const updatePodsChecksum = (c) => { +const updatePodsChecksum = (c: Context) => { logTask('updatePodsChecksum'); - const appFolder = getAppFolder(c, c.platform); + const appFolder = getAppFolder(c); const podChecksumPath = path.join(appFolder, 'Podfile.checksum'); const podContentChecksum = generateChecksum(fsReadFileSync(path.join(appFolder, 'Podfile')).toString()); if (fsExistsSync(podChecksumPath)) { @@ -76,7 +78,7 @@ const updatePodsChecksum = (c) => { return fsWriteFileSync(podChecksumPath, podContentChecksum); }; -const runCocoaPods = async (c) => { +const runCocoaPods = async (c: Context) => { logTask('runCocoaPods', `forceUpdate:${!!c.program.updatePods}`); if (c.runtime._skipNativeDepResolutions) return; @@ -122,8 +124,8 @@ const runCocoaPods = async (c) => { } }; -const copyAppleAssets = (c, platform, appFolderName) => - new Promise((resolve) => { +const copyAppleAssets = (c: Context, platform: string, appFolderName: string) => + new Promise((resolve) => { logTask('copyAppleAssets'); if (!isPlatformActive(c, platform, resolve)) return; @@ -137,18 +139,18 @@ const copyAppleAssets = (c, platform, appFolderName) => resolve(); }); -export const runXcodeProject = async (c) => { +export const runXcodeProject = async (c: Context) => { logTask('runXcodeProject', `target:${c.runtime.target}`); - const appPath = getAppFolder(c, c.platform); + const appPath = getAppFolder(c); const { device } = c.program; const appFolderName = getAppFolderName(c, c.platform); const runScheme = getConfigProp(c, c.platform, 'runScheme'); const bundleIsDev = getConfigProp(c, c.platform, 'bundleIsDev') === true; const bundleAssets = getConfigProp(c, c.platform, 'bundleAssets') === true; - let p; + let p: string | undefined; - let devicesArr; + let devicesArr: AppleDevice[] = []; if (device === true) { devicesArr = await getAppleDevices(c, false, true); } else if (c.runtime.target) { @@ -169,7 +171,7 @@ export const runXcodeProject = async (c) => { p = `--device ${devicesArr[0].name}`; } } else if (devicesArr.length > 1) { - const run = (selectedDevice) => { + const run = (selectedDevice: AppleDevice) => { logDebug(`Selected device: ${JSON.stringify(selectedDevice, null, 3)}`); c.runtime.targetUDID = selectedDevice.udid; if (selectedDevice.udid) { @@ -303,7 +305,7 @@ export const runXcodeProject = async (c) => { } try { - await buildXcodeProject(c, c.platform); + await buildXcodeProject(c); } catch (e) { await _handleMissingTeam(c, e); } @@ -323,7 +325,15 @@ export const runXcodeProject = async (c) => { // return Promise.reject('Missing options for react-native command!'); }; -const _packageOrRun = (c, bundleAssets, bundleIsDev, appPath, scheme, runScheme, p) => { +const _packageOrRun = ( + c: Context, + bundleAssets: boolean, + bundleIsDev: boolean, + appPath: string, + scheme: string, + runScheme: string, + p: string +) => { if (bundleAssets) { return packageBundleForXcode(c, bundleIsDev).then(() => _checkLockAndExec(c, appPath, scheme, runScheme, p)); } @@ -335,7 +345,7 @@ const _packageOrRun = (c, bundleAssets, bundleIsDev, appPath, scheme, runScheme, // return path.join(cli, 'build/bin.js'); // }; -const _checkLockAndExec = async (c, appPath, scheme, runScheme, p = '') => { +const _checkLockAndExec = async (c: Context, appPath: string, scheme: string, runScheme: string, p = '') => { logTask('_checkLockAndExec', `scheme:${scheme} runScheme:${runScheme}`); const appFolderName = getAppFolderName(c, c.platform); @@ -346,7 +356,7 @@ const _checkLockAndExec = async (c, appPath, scheme, runScheme, p = '') => { // Inherit full logs // return executeAsync(c, cmd, { stdio: 'inherit', silent: true }); return executeAsync(c, cmd); - } catch (e) { + } catch (e: any) { if (e && e.includes) { const isDeviceLocked = e.includes('ERROR:DEVICE_LOCKED'); if (isDeviceLocked) { @@ -416,7 +426,7 @@ and we will try to help! } }; -const _handleMissingTeam = async (c, e) => { +const _handleMissingTeam = async (c: Context, e: any) => { const isDevelopmentTeamMissing = e.includes('requires a development team. Select a development team'); if (isDevelopmentTeamMissing) { const loc = `./appConfigs/${c.runtime.appId}/renative.json:{ "platforms": { "${c.platform}": { "teamID": "....."`; @@ -443,7 +453,7 @@ Type in your Apple Team ID to be used (will be saved to ${c.paths.appConfig?.con } }; -const _handleProvisioningIssues = async (c, e, msg) => { +const _handleProvisioningIssues = async (c: Context, e: any, msg: string) => { const provisioningStyle = getConfigProp(c, c.platform, 'provisioningStyle'); const appFolderName = getAppFolderName(c, c.platform); // Sometimes xcodebuild reports Automatic signing is disabled but it could be keychain not accepted by user const isProvAutomatic = provisioningStyle === 'Automatic'; @@ -453,7 +463,7 @@ const _handleProvisioningIssues = async (c, e, msg) => { c.platform }, scheme: ${c.runtime.scheme}`; const fixCommand = `rnv crypto updateProfile -p ${c.platform} -s ${c.runtime.scheme}`; - const workspacePath = chalk().white(`${getAppFolder(c, c.platform)}/${appFolderName}.xcworkspace`); + const workspacePath = chalk().white(`${getAppFolder(c)}/${appFolderName}.xcworkspace`); logError(e); logWarning(`${msg}. To fix try: ${chalk().white('[1]>')} Configure your certificates, provisioning profiles correctly manually @@ -479,7 +489,7 @@ ${proAutoText}`); } }; -const _setAutomaticSigning = async (c) => { +const _setAutomaticSigning = async (c: Context) => { logTask(`_setAutomaticSigning:${c.platform}`); const scheme = c.files.appConfig?.config?.platforms?.[c.platform]?.buildSchemes?.[c.runtime.scheme]; @@ -494,7 +504,7 @@ const _setAutomaticSigning = async (c) => { } }; -const _setDevelopmentTeam = async (c, teamID) => { +const _setDevelopmentTeam = async (c: Context, teamID: string) => { logTask(`_setDevelopmentTeam:${teamID}`); try { @@ -512,7 +522,7 @@ const _setDevelopmentTeam = async (c, teamID) => { logSuccess(`Succesfully updated ${c.paths.appConfig.config}`); }; -const composeXcodeArgsFromCLI = (string) => { +const composeXcodeArgsFromCLI = (string: string) => { const spacesReplaced = string.replace(/\s(?=(?:[^'"`]*(['"`])[^'"`]*\1)*[^'"`]*$)/g, '&&&'); // replaces spaces outside quotes with &&& for easy split const keysAndValues = spacesReplaced.split('&&&'); const unescapedValues = keysAndValues.map((s) => s.replace(/'/g, '').replace(/"/g, '').replace(/\\/g, '')); // removes all quotes or backslashes @@ -520,7 +530,7 @@ const composeXcodeArgsFromCLI = (string) => { return unescapedValues; }; -export const buildXcodeProject = async (c) => { +export const buildXcodeProject = async (c: Context) => { logTask('buildXcodeProject'); const { platform } = c; @@ -616,7 +626,7 @@ export const buildXcodeProject = async (c) => { }); }; -const archiveXcodeProject = (c) => { +const archiveXcodeProject = (c: Context) => { logTask('archiveXcodeProject'); const { platform } = c; @@ -684,7 +694,7 @@ const archiveXcodeProject = (c) => { }); }; -const exportXcodeProject = async (c) => { +const exportXcodeProject = async (c: Context) => { logTask('exportXcodeProject'); const { platform } = c; @@ -728,7 +738,7 @@ const exportXcodeProject = async (c) => { }); }; -export const packageBundleForXcode = (c, isDev = false) => { +export const packageBundleForXcode = (c: Context, isDev = false) => { logTask('packageBundleForXcode'); // const { maxErrorLength } = c.program; const args = [ @@ -740,14 +750,14 @@ export const packageBundleForXcode = (c, isDev = false) => { '--assets-dest', `platformBuilds/${c.runtime.appId}_${c.platform}${c.runtime._platformBuildsSuffix || ''}`, '--entry-file', - `${c.buildConfig.platforms[c.platform].entryFile}.js`, + `${c.buildConfig.platforms?.[c.platform].entryFile}.js`, '--bundle-output', - `${getAppFolder(c, c.platform)}/main.jsbundle`, + `${getAppFolder(c)}/main.jsbundle`, ]; if (getConfigProp(c, c.platform, 'enableSourceMaps', false)) { args.push('--sourcemap-output'); - args.push(`${getAppFolder(c, c.platform)}/main.jsbundle.map`); + args.push(`${getAppFolder(c)}/main.jsbundle.map`); } if (c.program.info) { @@ -766,7 +776,7 @@ export const packageBundleForXcode = (c, isDev = false) => { }; // Resolve or reject will not be called so this will keep running -const runAppleLog = (c) => +const runAppleLog = (c: Context) => new Promise(() => { logTask('runAppleLog'); const filter = c.program.filter || 'RNV'; @@ -788,7 +798,7 @@ const runAppleLog = (c) => }); }); -const configureXcodeProject = async (c) => { +const configureXcodeProject = async (c: Context) => { logTask('configureXcodeProject'); const { device } = c.program; @@ -800,7 +810,7 @@ const configureXcodeProject = async (c) => { const bundleAssets = getConfigProp(c, platform, 'bundleAssets') === true; // INJECTORS - c.pluginConfigiOS = { + c.payload.pluginConfigiOS = { podfileInject: '', podPostInstall: '', staticPodExtraConditions: '', @@ -846,14 +856,14 @@ const configureXcodeProject = async (c) => { // // TODO: enable this once mmoved to modular_headers Podfile // // if (ignoreProjectFonts) { // // ignoreProjectFonts.forEach((v) => { - // // if (!c.pluginConfigiOS.ignoreProjectFonts.includes(v)) { + // // if (!c.payload.pluginConfigiOS.ignoreProjectFonts.includes(v)) { // // logDebug(`Igonoring font: ${v}`); - // // c.pluginConfigiOS.ignoreProjectFonts.push(v); + // // c.payload.pluginConfigiOS.ignoreProjectFonts.push(v); // // } // // }); // // } // }); - const embeddedFontSourcesCheck = []; + const embeddedFontSourcesCheck: Array = []; parseFonts(c, (font, dir) => { if (font.includes('.ttf') || font.includes('.otf')) { const key = font.split('.')[0]; @@ -867,15 +877,15 @@ const configureXcodeProject = async (c) => { copyFileSync(fontSource, fontDest); if ( - !c.pluginConfigiOS.ignoreProjectFonts.includes(font) && + !c.payload.pluginConfigiOS.ignoreProjectFonts.includes(font) && !embeddedFontSourcesCheck.includes(font) ) { - c.pluginConfigiOS.embeddedFontSources.push(fontSource); + c.payload.pluginConfigiOS.embeddedFontSources.push(fontSource); embeddedFontSourcesCheck.push(font); } - if (!c.pluginConfigiOS.embeddedFonts.includes(font)) { - c.pluginConfigiOS.embeddedFonts.push(font); + if (!c.payload.pluginConfigiOS.embeddedFonts.includes(font)) { + c.payload.pluginConfigiOS.embeddedFonts.push(font); } } else { logWarning(`Font ${chalk().white(fontSource)} doesn't exist! Skipping.`); @@ -904,7 +914,7 @@ const configureXcodeProject = async (c) => { await parseInfoPlist(c, platform); await copyBuildsFolder(c, platform); await runCocoaPods(c); - await parseXcodeProject(c, platform); + await parseXcodeProject(c); return true; }; diff --git a/packages/sdk-apple/src/plistParser.js b/packages/sdk-apple/src/plistParser.ts similarity index 83% rename from packages/sdk-apple/src/plistParser.js rename to packages/sdk-apple/src/plistParser.ts index 16ba5cd3de..6b73e292bb 100644 --- a/packages/sdk-apple/src/plistParser.js +++ b/packages/sdk-apple/src/plistParser.ts @@ -1,6 +1,15 @@ import path from 'path'; -import { Logger, Common, ObjectUtils, PluginManager, FileUtils } from 'rnv'; +import { + Logger, + Common, + ObjectUtils, + PluginManager, + FileUtils, + RnvPluginPlatform, + RenativeConfigPermissionsList, +} from 'rnv'; import { getAppFolderName } from './common'; +import { Context } from './types'; const { isObject, isArray, isBool, isString, isNumber } = ObjectUtils; const { @@ -17,15 +26,15 @@ const { logTask, logError, logWarning } = Logger; const { parsePlugins } = PluginManager; const { readObjectSync, mergeObjects, writeCleanFile, fsWriteFileSync } = FileUtils; -export const parseExportOptionsPlist = (c, platform) => - new Promise((resolve) => { +export const parseExportOptionsPlist = (c: Context, platform: string) => + new Promise((resolve) => { // EXPORT OPTIONS const tId = getConfigProp(c, platform, 'teamID'); const appFolder = getAppFolder(c); const exportOptions = getConfigProp(c, platform, 'exportOptions') || {}; const id = getConfigProp(c, platform, 'id'); - c.pluginConfigiOS.exportOptions = objToPlist(exportOptions); + c.payload.pluginConfigiOS.exportOptions = objToPlist(exportOptions); if (exportOptions.provisioningProfiles) { const expProvProfile = exportOptions.provisioningProfiles[id]; @@ -42,18 +51,18 @@ export const parseExportOptionsPlist = (c, platform) => { pattern: '{{TEAM_ID}}', override: tId }, { pattern: '{{PLUGIN_EXPORT_OPTIONS}}', - override: c.pluginConfigiOS.exportOptions, + override: c.payload.pluginConfigiOS.exportOptions, }, ]; addSystemInjects(c, injects); - writeCleanFile(bPath, path.join(appFolder, 'exportOptions.plist'), injects, null, c); + writeCleanFile(bPath, path.join(appFolder, 'exportOptions.plist'), injects, undefined, c); resolve(); }); -export const parseEntitlementsPlist = (c, platform) => - new Promise((resolve) => { +export const parseEntitlementsPlist = (c: Context, platform: string) => + new Promise((resolve) => { logTask('parseEntitlementsPlist'); const appFolder = getAppFolder(c); @@ -69,13 +78,13 @@ export const parseEntitlementsPlist = (c, platform) => resolve(); }); -export const parseInfoPlist = (c, platform) => - new Promise((resolve) => { +export const parseInfoPlist = (c: Context, platform: string) => + new Promise((resolve) => { logTask('parseInfoPlist'); const appFolder = getAppFolder(c); const appFolderName = getAppFolderName(c, platform); - const plat = c.buildConfig.platforms[platform]; + const plat = c.buildConfig.platforms?.[platform] || {}; const { orientationSupport, urlScheme } = plat; const plistPath = path.join(appFolder, `${appFolderName}/Info.plist`); @@ -85,11 +94,11 @@ export const parseInfoPlist = (c, platform) => plistObj.CFBundleShortVersionString = getAppVersion(c, platform); plistObj.CFBundleVersion = getAppVersionCode(c, platform); // FONTS - if (c.pluginConfigiOS.embeddedFonts.length) { - plistObj.UIAppFonts = c.pluginConfigiOS.embeddedFonts; + if (c.payload.pluginConfigiOS.embeddedFonts.length) { + plistObj.UIAppFonts = c.payload.pluginConfigiOS.embeddedFonts; } // PERMISSIONS - const includedPermissions = getConfigProp(c, platform, 'includedPermissions'); + const includedPermissions = getConfigProp(c, platform, 'includedPermissions'); if (includedPermissions && c.buildConfig.permissions) { const platPrem = c.buildConfig.permissions[platform] ? platform : 'ios'; const pc = c.buildConfig.permissions[platPrem]; @@ -139,7 +148,7 @@ export const parseInfoPlist = (c, platform) => } // PLUGINS - parsePlugins(c, platform, (plugin, pluginPlat) => { + parsePlugins(c, platform as RnvPluginPlatform, (plugin, pluginPlat) => { const plistPlug = getFlavouredProp(c, pluginPlat, 'plist'); if (plistPlug) { plistObj = mergeObjects(c, plistObj, plistPlug, true, false); @@ -155,14 +164,14 @@ const PLIST_START = ` const PLIST_END = '\n'; -const objToPlist = (obj) => { +const objToPlist = (obj: any): string => { let output = PLIST_START; output += _parseObject(obj, 0); output += PLIST_END; return output; }; -const _parseObject = (obj, level) => { +const _parseObject = (obj: any, level: number) => { let output = ''; let space = ''; for (let i = 0; i < level; i++) { @@ -170,7 +179,7 @@ const _parseObject = (obj, level) => { } if (isArray(obj)) { output += `${space}\n`; - obj.forEach((v) => { + obj.forEach((v: any) => { output += _parseObject(v, level + 1); }); output += `${space}\n`; @@ -192,7 +201,7 @@ const _parseObject = (obj, level) => { return output; }; -const saveObjToPlistSync = (c, filePath, obj) => { +const saveObjToPlistSync = (c: Context, filePath: string, obj: any) => { // fsWriteFileSync(filePath, objToPlist(sanitizeDynamicProps(obj, c.buildConfig?._refs))); fsWriteFileSync(filePath, objToPlist(obj)); }; diff --git a/packages/sdk-apple/src/podfileParser.js b/packages/sdk-apple/src/podfileParser.ts similarity index 79% rename from packages/sdk-apple/src/podfileParser.js rename to packages/sdk-apple/src/podfileParser.ts index 1b77b4a6b8..d4b4b04998 100644 --- a/packages/sdk-apple/src/podfileParser.js +++ b/packages/sdk-apple/src/podfileParser.ts @@ -17,7 +17,7 @@ export const parsePodFile = async (c, platform) => { let pluginInject = ''; // PLUGINS - c.pluginConfigiOS.podfileInject = ''; + c.payload.pluginConfigiOS.podfileInject = ''; parsePlugins(c, platform, (plugin, pluginPlat, key) => { const podName = getFlavouredProp(c, pluginPlat, 'podName'); if (podName) { @@ -37,15 +37,15 @@ export const parsePodFile = async (c, platform) => { } const isStatic = getFlavouredProp(c, pluginPlat, 'isStatic'); if (isStatic === true) { - if (!c.pluginConfigiOS.staticFrameworks.includes(podName)) { - c.pluginConfigiOS.staticFrameworks.push(`'${podName}'`); + if (!c.payload.pluginConfigiOS.staticFrameworks.includes(podName)) { + c.payload.pluginConfigiOS.staticFrameworks.push(`'${podName}'`); } } const staticPods = getFlavouredProp(c, pluginPlat, 'staticPods'); if (staticPods?.forEach) { staticPods.forEach((sPod) => { if (sPod.startsWith('::startsWith::')) { - c.pluginConfigiOS.staticPodExtraConditions += ` || pod.name.start_with?('${sPod.replace( + c.payload.pluginConfigiOS.staticPodExtraConditions += ` || pod.name.start_with?('${sPod.replace( '::startsWith::', '' )}')`; @@ -64,20 +64,20 @@ export const parsePodFile = async (c, platform) => { // INJECT LINES if (injectLines) { injectLines.forEach((v) => { - c.pluginConfigiOS.podfileInject += `${v}\n`; + c.payload.pluginConfigiOS.podfileInject += `${v}\n`; }); } if (post_install) { post_install.forEach((v) => { - c.pluginConfigiOS.podPostInstall += `${v}\n`; + c.payload.pluginConfigiOS.podPostInstall += `${v}\n`; }); } const podfileSources = podfile?.sources; if (podfileSources && podfileSources.length) { podfileSources.forEach((v) => { - if (!c.pluginConfigiOS.podfileSources.includes(v)) { - c.pluginConfigiOS.podfileSources += `source '${v}'\n`; + if (!c.payload.pluginConfigiOS.podfileSources.includes(v)) { + c.payload.pluginConfigiOS.podfileSources += `source '${v}'\n`; } }); } @@ -94,21 +94,21 @@ export const parsePodFile = async (c, platform) => { // INJECT LINES if (injectLines) { injectLines.forEach((v) => { - c.pluginConfigiOS.podfileInject += `${v}\n`; + c.payload.pluginConfigiOS.podfileInject += `${v}\n`; }); } // POST INSTALL if (post_install) { post_install.forEach((v) => { - c.pluginConfigiOS.podPostInstall += `${v}\n`; + c.payload.pluginConfigiOS.podPostInstall += `${v}\n`; }); } // SOURCES const podfileSources = podfile?.sources; if (podfileSources && podfileSources.length) { podfileSources.forEach((v) => { - if (!c.pluginConfigiOS.podfileSources.includes(v)) { - c.pluginConfigiOS.podfileSources += `source '${v}'\n`; + if (!c.payload.pluginConfigiOS.podfileSources.includes(v)) { + c.payload.pluginConfigiOS.podfileSources += `source '${v}'\n`; } }); } @@ -116,16 +116,16 @@ export const parsePodFile = async (c, platform) => { // DEPLOYMENT TARGET const deploymentTarget = getConfigProp(c, platform, 'deploymentTarget', '11.0'); - c.pluginConfigiOS.deploymentTarget = deploymentTarget; + c.payload.pluginConfigiOS.deploymentTarget = deploymentTarget; // STATIC POD INJECT VERSION - c.pluginConfigiOS.staticPodDefinition = 'Pod::BuildType.static_library'; + c.payload.pluginConfigiOS.staticPodDefinition = 'Pod::BuildType.static_library'; if (!c.runtime._skipNativeDepResolutions) { try { const podVersion = await executeAsync(c, 'pod --version'); const isPodOld = compareVersions(podVersion, '1.9') < 0; if (isPodOld) { - c.pluginConfigiOS.staticPodDefinition = 'Pod::Target::BuildType.static_library'; + c.payload.pluginConfigiOS.staticPodDefinition = 'Pod::Target::BuildType.static_library'; } } catch (e) { // Ignore @@ -137,23 +137,23 @@ export const parsePodFile = async (c, platform) => { { pattern: '{{PLUGIN_WARNINGS}}', override: podWarnings }, { pattern: '{{PLUGIN_PODFILE_INJECT}}', - override: c.pluginConfigiOS.podfileInject, + override: c.payload.pluginConfigiOS.podfileInject, }, { pattern: '{{INJECT_POST_INSTALL}}', - override: c.pluginConfigiOS.podPostInstall, + override: c.payload.pluginConfigiOS.podPostInstall, }, { pattern: '{{PLUGIN_PODFILE_SOURCES}}', - override: c.pluginConfigiOS.podfileSources, + override: c.payload.pluginConfigiOS.podfileSources, }, { pattern: '{{PLUGIN_DEPLOYMENT_TARGET}}', - override: c.pluginConfigiOS.deploymentTarget, + override: c.payload.pluginConfigiOS.deploymentTarget, }, { pattern: '{{PLUGIN_STATIC_FRAMEWORKS}}', - override: c.pluginConfigiOS.staticFrameworks.join(','), + override: c.payload.pluginConfigiOS.staticFrameworks.join(','), }, { pattern: '{{PATH_JSC_ANDROID}}', @@ -165,11 +165,11 @@ export const parsePodFile = async (c, platform) => { }, { pattern: '{{PLUGIN_STATIC_POD_DEFINITION}}', - override: c.pluginConfigiOS.staticPodDefinition, + override: c.payload.pluginConfigiOS.staticPodDefinition, }, { pattern: '{{PLUGIN_STATIC_POD_EXTRA_CONDITIONS}}', - override: c.pluginConfigiOS.staticPodExtraConditions, + override: c.payload.pluginConfigiOS.staticPodExtraConditions, }, ]; diff --git a/packages/sdk-apple/src/provisionParser.js b/packages/sdk-apple/src/provisionParser.ts similarity index 100% rename from packages/sdk-apple/src/provisionParser.js rename to packages/sdk-apple/src/provisionParser.ts diff --git a/packages/sdk-apple/src/swiftParser.js b/packages/sdk-apple/src/swiftParser.ts similarity index 91% rename from packages/sdk-apple/src/swiftParser.js rename to packages/sdk-apple/src/swiftParser.ts index 0e78cf36a2..bd7b0300f6 100644 --- a/packages/sdk-apple/src/swiftParser.js +++ b/packages/sdk-apple/src/swiftParser.ts @@ -171,7 +171,7 @@ export const parseAppDelegate = (c, platform, appFolder, appFolderName, isBundle const method = methods[key]; Object.keys(method).forEach((key2) => { const f = method[key2]; - const lines = c.pluginConfigiOS.appDelegateMethods[key][key2]; + const lines = c.payload.pluginConfigiOS.appDelegateMethods[key][key2]; const cleanedLines = {}; lines.forEach((l) => { @@ -195,7 +195,7 @@ export const parseAppDelegate = (c, platform, appFolder, appFolderName, isBundle }); injectors.forEach((v) => { - c.pluginConfigiOS.pluginAppDelegateMethods += constructMethod(v.lines, v.f); + c.payload.pluginConfigiOS.pluginAppDelegateMethods += constructMethod(v.lines, v.f); }); const injects = [ @@ -206,15 +206,15 @@ export const parseAppDelegate = (c, platform, appFolder, appFolderName, isBundle { pattern: '{{BACKGROUND_COLOR}}', override: pluginBgColor }, { pattern: '{{APPDELEGATE_IMPORTS}}', - override: c.pluginConfigiOS.pluginAppDelegateImports, + override: c.payload.pluginConfigiOS.pluginAppDelegateImports, }, { pattern: '{{APPDELEGATE_METHODS}}', - override: c.pluginConfigiOS.pluginAppDelegateMethods, + override: c.payload.pluginConfigiOS.pluginAppDelegateMethods, }, { pattern: '{{APPDELEGATE_EXTENSIONS}}', - override: c.pluginConfigiOS.pluginAppDelegateExtensions, + override: c.payload.pluginConfigiOS.pluginAppDelegateExtensions, }, ]; @@ -237,14 +237,14 @@ export const injectPluginSwiftSync = (c, plugin, key) => { appDelegateImports.forEach((appDelegateImport) => { // Avoid duplicate imports logDebug('appDelegateImports add'); - if (c.pluginConfigiOS.pluginAppDelegateImports.indexOf(appDelegateImport) === -1) { + if (c.payload.pluginConfigiOS.pluginAppDelegateImports.indexOf(appDelegateImport) === -1) { logDebug('appDelegateImports add ok'); - c.pluginConfigiOS.pluginAppDelegateImports += `import ${appDelegateImport}\n`; + c.payload.pluginConfigiOS.pluginAppDelegateImports += `import ${appDelegateImport}\n`; } }); } // if (plugin.appDelegateMethods instanceof Array) { - // c.pluginConfigiOS.pluginAppDelegateMethods += `${plugin.appDelegateMethods.join('\n ')}`; + // c.payload.pluginConfigiOS.pluginAppDelegateMethods += `${plugin.appDelegateMethods.join('\n ')}`; // } const appDelegateExtensions = getFlavouredProp(c, plugin, 'appDelegateExtensions'); @@ -252,9 +252,9 @@ export const injectPluginSwiftSync = (c, plugin, key) => { appDelegateExtensions.forEach((appDelegateExtension) => { // Avoid duplicate imports logDebug('appDelegateExtensions add'); - if (c.pluginConfigiOS.pluginAppDelegateExtensions.indexOf(appDelegateExtension) === -1) { + if (c.payload.pluginConfigiOS.pluginAppDelegateExtensions.indexOf(appDelegateExtension) === -1) { logDebug('appDelegateExtensions add ok'); - c.pluginConfigiOS.pluginAppDelegateExtensions += `, ${appDelegateExtension}`; + c.payload.pluginConfigiOS.pluginAppDelegateExtensions += `, ${appDelegateExtension}`; } }); } @@ -263,7 +263,7 @@ export const injectPluginSwiftSync = (c, plugin, key) => { if (appDelegateMethods) { Object.keys(appDelegateMethods).forEach((delKey) => { Object.keys(appDelegateMethods[delKey]).forEach((key2) => { - const plugArr = c.pluginConfigiOS.appDelegateMethods[delKey][key2]; + const plugArr = c.payload.pluginConfigiOS.appDelegateMethods[delKey][key2]; if (!plugArr) { logWarning(`appDelegateMethods.${delKey}.${chalk().red(key2)} not supported. SKIPPING.`); } else { diff --git a/packages/sdk-apple/src/types.ts b/packages/sdk-apple/src/types.ts new file mode 100644 index 0000000000..6f66e38c7b --- /dev/null +++ b/packages/sdk-apple/src/types.ts @@ -0,0 +1,43 @@ +import { RnvContext } from 'rnv'; + +export type Payload = { + pluginConfigiOS: { + exportOptions: string; + // exportOptions: { + // provisioningProfiles: Record; + // }; + embeddedFonts: Array; + podfileInject: string; + podPostInstall: string; + staticPodExtraConditions: string; + staticFrameworks: Array; + staticPodDefinition: string; + embeddedFontSources: Array; + ignoreProjectFonts: Array; + pluginAppDelegateImports: string; + pluginAppDelegateMethods: string; + pluginAppDelegateExtensions: string; + appDelegateMethods: { + application: { + didFinishLaunchingWithOptions: Array; + applicationDidBecomeActive: Array; + open: Array; + supportedInterfaceOrientationsFor: Array; + didReceiveRemoteNotification: Array; + didFailToRegisterForRemoteNotificationsWithError: Array; + didReceive: Array; + didRegister: Array; + didRegisterForRemoteNotificationsWithDeviceToken: Array; + continue: Array; + didConnectCarInterfaceController: Array; + didDisconnectCarInterfaceController: Array; + }; + userNotificationCenter: { + willPresent: Array; + }; + }; + podfileSources: string; + }; +}; + +export type Context = RnvContext; diff --git a/packages/sdk-apple/src/xcodeParser.js b/packages/sdk-apple/src/xcodeParser.ts similarity index 99% rename from packages/sdk-apple/src/xcodeParser.js rename to packages/sdk-apple/src/xcodeParser.ts index f6af9f305b..3aa68621fd 100644 --- a/packages/sdk-apple/src/xcodeParser.js +++ b/packages/sdk-apple/src/xcodeParser.ts @@ -247,7 +247,7 @@ const _parseXcodeProject = (c, platform) => // FONTS // Cocoapods take care of this - c.pluginConfigiOS.embeddedFontSources.forEach((v) => { + c.payload.pluginConfigiOS.embeddedFontSources.forEach((v) => { xcodeProj.addResourceFile(v, { variantGroup: false }); }); diff --git a/packages/sdk-apple/src/xcschemeParser.js b/packages/sdk-apple/src/xcschemeParser.ts similarity index 100% rename from packages/sdk-apple/src/xcschemeParser.js rename to packages/sdk-apple/src/xcschemeParser.ts diff --git a/packages/sdk-apple/tsconfig.json b/packages/sdk-apple/tsconfig.json index 9d2faec89d..432e693d6c 100644 --- a/packages/sdk-apple/tsconfig.json +++ b/packages/sdk-apple/tsconfig.json @@ -4,7 +4,8 @@ "outDir": "./dist", "rootDir": "./src", "allowJs": true, - "resolveJsonModule": false + "resolveJsonModule": false, + "lib": ["ES2021.String"] }, "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"], "exclude": ["node_modules", "./src/__tests__"] diff --git a/packages/sdk-apple/types.d.ts b/packages/sdk-apple/types.d.ts index 01310624e5..7ed0785121 100644 --- a/packages/sdk-apple/types.d.ts +++ b/packages/sdk-apple/types.d.ts @@ -1,3 +1,2 @@ -declare module 'rnv'; declare module 'inquirer'; declare module 'shelljs'; From 426977e828bad24aac818f0997eabc3712a587bd Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Sun, 3 Sep 2023 21:49:23 +0200 Subject: [PATCH 47/83] migrate apple sdk to TS --- packages/rnv/src/core/common.ts | 2 +- packages/rnv/src/core/configManager/types.ts | 12 +++++ packages/rnv/src/core/context/types.ts | 15 ++++++ packages/rnv/src/core/runtimeManager/index.ts | 2 +- packages/sdk-apple/src/index.ts | 36 ++++++++------- packages/sdk-apple/src/provisionParser.ts | 3 +- packages/sdk-apple/src/swiftParser.ts | 16 +++++-- packages/sdk-apple/src/xcodeParser.ts | 46 +++++++++++++------ packages/sdk-apple/src/xcschemeParser.ts | 7 +-- 9 files changed, 99 insertions(+), 40 deletions(-) diff --git a/packages/rnv/src/core/common.ts b/packages/rnv/src/core/common.ts index bfc7e06e62..6a083585bf 100755 --- a/packages/rnv/src/core/common.ts +++ b/packages/rnv/src/core/common.ts @@ -515,7 +515,7 @@ export const checkPortInUse = (c: RnvContext, platform: string, port: string) => }); }); -export const getFlavouredProp = (c: RnvContext, obj: Record, key: string) => { +export const getFlavouredProp = (c: RnvContext, obj: Record, key: string): T | null => { if (!key || !obj) return null; const val1 = obj[`${key}@${c.runtime.scheme}`]; if (val1) return val1; diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index c9882c629d..6b065dd21f 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -64,6 +64,18 @@ export type RenativeConfigPlatform = { tab: string; }; urlScheme?: string; + xcodeproj?: { + sourceFiles: Array; + resourceFiles: Array; + headerFiles: Array; + buildPhases: Array<{ + shellPath: string; + shellScript: string; + inputPaths: string; + }>; + frameworks: Array; + buildSettings: Record; + }; }; export type RenativeConfigPermissionsList = Array; diff --git a/packages/rnv/src/core/context/types.ts b/packages/rnv/src/core/context/types.ts index 929fcc2b3c..921b748f18 100644 --- a/packages/rnv/src/core/context/types.ts +++ b/packages/rnv/src/core/context/types.ts @@ -54,6 +54,7 @@ export interface RnvContext { activeTemplate: string; engine?: RnvEngine; target: string; + isTargetTrue: boolean; supportedPlatforms: Array; keepSessionActive: boolean; platformBuildsProjectPath: string; @@ -86,6 +87,20 @@ export interface RnvContext { isWSConfirmed: boolean; _skipNativeDepResolutions: boolean; targetUDID?: string; + xcodeProj?: { + id?: string; + runScheme?: string; + provisioningStyle?: string; + deploymentTarget?: string; + provisionProfileSpecifier?: any; + provisionProfileSpecifiers?: any; + excludedArchs?: Array; + codeSignIdentity?: string; + codeSignIdentities?: Record; + systemCapabilities?: Record; + teamID?: any; + appId?: any; + }; }; paths: { GLOBAL_RNV_CONFIG: string; diff --git a/packages/rnv/src/core/runtimeManager/index.ts b/packages/rnv/src/core/runtimeManager/index.ts index 68d435a8d8..2284f13e24 100644 --- a/packages/rnv/src/core/runtimeManager/index.ts +++ b/packages/rnv/src/core/runtimeManager/index.ts @@ -36,7 +36,7 @@ export const configureRuntimeDefaults = async (c: RnvContext) => { if (c.program.target !== true) { c.runtime.target = c.program.target || c.buildConfig?.defaultTargets?.[c.platform]; - } else c.runtime.target = c.program.target; + } else c.runtime.isTargetTrue = c.program.target; c.runtime.scheme = c.program.scheme || 'debug'; c.runtime.localhost = c.program.hostIp || defaultHost; c.runtime.timestamp = c.runtime.timestamp || Date.now(); diff --git a/packages/sdk-apple/src/index.ts b/packages/sdk-apple/src/index.ts index 9d5e5a7590..72e559d9ac 100644 --- a/packages/sdk-apple/src/index.ts +++ b/packages/sdk-apple/src/index.ts @@ -1,4 +1,4 @@ -import child_process from 'child_process'; +import child_process, { ExecFileOptions } from 'child_process'; import crypto from 'crypto'; import inquirer from 'inquirer'; import path from 'path'; @@ -24,6 +24,7 @@ import { parseXcodeProject } from './xcodeParser'; import { parseXcscheme } from './xcschemeParser'; import { ejectXcodeProject } from './ejector'; import { Context } from './types'; +import { ObjectEncodingOptions } from 'fs'; const { getAppleDevices, launchAppleSimulator } = SDKManager.Apple; @@ -38,14 +39,14 @@ const { copyAssetsFolder, copyBuildsFolder, parseFonts } = ProjectManager; const { IOS, MACOS, TVOS } = Constants; const { chalk, logInfo, logTask, logError, logWarning, logDebug, logSuccess, logRaw } = Logger; -export const generateChecksum = (str: string, algorithm?: string, encoding?: string) => +export const generateChecksum = (str: string, algorithm?: string, encoding?: 'base64' | 'base64url' | 'hex') => crypto .createHash(algorithm || 'md5') .update(str, 'utf8') .digest(encoding || 'hex'); const checkIfPodsIsRequired = async (c: Context) => { - const appFolder = getAppFolder(c, c.platform); + const appFolder = getAppFolder(c); const podChecksumPath = path.join(appFolder, 'Podfile.checksum'); if (!fsExistsSync(podChecksumPath)) return true; const podChecksum = fsReadFileSync(podChecksumPath).toString(); @@ -191,7 +192,7 @@ export const runXcodeProject = async (c: Context) => { return _checkLockAndExec(c, appPath, appFolderName, runScheme, p); }; - if (c.runtime.target !== true) { + if (c.runtime.target) { const selectedDevice = devicesArr.find((d) => d.name === c.runtime.target); if (selectedDevice) { return run(selectedDevice); @@ -221,7 +222,7 @@ export const runXcodeProject = async (c: Context) => { } } else if (device) { p = `--device ${device}`; - } else if (c.runtime.target === true) { + } else if (c.runtime.isTargetTrue) { const devices = devicesArr.map((v) => ({ name: `${v.name} | ${v.icon} | v: ${chalk().green(v.version)} | udid: ${chalk().grey(v.udid)}${ v.isDevice ? chalk().red(' (device)') : '' @@ -780,22 +781,25 @@ const runAppleLog = (c: Context) => new Promise(() => { logTask('runAppleLog'); const filter = c.program.filter || 'RNV'; + const opts: ObjectEncodingOptions & ExecFileOptions = {}; //{ stdio: 'inherit', customFds: [0, 1, 2] }; const child = child_process.execFile( 'xcrun', ['simctl', 'spawn', 'booted', 'log', 'stream', '--predicate', `eventMessage contains "${filter}"`], - { stdio: 'inherit', customFds: [0, 1, 2] } + opts ); // use event hooks to provide a callback to execute when data are available: - child.stdout.on('data', (data) => { - const d = data.toString(); - if (d.toLowerCase().includes('error')) { - logRaw(chalk().red(d)); - } else if (d.toLowerCase().includes('success')) { - logRaw(chalk().green(d)); - } else { - logRaw(d); - } - }); + if (child.stdout) { + child.stdout.on('data', (data) => { + const d = data.toString(); + if (d.toLowerCase().includes('error')) { + logRaw(chalk().red(d)); + } else if (d.toLowerCase().includes('success')) { + logRaw(chalk().green(d)); + } else { + logRaw(d); + } + }); + } }); const configureXcodeProject = async (c: Context) => { diff --git a/packages/sdk-apple/src/provisionParser.ts b/packages/sdk-apple/src/provisionParser.ts index 2df4776033..a2077dcdcf 100644 --- a/packages/sdk-apple/src/provisionParser.ts +++ b/packages/sdk-apple/src/provisionParser.ts @@ -1,11 +1,12 @@ import { provision, cert } from 'ios-mobileprovision-finder'; import path from 'path'; import { Logger, Common } from 'rnv'; +import { Context } from './types'; const { getConfigProp } = Common; const { chalk, logWarning } = Logger; -export const parseProvisioningProfiles = async (c) => { +export const parseProvisioningProfiles = async (c: Context) => { // PROJECT const teamID = getConfigProp(c, c.platform, 'teamID'); const id = getConfigProp(c, c.platform, 'id'); diff --git a/packages/sdk-apple/src/swiftParser.ts b/packages/sdk-apple/src/swiftParser.ts index bd7b0300f6..33702d74c6 100644 --- a/packages/sdk-apple/src/swiftParser.ts +++ b/packages/sdk-apple/src/swiftParser.ts @@ -1,5 +1,6 @@ import path from 'path'; -import { FileUtils, Logger, PluginManager, Common } from 'rnv'; +import { FileUtils, Logger, PluginManager, Common, RnvPluginPlatform } from 'rnv'; +import { Context } from './types'; const { getEntryFile, @@ -14,7 +15,14 @@ const { chalk, logTask, logDebug, logWarning } = Logger; const { parsePlugins } = PluginManager; const { writeCleanFile } = FileUtils; -export const parseAppDelegate = (c, platform, appFolder, appFolderName, isBundled = false, ip = 'localhost') => +export const parseAppDelegate = ( + c: Context, + platform: string, + appFolder: string, + appFolderName: string, + isBundled = false, + ip = 'localhost' +) => new Promise((resolve) => { const newPort = c.runtime?.port; logTask('parseAppDelegateSync', `ip:${ip} port:${newPort}`); @@ -33,8 +41,8 @@ export const parseAppDelegate = (c, platform, appFolder, appFolderName, isBundle } // PLUGINS - parsePlugins(c, platform, (plugin, pluginPlat, key) => { - injectPluginSwiftSync(c, pluginPlat, key, pluginPlat.package); + parsePlugins(c, platform as RnvPluginPlatform, (plugin, pluginPlat, key) => { + injectPluginSwiftSync(c, pluginPlat, key); }); // BG COLOR diff --git a/packages/sdk-apple/src/xcodeParser.ts b/packages/sdk-apple/src/xcodeParser.ts index 3aa68621fd..b75ff61904 100644 --- a/packages/sdk-apple/src/xcodeParser.ts +++ b/packages/sdk-apple/src/xcodeParser.ts @@ -1,7 +1,20 @@ +import { provision } from 'ios-mobileprovision-finder'; import path from 'path'; -import { Resolver, Logger, Constants, Common, PluginManager, Prompt, FileUtils } from 'rnv'; +import { + Resolver, + Logger, + Constants, + Common, + PluginManager, + Prompt, + FileUtils, + logError, + RenativeConfigPlatform, + RnvPluginPlatform, +} from 'rnv'; import { getAppFolderName } from './common'; import { parseProvisioningProfiles } from './provisionParser'; +import { Context } from './types'; const { getAppFolder, getAppId, getConfigProp, getFlavouredProp } = Common; const { fsExistsSync, writeFileSync, fsWriteFileSync } = FileUtils; @@ -11,7 +24,7 @@ const { inquirerPrompt } = Prompt; const { IOS } = Constants; const { parsePlugins } = PluginManager; -export const parseXcodeProject = async (c) => { +export const parseXcodeProject = async (c: Context) => { logTask('parseXcodeProject'); const { platform } = c; // PROJECT @@ -34,13 +47,13 @@ export const parseXcodeProject = async (c) => { if (c.runtime.xcodeProj.provisioningStyle !== 'Automatic' && !c.runtime.xcodeProj.provisionProfileSpecifier) { const result = await parseProvisioningProfiles(c); - let eligibleProfile; + let eligibleProfile: provision.MobileProvision | undefined; if (result?.eligable) { result.eligable.forEach((v) => { const bundleId = v.Entitlements['application-identifier']; - if (bundleId === `${c.runtime.xcodeProj.teamID}.${c.runtime.xcodeProj.id}`) { + if (bundleId === `${c.runtime.xcodeProj?.teamID}.${c.runtime.xcodeProj?.id}`) { eligibleProfile = v; } }); @@ -70,10 +83,15 @@ export const parseXcodeProject = async (c) => { await _parseXcodeProject(c, platform); }; -const _parseXcodeProject = (c, platform) => - new Promise((resolve) => { +const _parseXcodeProject = (c: Context, platform: string) => + new Promise((resolve) => { logTask('_parseXcodeProject'); - const xcode = require(doResolve('xcode')); + const xcodePath = doResolve('xcode'); + if (!xcodePath) { + logError(`Cannot resolve xcode path`); + return; + } + const xcode = require(xcodePath); // const xcode = require(`${c.paths.project.nodeModulesDir}/xcode`); const appFolder = getAppFolder(c); const appFolderName = getAppFolderName(c, platform); @@ -91,9 +109,9 @@ const _parseXcodeProject = (c, platform) => systemCapabilities, teamID, appId, - } = c.runtime.xcodeProj; + } = c.runtime.xcodeProj || {}; - if (c.runtime.xcodeProj.teamID) { + if (teamID) { xcodeProj.updateBuildProperty('DEVELOPMENT_TEAM', teamID); } else { xcodeProj.updateBuildProperty('DEVELOPMENT_TEAM', '""'); @@ -121,7 +139,7 @@ const _parseXcodeProject = (c, platform) => } if (excludedArchs) { - const tempExcludedArchs = []; + const tempExcludedArchs: string[] = []; if (typeof excludedArchs.forEach === 'function') { excludedArchs.forEach((arch) => { @@ -162,7 +180,7 @@ const _parseXcodeProject = (c, platform) => // } if (systemCapabilities) { - const sysCapObj = {}; + const sysCapObj: Record = {}; Object.keys(systemCapabilities).forEach((sk) => { const val = systemCapabilities[sk]; sysCapObj[sk] = { enabled: val === true ? 1 : 0 }; @@ -171,7 +189,7 @@ const _parseXcodeProject = (c, platform) => xcodeProj.addTargetAttribute('SystemCapabilities', sysCapObj); } - const xcodeprojObj1 = getConfigProp(c, c.platform, 'xcodeproj'); + const xcodeprojObj1 = getConfigProp(c, c.platform, 'xcodeproj'); if (xcodeprojObj1?.sourceFiles) { xcodeprojObj1.sourceFiles.forEach((v) => { @@ -189,8 +207,8 @@ const _parseXcodeProject = (c, platform) => } // PLUGINS - parsePlugins(c, platform, (plugin, pluginPlat) => { - const xcodeprojObj = getFlavouredProp(c, pluginPlat, 'xcodeproj'); + parsePlugins(c, platform as RnvPluginPlatform, (plugin, pluginPlat) => { + const xcodeprojObj = getFlavouredProp(c, pluginPlat, 'xcodeproj'); if (xcodeprojObj) { if (xcodeprojObj.resourceFiles) { xcodeprojObj.resourceFiles.forEach((v) => { diff --git a/packages/sdk-apple/src/xcschemeParser.ts b/packages/sdk-apple/src/xcschemeParser.ts index 8bd73ace73..962cec28a2 100644 --- a/packages/sdk-apple/src/xcschemeParser.ts +++ b/packages/sdk-apple/src/xcschemeParser.ts @@ -1,6 +1,7 @@ import path from 'path'; import { FileUtils, Logger, Common } from 'rnv'; import { getAppFolderName } from './common'; +import { Context } from './types'; const { getAppFolder, getAppTemplateFolder, addSystemInjects, getConfigProp } = Common; const { logTask } = Logger; @@ -8,7 +9,7 @@ const { writeCleanFile } = FileUtils; // const xml2js = require('xml2js'); // const parser = new xml2js.Parser(); -export const parseXcscheme = async (c, platform) => { +export const parseXcscheme = async (c: Context, platform: string) => { logTask('parseXcscheme'); // XCSCHEME // const allowProvisioningUpdates = getConfigProp( @@ -37,7 +38,7 @@ export const parseXcscheme = async (c, platform) => { const schemePath = `${appFolderName}.xcodeproj/xcshareddata/xcschemes/${appFolderName}.xcscheme`; let _commandLineArguments = ''; - const commandLineArguments = getConfigProp(c, c.platform, 'commandLineArguments'); + const commandLineArguments = getConfigProp(c, c.platform, 'commandLineArguments'); if (commandLineArguments?.length) { commandLineArguments.forEach((arg) => { _commandLineArguments += ` @@ -57,7 +58,7 @@ export const parseXcscheme = async (c, platform) => { addSystemInjects(c, injects); - writeCleanFile(path.join(appTemplateFolder, schemePath), path.join(appFolder, schemePath), injects, null, c); + writeCleanFile(path.join(appTemplateFolder, schemePath), path.join(appFolder, schemePath), injects, undefined, c); // const parseObj = await parser.parseStringPromise(path.join(appFolder, schemePath)); }; From a64a8c6e28f8a759109004d60ca5924d16d17fd9 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Sun, 3 Sep 2023 23:08:01 +0200 Subject: [PATCH 48/83] ts type refactor & fixes --- packages/rnv/src/core/common.ts | 6 +- packages/rnv/src/core/configManager/types.ts | 53 +++++++++++++-- packages/rnv/src/core/pluginManager/index.ts | 13 +++- packages/rnv/src/core/pluginManager/types.ts | 9 ++- packages/sdk-apple/src/podfileParser.ts | 41 ++++++++--- packages/sdk-apple/src/swiftParser.ts | 67 ++++++++++++------ packages/sdk-apple/src/types.ts | 71 ++++++++++++++++---- 7 files changed, 203 insertions(+), 57 deletions(-) diff --git a/packages/rnv/src/core/common.ts b/packages/rnv/src/core/common.ts index 6a083585bf..d487b5cb62 100755 --- a/packages/rnv/src/core/common.ts +++ b/packages/rnv/src/core/common.ts @@ -515,7 +515,11 @@ export const checkPortInUse = (c: RnvContext, platform: string, port: string) => }); }); -export const getFlavouredProp = (c: RnvContext, obj: Record, key: string): T | null => { +export const getFlavouredProp = ( + c: RnvContext, + obj: Record | undefined, + key: string +): T | null => { if (!key || !obj) return null; const val1 = obj[`${key}@${c.runtime.scheme}`]; if (val1) return val1; diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index 6b065dd21f..792b56ad15 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -86,13 +86,14 @@ export type RenativeConfigPlugin = { 'no-active'?: boolean; version?: string; pluginDependencies?: Record; - ios?: any; - android?: any; - tvos?: any; - androidtv?: any; - web?: any; + ios?: RenativeConfigPluginPlatform; + android?: RenativeConfigPluginPlatform; + tvos?: RenativeConfigPluginPlatform; + androidtv?: RenativeConfigPluginPlatform; + web?: RenativeConfigPluginPlatform; webpack?: RenativeWebpackConfig; //DEPRECATED webpackConfig?: RenativeWebpackConfig; + 'engine-rn-next'?: RenativeWebpackConfig; //DEPRECATED? npm?: Record; enabled?: boolean; deprecated?: boolean; @@ -103,8 +104,10 @@ export type RenativeConfigPlugin = { export type RenativeConfigPluginPlatform = { package?: string; path?: string; - //IOS - + git?: string; + commit?: string; + enabled?: boolean; + version?: string; //ANDROID projectName?: string; skipLinking?: boolean; @@ -136,8 +139,44 @@ export type RenativeConfigPluginPlatform = { child_value: string; }>; }; + //iOS + appDelegateMethods: RenativeConfigAppDelegateMethods; + Podfile: { + injectLines: Array; + post_install: Array; + sources: Array; + }; + staticPods: Array; }; +export type RenativeConfigAppDelegateMethods = { + application: { + didFinishLaunchingWithOptions: Array; + applicationDidBecomeActive: Array; + open: Array; + supportedInterfaceOrientationsFor: Array; + didReceiveRemoteNotification: Array; + didFailToRegisterForRemoteNotificationsWithError: Array; + didReceive: Array; + didRegister: Array; + didRegisterForRemoteNotificationsWithDeviceToken: Array; + continue: Array; + didConnectCarInterfaceController: Array; + didDisconnectCarInterfaceController: Array; + }; + userNotificationCenter: { + willPresent: Array; + }; +}; + +export type RenativeConfigAppDelegateMethod = + | { + order: number; + value: string; + weight: number; + } + | string; + export type RenativeWebpackConfig = { modulePaths?: | Array< diff --git a/packages/rnv/src/core/pluginManager/index.ts b/packages/rnv/src/core/pluginManager/index.ts index 82fbfdc388..555434c087 100644 --- a/packages/rnv/src/core/pluginManager/index.ts +++ b/packages/rnv/src/core/pluginManager/index.ts @@ -21,7 +21,14 @@ import { installPackageDependencies } from '../systemManager/npmUtils'; import { doResolve, doResolvePath } from '../systemManager/resolve'; import { RnvContext } from '../context/types'; import { ResolveOptions } from '../systemManager/types'; -import { PluginCallback, PluginListResponse, RnvPlugin, RnvPluginPlatform, RnvPluginScope } from './types'; +import { + PluginCallback, + PluginListResponse, + RnvPlugin, + RnvPluginPlatform, + RnvPluginScope, + RnvPluginWebpackKey, +} from './types'; import { RenativeConfigPlugin, RenativeWebpackConfig } from '../configManager/types'; export const getPluginList = (c: RnvContext, isUpdate = false) => { @@ -942,7 +949,7 @@ export const sanitizePluginPath = (str: string, name: string, mandatory?: boolea return newStr; }; -export const includesPluginPath = (str: string) => { +export const includesPluginPath = (str?: string) => { if (str?.includes) { return str.includes('{{PLUGIN_ROOT}}'); } @@ -961,7 +968,7 @@ export const getLocalRenativePlugin = () => ({ }, }); -export const getModuleConfigs = (c: RnvContext, primaryKey?: RnvPluginPlatform) => { +export const getModuleConfigs = (c: RnvContext, primaryKey?: RnvPluginWebpackKey) => { let modulePaths: Array = []; const moduleAliases: Record = {}; diff --git a/packages/rnv/src/core/pluginManager/types.ts b/packages/rnv/src/core/pluginManager/types.ts index 8146b3906d..c31a5dc84e 100644 --- a/packages/rnv/src/core/pluginManager/types.ts +++ b/packages/rnv/src/core/pluginManager/types.ts @@ -1,6 +1,6 @@ -import { RenativeConfigPlugin } from '../configManager/types'; +import { RenativeConfigPlugin, RenativeConfigPluginPlatform } from '../configManager/types'; -export type PluginCallback = (plugin: RnvPlugin, pluginPlat: any, key: string) => void; +export type PluginCallback = (plugin: RnvPlugin, pluginPlat: RenativeConfigPluginPlatform, key: string) => void; export type PluginListResponse = { asString: string; @@ -23,6 +23,7 @@ export type RnvPluginScope = { }; export type RnvPlugin = RenativeConfigPlugin & { + packageName?: string; scope?: string; _scopes?: Array; _id?: string; @@ -31,4 +32,6 @@ export type RnvPlugin = RenativeConfigPlugin & { }; }; -export type RnvPluginPlatform = 'ios' | 'android' | 'webpack'; +export type RnvPluginPlatform = 'ios' | 'android' | 'web'; + +export type RnvPluginWebpackKey = 'webpack' | 'webpackConfig' | 'engine-rn-next'; diff --git a/packages/sdk-apple/src/podfileParser.ts b/packages/sdk-apple/src/podfileParser.ts index d4b4b04998..9e6dc8aec6 100644 --- a/packages/sdk-apple/src/podfileParser.ts +++ b/packages/sdk-apple/src/podfileParser.ts @@ -1,7 +1,19 @@ import path from 'path'; -import { Exec, Logger, PluginManager, FileUtils, Resolver, Common } from 'rnv'; +import { + Exec, + Logger, + PluginManager, + FileUtils, + Resolver, + Common, + RnvPluginPlatform, + RnvPlugin, + RenativeConfigPluginPlatform, + OverridesOptions, +} from 'rnv'; import compareVersions from 'compare-versions'; +import { Context } from './types'; const { getAppFolder, getAppTemplateFolder, getConfigProp, getFlavouredProp, addSystemInjects } = Common; const { logTask, logWarning } = Logger; @@ -10,7 +22,7 @@ const { doResolve, doResolvePath } = Resolver; const { executeAsync } = Exec; const { writeCleanFile } = FileUtils; -export const parsePodFile = async (c, platform) => { +export const parsePodFile = async (c: Context, platform: string) => { logTask('parsePodFile'); const appFolder = getAppFolder(c); @@ -18,7 +30,7 @@ export const parsePodFile = async (c, platform) => { // PLUGINS c.payload.pluginConfigiOS.podfileInject = ''; - parsePlugins(c, platform, (plugin, pluginPlat, key) => { + parsePlugins(c, platform as RnvPluginPlatform, (plugin, pluginPlat, key) => { const podName = getFlavouredProp(c, pluginPlat, 'podName'); if (podName) { pluginInject += _injectPod(podName, pluginPlat, plugin, key); @@ -41,7 +53,7 @@ export const parsePodFile = async (c, platform) => { c.payload.pluginConfigiOS.staticFrameworks.push(`'${podName}'`); } } - const staticPods = getFlavouredProp(c, pluginPlat, 'staticPods'); + const staticPods = getFlavouredProp(c, pluginPlat, 'staticPods'); if (staticPods?.forEach) { staticPods.forEach((sPod) => { if (sPod.startsWith('::startsWith::')) { @@ -58,7 +70,7 @@ export const parsePodFile = async (c, platform) => { logWarning('reactSubSpecs prop is deprecated. You can safely remove it'); } - const podfile = getFlavouredProp(c, pluginPlat, 'Podfile'); + const podfile = getFlavouredProp(c, pluginPlat, 'Podfile'); if (podfile) { const { injectLines, post_install } = podfile; // INJECT LINES @@ -132,7 +144,7 @@ export const parsePodFile = async (c, platform) => { } } - const injects = [ + const injects: OverridesOptions = [ { pattern: '{{PLUGIN_PATHS}}', override: pluginInject }, { pattern: '{{PLUGIN_WARNINGS}}', override: podWarnings }, { @@ -157,11 +169,13 @@ export const parsePodFile = async (c, platform) => { }, { pattern: '{{PATH_JSC_ANDROID}}', - override: doResolve('jsc-android'), + override: doResolve('jsc-android') || 'UNRESOLVED(jsc-android)', }, { pattern: '{{PATH_REACT_NATIVE}}', - override: doResolve(c.runtime.runtimeExtraProps?.reactNativePackageName || 'react-native'), + override: + doResolve(c.runtime.runtimeExtraProps?.reactNativePackageName || 'react-native') || + 'UNRESOLVED(react-native)', }, { pattern: '{{PLUGIN_STATIC_POD_DEFINITION}}', @@ -179,7 +193,7 @@ export const parsePodFile = async (c, platform) => { path.join(getAppTemplateFolder(c, platform), 'Podfile'), path.join(appFolder, 'Podfile'), injects, - null, + undefined, c ); return true; @@ -190,7 +204,14 @@ const REACT_CORE_OVERRIDES = { 's.dependency "React"': 's.dependency "React-Core"', }; -const _injectPod = (_podName, pluginPlat, plugin, _key) => { +const _injectPod = ( + _podName: string, + pluginPlat: RenativeConfigPluginPlatform | undefined, + plugin: RnvPlugin, + _key: string +) => { + if (!pluginPlat) return ''; + const key = plugin.packageName || _key; const podName = _podName; let pluginInject = ''; diff --git a/packages/sdk-apple/src/swiftParser.ts b/packages/sdk-apple/src/swiftParser.ts index 33702d74c6..f89231e958 100644 --- a/packages/sdk-apple/src/swiftParser.ts +++ b/packages/sdk-apple/src/swiftParser.ts @@ -1,6 +1,24 @@ import path from 'path'; -import { FileUtils, Logger, PluginManager, Common, RnvPluginPlatform } from 'rnv'; -import { Context } from './types'; +import { + FileUtils, + Logger, + PluginManager, + Common, + RnvPluginPlatform, + RenativeConfigAppDelegateMethod, + RenativeConfigAppDelegateMethods, + RenativeConfigPluginPlatform, +} from 'rnv'; +import { + Context, + PayloadAppDelegateKey, + PayloadAppDelegateMethod, + PayloadAppDelegateSubKey, + SwiftAppDelegate, + SwiftAppDelegateKey, + SwiftAppDelegateSubKey, + SwiftMethod, +} from './types'; const { getEntryFile, @@ -23,7 +41,7 @@ export const parseAppDelegate = ( isBundled = false, ip = 'localhost' ) => - new Promise((resolve) => { + new Promise((resolve) => { const newPort = c.runtime?.port; logTask('parseAppDelegateSync', `ip:${ip} port:${newPort}`); const appDelegate = 'AppDelegate.swift'; @@ -58,7 +76,7 @@ export const parseAppDelegate = ( const clr = sanitizeColor(getConfigProp(c, platform, 'backgroundColor'), 'backgroundColor').rgbDecimal; const pluginBgColor = `vc.view.backgroundColor = UIColor(red: ${clr[0]}, green: ${clr[1]}, blue: ${clr[2]}, alpha: ${clr[3]})`; - const methods = { + const methods: SwiftAppDelegate = { application: { didFinishLaunchingWithOptions: { isRequired: true, @@ -158,7 +176,7 @@ export const parseAppDelegate = ( }, }; - const constructMethod = (lines, method) => { + const constructMethod = (lines: Array, method: SwiftMethod) => { let output = ''; if (lines.length || method.isRequired) { output += `\n${method.func}\n`; @@ -173,14 +191,19 @@ export const parseAppDelegate = ( }; // REORDER Injects - const injectors = []; + const injectors: Array<{ + f: SwiftMethod; + lines: Array; + }> = []; let cleanedLinesArr; - Object.keys(methods).forEach((key) => { + const mk = Object.keys(methods) as Array; + mk.forEach((key) => { const method = methods[key]; - Object.keys(method).forEach((key2) => { + const mk2 = Object.keys(method) as Array; + mk2.forEach((key2) => { const f = method[key2]; - const lines = c.payload.pluginConfigiOS.appDelegateMethods[key][key2]; - const cleanedLines = {}; + const lines: Array = c.payload.pluginConfigiOS.appDelegateMethods[key][key2]; + const cleanedLines: Record = {}; lines.forEach((l) => { if (!cleanedLines[l.value]) { @@ -232,13 +255,13 @@ export const parseAppDelegate = ( path.join(getAppTemplateFolder(c, platform), appFolderName, appDelegate), path.join(appFolder, appFolderName, appDelegate), injects, - null, + undefined, c ); resolve(); }); -export const injectPluginSwiftSync = (c, plugin, key) => { +export const injectPluginSwiftSync = (c: Context, plugin: RenativeConfigPluginPlatform, key: string) => { logDebug(`injectPluginSwiftSync:${c.platform}:${key}`); const appDelegateImports = getFlavouredProp(c, plugin, 'appDelegateImports'); if (appDelegateImports instanceof Array) { @@ -267,21 +290,25 @@ export const injectPluginSwiftSync = (c, plugin, key) => { }); } - const appDelegateMethods = getFlavouredProp(c, plugin, 'appDelegateMethods'); + const appDelegateMethods = getFlavouredProp(c, plugin, 'appDelegateMethods'); if (appDelegateMethods) { - Object.keys(appDelegateMethods).forEach((delKey) => { - Object.keys(appDelegateMethods[delKey]).forEach((key2) => { - const plugArr = c.payload.pluginConfigiOS.appDelegateMethods[delKey][key2]; + const admk = Object.keys(appDelegateMethods) as Array; + admk.forEach((delKey) => { + const amdk2 = Object.keys(appDelegateMethods[delKey]) as Array; + amdk2.forEach((key2) => { + const plugArr: Array = + c.payload.pluginConfigiOS.appDelegateMethods[delKey][key2]; if (!plugArr) { logWarning(`appDelegateMethods.${delKey}.${chalk().red(key2)} not supported. SKIPPING.`); } else { - const plugVal = appDelegateMethods[delKey][key2]; + const plugVal: Array = appDelegateMethods[delKey][key2]; if (plugVal) { plugVal.forEach((v) => { + const isString = typeof v === 'string'; plugArr.push({ - order: v?.order || 0, - value: v?.value || v, - weight: v?.weight || 0, + order: isString ? 0 : v?.order || 0, + value: isString ? v : v?.value, + weight: isString ? 0 : v?.weight || 0, }); }); } diff --git a/packages/sdk-apple/src/types.ts b/packages/sdk-apple/src/types.ts index 6f66e38c7b..76c8bbf3ab 100644 --- a/packages/sdk-apple/src/types.ts +++ b/packages/sdk-apple/src/types.ts @@ -19,25 +19,70 @@ export type Payload = { pluginAppDelegateExtensions: string; appDelegateMethods: { application: { - didFinishLaunchingWithOptions: Array; - applicationDidBecomeActive: Array; - open: Array; - supportedInterfaceOrientationsFor: Array; - didReceiveRemoteNotification: Array; - didFailToRegisterForRemoteNotificationsWithError: Array; - didReceive: Array; - didRegister: Array; - didRegisterForRemoteNotificationsWithDeviceToken: Array; - continue: Array; - didConnectCarInterfaceController: Array; - didDisconnectCarInterfaceController: Array; + didFinishLaunchingWithOptions: Array; + applicationDidBecomeActive: Array; + open: Array; + supportedInterfaceOrientationsFor: Array; + didReceiveRemoteNotification: Array; + didFailToRegisterForRemoteNotificationsWithError: Array; + didReceive: Array; + didRegister: Array; + didRegisterForRemoteNotificationsWithDeviceToken: Array; + continue: Array; + didConnectCarInterfaceController: Array; + didDisconnectCarInterfaceController: Array; }; userNotificationCenter: { - willPresent: Array; + willPresent: Array; }; }; podfileSources: string; + deploymentTarget: string; }; }; +export type PayloadAppDelegateMethod = { + order: number; + value: string; + weight: number; +}; + +export type PayloadAppDelegateKey = keyof Payload['pluginConfigiOS']['appDelegateMethods']; + +export type PayloadAppDelegateSubKey = keyof Payload['pluginConfigiOS']['appDelegateMethods']['application'] & + keyof Payload['pluginConfigiOS']['appDelegateMethods']['userNotificationCenter']; + export type Context = RnvContext; + +export type SwiftMethod = { + isRequired?: boolean; + func: string; + begin: string | null; + render: (v: string) => string; + end: string | null; +}; + +export type SwiftAppDelegate = { + application: { + didFinishLaunchingWithOptions: SwiftMethod; + applicationDidBecomeActive: SwiftMethod; + open: SwiftMethod; + continue: SwiftMethod; + supportedInterfaceOrientationsFor: SwiftMethod; + didConnectCarInterfaceController: SwiftMethod; + didDisconnectCarInterfaceController: SwiftMethod; + didReceiveRemoteNotification: SwiftMethod; + didFailToRegisterForRemoteNotificationsWithError: SwiftMethod; + didReceive: SwiftMethod; + didRegister: SwiftMethod; + didRegisterForRemoteNotificationsWithDeviceToken: SwiftMethod; + }; + userNotificationCenter: { + willPresent: SwiftMethod; + }; +}; + +export type SwiftAppDelegateSubKey = keyof SwiftAppDelegate['application'] & + keyof SwiftAppDelegate['userNotificationCenter']; + +export type SwiftAppDelegateKey = keyof SwiftAppDelegate; From 37b71548799efbec5f0ffa3ee32105e59b0e8965 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Sun, 3 Sep 2023 23:16:47 +0200 Subject: [PATCH 49/83] apple sdk TS migration done --- packages/rnv/src/core/configManager/types.ts | 10 ++++++---- packages/rnv/src/core/pluginManager/index.ts | 2 +- packages/sdk-android/src/types.ts | 2 +- packages/sdk-apple/src/index.ts | 1 + packages/sdk-apple/src/podfileParser.ts | 12 ++++++++---- packages/sdk-apple/src/provisionParser.ts | 1 + 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index 792b56ad15..345991b549 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -132,7 +132,7 @@ export type RenativeConfigPluginPlatform = { dexOptions: Record; }; BuildGradle?: RenativeConfigPluginPlatform['build.gradle']; - ResourceStrings: { + ResourceStrings?: { children: Array<{ tag: string; name: string; @@ -140,13 +140,15 @@ export type RenativeConfigPluginPlatform = { }>; }; //iOS - appDelegateMethods: RenativeConfigAppDelegateMethods; - Podfile: { + appDelegateMethods?: RenativeConfigAppDelegateMethods; + Podfile?: { injectLines: Array; post_install: Array; sources: Array; }; - staticPods: Array; + staticPods?: Array; + podNames?: Array; + podDependencies?: Array; }; export type RenativeConfigAppDelegateMethods = { diff --git a/packages/rnv/src/core/pluginManager/index.ts b/packages/rnv/src/core/pluginManager/index.ts index 555434c087..b1938a8327 100644 --- a/packages/rnv/src/core/pluginManager/index.ts +++ b/packages/rnv/src/core/pluginManager/index.ts @@ -447,7 +447,7 @@ export const parsePlugins = ( const plugin = getMergedPlugin(c, key); if (plugin) { - const pluginPlat = plugin[platform]; + const pluginPlat = plugin[platform] || {}; if (ignorePlatformObjectCheck) { // totalIncludedPlugins++; pluginCallback(plugin, pluginPlat, key); diff --git a/packages/sdk-android/src/types.ts b/packages/sdk-android/src/types.ts index 605e540bbb..ef5fdce0cf 100644 --- a/packages/sdk-android/src/types.ts +++ b/packages/sdk-android/src/types.ts @@ -43,7 +43,7 @@ export type Payload = { pluginActivityResultMethods: string; pluginApplicationCreateMethods: string; pluginSplashActivityImports: string; - resourceStrings: RenativeConfigPluginPlatform['ResourceStrings']['children']; + resourceStrings: Required['ResourceStrings']['children']; store?: { storeFile: string; keyAlias: string; diff --git a/packages/sdk-apple/src/index.ts b/packages/sdk-apple/src/index.ts index 72e559d9ac..82cc8497ab 100644 --- a/packages/sdk-apple/src/index.ts +++ b/packages/sdk-apple/src/index.ts @@ -847,6 +847,7 @@ const configureXcodeProject = async (c: Context) => { }, }, podfileSources: '', + deploymentTarget: '', }; // FONTS diff --git a/packages/sdk-apple/src/podfileParser.ts b/packages/sdk-apple/src/podfileParser.ts index 9e6dc8aec6..7efdd66d7e 100644 --- a/packages/sdk-apple/src/podfileParser.ts +++ b/packages/sdk-apple/src/podfileParser.ts @@ -35,13 +35,17 @@ export const parsePodFile = async (c: Context, platform: string) => { if (podName) { pluginInject += _injectPod(podName, pluginPlat, plugin, key); } - const podNames = getFlavouredProp(c, pluginPlat, 'podNames'); + const podNames = getFlavouredProp(c, pluginPlat, 'podNames'); if (podNames) { podNames.forEach((v) => { pluginInject += _injectPod(v, pluginPlat, plugin, key); }); } - const podDependencies = getFlavouredProp(c, pluginPlat, 'podDependencies'); + const podDependencies = getFlavouredProp( + c, + pluginPlat, + 'podDependencies' + ); if (podDependencies) { podDependencies.forEach((v) => { pluginInject += ` pod ${v}\n`; @@ -100,7 +104,7 @@ export const parsePodFile = async (c: Context, platform: string) => { const ignoreWarnings = getConfigProp(c, platform, 'ignoreWarnings'); const podWarnings = ignoreWarnings ? 'inhibit_all_warnings!' : ''; - const podfile = getConfigProp(c, c.platform, 'Podfile'); + const podfile = getConfigProp(c, c.platform, 'Podfile'); if (podfile) { const { injectLines, post_install } = podfile; // INJECT LINES @@ -219,7 +223,7 @@ const _injectPod = ( const isNpm = plugin['no-npm'] !== true; if (isNpm) { if (includesPluginPath(pluginPlat.path)) { - podPath = sanitizePluginPath(pluginPlat.path, key); + podPath = sanitizePluginPath(pluginPlat.path || '', key); } else { podPath = doResolvePath(pluginPlat.path ?? key); } diff --git a/packages/sdk-apple/src/provisionParser.ts b/packages/sdk-apple/src/provisionParser.ts index a2077dcdcf..a21cb1d93d 100644 --- a/packages/sdk-apple/src/provisionParser.ts +++ b/packages/sdk-apple/src/provisionParser.ts @@ -15,6 +15,7 @@ export const parseProvisioningProfiles = async (c: Context) => { const provisionProfiles = provision.read(); const result = provision.select(provisionProfiles, { AppId: id, + //@ts-ignore //TODO: Check TeamIdentifier in ios-mobileprovision-finder TeamIdentifier: teamID, Certificates: certificates.valid, }); From e3d1db4613124772b3ccf486bf9917b5cfa0b11f Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Sun, 3 Sep 2023 23:31:47 +0200 Subject: [PATCH 50/83] engine-rn rename to ts files --- packages/engine-rn/src/{adapter.js => adapter.ts} | 0 packages/engine-rn/src/{commonEngine.js => commonEngine.ts} | 0 packages/engine-rn/src/{index.js => index.ts} | 0 .../src/tasks/{task.rnv.build.js => task.rnv.build.ts} | 0 .../tasks/{task.rnv.configure.js => task.rnv.configure.ts} | 0 ...rypto.installCerts.js => task.rnv.crypto.installCerts.ts} | 0 ...installProfiles.js => task.rnv.crypto.installProfiles.ts} | 0 ...pto.updateProfile.js => task.rnv.crypto.updateProfile.ts} | 0 ...o.updateProfiles.js => task.rnv.crypto.updateProfiles.ts} | 0 .../src/tasks/{task.rnv.debug.js => task.rnv.debug.ts} | 0 .../src/tasks/{task.rnv.deploy.js => task.rnv.deploy.ts} | 0 .../src/tasks/{task.rnv.eject.js => task.rnv.eject.ts} | 0 .../src/tasks/{task.rnv.export.js => task.rnv.export.ts} | 0 .../engine-rn/src/tasks/{task.rnv.log.js => task.rnv.log.ts} | 0 .../src/tasks/{task.rnv.package.js => task.rnv.package.ts} | 0 .../engine-rn/src/tasks/{task.rnv.run.js => task.rnv.run.ts} | 0 .../src/tasks/{task.rnv.start.js => task.rnv.start.ts} | 0 packages/sdk-android/src/gradleParser.ts | 5 ++--- packages/sdk-android/src/index.ts | 2 +- 19 files changed, 3 insertions(+), 4 deletions(-) rename packages/engine-rn/src/{adapter.js => adapter.ts} (100%) rename packages/engine-rn/src/{commonEngine.js => commonEngine.ts} (100%) rename packages/engine-rn/src/{index.js => index.ts} (100%) rename packages/engine-rn/src/tasks/{task.rnv.build.js => task.rnv.build.ts} (100%) rename packages/engine-rn/src/tasks/{task.rnv.configure.js => task.rnv.configure.ts} (100%) rename packages/engine-rn/src/tasks/{task.rnv.crypto.installCerts.js => task.rnv.crypto.installCerts.ts} (100%) rename packages/engine-rn/src/tasks/{task.rnv.crypto.installProfiles.js => task.rnv.crypto.installProfiles.ts} (100%) rename packages/engine-rn/src/tasks/{task.rnv.crypto.updateProfile.js => task.rnv.crypto.updateProfile.ts} (100%) rename packages/engine-rn/src/tasks/{task.rnv.crypto.updateProfiles.js => task.rnv.crypto.updateProfiles.ts} (100%) rename packages/engine-rn/src/tasks/{task.rnv.debug.js => task.rnv.debug.ts} (100%) rename packages/engine-rn/src/tasks/{task.rnv.deploy.js => task.rnv.deploy.ts} (100%) rename packages/engine-rn/src/tasks/{task.rnv.eject.js => task.rnv.eject.ts} (100%) rename packages/engine-rn/src/tasks/{task.rnv.export.js => task.rnv.export.ts} (100%) rename packages/engine-rn/src/tasks/{task.rnv.log.js => task.rnv.log.ts} (100%) rename packages/engine-rn/src/tasks/{task.rnv.package.js => task.rnv.package.ts} (100%) rename packages/engine-rn/src/tasks/{task.rnv.run.js => task.rnv.run.ts} (100%) rename packages/engine-rn/src/tasks/{task.rnv.start.js => task.rnv.start.ts} (100%) diff --git a/packages/engine-rn/src/adapter.js b/packages/engine-rn/src/adapter.ts similarity index 100% rename from packages/engine-rn/src/adapter.js rename to packages/engine-rn/src/adapter.ts diff --git a/packages/engine-rn/src/commonEngine.js b/packages/engine-rn/src/commonEngine.ts similarity index 100% rename from packages/engine-rn/src/commonEngine.js rename to packages/engine-rn/src/commonEngine.ts diff --git a/packages/engine-rn/src/index.js b/packages/engine-rn/src/index.ts similarity index 100% rename from packages/engine-rn/src/index.js rename to packages/engine-rn/src/index.ts diff --git a/packages/engine-rn/src/tasks/task.rnv.build.js b/packages/engine-rn/src/tasks/task.rnv.build.ts similarity index 100% rename from packages/engine-rn/src/tasks/task.rnv.build.js rename to packages/engine-rn/src/tasks/task.rnv.build.ts diff --git a/packages/engine-rn/src/tasks/task.rnv.configure.js b/packages/engine-rn/src/tasks/task.rnv.configure.ts similarity index 100% rename from packages/engine-rn/src/tasks/task.rnv.configure.js rename to packages/engine-rn/src/tasks/task.rnv.configure.ts diff --git a/packages/engine-rn/src/tasks/task.rnv.crypto.installCerts.js b/packages/engine-rn/src/tasks/task.rnv.crypto.installCerts.ts similarity index 100% rename from packages/engine-rn/src/tasks/task.rnv.crypto.installCerts.js rename to packages/engine-rn/src/tasks/task.rnv.crypto.installCerts.ts diff --git a/packages/engine-rn/src/tasks/task.rnv.crypto.installProfiles.js b/packages/engine-rn/src/tasks/task.rnv.crypto.installProfiles.ts similarity index 100% rename from packages/engine-rn/src/tasks/task.rnv.crypto.installProfiles.js rename to packages/engine-rn/src/tasks/task.rnv.crypto.installProfiles.ts diff --git a/packages/engine-rn/src/tasks/task.rnv.crypto.updateProfile.js b/packages/engine-rn/src/tasks/task.rnv.crypto.updateProfile.ts similarity index 100% rename from packages/engine-rn/src/tasks/task.rnv.crypto.updateProfile.js rename to packages/engine-rn/src/tasks/task.rnv.crypto.updateProfile.ts diff --git a/packages/engine-rn/src/tasks/task.rnv.crypto.updateProfiles.js b/packages/engine-rn/src/tasks/task.rnv.crypto.updateProfiles.ts similarity index 100% rename from packages/engine-rn/src/tasks/task.rnv.crypto.updateProfiles.js rename to packages/engine-rn/src/tasks/task.rnv.crypto.updateProfiles.ts diff --git a/packages/engine-rn/src/tasks/task.rnv.debug.js b/packages/engine-rn/src/tasks/task.rnv.debug.ts similarity index 100% rename from packages/engine-rn/src/tasks/task.rnv.debug.js rename to packages/engine-rn/src/tasks/task.rnv.debug.ts diff --git a/packages/engine-rn/src/tasks/task.rnv.deploy.js b/packages/engine-rn/src/tasks/task.rnv.deploy.ts similarity index 100% rename from packages/engine-rn/src/tasks/task.rnv.deploy.js rename to packages/engine-rn/src/tasks/task.rnv.deploy.ts diff --git a/packages/engine-rn/src/tasks/task.rnv.eject.js b/packages/engine-rn/src/tasks/task.rnv.eject.ts similarity index 100% rename from packages/engine-rn/src/tasks/task.rnv.eject.js rename to packages/engine-rn/src/tasks/task.rnv.eject.ts diff --git a/packages/engine-rn/src/tasks/task.rnv.export.js b/packages/engine-rn/src/tasks/task.rnv.export.ts similarity index 100% rename from packages/engine-rn/src/tasks/task.rnv.export.js rename to packages/engine-rn/src/tasks/task.rnv.export.ts diff --git a/packages/engine-rn/src/tasks/task.rnv.log.js b/packages/engine-rn/src/tasks/task.rnv.log.ts similarity index 100% rename from packages/engine-rn/src/tasks/task.rnv.log.js rename to packages/engine-rn/src/tasks/task.rnv.log.ts diff --git a/packages/engine-rn/src/tasks/task.rnv.package.js b/packages/engine-rn/src/tasks/task.rnv.package.ts similarity index 100% rename from packages/engine-rn/src/tasks/task.rnv.package.js rename to packages/engine-rn/src/tasks/task.rnv.package.ts diff --git a/packages/engine-rn/src/tasks/task.rnv.run.js b/packages/engine-rn/src/tasks/task.rnv.run.ts similarity index 100% rename from packages/engine-rn/src/tasks/task.rnv.run.js rename to packages/engine-rn/src/tasks/task.rnv.run.ts diff --git a/packages/engine-rn/src/tasks/task.rnv.start.js b/packages/engine-rn/src/tasks/task.rnv.start.ts similarity index 100% rename from packages/engine-rn/src/tasks/task.rnv.start.js rename to packages/engine-rn/src/tasks/task.rnv.start.ts diff --git a/packages/sdk-android/src/gradleParser.ts b/packages/sdk-android/src/gradleParser.ts index 026b33a353..3fb0c47b17 100644 --- a/packages/sdk-android/src/gradleParser.ts +++ b/packages/sdk-android/src/gradleParser.ts @@ -572,10 +572,9 @@ export const parseGradlePropertiesSync = (c: RnvContext) => { export const injectPluginGradleSync = ( c: RnvContext, + pluginRoot: RnvPlugin, plugin: RenativeConfigPluginPlatform, - key: string, - _pkg: string, - pluginRoot: RnvPlugin + key: string ) => { // const keyFixed = key.replace(/\//g, '-').replace(/@/g, ''); // const packagePath = plugin.path ?? `${key}/android`; diff --git a/packages/sdk-android/src/index.ts b/packages/sdk-android/src/index.ts index b3be04d97f..f06e1c3171 100644 --- a/packages/sdk-android/src/index.ts +++ b/packages/sdk-android/src/index.ts @@ -550,7 +550,7 @@ export const configureProject = async (c: RnvContext) => { // PLUGINS parsePlugins(c, platform as RnvPluginPlatform, (plugin, pluginPlat, key) => { - injectPluginGradleSync(c, pluginPlat, key, pluginPlat.package, plugin); + injectPluginGradleSync(c, plugin, pluginPlat, key); injectPluginKotlinSync(c, pluginPlat, key, pluginPlat.package); injectPluginManifestSync(); injectPluginXmlValuesSync(c, pluginPlat); From 36c18a2c575e38d17aaed39f98770274663ea581 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Sun, 3 Sep 2023 23:51:13 +0200 Subject: [PATCH 51/83] TS fixes --- .../unitTests/{tasks.test.js => tasks.test.ts} | 0 packages/engine-rn/src/tasks/task.rnv.build.ts | 6 +++--- packages/engine-rn/src/tasks/task.rnv.configure.ts | 4 ++-- .../src/tasks/task.rnv.crypto.installCerts.ts | 6 +++--- .../src/tasks/task.rnv.crypto.installProfiles.ts | 6 +++--- .../src/tasks/task.rnv.crypto.updateProfile.ts | 4 ++-- .../src/tasks/task.rnv.crypto.updateProfiles.ts | 12 ++++++------ packages/engine-rn/src/tasks/task.rnv.debug.ts | 4 ++-- packages/engine-rn/src/tasks/task.rnv.deploy.ts | 4 ++-- packages/engine-rn/src/tasks/task.rnv.eject.ts | 4 ++-- packages/engine-rn/src/tasks/task.rnv.export.ts | 6 +++--- packages/engine-rn/src/tasks/task.rnv.log.ts | 4 ++-- packages/engine-rn/src/tasks/task.rnv.package.ts | 4 ++-- packages/engine-rn/src/tasks/task.rnv.run.ts | 4 ++-- packages/engine-rn/src/tasks/task.rnv.start.ts | 6 +++--- packages/engine-rn/tsconfig.json | 1 - packages/rnv/src/core/common.ts | 4 +++- packages/rnv/src/core/sdkManager/index.ts | 2 ++ packages/rnv/src/core/taskManager/index.ts | 2 +- packages/sdk-apple/src/fastlane.ts | 4 ++-- packages/sdk-apple/src/index.ts | 3 ++- 21 files changed, 47 insertions(+), 43 deletions(-) rename packages/engine-rn/__tests__/unitTests/{tasks.test.js => tasks.test.ts} (100%) diff --git a/packages/engine-rn/__tests__/unitTests/tasks.test.js b/packages/engine-rn/__tests__/unitTests/tasks.test.ts similarity index 100% rename from packages/engine-rn/__tests__/unitTests/tasks.test.js rename to packages/engine-rn/__tests__/unitTests/tasks.test.ts diff --git a/packages/engine-rn/src/tasks/task.rnv.build.ts b/packages/engine-rn/src/tasks/task.rnv.build.ts index 98e81bf08c..9e675c116d 100644 --- a/packages/engine-rn/src/tasks/task.rnv.build.ts +++ b/packages/engine-rn/src/tasks/task.rnv.build.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; import { buildAndroid } from '@rnv/sdk-android'; import { buildXcodeProject } from '@rnv/sdk-apple'; @@ -9,7 +9,7 @@ const { IOS, MACOS, ANDROID, ANDROID_TV, FIRE_TV, ANDROID_WEAR, TASK_BUILD, TASK const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvBuild = async (c, parentTask, originTask) => { +export const taskRnvBuild: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvBuild'); const { platform } = c; @@ -29,7 +29,7 @@ export const taskRnvBuild = async (c, parentTask, originTask) => { // build task is not necessary when exporting ios return true; } - return buildXcodeProject(c, platform); + return buildXcodeProject(c); default: return logErrorPlatform(c); } diff --git a/packages/engine-rn/src/tasks/task.rnv.configure.ts b/packages/engine-rn/src/tasks/task.rnv.configure.ts index 853a423f58..bc09bcab70 100644 --- a/packages/engine-rn/src/tasks/task.rnv.configure.ts +++ b/packages/engine-rn/src/tasks/task.rnv.configure.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager, NPMUtils, TemplateManager } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, NPMUtils, TemplateManager, RnvTaskFn } from 'rnv'; import { configureGradleProject } from '@rnv/sdk-android'; import { configureXcodeProject } from '@rnv/sdk-apple'; import { configureMetroConfigs } from '../commonEngine'; @@ -12,7 +12,7 @@ const { IOS, MACOS, ANDROID, ANDROID_TV, FIRE_TV, ANDROID_WEAR, TASK_PLATFORM_CO const { executeTask, shouldSkipTask } = TaskManager; const { configureEntryPoint } = TemplateManager; -export const taskRnvConfigure = async (c, parentTask, originTask) => { +export const taskRnvConfigure: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvConfigure'); await configureMetroConfigs(c); diff --git a/packages/engine-rn/src/tasks/task.rnv.crypto.installCerts.ts b/packages/engine-rn/src/tasks/task.rnv.crypto.installCerts.ts index 6f166a1db7..76b4fb9d02 100644 --- a/packages/engine-rn/src/tasks/task.rnv.crypto.installCerts.ts +++ b/packages/engine-rn/src/tasks/task.rnv.crypto.installCerts.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, Exec, FileUtils } from 'rnv'; +import { TaskManager, Constants, Logger, Exec, FileUtils, RnvTaskFn } from 'rnv'; const { logWarning, logError, logTask } = Logger; const { getFileListSync } = FileUtils; @@ -6,7 +6,7 @@ const { executeAsync } = Exec; const { executeTask, shouldSkipTask } = TaskManager; const { TASK_CRYPTO_INSTALL_CERTS, TASK_PROJECT_CONFIGURE, PARAMS } = Constants; -export const taskRnvCryptoInstallCerts = async (c, parentTask, originTask) => { +export const taskRnvCryptoInstallCerts: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvCryptoInstallCerts'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_CRYPTO_INSTALL_CERTS, originTask); @@ -24,7 +24,7 @@ export const taskRnvCryptoInstallCerts = async (c, parentTask, originTask) => { try { Promise.all(cerArr.map((v) => executeAsync(c, `security import ${v} -k ${kChain} -A`))); - } catch (e) { + } catch (e: any) { logWarning(e); return true; } diff --git a/packages/engine-rn/src/tasks/task.rnv.crypto.installProfiles.ts b/packages/engine-rn/src/tasks/task.rnv.crypto.installProfiles.ts index 608efba2a5..e5e72680ac 100644 --- a/packages/engine-rn/src/tasks/task.rnv.crypto.installProfiles.ts +++ b/packages/engine-rn/src/tasks/task.rnv.crypto.installProfiles.ts @@ -1,12 +1,12 @@ import path from 'path'; -import { TaskManager, Constants, Logger, FileUtils } from 'rnv'; +import { TaskManager, Constants, Logger, FileUtils, RnvTaskFn } from 'rnv'; const { logWarning, logError, logTask, logDebug } = Logger; const { getFileListSync, copyFileSync, mkdirSync, fsExistsSync } = FileUtils; const { executeTask, shouldSkipTask } = TaskManager; const { TASK_CRYPTO_INSTALL_PROFILES, TASK_PROJECT_CONFIGURE, PARAMS } = Constants; -export const taskRnvCryptoInstallProfiles = async (c, parentTask, originTask) => { +export const taskRnvCryptoInstallProfiles: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvCryptoInstallProfiles'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_CRYPTO_INSTALL_PROFILES, originTask); @@ -33,7 +33,7 @@ export const taskRnvCryptoInstallProfiles = async (c, parentTask, originTask) => logDebug(`taskRnvCryptoInstallProfiles: Installing: ${v}`); copyFileSync(v, ppFolder); }); - } catch (e) { + } catch (e: any) { logError(e); } diff --git a/packages/engine-rn/src/tasks/task.rnv.crypto.updateProfile.ts b/packages/engine-rn/src/tasks/task.rnv.crypto.updateProfile.ts index bf52e23297..42416e3981 100644 --- a/packages/engine-rn/src/tasks/task.rnv.crypto.updateProfile.ts +++ b/packages/engine-rn/src/tasks/task.rnv.crypto.updateProfile.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger } from 'rnv'; +import { TaskManager, Constants, Logger, RnvTaskFn } from 'rnv'; import { updateProfile } from '@rnv/sdk-apple'; @@ -6,7 +6,7 @@ const { executeTask, shouldSkipTask } = TaskManager; const { logTask } = Logger; const { TASK_CRYPTO_UPDATE_PROFILE, TASK_PROJECT_CONFIGURE, IOS, PARAMS } = Constants; -export const taskRnvCryptoUpdateProfile = async (c, parentTask, originTask) => { +export const taskRnvCryptoUpdateProfile: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvCryptoUpdateProfile'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_CRYPTO_UPDATE_PROFILE, originTask); diff --git a/packages/engine-rn/src/tasks/task.rnv.crypto.updateProfiles.ts b/packages/engine-rn/src/tasks/task.rnv.crypto.updateProfiles.ts index 7639ce4a0b..d3a5d7f3e3 100644 --- a/packages/engine-rn/src/tasks/task.rnv.crypto.updateProfiles.ts +++ b/packages/engine-rn/src/tasks/task.rnv.crypto.updateProfiles.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, ConfigManager } from 'rnv'; +import { TaskManager, Constants, Logger, ConfigManager, RnvTaskFn, RnvContext } from 'rnv'; import { updateProfile } from '@rnv/sdk-apple'; const { listAppConfigsFoldersSync } = ConfigManager; @@ -7,22 +7,22 @@ const { chalk, logTask } = Logger; const { IOS, TASK_CRYPTO_UPDATE_PROFILES, TASK_PROJECT_CONFIGURE, PARAMS } = Constants; const { executeTask, shouldSkipTask } = TaskManager; -const _updateProfile = (c, v) => - new Promise((resolve, reject) => { +const _updateProfile = (c: RnvContext, v: string) => + new Promise((resolve, reject) => { logTask(`_updateProfile:${v}`, chalk().grey); updateProfile(c, v) .then(() => resolve()) - .catch((e) => reject(e)); + .catch((e: any) => reject(e)); }); -const _updateProfiles = (c) => { +const _updateProfiles = (c: RnvContext) => { logTask('_updateProfiles', chalk().grey); const acList = listAppConfigsFoldersSync(c, true); return acList.reduce((previousPromise, v) => previousPromise.then(() => _updateProfile(c, v)), Promise.resolve()); }; -export const taskRnvCryptoUpdateProfiles = async (c, parentTask, originTask) => { +export const taskRnvCryptoUpdateProfiles: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvCryptoUpdateProfiles'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_CRYPTO_UPDATE_PROFILES, originTask); diff --git a/packages/engine-rn/src/tasks/task.rnv.debug.ts b/packages/engine-rn/src/tasks/task.rnv.debug.ts index 3aeea71d31..27c6809ee6 100644 --- a/packages/engine-rn/src/tasks/task.rnv.debug.ts +++ b/packages/engine-rn/src/tasks/task.rnv.debug.ts @@ -1,10 +1,10 @@ -import { Constants, Logger, PlatformManager } from 'rnv'; +import { Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; const { logErrorPlatform } = PlatformManager; const { logTask } = Logger; const { PARAMS } = Constants; -export const taskRnvDebug = async (c, parentTask) => { +export const taskRnvDebug: RnvTaskFn = async (c, parentTask) => { logTask('taskRnvDebug', `parent:${parentTask}`); const { platform } = c; diff --git a/packages/engine-rn/src/tasks/task.rnv.deploy.ts b/packages/engine-rn/src/tasks/task.rnv.deploy.ts index 18aaf137a5..c3bea20cf8 100644 --- a/packages/engine-rn/src/tasks/task.rnv.deploy.ts +++ b/packages/engine-rn/src/tasks/task.rnv.deploy.ts @@ -1,10 +1,10 @@ -import { TaskManager, Constants, Logger } from 'rnv'; +import { TaskManager, Constants, Logger, RnvTaskFn } from 'rnv'; const { logTask } = Logger; const { TASK_EXPORT, TASK_DEPLOY, IOS, MACOS, ANDROID, ANDROID_TV, FIRE_TV, ANDROID_WEAR, PARAMS } = Constants; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvDeploy = async (c, parentTask, originTask) => { +export const taskRnvDeploy: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvDeploy', `parent:${parentTask}`); await executeOrSkipTask(c, TASK_EXPORT, TASK_DEPLOY, originTask); diff --git a/packages/engine-rn/src/tasks/task.rnv.eject.ts b/packages/engine-rn/src/tasks/task.rnv.eject.ts index 7635242a9d..fc7a47ca28 100644 --- a/packages/engine-rn/src/tasks/task.rnv.eject.ts +++ b/packages/engine-rn/src/tasks/task.rnv.eject.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; import { ejectGradleProject } from '@rnv/sdk-android'; import { ejectXcodeProject } from '@rnv/sdk-apple'; @@ -10,7 +10,7 @@ const TASK_EJECT = 'eject'; const { shouldSkipTask, executeOrSkipTask } = TaskManager; -export const taskRnvEject = async (c, parentTask, originTask) => { +export const taskRnvEject: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvEject'); const { platform } = c; diff --git a/packages/engine-rn/src/tasks/task.rnv.export.ts b/packages/engine-rn/src/tasks/task.rnv.export.ts index 0012b01d08..75297ba337 100644 --- a/packages/engine-rn/src/tasks/task.rnv.export.ts +++ b/packages/engine-rn/src/tasks/task.rnv.export.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; import { exportXcodeProject } from '@rnv/sdk-apple'; const { logErrorPlatform } = PlatformManager; @@ -7,7 +7,7 @@ const { IOS, MACOS, ANDROID, ANDROID_TV, FIRE_TV, ANDROID_WEAR, TASK_BUILD, TASK const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvExport = async (c, parentTask, originTask) => { +export const taskRnvExport: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvExport', `parent:${parentTask}`); const { platform } = c; @@ -18,7 +18,7 @@ export const taskRnvExport = async (c, parentTask, originTask) => { switch (platform) { case IOS: case MACOS: - return exportXcodeProject(c, platform); + return exportXcodeProject(c); case ANDROID: case ANDROID_TV: case FIRE_TV: diff --git a/packages/engine-rn/src/tasks/task.rnv.log.ts b/packages/engine-rn/src/tasks/task.rnv.log.ts index b43ac10794..0ef13828e2 100644 --- a/packages/engine-rn/src/tasks/task.rnv.log.ts +++ b/packages/engine-rn/src/tasks/task.rnv.log.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager, SDKManager } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, SDKManager, RnvTaskFn } from 'rnv'; import { runAndroidLog } from '@rnv/sdk-android'; @@ -13,7 +13,7 @@ const { PARAMS, IOS, ANDROID, ANDROID_TV, FIRE_TV, ANDROID_WEAR, TASK_WORKSPACE_ Constants; const { executeTask } = TaskManager; -export const taskRnvLog = async (c, parentTask, originTask) => { +export const taskRnvLog: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvLog', `parent:${parentTask}`); await executeTask(c, TASK_WORKSPACE_CONFIGURE, TASK_PROJECT_CONFIGURE, originTask); diff --git a/packages/engine-rn/src/tasks/task.rnv.package.ts b/packages/engine-rn/src/tasks/task.rnv.package.ts index 26c2cd33fd..b46cda9695 100644 --- a/packages/engine-rn/src/tasks/task.rnv.package.ts +++ b/packages/engine-rn/src/tasks/task.rnv.package.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager, Common } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, Common, RnvTaskFn } from 'rnv'; import { packageAndroid } from '@rnv/sdk-android'; import { packageBundleForXcode } from '@rnv/sdk-apple'; @@ -9,7 +9,7 @@ const { getConfigProp } = Common; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvPackage = async (c, parentTask, originTask) => { +export const taskRnvPackage: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvPackage', `parent:${parentTask}`); const { platform } = c; diff --git a/packages/engine-rn/src/tasks/task.rnv.run.ts b/packages/engine-rn/src/tasks/task.rnv.run.ts index 62cfc52c16..01a2dd4918 100644 --- a/packages/engine-rn/src/tasks/task.rnv.run.ts +++ b/packages/engine-rn/src/tasks/task.rnv.run.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager, Common } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, Common, RnvTaskFn } from 'rnv'; import { packageAndroid, runAndroid } from '@rnv/sdk-android'; import { runXcodeProject } from '@rnv/sdk-apple'; import { startBundlerIfRequired, waitForBundlerIfRequired } from '../commonEngine'; @@ -10,7 +10,7 @@ const { IOS, MACOS, ANDROID, ANDROID_TV, FIRE_TV, ANDROID_WEAR, TASK_RUN, TASK_C const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvRun = async (c, parentTask, originTask) => { +export const taskRnvRun: RnvTaskFn = async (c, parentTask, originTask) => { const { platform } = c; const { port } = c.runtime; const { hosted } = c.program; diff --git a/packages/engine-rn/src/tasks/task.rnv.start.ts b/packages/engine-rn/src/tasks/task.rnv.start.ts index a1664f8d98..51cf33ec9e 100644 --- a/packages/engine-rn/src/tasks/task.rnv.start.ts +++ b/packages/engine-rn/src/tasks/task.rnv.start.ts @@ -1,4 +1,4 @@ -import { TaskManager, EngineManager, Constants, Logger, PlatformManager, Exec, Common, Resolver } from 'rnv'; +import { TaskManager, EngineManager, Constants, Logger, PlatformManager, Exec, Common, Resolver, RnvTaskFn } from 'rnv'; import { isBundlerActive } from '../commonEngine'; const { getEntryFile, confirmActiveBundler } = Common; @@ -10,7 +10,7 @@ const { chalk, logTask, logError, logRaw, logInfo } = Logger; const { IOS, MACOS, ANDROID, ANDROID_TV, FIRE_TV, ANDROID_WEAR, TASK_START, TASK_CONFIGURE_SOFT, PARAMS } = Constants; const { executeAsync } = Exec; -const BUNDLER_PLATFORMS = {}; +const BUNDLER_PLATFORMS: Record = {}; BUNDLER_PLATFORMS[IOS] = IOS; BUNDLER_PLATFORMS[MACOS] = IOS; @@ -19,7 +19,7 @@ BUNDLER_PLATFORMS[ANDROID_TV] = ANDROID; BUNDLER_PLATFORMS[FIRE_TV] = ANDROID; BUNDLER_PLATFORMS[ANDROID_WEAR] = ANDROID; -export const taskRnvStart = async (c, parentTask, originTask) => { +export const taskRnvStart: RnvTaskFn = async (c, parentTask, originTask) => { const { platform } = c; const { hosted } = c.program; diff --git a/packages/engine-rn/tsconfig.json b/packages/engine-rn/tsconfig.json index eef5815c2f..47fc361091 100644 --- a/packages/engine-rn/tsconfig.json +++ b/packages/engine-rn/tsconfig.json @@ -3,7 +3,6 @@ "compilerOptions": { "outDir": "./dist", "rootDir": "./src", - "allowJs": true, "resolveJsonModule": false }, "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"] diff --git a/packages/rnv/src/core/common.ts b/packages/rnv/src/core/common.ts index d487b5cb62..d9db5684da 100755 --- a/packages/rnv/src/core/common.ts +++ b/packages/rnv/src/core/common.ts @@ -161,7 +161,9 @@ export const confirmActiveBundler = async (c: RnvContext) => { if (c.runtime.skipActiveServerCheck) return true; if (c.program.ci) { - return killPort(parseInt(c.runtime.port)); + //TODO: handle return codes properly + await killPort(parseInt(c.runtime.port)); + return true; } const choices = ['Restart the server (recommended)', 'Use existing session']; diff --git a/packages/rnv/src/core/sdkManager/index.ts b/packages/rnv/src/core/sdkManager/index.ts index 22c9dfa70d..deb1a29503 100644 --- a/packages/rnv/src/core/sdkManager/index.ts +++ b/packages/rnv/src/core/sdkManager/index.ts @@ -6,4 +6,6 @@ import * as Webos from './deviceUtils/webos'; import * as Kaios from './deviceUtils/kaios'; import * as Installer from './installer'; +export * from './installer'; + export { waitForEmulator, Android, Apple, Tizen, Webos, Kaios, Installer }; diff --git a/packages/rnv/src/core/taskManager/index.ts b/packages/rnv/src/core/taskManager/index.ts index 88af2eacff..9a2224c78a 100644 --- a/packages/rnv/src/core/taskManager/index.ts +++ b/packages/rnv/src/core/taskManager/index.ts @@ -331,7 +331,7 @@ To avoid that test your task code against parentTask and avoid executing same ta logExitTask(`${prt}<= ${task}`); }; -export const executeOrSkipTask = async (c: RnvContext, task: string, parentTask: string, originTask: string) => { +export const executeOrSkipTask = async (c: RnvContext, task: string, parentTask: string, originTask?: string) => { if (!c.program.only) { return executeTask(c, task, parentTask, originTask); } diff --git a/packages/sdk-apple/src/fastlane.ts b/packages/sdk-apple/src/fastlane.ts index 0ddbad22c5..1e55e9bbce 100644 --- a/packages/sdk-apple/src/fastlane.ts +++ b/packages/sdk-apple/src/fastlane.ts @@ -30,8 +30,8 @@ export const registerDevice = async (c: RnvContext) => { } }; -export const updateProfile = async (c: RnvContext, appConfigId: string) => { - logTask(`updateProfile:${appConfigId}`, chalk().grey); +export const updateProfile = async (c: RnvContext) => { + logTask(`updateProfile`, chalk().grey); // TODO: run trough all schemes // const schemes = c.buildConfig.platforms?.[c.platform]?.buildSchemes diff --git a/packages/sdk-apple/src/index.ts b/packages/sdk-apple/src/index.ts index 82cc8497ab..b64d324242 100644 --- a/packages/sdk-apple/src/index.ts +++ b/packages/sdk-apple/src/index.ts @@ -16,7 +16,7 @@ import { SDKManager, } from 'rnv'; import { getAppFolderName } from './common'; -import { registerDevice } from './fastlane'; +import { registerDevice, updateProfile } from './fastlane'; import { parseEntitlementsPlist, parseExportOptionsPlist, parseInfoPlist } from './plistParser'; import { parsePodFile } from './podfileParser'; import { parseAppDelegate } from './swiftParser'; @@ -931,4 +931,5 @@ export { exportXcodeProject, archiveXcodeProject, runAppleLog, + updateProfile, }; From 214502b7e495794924a1ab0b7895efb68a0e52cd Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 00:12:40 +0200 Subject: [PATCH 52/83] engine-rn migrated to TS --- packages/engine-rn/src/adapter.ts | 19 +++++++------- packages/engine-rn/src/commonEngine.ts | 26 +++++++++---------- packages/engine-rn/src/index.ts | 11 +++++--- .../tasks/task.rnv.crypto.updateProfiles.ts | 2 +- packages/rnv/src/core/engineManager/types.ts | 8 +++--- 5 files changed, 36 insertions(+), 30 deletions(-) diff --git a/packages/engine-rn/src/adapter.ts b/packages/engine-rn/src/adapter.ts index f3285dba04..bb3c8f802b 100644 --- a/packages/engine-rn/src/adapter.ts +++ b/packages/engine-rn/src/adapter.ts @@ -7,29 +7,30 @@ const sharedBlacklist = [ /.*\/__tests__\/.*/, ]; -function escapeRegExp(pattern) { - if (Object.prototype.toString.call(pattern) === '[object RegExp]') { - return pattern.source.replace(/\//g, path.sep); - } +const env: any = process?.env; + +function escapeRegExp(pattern: RegExp | string) { if (typeof pattern === 'string') { // eslint-disable-next-line const escaped = pattern.replace(/[\-\[\]\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'); // convert the '/' into an escaped local file separator return escaped.replace(/\//g, `\\${path.sep}`); + } else if (Object.prototype.toString.call(pattern) === '[object RegExp]') { + return pattern.source.replace(/\//g, path.sep); } throw new Error(`Unexpected blacklist pattern: ${pattern}`); } -function blacklist(additionalBlacklist) { +function blacklist(additionalBlacklist: RegExp[]) { return new RegExp(`(${(additionalBlacklist || []).concat(sharedBlacklist).map(escapeRegExp).join('|')})$`); } -export const withRNVMetro = (config) => { +export const withRNVMetro = (config: any) => { const projectPath = process.env.RNV_PROJECT_ROOT || process.cwd(); const watchFolders = [path.resolve(projectPath, 'node_modules')]; - if (process.env.RNV_IS_MONOREPO === 'true' || process.env.RNV_IS_MONOREPO === true) { + if (env.RNV_IS_MONOREPO === 'true' || env.RNV_IS_MONOREPO === true) { const monoRootPath = process.env.RNV_MONO_ROOT || projectPath; watchFolders.push(path.resolve(monoRootPath, 'node_modules')); watchFolders.push(path.resolve(monoRootPath, 'packages')); @@ -38,7 +39,7 @@ export const withRNVMetro = (config) => { watchFolders.push(...config.watchFolders); } - const exts = process.env.RNV_EXTENSIONS || []; + const exts: string = env.RNV_EXTENSIONS || ''; const cnf = { ...config, @@ -75,7 +76,7 @@ export const withRNVMetro = (config) => { return cnf; }; -export const withRNVBabel = (cnf) => { +export const withRNVBabel = (cnf: any) => { const plugins = cnf?.plugins || []; return { diff --git a/packages/engine-rn/src/commonEngine.ts b/packages/engine-rn/src/commonEngine.ts index 73dfdc17b1..f7fe283700 100644 --- a/packages/engine-rn/src/commonEngine.ts +++ b/packages/engine-rn/src/commonEngine.ts @@ -1,6 +1,6 @@ import path from 'path'; import axios from 'axios'; -import { TaskManager, Constants, Logger, Common, FileUtils, Prompt, Spinner } from 'rnv'; +import { TaskManager, Constants, Logger, Common, FileUtils, Prompt, Spinner, RnvContext } from 'rnv'; const { inquirerPrompt } = Prompt; const { getConfigProp, confirmActiveBundler } = Common; @@ -11,7 +11,7 @@ const { executeTask } = TaskManager; let keepRNVRunning = false; -export const startBundlerIfRequired = async (c, parentTask, originTask) => { +export const startBundlerIfRequired = async (c: RnvContext, parentTask: string, originTask?: string) => { logTask('startBundlerIfRequired'); const bundleAssets = getConfigProp(c, c.platform, 'bundleAssets'); if (bundleAssets === true) return; @@ -34,7 +34,7 @@ export const startBundlerIfRequired = async (c, parentTask, originTask) => { } }; -export const waitForBundlerIfRequired = async (c) => { +export const waitForBundlerIfRequired = async (c: RnvContext) => { const bundleAssets = getConfigProp(c, c.platform, 'bundleAssets'); if (bundleAssets === true) return; // return a new promise that does...nothing, just to keep RNV running while the bundler is running @@ -45,7 +45,7 @@ export const waitForBundlerIfRequired = async (c) => { return true; }; -export const configureMetroConfigs = async (c) => { +export const configureMetroConfigs = async (c: RnvContext) => { logTask('configureMetroConfigs'); const metroSnippet = ` @@ -80,7 +80,7 @@ to your ${chalk().white('/.metro.config.js')} instead and delete deprecated file } }; -const _isBundlerRunning = async (c) => { +const _isBundlerRunning = async (c: RnvContext) => { logTask('_isBundlerRunning'); try { const { data } = await axios.get( @@ -98,7 +98,7 @@ const _isBundlerRunning = async (c) => { } }; -export const isBundlerActive = async (c) => { +export const isBundlerActive = async (c: RnvContext) => { logTask('isBundlerActive', `(http://${c.runtime.localhost}:${c.runtime.port})`); try { await axios.get(`http://${c.runtime.localhost}:${c.runtime.port}`); @@ -108,15 +108,15 @@ export const isBundlerActive = async (c) => { } }; -const poll = (fn, timeout = 10000, interval = 1000) => { +const poll = (fn: () => Promise, timeout = 10000, interval = 1000) => { const endTime = Number(new Date()) + timeout; - const spinner = Spinner('Waiting for bundler to finish...').start(); - const checkCondition = async (resolve, reject) => { + const spinner = Spinner('Waiting for bundler to finish...').start(''); + const checkCondition = async (resolve: () => void, reject: (e: string) => void) => { try { const result = await fn(); if (result) { - spinner.succeed(); + spinner.succeed(''); resolve(); } else if (Number(new Date()) < endTime) { setTimeout(checkCondition, interval, resolve, reject); @@ -124,13 +124,13 @@ const poll = (fn, timeout = 10000, interval = 1000) => { spinner.fail("Can't connect to bundler. Try restarting it."); reject("Can't connect to bundler. Try restarting it."); } - } catch (e) { + } catch (e: any) { spinner.fail("Can't connect to bundler. Try restarting it."); reject(e); } }; - return new Promise(checkCondition); + return new Promise(checkCondition); }; -export const waitForBundler = async (c) => poll(() => _isBundlerRunning(c)); +export const waitForBundler = async (c: RnvContext) => poll(() => _isBundlerRunning(c)); diff --git a/packages/engine-rn/src/index.ts b/packages/engine-rn/src/index.ts index aa12b7b37f..1d2515abce 100644 --- a/packages/engine-rn/src/index.ts +++ b/packages/engine-rn/src/index.ts @@ -1,5 +1,6 @@ -import { EngineManager, Config } from 'rnv'; +import { EngineManager, Config, RnvEngine } from 'rnv'; import { withRNVMetro, withRNVBabel } from './adapter'; +//@ts-ignore import CNF from '../renative.engine.json'; import taskRnvRun from './tasks/task.rnv.run'; import taskRnvPackage from './tasks/task.rnv.package'; @@ -18,7 +19,7 @@ import taskRnvEject from './tasks/task.rnv.eject'; const { generateEngineTasks, generateEngineExtensions } = EngineManager; -export default { +const engine: RnvEngine = { initializeRuntimeConfig: (c) => Config.initializeConfig(c), tasks: generateEngineTasks([ taskRnvRun, @@ -43,7 +44,9 @@ export default { xcodeProjectName: 'RNVApp', }, projectDirName: '', - ejectPlatform: null, + serverDirName: '', + package: '', + // ejectPlatform: null, platforms: { ios: { defaultPort: 8082, @@ -87,6 +90,8 @@ export default { }, }; +export default engine; + // Backward compatibility const withRNV = withRNVMetro; diff --git a/packages/engine-rn/src/tasks/task.rnv.crypto.updateProfiles.ts b/packages/engine-rn/src/tasks/task.rnv.crypto.updateProfiles.ts index d3a5d7f3e3..4627adf0e3 100644 --- a/packages/engine-rn/src/tasks/task.rnv.crypto.updateProfiles.ts +++ b/packages/engine-rn/src/tasks/task.rnv.crypto.updateProfiles.ts @@ -10,7 +10,7 @@ const { executeTask, shouldSkipTask } = TaskManager; const _updateProfile = (c: RnvContext, v: string) => new Promise((resolve, reject) => { logTask(`_updateProfile:${v}`, chalk().grey); - updateProfile(c, v) + updateProfile(c) .then(() => resolve()) .catch((e: any) => reject(e)); }); diff --git a/packages/rnv/src/core/engineManager/types.ts b/packages/rnv/src/core/engineManager/types.ts index b828d2b664..d7994cc712 100644 --- a/packages/rnv/src/core/engineManager/types.ts +++ b/packages/rnv/src/core/engineManager/types.ts @@ -13,14 +13,14 @@ export type RnvEngine = { runtimeExtraProps: any; outputDirName?: string; serverDirName: string; - package: any; - ejectPlatform: any; + package: string; + // ejectPlatform: null; }; export type RnvEnginePlatform = { extensions: Array; - isWebHosted: boolean; - defaultPort: string; + isWebHosted?: boolean; + defaultPort: number; }; export type RnvEngineConfig = { From 3f50d45fce400708456fa3efbef3738bdf581e58 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 00:18:49 +0200 Subject: [PATCH 53/83] more ts fixes --- packages/engine-rn/src/index.ts | 2 +- packages/rnv/src/core/common.ts | 4 ++-- packages/rnv/src/core/configManager/types.ts | 2 +- packages/rnv/src/core/context/types.ts | 2 +- packages/rnv/src/core/engineManager/types.ts | 2 +- packages/rnv/src/engine-core/index.ts | 4 ++-- packages/rnv/src/engine-core/tasks/task.rnv.kill.ts | 4 ++-- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/engine-rn/src/index.ts b/packages/engine-rn/src/index.ts index 1d2515abce..4b23df4894 100644 --- a/packages/engine-rn/src/index.ts +++ b/packages/engine-rn/src/index.ts @@ -45,7 +45,7 @@ const engine: RnvEngine = { }, projectDirName: '', serverDirName: '', - package: '', + // package: '', // ejectPlatform: null, platforms: { ios: { diff --git a/packages/rnv/src/core/common.ts b/packages/rnv/src/core/common.ts index d9db5684da..97ddc055b8 100755 --- a/packages/rnv/src/core/common.ts +++ b/packages/rnv/src/core/common.ts @@ -501,7 +501,7 @@ export const getBuildsFolder = (c: RnvContext, platform: string, customPath?: st export const getIP = () => ip.address(); -export const checkPortInUse = (c: RnvContext, platform: string, port: string) => +export const checkPortInUse = (c: RnvContext, platform: string, port: number) => new Promise((resolve, reject) => { if (port === undefined || port === null) { resolve(false); @@ -512,7 +512,7 @@ export const checkPortInUse = (c: RnvContext, platform: string, port: string) => reject(err); return; } - const result = parseInt(port, 10) !== parseInt(availablePort, 10); + const result = port !== parseInt(availablePort, 10); resolve(result); }); }); diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index 345991b549..5285750a41 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -10,7 +10,7 @@ export type RenativeConfigFile = { excludedPermissions: RenativeConfigPermissionsList; }; defaults: { - ports?: Record; + ports?: Record; supportedPlatforms?: Array; portOffset?: number; }; diff --git a/packages/rnv/src/core/context/types.ts b/packages/rnv/src/core/context/types.ts index 921b748f18..ab7ef35ace 100644 --- a/packages/rnv/src/core/context/types.ts +++ b/packages/rnv/src/core/context/types.ts @@ -261,6 +261,6 @@ export interface RnvContextPlatform { platform: string; isConnected: boolean; engine?: any; - port?: string; + port?: number; isValid?: boolean; } diff --git a/packages/rnv/src/core/engineManager/types.ts b/packages/rnv/src/core/engineManager/types.ts index d7994cc712..869623ee62 100644 --- a/packages/rnv/src/core/engineManager/types.ts +++ b/packages/rnv/src/core/engineManager/types.ts @@ -13,7 +13,7 @@ export type RnvEngine = { runtimeExtraProps: any; outputDirName?: string; serverDirName: string; - package: string; + // package: string; // ejectPlatform: null; }; diff --git a/packages/rnv/src/engine-core/index.ts b/packages/rnv/src/engine-core/index.ts index 7981c05258..7c6ce937f4 100644 --- a/packages/rnv/src/engine-core/index.ts +++ b/packages/rnv/src/engine-core/index.ts @@ -98,9 +98,9 @@ const engine: RnvEngine = { platforms: {}, npm: {}, }, - package: {}, + // package: '', projectDirName: '', - ejectPlatform: null, + // ejectPlatform: null, platforms: {}, }; diff --git a/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts b/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts index ec77758eb9..68d256183b 100644 --- a/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts +++ b/packages/rnv/src/engine-core/tasks/task.rnv.kill.ts @@ -15,7 +15,7 @@ export const taskRnvKill: RnvTaskFn = async (c, _parentTask, originTask) => { const usedPorts: RnvContext['runtime']['supportedPlatforms'] = []; let platArray: RnvContext['runtime']['supportedPlatforms'] = []; const results = []; - let ports: Record = {}; + let ports: Record = {}; await configureRuntimeDefaults(c); @@ -50,7 +50,7 @@ ${usedPorts.map((v) => chalk().white(`> ${v.port} (${v.platform})`)).join('\n')} if (confirm) { const killPromise = []; usedPorts.forEach((v) => { - if (v.port) killPromise.push(killPort(parseInt(v.port))); + if (v.port) killPromise.push(killPort(v.port)); }); await Promise.all(usedPorts); logSuccess('Processes KILLED'); From fa0c1b5e3b05bd2cbe0782b315de353db1766d97 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 00:21:24 +0200 Subject: [PATCH 54/83] rename engine-lightning js to ts --- packages/engine-lightning/src/{index.js => index.ts} | 0 packages/engine-lightning/src/sdks/{index.js => index.ts} | 0 .../src/sdks/sdk-lightning/{index.js => index.ts} | 0 .../src/tasks/{task.rnv.build.js => task.rnv.build.ts} | 0 .../src/tasks/{task.rnv.configure.js => task.rnv.configure.ts} | 0 .../src/tasks/{task.rnv.run.js => task.rnv.run.ts} | 0 packages/engine-lightning/tsconfig.json | 1 - 7 files changed, 1 deletion(-) rename packages/engine-lightning/src/{index.js => index.ts} (100%) rename packages/engine-lightning/src/sdks/{index.js => index.ts} (100%) rename packages/engine-lightning/src/sdks/sdk-lightning/{index.js => index.ts} (100%) rename packages/engine-lightning/src/tasks/{task.rnv.build.js => task.rnv.build.ts} (100%) rename packages/engine-lightning/src/tasks/{task.rnv.configure.js => task.rnv.configure.ts} (100%) rename packages/engine-lightning/src/tasks/{task.rnv.run.js => task.rnv.run.ts} (100%) diff --git a/packages/engine-lightning/src/index.js b/packages/engine-lightning/src/index.ts similarity index 100% rename from packages/engine-lightning/src/index.js rename to packages/engine-lightning/src/index.ts diff --git a/packages/engine-lightning/src/sdks/index.js b/packages/engine-lightning/src/sdks/index.ts similarity index 100% rename from packages/engine-lightning/src/sdks/index.js rename to packages/engine-lightning/src/sdks/index.ts diff --git a/packages/engine-lightning/src/sdks/sdk-lightning/index.js b/packages/engine-lightning/src/sdks/sdk-lightning/index.ts similarity index 100% rename from packages/engine-lightning/src/sdks/sdk-lightning/index.js rename to packages/engine-lightning/src/sdks/sdk-lightning/index.ts diff --git a/packages/engine-lightning/src/tasks/task.rnv.build.js b/packages/engine-lightning/src/tasks/task.rnv.build.ts similarity index 100% rename from packages/engine-lightning/src/tasks/task.rnv.build.js rename to packages/engine-lightning/src/tasks/task.rnv.build.ts diff --git a/packages/engine-lightning/src/tasks/task.rnv.configure.js b/packages/engine-lightning/src/tasks/task.rnv.configure.ts similarity index 100% rename from packages/engine-lightning/src/tasks/task.rnv.configure.js rename to packages/engine-lightning/src/tasks/task.rnv.configure.ts diff --git a/packages/engine-lightning/src/tasks/task.rnv.run.js b/packages/engine-lightning/src/tasks/task.rnv.run.ts similarity index 100% rename from packages/engine-lightning/src/tasks/task.rnv.run.js rename to packages/engine-lightning/src/tasks/task.rnv.run.ts diff --git a/packages/engine-lightning/tsconfig.json b/packages/engine-lightning/tsconfig.json index eef5815c2f..47fc361091 100644 --- a/packages/engine-lightning/tsconfig.json +++ b/packages/engine-lightning/tsconfig.json @@ -3,7 +3,6 @@ "compilerOptions": { "outDir": "./dist", "rootDir": "./src", - "allowJs": true, "resolveJsonModule": false }, "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"] From 8422c071f499a23c86df1a7f6d7f2564d9f2193d Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 00:30:15 +0200 Subject: [PATCH 55/83] fix ts errors --- packages/engine-lightning/src/index.ts | 10 ++++-- .../src/sdks/sdk-lightning/index.ts | 31 ++++++++++--------- .../src/tasks/task.rnv.build.ts | 4 +-- .../src/tasks/task.rnv.configure.ts | 4 +-- .../src/tasks/task.rnv.run.ts | 4 +-- packages/rnv/src/core/configManager/types.ts | 3 ++ packages/rnv/src/core/context/types.ts | 1 + packages/rnv/src/core/projectManager/index.ts | 2 +- .../src/core/sdkManager/deviceUtils/tizen.ts | 2 +- 9 files changed, 35 insertions(+), 26 deletions(-) diff --git a/packages/engine-lightning/src/index.ts b/packages/engine-lightning/src/index.ts index 0414775b5b..0ec9134360 100644 --- a/packages/engine-lightning/src/index.ts +++ b/packages/engine-lightning/src/index.ts @@ -1,4 +1,5 @@ -import { Config, EngineManager } from 'rnv'; +import { Config, EngineManager, RnvEngine } from 'rnv'; +//@ts-ignore import CNF from '../renative.engine.json'; // import taskRnvPackage from './tasks/task.rnv.package'; import taskRnvBuild from './tasks/task.rnv.build'; @@ -11,7 +12,7 @@ import taskRnvRun from './tasks/task.rnv.run'; const { generateEngineTasks, generateEngineExtensions } = EngineManager; -export default { +const Engine: RnvEngine = { initializeRuntimeConfig: (c) => Config.initializeConfig(c), tasks: generateEngineTasks([ taskRnvRun, @@ -26,7 +27,8 @@ export default { config: CNF, projectDirName: 'project', serverDirName: 'server', - ejectPlatform: null, + runtimeExtraProps: {}, + // ejectPlatform: null, platforms: { tizen: { defaultPort: 8087, @@ -40,3 +42,5 @@ export default { }, }, }; + +export default Engine; diff --git a/packages/engine-lightning/src/sdks/sdk-lightning/index.ts b/packages/engine-lightning/src/sdks/sdk-lightning/index.ts index bfd45f3068..a7c05ca0e3 100644 --- a/packages/engine-lightning/src/sdks/sdk-lightning/index.ts +++ b/packages/engine-lightning/src/sdks/sdk-lightning/index.ts @@ -8,6 +8,7 @@ import { Logger, PlatformManager, ProjectManager, + RnvContext, SDKManager, } from 'rnv'; import semver from 'semver'; @@ -33,8 +34,8 @@ const { writeCleanFile } = FileUtils; const { runTizenSimOrDevice, DEFAULT_SECURITY_PROFILE_NAME } = SDKManager.Tizen; const { runWebosSimOrDevice } = SDKManager.Webos; -export const runLightningProject = async (c, target) => { - logTask('runLightningProject', `target:${target}`); +export const runLightningProject = async (c: RnvContext) => { + logTask('runLightningProject'); const entryFile = getConfigProp(c, c.platform, 'entryFile'); const { platform } = c; const { hosted } = c.program; @@ -63,18 +64,18 @@ export const runLightningProject = async (c, target) => { return true; }; -export const buildLightningProject = async (c) => { +export const buildLightningProject = async (c: RnvContext) => { logTask('buildLightningProject'); const { platform } = c; - const platformConfig = c.buildConfig.platforms[platform]; + const platformConfig = c.buildConfig.platforms?.[platform]; const entryFile = getConfigProp(c, c.platform, 'entryFile'); const target = getConfigProp(c, platform, 'target', 'es6'); const tBuild = getPlatformProjectDir(c); - const tOut = path.join(tBuild, 'output'); - const certProfile = platformConfig.certificateProfile ?? DEFAULT_SECURITY_PROFILE_NAME; + const tOut = path.join(tBuild || '', 'output'); + const certProfile = platformConfig?.certificateProfile ?? DEFAULT_SECURITY_PROFILE_NAME; await executeAsync(c, `lng dist --${target}`, { stdio: 'inherit', @@ -99,7 +100,7 @@ export const buildLightningProject = async (c) => { return true; }; -export const configureLightningProject = async (c) => { +export const configureLightningProject = async (c: RnvContext) => { logTask('configureLightningProject'); const { platform } = c; c.runtime.platformBuildsProjectPath = `${getPlatformBuildDir(c)}`; @@ -111,18 +112,18 @@ export const configureLightningProject = async (c) => { return copyBuildsFolder(c, platform); }; -const _configureProject = (c) => - new Promise((resolve) => { +const _configureProject = (c: RnvContext) => + new Promise((resolve) => { logTask('_configureProject'); const { platform } = c; - const p = c.buildConfig.platforms[platform]; + const p = c.buildConfig.platforms?.[platform]; const injects = platform === TIZEN ? [ - { pattern: '{{PACKAGE}}', override: p.package }, - { pattern: '{{ID}}', override: p.id }, - { pattern: '{{APP_NAME}}', override: p.appName }, + { pattern: '{{PACKAGE}}', override: p?.package }, + { pattern: '{{ID}}', override: p?.id }, + { pattern: '{{APP_NAME}}', override: p?.appName }, { pattern: '{{APP_VERSION}}', override: semver.coerce(getAppVersion(c, platform)) }, ] : [ @@ -138,8 +139,8 @@ const _configureProject = (c) => addSystemInjects(c, injects); const configFile = platform === TIZEN ? 'config.xml' : 'appinfo.json'; - const file = path.join(getPlatformProjectDir(c), configFile); - writeCleanFile(file, file, injects, null, c); + const file = path.join(getPlatformProjectDir(c) || '', configFile); + writeCleanFile(file, file, injects, undefined, c); resolve(); }); diff --git a/packages/engine-lightning/src/tasks/task.rnv.build.ts b/packages/engine-lightning/src/tasks/task.rnv.build.ts index 2da380e2da..397e3d627a 100644 --- a/packages/engine-lightning/src/tasks/task.rnv.build.ts +++ b/packages/engine-lightning/src/tasks/task.rnv.build.ts @@ -1,4 +1,4 @@ -import { Constants, Logger, PlatformManager, TaskManager } from 'rnv'; +import { Constants, Logger, PlatformManager, RnvTaskFn, TaskManager } from 'rnv'; import { SDKLightning } from '../sdks'; const { logErrorPlatform } = PlatformManager; @@ -7,7 +7,7 @@ const { TIZEN, WEBOS, TASK_BUILD, TASK_CONFIGURE, PARAMS } = Constants; const { buildLightningProject } = SDKLightning; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvBuild = async (c, parentTask, originTask) => { +export const taskRnvBuild: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvBuild', `parent:${parentTask}`); const { platform } = c; c.runtime.forceBundleAssets = true; diff --git a/packages/engine-lightning/src/tasks/task.rnv.configure.ts b/packages/engine-lightning/src/tasks/task.rnv.configure.ts index 5f5a3a7eb7..4aeaae69ab 100644 --- a/packages/engine-lightning/src/tasks/task.rnv.configure.ts +++ b/packages/engine-lightning/src/tasks/task.rnv.configure.ts @@ -1,4 +1,4 @@ -import { Constants, Logger, PlatformManager, TaskManager } from 'rnv'; +import { Constants, Logger, PlatformManager, RnvTaskFn, TaskManager } from 'rnv'; import { SDKLightning } from '../sdks'; const { logErrorPlatform } = PlatformManager; @@ -7,7 +7,7 @@ const { TIZEN, WEBOS, TASK_PLATFORM_CONFIGURE, TASK_CONFIGURE, PARAMS } = Consta const { configureLightningProject } = SDKLightning; const { executeTask } = TaskManager; -export const taskRnvConfigure = async (c, parentTask, originTask) => { +export const taskRnvConfigure: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvConfigure'); await executeTask(c, TASK_PLATFORM_CONFIGURE, TASK_CONFIGURE, originTask); diff --git a/packages/engine-lightning/src/tasks/task.rnv.run.ts b/packages/engine-lightning/src/tasks/task.rnv.run.ts index 77e02bac4a..851f2267ee 100644 --- a/packages/engine-lightning/src/tasks/task.rnv.run.ts +++ b/packages/engine-lightning/src/tasks/task.rnv.run.ts @@ -1,4 +1,4 @@ -import { Constants, Logger, PlatformManager, TaskManager } from 'rnv'; +import { Constants, Logger, PlatformManager, RnvTaskFn, TaskManager } from 'rnv'; import { SDKLightning } from '../sdks'; const { logErrorPlatform } = PlatformManager; @@ -7,7 +7,7 @@ const { TIZEN, WEBOS, TASK_RUN, TASK_CONFIGURE, PARAMS } = Constants; const { runLightningProject } = SDKLightning; const { executeOrSkipTask } = TaskManager; -export const taskRnvRun = async (c, parentTask, originTask) => { +export const taskRnvRun: RnvTaskFn = async (c, parentTask, originTask) => { const { platform } = c; const { port } = c.runtime; const { target } = c.runtime; diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index 5285750a41..aed883b0d2 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -59,6 +59,7 @@ export type RenativeConfigPlatform = { 'gradle.properties'?: Record; includedPermissions?: RenativeConfigPermissionsList; excludedPermissions?: RenativeConfigPermissionsList; + //iOS orientationSupport?: { phone: string; tab: string; @@ -76,6 +77,8 @@ export type RenativeConfigPlatform = { frameworks: Array; buildSettings: Record; }; + //Tizen + package?: string; }; export type RenativeConfigPermissionsList = Array; diff --git a/packages/rnv/src/core/context/types.ts b/packages/rnv/src/core/context/types.ts index ab7ef35ace..17d2da47fe 100644 --- a/packages/rnv/src/core/context/types.ts +++ b/packages/rnv/src/core/context/types.ts @@ -87,6 +87,7 @@ export interface RnvContext { isWSConfirmed: boolean; _skipNativeDepResolutions: boolean; targetUDID?: string; + forceBundleAssets?: boolean; xcodeProj?: { id?: string; runScheme?: string; diff --git a/packages/rnv/src/core/projectManager/index.ts b/packages/rnv/src/core/projectManager/index.ts index 6105c00411..081402a328 100644 --- a/packages/rnv/src/core/projectManager/index.ts +++ b/packages/rnv/src/core/projectManager/index.ts @@ -432,7 +432,7 @@ const _resolvePackage = (c: RnvContext, v: string) => { export const copyAssetsFolder = async ( c: RnvContext, platform: RnvPlatform, - subPath: string, + subPath?: string, customFn?: (c: RnvContext, platform: string) => void ) => { logTask('copyAssetsFolder'); diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts index 03c33f9d9a..0acf2ca2b5 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts @@ -212,7 +212,7 @@ const _composeDevicesString = (devices: Array) => // } // }; -export const runTizenSimOrDevice = async (c: RnvContext, buildCoreWebpackProject: () => Promise) => { +export const runTizenSimOrDevice = async (c: RnvContext, buildCoreWebpackProject?: () => Promise) => { const { hosted } = c.program; const { target, engine } = c.runtime; const { platform } = c; From 8a32a1029322320f07de9efc69836bb739cd06fb Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 00:32:06 +0200 Subject: [PATCH 56/83] engine rn-electron rename js to ts --- packages/engine-rn-electron/src/{adapter.js => adapter.ts} | 0 packages/engine-rn-electron/src/{index.js => index.ts} | 0 packages/engine-rn-electron/src/sdks/{index.js => index.ts} | 0 .../src/sdks/sdk-electron/{index.js => index.ts} | 0 .../src/tasks/{task.rnv.build.js => task.rnv.build.ts} | 0 .../src/tasks/{task.rnv.configure.js => task.rnv.configure.ts} | 0 .../src/tasks/{task.rnv.debug.js => task.rnv.debug.ts} | 0 .../src/tasks/{task.rnv.deploy.js => task.rnv.deploy.ts} | 0 .../src/tasks/{task.rnv.export.js => task.rnv.export.ts} | 0 .../src/tasks/{task.rnv.package.js => task.rnv.package.ts} | 0 .../src/tasks/{task.rnv.run.js => task.rnv.run.ts} | 0 .../src/tasks/{task.rnv.start.js => task.rnv.start.ts} | 0 packages/engine-rn-electron/tsconfig.json | 1 - 13 files changed, 1 deletion(-) rename packages/engine-rn-electron/src/{adapter.js => adapter.ts} (100%) rename packages/engine-rn-electron/src/{index.js => index.ts} (100%) rename packages/engine-rn-electron/src/sdks/{index.js => index.ts} (100%) rename packages/engine-rn-electron/src/sdks/sdk-electron/{index.js => index.ts} (100%) rename packages/engine-rn-electron/src/tasks/{task.rnv.build.js => task.rnv.build.ts} (100%) rename packages/engine-rn-electron/src/tasks/{task.rnv.configure.js => task.rnv.configure.ts} (100%) rename packages/engine-rn-electron/src/tasks/{task.rnv.debug.js => task.rnv.debug.ts} (100%) rename packages/engine-rn-electron/src/tasks/{task.rnv.deploy.js => task.rnv.deploy.ts} (100%) rename packages/engine-rn-electron/src/tasks/{task.rnv.export.js => task.rnv.export.ts} (100%) rename packages/engine-rn-electron/src/tasks/{task.rnv.package.js => task.rnv.package.ts} (100%) rename packages/engine-rn-electron/src/tasks/{task.rnv.run.js => task.rnv.run.ts} (100%) rename packages/engine-rn-electron/src/tasks/{task.rnv.start.js => task.rnv.start.ts} (100%) diff --git a/packages/engine-rn-electron/src/adapter.js b/packages/engine-rn-electron/src/adapter.ts similarity index 100% rename from packages/engine-rn-electron/src/adapter.js rename to packages/engine-rn-electron/src/adapter.ts diff --git a/packages/engine-rn-electron/src/index.js b/packages/engine-rn-electron/src/index.ts similarity index 100% rename from packages/engine-rn-electron/src/index.js rename to packages/engine-rn-electron/src/index.ts diff --git a/packages/engine-rn-electron/src/sdks/index.js b/packages/engine-rn-electron/src/sdks/index.ts similarity index 100% rename from packages/engine-rn-electron/src/sdks/index.js rename to packages/engine-rn-electron/src/sdks/index.ts diff --git a/packages/engine-rn-electron/src/sdks/sdk-electron/index.js b/packages/engine-rn-electron/src/sdks/sdk-electron/index.ts similarity index 100% rename from packages/engine-rn-electron/src/sdks/sdk-electron/index.js rename to packages/engine-rn-electron/src/sdks/sdk-electron/index.ts diff --git a/packages/engine-rn-electron/src/tasks/task.rnv.build.js b/packages/engine-rn-electron/src/tasks/task.rnv.build.ts similarity index 100% rename from packages/engine-rn-electron/src/tasks/task.rnv.build.js rename to packages/engine-rn-electron/src/tasks/task.rnv.build.ts diff --git a/packages/engine-rn-electron/src/tasks/task.rnv.configure.js b/packages/engine-rn-electron/src/tasks/task.rnv.configure.ts similarity index 100% rename from packages/engine-rn-electron/src/tasks/task.rnv.configure.js rename to packages/engine-rn-electron/src/tasks/task.rnv.configure.ts diff --git a/packages/engine-rn-electron/src/tasks/task.rnv.debug.js b/packages/engine-rn-electron/src/tasks/task.rnv.debug.ts similarity index 100% rename from packages/engine-rn-electron/src/tasks/task.rnv.debug.js rename to packages/engine-rn-electron/src/tasks/task.rnv.debug.ts diff --git a/packages/engine-rn-electron/src/tasks/task.rnv.deploy.js b/packages/engine-rn-electron/src/tasks/task.rnv.deploy.ts similarity index 100% rename from packages/engine-rn-electron/src/tasks/task.rnv.deploy.js rename to packages/engine-rn-electron/src/tasks/task.rnv.deploy.ts diff --git a/packages/engine-rn-electron/src/tasks/task.rnv.export.js b/packages/engine-rn-electron/src/tasks/task.rnv.export.ts similarity index 100% rename from packages/engine-rn-electron/src/tasks/task.rnv.export.js rename to packages/engine-rn-electron/src/tasks/task.rnv.export.ts diff --git a/packages/engine-rn-electron/src/tasks/task.rnv.package.js b/packages/engine-rn-electron/src/tasks/task.rnv.package.ts similarity index 100% rename from packages/engine-rn-electron/src/tasks/task.rnv.package.js rename to packages/engine-rn-electron/src/tasks/task.rnv.package.ts diff --git a/packages/engine-rn-electron/src/tasks/task.rnv.run.js b/packages/engine-rn-electron/src/tasks/task.rnv.run.ts similarity index 100% rename from packages/engine-rn-electron/src/tasks/task.rnv.run.js rename to packages/engine-rn-electron/src/tasks/task.rnv.run.ts diff --git a/packages/engine-rn-electron/src/tasks/task.rnv.start.js b/packages/engine-rn-electron/src/tasks/task.rnv.start.ts similarity index 100% rename from packages/engine-rn-electron/src/tasks/task.rnv.start.js rename to packages/engine-rn-electron/src/tasks/task.rnv.start.ts diff --git a/packages/engine-rn-electron/tsconfig.json b/packages/engine-rn-electron/tsconfig.json index eef5815c2f..47fc361091 100644 --- a/packages/engine-rn-electron/tsconfig.json +++ b/packages/engine-rn-electron/tsconfig.json @@ -3,7 +3,6 @@ "compilerOptions": { "outDir": "./dist", "rootDir": "./src", - "allowJs": true, "resolveJsonModule": false }, "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"] From 373021b0d5c73934c45c4d943d78f2505d8b6679 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 00:38:38 +0200 Subject: [PATCH 57/83] ts fixes --- packages/engine-rn-electron/src/adapter.ts | 2 +- packages/engine-rn-electron/src/index.ts | 12 ++++++++---- .../src/sdks/sdk-electron/index.ts | 19 ++++++++++--------- .../src/tasks/task.rnv.build.ts | 4 ++-- .../src/tasks/task.rnv.configure.ts | 4 ++-- .../src/tasks/task.rnv.debug.ts | 4 ++-- .../src/tasks/task.rnv.deploy.ts | 4 ++-- .../src/tasks/task.rnv.export.ts | 4 ++-- .../src/tasks/task.rnv.package.ts | 4 ++-- .../src/tasks/task.rnv.run.ts | 4 ++-- .../src/tasks/task.rnv.start.ts | 4 ++-- packages/rnv/src/core/context/types.ts | 1 + 12 files changed, 36 insertions(+), 30 deletions(-) diff --git a/packages/engine-rn-electron/src/adapter.ts b/packages/engine-rn-electron/src/adapter.ts index 7fdd63a0bf..2fa9e36a0f 100644 --- a/packages/engine-rn-electron/src/adapter.ts +++ b/packages/engine-rn-electron/src/adapter.ts @@ -1,4 +1,4 @@ -export const withRNVBabel = (cnf) => { +export const withRNVBabel = (cnf: any) => { const plugins = cnf?.plugins || []; return { retainLines: true, diff --git a/packages/engine-rn-electron/src/index.ts b/packages/engine-rn-electron/src/index.ts index cd0317d3da..95c3404ec7 100644 --- a/packages/engine-rn-electron/src/index.ts +++ b/packages/engine-rn-electron/src/index.ts @@ -1,4 +1,5 @@ -import { Config, EngineManager } from 'rnv'; +import { Config, EngineManager, RnvContext, RnvEngine } from 'rnv'; +//@ts-ignore import CNF from '../renative.engine.json'; import taskRnvBuild from './tasks/task.rnv.build'; import taskRnvConfigure from './tasks/task.rnv.configure'; @@ -12,8 +13,8 @@ import { withRNVBabel } from './adapter'; const { generateEngineTasks, generateEngineExtensions } = EngineManager; -export default { - initializeRuntimeConfig: (c) => Config.initializeConfig(c), +const Engine: RnvEngine = { + initializeRuntimeConfig: (c: RnvContext) => Config.initializeConfig(c), tasks: generateEngineTasks([ taskRnvRun, taskRnvPackage, @@ -27,7 +28,8 @@ export default { config: CNF, projectDirName: '', serverDirName: '', - ejectPlatform: null, + // ejectPlatform: null, + runtimeExtraProps: {}, platforms: { macos: { defaultPort: 8086, @@ -57,3 +59,5 @@ export default { }; export { withRNVBabel }; + +export default Engine; diff --git a/packages/engine-rn-electron/src/sdks/sdk-electron/index.ts b/packages/engine-rn-electron/src/sdks/sdk-electron/index.ts index 67974685f5..0da432ae7f 100644 --- a/packages/engine-rn-electron/src/sdks/sdk-electron/index.ts +++ b/packages/engine-rn-electron/src/sdks/sdk-electron/index.ts @@ -11,6 +11,7 @@ import { PlatformManager, ProjectManager, Resolver, + RnvContext, } from 'rnv'; const { getEngineRunnerByPlatform } = EngineManager; @@ -38,7 +39,7 @@ const { chalk, logTask, logError, logWarning, logSuccess, logInfo } = Logger; const { copyBuildsFolder, copyAssetsFolder } = ProjectManager; const { MACOS, LINUX } = Constants; -export const configureElectronProject = async (c, exitOnFail) => { +export const configureElectronProject = async (c: RnvContext, exitOnFail?: boolean) => { logTask('configureElectronProject'); const { platform } = c; @@ -52,7 +53,7 @@ export const configureElectronProject = async (c, exitOnFail) => { await copyAssetsFolder( c, platform, - null, + undefined, (platform === MACOS || platform === LINUX) && fsExistsSync(iconsetPath) ? _generateICNS : null ); @@ -63,8 +64,8 @@ export const configureElectronProject = async (c, exitOnFail) => { }; const merge = require('deepmerge'); -const configureProject = (c, exitOnFail) => - new Promise((resolve, reject) => { +const configureProject = (c: RnvContext, exitOnFail) => + new Promise((resolve, reject) => { logTask('configureProject'); const { platform } = c; @@ -194,7 +195,7 @@ const configureProject = (c, exitOnFail) => path.join(platformProjectDir, 'main.dev.js'), path.join(platformProjectDir, 'main.js'), injects, - null, + undefined, c ); } @@ -237,7 +238,7 @@ const configureProject = (c, exitOnFail) => resolve(); }); -const buildElectron = async (c) => { +const buildElectron = async (c: RnvContext) => { logTask('buildElectron'); await buildCoreWebpackProject(c); @@ -263,7 +264,7 @@ const buildElectron = async (c) => { return true; }; -const exportElectron = async (c) => { +const exportElectron = async (c: RnvContext) => { logTask('exportElectron'); const platformBuildDir = getPlatformBuildDir(c); @@ -355,8 +356,8 @@ const _runElectronSimulator = async (c) => { child.unref(); }; -const _generateICNS = (c) => - new Promise((resolve, reject) => { +const _generateICNS = (c: RnvContext) => + new Promise((resolve, reject) => { logTask('_generateICNS'); const { platform } = c; diff --git a/packages/engine-rn-electron/src/tasks/task.rnv.build.ts b/packages/engine-rn-electron/src/tasks/task.rnv.build.ts index 0c4a6a0920..d1db0c2eeb 100644 --- a/packages/engine-rn-electron/src/tasks/task.rnv.build.ts +++ b/packages/engine-rn-electron/src/tasks/task.rnv.build.ts @@ -1,4 +1,4 @@ -import { Constants, Logger, PlatformManager, TaskManager } from 'rnv'; +import { Constants, Logger, PlatformManager, RnvTaskFn, TaskManager } from 'rnv'; import { SDKElectron } from '../sdks'; const { logTask } = Logger; @@ -7,7 +7,7 @@ const { logErrorPlatform } = PlatformManager; const { buildElectron } = SDKElectron; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvBuild = async (c, parentTask, originTask) => { +export const taskRnvBuild: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvBuild', `parent:${parentTask}`); const { platform } = c; diff --git a/packages/engine-rn-electron/src/tasks/task.rnv.configure.ts b/packages/engine-rn-electron/src/tasks/task.rnv.configure.ts index db361ba07c..7e889c81ee 100644 --- a/packages/engine-rn-electron/src/tasks/task.rnv.configure.ts +++ b/packages/engine-rn-electron/src/tasks/task.rnv.configure.ts @@ -1,4 +1,4 @@ -import { Constants, Logger, PlatformManager, TaskManager, TemplateManager } from 'rnv'; +import { Constants, Logger, PlatformManager, RnvTaskFn, TaskManager, TemplateManager } from 'rnv'; import { SDKElectron } from '../sdks'; const { logErrorPlatform, copySharedPlatforms } = PlatformManager; @@ -8,7 +8,7 @@ const { configureElectronProject } = SDKElectron; const { executeTask, shouldSkipTask } = TaskManager; const { configureEntryPoint } = TemplateManager; -export const taskRnvConfigure = async (c, parentTask, originTask) => { +export const taskRnvConfigure: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvConfigure'); await executeTask(c, TASK_PLATFORM_CONFIGURE, TASK_CONFIGURE, originTask); diff --git a/packages/engine-rn-electron/src/tasks/task.rnv.debug.ts b/packages/engine-rn-electron/src/tasks/task.rnv.debug.ts index 4675f4dbdd..9a1ba6d013 100644 --- a/packages/engine-rn-electron/src/tasks/task.rnv.debug.ts +++ b/packages/engine-rn-electron/src/tasks/task.rnv.debug.ts @@ -1,10 +1,10 @@ -import { Constants, Logger, PlatformManager } from 'rnv'; +import { Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; const { logErrorPlatform } = PlatformManager; const { logTask } = Logger; const { MACOS, WINDOWS, LINUX, PARAMS } = Constants; -export const taskRnvDebug = async (c) => { +export const taskRnvDebug: RnvTaskFn = async (c) => { logTask('taskRnvDebug'); const { platform } = c; diff --git a/packages/engine-rn-electron/src/tasks/task.rnv.deploy.ts b/packages/engine-rn-electron/src/tasks/task.rnv.deploy.ts index 773248630f..68ff972b9b 100644 --- a/packages/engine-rn-electron/src/tasks/task.rnv.deploy.ts +++ b/packages/engine-rn-electron/src/tasks/task.rnv.deploy.ts @@ -1,10 +1,10 @@ -import { Constants, Logger, TaskManager } from 'rnv'; +import { Constants, Logger, RnvTaskFn, TaskManager } from 'rnv'; const { logTask } = Logger; const { MACOS, WINDOWS, LINUX, TASK_EXPORT, TASK_DEPLOY, PARAMS } = Constants; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvDeploy = async (c, parentTask, originTask) => { +export const taskRnvDeploy: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvDeploy', `parent:${parentTask}`); await executeOrSkipTask(c, TASK_EXPORT, TASK_DEPLOY, originTask); diff --git a/packages/engine-rn-electron/src/tasks/task.rnv.export.ts b/packages/engine-rn-electron/src/tasks/task.rnv.export.ts index c2693e3b91..7010c58afa 100644 --- a/packages/engine-rn-electron/src/tasks/task.rnv.export.ts +++ b/packages/engine-rn-electron/src/tasks/task.rnv.export.ts @@ -1,4 +1,4 @@ -import { Constants, Logger, PlatformManager, TaskManager } from 'rnv'; +import { Constants, Logger, PlatformManager, RnvTaskFn, TaskManager } from 'rnv'; import { SDKElectron } from '../sdks'; const { logErrorPlatform } = PlatformManager; @@ -7,7 +7,7 @@ const { MACOS, WINDOWS, LINUX, TASK_BUILD, TASK_EXPORT, PARAMS } = Constants; const { exportElectron } = SDKElectron; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvExport = async (c, parentTask, originTask) => { +export const taskRnvExport: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvExport', `parent:${parentTask}`); const { platform } = c; diff --git a/packages/engine-rn-electron/src/tasks/task.rnv.package.ts b/packages/engine-rn-electron/src/tasks/task.rnv.package.ts index fc7edd0250..623f6ef551 100644 --- a/packages/engine-rn-electron/src/tasks/task.rnv.package.ts +++ b/packages/engine-rn-electron/src/tasks/task.rnv.package.ts @@ -1,10 +1,10 @@ -import { Constants, Logger, TaskManager } from 'rnv'; +import { Constants, Logger, RnvTaskFn, TaskManager } from 'rnv'; const { logTask } = Logger; const { MACOS, WINDOWS, LINUX, TASK_PACKAGE, TASK_CONFIGURE, PARAMS } = Constants; const { executeOrSkipTask } = TaskManager; -export const taskRnvPackage = async (c, parentTask, originTask) => { +export const taskRnvPackage: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvPackage', `parent:${parentTask}`); await executeOrSkipTask(c, TASK_CONFIGURE, TASK_PACKAGE, originTask); diff --git a/packages/engine-rn-electron/src/tasks/task.rnv.run.ts b/packages/engine-rn-electron/src/tasks/task.rnv.run.ts index f08f8222fd..ce9086dd77 100644 --- a/packages/engine-rn-electron/src/tasks/task.rnv.run.ts +++ b/packages/engine-rn-electron/src/tasks/task.rnv.run.ts @@ -1,4 +1,4 @@ -import { Constants, Logger, PlatformManager, TaskManager } from 'rnv'; +import { Constants, Logger, PlatformManager, RnvTaskFn, TaskManager } from 'rnv'; import { SDKElectron } from '../sdks'; const { logErrorPlatform } = PlatformManager; @@ -7,7 +7,7 @@ const { MACOS, WINDOWS, LINUX, TASK_RUN, TASK_CONFIGURE, PARAMS } = Constants; const { runElectron } = SDKElectron; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvRun = async (c, parentTask, originTask) => { +export const taskRnvRun: RnvTaskFn = async (c, parentTask, originTask) => { const { platform } = c; const { port } = c.runtime; const { target } = c.runtime; diff --git a/packages/engine-rn-electron/src/tasks/task.rnv.start.ts b/packages/engine-rn-electron/src/tasks/task.rnv.start.ts index c5774cd00b..0b8f7ea810 100644 --- a/packages/engine-rn-electron/src/tasks/task.rnv.start.ts +++ b/packages/engine-rn-electron/src/tasks/task.rnv.start.ts @@ -1,6 +1,6 @@ import { runWebpackServer } from '@rnv/sdk-webpack'; import open from 'better-opn'; -import { Common, Constants, Logger, PlatformManager, TaskManager } from 'rnv'; +import { Common, Constants, Logger, PlatformManager, RnvTaskFn, TaskManager } from 'rnv'; const { logErrorPlatform } = PlatformManager; const { logTask, logError } = Logger; @@ -9,7 +9,7 @@ const { waitForHost } = Common; const { executeTask, shouldSkipTask } = TaskManager; -export const taskRnvStart = async (c, parentTask, originTask) => { +export const taskRnvStart: RnvTaskFn = async (c, parentTask, originTask) => { const { platform } = c; const { port } = c.runtime; const { hosted } = c.program; diff --git a/packages/rnv/src/core/context/types.ts b/packages/rnv/src/core/context/types.ts index 17d2da47fe..e1fa623035 100644 --- a/packages/rnv/src/core/context/types.ts +++ b/packages/rnv/src/core/context/types.ts @@ -88,6 +88,7 @@ export interface RnvContext { _skipNativeDepResolutions: boolean; targetUDID?: string; forceBundleAssets?: boolean; + webpackTarget?: string; xcodeProj?: { id?: string; runScheme?: string; From d800276c86b2f70a6a423051b2e584b418d3f91a Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 00:55:16 +0200 Subject: [PATCH 58/83] refactored sdk webpack --- .../src/sdks/sdk-electron/index.ts | 6 +- packages/rnv/src/core/common.ts | 4 +- packages/rnv/src/core/context/types.ts | 5 +- packages/rnv/src/core/pluginManager/index.ts | 7 ++- packages/rnv/src/core/types.ts | 1 + .../sdk-webpack/src/{index.js => index.ts} | 55 +++++++++++-------- packages/sdk-webpack/types.d.ts | 3 +- 7 files changed, 46 insertions(+), 35 deletions(-) rename packages/sdk-webpack/src/{index.js => index.ts} (88%) diff --git a/packages/engine-rn-electron/src/sdks/sdk-electron/index.ts b/packages/engine-rn-electron/src/sdks/sdk-electron/index.ts index 0da432ae7f..c0761cc416 100644 --- a/packages/engine-rn-electron/src/sdks/sdk-electron/index.ts +++ b/packages/engine-rn-electron/src/sdks/sdk-electron/index.ts @@ -342,7 +342,7 @@ const _runElectronSimulator = async (c) => { let platformProjectDir = getPlatformProjectDir(c); if (bundleAssets) { - platformProjectDir = path.join(getPlatformBuildDir(c), 'build'); + platformProjectDir = path.join(getPlatformBuildDir(c)!, 'build'); } const child = spawn('node', [elc, path.join(platformProjectDir, '/main.js')], { @@ -374,7 +374,7 @@ const _generateICNS = (c: RnvContext) => source = path.join(c.paths.appConfig.dir, `assets/${platform}/AppIcon.iconset`); } - const dest = path.join(getPlatformProjectDir(c), 'resources/icon.icns'); + const dest = path.join(getPlatformProjectDir(c)!, 'resources/icon.icns'); // It's ok if icns are not generated as png is also valid https://www.electron.build/icons.html#macos if (!source) { @@ -393,7 +393,7 @@ const _generateICNS = (c: RnvContext) => return; } - mkdirSync(path.join(getPlatformProjectDir(c), 'resources')); + mkdirSync(path.join(getPlatformProjectDir(c)!, 'resources')); const p = ['--convert', 'icns', source, '--output', dest]; try { diff --git a/packages/rnv/src/core/common.ts b/packages/rnv/src/core/common.ts index 97ddc055b8..3636cdc876 100755 --- a/packages/rnv/src/core/common.ts +++ b/packages/rnv/src/core/common.ts @@ -162,7 +162,7 @@ export const confirmActiveBundler = async (c: RnvContext) => { if (c.program.ci) { //TODO: handle return codes properly - await killPort(parseInt(c.runtime.port)); + await killPort(c.runtime.port); return true; } @@ -176,7 +176,7 @@ export const confirmActiveBundler = async (c: RnvContext) => { }); if (choices[0] === selectedOption) { - await killPort(parseInt(c.runtime.port)); + await killPort(c.runtime.port); } else { return false; } diff --git a/packages/rnv/src/core/context/types.ts b/packages/rnv/src/core/context/types.ts index e1fa623035..cc8f0d295e 100644 --- a/packages/rnv/src/core/context/types.ts +++ b/packages/rnv/src/core/context/types.ts @@ -57,7 +57,7 @@ export interface RnvContext { isTargetTrue: boolean; supportedPlatforms: Array; keepSessionActive: boolean; - platformBuildsProjectPath: string; + platformBuildsProjectPath?: string; availablePlatforms: Array; _platformBuildsSuffix?: string; timestamp: number; @@ -72,7 +72,7 @@ export interface RnvContext { forceBuildHookRebuild: boolean; disableReset: boolean; skipActiveServerCheck: boolean; - port: string; + port: number; rnvVersionRunner: string; rnvVersionProject: string; versionCheckCompleted: boolean; @@ -89,6 +89,7 @@ export interface RnvContext { targetUDID?: string; forceBundleAssets?: boolean; webpackTarget?: string; + shouldOpenBrowser?: string; xcodeProj?: { id?: string; runScheme?: string; diff --git a/packages/rnv/src/core/pluginManager/index.ts b/packages/rnv/src/core/pluginManager/index.ts index b1938a8327..a016acad60 100644 --- a/packages/rnv/src/core/pluginManager/index.ts +++ b/packages/rnv/src/core/pluginManager/index.ts @@ -30,6 +30,7 @@ import { RnvPluginWebpackKey, } from './types'; import { RenativeConfigPlugin, RenativeWebpackConfig } from '../configManager/types'; +import { RnvModuleConfig } from '../types'; export const getPluginList = (c: RnvContext, isUpdate = false) => { const output: PluginListResponse = { @@ -968,8 +969,8 @@ export const getLocalRenativePlugin = () => ({ }, }); -export const getModuleConfigs = (c: RnvContext, primaryKey?: RnvPluginWebpackKey) => { - let modulePaths: Array = []; +export const getModuleConfigs = (c: RnvContext, primaryKey?: RnvPluginWebpackKey): RnvModuleConfig => { + let modulePaths: Array = []; const moduleAliases: Record = {}; const doNotResolveModulePaths: Array = []; @@ -1035,7 +1036,7 @@ export const getModuleConfigs = (c: RnvContext, primaryKey?: RnvPluginWebpackKey }); modulePaths = modulePaths - .map((v) => v && doResolvePath(v, true, {}, c.paths.project.dir)) + .map((v) => v && doResolvePath(v, true, {}, c.paths.project.dir)!) .concat(doNotResolveModulePaths) .concat([c.paths.project.assets.dir]) .filter(Boolean); diff --git a/packages/rnv/src/core/types.ts b/packages/rnv/src/core/types.ts index 14e1631d86..97135db606 100644 --- a/packages/rnv/src/core/types.ts +++ b/packages/rnv/src/core/types.ts @@ -4,6 +4,7 @@ export type RnvPlatform = string; export type RnvModuleConfig = { modulePaths: Array; + moduleAliases: Record; moduleAliasesArray: Array; }; diff --git a/packages/sdk-webpack/src/index.js b/packages/sdk-webpack/src/index.ts similarity index 88% rename from packages/sdk-webpack/src/index.js rename to packages/sdk-webpack/src/index.ts index 0206aa29b2..a675095a91 100644 --- a/packages/sdk-webpack/src/index.js +++ b/packages/sdk-webpack/src/index.ts @@ -14,6 +14,7 @@ import { PluginManager, ProjectManager, FileUtils, + RnvContext, } from 'rnv'; // import { fsExistsSync, fsWriteFileSync } from 'rnv/dist/core/systemManager/fileutils'; // import { runServer } from './scripts/start'; @@ -29,7 +30,7 @@ const { REMOTE_DEBUG_PORT } = Constants; const { executeAsync } = Exec; const { copyFileSync, fsExistsSync } = FileUtils; -export const waitForUrl = (url) => +export const waitForUrl = (url: string) => new Promise((resolve, reject) => { let attempts = 0; const maxAttempts = 10; @@ -51,8 +52,14 @@ export const waitForUrl = (url) => }, CHECK_INTEVAL); }); -const _runWebBrowser = (c, platform, devServerHost, port, alreadyStarted) => - new Promise((resolve) => { +const _runWebBrowser = ( + c: RnvContext, + platform: string, + devServerHost: string, + port: number, + alreadyStarted: boolean +) => + new Promise((resolve) => { logTask('_runWebBrowser', `ip:${devServerHost} port:${port} openBrowser:${!!c.runtime.shouldOpenBrowser}`); if (!c.runtime.shouldOpenBrowser) return resolve(); const wait = waitForHost(c, '') @@ -66,7 +73,7 @@ const _runWebBrowser = (c, platform, devServerHost, port, alreadyStarted) => return resolve(); }); -const _runRemoteDebuggerChii = async (c, obj) => { +const _runRemoteDebuggerChii = async (c: RnvContext, obj: any) => { const { debugIp } = c.program; try { await commandExists('chii'); @@ -87,7 +94,7 @@ const _runRemoteDebuggerChii = async (c, obj) => { Debugger running at: ${debugUrl}`); open(`http://${resolvedDebugIp}:${REMOTE_DEBUG_PORT}/`); - } catch (e) { + } catch (e: any) { logError(e); } obj.remoteDebuggerActive = true; @@ -103,7 +110,7 @@ Debugger running at: ${debugUrl}`); return true; }; -const _runRemoteDebuggerWeinre = async (c, obj) => { +const _runRemoteDebuggerWeinre = async (c: RnvContext, obj: any) => { const { debugIp } = c.program; try { await commandExists('weinre'); @@ -124,7 +131,7 @@ const _runRemoteDebuggerWeinre = async (c, obj) => { Debugger running at: ${debugUrl}`); open(`http://${resolvedDebugIp}:${REMOTE_DEBUG_PORT}/client/#${c.platform}`); - } catch (e) { + } catch (e: any) { logError(e); } obj.remoteDebuggerActive = true; @@ -138,10 +145,10 @@ Debugger running at: ${debugUrl}`); return true; }; -export const _runWebDevServer = async (c, enableRemoteDebugger) => { +export const _runWebDevServer = async (c: RnvContext, enableRemoteDebugger?: boolean) => { logTask('_runWebDevServer'); const { debug } = c.program; - const env = { ...generateEnvVars(c, getModuleConfigs(c)) }; + const env: Record = { ...generateEnvVars(c, getModuleConfigs(c)) }; Object.keys(env).forEach((v) => { process.env[v] = env[v]; }); @@ -154,14 +161,14 @@ export const _runWebDevServer = async (c, enableRemoteDebugger) => { reactDevUtilsPath ); } - } catch (e) { + } catch (e: any) { // Do nothing logError(e); } process.env.PUBLIC_URL = getConfigProp(c, c.platform, 'publicUrl', '.'); process.env.RNV_ENTRY_FILE = getConfigProp(c, c.platform, 'entryFile'); - process.env.PORT = c.runtime.port; + process.env.PORT = String(c.runtime.port); if (c.runtime.webpackTarget) { process.env.WEBPACK_TARGET = c.runtime.webpackTarget; } @@ -181,17 +188,17 @@ export const _runWebDevServer = async (c, enableRemoteDebugger) => { await start(); }; -export const buildCoreWebpackProject = async (c) => { +export const buildCoreWebpackProject = async (c: RnvContext) => { const { debug, debugIp } = c.program; logTask('buildCoreWebpackProject'); - const env = { ...generateEnvVars(c, getModuleConfigs(c)) }; + const env: Record = { ...generateEnvVars(c, getModuleConfigs(c)) }; Object.keys(env).forEach((v) => { process.env[v] = env[v]; }); process.env.PUBLIC_URL = getConfigProp(c, c.platform, 'publicUrl', '.'); process.env.RNV_ENTRY_FILE = getConfigProp(c, c.platform, 'entryFile'); - process.env.PORT = c.runtime.port; + process.env.PORT = String(c.runtime.port); if (c.runtime.webpackTarget) { process.env.WEBPACK_TARGET = c.runtime.webpackTarget; } @@ -214,7 +221,7 @@ export const configureCoreWebProject = async () => { logTask('configureCoreWebProject'); }; -export const runWebpackServer = async (c, enableRemoteDebugger) => { +export const runWebpackServer = async (c: RnvContext, enableRemoteDebugger?: boolean) => { const { port } = c.runtime; const { platform } = c; logTask('runWeb', `port:${port} debugger:${!!enableRemoteDebugger}`); @@ -258,7 +265,7 @@ export const runWebpackServer = async (c, enableRemoteDebugger) => { } }; -export const waitForWebpack = async (c, suffix = 'assets/bundle.js') => { +export const waitForWebpack = async (c: RnvContext, suffix = 'assets/bundle.js') => { logTask('waitForWebpack', `port:${c.runtime.port}`); let attempts = 0; const maxAttempts = 10; @@ -297,41 +304,41 @@ export const waitForWebpack = async (c, suffix = 'assets/bundle.js') => { }); }; -export const buildWeb = async (c) => buildCoreWebpackProject(c); +export const buildWeb = async (c: RnvContext) => buildCoreWebpackProject(c); -export const configureWebProject = async (c) => { +export const configureWebProject = async (c: RnvContext) => { logTask('configureWebProject'); const { platform } = c; - c.runtime.platformBuildsProjectPath = getPlatformProjectDir(c); + c.runtime.platformBuildsProjectPath = getPlatformProjectDir(c) || undefined; if (!isPlatformActive(c, platform)) return; await copyAssetsFolder(c, platform); - await configureCoreWebProject(c); + await configureCoreWebProject(); return copyBuildsFolder(c, platform); }; // CHROMECAST -export const configureChromecastProject = async (c) => { +export const configureChromecastProject = async (c: RnvContext) => { logTask(`configureChromecastProject:${c.platform}`); c.runtime.platformBuildsProjectPath = `${getPlatformProjectDir(c)}`; await copyAssetsFolder(c, c.platform); - await configureCoreWebProject(c); + await configureCoreWebProject(); await _configureProject(c); return copyBuildsFolder(c, c.platform); }; -const _configureProject = async (c) => { +const _configureProject = async (c: RnvContext) => { logTask(`_configureProject:${c.platform}`); }; -export const runChromecast = async (c) => { +export const runChromecast = async (c: RnvContext) => { logTask(`runChromecast:${c.platform}`); await runWebpackServer(c); }; diff --git a/packages/sdk-webpack/types.d.ts b/packages/sdk-webpack/types.d.ts index 01310624e5..b7ecf05402 100644 --- a/packages/sdk-webpack/types.d.ts +++ b/packages/sdk-webpack/types.d.ts @@ -1,3 +1,4 @@ -declare module 'rnv'; declare module 'inquirer'; declare module 'shelljs'; +declare module 'command-exists' +declare module 'better-opn' \ No newline at end of file From 6f3f404a7ea6a1f64cc88038dd368938f7a02164 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 01:17:12 +0200 Subject: [PATCH 59/83] ts fixes --- .../src/sdks/sdk-electron/index.ts | 74 +++++++++---------- packages/engine-rn-electron/tsconfig.json | 3 +- packages/engine-rn-electron/types.d.ts | 1 + packages/rnv/src/core/runtimeManager/index.ts | 2 +- packages/rnv/src/core/systemManager/logger.ts | 2 +- packages/sdk-webpack/tsconfig.json | 2 +- 6 files changed, 43 insertions(+), 41 deletions(-) create mode 100644 packages/engine-rn-electron/types.d.ts diff --git a/packages/engine-rn-electron/src/sdks/sdk-electron/index.ts b/packages/engine-rn-electron/src/sdks/sdk-electron/index.ts index c0761cc416..09d446f6b3 100644 --- a/packages/engine-rn-electron/src/sdks/sdk-electron/index.ts +++ b/packages/engine-rn-electron/src/sdks/sdk-electron/index.ts @@ -54,17 +54,17 @@ export const configureElectronProject = async (c: RnvContext, exitOnFail?: boole c, platform, undefined, - (platform === MACOS || platform === LINUX) && fsExistsSync(iconsetPath) ? _generateICNS : null + (platform === MACOS || platform === LINUX) && fsExistsSync(iconsetPath) ? _generateICNS : undefined ); - await configureCoreWebProject(c); + await configureCoreWebProject(); await configureProject(c, exitOnFail); return copyBuildsFolder(c, platform); }; const merge = require('deepmerge'); -const configureProject = (c: RnvContext, exitOnFail) => +const configureProject = (c: RnvContext, exitOnFail?: boolean) => new Promise((resolve, reject) => { logTask('configureProject'); const { platform } = c; @@ -75,8 +75,8 @@ const configureProject = (c: RnvContext, exitOnFail) => const engine = getEngineRunnerByPlatform(c, c.platform); const platformBuildDir = getPlatformBuildDir(c); const bundleAssets = getConfigProp(c, platform, 'bundleAssets') === true; - const electronConfigPath = path.join(platformBuildDir, 'electronConfig.json'); - const packagePath = path.join(platformBuildDir, 'package.json'); + const electronConfigPath = path.join(platformBuildDir!, 'electronConfig.json'); + const packagePath = path.join(platformBuildDir!, 'package.json'); // If path does not exist for png, try iconset const pngIconPath = path.join(c.paths.appConfig.dir, `assets/${platform}/resources/icon.png`); const appId = getAppId(c, platform); @@ -86,14 +86,14 @@ const configureProject = (c: RnvContext, exitOnFail) => logWarning(`Your ${chalk().white(platform)} platformBuild is misconfigured!. let's repair it.`); createPlatformBuild(c, platform) .then(() => configureElectronProject(c, true)) - .then(() => resolve(c)) + .then(() => resolve()) .catch((e) => reject(e)); return; } reject(`${packagePath} does not exist!`); return; } - const pkgJson = path.join(engine.originalTemplatePlatformsDir, platform, 'package.json'); + const pkgJson = path.join(engine.originalTemplatePlatformsDir!, platform, 'package.json'); const packageJson = readObjectSync(pkgJson); packageJson.name = `${c.runtime.appId}-${platform}`; @@ -124,8 +124,8 @@ const configureProject = (c: RnvContext, exitOnFail) => webPreferences: { nodeIntegration: true, enableRemoteModule: true, contextIsolation: false }, icon: (platform === MACOS || platform === LINUX) && !fsExistsSync(pngIconPath) - ? path.join(platformProjectDir, 'resources', 'icon.icns') - : path.join(platformProjectDir, 'resources', 'icon.png'), + ? path.join(platformProjectDir!, 'resources', 'icon.icns') + : path.join(platformProjectDir!, 'resources', 'icon.png'), }; const browserWindowExt = getConfigProp(c, platform, 'BrowserWindow'); if (browserWindowExt) { @@ -159,10 +159,10 @@ const configureProject = (c: RnvContext, exitOnFail) => addSystemInjects(c, injects); writeCleanFile( - path.join(platformProjectDir, 'main.prod.js'), - path.join(platformProjectDir, 'main.js'), + path.join(platformProjectDir!, 'main.prod.js'), + path.join(platformProjectDir!, 'main.js'), injects, - null, + undefined, c ); } else { @@ -192,25 +192,25 @@ const configureProject = (c: RnvContext, exitOnFail) => addSystemInjects(c, injects); writeCleanFile( - path.join(platformProjectDir, 'main.dev.js'), - path.join(platformProjectDir, 'main.js'), + path.join(platformProjectDir!, 'main.dev.js'), + path.join(platformProjectDir!, 'main.js'), injects, undefined, c ); } - const macConfig = {}; + const macConfig: any = {}; if (platform === MACOS) { macConfig.mac = { - entitlements: path.join(platformProjectDir, 'entitlements.mac.plist'), - entitlementsInherit: path.join(platformProjectDir, 'entitlements.mac.plist'), + entitlements: path.join(platformProjectDir!, 'entitlements.mac.plist'), + entitlementsInherit: path.join(platformProjectDir!, 'entitlements.mac.plist'), hardenedRuntime: true, }; macConfig.mas = { - entitlements: path.join(platformProjectDir, 'entitlements.mas.plist'), - entitlementsInherit: path.join(platformProjectDir, 'entitlements.mas.inherit.plist'), - provisioningProfile: path.join(platformProjectDir, 'embedded.provisionprofile'), + entitlements: path.join(platformProjectDir!, 'entitlements.mas.plist'), + entitlementsInherit: path.join(platformProjectDir!, 'entitlements.mas.inherit.plist'), + provisioningProfile: path.join(platformProjectDir!, 'embedded.provisionprofile'), hardenedRuntime: false, }; } @@ -219,9 +219,9 @@ const configureProject = (c: RnvContext, exitOnFail) => { appId, directories: { - app: path.join(platformBuildDir, 'build'), - buildResources: path.join(platformProjectDir, 'resources'), - output: path.join(platformBuildDir, 'export'), + app: path.join(platformBuildDir!, 'build'), + buildResources: path.join(platformProjectDir!, 'resources'), + output: path.join(platformBuildDir!, 'export'), }, files: ['!export/*'], }, @@ -247,18 +247,18 @@ const buildElectron = async (c: RnvContext) => { const platformBuildDir = getPlatformBuildDir(c); // workaround: electron-builder fails export in npx mode due to trying install node_modules. we trick it not to do that - mkdirSync(path.join(platformBuildDir, 'build', 'node_modules')); + mkdirSync(path.join(platformBuildDir!, 'build', 'node_modules')); - const packagePathSrc = path.join(platformBuildDir, 'package.json'); - const packagePathDest = path.join(platformBuildDir, 'build', 'package.json'); + const packagePathSrc = path.join(platformBuildDir!, 'package.json'); + const packagePathDest = path.join(platformBuildDir!, 'build', 'package.json'); copyFileSync(packagePathSrc, packagePathDest); - const mainPathSrc = path.join(platformBuildDir, 'main.js'); - const mainPathDest = path.join(platformBuildDir, 'build', 'main.js'); + const mainPathSrc = path.join(platformBuildDir!, 'main.js'); + const mainPathDest = path.join(platformBuildDir!, 'build', 'main.js'); copyFileSync(mainPathSrc, mainPathDest); - const menuPathSrc = path.join(platformBuildDir, 'contextMenu.js'); - const menuPathDest = path.join(platformBuildDir, 'build', 'contextMenu.js'); + const menuPathSrc = path.join(platformBuildDir!, 'contextMenu.js'); + const menuPathDest = path.join(platformBuildDir!, 'build', 'contextMenu.js'); copyFileSync(menuPathSrc, menuPathDest); return true; @@ -268,7 +268,7 @@ const exportElectron = async (c: RnvContext) => { logTask('exportElectron'); const platformBuildDir = getPlatformBuildDir(c); - const buildPath = path.join(platformBuildDir, 'build', 'release'); + const buildPath = path.join(platformBuildDir!, 'build', 'release'); if (fsExistsSync(buildPath)) { logInfo(`exportElectron: removing old build ${buildPath}`); @@ -288,13 +288,13 @@ const exportElectron = async (c: RnvContext) => { } await executeAsync( c, - `${electronBuilderPath} --config ${path.join(platformBuildDir, 'electronConfig.json')} --${c.platform}` + `${electronBuilderPath} --config ${path.join(platformBuildDir!, 'electronConfig.json')} --${c.platform}` ); - logSuccess(`Your Exported App is located in ${chalk().cyan(path.join(platformBuildDir, 'export'))} .`); + logSuccess(`Your Exported App is located in ${chalk().cyan(path.join(platformBuildDir!, 'export'))} .`); }; -export const runElectron = async (c) => { +export const runElectron = async (c: RnvContext) => { logTask('runElectron'); const { platform } = c; @@ -334,7 +334,7 @@ export const runElectron = async (c) => { } }; -const _runElectronSimulator = async (c) => { +const _runElectronSimulator = async (c: RnvContext) => { logTask(`_runElectronSimulator:${c.platform}`); // const appFolder = getAppFolder(c, c.platform); const elc = `${doResolve('electron')}/cli.js`; @@ -345,12 +345,12 @@ const _runElectronSimulator = async (c) => { platformProjectDir = path.join(getPlatformBuildDir(c)!, 'build'); } - const child = spawn('node', [elc, path.join(platformProjectDir, '/main.js')], { + const child = spawn('node', [elc, path.join(platformProjectDir!, '/main.js')], { detached: true, env: process.env, stdio: 'inherit', }) - .on('close', (code) => process.exit(code)) + .on('close', (code) => process.exit(code || undefined)) .on('error', (spawnError) => logError(spawnError)); child.unref(); diff --git a/packages/engine-rn-electron/tsconfig.json b/packages/engine-rn-electron/tsconfig.json index 47fc361091..cf64fd612c 100644 --- a/packages/engine-rn-electron/tsconfig.json +++ b/packages/engine-rn-electron/tsconfig.json @@ -5,5 +5,6 @@ "rootDir": "./src", "resolveJsonModule": false }, - "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"] + "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"], + "exclude": ["node_modules", "./src/__tests__", "./dist/**/*"] } diff --git a/packages/engine-rn-electron/types.d.ts b/packages/engine-rn-electron/types.d.ts new file mode 100644 index 0000000000..ab1fc354c1 --- /dev/null +++ b/packages/engine-rn-electron/types.d.ts @@ -0,0 +1 @@ +declare module 'better-opn' \ No newline at end of file diff --git a/packages/rnv/src/core/runtimeManager/index.ts b/packages/rnv/src/core/runtimeManager/index.ts index 2284f13e24..bc24922146 100644 --- a/packages/rnv/src/core/runtimeManager/index.ts +++ b/packages/rnv/src/core/runtimeManager/index.ts @@ -32,7 +32,7 @@ export const configureRuntimeDefaults = async (c: RnvContext) => { const portOffset = c.buildConfig?.defaults?.portOffset || 0; - c.runtime.port = (Number(portString) + portOffset).toString(); + c.runtime.port = Number(portString) + portOffset; if (c.program.target !== true) { c.runtime.target = c.program.target || c.buildConfig?.defaultTargets?.[c.platform]; diff --git a/packages/rnv/src/core/systemManager/logger.ts b/packages/rnv/src/core/systemManager/logger.ts index 8206c8c7a9..d3f5ba8733 100644 --- a/packages/rnv/src/core/systemManager/logger.ts +++ b/packages/rnv/src/core/systemManager/logger.ts @@ -252,7 +252,7 @@ export const logSummary = (header = 'SUMMARY') => { str += printIntoBox(''); if (cnf().runtime?.platformBuildsProjectPath) { str += printIntoBox('Project location:'); - str += printIntoBox(`${currentChalk.cyan(_sanitizePaths(cnf().runtime.platformBuildsProjectPath))}`); + str += printIntoBox(`${currentChalk.cyan(_sanitizePaths(cnf().runtime.platformBuildsProjectPath || ''))}`); } str += printBoxEnd(); diff --git a/packages/sdk-webpack/tsconfig.json b/packages/sdk-webpack/tsconfig.json index 9d2faec89d..76ccfdb45b 100644 --- a/packages/sdk-webpack/tsconfig.json +++ b/packages/sdk-webpack/tsconfig.json @@ -7,5 +7,5 @@ "resolveJsonModule": false }, "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"], - "exclude": ["node_modules", "./src/__tests__"] + "exclude": ["node_modules", "./src/__tests__", "./dist/**/*"] } From 76257784a484e644179aa5e30e55493650cb9f2b Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 01:18:55 +0200 Subject: [PATCH 60/83] convert js to ts engine-tvos --- packages/engine-rn-tvos/src/{adapter.js => adapter.ts} | 0 packages/engine-rn-tvos/src/{commonEngine.js => commonEngine.ts} | 0 packages/engine-rn-tvos/src/{index.js => index.ts} | 0 .../src/tasks/{task.rnv.build.js => task.rnv.build.ts} | 0 .../src/tasks/{task.rnv.configure.js => task.rnv.configure.ts} | 0 ...rnv.crypto.installCerts.js => task.rnv.crypto.installCerts.ts} | 0 ...ypto.installProfiles.js => task.rnv.crypto.installProfiles.ts} | 0 ...v.crypto.updateProfile.js => task.rnv.crypto.updateProfile.ts} | 0 ...crypto.updateProfiles.js => task.rnv.crypto.updateProfiles.ts} | 0 .../src/tasks/{task.rnv.debug.js => task.rnv.debug.ts} | 0 .../src/tasks/{task.rnv.deploy.js => task.rnv.deploy.ts} | 0 .../src/tasks/{task.rnv.export.js => task.rnv.export.ts} | 0 .../engine-rn-tvos/src/tasks/{task.rnv.log.js => task.rnv.log.ts} | 0 .../src/tasks/{task.rnv.package.js => task.rnv.package.ts} | 0 .../engine-rn-tvos/src/tasks/{task.rnv.run.js => task.rnv.run.ts} | 0 .../src/tasks/{task.rnv.start.js => task.rnv.start.ts} | 0 16 files changed, 0 insertions(+), 0 deletions(-) rename packages/engine-rn-tvos/src/{adapter.js => adapter.ts} (100%) rename packages/engine-rn-tvos/src/{commonEngine.js => commonEngine.ts} (100%) rename packages/engine-rn-tvos/src/{index.js => index.ts} (100%) rename packages/engine-rn-tvos/src/tasks/{task.rnv.build.js => task.rnv.build.ts} (100%) rename packages/engine-rn-tvos/src/tasks/{task.rnv.configure.js => task.rnv.configure.ts} (100%) rename packages/engine-rn-tvos/src/tasks/{task.rnv.crypto.installCerts.js => task.rnv.crypto.installCerts.ts} (100%) rename packages/engine-rn-tvos/src/tasks/{task.rnv.crypto.installProfiles.js => task.rnv.crypto.installProfiles.ts} (100%) rename packages/engine-rn-tvos/src/tasks/{task.rnv.crypto.updateProfile.js => task.rnv.crypto.updateProfile.ts} (100%) rename packages/engine-rn-tvos/src/tasks/{task.rnv.crypto.updateProfiles.js => task.rnv.crypto.updateProfiles.ts} (100%) rename packages/engine-rn-tvos/src/tasks/{task.rnv.debug.js => task.rnv.debug.ts} (100%) rename packages/engine-rn-tvos/src/tasks/{task.rnv.deploy.js => task.rnv.deploy.ts} (100%) rename packages/engine-rn-tvos/src/tasks/{task.rnv.export.js => task.rnv.export.ts} (100%) rename packages/engine-rn-tvos/src/tasks/{task.rnv.log.js => task.rnv.log.ts} (100%) rename packages/engine-rn-tvos/src/tasks/{task.rnv.package.js => task.rnv.package.ts} (100%) rename packages/engine-rn-tvos/src/tasks/{task.rnv.run.js => task.rnv.run.ts} (100%) rename packages/engine-rn-tvos/src/tasks/{task.rnv.start.js => task.rnv.start.ts} (100%) diff --git a/packages/engine-rn-tvos/src/adapter.js b/packages/engine-rn-tvos/src/adapter.ts similarity index 100% rename from packages/engine-rn-tvos/src/adapter.js rename to packages/engine-rn-tvos/src/adapter.ts diff --git a/packages/engine-rn-tvos/src/commonEngine.js b/packages/engine-rn-tvos/src/commonEngine.ts similarity index 100% rename from packages/engine-rn-tvos/src/commonEngine.js rename to packages/engine-rn-tvos/src/commonEngine.ts diff --git a/packages/engine-rn-tvos/src/index.js b/packages/engine-rn-tvos/src/index.ts similarity index 100% rename from packages/engine-rn-tvos/src/index.js rename to packages/engine-rn-tvos/src/index.ts diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.build.js b/packages/engine-rn-tvos/src/tasks/task.rnv.build.ts similarity index 100% rename from packages/engine-rn-tvos/src/tasks/task.rnv.build.js rename to packages/engine-rn-tvos/src/tasks/task.rnv.build.ts diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.configure.js b/packages/engine-rn-tvos/src/tasks/task.rnv.configure.ts similarity index 100% rename from packages/engine-rn-tvos/src/tasks/task.rnv.configure.js rename to packages/engine-rn-tvos/src/tasks/task.rnv.configure.ts diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.crypto.installCerts.js b/packages/engine-rn-tvos/src/tasks/task.rnv.crypto.installCerts.ts similarity index 100% rename from packages/engine-rn-tvos/src/tasks/task.rnv.crypto.installCerts.js rename to packages/engine-rn-tvos/src/tasks/task.rnv.crypto.installCerts.ts diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.crypto.installProfiles.js b/packages/engine-rn-tvos/src/tasks/task.rnv.crypto.installProfiles.ts similarity index 100% rename from packages/engine-rn-tvos/src/tasks/task.rnv.crypto.installProfiles.js rename to packages/engine-rn-tvos/src/tasks/task.rnv.crypto.installProfiles.ts diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.crypto.updateProfile.js b/packages/engine-rn-tvos/src/tasks/task.rnv.crypto.updateProfile.ts similarity index 100% rename from packages/engine-rn-tvos/src/tasks/task.rnv.crypto.updateProfile.js rename to packages/engine-rn-tvos/src/tasks/task.rnv.crypto.updateProfile.ts diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.crypto.updateProfiles.js b/packages/engine-rn-tvos/src/tasks/task.rnv.crypto.updateProfiles.ts similarity index 100% rename from packages/engine-rn-tvos/src/tasks/task.rnv.crypto.updateProfiles.js rename to packages/engine-rn-tvos/src/tasks/task.rnv.crypto.updateProfiles.ts diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.debug.js b/packages/engine-rn-tvos/src/tasks/task.rnv.debug.ts similarity index 100% rename from packages/engine-rn-tvos/src/tasks/task.rnv.debug.js rename to packages/engine-rn-tvos/src/tasks/task.rnv.debug.ts diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.deploy.js b/packages/engine-rn-tvos/src/tasks/task.rnv.deploy.ts similarity index 100% rename from packages/engine-rn-tvos/src/tasks/task.rnv.deploy.js rename to packages/engine-rn-tvos/src/tasks/task.rnv.deploy.ts diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.export.js b/packages/engine-rn-tvos/src/tasks/task.rnv.export.ts similarity index 100% rename from packages/engine-rn-tvos/src/tasks/task.rnv.export.js rename to packages/engine-rn-tvos/src/tasks/task.rnv.export.ts diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.log.js b/packages/engine-rn-tvos/src/tasks/task.rnv.log.ts similarity index 100% rename from packages/engine-rn-tvos/src/tasks/task.rnv.log.js rename to packages/engine-rn-tvos/src/tasks/task.rnv.log.ts diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.package.js b/packages/engine-rn-tvos/src/tasks/task.rnv.package.ts similarity index 100% rename from packages/engine-rn-tvos/src/tasks/task.rnv.package.js rename to packages/engine-rn-tvos/src/tasks/task.rnv.package.ts diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.run.js b/packages/engine-rn-tvos/src/tasks/task.rnv.run.ts similarity index 100% rename from packages/engine-rn-tvos/src/tasks/task.rnv.run.js rename to packages/engine-rn-tvos/src/tasks/task.rnv.run.ts diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.start.js b/packages/engine-rn-tvos/src/tasks/task.rnv.start.ts similarity index 100% rename from packages/engine-rn-tvos/src/tasks/task.rnv.start.js rename to packages/engine-rn-tvos/src/tasks/task.rnv.start.ts From e4af178624f54cc52a964dca6579a5cc177a0545 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 01:32:18 +0200 Subject: [PATCH 61/83] refactor engine tvos --- packages/engine-rn-tvos/src/adapter.ts | 38 +++++++------- packages/engine-rn-tvos/src/commonEngine.ts | 51 +++++++++++++------ packages/engine-rn-tvos/src/index.ts | 10 ++-- .../src/tasks/task.rnv.build.ts | 6 +-- .../src/tasks/task.rnv.configure.ts | 4 +- .../src/tasks/task.rnv.crypto.installCerts.ts | 6 +-- .../tasks/task.rnv.crypto.installProfiles.ts | 6 +-- .../tasks/task.rnv.crypto.updateProfile.ts | 4 +- .../tasks/task.rnv.crypto.updateProfiles.ts | 16 +++--- .../src/tasks/task.rnv.debug.ts | 4 +- .../src/tasks/task.rnv.deploy.ts | 4 +- .../src/tasks/task.rnv.export.ts | 6 +-- .../engine-rn-tvos/src/tasks/task.rnv.log.ts | 4 +- .../src/tasks/task.rnv.package.ts | 4 +- .../engine-rn-tvos/src/tasks/task.rnv.run.ts | 8 +-- .../src/tasks/task.rnv.start.ts | 6 +-- packages/engine-rn/src/index.ts | 4 +- packages/rnv/src/core/engineManager/types.ts | 1 + packages/rnv/src/engine-core/index.ts | 4 +- 19 files changed, 106 insertions(+), 80 deletions(-) diff --git a/packages/engine-rn-tvos/src/adapter.ts b/packages/engine-rn-tvos/src/adapter.ts index 854c247f94..93a7c8ac8d 100644 --- a/packages/engine-rn-tvos/src/adapter.ts +++ b/packages/engine-rn-tvos/src/adapter.ts @@ -13,30 +13,31 @@ const sharedBlacklist = [ /.*\/__tests__\/.*/, ]; -function escapeRegExp(pattern) { - if (Object.prototype.toString.call(pattern) === '[object RegExp]') { - return pattern.source.replace(/\//g, path.sep); - } +const env: any = process?.env; + +function escapeRegExp(pattern: RegExp | string) { if (typeof pattern === 'string') { // eslint-disable-next-line const escaped = pattern.replace(/[\-\[\]\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'); // convert the '/' into an escaped local file separator return escaped.replace(/\//g, `\\${path.sep}`); + } else if (Object.prototype.toString.call(pattern) === '[object RegExp]') { + return pattern.source.replace(/\//g, path.sep); } throw new Error(`Unexpected blacklist pattern: ${pattern}`); } -function blacklist(additionalBlacklist) { +function blacklist(additionalBlacklist: RegExp[]) { return new RegExp(`(${(additionalBlacklist || []).concat(sharedBlacklist).map(escapeRegExp).join('|')})$`); } -export const withRNVMetro = (config) => { - const projectPath = process.env.RNV_PROJECT_ROOT || process.cwd(); +export const withRNVMetro = (config: any) => { + const projectPath = env.RNV_PROJECT_ROOT || process.cwd(); const watchFolders = [path.resolve(projectPath, 'node_modules')]; - if (process.env.RNV_IS_MONOREPO === 'true' || process.env.RNV_IS_MONOREPO === true) { - const monoRootPath = process.env.RNV_MONO_ROOT || projectPath; + if (env.RNV_IS_MONOREPO === 'true' || env.RNV_IS_MONOREPO === true) { + const monoRootPath = env.RNV_MONO_ROOT || projectPath; watchFolders.push(path.resolve(monoRootPath, 'node_modules')); watchFolders.push(path.resolve(monoRootPath, 'packages')); } @@ -44,7 +45,7 @@ export const withRNVMetro = (config) => { watchFolders.push(...config.watchFolders); } - const exts = process.env.RNV_EXTENSIONS || []; + const exts: string = env.RNV_EXTENSIONS || ''; const cnf = { ...config, @@ -56,6 +57,7 @@ export const withRNVMetro = (config) => { transformer: { getTransformOptions: async () => ({ transform: { + experimentalImportSupport: false, // this defeats the RCTDeviceEventEmitter is not a registered callable module inlineRequires: true, }, @@ -86,20 +88,19 @@ export const withRNVMetro = (config) => { return cnf; }; -export const createEngineAlias = (customAlias) => { - const projectPath = process.env.RNV_PROJECT_ROOT || process.cwd(); - const isMonorepo = process.env.RNV_IS_MONOREPO === 'true' || process.env.RNV_IS_MONOREPO === true; - const rootPath = isMonorepo ? process.env.RNV_MONO_ROOT || projectPath : projectPath; +export const createEngineAlias = (customAlias: any) => { + const projectPath = env.RNV_PROJECT_ROOT || process.cwd(); + const isMonorepo = env.RNV_IS_MONOREPO === 'true' || env.RNV_IS_MONOREPO === true; + const rootPath = isMonorepo ? env.RNV_MONO_ROOT || projectPath : projectPath; const alias = customAlias ? { ...customAlias } : {}; - if (process.env.RNV_IS_NATIVE_TV === 'true' || process.env.RNV_IS_NATIVE_TV === true) { + if (env.RNV_IS_NATIVE_TV === 'true' || env.RNV_IS_NATIVE_TV === true) { alias['react-native'] = `${rootPath}/node_modules/react-native-tvos`; } return alias; }; - -export const withRNVBabel = (cnf) => { +export const withRNVBabel = (cnf: any) => { const plugins = cnf?.plugins || []; return { @@ -110,8 +111,7 @@ export const withRNVBabel = (cnf) => { [ require.resolve('babel-plugin-module-resolver'), { - root: [process.env.RNV_MONO_ROOT || '.'], - alias: createEngineAlias({}), + root: [env.RNV_MONO_ROOT || '.'], }, ], ...plugins, diff --git a/packages/engine-rn-tvos/src/commonEngine.ts b/packages/engine-rn-tvos/src/commonEngine.ts index 18d6cf46aa..f7fe283700 100644 --- a/packages/engine-rn-tvos/src/commonEngine.ts +++ b/packages/engine-rn-tvos/src/commonEngine.ts @@ -1,7 +1,8 @@ import path from 'path'; import axios from 'axios'; -import { TaskManager, Constants, Logger, Common, FileUtils, Spinner } from 'rnv'; +import { TaskManager, Constants, Logger, Common, FileUtils, Prompt, Spinner, RnvContext } from 'rnv'; +const { inquirerPrompt } = Prompt; const { getConfigProp, confirmActiveBundler } = Common; const { chalk, logTask, logInfo, logWarning } = Logger; const { fsExistsSync, copyFileSync } = FileUtils; @@ -10,7 +11,7 @@ const { executeTask } = TaskManager; let keepRNVRunning = false; -export const startBundlerIfRequired = async (c, parentTask, originTask) => { +export const startBundlerIfRequired = async (c: RnvContext, parentTask: string, originTask?: string) => { logTask('startBundlerIfRequired'); const bundleAssets = getConfigProp(c, c.platform, 'bundleAssets'); if (bundleAssets === true) return; @@ -33,7 +34,7 @@ export const startBundlerIfRequired = async (c, parentTask, originTask) => { } }; -export const waitForBundlerIfRequired = async (c) => { +export const waitForBundlerIfRequired = async (c: RnvContext) => { const bundleAssets = getConfigProp(c, c.platform, 'bundleAssets'); if (bundleAssets === true) return; // return a new promise that does...nothing, just to keep RNV running while the bundler is running @@ -44,12 +45,32 @@ export const waitForBundlerIfRequired = async (c) => { return true; }; -export const configureMetroConfigs = async (c) => { +export const configureMetroConfigs = async (c: RnvContext) => { logTask('configureMetroConfigs'); - const cfPath = path.join(c.paths.project.dir, 'configs', `metro.config.${c.platform}.js`); + const metroSnippet = ` +const { withRNVMetro } = require('rnv'); +module.exports = withRNVMetro({}); +`; + + let cfPath = path.join(c.paths.project.dir, 'configs', `metro.config.${c.platform}.js`); + if (!fsExistsSync(cfPath)) { + cfPath = path.join(c.paths.project.dir, `metro.config.${c.platform}.js`); + } if (fsExistsSync(cfPath)) { - logWarning(`${chalk().white(cfPath)} is DEPRECATED. use withRNVMetro(config) directly in /.metro.config.js`); + logWarning(`${chalk().white(cfPath)} is DEPRECATED. You can add following snippet: +${chalk().white(metroSnippet)} +to your ${chalk().white('/.metro.config.js')} instead and delete deprecated file +`); + const confirm = await inquirerPrompt({ + name: 'selectedScheme', + type: 'confirm', + message: 'Are you sure you want to continue?', + }); + + if (!confirm) { + return Promise.reject('Cancelled by user'); + } } // Check rn-cli-config @@ -59,7 +80,7 @@ export const configureMetroConfigs = async (c) => { } }; -const _isBundlerRunning = async (c) => { +const _isBundlerRunning = async (c: RnvContext) => { logTask('_isBundlerRunning'); try { const { data } = await axios.get( @@ -77,7 +98,7 @@ const _isBundlerRunning = async (c) => { } }; -export const isBundlerActive = async (c) => { +export const isBundlerActive = async (c: RnvContext) => { logTask('isBundlerActive', `(http://${c.runtime.localhost}:${c.runtime.port})`); try { await axios.get(`http://${c.runtime.localhost}:${c.runtime.port}`); @@ -87,15 +108,15 @@ export const isBundlerActive = async (c) => { } }; -const poll = (fn, timeout = 10000, interval = 1000) => { +const poll = (fn: () => Promise, timeout = 10000, interval = 1000) => { const endTime = Number(new Date()) + timeout; - const spinner = Spinner('Waiting for bundler to finish...').start(); - const checkCondition = async (resolve, reject) => { + const spinner = Spinner('Waiting for bundler to finish...').start(''); + const checkCondition = async (resolve: () => void, reject: (e: string) => void) => { try { const result = await fn(); if (result) { - spinner.succeed(); + spinner.succeed(''); resolve(); } else if (Number(new Date()) < endTime) { setTimeout(checkCondition, interval, resolve, reject); @@ -103,13 +124,13 @@ const poll = (fn, timeout = 10000, interval = 1000) => { spinner.fail("Can't connect to bundler. Try restarting it."); reject("Can't connect to bundler. Try restarting it."); } - } catch (e) { + } catch (e: any) { spinner.fail("Can't connect to bundler. Try restarting it."); reject(e); } }; - return new Promise(checkCondition); + return new Promise(checkCondition); }; -export const waitForBundler = async (c) => poll(() => _isBundlerRunning(c)); +export const waitForBundler = async (c: RnvContext) => poll(() => _isBundlerRunning(c)); diff --git a/packages/engine-rn-tvos/src/index.ts b/packages/engine-rn-tvos/src/index.ts index fedded12bb..a62a61924b 100644 --- a/packages/engine-rn-tvos/src/index.ts +++ b/packages/engine-rn-tvos/src/index.ts @@ -1,4 +1,4 @@ -import { EngineManager, Config } from 'rnv'; +import { EngineManager, Config, RnvEngine } from 'rnv'; import taskRnvRun from './tasks/task.rnv.run'; import taskRnvPackage from './tasks/task.rnv.package'; import taskRnvBuild from './tasks/task.rnv.build'; @@ -12,12 +12,13 @@ import taskRnvCryptoUpdateProfile from './tasks/task.rnv.crypto.updateProfile'; import taskRnvCryptoUpdateProfiles from './tasks/task.rnv.crypto.updateProfiles'; import taskRnvCryptoInstallProfiles from './tasks/task.rnv.crypto.installProfiles'; import taskRnvLog from './tasks/task.rnv.log'; +//@ts-ignore import CNF from '../renative.engine.json'; import { createEngineAlias, withRNVMetro, withRNVBabel } from './adapter'; const { generateEngineTasks, generateEngineExtensions } = EngineManager; -export default { +const Engine: RnvEngine = { initializeRuntimeConfig: (c) => Config.initializeConfig(c), tasks: generateEngineTasks([ taskRnvRun, @@ -42,7 +43,8 @@ export default { xcodeProjectName: 'RNVAppTVOS', }, projectDirName: '', - ejectPlatform: null, + serverDirName: '', + // ejectPlatform: null, platforms: { tvos: { defaultPort: 8089, @@ -68,3 +70,5 @@ export default { const withRNV = withRNVMetro; export { withRNVMetro, withRNV, withRNVBabel }; + +export default Engine; diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.build.ts b/packages/engine-rn-tvos/src/tasks/task.rnv.build.ts index 872dac4d28..17b045299b 100644 --- a/packages/engine-rn-tvos/src/tasks/task.rnv.build.ts +++ b/packages/engine-rn-tvos/src/tasks/task.rnv.build.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; import { buildAndroid } from '@rnv/sdk-android'; import { buildXcodeProject } from '@rnv/sdk-apple'; @@ -8,7 +8,7 @@ const { TVOS, ANDROID_TV, FIRE_TV, TASK_BUILD, TASK_PACKAGE, TASK_EXPORT, PARAMS const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvBuild = async (c, parentTask, originTask) => { +export const taskRnvBuild: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvBuild'); const { platform } = c; @@ -25,7 +25,7 @@ export const taskRnvBuild = async (c, parentTask, originTask) => { // build task is not necessary when exporting ios return true; } - return buildXcodeProject(c, platform); + return buildXcodeProject(c); default: return logErrorPlatform(c); } diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.configure.ts b/packages/engine-rn-tvos/src/tasks/task.rnv.configure.ts index 19f0ec19ef..ab5ffa3893 100644 --- a/packages/engine-rn-tvos/src/tasks/task.rnv.configure.ts +++ b/packages/engine-rn-tvos/src/tasks/task.rnv.configure.ts @@ -1,4 +1,4 @@ -import { Constants, Logger, PlatformManager, TaskManager, NPMUtils, TemplateManager } from 'rnv'; +import { Constants, Logger, PlatformManager, TaskManager, NPMUtils, TemplateManager, RnvTaskFn } from 'rnv'; import { configureGradleProject } from '@rnv/sdk-android'; import { configureXcodeProject } from '@rnv/sdk-apple'; import { configureMetroConfigs } from '../commonEngine'; @@ -12,7 +12,7 @@ const { TVOS, ANDROID_TV, FIRE_TV, TASK_PLATFORM_CONFIGURE, TASK_CONFIGURE, PARA const { executeTask, shouldSkipTask } = TaskManager; const { configureEntryPoint } = TemplateManager; -export const taskRnvConfigure = async (c, parentTask, originTask) => { +export const taskRnvConfigure: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvConfigure'); await configureMetroConfigs(c); diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.crypto.installCerts.ts b/packages/engine-rn-tvos/src/tasks/task.rnv.crypto.installCerts.ts index b1669d07a0..6f9bc5b45c 100644 --- a/packages/engine-rn-tvos/src/tasks/task.rnv.crypto.installCerts.ts +++ b/packages/engine-rn-tvos/src/tasks/task.rnv.crypto.installCerts.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, Exec, FileUtils } from 'rnv'; +import { TaskManager, Constants, Logger, Exec, FileUtils, RnvTaskFn } from 'rnv'; const { logWarning, logError, logTask } = Logger; const { getFileListSync } = FileUtils; @@ -6,7 +6,7 @@ const { executeAsync } = Exec; const { executeTask, shouldSkipTask } = TaskManager; const { TASK_CRYPTO_INSTALL_CERTS, TASK_PROJECT_CONFIGURE, PARAMS } = Constants; -export const taskRnvCryptoInstallCerts = async (c, parentTask, originTask) => { +export const taskRnvCryptoInstallCerts: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvCryptoInstallCerts'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_CRYPTO_INSTALL_CERTS, originTask); @@ -24,7 +24,7 @@ export const taskRnvCryptoInstallCerts = async (c, parentTask, originTask) => { try { Promise.all(cerArr.map((v) => executeAsync(c, `security import ${v} -k ${kChain} -A`))); - } catch (e) { + } catch (e: any) { logWarning(e); return true; } diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.crypto.installProfiles.ts b/packages/engine-rn-tvos/src/tasks/task.rnv.crypto.installProfiles.ts index de6c521fca..056eba6b20 100644 --- a/packages/engine-rn-tvos/src/tasks/task.rnv.crypto.installProfiles.ts +++ b/packages/engine-rn-tvos/src/tasks/task.rnv.crypto.installProfiles.ts @@ -1,12 +1,12 @@ import path from 'path'; -import { TaskManager, Constants, Logger, FileUtils } from 'rnv'; +import { TaskManager, Constants, Logger, FileUtils, RnvTaskFn } from 'rnv'; const { logWarning, logError, logTask, logDebug } = Logger; const { getFileListSync, copyFileSync, mkdirSync, fsExistsSync } = FileUtils; const { executeTask, shouldSkipTask } = TaskManager; const { TASK_CRYPTO_INSTALL_PROFILES, TASK_PROJECT_CONFIGURE, PARAMS } = Constants; -export const taskRnvCryptoInstallProfiles = async (c, parentTask, originTask) => { +export const taskRnvCryptoInstallProfiles: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvCryptoInstallProfiles'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_CRYPTO_INSTALL_PROFILES, originTask); @@ -33,7 +33,7 @@ export const taskRnvCryptoInstallProfiles = async (c, parentTask, originTask) => logDebug(`taskRnvCryptoInstallProfiles: Installing: ${v}`); copyFileSync(v, ppFolder); }); - } catch (e) { + } catch (e: any) { logError(e); } diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.crypto.updateProfile.ts b/packages/engine-rn-tvos/src/tasks/task.rnv.crypto.updateProfile.ts index 50471f430b..0f792b8c1b 100644 --- a/packages/engine-rn-tvos/src/tasks/task.rnv.crypto.updateProfile.ts +++ b/packages/engine-rn-tvos/src/tasks/task.rnv.crypto.updateProfile.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger } from 'rnv'; +import { TaskManager, Constants, Logger, RnvTaskFn } from 'rnv'; import { updateProfile } from '@rnv/sdk-apple'; @@ -6,7 +6,7 @@ const { executeTask, shouldSkipTask } = TaskManager; const { logTask } = Logger; const { TASK_CRYPTO_UPDATE_PROFILE, TASK_PROJECT_CONFIGURE, TVOS, PARAMS } = Constants; -export const taskRnvCryptoUpdateProfile = async (c, parentTask, originTask) => { +export const taskRnvCryptoUpdateProfile: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvCryptoUpdateProfile'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_CRYPTO_UPDATE_PROFILE, originTask); diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.crypto.updateProfiles.ts b/packages/engine-rn-tvos/src/tasks/task.rnv.crypto.updateProfiles.ts index 288ca5df38..0cfddd741b 100644 --- a/packages/engine-rn-tvos/src/tasks/task.rnv.crypto.updateProfiles.ts +++ b/packages/engine-rn-tvos/src/tasks/task.rnv.crypto.updateProfiles.ts @@ -1,28 +1,28 @@ -import { TaskManager, Constants, Logger, ConfigManager } from 'rnv'; +import { TaskManager, Constants, Logger, ConfigManager, RnvTaskFn, RnvContext, TVOS } from 'rnv'; import { updateProfile } from '@rnv/sdk-apple'; const { listAppConfigsFoldersSync } = ConfigManager; const { chalk, logTask } = Logger; -const { TVOS, TASK_CRYPTO_UPDATE_PROFILES, TASK_PROJECT_CONFIGURE, PARAMS } = Constants; +const { TASK_CRYPTO_UPDATE_PROFILES, TASK_PROJECT_CONFIGURE, PARAMS } = Constants; const { executeTask, shouldSkipTask } = TaskManager; -const _updateProfile = (c, v) => - new Promise((resolve, reject) => { +const _updateProfile = (c: RnvContext, v: string) => + new Promise((resolve, reject) => { logTask(`_updateProfile:${v}`, chalk().grey); - updateProfile(c, v) + updateProfile(c) .then(() => resolve()) - .catch((e) => reject(e)); + .catch((e: any) => reject(e)); }); -const _updateProfiles = (c) => { +const _updateProfiles = (c: RnvContext) => { logTask('_updateProfiles', chalk().grey); const acList = listAppConfigsFoldersSync(c, true); return acList.reduce((previousPromise, v) => previousPromise.then(() => _updateProfile(c, v)), Promise.resolve()); }; -export const taskRnvCryptoUpdateProfiles = async (c, parentTask, originTask) => { +export const taskRnvCryptoUpdateProfiles: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvCryptoUpdateProfiles'); await executeTask(c, TASK_PROJECT_CONFIGURE, TASK_CRYPTO_UPDATE_PROFILES, originTask); diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.debug.ts b/packages/engine-rn-tvos/src/tasks/task.rnv.debug.ts index 3aeea71d31..27c6809ee6 100644 --- a/packages/engine-rn-tvos/src/tasks/task.rnv.debug.ts +++ b/packages/engine-rn-tvos/src/tasks/task.rnv.debug.ts @@ -1,10 +1,10 @@ -import { Constants, Logger, PlatformManager } from 'rnv'; +import { Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; const { logErrorPlatform } = PlatformManager; const { logTask } = Logger; const { PARAMS } = Constants; -export const taskRnvDebug = async (c, parentTask) => { +export const taskRnvDebug: RnvTaskFn = async (c, parentTask) => { logTask('taskRnvDebug', `parent:${parentTask}`); const { platform } = c; diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.deploy.ts b/packages/engine-rn-tvos/src/tasks/task.rnv.deploy.ts index 14be257fc9..09988512c1 100644 --- a/packages/engine-rn-tvos/src/tasks/task.rnv.deploy.ts +++ b/packages/engine-rn-tvos/src/tasks/task.rnv.deploy.ts @@ -1,10 +1,10 @@ -import { TaskManager, Constants, Logger } from 'rnv'; +import { TaskManager, Constants, Logger, RnvTaskFn } from 'rnv'; const { logTask } = Logger; const { TASK_EXPORT, TASK_DEPLOY, ANDROID_TV, FIRE_TV, TVOS, PARAMS } = Constants; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvDeploy = async (c, parentTask, originTask) => { +export const taskRnvDeploy: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvDeploy', `parent:${parentTask}`); await executeOrSkipTask(c, TASK_EXPORT, TASK_DEPLOY, originTask); diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.export.ts b/packages/engine-rn-tvos/src/tasks/task.rnv.export.ts index fa02b08974..63ab342872 100644 --- a/packages/engine-rn-tvos/src/tasks/task.rnv.export.ts +++ b/packages/engine-rn-tvos/src/tasks/task.rnv.export.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; import { exportXcodeProject } from '@rnv/sdk-apple'; const { logErrorPlatform } = PlatformManager; @@ -7,7 +7,7 @@ const { TVOS, ANDROID_TV, FIRE_TV, TASK_BUILD, TASK_EXPORT, PARAMS } = Constants const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvExport = async (c, parentTask, originTask) => { +export const taskRnvExport: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvExport', `parent:${parentTask}`); const { platform } = c; @@ -21,7 +21,7 @@ export const taskRnvExport = async (c, parentTask, originTask) => { // Android Platforms don't need extra export step return true; case TVOS: - return exportXcodeProject(c, platform); + return exportXcodeProject(c); default: return logErrorPlatform(c); } diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.log.ts b/packages/engine-rn-tvos/src/tasks/task.rnv.log.ts index 750260371a..2e6230cd6f 100644 --- a/packages/engine-rn-tvos/src/tasks/task.rnv.log.ts +++ b/packages/engine-rn-tvos/src/tasks/task.rnv.log.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager, SDKManager } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, SDKManager, RnvTaskFn } from 'rnv'; import { runAppleLog } from '@rnv/sdk-apple'; import { runAndroidLog } from '@rnv/sdk-android'; @@ -11,7 +11,7 @@ const { logTask } = Logger; const { PARAMS, TVOS, ANDROID_TV, FIRE_TV, TASK_WORKSPACE_CONFIGURE, TASK_PROJECT_CONFIGURE } = Constants; const { executeTask } = TaskManager; -export const taskRnvLog = async (c, parentTask, originTask) => { +export const taskRnvLog: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvLog', `parent:${parentTask}`); await executeTask(c, TASK_WORKSPACE_CONFIGURE, TASK_PROJECT_CONFIGURE, originTask); diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.package.ts b/packages/engine-rn-tvos/src/tasks/task.rnv.package.ts index 98610465e4..17e7de0b2c 100644 --- a/packages/engine-rn-tvos/src/tasks/task.rnv.package.ts +++ b/packages/engine-rn-tvos/src/tasks/task.rnv.package.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager, Common } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, Common, RnvTaskFn } from 'rnv'; import { packageAndroid } from '@rnv/sdk-android'; import { packageBundleForXcode } from '@rnv/sdk-apple'; @@ -9,7 +9,7 @@ const { getConfigProp } = Common; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvPackage = async (c, parentTask, originTask) => { +export const taskRnvPackage: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvPackage', `parent:${parentTask}`); const { platform } = c; diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.run.ts b/packages/engine-rn-tvos/src/tasks/task.rnv.run.ts index e5deef6e6f..2ba0e6fb6a 100644 --- a/packages/engine-rn-tvos/src/tasks/task.rnv.run.ts +++ b/packages/engine-rn-tvos/src/tasks/task.rnv.run.ts @@ -1,4 +1,4 @@ -import { Common, Constants, Logger, PlatformManager, TaskManager } from 'rnv'; +import { Common, Constants, Logger, PlatformManager, RnvTaskFn, TaskManager } from 'rnv'; import { packageAndroid, runAndroid } from '@rnv/sdk-android'; import { runXcodeProject } from '@rnv/sdk-apple'; import { startBundlerIfRequired, waitForBundlerIfRequired } from '../commonEngine'; @@ -10,7 +10,7 @@ const { logTask, logSummary, logRaw } = Logger; const { logErrorPlatform } = PlatformManager; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvRun = async (c, parentTask, originTask) => { +export const taskRnvRun: RnvTaskFn = async (c, parentTask, originTask) => { const { platform } = c; const { port } = c.runtime; const { target } = c.runtime; @@ -31,13 +31,13 @@ export const taskRnvRun = async (c, parentTask, originTask) => { if (bundleAssets) { await packageAndroid(c); } - await runAndroid(c, target); + await runAndroid(c); if (!bundleAssets) { logSummary('BUNDLER STARTED'); } return waitForBundlerIfRequired(c); } - return runAndroid(c, target); + return runAndroid(c); case TVOS: if (!c.program.only) { await startBundlerIfRequired(c, TASK_RUN, originTask); diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.start.ts b/packages/engine-rn-tvos/src/tasks/task.rnv.start.ts index 8767405fc8..1e7bef8c55 100644 --- a/packages/engine-rn-tvos/src/tasks/task.rnv.start.ts +++ b/packages/engine-rn-tvos/src/tasks/task.rnv.start.ts @@ -1,4 +1,4 @@ -import { TaskManager, EngineManager, Constants, Logger, PlatformManager, Exec, Common, Resolver } from 'rnv'; +import { TaskManager, EngineManager, Constants, Logger, PlatformManager, Exec, Common, Resolver, RnvTaskFn } from 'rnv'; import { isBundlerActive } from '../commonEngine'; const { getEntryFile, confirmActiveBundler } = Common; @@ -10,13 +10,13 @@ const { chalk, logTask, logError, logRaw, logInfo } = Logger; const { IOS, TVOS, ANDROID, ANDROID_TV, FIRE_TV, TASK_START, TASK_CONFIGURE_SOFT, PARAMS } = Constants; const { executeAsync } = Exec; -const BUNDLER_PLATFORMS = {}; +const BUNDLER_PLATFORMS: Record = {}; BUNDLER_PLATFORMS[TVOS] = IOS; BUNDLER_PLATFORMS[ANDROID_TV] = ANDROID; BUNDLER_PLATFORMS[FIRE_TV] = ANDROID; -export const taskRnvStart = async (c, parentTask, originTask) => { +export const taskRnvStart: RnvTaskFn = async (c, parentTask, originTask) => { const { platform } = c; const { hosted } = c.program; diff --git a/packages/engine-rn/src/index.ts b/packages/engine-rn/src/index.ts index 4b23df4894..17389f1348 100644 --- a/packages/engine-rn/src/index.ts +++ b/packages/engine-rn/src/index.ts @@ -19,7 +19,7 @@ import taskRnvEject from './tasks/task.rnv.eject'; const { generateEngineTasks, generateEngineExtensions } = EngineManager; -const engine: RnvEngine = { +const Engine: RnvEngine = { initializeRuntimeConfig: (c) => Config.initializeConfig(c), tasks: generateEngineTasks([ taskRnvRun, @@ -90,7 +90,7 @@ const engine: RnvEngine = { }, }; -export default engine; +export default Engine; // Backward compatibility const withRNV = withRNVMetro; diff --git a/packages/rnv/src/core/engineManager/types.ts b/packages/rnv/src/core/engineManager/types.ts index 869623ee62..2215141334 100644 --- a/packages/rnv/src/core/engineManager/types.ts +++ b/packages/rnv/src/core/engineManager/types.ts @@ -13,6 +13,7 @@ export type RnvEngine = { runtimeExtraProps: any; outputDirName?: string; serverDirName: string; + getAliases?: (alias: any) => any; // package: string; // ejectPlatform: null; }; diff --git a/packages/rnv/src/engine-core/index.ts b/packages/rnv/src/engine-core/index.ts index 7c6ce937f4..12d0f75bd6 100644 --- a/packages/rnv/src/engine-core/index.ts +++ b/packages/rnv/src/engine-core/index.ts @@ -43,7 +43,7 @@ import taskRnvLink from './tasks/task.rnv.link'; import taskRnvUnlink from './tasks/task.rnv.unlink'; import { RnvEngine } from '../core/engineManager/types'; -const engine: RnvEngine = { +const Engine: RnvEngine = { initializeRuntimeConfig: () => { //Do nothing }, @@ -104,4 +104,4 @@ const engine: RnvEngine = { platforms: {}, }; -export default engine; +export default Engine; From be38c2043a088ef497d54daa566fa8c1708736dc Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 01:43:08 +0200 Subject: [PATCH 62/83] migrate engine-rn-next to TS --- .../src/{adapter.js => adapter.ts} | 8 ++-- .../engine-rn-next/src/{index.js => index.ts} | 10 ++-- .../src/sdks/{index.js => index.ts} | 0 .../src/sdks/sdk-next/{index.js => index.ts} | 47 +++++++++++++------ .../{task.rnv.build.js => task.rnv.build.ts} | 4 +- ...rnv.configure.js => task.rnv.configure.ts} | 4 +- .../{task.rnv.debug.js => task.rnv.debug.ts} | 4 +- ...{task.rnv.deploy.js => task.rnv.deploy.ts} | 8 ++-- ...{task.rnv.export.js => task.rnv.export.ts} | 4 +- ...ask.rnv.package.js => task.rnv.package.ts} | 4 +- .../{task.rnv.run.js => task.rnv.run.ts} | 6 +-- .../{task.rnv.start.js => task.rnv.start.ts} | 6 +-- packages/engine-rn-next/tsconfig.json | 4 +- packages/engine-rn-next/types.d.ts | 1 + packages/engine-rn-tvos/tsconfig.json | 4 +- packages/rnv/src/core/configManager/types.ts | 1 + packages/rnv/src/core/context/types.ts | 2 +- 17 files changed, 70 insertions(+), 47 deletions(-) rename packages/engine-rn-next/src/{adapter.js => adapter.ts} (95%) rename packages/engine-rn-next/src/{index.js => index.ts} (90%) rename packages/engine-rn-next/src/sdks/{index.js => index.ts} (100%) rename packages/engine-rn-next/src/sdks/sdk-next/{index.js => index.ts} (88%) rename packages/engine-rn-next/src/tasks/{task.rnv.build.js => task.rnv.build.ts} (84%) rename packages/engine-rn-next/src/tasks/{task.rnv.configure.js => task.rnv.configure.ts} (85%) rename packages/engine-rn-next/src/tasks/{task.rnv.debug.js => task.rnv.debug.ts} (78%) rename packages/engine-rn-next/src/tasks/{task.rnv.deploy.js => task.rnv.deploy.ts} (78%) rename packages/engine-rn-next/src/tasks/{task.rnv.export.js => task.rnv.export.ts} (84%) rename packages/engine-rn-next/src/tasks/{task.rnv.package.js => task.rnv.package.ts} (77%) rename packages/engine-rn-next/src/tasks/{task.rnv.run.js => task.rnv.run.ts} (82%) rename packages/engine-rn-next/src/tasks/{task.rnv.start.js => task.rnv.start.ts} (90%) create mode 100644 packages/engine-rn-next/types.d.ts diff --git a/packages/engine-rn-next/src/adapter.js b/packages/engine-rn-next/src/adapter.ts similarity index 95% rename from packages/engine-rn-next/src/adapter.js rename to packages/engine-rn-next/src/adapter.ts index 33e0f9fca3..b7dbcd4f08 100644 --- a/packages/engine-rn-next/src/adapter.js +++ b/packages/engine-rn-next/src/adapter.ts @@ -8,7 +8,7 @@ const nextTranspile = require('next-transpile-modules'); // DEPRECATED // const withCSS = require('@zeit/next-css'); -export const withRNVNext = (config, opts) => { +export const withRNVNext = (config: any, opts: any) => { const cnf = { ...config, images: { @@ -17,7 +17,7 @@ export const withRNVNext = (config, opts) => { }, // webpack5: false, distDir: process.env.NEXT_DIST_DIR, - webpack: (cfg, props) => { + webpack: (cfg: any, props: any) => { const { isServer } = props; const rootPath = process.env.RNV_PROJECT_ROOT || process.cwd(); if (process.env.RNV_EXTENSIONS) { @@ -67,7 +67,7 @@ export const withRNVNext = (config, opts) => { return cfg; }, }; - let transModules = []; + let transModules: string[] = []; // console.log('Transpiled Modules:', process.env.RNV_NEXT_TRANSPILE_MODULES.split(',')); if (process.env.RNV_NEXT_TRANSPILE_MODULES) { transModules = process.env.RNV_NEXT_TRANSPILE_MODULES.split(','); @@ -93,7 +93,7 @@ export const withRNVNext = (config, opts) => { return cnf1; }; -export const withRNVBabel = (cnf) => { +export const withRNVBabel = (cnf: any) => { const plugins = cnf?.plugins || []; return { diff --git a/packages/engine-rn-next/src/index.js b/packages/engine-rn-next/src/index.ts similarity index 90% rename from packages/engine-rn-next/src/index.js rename to packages/engine-rn-next/src/index.ts index 5433009f60..de4cfa4f26 100644 --- a/packages/engine-rn-next/src/index.js +++ b/packages/engine-rn-next/src/index.ts @@ -1,5 +1,6 @@ -import { EngineManager, Config } from 'rnv'; +import { EngineManager, Config, RnvEngine } from 'rnv'; import { withRNVNext, withRNVBabel } from './adapter'; +//@ts-ignore import CNF from '../renative.engine.json'; import taskRnvRun from './tasks/task.rnv.run'; import taskRnvPackage from './tasks/task.rnv.package'; @@ -12,7 +13,7 @@ import taskRnvDebug from './tasks/task.rnv.debug'; const { generateEngineTasks, generateEngineExtensions } = EngineManager; -export default { +const Engine: RnvEngine = { initializeRuntimeConfig: (c) => Config.initializeConfig(c), tasks: generateEngineTasks([ taskRnvRun, @@ -26,7 +27,8 @@ export default { ]), config: CNF, projectDirName: '', - ejectPlatform: null, + runtimeExtraProps: {}, + serverDirName: '', platforms: { web: { defaultPort: 8080, @@ -48,3 +50,5 @@ export default { const withRNV = withRNVNext; export { withRNV, withRNVNext, withRNVBabel }; + +export default Engine; diff --git a/packages/engine-rn-next/src/sdks/index.js b/packages/engine-rn-next/src/sdks/index.ts similarity index 100% rename from packages/engine-rn-next/src/sdks/index.js rename to packages/engine-rn-next/src/sdks/index.ts diff --git a/packages/engine-rn-next/src/sdks/sdk-next/index.js b/packages/engine-rn-next/src/sdks/sdk-next/index.ts similarity index 88% rename from packages/engine-rn-next/src/sdks/sdk-next/index.js rename to packages/engine-rn-next/src/sdks/sdk-next/index.ts index 153adabc4e..8931837a56 100644 --- a/packages/engine-rn-next/src/sdks/sdk-next/index.js +++ b/packages/engine-rn-next/src/sdks/sdk-next/index.ts @@ -1,6 +1,17 @@ import path from 'path'; import open from 'better-opn'; -import { Exec, FileUtils, Common, Logger, Constants, EngineManager, PluginManager, ProjectManager } from 'rnv'; +import { + Exec, + FileUtils, + Common, + Logger, + Constants, + EngineManager, + PluginManager, + ProjectManager, + RnvContext, + RnvPluginPlatform, +} from 'rnv'; const { executeAsync } = Exec; const { checkPortInUse, getConfigProp, confirmActiveBundler, getPlatformBuildDir, getDevServerHost, waitForHost } = @@ -13,7 +24,7 @@ const { copyAssetsFolder } = ProjectManager; const { parsePlugins, getModuleConfigs } = PluginManager; -export const configureNextIfRequired = async (c) => { +export const configureNextIfRequired = async (c: RnvContext) => { logTask('configureNextIfRequired'); c.runtime.platformBuildsProjectPath = `${getPlatformBuildDir(c)}`; const { platformTemplatesDirs, dir } = c.paths.project; @@ -38,11 +49,11 @@ export const configureNextIfRequired = async (c) => { // add config if (!fsExistsSync(configFile)) { - writeCleanFile(path.join(supportFilesDir, NEXT_CONFIG_NAME), configFile, null, null, c); + writeCleanFile(path.join(supportFilesDir, NEXT_CONFIG_NAME), configFile, undefined, undefined, c); } }; -export const runWebNext = async (c) => { +export const runWebNext = async (c: RnvContext) => { const { port } = c.runtime; logTask('runWebNext', `port:${port}`); const { platform } = c; @@ -79,8 +90,14 @@ export const runWebNext = async (c) => { } }; -const _runWebBrowser = (c, platform, devServerHost, port, alreadyStarted) => - new Promise((resolve) => { +const _runWebBrowser = ( + c: RnvContext, + _platform: string, + devServerHost: string, + port: number, + alreadyStarted: boolean +) => + new Promise((resolve) => { logTask('_runWebBrowser', `ip:${devServerHost} port:${port} openBrowser:${!!c.runtime.shouldOpenBrowser}`); if (!c.runtime.shouldOpenBrowser) return resolve(); const wait = waitForHost(c, '') @@ -94,17 +111,17 @@ const _runWebBrowser = (c, platform, devServerHost, port, alreadyStarted) => return resolve(); }); -const getOutputDir = (c) => { +const getOutputDir = (c: RnvContext) => { const distDir = getConfigProp(c, c.platform, 'outputDir'); return distDir || `platformBuilds/${c.runtime.appId}_${c.platform}/.next`; }; -const getExportDir = (c) => { +const getExportDir = (c: RnvContext) => { const outputDir = getConfigProp(c, c.platform, 'exportDir'); - return outputDir || path.join(getPlatformBuildDir(c), 'output'); + return outputDir || path.join(getPlatformBuildDir(c)!, 'output'); }; -const _checkPagesDir = async (c) => { +const _checkPagesDir = async (c: RnvContext) => { const pagesDir = getConfigProp(c, c.platform, 'pagesDir'); const distDir = getOutputDir(c); if (pagesDir) { @@ -131,12 +148,12 @@ Alternatively you can configure custom entry folder via ${c.platform}.pagesDir i return { NEXT_PAGES_DIR: 'src/app', NEXT_DIST_DIR: distDir }; }; -export const getTranspileModules = (c) => { +export const getTranspileModules = (c: RnvContext) => { const transModules = getConfigProp(c, c.platform, 'webpackConfig', {}).nextTranspileModules || []; parsePlugins( c, - c.platform, + c.platform as RnvPluginPlatform, (plugin, pluginPlat, key) => { const webpackConfig = plugin.webpack || plugin.webpackConfig; if (webpackConfig) { @@ -157,7 +174,7 @@ export const getTranspileModules = (c) => { return transModules; }; -export const buildWebNext = async (c) => { +export const buildWebNext = async (c: RnvContext) => { logTask('buildWebNext'); const env = getConfigProp(c, c.platform, 'environment'); @@ -175,7 +192,7 @@ export const buildWebNext = async (c) => { return true; }; -export const runWebDevServer = async (c) => { +export const runWebDevServer = async (c: RnvContext) => { logTask('runWebDevServer'); const env = getConfigProp(c, c.platform, 'environment'); const envExt = await _checkPagesDir(c); @@ -210,7 +227,7 @@ export const deployWebNext = () => { return true; }; -export const exportWebNext = async (c) => { +export const exportWebNext = async (c: RnvContext) => { logTask('exportWebNext'); // const { platform } = c; diff --git a/packages/engine-rn-next/src/tasks/task.rnv.build.js b/packages/engine-rn-next/src/tasks/task.rnv.build.ts similarity index 84% rename from packages/engine-rn-next/src/tasks/task.rnv.build.js rename to packages/engine-rn-next/src/tasks/task.rnv.build.ts index 9e3f08b918..9fd43076ec 100644 --- a/packages/engine-rn-next/src/tasks/task.rnv.build.js +++ b/packages/engine-rn-next/src/tasks/task.rnv.build.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; import { SDKNext } from '../sdks'; const { logErrorPlatform } = PlatformManager; @@ -7,7 +7,7 @@ const { WEB, CHROMECAST, TASK_BUILD, TASK_PACKAGE, PARAMS } = Constants; const { buildWebNext } = SDKNext; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvBuild = async (c, parentTask, originTask) => { +export const taskRnvBuild: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvBuild', `parent:${parentTask}`); const { platform } = c; diff --git a/packages/engine-rn-next/src/tasks/task.rnv.configure.js b/packages/engine-rn-next/src/tasks/task.rnv.configure.ts similarity index 85% rename from packages/engine-rn-next/src/tasks/task.rnv.configure.js rename to packages/engine-rn-next/src/tasks/task.rnv.configure.ts index 8dde7875c7..1b23cfce46 100644 --- a/packages/engine-rn-next/src/tasks/task.rnv.configure.js +++ b/packages/engine-rn-next/src/tasks/task.rnv.configure.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; import { SDKNext } from '../sdks'; const { logErrorPlatform } = PlatformManager; @@ -7,7 +7,7 @@ const { WEB, CHROMECAST, TASK_PLATFORM_CONFIGURE, TASK_CONFIGURE, PARAMS } = Con const { configureNextIfRequired } = SDKNext; const { executeTask, shouldSkipTask } = TaskManager; -export const taskRnvConfigure = async (c, parentTask, originTask) => { +export const taskRnvConfigure: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvConfigure'); await executeTask(c, TASK_PLATFORM_CONFIGURE, TASK_CONFIGURE, originTask); diff --git a/packages/engine-rn-next/src/tasks/task.rnv.debug.js b/packages/engine-rn-next/src/tasks/task.rnv.debug.ts similarity index 78% rename from packages/engine-rn-next/src/tasks/task.rnv.debug.js rename to packages/engine-rn-next/src/tasks/task.rnv.debug.ts index bae95863c7..1a1ca251ba 100644 --- a/packages/engine-rn-next/src/tasks/task.rnv.debug.js +++ b/packages/engine-rn-next/src/tasks/task.rnv.debug.ts @@ -1,10 +1,10 @@ -import { Constants, Logger, PlatformManager } from 'rnv'; +import { Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; const { logErrorPlatform } = PlatformManager; const { logTask } = Logger; const { WEB, CHROMECAST, PARAMS } = Constants; -export const taskRnvDebug = async (c, parentTask) => { +export const taskRnvDebug: RnvTaskFn = async (c, parentTask) => { logTask('taskRnvDebug', `parent:${parentTask}`); const { platform } = c; diff --git a/packages/engine-rn-next/src/tasks/task.rnv.deploy.js b/packages/engine-rn-next/src/tasks/task.rnv.deploy.ts similarity index 78% rename from packages/engine-rn-next/src/tasks/task.rnv.deploy.js rename to packages/engine-rn-next/src/tasks/task.rnv.deploy.ts index 40e4fc29a0..316b2a0325 100644 --- a/packages/engine-rn-next/src/tasks/task.rnv.deploy.js +++ b/packages/engine-rn-next/src/tasks/task.rnv.deploy.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; import { SDKNext } from '../sdks'; const { logErrorPlatform } = PlatformManager; @@ -7,7 +7,7 @@ const { WEB, CHROMECAST, TASK_EXPORT, TASK_DEPLOY, PARAMS } = Constants; const { deployWebNext } = SDKNext; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvDeploy = async (c, parentTask, originTask) => { +export const taskRnvDeploy: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvDeploy', `parent:${parentTask}`); const { platform } = c; @@ -17,9 +17,9 @@ export const taskRnvDeploy = async (c, parentTask, originTask) => { switch (platform) { case WEB: - return deployWebNext(c); + return deployWebNext(); case CHROMECAST: - return deployWebNext(c); + return deployWebNext(); default: logErrorPlatform(c); } diff --git a/packages/engine-rn-next/src/tasks/task.rnv.export.js b/packages/engine-rn-next/src/tasks/task.rnv.export.ts similarity index 84% rename from packages/engine-rn-next/src/tasks/task.rnv.export.js rename to packages/engine-rn-next/src/tasks/task.rnv.export.ts index 70bc4d6be8..5c52041897 100644 --- a/packages/engine-rn-next/src/tasks/task.rnv.export.js +++ b/packages/engine-rn-next/src/tasks/task.rnv.export.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; import { SDKNext } from '../sdks'; const { logErrorPlatform } = PlatformManager; @@ -7,7 +7,7 @@ const { WEB, CHROMECAST, TASK_BUILD, TASK_EXPORT, PARAMS } = Constants; const { exportWebNext } = SDKNext; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvExport = async (c, parentTask, originTask) => { +export const taskRnvExport: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvExport', `parent:${parentTask}`); const { platform } = c; diff --git a/packages/engine-rn-next/src/tasks/task.rnv.package.js b/packages/engine-rn-next/src/tasks/task.rnv.package.ts similarity index 77% rename from packages/engine-rn-next/src/tasks/task.rnv.package.js rename to packages/engine-rn-next/src/tasks/task.rnv.package.ts index 59f33c6d59..cc96fa8290 100644 --- a/packages/engine-rn-next/src/tasks/task.rnv.package.js +++ b/packages/engine-rn-next/src/tasks/task.rnv.package.ts @@ -1,10 +1,10 @@ -import { TaskManager, Constants, Logger } from 'rnv'; +import { TaskManager, Constants, Logger, RnvTaskFn } from 'rnv'; const { logTask } = Logger; const { WEB, CHROMECAST, TASK_PACKAGE, TASK_CONFIGURE, PARAMS } = Constants; const { executeOrSkipTask } = TaskManager; -export const taskRnvPackage = async (c, parentTask, originTask) => { +export const taskRnvPackage: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvPackage', `parent:${parentTask}`); await executeOrSkipTask(c, TASK_CONFIGURE, TASK_PACKAGE, originTask); diff --git a/packages/engine-rn-next/src/tasks/task.rnv.run.js b/packages/engine-rn-next/src/tasks/task.rnv.run.ts similarity index 82% rename from packages/engine-rn-next/src/tasks/task.rnv.run.js rename to packages/engine-rn-next/src/tasks/task.rnv.run.ts index 0a13a28d18..40caad4ff5 100644 --- a/packages/engine-rn-next/src/tasks/task.rnv.run.js +++ b/packages/engine-rn-next/src/tasks/task.rnv.run.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; import { SDKNext } from '../sdks'; const { logErrorPlatform } = PlatformManager; @@ -7,7 +7,7 @@ const { WEB, CHROMECAST, TASK_RUN, TASK_CONFIGURE, PARAMS } = Constants; const { runWebNext } = SDKNext; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvRun = async (c, parentTask, originTask) => { +export const taskRnvRun: RnvTaskFn = async (c, parentTask, originTask) => { const { platform } = c; logTask('taskRnvRun', `parent:${parentTask}`); @@ -19,7 +19,7 @@ export const taskRnvRun = async (c, parentTask, originTask) => { case WEB: case CHROMECAST: c.runtime.shouldOpenBrowser = true; - return runWebNext(c, true); + return runWebNext(c); default: return logErrorPlatform(c); } diff --git a/packages/engine-rn-next/src/tasks/task.rnv.start.js b/packages/engine-rn-next/src/tasks/task.rnv.start.ts similarity index 90% rename from packages/engine-rn-next/src/tasks/task.rnv.start.js rename to packages/engine-rn-next/src/tasks/task.rnv.start.ts index 65d1681801..de3f140cd6 100644 --- a/packages/engine-rn-next/src/tasks/task.rnv.start.js +++ b/packages/engine-rn-next/src/tasks/task.rnv.start.ts @@ -1,5 +1,5 @@ import open from 'better-opn'; -import { TaskManager, Constants, Logger, PlatformManager, Common } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, Common, RnvTaskFn } from 'rnv'; import { SDKNext } from '../sdks'; const { logErrorPlatform } = PlatformManager; @@ -9,7 +9,7 @@ const { runWebNext } = SDKNext; const { executeTask, shouldSkipTask } = TaskManager; const { waitForHost } = Common; -export const taskRnvStart = async (c, parentTask, originTask) => { +export const taskRnvStart: RnvTaskFn = async (c, parentTask, originTask) => { const { platform } = c; const { port } = c.runtime; const { hosted } = c.program; @@ -35,7 +35,7 @@ export const taskRnvStart = async (c, parentTask, originTask) => { case WEB: case CHROMECAST: c.runtime.shouldOpenBrowser = false; - return runWebNext(c, port, true); + return runWebNext(c); default: return logErrorPlatform(c); } diff --git a/packages/engine-rn-next/tsconfig.json b/packages/engine-rn-next/tsconfig.json index eef5815c2f..cf64fd612c 100644 --- a/packages/engine-rn-next/tsconfig.json +++ b/packages/engine-rn-next/tsconfig.json @@ -3,8 +3,8 @@ "compilerOptions": { "outDir": "./dist", "rootDir": "./src", - "allowJs": true, "resolveJsonModule": false }, - "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"] + "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"], + "exclude": ["node_modules", "./src/__tests__", "./dist/**/*"] } diff --git a/packages/engine-rn-next/types.d.ts b/packages/engine-rn-next/types.d.ts new file mode 100644 index 0000000000..ab1fc354c1 --- /dev/null +++ b/packages/engine-rn-next/types.d.ts @@ -0,0 +1 @@ +declare module 'better-opn' \ No newline at end of file diff --git a/packages/engine-rn-tvos/tsconfig.json b/packages/engine-rn-tvos/tsconfig.json index eef5815c2f..cf64fd612c 100644 --- a/packages/engine-rn-tvos/tsconfig.json +++ b/packages/engine-rn-tvos/tsconfig.json @@ -3,8 +3,8 @@ "compilerOptions": { "outDir": "./dist", "rootDir": "./src", - "allowJs": true, "resolveJsonModule": false }, - "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"] + "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"], + "exclude": ["node_modules", "./src/__tests__", "./dist/**/*"] } diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index aed883b0d2..cd08d2818a 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -202,6 +202,7 @@ export type RenativeWebpackConfig = { } > | boolean; + nextTranspileModules?: Array; }; export type RenativeConfigBuildScheme = Record; diff --git a/packages/rnv/src/core/context/types.ts b/packages/rnv/src/core/context/types.ts index cc8f0d295e..19a4c6efa6 100644 --- a/packages/rnv/src/core/context/types.ts +++ b/packages/rnv/src/core/context/types.ts @@ -89,7 +89,7 @@ export interface RnvContext { targetUDID?: string; forceBundleAssets?: boolean; webpackTarget?: string; - shouldOpenBrowser?: string; + shouldOpenBrowser?: boolean; xcodeProj?: { id?: string; runScheme?: string; From b59d9c36a06d0298dcc60f945dbab4c44cf8f758 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 01:45:33 +0200 Subject: [PATCH 63/83] rename js to ts engine-rn-web --- packages/engine-rn-web/src/{adapter.js => adapter.ts} | 0 packages/engine-rn-web/src/{index.js => index.ts} | 0 .../engine-rn-web/src/sdks/sdk-firefox/{index.js => index.ts} | 0 .../engine-rn-web/src/sdks/sdk-tizen/{index.js => index.ts} | 0 .../engine-rn-web/src/sdks/sdk-webos/{index.js => index.ts} | 0 .../src/tasks/{task.rnv.build.js => task.rnv.build.ts} | 0 .../tasks/{task.rnv.configure.js => task.rnv.configure.ts} | 0 .../src/tasks/{task.rnv.debug.js => task.rnv.debug.ts} | 0 .../src/tasks/{task.rnv.deploy.js => task.rnv.deploy.ts} | 0 .../src/tasks/{task.rnv.export.js => task.rnv.export.ts} | 0 .../src/tasks/{task.rnv.package.js => task.rnv.package.ts} | 0 .../src/tasks/{task.rnv.run.js => task.rnv.run.ts} | 0 .../src/tasks/{task.rnv.start.js => task.rnv.start.ts} | 0 packages/engine-rn-web/tsconfig.json | 4 ++-- 14 files changed, 2 insertions(+), 2 deletions(-) rename packages/engine-rn-web/src/{adapter.js => adapter.ts} (100%) rename packages/engine-rn-web/src/{index.js => index.ts} (100%) rename packages/engine-rn-web/src/sdks/sdk-firefox/{index.js => index.ts} (100%) rename packages/engine-rn-web/src/sdks/sdk-tizen/{index.js => index.ts} (100%) rename packages/engine-rn-web/src/sdks/sdk-webos/{index.js => index.ts} (100%) rename packages/engine-rn-web/src/tasks/{task.rnv.build.js => task.rnv.build.ts} (100%) rename packages/engine-rn-web/src/tasks/{task.rnv.configure.js => task.rnv.configure.ts} (100%) rename packages/engine-rn-web/src/tasks/{task.rnv.debug.js => task.rnv.debug.ts} (100%) rename packages/engine-rn-web/src/tasks/{task.rnv.deploy.js => task.rnv.deploy.ts} (100%) rename packages/engine-rn-web/src/tasks/{task.rnv.export.js => task.rnv.export.ts} (100%) rename packages/engine-rn-web/src/tasks/{task.rnv.package.js => task.rnv.package.ts} (100%) rename packages/engine-rn-web/src/tasks/{task.rnv.run.js => task.rnv.run.ts} (100%) rename packages/engine-rn-web/src/tasks/{task.rnv.start.js => task.rnv.start.ts} (100%) diff --git a/packages/engine-rn-web/src/adapter.js b/packages/engine-rn-web/src/adapter.ts similarity index 100% rename from packages/engine-rn-web/src/adapter.js rename to packages/engine-rn-web/src/adapter.ts diff --git a/packages/engine-rn-web/src/index.js b/packages/engine-rn-web/src/index.ts similarity index 100% rename from packages/engine-rn-web/src/index.js rename to packages/engine-rn-web/src/index.ts diff --git a/packages/engine-rn-web/src/sdks/sdk-firefox/index.js b/packages/engine-rn-web/src/sdks/sdk-firefox/index.ts similarity index 100% rename from packages/engine-rn-web/src/sdks/sdk-firefox/index.js rename to packages/engine-rn-web/src/sdks/sdk-firefox/index.ts diff --git a/packages/engine-rn-web/src/sdks/sdk-tizen/index.js b/packages/engine-rn-web/src/sdks/sdk-tizen/index.ts similarity index 100% rename from packages/engine-rn-web/src/sdks/sdk-tizen/index.js rename to packages/engine-rn-web/src/sdks/sdk-tizen/index.ts diff --git a/packages/engine-rn-web/src/sdks/sdk-webos/index.js b/packages/engine-rn-web/src/sdks/sdk-webos/index.ts similarity index 100% rename from packages/engine-rn-web/src/sdks/sdk-webos/index.js rename to packages/engine-rn-web/src/sdks/sdk-webos/index.ts diff --git a/packages/engine-rn-web/src/tasks/task.rnv.build.js b/packages/engine-rn-web/src/tasks/task.rnv.build.ts similarity index 100% rename from packages/engine-rn-web/src/tasks/task.rnv.build.js rename to packages/engine-rn-web/src/tasks/task.rnv.build.ts diff --git a/packages/engine-rn-web/src/tasks/task.rnv.configure.js b/packages/engine-rn-web/src/tasks/task.rnv.configure.ts similarity index 100% rename from packages/engine-rn-web/src/tasks/task.rnv.configure.js rename to packages/engine-rn-web/src/tasks/task.rnv.configure.ts diff --git a/packages/engine-rn-web/src/tasks/task.rnv.debug.js b/packages/engine-rn-web/src/tasks/task.rnv.debug.ts similarity index 100% rename from packages/engine-rn-web/src/tasks/task.rnv.debug.js rename to packages/engine-rn-web/src/tasks/task.rnv.debug.ts diff --git a/packages/engine-rn-web/src/tasks/task.rnv.deploy.js b/packages/engine-rn-web/src/tasks/task.rnv.deploy.ts similarity index 100% rename from packages/engine-rn-web/src/tasks/task.rnv.deploy.js rename to packages/engine-rn-web/src/tasks/task.rnv.deploy.ts diff --git a/packages/engine-rn-web/src/tasks/task.rnv.export.js b/packages/engine-rn-web/src/tasks/task.rnv.export.ts similarity index 100% rename from packages/engine-rn-web/src/tasks/task.rnv.export.js rename to packages/engine-rn-web/src/tasks/task.rnv.export.ts diff --git a/packages/engine-rn-web/src/tasks/task.rnv.package.js b/packages/engine-rn-web/src/tasks/task.rnv.package.ts similarity index 100% rename from packages/engine-rn-web/src/tasks/task.rnv.package.js rename to packages/engine-rn-web/src/tasks/task.rnv.package.ts diff --git a/packages/engine-rn-web/src/tasks/task.rnv.run.js b/packages/engine-rn-web/src/tasks/task.rnv.run.ts similarity index 100% rename from packages/engine-rn-web/src/tasks/task.rnv.run.js rename to packages/engine-rn-web/src/tasks/task.rnv.run.ts diff --git a/packages/engine-rn-web/src/tasks/task.rnv.start.js b/packages/engine-rn-web/src/tasks/task.rnv.start.ts similarity index 100% rename from packages/engine-rn-web/src/tasks/task.rnv.start.js rename to packages/engine-rn-web/src/tasks/task.rnv.start.ts diff --git a/packages/engine-rn-web/tsconfig.json b/packages/engine-rn-web/tsconfig.json index eef5815c2f..cf64fd612c 100644 --- a/packages/engine-rn-web/tsconfig.json +++ b/packages/engine-rn-web/tsconfig.json @@ -3,8 +3,8 @@ "compilerOptions": { "outDir": "./dist", "rootDir": "./src", - "allowJs": true, "resolveJsonModule": false }, - "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"] + "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"], + "exclude": ["node_modules", "./src/__tests__", "./dist/**/*"] } From 65f925df4e76c76c34850607ec81d014d3a23561 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 02:02:17 +0200 Subject: [PATCH 64/83] migrated engine rn-web --- packages/engine-rn-web/src/adapter.ts | 2 +- packages/engine-rn-web/src/index.ts | 9 ++-- .../src/sdks/{index.js => index.ts} | 0 .../src/sdks/sdk-firefox/index.ts | 21 ++++---- .../engine-rn-web/src/sdks/sdk-tizen/index.ts | 53 +++++++++++-------- .../engine-rn-web/src/sdks/sdk-webos/index.ts | 30 +++++++---- .../engine-rn-web/src/tasks/task.rnv.build.ts | 10 ++-- .../src/tasks/task.rnv.configure.ts | 4 +- .../engine-rn-web/src/tasks/task.rnv.debug.ts | 4 +- .../src/tasks/task.rnv.deploy.ts | 6 +-- .../src/tasks/task.rnv.export.ts | 6 +-- .../src/tasks/task.rnv.package.ts | 4 +- .../engine-rn-web/src/tasks/task.rnv.run.ts | 14 ++--- .../engine-rn-web/src/tasks/task.rnv.start.ts | 4 +- packages/engine-rn-web/types.d.ts | 2 + .../src/core/sdkManager/deviceUtils/tizen.ts | 7 ++- 16 files changed, 102 insertions(+), 74 deletions(-) rename packages/engine-rn-web/src/sdks/{index.js => index.ts} (100%) create mode 100644 packages/engine-rn-web/types.d.ts diff --git a/packages/engine-rn-web/src/adapter.ts b/packages/engine-rn-web/src/adapter.ts index acd36f0733..1267339d2b 100644 --- a/packages/engine-rn-web/src/adapter.ts +++ b/packages/engine-rn-web/src/adapter.ts @@ -1,4 +1,4 @@ -export const withRNVBabel = (cnf) => { +export const withRNVBabel = (cnf: any) => { const plugins = cnf?.plugins || []; return { diff --git a/packages/engine-rn-web/src/index.ts b/packages/engine-rn-web/src/index.ts index c296f6969a..354a606d37 100644 --- a/packages/engine-rn-web/src/index.ts +++ b/packages/engine-rn-web/src/index.ts @@ -1,5 +1,6 @@ -import { EngineManager, Config } from 'rnv'; +import { EngineManager, Config, RnvEngine } from 'rnv'; import { withRNVBabel } from './adapter'; +//@ts-ignore import CNF from '../renative.engine.json'; import taskRnvRun from './tasks/task.rnv.run'; import taskRnvPackage from './tasks/task.rnv.package'; @@ -20,7 +21,7 @@ const { generateEngineTasks, generateEngineExtensions } = EngineManager; export { webpack, HtmlWebpackPlugin, HtmlWebpackHarddiskPlugin, MiniCssExtractPlugin, BundleAnalyzerPlugin }; -export default { +const Engine: RnvEngine = { initializeRuntimeConfig: (c) => Config.initializeConfig(c), tasks: generateEngineTasks([ taskRnvRun, @@ -35,7 +36,7 @@ export default { config: CNF, projectDirName: '', serverDirName: '', - ejectPlatform: null, + runtimeExtraProps: {}, platforms: { web: { defaultPort: 8080, @@ -100,3 +101,5 @@ export default { }; export { withRNVBabel }; + +export default Engine; diff --git a/packages/engine-rn-web/src/sdks/index.js b/packages/engine-rn-web/src/sdks/index.ts similarity index 100% rename from packages/engine-rn-web/src/sdks/index.js rename to packages/engine-rn-web/src/sdks/index.ts diff --git a/packages/engine-rn-web/src/sdks/sdk-firefox/index.ts b/packages/engine-rn-web/src/sdks/sdk-firefox/index.ts index efd02bf757..75d734a549 100644 --- a/packages/engine-rn-web/src/sdks/sdk-firefox/index.ts +++ b/packages/engine-rn-web/src/sdks/sdk-firefox/index.ts @@ -1,6 +1,6 @@ import { buildCoreWebpackProject, configureCoreWebProject } from '@rnv/sdk-webpack'; import path from 'path'; -import { Common, FileUtils, Logger, PlatformManager, ProjectManager, SDKManager } from 'rnv'; +import { Common, FileUtils, Logger, PlatformManager, ProjectManager, RnvContext, SDKManager } from 'rnv'; const { getPlatformProjectDir, getAppTitle, getAppDescription, getAppAuthor } = Common; const { fsWriteFileSync, fsReadFileSync } = FileUtils; @@ -10,7 +10,7 @@ const { copyBuildsFolder, copyAssetsFolder } = ProjectManager; const { launchKaiOSSimulator } = SDKManager.Kaios; -export const configureKaiOSProject = async (c) => { +export const configureKaiOSProject = async (c: RnvContext) => { logTask('configureKaiOSProject'); const { platform } = c; @@ -20,13 +20,13 @@ export const configureKaiOSProject = async (c) => { if (!isPlatformActive(c, platform)) return; await copyAssetsFolder(c, platform); - await configureCoreWebProject(c); + await configureCoreWebProject(); await _configureProject(c); return copyBuildsFolder(c, platform); }; -const _configureProject = (c) => - new Promise((resolve) => { +const _configureProject = (c: RnvContext) => + new Promise((resolve) => { logTask('configureProject'); const { platform } = c; @@ -34,8 +34,8 @@ const _configureProject = (c) => const appFolder = getPlatformProjectDir(c); - const manifestFilePath = path.join(appFolder, 'manifest.webapp'); - const manifestFile = JSON.parse(fsReadFileSync(manifestFilePath)); + const manifestFilePath = path.join(appFolder!, 'manifest.webapp'); + const manifestFile = JSON.parse(fsReadFileSync(manifestFilePath).toString()); manifestFile.name = `${getAppTitle(c, platform)}`; manifestFile.description = `${getAppDescription(c, platform)}`; @@ -46,16 +46,15 @@ const _configureProject = (c) => resolve(); }); -export const runFirefoxProject = async (c) => { +export const runFirefoxProject = async (c: RnvContext) => { logTask('runFirefoxProject'); - const { platform } = c; await buildCoreWebpackProject(c); - await launchKaiOSSimulator(c, platform); + await launchKaiOSSimulator(c); return true; }; -export const buildFirefoxProject = async (c) => { +export const buildFirefoxProject = async (c: RnvContext) => { logTask('buildFirefoxProject'); await buildCoreWebpackProject(c); diff --git a/packages/engine-rn-web/src/sdks/sdk-tizen/index.ts b/packages/engine-rn-web/src/sdks/sdk-tizen/index.ts index 8dd1077116..7dab618382 100644 --- a/packages/engine-rn-web/src/sdks/sdk-tizen/index.ts +++ b/packages/engine-rn-web/src/sdks/sdk-tizen/index.ts @@ -1,6 +1,17 @@ import { buildCoreWebpackProject, configureCoreWebProject, runWebpackServer } from '@rnv/sdk-webpack'; import path from 'path'; -import { Common, Constants, Exec, FileUtils, Logger, PlatformManager, ProjectManager, SDKManager } from 'rnv'; +import { + Common, + Constants, + Exec, + FileUtils, + Logger, + OverridesOptions, + PlatformManager, + ProjectManager, + RnvContext, + SDKManager, +} from 'rnv'; import semver from 'semver'; const { execCLI } = Exec; @@ -26,8 +37,8 @@ const { runTizenSimOrDevice, createDevelopTizenCertificate, DEFAULT_CERTIFICATE_ const DEFAULT_CERTIFICATE_NAME_WITH_EXTENSION = `${DEFAULT_CERTIFICATE_NAME}.p12`; -export const configureTizenGlobal = (c) => - new Promise((resolve, reject) => { +export const configureTizenGlobal = (c: RnvContext) => + new Promise((resolve, reject) => { logTask('configureTizenGlobal'); // Check Tizen Cert // if (isPlatformActive(c, TIZEN) || isPlatformActive(c, TIZEN_WATCH)) { @@ -44,7 +55,7 @@ export const configureTizenGlobal = (c) => // } }); -const _runTizenSimOrDevice = async (c) => { +const _runTizenSimOrDevice = async (c: RnvContext) => { try { await runTizenSimOrDevice(c, buildCoreWebpackProject); } catch (e) { @@ -54,7 +65,7 @@ const _runTizenSimOrDevice = async (c) => { return true; }; -export const runTizen = async (c, target) => { +export const runTizen = async (c: RnvContext, target: string) => { logTask('runTizen', `target:${target}`); const { platform } = c; const { hosted } = c.program; @@ -106,19 +117,19 @@ export const runTizen = async (c, target) => { } }; -export const buildTizenProject = async (c) => { +export const buildTizenProject = async (c: RnvContext) => { logTask('buildTizenProject'); const { platform } = c; - const platformConfig = c.buildConfig.platforms[platform]; - const tDir = getPlatformProjectDir(c); + const platformConfig = c.buildConfig.platforms?.[platform]; + const tDir = getPlatformProjectDir(c)!; await buildCoreWebpackProject(c); if (!c.program.hosted) { const tOut = path.join(tDir, 'output'); const tBuild = path.join(tDir, 'build'); - const certProfile = platformConfig.certificateProfile ?? DEFAULT_SECURITY_PROFILE_NAME; + const certProfile = platformConfig?.certificateProfile ?? DEFAULT_SECURITY_PROFILE_NAME; await execCLI(c, CLI_TIZEN, `build-web -- ${tDir} -out ${tBuild}`); await execCLI(c, CLI_TIZEN, `package -- ${tBuild} -s ${certProfile} -t wgt -o ${tOut}`); @@ -131,7 +142,7 @@ export const buildTizenProject = async (c) => { let _isGlobalConfigured = false; -export const configureTizenProject = async (c) => { +export const configureTizenProject = async (c: RnvContext) => { logTask('configureTizenProject'); const { platform } = c; @@ -148,30 +159,30 @@ export const configureTizenProject = async (c) => { } await copyAssetsFolder(c, platform); - await configureCoreWebProject(c); + await configureCoreWebProject(); await _configureProject(c); return copyBuildsFolder(c, platform); }; -const _configureProject = (c) => - new Promise((resolve) => { +const _configureProject = (c: RnvContext) => + new Promise((resolve) => { logTask('_configureProject'); const { platform } = c; const configFile = 'config.xml'; - const p = c.buildConfig.platforms[platform]; + const p = c.buildConfig.platforms?.[platform]; - const injects = [ - { pattern: '{{PACKAGE}}', override: p.package }, - { pattern: '{{ID}}', override: p.id }, - { pattern: '{{APP_NAME}}', override: p.appName }, - { pattern: '{{APP_VERSION}}', override: semver.coerce(getAppVersion(c, platform)) }, + const injects: OverridesOptions = [ + { pattern: '{{PACKAGE}}', override: p?.package || '' }, + { pattern: '{{ID}}', override: p?.id || '' }, + { pattern: '{{APP_NAME}}', override: p?.appName || '' }, + { pattern: '{{APP_VERSION}}', override: semver.valid(semver.coerce(getAppVersion(c, platform))) || '' }, ]; addSystemInjects(c, injects); - const file = path.join(getPlatformProjectDir(c), configFile); - writeCleanFile(file, file, injects, null, c); + const file = path.join(getPlatformProjectDir(c)!, configFile); + writeCleanFile(file, file, injects, undefined, c); resolve(); }); diff --git a/packages/engine-rn-web/src/sdks/sdk-webos/index.ts b/packages/engine-rn-web/src/sdks/sdk-webos/index.ts index 10f055e03b..343d460c03 100644 --- a/packages/engine-rn-web/src/sdks/sdk-webos/index.ts +++ b/packages/engine-rn-web/src/sdks/sdk-webos/index.ts @@ -1,6 +1,16 @@ import { buildCoreWebpackProject, configureCoreWebProject, runWebpackServer } from '@rnv/sdk-webpack'; import path from 'path'; -import { Common, Constants, Exec, FileUtils, Logger, PlatformManager, ProjectManager, SDKManager } from 'rnv'; +import { + Common, + Constants, + Exec, + FileUtils, + Logger, + PlatformManager, + ProjectManager, + RnvContext, + SDKManager, +} from 'rnv'; import semver from 'semver'; const { writeCleanFile } = FileUtils; @@ -25,7 +35,7 @@ const { copyBuildsFolder, copyAssetsFolder } = ProjectManager; const { CLI_WEBOS_ARES_PACKAGE, REMOTE_DEBUGGER_ENABLED_PLATFORMS } = Constants; const { runWebosSimOrDevice } = SDKManager.Webos; -export const runWebOS = async (c) => { +export const runWebOS = async (c: RnvContext) => { const { hosted } = c.program; const { target } = c.runtime; const { platform } = c; @@ -85,36 +95,36 @@ export const runWebOS = async (c) => { } }; -export const buildWebOSProject = async (c) => { +export const buildWebOSProject = async (c: RnvContext) => { logTask('buildWebOSProject'); await buildCoreWebpackProject(c); if (!c.program.hosted) { const tDir = getPlatformProjectDir(c); - const tOut = path.join(getPlatformBuildDir(c), 'output'); + const tOut = path.join(getPlatformBuildDir(c)!, 'output'); await execCLI(c, CLI_WEBOS_ARES_PACKAGE, `-o ${tOut} ${tDir} -n`); logSuccess(`Your IPK package is located in ${chalk().cyan(tOut)} .`); } }; -export const configureWebOSProject = async (c) => { +export const configureWebOSProject = async (c: RnvContext) => { logTask('configureWebOSProject'); const { platform } = c; - c.runtime.platformBuildsProjectPath = getPlatformProjectDir(c); + c.runtime.platformBuildsProjectPath = getPlatformProjectDir(c)!; if (!isPlatformActive(c, platform)) return; await copyAssetsFolder(c, platform); - await configureCoreWebProject(c); + await configureCoreWebProject(); await _configureProject(c); return copyBuildsFolder(c, platform); }; -const _configureProject = async (c) => { +const _configureProject = async (c: RnvContext) => { logTask('_configureProject'); const { platform } = c; @@ -153,9 +163,9 @@ const _configureProject = async (c) => { addSystemInjects(c, injects); - const file = path.join(getPlatformProjectDir(c), configFile); + const file = path.join(getPlatformProjectDir(c)!, configFile); - writeCleanFile(file, file, injects, null, c); + writeCleanFile(file, file, injects, undefined, c); return true; }; diff --git a/packages/engine-rn-web/src/tasks/task.rnv.build.ts b/packages/engine-rn-web/src/tasks/task.rnv.build.ts index 4d7640dca6..876b450ad6 100644 --- a/packages/engine-rn-web/src/tasks/task.rnv.build.ts +++ b/packages/engine-rn-web/src/tasks/task.rnv.build.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; import { buildWeb } from '@rnv/sdk-webpack'; import { SDKTizen, SDKWebos, SDKFirefox } from '../sdks'; @@ -25,7 +25,7 @@ const { buildWebOSProject } = SDKWebos; const { buildFirefoxProject } = SDKFirefox; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvBuild = async (c, parentTask, originTask) => { +export const taskRnvBuild: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvBuild', `parent:${parentTask}`); const { platform } = c; @@ -46,15 +46,15 @@ export const taskRnvBuild = async (c, parentTask, originTask) => { case KAIOS: case FIREFOX_OS: case FIREFOX_TV: - await buildFirefoxProject(c, platform); + await buildFirefoxProject(c); return; case TIZEN: case TIZEN_MOBILE: case TIZEN_WATCH: - await buildTizenProject(c, platform); + await buildTizenProject(c); return; case WEBOS: - await buildWebOSProject(c, platform); + await buildWebOSProject(c); return; default: logErrorPlatform(c); diff --git a/packages/engine-rn-web/src/tasks/task.rnv.configure.ts b/packages/engine-rn-web/src/tasks/task.rnv.configure.ts index 0c2e8d6da5..de21b537fc 100644 --- a/packages/engine-rn-web/src/tasks/task.rnv.configure.ts +++ b/packages/engine-rn-web/src/tasks/task.rnv.configure.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager, TemplateManager } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, TemplateManager, RnvTaskFn } from 'rnv'; import { configureWebProject, configureChromecastProject } from '@rnv/sdk-webpack'; import { SDKTizen, SDKWebos, SDKFirefox } from '../sdks'; @@ -26,7 +26,7 @@ const { configureKaiOSProject } = SDKFirefox; const { executeTask, shouldSkipTask } = TaskManager; const { configureEntryPoint } = TemplateManager; -export const taskRnvConfigure = async (c, parentTask, originTask) => { +export const taskRnvConfigure: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvConfigure'); await executeTask(c, TASK_PLATFORM_CONFIGURE, TASK_CONFIGURE, originTask); diff --git a/packages/engine-rn-web/src/tasks/task.rnv.debug.ts b/packages/engine-rn-web/src/tasks/task.rnv.debug.ts index 7880121b16..2743f4d4fd 100644 --- a/packages/engine-rn-web/src/tasks/task.rnv.debug.ts +++ b/packages/engine-rn-web/src/tasks/task.rnv.debug.ts @@ -1,4 +1,4 @@ -import { Constants, Logger, PlatformManager, Exec, TaskManager } from 'rnv'; +import { Constants, Logger, PlatformManager, Exec, TaskManager, RnvTaskFn } from 'rnv'; const { logErrorPlatform } = PlatformManager; const { logTask } = Logger; @@ -6,7 +6,7 @@ const { WEB, WEBTV, TIZEN, PARAMS, TASK_DEBUG } = Constants; const { executeAsync } = Exec; const { shouldSkipTask } = TaskManager; -export const taskRnvDebug = async (c, parentTask, originTask) => { +export const taskRnvDebug: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvDebug', `parent:${parentTask}`); if (shouldSkipTask(c, TASK_DEBUG, originTask)) return true; diff --git a/packages/engine-rn-web/src/tasks/task.rnv.deploy.ts b/packages/engine-rn-web/src/tasks/task.rnv.deploy.ts index 7e5c2e8fee..64d4eaa6d2 100644 --- a/packages/engine-rn-web/src/tasks/task.rnv.deploy.ts +++ b/packages/engine-rn-web/src/tasks/task.rnv.deploy.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; import { deployWeb } from '@rnv/sdk-webpack'; const { logErrorPlatform } = PlatformManager; @@ -21,7 +21,7 @@ const { const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvDeploy = async (c, parentTask, originTask) => { +export const taskRnvDeploy: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvDeploy', `parent:${parentTask}`); const { platform } = c; @@ -34,7 +34,7 @@ export const taskRnvDeploy = async (c, parentTask, originTask) => { case WEB: case WEBTV: case CHROMECAST: - return deployWeb(c); + return deployWeb(); default: logErrorPlatform(c); } diff --git a/packages/engine-rn-web/src/tasks/task.rnv.export.ts b/packages/engine-rn-web/src/tasks/task.rnv.export.ts index 64fee74140..0e76dad90f 100644 --- a/packages/engine-rn-web/src/tasks/task.rnv.export.ts +++ b/packages/engine-rn-web/src/tasks/task.rnv.export.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; import { exportWeb } from '@rnv/sdk-webpack'; const { logErrorPlatform } = PlatformManager; @@ -20,7 +20,7 @@ const { const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvExport = async (c, parentTask, originTask) => { +export const taskRnvExport: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvExport', `parent:${parentTask}`); const { platform } = c; @@ -31,7 +31,7 @@ export const taskRnvExport = async (c, parentTask, originTask) => { switch (platform) { case WEB: - return exportWeb(c); + return exportWeb(); default: logErrorPlatform(c); } diff --git a/packages/engine-rn-web/src/tasks/task.rnv.package.ts b/packages/engine-rn-web/src/tasks/task.rnv.package.ts index edd96bba43..fbad4ae246 100644 --- a/packages/engine-rn-web/src/tasks/task.rnv.package.ts +++ b/packages/engine-rn-web/src/tasks/task.rnv.package.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger } from 'rnv'; +import { TaskManager, Constants, Logger, RnvTaskFn } from 'rnv'; const { logTask } = Logger; const { @@ -18,7 +18,7 @@ const { const { executeOrSkipTask } = TaskManager; -export const taskRnvPackage = async (c, parentTask, originTask) => { +export const taskRnvPackage: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvPackage', `parent:${parentTask}`); await executeOrSkipTask(c, TASK_CONFIGURE, TASK_PACKAGE, originTask); diff --git a/packages/engine-rn-web/src/tasks/task.rnv.run.ts b/packages/engine-rn-web/src/tasks/task.rnv.run.ts index bc76432ce1..4c3dc4d9a2 100644 --- a/packages/engine-rn-web/src/tasks/task.rnv.run.ts +++ b/packages/engine-rn-web/src/tasks/task.rnv.run.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager, FileUtils, Common } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, FileUtils, Common, RnvContext, RnvTaskFn } from 'rnv'; import ip from 'ip'; import path from 'path'; import { runChromecast, runWebpackServer } from '@rnv/sdk-webpack'; @@ -30,19 +30,19 @@ const { runFirefoxProject } = SDKFirefox; const { writeCleanFile } = FileUtils; const { executeTask, executeOrSkipTask, shouldSkipTask } = TaskManager; -const _configureHostedIfRequired = async (c) => { +const _configureHostedIfRequired = async (c: RnvContext) => { logTask('_configureHostedIfRequired'); const bundleAssets = getConfigProp(c, c.platform, 'bundleAssets', false); const hostedShellHeaders = getConfigProp(c, c.platform, 'hostedShellHeaders', ''); - if (!bundleAssets && !existBuildsOverrideForTargetPathSync(c, path.join(getPlatformProjectDir(c), 'index.html'))) { + if (!bundleAssets && !existBuildsOverrideForTargetPathSync(c, path.join(getPlatformProjectDir(c)!, 'index.html'))) { logDebug('Running hosted build'); const { rnv } = c.paths; const ipAddress = c.program.hostIp || ip.address(); writeCleanFile( path.join(rnv.dir, 'coreTemplateFiles', 'appShell', 'index.html'), - path.join(getPlatformProjectDir(c), 'index.html'), + path.join(getPlatformProjectDir(c)!, 'index.html'), [ { pattern: '{{DEV_SERVER}}', @@ -53,13 +53,13 @@ const _configureHostedIfRequired = async (c) => { override: String(hostedShellHeaders || ''), }, ], - null, + undefined, c ); } }; -export const taskRnvRun = async (c, parentTask, originTask) => { +export const taskRnvRun: RnvTaskFn = async (c, parentTask, originTask) => { const { platform } = c; const { port } = c.runtime; const { target } = c.runtime; @@ -101,7 +101,7 @@ export const taskRnvRun = async (c, parentTask, originTask) => { if (!c.program.only) { await _configureHostedIfRequired(c); } - return runChromecast(c, platform, target); + return runChromecast(c); default: return logErrorPlatform(c); } diff --git a/packages/engine-rn-web/src/tasks/task.rnv.start.ts b/packages/engine-rn-web/src/tasks/task.rnv.start.ts index c4db7c8549..884b4fd8e4 100644 --- a/packages/engine-rn-web/src/tasks/task.rnv.start.ts +++ b/packages/engine-rn-web/src/tasks/task.rnv.start.ts @@ -1,6 +1,6 @@ import { runWebpackServer } from '@rnv/sdk-webpack'; import open from 'better-opn'; -import { Common, Constants, Logger, PlatformManager, TaskManager } from 'rnv'; +import { Common, Constants, Logger, PlatformManager, RnvTaskFn, TaskManager } from 'rnv'; const { getConfigProp, waitForHost } = Common; const { logErrorPlatform } = PlatformManager; @@ -24,7 +24,7 @@ const { const { executeTask, shouldSkipTask } = TaskManager; -export const taskRnvStart = async (c, parentTask, originTask) => { +export const taskRnvStart: RnvTaskFn = async (c, parentTask, originTask) => { const { platform } = c; const { port } = c.runtime; const { hosted } = c.program; diff --git a/packages/engine-rn-web/types.d.ts b/packages/engine-rn-web/types.d.ts new file mode 100644 index 0000000000..4658ead387 --- /dev/null +++ b/packages/engine-rn-web/types.d.ts @@ -0,0 +1,2 @@ +declare module 'better-opn' +declare module 'ip' \ No newline at end of file diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts index 0acf2ca2b5..b6de81df13 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts @@ -212,7 +212,10 @@ const _composeDevicesString = (devices: Array) => // } // }; -export const runTizenSimOrDevice = async (c: RnvContext, buildCoreWebpackProject?: () => Promise) => { +export const runTizenSimOrDevice = async ( + c: RnvContext, + buildCoreWebpackProject?: (c: RnvContext) => Promise +) => { const { hosted } = c.program; const { target, engine } = c.runtime; const { platform } = c; @@ -289,7 +292,7 @@ Please create one and then edit the default target from ${c.paths.workspace.dir} if (!isLightningEngine && buildCoreWebpackProject) { // lightning engine handles the build and packaging - !isHosted && (await buildCoreWebpackProject()); + !isHosted && (await buildCoreWebpackProject(c)); await execCLI(c, CLI_TIZEN, `build-web -- ${tDir} -out ${tBuild}`); await execCLI(c, CLI_TIZEN, `package -- ${tBuild} -s ${certProfile} -t wgt -o ${tOut}`); } From 43f2a9c8994b63c413756facaaa541b286d79180 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 02:04:07 +0200 Subject: [PATCH 65/83] rename engine-rn-macos js to ts --- packages/engine-rn-macos/src/{adapter.js => adapter.ts} | 0 .../engine-rn-macos/src/{commonEngine.js => commonEngine.ts} | 0 packages/engine-rn-macos/src/{index.js => index.ts} | 0 .../src/tasks/{task.rnv.build.js => task.rnv.build.ts} | 0 .../tasks/{task.rnv.configure.js => task.rnv.configure.ts} | 0 .../src/tasks/{task.rnv.deploy.js => task.rnv.deploy.ts} | 0 .../src/tasks/{task.rnv.export.js => task.rnv.export.ts} | 0 .../src/tasks/{task.rnv.package.js => task.rnv.package.ts} | 0 .../src/tasks/{task.rnv.run.js => task.rnv.run.ts} | 0 .../src/tasks/{task.rnv.start.js => task.rnv.start.ts} | 0 packages/engine-rn-macos/tsconfig.json | 4 ++-- 11 files changed, 2 insertions(+), 2 deletions(-) rename packages/engine-rn-macos/src/{adapter.js => adapter.ts} (100%) rename packages/engine-rn-macos/src/{commonEngine.js => commonEngine.ts} (100%) rename packages/engine-rn-macos/src/{index.js => index.ts} (100%) rename packages/engine-rn-macos/src/tasks/{task.rnv.build.js => task.rnv.build.ts} (100%) rename packages/engine-rn-macos/src/tasks/{task.rnv.configure.js => task.rnv.configure.ts} (100%) rename packages/engine-rn-macos/src/tasks/{task.rnv.deploy.js => task.rnv.deploy.ts} (100%) rename packages/engine-rn-macos/src/tasks/{task.rnv.export.js => task.rnv.export.ts} (100%) rename packages/engine-rn-macos/src/tasks/{task.rnv.package.js => task.rnv.package.ts} (100%) rename packages/engine-rn-macos/src/tasks/{task.rnv.run.js => task.rnv.run.ts} (100%) rename packages/engine-rn-macos/src/tasks/{task.rnv.start.js => task.rnv.start.ts} (100%) diff --git a/packages/engine-rn-macos/src/adapter.js b/packages/engine-rn-macos/src/adapter.ts similarity index 100% rename from packages/engine-rn-macos/src/adapter.js rename to packages/engine-rn-macos/src/adapter.ts diff --git a/packages/engine-rn-macos/src/commonEngine.js b/packages/engine-rn-macos/src/commonEngine.ts similarity index 100% rename from packages/engine-rn-macos/src/commonEngine.js rename to packages/engine-rn-macos/src/commonEngine.ts diff --git a/packages/engine-rn-macos/src/index.js b/packages/engine-rn-macos/src/index.ts similarity index 100% rename from packages/engine-rn-macos/src/index.js rename to packages/engine-rn-macos/src/index.ts diff --git a/packages/engine-rn-macos/src/tasks/task.rnv.build.js b/packages/engine-rn-macos/src/tasks/task.rnv.build.ts similarity index 100% rename from packages/engine-rn-macos/src/tasks/task.rnv.build.js rename to packages/engine-rn-macos/src/tasks/task.rnv.build.ts diff --git a/packages/engine-rn-macos/src/tasks/task.rnv.configure.js b/packages/engine-rn-macos/src/tasks/task.rnv.configure.ts similarity index 100% rename from packages/engine-rn-macos/src/tasks/task.rnv.configure.js rename to packages/engine-rn-macos/src/tasks/task.rnv.configure.ts diff --git a/packages/engine-rn-macos/src/tasks/task.rnv.deploy.js b/packages/engine-rn-macos/src/tasks/task.rnv.deploy.ts similarity index 100% rename from packages/engine-rn-macos/src/tasks/task.rnv.deploy.js rename to packages/engine-rn-macos/src/tasks/task.rnv.deploy.ts diff --git a/packages/engine-rn-macos/src/tasks/task.rnv.export.js b/packages/engine-rn-macos/src/tasks/task.rnv.export.ts similarity index 100% rename from packages/engine-rn-macos/src/tasks/task.rnv.export.js rename to packages/engine-rn-macos/src/tasks/task.rnv.export.ts diff --git a/packages/engine-rn-macos/src/tasks/task.rnv.package.js b/packages/engine-rn-macos/src/tasks/task.rnv.package.ts similarity index 100% rename from packages/engine-rn-macos/src/tasks/task.rnv.package.js rename to packages/engine-rn-macos/src/tasks/task.rnv.package.ts diff --git a/packages/engine-rn-macos/src/tasks/task.rnv.run.js b/packages/engine-rn-macos/src/tasks/task.rnv.run.ts similarity index 100% rename from packages/engine-rn-macos/src/tasks/task.rnv.run.js rename to packages/engine-rn-macos/src/tasks/task.rnv.run.ts diff --git a/packages/engine-rn-macos/src/tasks/task.rnv.start.js b/packages/engine-rn-macos/src/tasks/task.rnv.start.ts similarity index 100% rename from packages/engine-rn-macos/src/tasks/task.rnv.start.js rename to packages/engine-rn-macos/src/tasks/task.rnv.start.ts diff --git a/packages/engine-rn-macos/tsconfig.json b/packages/engine-rn-macos/tsconfig.json index eef5815c2f..cf64fd612c 100644 --- a/packages/engine-rn-macos/tsconfig.json +++ b/packages/engine-rn-macos/tsconfig.json @@ -3,8 +3,8 @@ "compilerOptions": { "outDir": "./dist", "rootDir": "./src", - "allowJs": true, "resolveJsonModule": false }, - "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"] + "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"], + "exclude": ["node_modules", "./src/__tests__", "./dist/**/*"] } From a85075e110d6ec28820f33cd6725f33b30a63072 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 02:23:20 +0200 Subject: [PATCH 66/83] engine-rn-macos TS done --- packages/engine-rn-macos/src/adapter.ts | 48 +++++++++++++------ packages/engine-rn-macos/src/commonEngine.ts | 24 +++++----- packages/engine-rn-macos/src/index.ts | 15 ++++-- .../src/tasks/task.rnv.build.ts | 6 +-- .../src/tasks/task.rnv.configure.ts | 4 +- .../src/tasks/task.rnv.deploy.ts | 4 +- .../src/tasks/task.rnv.export.ts | 6 +-- .../src/tasks/task.rnv.package.ts | 4 +- .../engine-rn-macos/src/tasks/task.rnv.run.ts | 4 +- .../src/tasks/task.rnv.start.ts | 6 +-- 10 files changed, 72 insertions(+), 49 deletions(-) diff --git a/packages/engine-rn-macos/src/adapter.ts b/packages/engine-rn-macos/src/adapter.ts index ea98438259..bb3c8f802b 100644 --- a/packages/engine-rn-macos/src/adapter.ts +++ b/packages/engine-rn-macos/src/adapter.ts @@ -7,29 +7,30 @@ const sharedBlacklist = [ /.*\/__tests__\/.*/, ]; -function escapeRegExp(pattern) { - if (Object.prototype.toString.call(pattern) === '[object RegExp]') { - return pattern.source.replace(/\//g, path.sep); - } +const env: any = process?.env; + +function escapeRegExp(pattern: RegExp | string) { if (typeof pattern === 'string') { // eslint-disable-next-line const escaped = pattern.replace(/[\-\[\]\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'); // convert the '/' into an escaped local file separator return escaped.replace(/\//g, `\\${path.sep}`); + } else if (Object.prototype.toString.call(pattern) === '[object RegExp]') { + return pattern.source.replace(/\//g, path.sep); } throw new Error(`Unexpected blacklist pattern: ${pattern}`); } -function blacklist(additionalBlacklist) { +function blacklist(additionalBlacklist: RegExp[]) { return new RegExp(`(${(additionalBlacklist || []).concat(sharedBlacklist).map(escapeRegExp).join('|')})$`); } -export const withRNV = (config) => { +export const withRNVMetro = (config: any) => { const projectPath = process.env.RNV_PROJECT_ROOT || process.cwd(); const watchFolders = [path.resolve(projectPath, 'node_modules')]; - if (process.env.RNV_IS_MONOREPO === 'true' || process.env.RNV_IS_MONOREPO === true) { + if (env.RNV_IS_MONOREPO === 'true' || env.RNV_IS_MONOREPO === true) { const monoRootPath = process.env.RNV_MONO_ROOT || projectPath; watchFolders.push(path.resolve(monoRootPath, 'node_modules')); watchFolders.push(path.resolve(monoRootPath, 'packages')); @@ -38,7 +39,7 @@ export const withRNV = (config) => { watchFolders.push(...config.watchFolders); } - const exts = process.env.RNV_EXTENSIONS || []; + const exts: string = env.RNV_EXTENSIONS || ''; const cnf = { ...config, @@ -46,18 +47,14 @@ export const withRNV = (config) => { getTransformOptions: async () => ({ transform: { experimentalImportSupport: false, - inlineRequires: false, + // this defeats the RCTDeviceEventEmitter is not a registered callable module + inlineRequires: true, }, }), + ...(config?.transformer || {}), }, resolver: { blacklistRE: blacklist([ - /platformBuilds\/.*/, - /buildHooks\/.*/, - /projectConfig\/.*/, - /appConfigs\/.*/, - /renative.local.*/, - /metro.config.local.*/, /platformBuilds\/.*/, /buildHooks\/.*/, /projectConfig\/.*/, @@ -65,6 +62,8 @@ export const withRNV = (config) => { /appConfigs\/.*/, /renative.local.*/, /metro.config.local.*/, + /.expo\/.*/, + /.rollup.cache\/.*/, ]), ...(config?.resolver || {}), sourceExts: [...(config?.resolver?.sourceExts || []), ...exts.split(',')], @@ -76,3 +75,22 @@ export const withRNV = (config) => { return cnf; }; + +export const withRNVBabel = (cnf: any) => { + const plugins = cnf?.plugins || []; + + return { + retainLines: true, + presets: ['module:metro-react-native-babel-preset'], + ...cnf, + plugins: [ + [ + require.resolve('babel-plugin-module-resolver'), + { + root: [process.env.RNV_MONO_ROOT || '.'], + }, + ], + ...plugins, + ], + }; +}; diff --git a/packages/engine-rn-macos/src/commonEngine.ts b/packages/engine-rn-macos/src/commonEngine.ts index 18d6cf46aa..bd731e9fc1 100644 --- a/packages/engine-rn-macos/src/commonEngine.ts +++ b/packages/engine-rn-macos/src/commonEngine.ts @@ -1,6 +1,6 @@ import path from 'path'; import axios from 'axios'; -import { TaskManager, Constants, Logger, Common, FileUtils, Spinner } from 'rnv'; +import { TaskManager, Constants, Logger, Common, FileUtils, Spinner, RnvContext } from 'rnv'; const { getConfigProp, confirmActiveBundler } = Common; const { chalk, logTask, logInfo, logWarning } = Logger; @@ -10,7 +10,7 @@ const { executeTask } = TaskManager; let keepRNVRunning = false; -export const startBundlerIfRequired = async (c, parentTask, originTask) => { +export const startBundlerIfRequired = async (c: RnvContext, parentTask: string, originTask?: string) => { logTask('startBundlerIfRequired'); const bundleAssets = getConfigProp(c, c.platform, 'bundleAssets'); if (bundleAssets === true) return; @@ -33,7 +33,7 @@ export const startBundlerIfRequired = async (c, parentTask, originTask) => { } }; -export const waitForBundlerIfRequired = async (c) => { +export const waitForBundlerIfRequired = async (c: RnvContext) => { const bundleAssets = getConfigProp(c, c.platform, 'bundleAssets'); if (bundleAssets === true) return; // return a new promise that does...nothing, just to keep RNV running while the bundler is running @@ -44,7 +44,7 @@ export const waitForBundlerIfRequired = async (c) => { return true; }; -export const configureMetroConfigs = async (c) => { +export const configureMetroConfigs = async (c: RnvContext) => { logTask('configureMetroConfigs'); const cfPath = path.join(c.paths.project.dir, 'configs', `metro.config.${c.platform}.js`); @@ -59,7 +59,7 @@ export const configureMetroConfigs = async (c) => { } }; -const _isBundlerRunning = async (c) => { +const _isBundlerRunning = async (c: RnvContext) => { logTask('_isBundlerRunning'); try { const { data } = await axios.get( @@ -77,7 +77,7 @@ const _isBundlerRunning = async (c) => { } }; -export const isBundlerActive = async (c) => { +export const isBundlerActive = async (c: RnvContext) => { logTask('isBundlerActive', `(http://${c.runtime.localhost}:${c.runtime.port})`); try { await axios.get(`http://${c.runtime.localhost}:${c.runtime.port}`); @@ -87,15 +87,15 @@ export const isBundlerActive = async (c) => { } }; -const poll = (fn, timeout = 10000, interval = 1000) => { +const poll = (fn: () => Promise, timeout = 10000, interval = 1000) => { const endTime = Number(new Date()) + timeout; - const spinner = Spinner('Waiting for bundler to finish...').start(); - const checkCondition = async (resolve, reject) => { + const spinner = Spinner('Waiting for bundler to finish...').start(''); + const checkCondition = async (resolve: () => void, reject: (e: any) => void) => { try { const result = await fn(); if (result) { - spinner.succeed(); + spinner.succeed(''); resolve(); } else if (Number(new Date()) < endTime) { setTimeout(checkCondition, interval, resolve, reject); @@ -109,7 +109,7 @@ const poll = (fn, timeout = 10000, interval = 1000) => { } }; - return new Promise(checkCondition); + return new Promise(checkCondition); }; -export const waitForBundler = async (c) => poll(() => _isBundlerRunning(c)); +export const waitForBundler = async (c: RnvContext) => poll(() => _isBundlerRunning(c)); diff --git a/packages/engine-rn-macos/src/index.ts b/packages/engine-rn-macos/src/index.ts index 76576b8372..8cefcbb122 100644 --- a/packages/engine-rn-macos/src/index.ts +++ b/packages/engine-rn-macos/src/index.ts @@ -1,5 +1,6 @@ -import { EngineManager, Config } from 'rnv'; -import { withRNV } from './adapter'; +import { EngineManager, Config, RnvEngine } from 'rnv'; +import { withRNVBabel, withRNVMetro } from './adapter'; +//@ts-ignore import CNF from '../renative.engine.json'; import taskRnvRun from './tasks/task.rnv.run'; import taskRnvPackage from './tasks/task.rnv.package'; @@ -12,7 +13,7 @@ import taskRnvDeploy from './tasks/task.rnv.deploy'; const { generateEngineTasks, generateEngineExtensions } = EngineManager; -export default { +const Engine: RnvEngine = { initializeRuntimeConfig: (c) => Config.initializeConfig(c), tasks: generateEngineTasks([ taskRnvRun, @@ -32,7 +33,6 @@ export default { }, projectDirName: '', serverDirName: 'server', - ejectPlatform: null, platforms: { macos: { defaultPort: 8086, @@ -44,4 +44,9 @@ export default { }, }; -export { withRNV }; +// Backward compatibility +const withRNV = withRNVMetro; + +export { withRNV, withRNVMetro, withRNVBabel }; + +export default Engine; diff --git a/packages/engine-rn-macos/src/tasks/task.rnv.build.ts b/packages/engine-rn-macos/src/tasks/task.rnv.build.ts index bff0d426c9..ce9f05634e 100644 --- a/packages/engine-rn-macos/src/tasks/task.rnv.build.ts +++ b/packages/engine-rn-macos/src/tasks/task.rnv.build.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; import { buildXcodeProject } from '@rnv/sdk-apple'; const { logErrorPlatform } = PlatformManager; @@ -7,7 +7,7 @@ const { MACOS, TASK_BUILD, TASK_PACKAGE, TASK_EXPORT, PARAMS } = Constants; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvBuild = async (c, parentTask, originTask) => { +export const taskRnvBuild: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvBuild'); const { platform } = c; @@ -21,7 +21,7 @@ export const taskRnvBuild = async (c, parentTask, originTask) => { // build task is not necessary when exporting macos return true; } - return buildXcodeProject(c, platform); + return buildXcodeProject(c); default: return logErrorPlatform(c); } diff --git a/packages/engine-rn-macos/src/tasks/task.rnv.configure.ts b/packages/engine-rn-macos/src/tasks/task.rnv.configure.ts index eff68b5ad3..731e64aa25 100644 --- a/packages/engine-rn-macos/src/tasks/task.rnv.configure.ts +++ b/packages/engine-rn-macos/src/tasks/task.rnv.configure.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager, TemplateManager } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, TemplateManager, RnvTaskFn } from 'rnv'; import { configureXcodeProject } from '@rnv/sdk-apple'; import { configureMetroConfigs } from '../commonEngine'; @@ -9,7 +9,7 @@ const { MACOS, TASK_PLATFORM_CONFIGURE, TASK_CONFIGURE, PARAMS } = Constants; const { executeTask, shouldSkipTask } = TaskManager; const { configureEntryPoint } = TemplateManager; -export const taskRnvConfigure = async (c, parentTask, originTask) => { +export const taskRnvConfigure: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvConfigure'); await configureMetroConfigs(c); diff --git a/packages/engine-rn-macos/src/tasks/task.rnv.deploy.ts b/packages/engine-rn-macos/src/tasks/task.rnv.deploy.ts index 0ce94d215d..5b2ae642e2 100644 --- a/packages/engine-rn-macos/src/tasks/task.rnv.deploy.ts +++ b/packages/engine-rn-macos/src/tasks/task.rnv.deploy.ts @@ -1,10 +1,10 @@ -import { TaskManager, Constants, Logger } from 'rnv'; +import { TaskManager, Constants, Logger, RnvTaskFn } from 'rnv'; const { logTask } = Logger; const { TASK_EXPORT, TASK_DEPLOY, MACOS, PARAMS } = Constants; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvDeploy = async (c, parentTask, originTask) => { +export const taskRnvDeploy: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvDeploy', `parent:${parentTask}`); await executeOrSkipTask(c, TASK_EXPORT, TASK_DEPLOY, originTask); diff --git a/packages/engine-rn-macos/src/tasks/task.rnv.export.ts b/packages/engine-rn-macos/src/tasks/task.rnv.export.ts index 7f064c29d7..812f3be075 100644 --- a/packages/engine-rn-macos/src/tasks/task.rnv.export.ts +++ b/packages/engine-rn-macos/src/tasks/task.rnv.export.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; import { exportXcodeProject } from '@rnv/sdk-apple'; const { logErrorPlatform } = PlatformManager; @@ -7,7 +7,7 @@ const { MACOS, TASK_BUILD, TASK_EXPORT, PARAMS } = Constants; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvExport = async (c, parentTask, originTask) => { +export const taskRnvExport: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvExport', `parent:${parentTask}`); const { platform } = c; @@ -17,7 +17,7 @@ export const taskRnvExport = async (c, parentTask, originTask) => { switch (platform) { case MACOS: - return exportXcodeProject(c, platform); + return exportXcodeProject(c); default: return logErrorPlatform(c); } diff --git a/packages/engine-rn-macos/src/tasks/task.rnv.package.ts b/packages/engine-rn-macos/src/tasks/task.rnv.package.ts index 7631296792..f0706cf45f 100644 --- a/packages/engine-rn-macos/src/tasks/task.rnv.package.ts +++ b/packages/engine-rn-macos/src/tasks/task.rnv.package.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager, Common } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, Common, RnvTaskFn } from 'rnv'; import { packageBundleForXcode } from '@rnv/sdk-apple'; const { logErrorPlatform } = PlatformManager; @@ -8,7 +8,7 @@ const { getConfigProp } = Common; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvPackage = async (c, parentTask, originTask) => { +export const taskRnvPackage: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvPackage', `parent:${parentTask}`); const { platform } = c; diff --git a/packages/engine-rn-macos/src/tasks/task.rnv.run.ts b/packages/engine-rn-macos/src/tasks/task.rnv.run.ts index c5faa9a003..2a60321748 100644 --- a/packages/engine-rn-macos/src/tasks/task.rnv.run.ts +++ b/packages/engine-rn-macos/src/tasks/task.rnv.run.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager, Common } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, Common, RnvTaskFn } from 'rnv'; import { runXcodeProject } from '@rnv/sdk-apple'; import { startBundlerIfRequired, waitForBundlerIfRequired } from '../commonEngine'; @@ -9,7 +9,7 @@ const { MACOS, TASK_RUN, TASK_CONFIGURE, PARAMS } = Constants; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvRun = async (c, parentTask, originTask) => { +export const taskRnvRun: RnvTaskFn = async (c, parentTask, originTask) => { const { platform } = c; const { port } = c.runtime; const { target } = c.runtime; diff --git a/packages/engine-rn-macos/src/tasks/task.rnv.start.ts b/packages/engine-rn-macos/src/tasks/task.rnv.start.ts index 789985614b..86a51f7b07 100644 --- a/packages/engine-rn-macos/src/tasks/task.rnv.start.ts +++ b/packages/engine-rn-macos/src/tasks/task.rnv.start.ts @@ -1,4 +1,4 @@ -import { TaskManager, EngineManager, Constants, Logger, PlatformManager, Exec, Common, Resolver } from 'rnv'; +import { TaskManager, EngineManager, Constants, Logger, PlatformManager, Exec, Common, Resolver, RnvTaskFn } from 'rnv'; import { isBundlerActive } from '../commonEngine'; const { getEntryFile, confirmActiveBundler } = Common; @@ -10,11 +10,11 @@ const { chalk, logTask, logError, logRaw, logInfo } = Logger; const { MACOS, TASK_START, TASK_CONFIGURE_SOFT, PARAMS } = Constants; const { executeAsync } = Exec; -const BUNDLER_PLATFORMS = {}; +const BUNDLER_PLATFORMS: Record = {}; BUNDLER_PLATFORMS[MACOS] = MACOS; -export const taskRnvStart = async (c, parentTask, originTask) => { +export const taskRnvStart: RnvTaskFn = async (c, parentTask, originTask) => { const { platform } = c; const { hosted } = c.program; From 2f394e3aa73e398ab607a2bc310ea5472bfd3731 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 02:27:30 +0200 Subject: [PATCH 67/83] update ts configs --- packages/engine-lightning/tsconfig.json | 3 ++- packages/engine-rn-windows/tsconfig.json | 4 ++-- packages/engine-rn/tsconfig.json | 3 ++- packages/engine-roku/tsconfig.json | 4 ++-- packages/integration-docker/tsconfig.json | 4 ++-- packages/integration-ftp/tsconfig.json | 4 ++-- packages/integration-terraform/tsconfig.json | 4 ++-- packages/integration-vercel/tsconfig.json | 4 ++-- 8 files changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/engine-lightning/tsconfig.json b/packages/engine-lightning/tsconfig.json index 47fc361091..cf64fd612c 100644 --- a/packages/engine-lightning/tsconfig.json +++ b/packages/engine-lightning/tsconfig.json @@ -5,5 +5,6 @@ "rootDir": "./src", "resolveJsonModule": false }, - "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"] + "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"], + "exclude": ["node_modules", "./src/__tests__", "./dist/**/*"] } diff --git a/packages/engine-rn-windows/tsconfig.json b/packages/engine-rn-windows/tsconfig.json index eef5815c2f..cf64fd612c 100644 --- a/packages/engine-rn-windows/tsconfig.json +++ b/packages/engine-rn-windows/tsconfig.json @@ -3,8 +3,8 @@ "compilerOptions": { "outDir": "./dist", "rootDir": "./src", - "allowJs": true, "resolveJsonModule": false }, - "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"] + "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"], + "exclude": ["node_modules", "./src/__tests__", "./dist/**/*"] } diff --git a/packages/engine-rn/tsconfig.json b/packages/engine-rn/tsconfig.json index 47fc361091..cf64fd612c 100644 --- a/packages/engine-rn/tsconfig.json +++ b/packages/engine-rn/tsconfig.json @@ -5,5 +5,6 @@ "rootDir": "./src", "resolveJsonModule": false }, - "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"] + "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"], + "exclude": ["node_modules", "./src/__tests__", "./dist/**/*"] } diff --git a/packages/engine-roku/tsconfig.json b/packages/engine-roku/tsconfig.json index eef5815c2f..cf64fd612c 100644 --- a/packages/engine-roku/tsconfig.json +++ b/packages/engine-roku/tsconfig.json @@ -3,8 +3,8 @@ "compilerOptions": { "outDir": "./dist", "rootDir": "./src", - "allowJs": true, "resolveJsonModule": false }, - "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"] + "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"], + "exclude": ["node_modules", "./src/__tests__", "./dist/**/*"] } diff --git a/packages/integration-docker/tsconfig.json b/packages/integration-docker/tsconfig.json index eef5815c2f..cf64fd612c 100644 --- a/packages/integration-docker/tsconfig.json +++ b/packages/integration-docker/tsconfig.json @@ -3,8 +3,8 @@ "compilerOptions": { "outDir": "./dist", "rootDir": "./src", - "allowJs": true, "resolveJsonModule": false }, - "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"] + "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"], + "exclude": ["node_modules", "./src/__tests__", "./dist/**/*"] } diff --git a/packages/integration-ftp/tsconfig.json b/packages/integration-ftp/tsconfig.json index eef5815c2f..cf64fd612c 100644 --- a/packages/integration-ftp/tsconfig.json +++ b/packages/integration-ftp/tsconfig.json @@ -3,8 +3,8 @@ "compilerOptions": { "outDir": "./dist", "rootDir": "./src", - "allowJs": true, "resolveJsonModule": false }, - "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"] + "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"], + "exclude": ["node_modules", "./src/__tests__", "./dist/**/*"] } diff --git a/packages/integration-terraform/tsconfig.json b/packages/integration-terraform/tsconfig.json index eef5815c2f..cf64fd612c 100644 --- a/packages/integration-terraform/tsconfig.json +++ b/packages/integration-terraform/tsconfig.json @@ -3,8 +3,8 @@ "compilerOptions": { "outDir": "./dist", "rootDir": "./src", - "allowJs": true, "resolveJsonModule": false }, - "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"] + "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"], + "exclude": ["node_modules", "./src/__tests__", "./dist/**/*"] } diff --git a/packages/integration-vercel/tsconfig.json b/packages/integration-vercel/tsconfig.json index eef5815c2f..cf64fd612c 100644 --- a/packages/integration-vercel/tsconfig.json +++ b/packages/integration-vercel/tsconfig.json @@ -3,8 +3,8 @@ "compilerOptions": { "outDir": "./dist", "rootDir": "./src", - "allowJs": true, "resolveJsonModule": false }, - "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"] + "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"], + "exclude": ["node_modules", "./src/__tests__", "./dist/**/*"] } From f21d1238b6e5f0471aa53fa648b79354bf717b47 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 02:29:27 +0200 Subject: [PATCH 68/83] ts integration-vercel --- .../src/{index.js => index.ts} | 1 + ...el.deploy.js => task.rnv.vercel.deploy.ts} | 22 ++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) rename packages/integration-vercel/src/{index.js => index.ts} (94%) rename packages/integration-vercel/src/tasks/{task.rnv.vercel.deploy.js => task.rnv.vercel.deploy.ts} (83%) diff --git a/packages/integration-vercel/src/index.js b/packages/integration-vercel/src/index.ts similarity index 94% rename from packages/integration-vercel/src/index.js rename to packages/integration-vercel/src/index.ts index 8052db178f..e3f472b08b 100644 --- a/packages/integration-vercel/src/index.js +++ b/packages/integration-vercel/src/index.ts @@ -1,4 +1,5 @@ import taskRnvVercelDeploy from './tasks/task.rnv.vercel.deploy'; +//@ts-ignore import config from '../renative.integration.json'; const TASKS = [taskRnvVercelDeploy]; diff --git a/packages/integration-vercel/src/tasks/task.rnv.vercel.deploy.js b/packages/integration-vercel/src/tasks/task.rnv.vercel.deploy.ts similarity index 83% rename from packages/integration-vercel/src/tasks/task.rnv.vercel.deploy.js rename to packages/integration-vercel/src/tasks/task.rnv.vercel.deploy.ts index 30b9b634db..cf2e9ad16b 100644 --- a/packages/integration-vercel/src/tasks/task.rnv.vercel.deploy.js +++ b/packages/integration-vercel/src/tasks/task.rnv.vercel.deploy.ts @@ -2,7 +2,7 @@ import path from 'path'; import inquirer from 'inquirer'; import dotenv from 'dotenv'; -import { Logger, Constants, FileUtils, Exec, Common } from 'rnv'; +import { Logger, Constants, FileUtils, Exec, Common, RnvContext } from 'rnv'; const { fsExistsSync, fsWriteFileSync, fsReadFileSync } = FileUtils; const { executeAsync } = Exec; @@ -11,13 +11,10 @@ const { chalk, logInfo, logTask } = Logger; const { PARAMS, WEB } = Constants; -const _runDeploymentTask = (c, nowConfigPath) => - new Promise((resolve, reject) => { +const _runDeploymentTask = (c: RnvContext, nowConfigPath: string) => + new Promise((resolve, reject) => { dotenv.config(); - const defaultBuildFolder = path.join( - getAppFolder(c, c.platform), - c.platform.includes('next') ? 'out' : 'public' - ); + const defaultBuildFolder = path.join(getAppFolder(c), c.platform.includes('next') ? 'out' : 'public'); const params = [defaultBuildFolder, '-A', nowConfigPath]; if (process.env.NOW_TOKEN) params.push('-t', process.env.NOW_TOKEN); const nowIsProduction = getConfigProp(c, c.platform, 'nowIsProduction', false) === true; @@ -29,10 +26,15 @@ const _runDeploymentTask = (c, nowConfigPath) => .catch((error) => reject(error)); }); -const _createConfigFiles = async (configFilePath, envConfigPath, nowParamsExists = false, _envContent = '') => { +const _createConfigFiles = async ( + configFilePath: string, + envConfigPath: string, + nowParamsExists = false, + _envContent = '' +) => { let envContent = _envContent; if (!fsExistsSync(configFilePath)) { - const content = { public: true, version: 2 }; + const content = { public: true, version: 2, name: '' }; logInfo(`${chalk().white('now.json')} file does not exist. Creating one for you`); const { name } = await inquirer.prompt([ @@ -67,7 +69,7 @@ const _createConfigFiles = async (configFilePath, envConfigPath, nowParamsExists } }; -export const taskRnvVercelDeploy = async (c) => { +export const taskRnvVercelDeploy = async (c: RnvContext) => { logTask('taskRnvVercelDeploy'); const nowConfigPath = path.resolve(c.paths.project.dir, 'configs', `now.${c.platform}.json`); From 6d90dd7ee4d9b11153c1172948367296892e9103 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 02:33:30 +0200 Subject: [PATCH 69/83] ts terraform --- .../integration-terraform/src/{index.js => index.ts} | 0 ...rraform.deploy.js => task.rnv.terraform.deploy.ts} | 10 +++++----- ...aform.destroy.js => task.rnv.terraform.destroy.ts} | 6 +++--- ...rraform.status.js => task.rnv.terraform.status.ts} | 11 ++++++----- 4 files changed, 14 insertions(+), 13 deletions(-) rename packages/integration-terraform/src/{index.js => index.ts} (100%) rename packages/integration-terraform/src/tasks/{task.rnv.terraform.deploy.js => task.rnv.terraform.deploy.ts} (90%) rename packages/integration-terraform/src/tasks/{task.rnv.terraform.destroy.js => task.rnv.terraform.destroy.ts} (86%) rename packages/integration-terraform/src/tasks/{task.rnv.terraform.status.js => task.rnv.terraform.status.ts} (80%) diff --git a/packages/integration-terraform/src/index.js b/packages/integration-terraform/src/index.ts similarity index 100% rename from packages/integration-terraform/src/index.js rename to packages/integration-terraform/src/index.ts diff --git a/packages/integration-terraform/src/tasks/task.rnv.terraform.deploy.js b/packages/integration-terraform/src/tasks/task.rnv.terraform.deploy.ts similarity index 90% rename from packages/integration-terraform/src/tasks/task.rnv.terraform.deploy.js rename to packages/integration-terraform/src/tasks/task.rnv.terraform.deploy.ts index a78ccfd1aa..9b4e77fe2d 100644 --- a/packages/integration-terraform/src/tasks/task.rnv.terraform.deploy.js +++ b/packages/integration-terraform/src/tasks/task.rnv.terraform.deploy.ts @@ -2,7 +2,7 @@ import path from 'path'; import lSet from 'lodash/set'; import lGet from 'lodash/get'; -import { Logger, Constants, FileUtils, Exec } from 'rnv'; +import { Logger, Constants, FileUtils, Exec, RnvContext } from 'rnv'; const { fsExistsSync, writeFileSync, fsReadFileSync, fsWriteFileSync } = FileUtils; const { executeAsync, commandExistsSync } = Exec; @@ -10,7 +10,7 @@ const { logInfo, logTask, logError, logSuccess } = Logger; const { PARAMS } = Constants; -const _checkPrereqs = (c) => { +const _checkPrereqs = (c: RnvContext) => { const backendFolder = path.resolve(c.paths.project.dir, 'backend'); if (!fsExistsSync(backendFolder)) { @@ -32,7 +32,7 @@ const _checkPrereqs = (c) => { } }; -export const taskRnvTerraformDeploy = async (c) => { +export const taskRnvTerraformDeploy = async (c: RnvContext) => { logTask('taskRnvTerraformDeploy'); // let's see if you're good to go @@ -63,12 +63,12 @@ export const taskRnvTerraformDeploy = async (c) => { logInfo('Terraform deployment complete'); - const tfStateFile = JSON.parse(FileUtils.fsReadFileSync(tfStateFilePath)); + const tfStateFile = JSON.parse(FileUtils.fsReadFileSync(tfStateFilePath).toString()); c.buildConfig.requiredBackendOutputs?.forEach((output) => { const value = lGet(tfStateFile, output.fromKey); const targetFile = path.join(c.paths.project.dir, output.toFile); - const targetFileContent = fsReadFileSync(targetFile); + const targetFileContent = fsReadFileSync(targetFile).toString(); const targetFileContentJson = JSON.parse(targetFileContent); lSet(targetFileContentJson, output.toKey, value); writeFileSync(targetFile, targetFileContentJson); diff --git a/packages/integration-terraform/src/tasks/task.rnv.terraform.destroy.js b/packages/integration-terraform/src/tasks/task.rnv.terraform.destroy.ts similarity index 86% rename from packages/integration-terraform/src/tasks/task.rnv.terraform.destroy.js rename to packages/integration-terraform/src/tasks/task.rnv.terraform.destroy.ts index 4db5afef32..85f7539573 100644 --- a/packages/integration-terraform/src/tasks/task.rnv.terraform.destroy.js +++ b/packages/integration-terraform/src/tasks/task.rnv.terraform.destroy.ts @@ -1,6 +1,6 @@ import path from 'path'; -import { Logger, Constants, FileUtils, Exec } from 'rnv'; +import { Logger, Constants, FileUtils, Exec, RnvContext } from 'rnv'; const { fsExistsSync } = FileUtils; const { executeAsync, commandExistsSync } = Exec; @@ -8,7 +8,7 @@ const { logSuccess, logTask, logError } = Logger; const { PARAMS } = Constants; -const _checkPrereqs = (c) => { +const _checkPrereqs = (c: RnvContext) => { const backendFolder = path.resolve(c.paths.project.dir, 'backend'); if (!fsExistsSync(backendFolder)) { @@ -23,7 +23,7 @@ const _checkPrereqs = (c) => { } }; -export const taskRnvTerraformDestroy = async (c) => { +export const taskRnvTerraformDestroy = async (c: RnvContext) => { logTask('taskRnvTerraformDestroy'); // let's see if you're good to go diff --git a/packages/integration-terraform/src/tasks/task.rnv.terraform.status.js b/packages/integration-terraform/src/tasks/task.rnv.terraform.status.ts similarity index 80% rename from packages/integration-terraform/src/tasks/task.rnv.terraform.status.js rename to packages/integration-terraform/src/tasks/task.rnv.terraform.status.ts index 9623d8971c..4aae4884b6 100644 --- a/packages/integration-terraform/src/tasks/task.rnv.terraform.status.js +++ b/packages/integration-terraform/src/tasks/task.rnv.terraform.status.ts @@ -1,6 +1,6 @@ import path from 'path'; -import { Logger, Constants, FileUtils, Exec } from 'rnv'; +import { Logger, Constants, FileUtils, Exec, RnvContext } from 'rnv'; const { fsExistsSync } = FileUtils; const { executeAsync, commandExistsSync } = Exec; @@ -8,7 +8,7 @@ const { logSuccess, logTask, logError } = Logger; const { PARAMS } = Constants; -const _checkPrereqs = (c) => { +const _checkPrereqs = (c: RnvContext) => { const backendFolder = path.resolve(c.paths.project.dir, 'backend'); if (!fsExistsSync(backendFolder)) { @@ -23,7 +23,7 @@ const _checkPrereqs = (c) => { } }; -export const taskRnvTerraformStatus = async (c) => { +export const taskRnvTerraformStatus = async (c: RnvContext) => { logTask('taskRnvTerraformStatus'); // let's see if you're good to go @@ -31,15 +31,16 @@ export const taskRnvTerraformStatus = async (c) => { const backendFolder = path.resolve(c.paths.project.dir, 'backend'); + const jp: any = JSON.parse; const lines = ( await executeAsync(c, 'terraform plan --json', { cwd: backendFolder, }) ) .split('\n') - .map(JSON.parse); + .map(jp); - const changeSummary = lines.filter((line) => line.type === 'change_summary'); + const changeSummary: any = lines.filter((line: any) => line.type === 'change_summary'); if (!changeSummary) { return logError('Could not get change summary from terraform plan', true); From 28e6065996b82cf9d3062511488483269ecd97b2 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 02:44:25 +0200 Subject: [PATCH 70/83] integration ftp TS migration --- .../src/{index.js => index.ts} | 1 + ...v.ftp.deploy.js => task.rnv.ftp.deploy.ts} | 36 ++++++++++--------- packages/rnv/src/core/configManager/types.ts | 18 ++++++++++ 3 files changed, 38 insertions(+), 17 deletions(-) rename packages/integration-ftp/src/{index.js => index.ts} (94%) rename packages/integration-ftp/src/tasks/{task.rnv.ftp.deploy.js => task.rnv.ftp.deploy.ts} (79%) diff --git a/packages/integration-ftp/src/index.js b/packages/integration-ftp/src/index.ts similarity index 94% rename from packages/integration-ftp/src/index.js rename to packages/integration-ftp/src/index.ts index 4a6e2593a3..73271b0400 100644 --- a/packages/integration-ftp/src/index.js +++ b/packages/integration-ftp/src/index.ts @@ -1,4 +1,5 @@ import taskRnvVercelDeploy from './tasks/task.rnv.ftp.deploy'; +//@ts-ignore import config from '../renative.integration.json'; const TASKS = [taskRnvVercelDeploy]; diff --git a/packages/integration-ftp/src/tasks/task.rnv.ftp.deploy.js b/packages/integration-ftp/src/tasks/task.rnv.ftp.deploy.ts similarity index 79% rename from packages/integration-ftp/src/tasks/task.rnv.ftp.deploy.js rename to packages/integration-ftp/src/tasks/task.rnv.ftp.deploy.ts index 920a7d081c..5acbe19596 100644 --- a/packages/integration-ftp/src/tasks/task.rnv.ftp.deploy.js +++ b/packages/integration-ftp/src/tasks/task.rnv.ftp.deploy.ts @@ -1,7 +1,7 @@ import path from 'path'; import inquirer from 'inquirer'; -import { Logger, Constants, FileUtils } from 'rnv'; +import { Logger, Constants, FileUtils, RnvContext } from 'rnv'; const { PARAMS, WEB } = Constants; const { logTask, logInfo } = Logger; @@ -11,7 +11,7 @@ const DEPLOY_TARGET_FTP = 'ftp'; const FtpDeploy = require('ftp-deploy'); const dotEnv = require('dotenv'); -const _deployToFtp = (c, platform) => +const _deployToFtp = (c: RnvContext, platform: string) => new Promise((resolve, reject) => { logTask('_deployToFtp'); let promise; @@ -21,20 +21,20 @@ const _deployToFtp = (c, platform) => promise = _createEnvFtpConfig(envPath); } else { promise = new Promise((resolve2) => { - fsReadFile(envPath, (err, data) => { + fsReadFile(envPath, (err: any, data: any) => { if (err) return reject(err); resolve2(data.toString()); }); }); } promise - .then((envContent) => { + .then((envContent: any) => { let matches = 0; const targetMatches = 2; envContent .split('\n') - .map((line) => line.split('=')) - .forEach(([key]) => { + .map((line: string) => line.split('=')) + .forEach(([key]: any) => { if (['RNV_DEPLOY_WEB_FTP_SERVER', 'RNV_DEPLOY_WEB_FTP_USER'].indexOf(key) > -1) { matches++; } @@ -55,12 +55,12 @@ const _deployToFtp = (c, platform) => password: process.env.RNV_DEPLOY_WEB_FTP_PASSWORD, // optional, prompted if none given host: process.env.RNV_DEPLOY_WEB_FTP_SERVER, port: process.env.RNV_DEPLOY_WEB_FTP_PORT || 21, - localRoot: c.buildConfig.platforms[platform].deploy[DEPLOY_TARGET_FTP].localRoot, - remoteRoot: c.buildConfig.platforms[platform].deploy[DEPLOY_TARGET_FTP].remoteRoot || '/', - include: c.buildConfig.platforms[platform].deploy[DEPLOY_TARGET_FTP].include || ['*', '**/*'], // this would upload everything except dot files - exclude: c.buildConfig.platforms[platform].deploy[DEPLOY_TARGET_FTP].exclude || [], // e.g. exclude sourcemaps - ** exclude: [] if nothing to exclude ** + localRoot: c.buildConfig.platforms?.[platform].deploy?.[DEPLOY_TARGET_FTP]?.localRoot, + remoteRoot: c.buildConfig.platforms?.[platform].deploy?.[DEPLOY_TARGET_FTP]?.remoteRoot || '/', + include: c.buildConfig.platforms?.[platform].deploy?.[DEPLOY_TARGET_FTP]?.include || ['*', '**/*'], // this would upload everything except dot files + exclude: c.buildConfig.platforms?.[platform].deploy?.[DEPLOY_TARGET_FTP]?.exclude || [], // e.g. exclude sourcemaps - ** exclude: [] if nothing to exclude ** deleteRemote: - c.buildConfig.platforms[platform].deploy[DEPLOY_TARGET_FTP].exclude.deleteRemote || false, // delete ALL existing files at destination before uploading, if true + c.buildConfig.platforms?.[platform].deploy?.[DEPLOY_TARGET_FTP]?.deleteRemote || false, // delete ALL existing files at destination before uploading, if true forcePasv: true, // Passive mode is forced (EPSV command is not sent) }; return config; @@ -72,7 +72,7 @@ const _deployToFtp = (c, platform) => .catch(reject); }); -const _createEnvFtpConfig = async (configFilePath, previousContent = '') => { +const _createEnvFtpConfig = async (configFilePath: string, previousContent = '') => { let envContent = previousContent || ''; const { host, user, password, port } = await inquirer.prompt([ @@ -111,10 +111,10 @@ const _createEnvFtpConfig = async (configFilePath, previousContent = '') => { logInfo(`Writing .env config to ${configFilePath}`); }; -const _createDeployConfig = async (c, platform) => { +const _createDeployConfig = async (c: RnvContext, platform: string) => { logTask('_createDeployConfig'); - const deploy = c.buildConfig.platforms[platform].deploy || {}; + const deploy = c.buildConfig.platforms?.[platform].deploy || {}; deploy[DEPLOY_TARGET_FTP] = {}; deploy[DEPLOY_TARGET_FTP].type = DEPLOY_TARGET_FTP; @@ -155,7 +155,9 @@ const _createDeployConfig = async (c, platform) => { deploy[DEPLOY_TARGET_FTP].deleteRemote = deleteRemote; deploy[DEPLOY_TARGET_FTP].include = include ? include.split(',') : ['*', '**/*']; deploy[DEPLOY_TARGET_FTP].exclude = exclude ? exclude.split(',') : []; - deploy[DEPLOY_TARGET_FTP].exclude = deploy[DEPLOY_TARGET_FTP].exclude.concat(excludeSourcemaps ? ['**/*.map'] : []); + deploy[DEPLOY_TARGET_FTP].exclude = deploy?.[DEPLOY_TARGET_FTP]?.exclude?.concat( + excludeSourcemaps ? ['**/*.map'] : [] + ); logInfo(`Setting your appconfig for ${platform} to include deploy type: ${DEPLOY_TARGET_FTP} on ${c.paths.appConfig.config} @@ -166,9 +168,9 @@ const _createDeployConfig = async (c, platform) => { writeFileSync(c.paths.appConfig.config, c.files.appConfig.config); }; -const taskRnvFtpDeploy = (c) => { +const taskRnvFtpDeploy = (c: RnvContext) => { logTask('taskRnvFtpDeploy'); - const targetConfig = c.buildConfig.platforms[c.platform]; + const targetConfig = c.buildConfig.platforms?.[c.platform]; if (targetConfig?.deploy?.[DEPLOY_TARGET_FTP]?.type) { return _deployToFtp(c, c.platform); } diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index cd08d2818a..323cd10024 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -41,6 +41,13 @@ export type RenativeConfigFile = { enableAnalytics?: boolean; workspaceAppConfigsDir?: string; permissions: Record; + //Integrations + requiredBackendOutputs?: Array<{ + toKey: string; + toFile: string; + fromKey: string; + }>; + backendServiceConfig: any; }; export type RenativeConfigPermission = Record>; @@ -79,6 +86,17 @@ export type RenativeConfigPlatform = { }; //Tizen package?: string; + //Integration ftp + deploy?: { + ftp?: { + type?: string; + localRoot?: string; + remoteRoot?: string; + include?: string[]; + exclude?: string[]; + deleteRemote?: boolean; + }; + }; }; export type RenativeConfigPermissionsList = Array; From 56f56dc67e2029fa1f36d9d2f7336d8045d17922 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 02:48:15 +0200 Subject: [PATCH 71/83] ts integration docker --- .../src/{docker.js => docker.ts} | 19 ++++++++++--------- .../src/{index.js => index.ts} | 1 + ...er.deploy.js => task.rnv.docker.deploy.ts} | 6 +++--- ...er.export.js => task.rnv.docker.export.ts} | 6 +++--- .../rnv/src/core/systemManager/fileutils.ts | 4 ++-- 5 files changed, 19 insertions(+), 17 deletions(-) rename packages/integration-docker/src/{docker.js => docker.ts} (92%) rename packages/integration-docker/src/{index.js => index.ts} (96%) rename packages/integration-docker/src/tasks/{task.rnv.docker.deploy.js => task.rnv.docker.deploy.ts} (77%) rename packages/integration-docker/src/tasks/{task.rnv.docker.export.js => task.rnv.docker.export.ts} (77%) diff --git a/packages/integration-docker/src/docker.js b/packages/integration-docker/src/docker.ts similarity index 92% rename from packages/integration-docker/src/docker.js rename to packages/integration-docker/src/docker.ts index dccdface44..cb396235b0 100644 --- a/packages/integration-docker/src/docker.js +++ b/packages/integration-docker/src/docker.ts @@ -1,6 +1,6 @@ import path from 'path'; import chalk from 'chalk'; -import { Logger, Common, Exec, Prompt, FileUtils } from 'rnv'; +import { Logger, Common, Exec, Prompt, FileUtils, RnvContext } from 'rnv'; const { logTask, logInfo, logSuccess } = Logger; const { executeAsync, commandExistsSync } = Exec; @@ -11,7 +11,8 @@ const { copyFolderRecursiveSync, cleanFolder, writeCleanFile, fsExistsSync } = F const rootPath = path.join(__dirname, './'); class Docker { - constructor(c) { + c: RnvContext; + constructor(c: RnvContext) { this.c = c; } @@ -19,12 +20,12 @@ class Docker { const { c } = this; const { runtime, platform, files } = c; let outputDir = 'output'; - let projectBuildWeb = path.join(getPlatformBuildDir(c), outputDir); + let projectBuildWeb = path.join(getPlatformBuildDir(c)!, outputDir); if (!fsExistsSync(projectBuildWeb)) { outputDir = 'project'; - projectBuildWeb = path.join(getPlatformBuildDir(c), outputDir); + projectBuildWeb = path.join(getPlatformBuildDir(c)!, outputDir); } - const dockerDestination = path.join(getPlatformBuildDir(c), 'export', 'docker'); + const dockerDestination = path.join(getPlatformBuildDir(c)!, 'export', 'docker'); const dockerFile = path.join(rootPath, '../Dockerfile'); const nginxConfFile = path.join(rootPath, '../nginx/default.conf'); @@ -39,7 +40,7 @@ class Docker { const copiedDockerComposeBuildFile = path.join(dockerDestination, 'docker-compose.build.yml'); const copiedDockerComposeFile = path.join(dockerDestination, 'docker-compose.yml'); - const imageName = runtime.appId.toLowerCase(); + const imageName = runtime.appId?.toLowerCase(); const appVersion = files.project.package.version; // save the docker files @@ -79,10 +80,10 @@ class Docker { program: { scheme = 'debug' }, } = c; - const imageName = runtime.appId.toLowerCase(); + const imageName = runtime.appId?.toLowerCase(); const appVersion = files.project.package.version; - const dockerDestination = path.join(getPlatformBuildDir(c), 'export', 'docker'); + const dockerDestination = path.join(getPlatformBuildDir(c)!, 'export', 'docker'); const dockerSaveFile = path.join(dockerDestination, `${imageName}_${appVersion}.tar`); logTask('docker:Dockerfile:build'); @@ -157,7 +158,7 @@ class Docker { } } - const imageName = runtime.appId.toLowerCase(); + const imageName = runtime.appId?.toLowerCase(); const imageTag = `${DOCKERHUB_USER}/${imageName}`; const appVersion = files.project.package.version; diff --git a/packages/integration-docker/src/index.js b/packages/integration-docker/src/index.ts similarity index 96% rename from packages/integration-docker/src/index.js rename to packages/integration-docker/src/index.ts index 5a36266798..395629c86d 100644 --- a/packages/integration-docker/src/index.js +++ b/packages/integration-docker/src/index.ts @@ -1,5 +1,6 @@ import taskRnvDockerDeploy from './tasks/task.rnv.docker.deploy'; import taskRnvDockerExport from './tasks/task.rnv.docker.export'; +//@ts-ignore import config from '../renative.integration.json'; const TASKS = [taskRnvDockerExport, taskRnvDockerDeploy]; diff --git a/packages/integration-docker/src/tasks/task.rnv.docker.deploy.js b/packages/integration-docker/src/tasks/task.rnv.docker.deploy.ts similarity index 77% rename from packages/integration-docker/src/tasks/task.rnv.docker.deploy.js rename to packages/integration-docker/src/tasks/task.rnv.docker.deploy.ts index 5babb72af8..c67f24772f 100644 --- a/packages/integration-docker/src/tasks/task.rnv.docker.deploy.js +++ b/packages/integration-docker/src/tasks/task.rnv.docker.deploy.ts @@ -1,11 +1,11 @@ -import { Logger, Constants, TaskManager } from 'rnv'; +import { Logger, Constants, TaskManager, RnvTaskFn } from 'rnv'; import Docker from '../docker'; const { logTask } = Logger; const { PARAMS, WEB, TASK_EXPORT } = Constants; const { executeOrSkipTask, initializeTask, findSuitableTask } = TaskManager; -export const taskRnvDockerDeploy = async (c, parentTask, originTask) => { +export const taskRnvDockerDeploy: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvDockerDeploy', `parent:${parentTask}`); if (c.program.only) { @@ -13,7 +13,7 @@ export const taskRnvDockerDeploy = async (c, parentTask, originTask) => { await executeOrSkipTask(c, TASK_EXPORT, 'docker export', originTask); } else { const taskInstance = await findSuitableTask(c, TASK_EXPORT); - await initializeTask(c, taskInstance.task); + if (taskInstance) await initializeTask(c, taskInstance.task); } const docker = new Docker(c); diff --git a/packages/integration-docker/src/tasks/task.rnv.docker.export.js b/packages/integration-docker/src/tasks/task.rnv.docker.export.ts similarity index 77% rename from packages/integration-docker/src/tasks/task.rnv.docker.export.js rename to packages/integration-docker/src/tasks/task.rnv.docker.export.ts index 0c086886dc..ea54d4f9f7 100644 --- a/packages/integration-docker/src/tasks/task.rnv.docker.export.js +++ b/packages/integration-docker/src/tasks/task.rnv.docker.export.ts @@ -1,11 +1,11 @@ -import { Logger, Constants, TaskManager } from 'rnv'; +import { Logger, Constants, TaskManager, RnvTaskFn } from 'rnv'; import Docker from '../docker'; const { logTask } = Logger; const { PARAMS, WEB, TASK_EXPORT } = Constants; const { executeOrSkipTask, initializeTask, findSuitableTask } = TaskManager; -export const taskRnvDockerExport = async (c, parentTask, originTask) => { +export const taskRnvDockerExport: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvDockerExport', `parent:${parentTask}`); if (c.program.only) { @@ -13,7 +13,7 @@ export const taskRnvDockerExport = async (c, parentTask, originTask) => { await executeOrSkipTask(c, TASK_EXPORT, 'docker export', originTask); } else { const taskInstance = await findSuitableTask(c, TASK_EXPORT); - await initializeTask(c, taskInstance.task); + if (taskInstance) await initializeTask(c, taskInstance.task); } const docker = new Docker(c); diff --git a/packages/rnv/src/core/systemManager/fileutils.ts b/packages/rnv/src/core/systemManager/fileutils.ts index 0259280483..886b6d6e27 100755 --- a/packages/rnv/src/core/systemManager/fileutils.ts +++ b/packages/rnv/src/core/systemManager/fileutils.ts @@ -187,7 +187,7 @@ export const readCleanFile = (source: string, overrides?: OverridesOptions) => { export const copyFileWithInjectSync = ( source: string, target: string, - skipOverride: boolean, + skipOverride?: boolean, injectObject?: OverridesOptions, timestampPathsConfig?: TimestampPathsConfig, c?: RnvContext @@ -231,7 +231,7 @@ export const copyFolderRecursiveSync = ( source: string, target: string, convertSvg = true, - skipOverride: boolean, + skipOverride?: boolean, injectObject?: OverridesOptions, timestampPathsConfig?: TimestampPathsConfig, c?: RnvContext, From 6442f0050b99dfccfaf7f832c8f83c499d34c771 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 02:53:12 +0200 Subject: [PATCH 72/83] reaftor engine windows to ts --- .../src/{adapter.0.64.js => adapter.0.64.ts} | 0 packages/engine-rn-windows/src/{adapter.js => adapter.ts} | 0 .../src/{commonEngine.js => commonEngine.ts} | 0 packages/engine-rn-windows/src/{index.js => index.ts} | 0 packages/engine-rn-windows/src/sdks/{index.js => index.ts} | 0 .../src/tasks/{task.rnv.build.js => task.rnv.build.ts} | 4 ++-- .../tasks/{task.rnv.configure.js => task.rnv.configure.ts} | 4 ++-- .../src/tasks/{task.rnv.debug.js => task.rnv.debug.ts} | 4 ++-- .../src/tasks/{task.rnv.deploy.js => task.rnv.deploy.ts} | 4 ++-- .../src/tasks/{task.rnv.export.js => task.rnv.export.ts} | 4 ++-- .../src/tasks/{task.rnv.package.js => task.rnv.package.ts} | 4 ++-- .../src/tasks/{task.rnv.run.js => task.rnv.run.ts} | 4 ++-- .../src/tasks/{task.rnv.start.js => task.rnv.start.ts} | 6 +++--- packages/engine-rn-windows/tsconfig.json | 1 + packages/engine-roku/src/{index.js => index.ts} | 0 15 files changed, 18 insertions(+), 17 deletions(-) rename packages/engine-rn-windows/src/{adapter.0.64.js => adapter.0.64.ts} (100%) rename packages/engine-rn-windows/src/{adapter.js => adapter.ts} (100%) rename packages/engine-rn-windows/src/{commonEngine.js => commonEngine.ts} (100%) rename packages/engine-rn-windows/src/{index.js => index.ts} (100%) rename packages/engine-rn-windows/src/sdks/{index.js => index.ts} (100%) rename packages/engine-rn-windows/src/tasks/{task.rnv.build.js => task.rnv.build.ts} (84%) rename packages/engine-rn-windows/src/tasks/{task.rnv.configure.js => task.rnv.configure.ts} (85%) rename packages/engine-rn-windows/src/tasks/{task.rnv.debug.js => task.rnv.debug.ts} (77%) rename packages/engine-rn-windows/src/tasks/{task.rnv.deploy.js => task.rnv.deploy.ts} (86%) rename packages/engine-rn-windows/src/tasks/{task.rnv.export.js => task.rnv.export.ts} (86%) rename packages/engine-rn-windows/src/tasks/{task.rnv.package.js => task.rnv.package.ts} (91%) rename packages/engine-rn-windows/src/tasks/{task.rnv.run.js => task.rnv.run.ts} (89%) rename packages/engine-rn-windows/src/tasks/{task.rnv.start.js => task.rnv.start.ts} (94%) rename packages/engine-roku/src/{index.js => index.ts} (100%) diff --git a/packages/engine-rn-windows/src/adapter.0.64.js b/packages/engine-rn-windows/src/adapter.0.64.ts similarity index 100% rename from packages/engine-rn-windows/src/adapter.0.64.js rename to packages/engine-rn-windows/src/adapter.0.64.ts diff --git a/packages/engine-rn-windows/src/adapter.js b/packages/engine-rn-windows/src/adapter.ts similarity index 100% rename from packages/engine-rn-windows/src/adapter.js rename to packages/engine-rn-windows/src/adapter.ts diff --git a/packages/engine-rn-windows/src/commonEngine.js b/packages/engine-rn-windows/src/commonEngine.ts similarity index 100% rename from packages/engine-rn-windows/src/commonEngine.js rename to packages/engine-rn-windows/src/commonEngine.ts diff --git a/packages/engine-rn-windows/src/index.js b/packages/engine-rn-windows/src/index.ts similarity index 100% rename from packages/engine-rn-windows/src/index.js rename to packages/engine-rn-windows/src/index.ts diff --git a/packages/engine-rn-windows/src/sdks/index.js b/packages/engine-rn-windows/src/sdks/index.ts similarity index 100% rename from packages/engine-rn-windows/src/sdks/index.js rename to packages/engine-rn-windows/src/sdks/index.ts diff --git a/packages/engine-rn-windows/src/tasks/task.rnv.build.js b/packages/engine-rn-windows/src/tasks/task.rnv.build.ts similarity index 84% rename from packages/engine-rn-windows/src/tasks/task.rnv.build.js rename to packages/engine-rn-windows/src/tasks/task.rnv.build.ts index f4f1b3eb1f..02037679cb 100644 --- a/packages/engine-rn-windows/src/tasks/task.rnv.build.js +++ b/packages/engine-rn-windows/src/tasks/task.rnv.build.ts @@ -1,4 +1,4 @@ -import { Constants, Logger, TaskManager, PlatformManager } from 'rnv'; +import { Constants, Logger, TaskManager, PlatformManager, RnvTaskFn } from 'rnv'; import { SDKWindows } from '../sdks'; const { logErrorPlatform } = PlatformManager; @@ -7,7 +7,7 @@ const { WINDOWS, XBOX, TASK_BUILD, TASK_PACKAGE, PARAMS } = Constants; const { ruWindowsProject } = SDKWindows; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvBuild = async (c, parentTask, originTask) => { +export const taskRnvBuild: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvBuild'); const { platform } = c; diff --git a/packages/engine-rn-windows/src/tasks/task.rnv.configure.js b/packages/engine-rn-windows/src/tasks/task.rnv.configure.ts similarity index 85% rename from packages/engine-rn-windows/src/tasks/task.rnv.configure.js rename to packages/engine-rn-windows/src/tasks/task.rnv.configure.ts index 504e29fe26..b295567769 100644 --- a/packages/engine-rn-windows/src/tasks/task.rnv.configure.js +++ b/packages/engine-rn-windows/src/tasks/task.rnv.configure.ts @@ -1,4 +1,4 @@ -import { Constants, Logger, PlatformManager, TaskManager, TemplateManager } from 'rnv'; +import { Constants, Logger, PlatformManager, RnvTaskFn, TaskManager, TemplateManager } from 'rnv'; import { SDKWindows } from '../sdks'; const { logErrorPlatform, copySharedPlatforms } = PlatformManager; @@ -9,7 +9,7 @@ const { configureWindowsProject } = SDKWindows; const { executeTask, shouldSkipTask } = TaskManager; const { configureEntryPoint } = TemplateManager; -export const taskRnvConfigure = async (c, parentTask, originTask) => { +export const taskRnvConfigure: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvConfigure'); await executeTask(c, TASK_PLATFORM_CONFIGURE, TASK_CONFIGURE, originTask); diff --git a/packages/engine-rn-windows/src/tasks/task.rnv.debug.js b/packages/engine-rn-windows/src/tasks/task.rnv.debug.ts similarity index 77% rename from packages/engine-rn-windows/src/tasks/task.rnv.debug.js rename to packages/engine-rn-windows/src/tasks/task.rnv.debug.ts index 3aeea71d31..27c6809ee6 100644 --- a/packages/engine-rn-windows/src/tasks/task.rnv.debug.js +++ b/packages/engine-rn-windows/src/tasks/task.rnv.debug.ts @@ -1,10 +1,10 @@ -import { Constants, Logger, PlatformManager } from 'rnv'; +import { Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; const { logErrorPlatform } = PlatformManager; const { logTask } = Logger; const { PARAMS } = Constants; -export const taskRnvDebug = async (c, parentTask) => { +export const taskRnvDebug: RnvTaskFn = async (c, parentTask) => { logTask('taskRnvDebug', `parent:${parentTask}`); const { platform } = c; diff --git a/packages/engine-rn-windows/src/tasks/task.rnv.deploy.js b/packages/engine-rn-windows/src/tasks/task.rnv.deploy.ts similarity index 86% rename from packages/engine-rn-windows/src/tasks/task.rnv.deploy.js rename to packages/engine-rn-windows/src/tasks/task.rnv.deploy.ts index e2e00ada03..524f2f8358 100644 --- a/packages/engine-rn-windows/src/tasks/task.rnv.deploy.js +++ b/packages/engine-rn-windows/src/tasks/task.rnv.deploy.ts @@ -1,4 +1,4 @@ -import { Constants, Logger, PlatformManager, TaskManager } from 'rnv'; +import { Constants, Logger, PlatformManager, RnvTaskFn, TaskManager } from 'rnv'; import { SDKWindows } from '../sdks'; const { logErrorPlatform } = PlatformManager; @@ -8,7 +8,7 @@ const { WINDOWS, XBOX, TASK_EXPORT, TASK_DEPLOY, PARAMS } = Constants; const { ruWindowsProject } = SDKWindows; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvDeploy = async (c, parentTask, originTask) => { +export const taskRnvDeploy: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvDeploy', `parent:${parentTask}`); const { platform } = c; diff --git a/packages/engine-rn-windows/src/tasks/task.rnv.export.js b/packages/engine-rn-windows/src/tasks/task.rnv.export.ts similarity index 86% rename from packages/engine-rn-windows/src/tasks/task.rnv.export.js rename to packages/engine-rn-windows/src/tasks/task.rnv.export.ts index 579d3c5ad8..f51c08818d 100644 --- a/packages/engine-rn-windows/src/tasks/task.rnv.export.js +++ b/packages/engine-rn-windows/src/tasks/task.rnv.export.ts @@ -1,4 +1,4 @@ -import { Constants, Logger, PlatformManager, TaskManager } from 'rnv'; +import { Constants, Logger, PlatformManager, RnvTaskFn, TaskManager } from 'rnv'; import { SDKWindows } from '../sdks'; const { logErrorPlatform } = PlatformManager; @@ -8,7 +8,7 @@ const { WINDOWS, XBOX, TASK_BUILD, TASK_EXPORT, PARAMS } = Constants; const { packageWindowsApp, clearWindowsTemporaryFiles } = SDKWindows; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvExport = async (c, parentTask, originTask) => { +export const taskRnvExport: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvExport', `parent:${parentTask}`); const { platform } = c; diff --git a/packages/engine-rn-windows/src/tasks/task.rnv.package.js b/packages/engine-rn-windows/src/tasks/task.rnv.package.ts similarity index 91% rename from packages/engine-rn-windows/src/tasks/task.rnv.package.js rename to packages/engine-rn-windows/src/tasks/task.rnv.package.ts index 13d840aecf..3cd6ce6fa7 100644 --- a/packages/engine-rn-windows/src/tasks/task.rnv.package.js +++ b/packages/engine-rn-windows/src/tasks/task.rnv.package.ts @@ -1,4 +1,4 @@ -import { TaskManager, Constants, Logger, PlatformManager, Common } from 'rnv'; +import { TaskManager, Constants, Logger, PlatformManager, Common, RnvTaskFn } from 'rnv'; import { SDKWindows } from '../sdks'; const { logErrorPlatform } = PlatformManager; @@ -8,7 +8,7 @@ const { getConfigProp } = Common; const { packageBundleForWindows } = SDKWindows; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvPackage = async (c, parentTask, originTask) => { +export const taskRnvPackage: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvPackage', `parent:${parentTask}`); const { platform } = c; diff --git a/packages/engine-rn-windows/src/tasks/task.rnv.run.js b/packages/engine-rn-windows/src/tasks/task.rnv.run.ts similarity index 89% rename from packages/engine-rn-windows/src/tasks/task.rnv.run.js rename to packages/engine-rn-windows/src/tasks/task.rnv.run.ts index 0487faee54..17f2ca4378 100644 --- a/packages/engine-rn-windows/src/tasks/task.rnv.run.js +++ b/packages/engine-rn-windows/src/tasks/task.rnv.run.ts @@ -1,4 +1,4 @@ -import { Constants, Logger, PlatformManager, TaskManager } from 'rnv'; +import { Constants, Logger, PlatformManager, RnvTaskFn, TaskManager } from 'rnv'; import { SDKWindows } from '../sdks'; import { startBundlerIfRequired, waitForBundlerIfRequired } from '../commonEngine'; @@ -8,7 +8,7 @@ const { WINDOWS, XBOX, TASK_RUN, TASK_CONFIGURE, PARAMS } = Constants; const { ruWindowsProject, clearWindowsTemporaryFiles } = SDKWindows; const { executeOrSkipTask, shouldSkipTask } = TaskManager; -export const taskRnvRun = async (c, parentTask, originTask) => { +export const taskRnvRun: RnvTaskFn = async (c, parentTask, originTask) => { const { platform } = c; const { port } = c.runtime; const { target } = c.runtime; diff --git a/packages/engine-rn-windows/src/tasks/task.rnv.start.js b/packages/engine-rn-windows/src/tasks/task.rnv.start.ts similarity index 94% rename from packages/engine-rn-windows/src/tasks/task.rnv.start.js rename to packages/engine-rn-windows/src/tasks/task.rnv.start.ts index ebdfbef3ea..9e881908f1 100644 --- a/packages/engine-rn-windows/src/tasks/task.rnv.start.js +++ b/packages/engine-rn-windows/src/tasks/task.rnv.start.ts @@ -1,4 +1,4 @@ -import { TaskManager, EngineManager, Constants, Logger, PlatformManager, Exec, Common, Resolver } from 'rnv'; +import { TaskManager, EngineManager, Constants, Logger, PlatformManager, Exec, Common, Resolver, RnvTaskFn } from 'rnv'; import { isBundlerActive } from '../commonEngine'; const { getEntryFile, confirmActiveBundler } = Common; @@ -10,12 +10,12 @@ const { WINDOWS, XBOX, TASK_START, TASK_CONFIGURE_SOFT, PARAMS } = Constants; const { executeAsync } = Exec; const { doResolve } = Resolver; -const BUNDLER_PLATFORMS = {}; +const BUNDLER_PLATFORMS: Record = {}; BUNDLER_PLATFORMS[WINDOWS] = WINDOWS; BUNDLER_PLATFORMS[XBOX] = WINDOWS; -export const taskRnvStart = async (c, parentTask, originTask) => { +export const taskRnvStart: RnvTaskFn = async (c, parentTask, originTask) => { const { platform } = c; const { hosted } = c.program; diff --git a/packages/engine-rn-windows/tsconfig.json b/packages/engine-rn-windows/tsconfig.json index cf64fd612c..76ccfdb45b 100644 --- a/packages/engine-rn-windows/tsconfig.json +++ b/packages/engine-rn-windows/tsconfig.json @@ -3,6 +3,7 @@ "compilerOptions": { "outDir": "./dist", "rootDir": "./src", + "allowJs": true, "resolveJsonModule": false }, "include": ["./src/**/*", "./src/**/*.json", "./types.d.ts", "./package.json"], diff --git a/packages/engine-roku/src/index.js b/packages/engine-roku/src/index.ts similarity index 100% rename from packages/engine-roku/src/index.js rename to packages/engine-roku/src/index.ts From f4e83aa4e330cfaddbb5275a690270aff7d0cf3f Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 03:01:17 +0200 Subject: [PATCH 73/83] ts fixes --- .../engine-rn-windows/src/adapter.0.64.ts | 19 ++--- packages/engine-rn-windows/src/adapter.ts | 77 +++++++++++-------- .../engine-rn-windows/src/commonEngine.ts | 24 +++--- packages/engine-rn-windows/src/index.ts | 17 ++-- packages/integration-terraform/src/index.ts | 1 + 5 files changed, 81 insertions(+), 57 deletions(-) diff --git a/packages/engine-rn-windows/src/adapter.0.64.ts b/packages/engine-rn-windows/src/adapter.0.64.ts index 8fa3d400ae..a10221c51c 100644 --- a/packages/engine-rn-windows/src/adapter.0.64.ts +++ b/packages/engine-rn-windows/src/adapter.0.64.ts @@ -8,31 +8,32 @@ const sharedBlacklist = [ /.*\/__tests__\/.*/, ]; -function escapeRegExp(pattern) { - if (Object.prototype.toString.call(pattern) === '[object RegExp]') { - return pattern.source.replace(/\//g, path.sep); - } +const env: any = process?.env; + +function escapeRegExp(pattern: RegExp | string) { if (typeof pattern === 'string') { // eslint-disable-next-line const escaped = pattern.replace(/[\-\[\]\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'); // convert the '/' into an escaped local file separator return escaped.replace(/\//g, `\\${path.sep}`); + } else if (Object.prototype.toString.call(pattern) === '[object RegExp]') { + return pattern.source.replace(/\//g, path.sep); } throw new Error(`Unexpected blacklist pattern: ${pattern}`); } -function exclusionList(additionalBlacklist) { +function exclusionList(additionalBlacklist: RegExp[]) { return new RegExp(`(${(additionalBlacklist || []).concat(sharedBlacklist).map(escapeRegExp).join('|')})$`); } -export const withRNV = (config) => { +export const withRNV = (config: any) => { const rnwPath = fs.realpathSync(path.resolve(require.resolve('react-native-windows/package.json'), '..')); const projectPath = process.env.RNV_PROJECT_ROOT || process.cwd(); const watchFolders = [rnwPath, path.resolve(projectPath, 'node_modules')]; - if (process.env.RNV_IS_MONOREPO === 'true' || process.env.RNV_IS_MONOREPO === true) { + if (process.env.RNV_IS_MONOREPO === 'true' || env.RNV_IS_MONOREPO === true) { const monoRootPath = process.env.RNV_MONO_ROOT || projectPath; watchFolders.push(path.resolve(monoRootPath, 'node_modules')); watchFolders.push(path.resolve(monoRootPath, 'packages')); @@ -47,7 +48,7 @@ export const withRNV = (config) => { blockList: exclusionList([ // This stops "react-native run-windows" from causing the metro server to crash if its already running // TODO. Project name should be dynamically injected here somehow - new RegExp(`${process.env.RNV_APP_BUILD_DIR.replace(/[/\\]/g, '/')}.*`), + new RegExp(`${env.RNV_APP_BUILD_DIR.replace(/[/\\]/g, '/')}.*`), // This prevents "react-native run-windows" from hitting: EBUSY: resource busy or locked, open msbuild.ProjectImports.zip /.*\.ProjectImports\.zip/, /platformBuilds\/.*/, @@ -81,7 +82,7 @@ export const withRNV = (config) => { projectRoot: path.resolve(projectPath), }; - cnf.resolver.sourceExts = process.env.RNV_EXTENSIONS.split(','); + cnf.resolver.sourceExts = env.RNV_EXTENSIONS.split(','); return cnf; }; diff --git a/packages/engine-rn-windows/src/adapter.ts b/packages/engine-rn-windows/src/adapter.ts index f1ed04da68..0782910769 100644 --- a/packages/engine-rn-windows/src/adapter.ts +++ b/packages/engine-rn-windows/src/adapter.ts @@ -1,5 +1,5 @@ -const fs = require('fs'); const path = require('path'); +import fs from 'fs'; const sharedBlacklist = [ /node_modules\/react\/dist\/.*/, @@ -8,31 +8,31 @@ const sharedBlacklist = [ /.*\/__tests__\/.*/, ]; -function escapeRegExp(pattern) { - if (Object.prototype.toString.call(pattern) === '[object RegExp]') { - return pattern.source.replace(/\//g, path.sep); - } +const env: any = process?.env; + +function escapeRegExp(pattern: RegExp | string) { if (typeof pattern === 'string') { // eslint-disable-next-line const escaped = pattern.replace(/[\-\[\]\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'); // convert the '/' into an escaped local file separator return escaped.replace(/\//g, `\\${path.sep}`); + } else if (Object.prototype.toString.call(pattern) === '[object RegExp]') { + return pattern.source.replace(/\//g, path.sep); } throw new Error(`Unexpected blacklist pattern: ${pattern}`); } -function blacklist(additionalBlacklist) { +function blacklist(additionalBlacklist: RegExp[]) { return new RegExp(`(${(additionalBlacklist || []).concat(sharedBlacklist).map(escapeRegExp).join('|')})$`); } -export const withRNV = (config) => { - const rnwPath = fs.realpathSync(path.resolve(require.resolve('react-native-windows/package.json'), '..')); - +export const withRNVMetro = (config: any) => { const projectPath = process.env.RNV_PROJECT_ROOT || process.cwd(); + const rnwPath = fs.realpathSync(path.resolve(require.resolve('react-native-windows/package.json'), '..')); - const watchFolders = [rnwPath, path.resolve(projectPath, 'node_modules')]; + const watchFolders = [path.resolve(projectPath, 'node_modules')]; - if (process.env.RNV_IS_MONOREPO === 'true' || process.env.RNV_IS_MONOREPO === true) { + if (env.RNV_IS_MONOREPO === 'true' || env.RNV_IS_MONOREPO === true) { const monoRootPath = process.env.RNV_MONO_ROOT || projectPath; watchFolders.push(path.resolve(monoRootPath, 'node_modules')); watchFolders.push(path.resolve(monoRootPath, 'packages')); @@ -41,23 +41,25 @@ export const withRNV = (config) => { watchFolders.push(...config.watchFolders); } - const exts = process.env.RNV_EXTENSIONS || []; + const exts: string = env.RNV_EXTENSIONS || ''; const cnf = { ...config, + transformer: { + getTransformOptions: async () => ({ + transform: { + experimentalImportSupport: false, + // this defeats the RCTDeviceEventEmitter is not a registered callable module + inlineRequires: true, + }, + }), + ...(config?.resolver || {}), + sourceExts: [...(config?.resolver?.sourceExts || []), ...exts.split(',')], + extraNodeModules: config?.resolver?.extraNodeModules, + ...(config?.transformer || {}), + }, resolver: { blacklistRE: blacklist([ - // This stops "react-native run-windows" from causing the metro server to crash if its already running - // TODO. Project name should be dynamically injected here somehow - new RegExp(`${process.env.RNV_APP_BUILD_DIR.replace(/[/\\]/g, '/')}.*`), - // This prevents "react-native run-windows" from hitting: EBUSY: resource busy or locked, open msbuild.ProjectImports.zip - /.*\.ProjectImports\.zip/, - /platformBuilds\/.*/, - /buildHooks\/.*/, - /projectConfig\/.*/, - /appConfigs\/.*/, - /renative.local.*/, - /metro.config.local.*/, /platformBuilds\/.*/, /buildHooks\/.*/, /projectConfig\/.*/, @@ -65,20 +67,14 @@ export const withRNV = (config) => { /appConfigs\/.*/, /renative.local.*/, /metro.config.local.*/, + /.expo\/.*/, + /.rollup.cache\/.*/, ]), extraNodeModules: { // Redirect react-native-windows to avoid symlink (metro doesn't like symlinks) 'react-native-windows': rnwPath, }, }, - transformer: { - getTransformOptions: async () => ({ - transform: { - experimentalImportSupport: false, - inlineRequires: true, - }, - }), - }, watchFolders, sourceExts: [...(config?.resolver?.sourceExts || []), ...exts.split(',')], projectRoot: path.resolve(projectPath), @@ -86,3 +82,22 @@ export const withRNV = (config) => { return cnf; }; + +export const withRNVBabel = (cnf: any) => { + const plugins = cnf?.plugins || []; + + return { + retainLines: true, + presets: ['module:metro-react-native-babel-preset'], + ...cnf, + plugins: [ + [ + require.resolve('babel-plugin-module-resolver'), + { + root: [process.env.RNV_MONO_ROOT || '.'], + }, + ], + ...plugins, + ], + }; +}; diff --git a/packages/engine-rn-windows/src/commonEngine.ts b/packages/engine-rn-windows/src/commonEngine.ts index 18d6cf46aa..bd731e9fc1 100644 --- a/packages/engine-rn-windows/src/commonEngine.ts +++ b/packages/engine-rn-windows/src/commonEngine.ts @@ -1,6 +1,6 @@ import path from 'path'; import axios from 'axios'; -import { TaskManager, Constants, Logger, Common, FileUtils, Spinner } from 'rnv'; +import { TaskManager, Constants, Logger, Common, FileUtils, Spinner, RnvContext } from 'rnv'; const { getConfigProp, confirmActiveBundler } = Common; const { chalk, logTask, logInfo, logWarning } = Logger; @@ -10,7 +10,7 @@ const { executeTask } = TaskManager; let keepRNVRunning = false; -export const startBundlerIfRequired = async (c, parentTask, originTask) => { +export const startBundlerIfRequired = async (c: RnvContext, parentTask: string, originTask?: string) => { logTask('startBundlerIfRequired'); const bundleAssets = getConfigProp(c, c.platform, 'bundleAssets'); if (bundleAssets === true) return; @@ -33,7 +33,7 @@ export const startBundlerIfRequired = async (c, parentTask, originTask) => { } }; -export const waitForBundlerIfRequired = async (c) => { +export const waitForBundlerIfRequired = async (c: RnvContext) => { const bundleAssets = getConfigProp(c, c.platform, 'bundleAssets'); if (bundleAssets === true) return; // return a new promise that does...nothing, just to keep RNV running while the bundler is running @@ -44,7 +44,7 @@ export const waitForBundlerIfRequired = async (c) => { return true; }; -export const configureMetroConfigs = async (c) => { +export const configureMetroConfigs = async (c: RnvContext) => { logTask('configureMetroConfigs'); const cfPath = path.join(c.paths.project.dir, 'configs', `metro.config.${c.platform}.js`); @@ -59,7 +59,7 @@ export const configureMetroConfigs = async (c) => { } }; -const _isBundlerRunning = async (c) => { +const _isBundlerRunning = async (c: RnvContext) => { logTask('_isBundlerRunning'); try { const { data } = await axios.get( @@ -77,7 +77,7 @@ const _isBundlerRunning = async (c) => { } }; -export const isBundlerActive = async (c) => { +export const isBundlerActive = async (c: RnvContext) => { logTask('isBundlerActive', `(http://${c.runtime.localhost}:${c.runtime.port})`); try { await axios.get(`http://${c.runtime.localhost}:${c.runtime.port}`); @@ -87,15 +87,15 @@ export const isBundlerActive = async (c) => { } }; -const poll = (fn, timeout = 10000, interval = 1000) => { +const poll = (fn: () => Promise, timeout = 10000, interval = 1000) => { const endTime = Number(new Date()) + timeout; - const spinner = Spinner('Waiting for bundler to finish...').start(); - const checkCondition = async (resolve, reject) => { + const spinner = Spinner('Waiting for bundler to finish...').start(''); + const checkCondition = async (resolve: () => void, reject: (e: any) => void) => { try { const result = await fn(); if (result) { - spinner.succeed(); + spinner.succeed(''); resolve(); } else if (Number(new Date()) < endTime) { setTimeout(checkCondition, interval, resolve, reject); @@ -109,7 +109,7 @@ const poll = (fn, timeout = 10000, interval = 1000) => { } }; - return new Promise(checkCondition); + return new Promise(checkCondition); }; -export const waitForBundler = async (c) => poll(() => _isBundlerRunning(c)); +export const waitForBundler = async (c: RnvContext) => poll(() => _isBundlerRunning(c)); diff --git a/packages/engine-rn-windows/src/index.ts b/packages/engine-rn-windows/src/index.ts index df0dfcad2c..647c720f8a 100644 --- a/packages/engine-rn-windows/src/index.ts +++ b/packages/engine-rn-windows/src/index.ts @@ -1,5 +1,6 @@ -import { Config, EngineManager } from 'rnv'; -import { withRNV } from './adapter'; +import { Config, EngineManager, RnvEngine } from 'rnv'; +import { withRNVBabel, withRNVMetro } from './adapter'; +//@ts-ignore import CNF from '../renative.engine.json'; import taskRnvBuild from './tasks/task.rnv.build'; import taskRnvConfigure from './tasks/task.rnv.configure'; @@ -12,7 +13,7 @@ import taskRnvStart from './tasks/task.rnv.start'; const { generateEngineTasks, generateEngineExtensions } = EngineManager; -export default { +const Engine: RnvEngine = { initializeRuntimeConfig: (c) => Config.initializeConfig(c), tasks: generateEngineTasks([ taskRnvRun, @@ -26,7 +27,8 @@ export default { ]), config: CNF, projectDirName: '', - ejectPlatform: null, + runtimeExtraProps: {}, + serverDirName: '', platforms: { windows: { defaultPort: 8092, @@ -40,4 +42,9 @@ export default { }, }; -export { withRNV }; +// Backward compatibility +const withRNV = withRNVMetro; + +export { withRNV, withRNVMetro, withRNVBabel }; + +export default Engine; diff --git a/packages/integration-terraform/src/index.ts b/packages/integration-terraform/src/index.ts index 67ae7f8fcd..2c3c65479e 100644 --- a/packages/integration-terraform/src/index.ts +++ b/packages/integration-terraform/src/index.ts @@ -1,6 +1,7 @@ import taskRnvTerraformDeploy from './tasks/task.rnv.terraform.deploy'; import taskRnvTerraformDestroy from './tasks/task.rnv.terraform.destroy'; import taskRnvTerraformStatus from './tasks/task.rnv.terraform.status'; +//@ts-ignore import config from '../renative.integration.json'; const TASKS = [taskRnvTerraformDeploy, taskRnvTerraformDestroy, taskRnvTerraformStatus]; From 6e23f56fed2e9b32dbc51cdf460ab64a894aabff Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 03:06:32 +0200 Subject: [PATCH 74/83] fix UTs --- packages/rnv/src/__tests__/common.test.ts | 2 +- packages/rnv/src/__tests__/exec.test.ts | 2 +- packages/rnv/src/__tests__/startup.test.ts | 1 + packages/rnv/src/__tests__/tasks.test.ts | 2 +- packages/rnv/src/core/configManager/types.ts | 6 +++--- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/rnv/src/__tests__/common.test.ts b/packages/rnv/src/__tests__/common.test.ts index fb0af787eb..0092d25468 100644 --- a/packages/rnv/src/__tests__/common.test.ts +++ b/packages/rnv/src/__tests__/common.test.ts @@ -1,5 +1,5 @@ import { getAppVersionCode } from '../../src/core/common'; -import { generateConfigBase } from '../core/configManager/configBase'; +import { generateConfigBase } from '../core/context/contextBase'; jest.mock('../../src/core/systemManager/logger.ts'); diff --git a/packages/rnv/src/__tests__/exec.test.ts b/packages/rnv/src/__tests__/exec.test.ts index 050fc8541b..8afe2864ed 100644 --- a/packages/rnv/src/__tests__/exec.test.ts +++ b/packages/rnv/src/__tests__/exec.test.ts @@ -1,5 +1,5 @@ import { executeAsync, commandExistsSync, commandExists } from '../../src/core/systemManager/exec'; -import { generateConfigBase } from '../core/configManager/configBase'; +import { generateConfigBase } from '../core/context/contextBase'; jest.mock('../../src/core/systemManager/logger.ts'); diff --git a/packages/rnv/src/__tests__/startup.test.ts b/packages/rnv/src/__tests__/startup.test.ts index 8c270d75d8..2b4a401b55 100644 --- a/packages/rnv/src/__tests__/startup.test.ts +++ b/packages/rnv/src/__tests__/startup.test.ts @@ -26,6 +26,7 @@ describe('Bootstrapping the CLI', () => { 'files', 'isBuildHooksReady', 'paths', + 'payload', 'platform', 'process', 'program', diff --git a/packages/rnv/src/__tests__/tasks.test.ts b/packages/rnv/src/__tests__/tasks.test.ts index 7b67944170..92ba7c324c 100644 --- a/packages/rnv/src/__tests__/tasks.test.ts +++ b/packages/rnv/src/__tests__/tasks.test.ts @@ -36,7 +36,7 @@ jest.mock('../../src/core/taskManager/index.ts', () => ({ shouldSkipTask: () => false, })); -jest.mock('../../src/core/configManager/config.ts', () => ({ +jest.mock('../../src/core/context/context.ts', () => ({ getConfig: () => null, })); diff --git a/packages/rnv/src/core/configManager/types.ts b/packages/rnv/src/core/configManager/types.ts index 323cd10024..bbf3dcbc27 100644 --- a/packages/rnv/src/core/configManager/types.ts +++ b/packages/rnv/src/core/configManager/types.ts @@ -5,9 +5,9 @@ export type RenativeConfigFile = { buildSchemes?: Record; runtime?: Record; versionCodeFormat?: string; - includedFonts: Array; - includedPermissions: RenativeConfigPermissionsList; - excludedPermissions: RenativeConfigPermissionsList; + includedFonts?: Array; + includedPermissions?: RenativeConfigPermissionsList; + excludedPermissions?: RenativeConfigPermissionsList; }; defaults: { ports?: Record; From b13657c73867cfa6e414db09c26955f90f0bfc9c Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 13:57:56 +0200 Subject: [PATCH 75/83] fix cli error --- packages/rnv/src/core/configManager/index.ts | 2 ++ packages/rnv/src/core/systemManager/fileutils.ts | 12 ++++++------ packages/rnv/src/core/systemManager/logger.ts | 2 ++ packages/rnv/src/runner.ts | 3 +++ packages/rnv/typings/global.d.ts | 6 +++--- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/rnv/src/core/configManager/index.ts b/packages/rnv/src/core/configManager/index.ts index 7c2908c6be..3a8db02d03 100644 --- a/packages/rnv/src/core/configManager/index.ts +++ b/packages/rnv/src/core/configManager/index.ts @@ -623,6 +623,8 @@ export const parseRenativeConfigs = async (c: RnvContext) => { export const createRnvConfig = (program: any, process: any, cmd: string, subCmd: string) => { const c: RnvContext = generateConfigBase(); + console.log('DHDHDH', c); + global.RNV_CONFIG = c; c.program = program; diff --git a/packages/rnv/src/core/systemManager/fileutils.ts b/packages/rnv/src/core/systemManager/fileutils.ts index 886b6d6e27..aa670b92f2 100755 --- a/packages/rnv/src/core/systemManager/fileutils.ts +++ b/packages/rnv/src/core/systemManager/fileutils.ts @@ -21,9 +21,9 @@ export const configureFilesystem = ( _doResolve: DoResolveFn, _isSystemWin: boolean ) => { - global.getConfigProp = _getConfigProp; - global.doResolve = _doResolve; - global.isSystemWin = _isSystemWin; + global._getConfigProp = _getConfigProp; + global._doResolve = _doResolve; + global._isSystemWin = _isSystemWin; }; export const fsWriteFileSync = (dest: string | undefined, data: string, options?: fs.WriteFileOptions) => { @@ -154,7 +154,7 @@ export const writeCleanFile = ( if (occurences) { occurences.forEach((occ) => { const val = occ.replace('{{configProps.', '').replace('}}', ''); - const configVal = global.getConfigProp(c, c.platform, val, ''); + const configVal = global._getConfigProp(c, c.platform, val, ''); pFileClean = pFileClean.replace(occ, configVal); }); } @@ -620,7 +620,7 @@ export const resolvePackage = (text: string) => { const val = match.replace('{{resolvePackage(', '').replace(')}}', ''); // TODO: Figure out WIN vs LINUX treatment here // forceForwardPaths is required for WIN Android to work correctly - newText = newText.replace(match, global.doResolve(val, false, { forceForwardPaths: true })); + newText = newText.replace(match, global._doResolve(val, false, { forceForwardPaths: true })); }); } return newText; @@ -726,7 +726,7 @@ export const updateConfigFile = async (update: FileUtilsUpdateConfig, globalConf }; export const replaceHomeFolder = (p: string) => { - if (global.isSystemWin) return p.replace('~', process.env.USERPROFILE || ''); + if (global._isSystemWin) return p.replace('~', process.env.USERPROFILE || ''); return p.replace('~', process.env.HOME || ''); }; diff --git a/packages/rnv/src/core/systemManager/logger.ts b/packages/rnv/src/core/systemManager/logger.ts index d3f5ba8733..bf208965f4 100644 --- a/packages/rnv/src/core/systemManager/logger.ts +++ b/packages/rnv/src/core/systemManager/logger.ts @@ -90,6 +90,8 @@ const cnf = () => { const _configureLogger = (c: RnvContext, analytics: AnalyticsApi) => { global._messages = []; + console.log('BOOLLLL', c); + _c = c; if (!global.timeStart) global.timeStart = new Date(); _currentProcess = c.process; diff --git a/packages/rnv/src/runner.ts b/packages/rnv/src/runner.ts index 914d0ef962..02dea2f019 100644 --- a/packages/rnv/src/runner.ts +++ b/packages/rnv/src/runner.ts @@ -4,6 +4,9 @@ import { configureFilesystem } from './core/systemManager/fileutils'; import { createRnvConfig } from './core/configManager'; import { logComplete, logError, logInitialize } from './core/systemManager/logger'; import CLI from './cli'; +import { getConfigProp } from './core/common'; +import { doResolve } from './core/systemManager/resolve'; +import { isSystemWin } from './core/systemManager/utils'; global.RNV_ANALYTICS = Analytics; diff --git a/packages/rnv/typings/global.d.ts b/packages/rnv/typings/global.d.ts index 4f7a2b8a65..b7da034117 100644 --- a/packages/rnv/typings/global.d.ts +++ b/packages/rnv/typings/global.d.ts @@ -12,11 +12,11 @@ declare global { //eslint-disable-next-line no-var var RNV_ANALYTICS //eslint-disable-next-line no-var - var isSystemWin: boolean; + var _isSystemWin: boolean; //eslint-disable-next-line no-var - var doResolve; + var _doResolve; //eslint-disable-next-line no-var - var getConfigProp + var _getConfigProp //eslint-disable-next-line no-var var fetch; } From a19396674632d1cbeb7e70becac3f6d22ddb8898 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 23:06:24 +0200 Subject: [PATCH 76/83] cleanup imports --- packages/engine-rn-electron/src/index.ts | 6 ++-- packages/engine-rn-macos/src/index.ts | 4 +-- packages/engine-rn-next/src/index.ts | 4 +-- packages/engine-rn-tvos/src/index.ts | 4 +-- packages/engine-rn-web/src/index.ts | 4 +-- .../src/tasks/task.rnv.build.ts | 21 ++++++----- .../src/tasks/task.rnv.configure.ts | 21 +++++++---- .../src/tasks/task.rnv.debug.ts | 6 +--- .../src/tasks/task.rnv.deploy.ts | 17 ++++++--- .../src/tasks/task.rnv.export.ts | 17 ++++++--- .../src/tasks/task.rnv.package.ts | 19 ++++++---- .../src/tasks/task.rnv.run.ts | 17 ++++++--- .../src/tasks/task.rnv.start.ts | 31 ++++++++++------ packages/engine-rn/src/commonEngine.ts | 26 +++++++++----- packages/engine-rn/src/index.ts | 4 +-- .../engine-rn/src/tasks/task.rnv.build.ts | 25 ++++++++----- .../engine-rn/src/tasks/task.rnv.configure.ts | 28 +++++++++------ .../src/tasks/task.rnv.crypto.installCerts.ts | 20 +++++++---- .../tasks/task.rnv.crypto.installProfiles.ts | 21 +++++++---- .../tasks/task.rnv.crypto.updateProfile.ts | 16 +++++---- .../tasks/task.rnv.crypto.updateProfiles.ts | 20 +++++++---- .../engine-rn/src/tasks/task.rnv.debug.ts | 6 +--- .../engine-rn/src/tasks/task.rnv.deploy.ts | 20 ++++++++--- .../engine-rn/src/tasks/task.rnv.eject.ts | 22 ++++++++---- .../engine-rn/src/tasks/task.rnv.export.ts | 23 ++++++++---- packages/engine-rn/src/tasks/task.rnv.log.ts | 27 +++++++------- .../engine-rn/src/tasks/task.rnv.package.ts | 25 ++++++++----- packages/engine-rn/src/tasks/task.rnv.run.ts | 27 +++++++++----- .../engine-rn/src/tasks/task.rnv.start.ts | 35 +++++++++++++------ 29 files changed, 331 insertions(+), 185 deletions(-) diff --git a/packages/engine-rn-electron/src/index.ts b/packages/engine-rn-electron/src/index.ts index 95c3404ec7..1d4b58707c 100644 --- a/packages/engine-rn-electron/src/index.ts +++ b/packages/engine-rn-electron/src/index.ts @@ -1,4 +1,4 @@ -import { Config, EngineManager, RnvContext, RnvEngine } from 'rnv'; +import { Config, generateEngineExtensions, generateEngineTasks, RnvEngine } from 'rnv'; //@ts-ignore import CNF from '../renative.engine.json'; import taskRnvBuild from './tasks/task.rnv.build'; @@ -11,10 +11,8 @@ import taskRnvRun from './tasks/task.rnv.run'; import taskRnvStart from './tasks/task.rnv.start'; import { withRNVBabel } from './adapter'; -const { generateEngineTasks, generateEngineExtensions } = EngineManager; - const Engine: RnvEngine = { - initializeRuntimeConfig: (c: RnvContext) => Config.initializeConfig(c), + initializeRuntimeConfig: (c) => Config.initializeConfig(c), tasks: generateEngineTasks([ taskRnvRun, taskRnvPackage, diff --git a/packages/engine-rn-macos/src/index.ts b/packages/engine-rn-macos/src/index.ts index 8cefcbb122..d85eef0ecc 100644 --- a/packages/engine-rn-macos/src/index.ts +++ b/packages/engine-rn-macos/src/index.ts @@ -1,4 +1,4 @@ -import { EngineManager, Config, RnvEngine } from 'rnv'; +import { Config, generateEngineExtensions, generateEngineTasks, RnvEngine } from 'rnv'; import { withRNVBabel, withRNVMetro } from './adapter'; //@ts-ignore import CNF from '../renative.engine.json'; @@ -11,8 +11,6 @@ import taskRnvExport from './tasks/task.rnv.export'; import taskRnvDeploy from './tasks/task.rnv.deploy'; // import taskRnvLog from './tasks/task.rnv.log'; -const { generateEngineTasks, generateEngineExtensions } = EngineManager; - const Engine: RnvEngine = { initializeRuntimeConfig: (c) => Config.initializeConfig(c), tasks: generateEngineTasks([ diff --git a/packages/engine-rn-next/src/index.ts b/packages/engine-rn-next/src/index.ts index de4cfa4f26..eb410749f1 100644 --- a/packages/engine-rn-next/src/index.ts +++ b/packages/engine-rn-next/src/index.ts @@ -1,4 +1,4 @@ -import { EngineManager, Config, RnvEngine } from 'rnv'; +import { Config, generateEngineExtensions, generateEngineTasks, RnvEngine } from 'rnv'; import { withRNVNext, withRNVBabel } from './adapter'; //@ts-ignore import CNF from '../renative.engine.json'; @@ -11,8 +11,6 @@ import taskRnvExport from './tasks/task.rnv.export'; import taskRnvDeploy from './tasks/task.rnv.deploy'; import taskRnvDebug from './tasks/task.rnv.debug'; -const { generateEngineTasks, generateEngineExtensions } = EngineManager; - const Engine: RnvEngine = { initializeRuntimeConfig: (c) => Config.initializeConfig(c), tasks: generateEngineTasks([ diff --git a/packages/engine-rn-tvos/src/index.ts b/packages/engine-rn-tvos/src/index.ts index a62a61924b..199e5915f9 100644 --- a/packages/engine-rn-tvos/src/index.ts +++ b/packages/engine-rn-tvos/src/index.ts @@ -1,4 +1,4 @@ -import { EngineManager, Config, RnvEngine } from 'rnv'; +import { Config, generateEngineExtensions, generateEngineTasks, RnvEngine } from 'rnv'; import taskRnvRun from './tasks/task.rnv.run'; import taskRnvPackage from './tasks/task.rnv.package'; import taskRnvBuild from './tasks/task.rnv.build'; @@ -16,8 +16,6 @@ import taskRnvLog from './tasks/task.rnv.log'; import CNF from '../renative.engine.json'; import { createEngineAlias, withRNVMetro, withRNVBabel } from './adapter'; -const { generateEngineTasks, generateEngineExtensions } = EngineManager; - const Engine: RnvEngine = { initializeRuntimeConfig: (c) => Config.initializeConfig(c), tasks: generateEngineTasks([ diff --git a/packages/engine-rn-web/src/index.ts b/packages/engine-rn-web/src/index.ts index 354a606d37..4c68d88cfd 100644 --- a/packages/engine-rn-web/src/index.ts +++ b/packages/engine-rn-web/src/index.ts @@ -1,4 +1,4 @@ -import { EngineManager, Config, RnvEngine } from 'rnv'; +import { Config, generateEngineExtensions, generateEngineTasks, RnvEngine } from 'rnv'; import { withRNVBabel } from './adapter'; //@ts-ignore import CNF from '../renative.engine.json'; @@ -17,8 +17,6 @@ const HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); -const { generateEngineTasks, generateEngineExtensions } = EngineManager; - export { webpack, HtmlWebpackPlugin, HtmlWebpackHarddiskPlugin, MiniCssExtractPlugin, BundleAnalyzerPlugin }; const Engine: RnvEngine = { diff --git a/packages/engine-rn-windows/src/tasks/task.rnv.build.ts b/packages/engine-rn-windows/src/tasks/task.rnv.build.ts index 02037679cb..095d22fda6 100644 --- a/packages/engine-rn-windows/src/tasks/task.rnv.build.ts +++ b/packages/engine-rn-windows/src/tasks/task.rnv.build.ts @@ -1,11 +1,16 @@ -import { Constants, Logger, TaskManager, PlatformManager, RnvTaskFn } from 'rnv'; -import { SDKWindows } from '../sdks'; - -const { logErrorPlatform } = PlatformManager; -const { logTask } = Logger; -const { WINDOWS, XBOX, TASK_BUILD, TASK_PACKAGE, PARAMS } = Constants; -const { ruWindowsProject } = SDKWindows; -const { executeOrSkipTask, shouldSkipTask } = TaskManager; +import { + RnvTaskFn, + executeOrSkipTask, + TASK_PACKAGE, + TASK_BUILD, + XBOX, + WINDOWS, + logErrorPlatform, + PARAMS, + logTask, + shouldSkipTask, +} from 'rnv'; +import { ruWindowsProject } from '../sdks/sdk-windows'; export const taskRnvBuild: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvBuild'); diff --git a/packages/engine-rn-windows/src/tasks/task.rnv.configure.ts b/packages/engine-rn-windows/src/tasks/task.rnv.configure.ts index b295567769..6775c89ad8 100644 --- a/packages/engine-rn-windows/src/tasks/task.rnv.configure.ts +++ b/packages/engine-rn-windows/src/tasks/task.rnv.configure.ts @@ -1,13 +1,20 @@ -import { Constants, Logger, PlatformManager, RnvTaskFn, TaskManager, TemplateManager } from 'rnv'; +import { + logErrorPlatform, + copySharedPlatforms, + logTask, + WINDOWS, + XBOX, + TASK_PLATFORM_CONFIGURE, + TASK_CONFIGURE, + PARAMS, + RnvTaskFn, + configureEntryPoint, + executeTask, + shouldSkipTask, +} from 'rnv'; import { SDKWindows } from '../sdks'; -const { logErrorPlatform, copySharedPlatforms } = PlatformManager; -const { logTask } = Logger; -const { WINDOWS, XBOX, TASK_PLATFORM_CONFIGURE, TASK_CONFIGURE, PARAMS } = Constants; - const { configureWindowsProject } = SDKWindows; -const { executeTask, shouldSkipTask } = TaskManager; -const { configureEntryPoint } = TemplateManager; export const taskRnvConfigure: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvConfigure'); diff --git a/packages/engine-rn-windows/src/tasks/task.rnv.debug.ts b/packages/engine-rn-windows/src/tasks/task.rnv.debug.ts index 27c6809ee6..cb934bec9e 100644 --- a/packages/engine-rn-windows/src/tasks/task.rnv.debug.ts +++ b/packages/engine-rn-windows/src/tasks/task.rnv.debug.ts @@ -1,8 +1,4 @@ -import { Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; - -const { logErrorPlatform } = PlatformManager; -const { logTask } = Logger; -const { PARAMS } = Constants; +import { logErrorPlatform, logTask, PARAMS, RnvTaskFn } from 'rnv'; export const taskRnvDebug: RnvTaskFn = async (c, parentTask) => { logTask('taskRnvDebug', `parent:${parentTask}`); diff --git a/packages/engine-rn-windows/src/tasks/task.rnv.deploy.ts b/packages/engine-rn-windows/src/tasks/task.rnv.deploy.ts index 524f2f8358..6086806e08 100644 --- a/packages/engine-rn-windows/src/tasks/task.rnv.deploy.ts +++ b/packages/engine-rn-windows/src/tasks/task.rnv.deploy.ts @@ -1,12 +1,19 @@ -import { Constants, Logger, PlatformManager, RnvTaskFn, TaskManager } from 'rnv'; +import { + logErrorPlatform, + logTask, + WINDOWS, + XBOX, + PARAMS, + RnvTaskFn, + shouldSkipTask, + TASK_EXPORT, + TASK_DEPLOY, + executeOrSkipTask, +} from 'rnv'; import { SDKWindows } from '../sdks'; -const { logErrorPlatform } = PlatformManager; -const { logTask } = Logger; -const { WINDOWS, XBOX, TASK_EXPORT, TASK_DEPLOY, PARAMS } = Constants; // TODO Implement export windows app (currently it only seems to be available through VS Studio itself...) const { ruWindowsProject } = SDKWindows; -const { executeOrSkipTask, shouldSkipTask } = TaskManager; export const taskRnvDeploy: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvDeploy', `parent:${parentTask}`); diff --git a/packages/engine-rn-windows/src/tasks/task.rnv.export.ts b/packages/engine-rn-windows/src/tasks/task.rnv.export.ts index f51c08818d..19006c6e16 100644 --- a/packages/engine-rn-windows/src/tasks/task.rnv.export.ts +++ b/packages/engine-rn-windows/src/tasks/task.rnv.export.ts @@ -1,12 +1,19 @@ -import { Constants, Logger, PlatformManager, RnvTaskFn, TaskManager } from 'rnv'; +import { + logErrorPlatform, + logTask, + WINDOWS, + XBOX, + PARAMS, + RnvTaskFn, + TASK_BUILD, + TASK_EXPORT, + executeOrSkipTask, + shouldSkipTask, +} from 'rnv'; import { SDKWindows } from '../sdks'; -const { logErrorPlatform } = PlatformManager; -const { logTask } = Logger; -const { WINDOWS, XBOX, TASK_BUILD, TASK_EXPORT, PARAMS } = Constants; // TODO Implement export windows app (currently it only seems to be available through VS Studio itself...) const { packageWindowsApp, clearWindowsTemporaryFiles } = SDKWindows; -const { executeOrSkipTask, shouldSkipTask } = TaskManager; export const taskRnvExport: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvExport', `parent:${parentTask}`); diff --git a/packages/engine-rn-windows/src/tasks/task.rnv.package.ts b/packages/engine-rn-windows/src/tasks/task.rnv.package.ts index 3cd6ce6fa7..9c78eeb746 100644 --- a/packages/engine-rn-windows/src/tasks/task.rnv.package.ts +++ b/packages/engine-rn-windows/src/tasks/task.rnv.package.ts @@ -1,12 +1,19 @@ -import { TaskManager, Constants, Logger, PlatformManager, Common, RnvTaskFn } from 'rnv'; +import { + logErrorPlatform, + logTask, + WINDOWS, + XBOX, + TASK_CONFIGURE, + PARAMS, + RnvTaskFn, + executeOrSkipTask, + shouldSkipTask, + getConfigProp, + TASK_PACKAGE, +} from 'rnv'; import { SDKWindows } from '../sdks'; -const { logErrorPlatform } = PlatformManager; -const { logTask } = Logger; -const { WINDOWS, XBOX, TASK_PACKAGE, TASK_CONFIGURE, PARAMS } = Constants; -const { getConfigProp } = Common; const { packageBundleForWindows } = SDKWindows; -const { executeOrSkipTask, shouldSkipTask } = TaskManager; export const taskRnvPackage: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvPackage', `parent:${parentTask}`); diff --git a/packages/engine-rn-windows/src/tasks/task.rnv.run.ts b/packages/engine-rn-windows/src/tasks/task.rnv.run.ts index 17f2ca4378..752423816c 100644 --- a/packages/engine-rn-windows/src/tasks/task.rnv.run.ts +++ b/packages/engine-rn-windows/src/tasks/task.rnv.run.ts @@ -1,12 +1,19 @@ -import { Constants, Logger, PlatformManager, RnvTaskFn, TaskManager } from 'rnv'; +import { + logErrorPlatform, + logTask, + WINDOWS, + XBOX, + TASK_CONFIGURE, + PARAMS, + RnvTaskFn, + executeOrSkipTask, + shouldSkipTask, + TASK_RUN, +} from 'rnv'; import { SDKWindows } from '../sdks'; import { startBundlerIfRequired, waitForBundlerIfRequired } from '../commonEngine'; -const { logErrorPlatform } = PlatformManager; -const { logTask } = Logger; -const { WINDOWS, XBOX, TASK_RUN, TASK_CONFIGURE, PARAMS } = Constants; const { ruWindowsProject, clearWindowsTemporaryFiles } = SDKWindows; -const { executeOrSkipTask, shouldSkipTask } = TaskManager; export const taskRnvRun: RnvTaskFn = async (c, parentTask, originTask) => { const { platform } = c; diff --git a/packages/engine-rn-windows/src/tasks/task.rnv.start.ts b/packages/engine-rn-windows/src/tasks/task.rnv.start.ts index 9e881908f1..4acdcdb13c 100644 --- a/packages/engine-rn-windows/src/tasks/task.rnv.start.ts +++ b/packages/engine-rn-windows/src/tasks/task.rnv.start.ts @@ -1,15 +1,26 @@ -import { TaskManager, EngineManager, Constants, Logger, PlatformManager, Exec, Common, Resolver, RnvTaskFn } from 'rnv'; +import { + logErrorPlatform, + logTask, + WINDOWS, + XBOX, + PARAMS, + RnvTaskFn, + executeTask, + shouldSkipTask, + doResolve, + chalk, + logInfo, + logRaw, + getEntryFile, + confirmActiveBundler, + generateEnvVars, + executeAsync, + TASK_START, + TASK_CONFIGURE_SOFT, + logError, +} from 'rnv'; import { isBundlerActive } from '../commonEngine'; -const { getEntryFile, confirmActiveBundler } = Common; -const { logErrorPlatform } = PlatformManager; -const { generateEnvVars } = EngineManager; -const { executeTask, shouldSkipTask } = TaskManager; -const { chalk, logTask, logError, logRaw, logInfo } = Logger; -const { WINDOWS, XBOX, TASK_START, TASK_CONFIGURE_SOFT, PARAMS } = Constants; -const { executeAsync } = Exec; -const { doResolve } = Resolver; - const BUNDLER_PLATFORMS: Record = {}; BUNDLER_PLATFORMS[WINDOWS] = WINDOWS; diff --git a/packages/engine-rn/src/commonEngine.ts b/packages/engine-rn/src/commonEngine.ts index f7fe283700..7d2dfdc2ec 100644 --- a/packages/engine-rn/src/commonEngine.ts +++ b/packages/engine-rn/src/commonEngine.ts @@ -1,13 +1,21 @@ import path from 'path'; import axios from 'axios'; -import { TaskManager, Constants, Logger, Common, FileUtils, Prompt, Spinner, RnvContext } from 'rnv'; - -const { inquirerPrompt } = Prompt; -const { getConfigProp, confirmActiveBundler } = Common; -const { chalk, logTask, logInfo, logWarning } = Logger; -const { fsExistsSync, copyFileSync } = FileUtils; -const { TASK_START, RN_CLI_CONFIG_NAME } = Constants; -const { executeTask } = TaskManager; +import { + logTask, + executeTask, + chalk, + logInfo, + confirmActiveBundler, + TASK_START, + getConfigProp, + RnvContext, + fsExistsSync, + logWarning, + inquirerPrompt, + RN_CLI_CONFIG_NAME, + Spinner, +} from 'rnv'; +import { copyFileSync } from 'fs'; let keepRNVRunning = false; @@ -76,7 +84,7 @@ to your ${chalk().white('/.metro.config.js')} instead and delete deprecated file // Check rn-cli-config if (!fsExistsSync(c.paths.project.rnCliConfig)) { logInfo(`Your rn-cli config file ${chalk().white(c.paths.project.rnCliConfig)} is missing! INSTALLING...DONE`); - copyFileSync(path.join(c.paths.rnv.projectTemplate.dir, RN_CLI_CONFIG_NAME), c.paths.project.rnCliConfig); + copyFileSync(path.join(c.paths.rnv.projectTemplate.dir, RN_CLI_CONFIG_NAME), c.paths.project.rnCliConfig!); } }; diff --git a/packages/engine-rn/src/index.ts b/packages/engine-rn/src/index.ts index 17389f1348..a847cb37a8 100644 --- a/packages/engine-rn/src/index.ts +++ b/packages/engine-rn/src/index.ts @@ -1,4 +1,3 @@ -import { EngineManager, Config, RnvEngine } from 'rnv'; import { withRNVMetro, withRNVBabel } from './adapter'; //@ts-ignore import CNF from '../renative.engine.json'; @@ -16,8 +15,7 @@ import taskRnvCryptoUpdateProfiles from './tasks/task.rnv.crypto.updateProfiles' import taskRnvCryptoInstallProfiles from './tasks/task.rnv.crypto.installProfiles'; import taskRnvLog from './tasks/task.rnv.log'; import taskRnvEject from './tasks/task.rnv.eject'; - -const { generateEngineTasks, generateEngineExtensions } = EngineManager; +import { Config, generateEngineExtensions, generateEngineTasks, RnvEngine } from 'rnv'; const Engine: RnvEngine = { initializeRuntimeConfig: (c) => Config.initializeConfig(c), diff --git a/packages/engine-rn/src/tasks/task.rnv.build.ts b/packages/engine-rn/src/tasks/task.rnv.build.ts index 9e675c116d..7d58d7b0f4 100644 --- a/packages/engine-rn/src/tasks/task.rnv.build.ts +++ b/packages/engine-rn/src/tasks/task.rnv.build.ts @@ -1,14 +1,23 @@ -import { TaskManager, Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; +import { + logErrorPlatform, + logTask, + PARAMS, + RnvTaskFn, + TASK_BUILD, + TASK_EXPORT, + executeOrSkipTask, + shouldSkipTask, + TASK_PACKAGE, + ANDROID, + ANDROID_TV, + FIRE_TV, + ANDROID_WEAR, + MACOS, + IOS, +} from 'rnv'; import { buildAndroid } from '@rnv/sdk-android'; import { buildXcodeProject } from '@rnv/sdk-apple'; -const { logErrorPlatform } = PlatformManager; -const { logTask } = Logger; -const { IOS, MACOS, ANDROID, ANDROID_TV, FIRE_TV, ANDROID_WEAR, TASK_BUILD, TASK_PACKAGE, TASK_EXPORT, PARAMS } = - Constants; - -const { executeOrSkipTask, shouldSkipTask } = TaskManager; - export const taskRnvBuild: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvBuild'); const { platform } = c; diff --git a/packages/engine-rn/src/tasks/task.rnv.configure.ts b/packages/engine-rn/src/tasks/task.rnv.configure.ts index bc09bcab70..ef291e4b18 100644 --- a/packages/engine-rn/src/tasks/task.rnv.configure.ts +++ b/packages/engine-rn/src/tasks/task.rnv.configure.ts @@ -1,17 +1,25 @@ -import { TaskManager, Constants, Logger, PlatformManager, NPMUtils, TemplateManager, RnvTaskFn } from 'rnv'; +import { + logErrorPlatform, + logTask, + TASK_PLATFORM_CONFIGURE, + TASK_CONFIGURE, + PARAMS, + RnvTaskFn, + configureEntryPoint, + executeTask, + shouldSkipTask, + ANDROID, + ANDROID_TV, + FIRE_TV, + ANDROID_WEAR, + MACOS, + IOS, + jetifyIfRequired, +} from 'rnv'; import { configureGradleProject } from '@rnv/sdk-android'; import { configureXcodeProject } from '@rnv/sdk-apple'; import { configureMetroConfigs } from '../commonEngine'; -const { logErrorPlatform } = PlatformManager; -const { logTask } = Logger; -const { jetifyIfRequired } = NPMUtils; -const { IOS, MACOS, ANDROID, ANDROID_TV, FIRE_TV, ANDROID_WEAR, TASK_PLATFORM_CONFIGURE, TASK_CONFIGURE, PARAMS } = - Constants; - -const { executeTask, shouldSkipTask } = TaskManager; -const { configureEntryPoint } = TemplateManager; - export const taskRnvConfigure: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvConfigure'); diff --git a/packages/engine-rn/src/tasks/task.rnv.crypto.installCerts.ts b/packages/engine-rn/src/tasks/task.rnv.crypto.installCerts.ts index 76b4fb9d02..32833e7e33 100644 --- a/packages/engine-rn/src/tasks/task.rnv.crypto.installCerts.ts +++ b/packages/engine-rn/src/tasks/task.rnv.crypto.installCerts.ts @@ -1,10 +1,16 @@ -import { TaskManager, Constants, Logger, Exec, FileUtils, RnvTaskFn } from 'rnv'; - -const { logWarning, logError, logTask } = Logger; -const { getFileListSync } = FileUtils; -const { executeAsync } = Exec; -const { executeTask, shouldSkipTask } = TaskManager; -const { TASK_CRYPTO_INSTALL_CERTS, TASK_PROJECT_CONFIGURE, PARAMS } = Constants; +import { + logTask, + PARAMS, + RnvTaskFn, + executeTask, + shouldSkipTask, + executeAsync, + logError, + TASK_PROJECT_CONFIGURE, + TASK_CRYPTO_INSTALL_CERTS, + getFileListSync, + logWarning, +} from 'rnv'; export const taskRnvCryptoInstallCerts: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvCryptoInstallCerts'); diff --git a/packages/engine-rn/src/tasks/task.rnv.crypto.installProfiles.ts b/packages/engine-rn/src/tasks/task.rnv.crypto.installProfiles.ts index e5e72680ac..e81f869d08 100644 --- a/packages/engine-rn/src/tasks/task.rnv.crypto.installProfiles.ts +++ b/packages/engine-rn/src/tasks/task.rnv.crypto.installProfiles.ts @@ -1,10 +1,19 @@ +import { copyFileSync, mkdirSync } from 'fs'; import path from 'path'; -import { TaskManager, Constants, Logger, FileUtils, RnvTaskFn } from 'rnv'; - -const { logWarning, logError, logTask, logDebug } = Logger; -const { getFileListSync, copyFileSync, mkdirSync, fsExistsSync } = FileUtils; -const { executeTask, shouldSkipTask } = TaskManager; -const { TASK_CRYPTO_INSTALL_PROFILES, TASK_PROJECT_CONFIGURE, PARAMS } = Constants; +import { + logTask, + PARAMS, + RnvTaskFn, + executeTask, + shouldSkipTask, + logError, + TASK_PROJECT_CONFIGURE, + TASK_CRYPTO_INSTALL_PROFILES, + fsExistsSync, + logWarning, + getFileListSync, + logDebug, +} from 'rnv'; export const taskRnvCryptoInstallProfiles: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvCryptoInstallProfiles'); diff --git a/packages/engine-rn/src/tasks/task.rnv.crypto.updateProfile.ts b/packages/engine-rn/src/tasks/task.rnv.crypto.updateProfile.ts index 42416e3981..efb993f159 100644 --- a/packages/engine-rn/src/tasks/task.rnv.crypto.updateProfile.ts +++ b/packages/engine-rn/src/tasks/task.rnv.crypto.updateProfile.ts @@ -1,11 +1,15 @@ -import { TaskManager, Constants, Logger, RnvTaskFn } from 'rnv'; - +import { + logTask, + PARAMS, + RnvTaskFn, + executeTask, + shouldSkipTask, + IOS, + TASK_PROJECT_CONFIGURE, + TASK_CRYPTO_UPDATE_PROFILE, +} from 'rnv'; import { updateProfile } from '@rnv/sdk-apple'; -const { executeTask, shouldSkipTask } = TaskManager; -const { logTask } = Logger; -const { TASK_CRYPTO_UPDATE_PROFILE, TASK_PROJECT_CONFIGURE, IOS, PARAMS } = Constants; - export const taskRnvCryptoUpdateProfile: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvCryptoUpdateProfile'); diff --git a/packages/engine-rn/src/tasks/task.rnv.crypto.updateProfiles.ts b/packages/engine-rn/src/tasks/task.rnv.crypto.updateProfiles.ts index 4627adf0e3..6525dd254c 100644 --- a/packages/engine-rn/src/tasks/task.rnv.crypto.updateProfiles.ts +++ b/packages/engine-rn/src/tasks/task.rnv.crypto.updateProfiles.ts @@ -1,12 +1,18 @@ -import { TaskManager, Constants, Logger, ConfigManager, RnvTaskFn, RnvContext } from 'rnv'; +import { + logTask, + PARAMS, + RnvTaskFn, + executeTask, + shouldSkipTask, + chalk, + IOS, + RnvContext, + listAppConfigsFoldersSync, + TASK_PROJECT_CONFIGURE, + TASK_CRYPTO_UPDATE_PROFILES, +} from 'rnv'; import { updateProfile } from '@rnv/sdk-apple'; -const { listAppConfigsFoldersSync } = ConfigManager; - -const { chalk, logTask } = Logger; -const { IOS, TASK_CRYPTO_UPDATE_PROFILES, TASK_PROJECT_CONFIGURE, PARAMS } = Constants; -const { executeTask, shouldSkipTask } = TaskManager; - const _updateProfile = (c: RnvContext, v: string) => new Promise((resolve, reject) => { logTask(`_updateProfile:${v}`, chalk().grey); diff --git a/packages/engine-rn/src/tasks/task.rnv.debug.ts b/packages/engine-rn/src/tasks/task.rnv.debug.ts index 27c6809ee6..cb934bec9e 100644 --- a/packages/engine-rn/src/tasks/task.rnv.debug.ts +++ b/packages/engine-rn/src/tasks/task.rnv.debug.ts @@ -1,8 +1,4 @@ -import { Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; - -const { logErrorPlatform } = PlatformManager; -const { logTask } = Logger; -const { PARAMS } = Constants; +import { logErrorPlatform, logTask, PARAMS, RnvTaskFn } from 'rnv'; export const taskRnvDebug: RnvTaskFn = async (c, parentTask) => { logTask('taskRnvDebug', `parent:${parentTask}`); diff --git a/packages/engine-rn/src/tasks/task.rnv.deploy.ts b/packages/engine-rn/src/tasks/task.rnv.deploy.ts index c3bea20cf8..700941a495 100644 --- a/packages/engine-rn/src/tasks/task.rnv.deploy.ts +++ b/packages/engine-rn/src/tasks/task.rnv.deploy.ts @@ -1,8 +1,18 @@ -import { TaskManager, Constants, Logger, RnvTaskFn } from 'rnv'; - -const { logTask } = Logger; -const { TASK_EXPORT, TASK_DEPLOY, IOS, MACOS, ANDROID, ANDROID_TV, FIRE_TV, ANDROID_WEAR, PARAMS } = Constants; -const { executeOrSkipTask, shouldSkipTask } = TaskManager; +import { + logTask, + PARAMS, + RnvTaskFn, + TASK_EXPORT, + executeOrSkipTask, + shouldSkipTask, + ANDROID, + ANDROID_TV, + FIRE_TV, + ANDROID_WEAR, + MACOS, + IOS, + TASK_DEPLOY, +} from 'rnv'; export const taskRnvDeploy: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvDeploy', `parent:${parentTask}`); diff --git a/packages/engine-rn/src/tasks/task.rnv.eject.ts b/packages/engine-rn/src/tasks/task.rnv.eject.ts index fc7a47ca28..12e54013a4 100644 --- a/packages/engine-rn/src/tasks/task.rnv.eject.ts +++ b/packages/engine-rn/src/tasks/task.rnv.eject.ts @@ -1,15 +1,23 @@ -import { TaskManager, Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; +import { + logErrorPlatform, + logTask, + PARAMS, + RnvTaskFn, + executeOrSkipTask, + shouldSkipTask, + TASK_PACKAGE, + ANDROID, + ANDROID_TV, + FIRE_TV, + ANDROID_WEAR, + MACOS, + IOS, +} from 'rnv'; import { ejectGradleProject } from '@rnv/sdk-android'; import { ejectXcodeProject } from '@rnv/sdk-apple'; -const { logErrorPlatform } = PlatformManager; -const { logTask } = Logger; -const { IOS, MACOS, ANDROID, ANDROID_TV, FIRE_TV, ANDROID_WEAR, TASK_PACKAGE, PARAMS } = Constants; - const TASK_EJECT = 'eject'; -const { shouldSkipTask, executeOrSkipTask } = TaskManager; - export const taskRnvEject: RnvTaskFn = async (c, _parentTask, originTask) => { logTask('taskRnvEject'); const { platform } = c; diff --git a/packages/engine-rn/src/tasks/task.rnv.export.ts b/packages/engine-rn/src/tasks/task.rnv.export.ts index 75297ba337..d05d198111 100644 --- a/packages/engine-rn/src/tasks/task.rnv.export.ts +++ b/packages/engine-rn/src/tasks/task.rnv.export.ts @@ -1,12 +1,21 @@ -import { TaskManager, Constants, Logger, PlatformManager, RnvTaskFn } from 'rnv'; +import { + logErrorPlatform, + logTask, + PARAMS, + RnvTaskFn, + TASK_BUILD, + TASK_EXPORT, + executeOrSkipTask, + shouldSkipTask, + ANDROID, + ANDROID_TV, + FIRE_TV, + ANDROID_WEAR, + MACOS, + IOS, +} from 'rnv'; import { exportXcodeProject } from '@rnv/sdk-apple'; -const { logErrorPlatform } = PlatformManager; -const { logTask } = Logger; -const { IOS, MACOS, ANDROID, ANDROID_TV, FIRE_TV, ANDROID_WEAR, TASK_BUILD, TASK_EXPORT, PARAMS } = Constants; - -const { executeOrSkipTask, shouldSkipTask } = TaskManager; - export const taskRnvExport: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvExport', `parent:${parentTask}`); const { platform } = c; diff --git a/packages/engine-rn/src/tasks/task.rnv.log.ts b/packages/engine-rn/src/tasks/task.rnv.log.ts index 0ef13828e2..3d71804d85 100644 --- a/packages/engine-rn/src/tasks/task.rnv.log.ts +++ b/packages/engine-rn/src/tasks/task.rnv.log.ts @@ -1,18 +1,21 @@ -import { TaskManager, Constants, Logger, PlatformManager, SDKManager, RnvTaskFn } from 'rnv'; - +import { + logErrorPlatform, + logTask, + PARAMS, + RnvTaskFn, + executeTask, + ANDROID, + ANDROID_TV, + FIRE_TV, + ANDROID_WEAR, + IOS, + TASK_WORKSPACE_CONFIGURE, + TASK_PROJECT_CONFIGURE, + checkAndConfigureSdks, +} from 'rnv'; import { runAndroidLog } from '@rnv/sdk-android'; - import { runAppleLog } from '@rnv/sdk-apple'; -const { checkAndConfigureSdks } = SDKManager; - -const { logErrorPlatform } = PlatformManager; - -const { logTask } = Logger; -const { PARAMS, IOS, ANDROID, ANDROID_TV, FIRE_TV, ANDROID_WEAR, TASK_WORKSPACE_CONFIGURE, TASK_PROJECT_CONFIGURE } = - Constants; -const { executeTask } = TaskManager; - export const taskRnvLog: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvLog', `parent:${parentTask}`); diff --git a/packages/engine-rn/src/tasks/task.rnv.package.ts b/packages/engine-rn/src/tasks/task.rnv.package.ts index b46cda9695..aef42218eb 100644 --- a/packages/engine-rn/src/tasks/task.rnv.package.ts +++ b/packages/engine-rn/src/tasks/task.rnv.package.ts @@ -1,14 +1,23 @@ -import { TaskManager, Constants, Logger, PlatformManager, Common, RnvTaskFn } from 'rnv'; +import { + logErrorPlatform, + logTask, + TASK_CONFIGURE, + PARAMS, + RnvTaskFn, + executeOrSkipTask, + shouldSkipTask, + TASK_PACKAGE, + ANDROID, + ANDROID_TV, + FIRE_TV, + ANDROID_WEAR, + MACOS, + IOS, + getConfigProp, +} from 'rnv'; import { packageAndroid } from '@rnv/sdk-android'; import { packageBundleForXcode } from '@rnv/sdk-apple'; -const { logErrorPlatform } = PlatformManager; -const { logTask } = Logger; -const { IOS, MACOS, ANDROID, ANDROID_TV, FIRE_TV, ANDROID_WEAR, TASK_PACKAGE, TASK_CONFIGURE, PARAMS } = Constants; -const { getConfigProp } = Common; - -const { executeOrSkipTask, shouldSkipTask } = TaskManager; - export const taskRnvPackage: RnvTaskFn = async (c, parentTask, originTask) => { logTask('taskRnvPackage', `parent:${parentTask}`); const { platform } = c; diff --git a/packages/engine-rn/src/tasks/task.rnv.run.ts b/packages/engine-rn/src/tasks/task.rnv.run.ts index 01a2dd4918..496bbae0bf 100644 --- a/packages/engine-rn/src/tasks/task.rnv.run.ts +++ b/packages/engine-rn/src/tasks/task.rnv.run.ts @@ -1,15 +1,26 @@ -import { TaskManager, Constants, Logger, PlatformManager, Common, RnvTaskFn } from 'rnv'; +import { + logErrorPlatform, + logTask, + TASK_CONFIGURE, + PARAMS, + RnvTaskFn, + executeOrSkipTask, + shouldSkipTask, + logRaw, + ANDROID, + ANDROID_TV, + FIRE_TV, + ANDROID_WEAR, + MACOS, + IOS, + TASK_RUN, + getConfigProp, + logSummary, +} from 'rnv'; import { packageAndroid, runAndroid } from '@rnv/sdk-android'; import { runXcodeProject } from '@rnv/sdk-apple'; import { startBundlerIfRequired, waitForBundlerIfRequired } from '../commonEngine'; -const { getConfigProp } = Common; -const { logErrorPlatform } = PlatformManager; -const { logTask, logSummary, logRaw } = Logger; -const { IOS, MACOS, ANDROID, ANDROID_TV, FIRE_TV, ANDROID_WEAR, TASK_RUN, TASK_CONFIGURE, PARAMS } = Constants; - -const { executeOrSkipTask, shouldSkipTask } = TaskManager; - export const taskRnvRun: RnvTaskFn = async (c, parentTask, originTask) => { const { platform } = c; const { port } = c.runtime; diff --git a/packages/engine-rn/src/tasks/task.rnv.start.ts b/packages/engine-rn/src/tasks/task.rnv.start.ts index 51cf33ec9e..465ef9c80b 100644 --- a/packages/engine-rn/src/tasks/task.rnv.start.ts +++ b/packages/engine-rn/src/tasks/task.rnv.start.ts @@ -1,15 +1,30 @@ -import { TaskManager, EngineManager, Constants, Logger, PlatformManager, Exec, Common, Resolver, RnvTaskFn } from 'rnv'; +import { + logErrorPlatform, + logTask, + PARAMS, + RnvTaskFn, + executeTask, + shouldSkipTask, + doResolve, + chalk, + logInfo, + logRaw, + getEntryFile, + confirmActiveBundler, + generateEnvVars, + executeAsync, + TASK_START, + TASK_CONFIGURE_SOFT, + logError, + ANDROID, + ANDROID_TV, + FIRE_TV, + ANDROID_WEAR, + MACOS, + IOS, +} from 'rnv'; import { isBundlerActive } from '../commonEngine'; -const { getEntryFile, confirmActiveBundler } = Common; -const { doResolve } = Resolver; -const { logErrorPlatform } = PlatformManager; -const { generateEnvVars } = EngineManager; -const { executeTask, shouldSkipTask } = TaskManager; -const { chalk, logTask, logError, logRaw, logInfo } = Logger; -const { IOS, MACOS, ANDROID, ANDROID_TV, FIRE_TV, ANDROID_WEAR, TASK_START, TASK_CONFIGURE_SOFT, PARAMS } = Constants; -const { executeAsync } = Exec; - const BUNDLER_PLATFORMS: Record = {}; BUNDLER_PLATFORMS[IOS] = IOS; From a2e8bd2ece33eeab19690c8a849d090ec0693659 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 23:20:49 +0200 Subject: [PATCH 77/83] skip linking undefined platforms --- packages/rnv/src/core/pluginManager/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rnv/src/core/pluginManager/index.ts b/packages/rnv/src/core/pluginManager/index.ts index a016acad60..f6ee42099a 100644 --- a/packages/rnv/src/core/pluginManager/index.ts +++ b/packages/rnv/src/core/pluginManager/index.ts @@ -448,7 +448,7 @@ export const parsePlugins = ( const plugin = getMergedPlugin(c, key); if (plugin) { - const pluginPlat = plugin[platform] || {}; + const pluginPlat = plugin[platform] || { skipLinking: true, enabled: false }; if (ignorePlatformObjectCheck) { // totalIncludedPlugins++; pluginCallback(plugin, pluginPlat, key); From 08447d1e46cfe8015ad5dfef81e9e44357c979f3 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 23:37:14 +0200 Subject: [PATCH 78/83] cleanup, fix plugins inject skip --- packages/rnv/src/core/configManager/index.ts | 2 -- packages/rnv/src/core/pluginManager/index.ts | 2 +- packages/rnv/src/core/systemManager/logger.ts | 1 - packages/sdk-android/src/gradleParser.ts | 2 +- 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/rnv/src/core/configManager/index.ts b/packages/rnv/src/core/configManager/index.ts index 3a8db02d03..7c2908c6be 100644 --- a/packages/rnv/src/core/configManager/index.ts +++ b/packages/rnv/src/core/configManager/index.ts @@ -623,8 +623,6 @@ export const parseRenativeConfigs = async (c: RnvContext) => { export const createRnvConfig = (program: any, process: any, cmd: string, subCmd: string) => { const c: RnvContext = generateConfigBase(); - console.log('DHDHDH', c); - global.RNV_CONFIG = c; c.program = program; diff --git a/packages/rnv/src/core/pluginManager/index.ts b/packages/rnv/src/core/pluginManager/index.ts index f6ee42099a..50ba3201b3 100644 --- a/packages/rnv/src/core/pluginManager/index.ts +++ b/packages/rnv/src/core/pluginManager/index.ts @@ -448,7 +448,7 @@ export const parsePlugins = ( const plugin = getMergedPlugin(c, key); if (plugin) { - const pluginPlat = plugin[platform] || { skipLinking: true, enabled: false }; + const pluginPlat = plugin[platform] || { skipLinking: true }; if (ignorePlatformObjectCheck) { // totalIncludedPlugins++; pluginCallback(plugin, pluginPlat, key); diff --git a/packages/rnv/src/core/systemManager/logger.ts b/packages/rnv/src/core/systemManager/logger.ts index bf208965f4..d3f2eb7cab 100644 --- a/packages/rnv/src/core/systemManager/logger.ts +++ b/packages/rnv/src/core/systemManager/logger.ts @@ -90,7 +90,6 @@ const cnf = () => { const _configureLogger = (c: RnvContext, analytics: AnalyticsApi) => { global._messages = []; - console.log('BOOLLLL', c); _c = c; if (!global.timeStart) global.timeStart = new Date(); diff --git a/packages/sdk-android/src/gradleParser.ts b/packages/sdk-android/src/gradleParser.ts index 3fb0c47b17..f1d02d9fe8 100644 --- a/packages/sdk-android/src/gradleParser.ts +++ b/packages/sdk-android/src/gradleParser.ts @@ -627,7 +627,7 @@ export const injectPluginGradleSync = ( c.payload.pluginConfigAndroid.pluginIncludes += `, ':${keyFixed}'`; c.payload.pluginConfigAndroid.pluginPaths += `project(':${keyFixed}').projectDir = new File('${pathAbsolute}')\n`; } - if (!plugin.skipImplementation) { + if (!plugin.skipLinking && !plugin.skipImplementation) { if (plugin.implementation) { c.payload.pluginConfigAndroid.appBuildGradleImplementations += `${plugin.implementation}\n`; } else { From 0e5d346d61c5613408b7d70b135c7108e608fb08 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Mon, 4 Sep 2023 23:47:11 +0200 Subject: [PATCH 79/83] refactor context type --- packages/sdk-android/src/ejector.ts | 17 ++++++------ packages/sdk-android/src/gradleParser.ts | 18 ++++++------- .../sdk-android/src/gradleWrapperParser.ts | 10 +++---- packages/sdk-android/src/index.ts | 21 +++++++-------- packages/sdk-android/src/kotlinParser.ts | 17 ++++++------ packages/sdk-android/src/manifestParser.ts | 26 ++++++++----------- packages/sdk-android/src/types.ts | 4 ++- packages/sdk-android/src/xmlValuesParser.ts | 23 ++++++++++------ packages/sdk-apple/src/common.ts | 8 +++--- packages/sdk-apple/src/fastlane.ts | 13 +++------- 10 files changed, 74 insertions(+), 83 deletions(-) diff --git a/packages/sdk-android/src/ejector.ts b/packages/sdk-android/src/ejector.ts index 3593ec81fb..690fdc53d2 100644 --- a/packages/sdk-android/src/ejector.ts +++ b/packages/sdk-android/src/ejector.ts @@ -1,18 +1,17 @@ import path from 'path'; -import { Common, FileUtils, PluginManager, Resolver, RnvContext, RnvPluginPlatform } from 'rnv'; -// import { logWarning } from 'rnv/dist/core/systemManager/logger'; - -const { +import { + PluginManager, + RnvContext, + RnvPluginPlatform, fsExistsSync, copyFileSync, fsWriteFileSync, fsReadFileSync, copyFolderContentsRecursiveSync, - // cleanEmptyFoldersRecursively, - // fsMkdirSync, -} = FileUtils; -const { getAppFolder, getConfigProp } = Common; -const { doResolvePath } = Resolver; + getAppFolder, + getConfigProp, + doResolvePath, +} from 'rnv'; const { parsePlugins, diff --git a/packages/sdk-android/src/gradleParser.ts b/packages/sdk-android/src/gradleParser.ts index f1d02d9fe8..ee18bcaca9 100644 --- a/packages/sdk-android/src/gradleParser.ts +++ b/packages/sdk-android/src/gradleParser.ts @@ -12,7 +12,7 @@ import { RnvPlugin, Utils, } from 'rnv'; -import { Payload } from './types'; +import { Context } from './types'; const { getAppFolder, getAppVersion, getAppVersionCode, getAppId, getBuildFilePath, getConfigProp, addSystemInjects } = Common; @@ -22,7 +22,7 @@ const { chalk, logTask, logWarning, logDebug } = Logger; const { sanitizePluginPath, includesPluginPath } = PluginManager; const { isSystemWin } = Utils; -export const parseBuildGradleSync = (c: RnvContext) => { +export const parseBuildGradleSync = (c: Context) => { const appFolder = getAppFolder(c); const { platform } = c; @@ -109,7 +109,7 @@ export const parseBuildGradleSync = (c: RnvContext) => { ); }; -const setReactNativeEngineDefault = (c: RnvContext) => { +const setReactNativeEngineDefault = (c: Context) => { c.payload.pluginConfigAndroid.injectReactNativeEngine = ` maven { url "${doResolve('react-native', true, { forceForwardPaths: true })}/android" } maven { url("${doResolve('jsc-android', true, { forceForwardPaths: true })}/dist") } @@ -120,7 +120,7 @@ maven { url("${doResolve('jsc-android', true, { forceForwardPaths: true })}/dist c.payload.pluginConfigAndroid.injectHermes = ' enableHermes: false,'; }; -const setReactNativeEngineHermes = (c: RnvContext) => { +const setReactNativeEngineHermes = (c: Context) => { c.payload.pluginConfigAndroid.injectReactNativeEngine = ` maven { url "${doResolve('react-native', true, { forceForwardPaths: true })}/android" } maven { url("${doResolve('jsc-android', true, { forceForwardPaths: true })}/dist") } @@ -143,7 +143,7 @@ deleteDebugFilesForVariant: { false }, `; }; -const setReactNativeEngineV8 = (c: RnvContext) => { +const setReactNativeEngineV8 = (c: Context) => { c.payload.pluginConfigAndroid.injectReactNativeEngine = ` maven { url "${doResolve('react-native', true, { forceForwardPaths: true })}/android" } maven { url("${doResolve('jsc-android', true, { forceForwardPaths: true })}/dist") } @@ -168,7 +168,7 @@ const setReactNativeEngineV8 = (c: RnvContext) => { exclude '**/libjsc.so'`; }; -export const parseAppBuildGradleSync = (c: RnvContext) => { +export const parseAppBuildGradleSync = (c: Context) => { logTask('parseAppBuildGradleSync'); const appFolder = getAppFolder(c); const { platform } = c; @@ -504,7 +504,7 @@ ${chalk().white(c.paths.workspace?.appConfig?.configsPrivate?.join('\n'))}`); ); }; -export const parseSettingsGradleSync = (c: RnvContext) => { +export const parseSettingsGradleSync = (c: Context) => { const appFolder = getAppFolder(c); const { platform } = c; const injects = [ @@ -529,7 +529,7 @@ export const parseSettingsGradleSync = (c: RnvContext) => { ); }; -export const parseGradlePropertiesSync = (c: RnvContext) => { +export const parseGradlePropertiesSync = (c: Context) => { const appFolder = getAppFolder(c); const { platform } = c; // GRADLE.PROPERTIES @@ -571,7 +571,7 @@ export const parseGradlePropertiesSync = (c: RnvContext) => { }; export const injectPluginGradleSync = ( - c: RnvContext, + c: Context, pluginRoot: RnvPlugin, plugin: RenativeConfigPluginPlatform, key: string diff --git a/packages/sdk-android/src/gradleWrapperParser.ts b/packages/sdk-android/src/gradleWrapperParser.ts index 044e60a032..ae20562d13 100644 --- a/packages/sdk-android/src/gradleWrapperParser.ts +++ b/packages/sdk-android/src/gradleWrapperParser.ts @@ -1,12 +1,8 @@ import path from 'path'; -import { FileUtils, Logger, Common, RnvContext } from 'rnv'; -import { Payload } from './types'; +import { getAppFolder, logTask, getConfigProp, addSystemInjects, writeCleanFile, getBuildFilePath } from 'rnv'; +import { Context } from './types'; -const { getAppFolder, getBuildFilePath, getConfigProp, addSystemInjects } = Common; -const { writeCleanFile } = FileUtils; -const { logTask } = Logger; - -export const parseGradleWrapperSync = (c: RnvContext) => { +export const parseGradleWrapperSync = (c: Context) => { logTask('parseGradleWrapperSync'); const appFolder = getAppFolder(c); diff --git a/packages/sdk-android/src/index.ts b/packages/sdk-android/src/index.ts index f06e1c3171..3e9f287358 100644 --- a/packages/sdk-android/src/index.ts +++ b/packages/sdk-android/src/index.ts @@ -17,7 +17,6 @@ import { Prompt, SDKManager, RuntimeManager, - RnvContext, RnvPluginPlatform, } from 'rnv'; import { parseAndroidManifestSync, injectPluginManifestSync } from './manifestParser'; @@ -38,7 +37,7 @@ import { import { parseGradleWrapperSync } from './gradleWrapperParser'; import { parseValuesStringsSync, injectPluginXmlValuesSync, parseValuesColorsSync } from './xmlValuesParser'; import { ejectGradleProject } from './ejector'; -import { Payload } from './types'; +import { Context } from './types'; const { resetAdb, @@ -64,7 +63,7 @@ const { updateRenativeConfigs } = RuntimeManager; const { chalk, logTask, logWarning, logDebug, logInfo, logSuccess, logRaw, logError } = Logger; const { ANDROID_WEAR, ANDROID, ANDROID_TV, FIRE_TV, CLI_ANDROID_ADB } = Constants; -export const packageAndroid = async (c: RnvContext) => { +export const packageAndroid = async (c: Context) => { logTask('packageAndroid'); const { platform } = c; @@ -122,7 +121,7 @@ export const packageAndroid = async (c: RnvContext) => { } }; -export const runAndroid = async (c: RnvContext) => { +export const runAndroid = async (c: Context) => { const { target } = c.program; const { platform } = c; const defaultTarget = c.runtime.target; @@ -225,7 +224,7 @@ export const runAndroid = async (c: RnvContext) => { } }; -const _checkSigningCerts = async (c: RnvContext) => { +const _checkSigningCerts = async (c: Context) => { logTask('_checkSigningCerts'); const signingConfig = getConfigProp(c, c.platform, 'signingConfig', 'Debug'); const isRelease = signingConfig === 'Release'; @@ -351,7 +350,7 @@ const _checkSigningCerts = async (c: RnvContext) => { } }; -const _runGradleApp = async (c: RnvContext, platform: any, device: any) => { +const _runGradleApp = async (c: Context, platform: any, device: any) => { logTask('_runGradleApp'); const signingConfig = getConfigProp(c, platform, 'signingConfig', 'Debug'); @@ -407,7 +406,7 @@ const _runGradleApp = async (c: RnvContext, platform: any, device: any) } }; -export const buildAndroid = async (c: RnvContext) => { +export const buildAndroid = async (c: Context) => { logTask('buildAndroid'); const { platform } = c; @@ -437,7 +436,7 @@ export const buildAndroid = async (c: RnvContext) => { return true; }; -export const configureAndroidProperties = async (c: RnvContext) => { +export const configureAndroidProperties = async (c: Context) => { logTask('configureAndroidProperties'); const appFolder = getAppFolder(c); @@ -468,7 +467,7 @@ sdk.dir=${sdkDir}` return true; }; -export const configureGradleProject = async (c: RnvContext) => { +export const configureGradleProject = async (c: Context) => { const { platform } = c; logTask('configureGradleProject'); @@ -480,7 +479,7 @@ export const configureGradleProject = async (c: RnvContext) => { return true; }; -export const configureProject = async (c: RnvContext) => { +export const configureProject = async (c: Context) => { logTask('configureProject'); const { platform } = c; @@ -603,7 +602,7 @@ export const configureProject = async (c: RnvContext) => { }; // Resolve or reject will not be called so this will keep running -export const runAndroidLog = async (c: RnvContext) => { +export const runAndroidLog = async (c: Context) => { logTask('runAndroidLog'); const filter = c.program.filter || ''; const child = execa.command(`${c.cli[CLI_ANDROID_ADB]} logcat`); diff --git a/packages/sdk-android/src/kotlinParser.ts b/packages/sdk-android/src/kotlinParser.ts index 87673c399e..c7c55a35a8 100644 --- a/packages/sdk-android/src/kotlinParser.ts +++ b/packages/sdk-android/src/kotlinParser.ts @@ -1,8 +1,5 @@ import path from 'path'; -import { Common, FileUtils, Logger, OverridesOptions, RnvContext } from 'rnv'; -import { Payload } from './types'; - -const { +import { getAppFolder, getAppId, getBuildFilePath, @@ -11,16 +8,18 @@ const { getConfigProp, getIP, addSystemInjects, -} = Common; -const { logWarning } = Logger; -const { writeCleanFile } = FileUtils; + logWarning, + writeCleanFile, + OverridesOptions, +} from 'rnv'; +import { Context } from './types'; const JS_BUNDLE_DEFAULTS: any = { // Android Wear does not support webview required for connecting to packager. this is hack to prevent RN connectiing to running bundler androidwear: '"assets://index.androidwear.bundle"', }; -export const parseMainApplicationSync = (c: RnvContext) => { +export const parseMainApplicationSync = (c: Context) => { const appFolder = getAppFolder(c); const { platform } = c; const applicationPath = 'app/src/main/java/rnv/MainApplication.kt'; @@ -123,7 +122,7 @@ export const parseMainActivitySync = (c: any) => { ); }; -export const parseSplashActivitySync = (c: RnvContext) => { +export const parseSplashActivitySync = (c: Context) => { const appFolder = getAppFolder(c); const { platform } = c; const splashPath = 'app/src/main/java/rnv/SplashActivity.kt'; diff --git a/packages/sdk-android/src/manifestParser.ts b/packages/sdk-android/src/manifestParser.ts index d22ce0e30b..0ed9a12217 100644 --- a/packages/sdk-android/src/manifestParser.ts +++ b/packages/sdk-android/src/manifestParser.ts @@ -1,16 +1,7 @@ import path from 'path'; import { - FileUtils, - Common, - Logger, - PluginManager, - RnvContext, RenativeConfigPermissionsList, RnvPluginPlatform, -} from 'rnv'; -import { Payload } from './types'; - -const { getAppFolder, getAppId, getBuildFilePath, @@ -18,10 +9,15 @@ const { getFlavouredProp, addSystemInjects, getConfigPropArray, -} = Common; -const { logTask, logError, logWarning, logDebug } = Logger; -const { readObjectSync, writeCleanFile } = FileUtils; -const { parsePlugins } = PluginManager; + logTask, + logError, + logWarning, + logDebug, + readObjectSync, + writeCleanFile, + parsePlugins, +} from 'rnv'; +import { Context } from './types'; const PROHIBITED_DUPLICATE_TAGS = ['intent-filter']; const SYSTEM_TAGS = ['tag', 'children']; @@ -141,7 +137,7 @@ type ManifestFeature = { // children: // } -const _mergeFeatures = (c: RnvContext, baseManifestFile: any, configKey: string, value: boolean) => { +const _mergeFeatures = (c: Context, baseManifestFile: any, configKey: string, value: boolean) => { const features = getConfigProp(c, c.platform, configKey); if (features) { @@ -157,7 +153,7 @@ const _mergeFeatures = (c: RnvContext, baseManifestFile: any, configKey } }; -export const parseAndroidManifestSync = (c: RnvContext) => { +export const parseAndroidManifestSync = (c: Context) => { logTask('parseAndroidManifestSync'); const { platform } = c; diff --git a/packages/sdk-android/src/types.ts b/packages/sdk-android/src/types.ts index ef5fdce0cf..04faef0493 100644 --- a/packages/sdk-android/src/types.ts +++ b/packages/sdk-android/src/types.ts @@ -1,4 +1,4 @@ -import { RenativeConfigPluginPlatform } from 'rnv'; +import { RenativeConfigPluginPlatform, RnvContext } from 'rnv'; export type Payload = { pluginConfigAndroid: { @@ -52,3 +52,5 @@ export type Payload = { }; }; }; + +export type Context = RnvContext; diff --git a/packages/sdk-android/src/xmlValuesParser.ts b/packages/sdk-android/src/xmlValuesParser.ts index 239bd9d161..9f76eb247f 100644 --- a/packages/sdk-android/src/xmlValuesParser.ts +++ b/packages/sdk-android/src/xmlValuesParser.ts @@ -1,11 +1,18 @@ import path from 'path'; -import { FileUtils, Common, RnvContext, RenativeConfigPluginPlatform } from 'rnv'; -import { Payload } from './types'; +import { + RenativeConfigPluginPlatform, + getAppFolder, + getAppTitle, + getBuildFilePath, + getConfigProp, + sanitizeColor, + addSystemInjects, + writeFileSync, + writeCleanFile, +} from 'rnv'; +import { Context } from './types'; -const { getAppFolder, getAppTitle, getBuildFilePath, getConfigProp, sanitizeColor, addSystemInjects } = Common; -const { writeFileSync, writeCleanFile } = FileUtils; - -export const parseValuesStringsSync = (c: RnvContext) => { +export const parseValuesStringsSync = (c: Context) => { const appFolder = getAppFolder(c); const stringsPath = 'app/src/main/res/values/strings.xml'; let strings = '\n'; @@ -17,7 +24,7 @@ export const parseValuesStringsSync = (c: RnvContext) => { writeFileSync(path.join(appFolder, stringsPath), strings); }; -export const parseValuesColorsSync = (c: RnvContext) => { +export const parseValuesColorsSync = (c: Context) => { const appFolder = getAppFolder(c); const stringsPath = 'app/src/main/res/values/colors.xml'; @@ -39,7 +46,7 @@ export const parseValuesColorsSync = (c: RnvContext) => { ); }; -export const injectPluginXmlValuesSync = (c: RnvContext, plugin: RenativeConfigPluginPlatform) => { +export const injectPluginXmlValuesSync = (c: Context, plugin: RenativeConfigPluginPlatform) => { const rStrings = plugin.ResourceStrings?.children; if (rStrings) { rStrings.forEach((obj) => { diff --git a/packages/sdk-apple/src/common.ts b/packages/sdk-apple/src/common.ts index a37251002f..019fe1b943 100644 --- a/packages/sdk-apple/src/common.ts +++ b/packages/sdk-apple/src/common.ts @@ -1,9 +1,7 @@ -import { Common, RnvContext } from 'rnv'; -import { Payload } from './types'; +import { getConfigProp } from 'rnv'; +import { Context } from './types'; -const { getConfigProp } = Common; - -export const getAppFolderName = (c: RnvContext, platform: string) => { +export const getAppFolderName = (c: Context, platform: string) => { // NOTE: DEPRECATED let projectFolder = getConfigProp(c, platform, 'projectFolder'); if (projectFolder) { diff --git a/packages/sdk-apple/src/fastlane.ts b/packages/sdk-apple/src/fastlane.ts index 1e55e9bbce..8beabb6a50 100644 --- a/packages/sdk-apple/src/fastlane.ts +++ b/packages/sdk-apple/src/fastlane.ts @@ -1,13 +1,8 @@ import path from 'path'; -import { Exec, Logger, Constants, Common, RnvContext } from 'rnv'; -import { Payload } from './types'; +import { getConfigProp, getAppId, chalk, logTask, logWarning, logSuccess, executeAsync, IOS } from 'rnv'; +import { Context } from './types'; -const { getConfigProp, getAppId } = Common; -const { chalk, logTask, logWarning, logSuccess } = Logger; -const { executeAsync } = Exec; -const { IOS } = Constants; - -export const registerDevice = async (c: RnvContext) => { +export const registerDevice = async (c: Context) => { logTask(`registerDevice:${c.platform}`); const teamID = getConfigProp(c, c.platform, 'teamID'); @@ -30,7 +25,7 @@ export const registerDevice = async (c: RnvContext) => { } }; -export const updateProfile = async (c: RnvContext) => { +export const updateProfile = async (c: Context) => { logTask(`updateProfile`, chalk().grey); // TODO: run trough all schemes From 2294a95df4b49f24859e015eb8dc493562b17599 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Tue, 5 Sep 2023 10:12:59 +0200 Subject: [PATCH 80/83] update apple-sdk, code fixes --- .../src/sdks/sdk-lightning/index.ts | 2 +- packages/rnv/src/core/context/types.ts | 14 -------- packages/rnv/src/core/projectManager/index.ts | 2 +- .../src/core/sdkManager/deviceUtils/tizen.ts | 2 +- packages/sdk-apple/src/types.ts | 14 ++++++++ packages/sdk-apple/src/xcodeParser.ts | 36 +++++++++---------- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/packages/engine-lightning/src/sdks/sdk-lightning/index.ts b/packages/engine-lightning/src/sdks/sdk-lightning/index.ts index a7c05ca0e3..e3cfc55e87 100644 --- a/packages/engine-lightning/src/sdks/sdk-lightning/index.ts +++ b/packages/engine-lightning/src/sdks/sdk-lightning/index.ts @@ -139,7 +139,7 @@ const _configureProject = (c: RnvContext) => addSystemInjects(c, injects); const configFile = platform === TIZEN ? 'config.xml' : 'appinfo.json'; - const file = path.join(getPlatformProjectDir(c) || '', configFile); + const file = path.join(getPlatformProjectDir(c)!, configFile); writeCleanFile(file, file, injects, undefined, c); resolve(); diff --git a/packages/rnv/src/core/context/types.ts b/packages/rnv/src/core/context/types.ts index 19a4c6efa6..66068f1be4 100644 --- a/packages/rnv/src/core/context/types.ts +++ b/packages/rnv/src/core/context/types.ts @@ -90,20 +90,6 @@ export interface RnvContext { forceBundleAssets?: boolean; webpackTarget?: string; shouldOpenBrowser?: boolean; - xcodeProj?: { - id?: string; - runScheme?: string; - provisioningStyle?: string; - deploymentTarget?: string; - provisionProfileSpecifier?: any; - provisionProfileSpecifiers?: any; - excludedArchs?: Array; - codeSignIdentity?: string; - codeSignIdentities?: Record; - systemCapabilities?: Record; - teamID?: any; - appId?: any; - }; }; paths: { GLOBAL_RNV_CONFIG: string; diff --git a/packages/rnv/src/core/projectManager/index.ts b/packages/rnv/src/core/projectManager/index.ts index 081402a328..6a303418f3 100644 --- a/packages/rnv/src/core/projectManager/index.ts +++ b/packages/rnv/src/core/projectManager/index.ts @@ -461,7 +461,7 @@ export const copyAssetsFolder = async ( } }); - const destPath = path.join(getPlatformProjectDir(c) || '', subPath || ''); + const destPath = path.join(getPlatformProjectDir(c)!, subPath!); // FOLDER MERGERS FROM EXTERNAL SOURCES if (validAssetSources.length > 0) { diff --git a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts index b6de81df13..1f059ba856 100644 --- a/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts +++ b/packages/rnv/src/core/sdkManager/deviceUtils/tizen.ts @@ -239,7 +239,7 @@ export const runTizenSimOrDevice = async ( ); } - const tDir = getPlatformProjectDir(c) || 'UNDEFINED'; + const tDir = getPlatformProjectDir(c)!; const tBuild = path.join(tDir, 'build'); const tOut = path.join(tDir, 'output'); const tId = platformConfig.id; diff --git a/packages/sdk-apple/src/types.ts b/packages/sdk-apple/src/types.ts index 76c8bbf3ab..b791d0853d 100644 --- a/packages/sdk-apple/src/types.ts +++ b/packages/sdk-apple/src/types.ts @@ -39,6 +39,20 @@ export type Payload = { podfileSources: string; deploymentTarget: string; }; + xcodeProj?: { + id?: string; + runScheme?: string; + provisioningStyle?: string; + deploymentTarget?: string; + provisionProfileSpecifier?: any; + provisionProfileSpecifiers?: any; + excludedArchs?: Array; + codeSignIdentity?: string; + codeSignIdentities?: Record; + systemCapabilities?: Record; + teamID?: any; + appId?: any; + }; }; export type PayloadAppDelegateMethod = { diff --git a/packages/sdk-apple/src/xcodeParser.ts b/packages/sdk-apple/src/xcodeParser.ts index b75ff61904..ecee47a143 100644 --- a/packages/sdk-apple/src/xcodeParser.ts +++ b/packages/sdk-apple/src/xcodeParser.ts @@ -28,23 +28,23 @@ export const parseXcodeProject = async (c: Context) => { logTask('parseXcodeProject'); const { platform } = c; // PROJECT - c.runtime.xcodeProj = {}; - c.runtime.xcodeProj.provisioningStyle = getConfigProp(c, platform, 'provisioningStyle', 'Automatic'); - c.runtime.xcodeProj.deploymentTarget = getConfigProp(c, platform, 'deploymentTarget', '14.0'); - c.runtime.xcodeProj.provisionProfileSpecifier = getConfigProp(c, platform, 'provisionProfileSpecifier'); - c.runtime.xcodeProj.provisionProfileSpecifiers = getConfigProp(c, platform, 'provisionProfileSpecifiers'); - c.runtime.xcodeProj.codeSignIdentity = getConfigProp(c, platform, 'codeSignIdentity', 'iPhone Developer'); + c.payload.xcodeProj = {}; + c.payload.xcodeProj.provisioningStyle = getConfigProp(c, platform, 'provisioningStyle', 'Automatic'); + c.payload.xcodeProj.deploymentTarget = getConfigProp(c, platform, 'deploymentTarget', '14.0'); + c.payload.xcodeProj.provisionProfileSpecifier = getConfigProp(c, platform, 'provisionProfileSpecifier'); + c.payload.xcodeProj.provisionProfileSpecifiers = getConfigProp(c, platform, 'provisionProfileSpecifiers'); + c.payload.xcodeProj.codeSignIdentity = getConfigProp(c, platform, 'codeSignIdentity', 'iPhone Developer'); - c.runtime.xcodeProj.codeSignIdentities = getConfigProp(c, platform, 'codeSignIdentities'); + c.payload.xcodeProj.codeSignIdentities = getConfigProp(c, platform, 'codeSignIdentities'); - c.runtime.xcodeProj.systemCapabilities = getConfigProp(c, platform, 'systemCapabilities'); - c.runtime.xcodeProj.excludedArchs = getConfigProp(c, platform, 'excludedArchs'); - c.runtime.xcodeProj.runScheme = getConfigProp(c, platform, 'runScheme'); - c.runtime.xcodeProj.teamID = getConfigProp(c, platform, 'teamID'); - c.runtime.xcodeProj.id = getConfigProp(c, platform, 'id'); - c.runtime.xcodeProj.appId = getAppId(c, platform); + c.payload.xcodeProj.systemCapabilities = getConfigProp(c, platform, 'systemCapabilities'); + c.payload.xcodeProj.excludedArchs = getConfigProp(c, platform, 'excludedArchs'); + c.payload.xcodeProj.runScheme = getConfigProp(c, platform, 'runScheme'); + c.payload.xcodeProj.teamID = getConfigProp(c, platform, 'teamID'); + c.payload.xcodeProj.id = getConfigProp(c, platform, 'id'); + c.payload.xcodeProj.appId = getAppId(c, platform); - if (c.runtime.xcodeProj.provisioningStyle !== 'Automatic' && !c.runtime.xcodeProj.provisionProfileSpecifier) { + if (c.payload.xcodeProj.provisioningStyle !== 'Automatic' && !c.payload.xcodeProj.provisionProfileSpecifier) { const result = await parseProvisioningProfiles(c); let eligibleProfile: provision.MobileProvision | undefined; @@ -53,7 +53,7 @@ export const parseXcodeProject = async (c: Context) => { result.eligable.forEach((v) => { const bundleId = v.Entitlements['application-identifier']; - if (bundleId === `${c.runtime.xcodeProj?.teamID}.${c.runtime.xcodeProj?.id}`) { + if (bundleId === `${c.payload.xcodeProj?.teamID}.${c.payload.xcodeProj?.id}`) { eligibleProfile = v; } }); @@ -68,7 +68,7 @@ export const parseXcodeProject = async (c: Context) => { 'No provisionProfileSpecifier configured in appConfig despite setting provisioningStyle to manual', }); if (autoFix) { - c.runtime.xcodeProj.provisionProfileSpecifier = eligibleProfile.Name; + c.payload.xcodeProj.provisionProfileSpecifier = eligibleProfile.Name; c.files.appConfig.config.platforms[platform].buildSchemes[c.program.scheme].provisionProfileSpecifier = eligibleProfile.Name; writeFileSync(c.paths.appConfig.config, c.files.appConfig.config); @@ -76,7 +76,7 @@ export const parseXcodeProject = async (c: Context) => { } else { const w = 'Your build config has provisioningStyle set to manual but no provisionProfileSpecifier configured in appConfig and no available provisioning profiles availiable for'; - logWarning(`${w} ${c.runtime.xcodeProj.id}`); + logWarning(`${w} ${c.payload.xcodeProj.id}`); } } @@ -109,7 +109,7 @@ const _parseXcodeProject = (c: Context, platform: string) => systemCapabilities, teamID, appId, - } = c.runtime.xcodeProj || {}; + } = c.payload.xcodeProj || {}; if (teamID) { xcodeProj.updateBuildProperty('DEVELOPMENT_TEAM', teamID); From fc9d0e6a87332b585db3a5665503101c6aec16cf Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Tue, 5 Sep 2023 12:33:54 +0200 Subject: [PATCH 81/83] https://github.com/flexn-io/renative/security/code-scanning/70 --- packages/rnv/src/core/systemManager/resolve.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/rnv/src/core/systemManager/resolve.ts b/packages/rnv/src/core/systemManager/resolve.ts index 317bad343b..f5d4b119e6 100644 --- a/packages/rnv/src/core/systemManager/resolve.ts +++ b/packages/rnv/src/core/systemManager/resolve.ts @@ -97,10 +97,16 @@ const _getPackagePathParts = (aPath: string) => { return parts.slice(1); }; +const DIR_MAX_LENGTH = 99999; + /** * We support path linking using 'file:' protocol (not part of official node resolution alg.) */ const _doResolveFSPath = (aPath: string, options: ResolveOptions) => { + //SECURITY-PATCH https://github.com/flexn-io/renative/security/code-scanning/70 + if (options.basedir && options.basedir?.length > DIR_MAX_LENGTH) { + throw new Error(`Dir path max length (${DIR_MAX_LENGTH}) exceeded: ${options.basedir?.length}`); + } const fileRelPath = `${options.basedir ? `${options.basedir}/`.replace(/.*\/+$/, '/') : ''}${aPath.replace( 'file:', '' From e4a1262d646ee0b8d910cca559607079ce8400f4 Mon Sep 17 00:00:00 2001 From: Mihai Blaga Date: Tue, 5 Sep 2023 16:04:16 +0300 Subject: [PATCH 82/83] https://github.com/flexn-io/renative/security/code-scanning/112 --- packages/sdk-apple/package.json | 8 ++++++-- packages/sdk-apple/src/index.ts | 4 +++- yarn.lock | 7 ++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/sdk-apple/package.json b/packages/sdk-apple/package.json index fa8111330f..bf94217aee 100644 --- a/packages/sdk-apple/package.json +++ b/packages/sdk-apple/package.json @@ -35,7 +35,11 @@ "inquirer": "8.2.0", "ios-mobileprovision-finder": "1.0.11", "shelljs": "0.8.5", - "xcode": "2.1.0" + "xcode": "2.1.0", + "shell-quote": "1.8.1" + }, + "devDependencies": { + "@types/shell-quote": "1.7.1" }, "peerDependencies": { "rnv": "^0.37.3" @@ -58,4 +62,4 @@ ] }, "gitHead": "930edaf234cc321ad9f1e296c5d394e3144845e2" -} +} \ No newline at end of file diff --git a/packages/sdk-apple/src/index.ts b/packages/sdk-apple/src/index.ts index b64d324242..4c25196db6 100644 --- a/packages/sdk-apple/src/index.ts +++ b/packages/sdk-apple/src/index.ts @@ -25,6 +25,7 @@ import { parseXcscheme } from './xcschemeParser'; import { ejectXcodeProject } from './ejector'; import { Context } from './types'; import { ObjectEncodingOptions } from 'fs'; +import shellQuote from 'shell-quote'; const { getAppleDevices, launchAppleSimulator } = SDKManager.Apple; @@ -751,7 +752,8 @@ export const packageBundleForXcode = (c: Context, isDev = false) => { '--assets-dest', `platformBuilds/${c.runtime.appId}_${c.platform}${c.runtime._platformBuildsSuffix || ''}`, '--entry-file', - `${c.buildConfig.platforms?.[c.platform].entryFile}.js`, + // SECURITY-PATCH https://github.com/flexn-io/renative/security/code-scanning/112 + shellQuote.quote([`${c.buildConfig.platforms?.[c.platform].entryFile}.js`]), '--bundle-output', `${getAppFolder(c)}/main.jsbundle`, ]; diff --git a/yarn.lock b/yarn.lock index 91748a61c3..f6012a5dc4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5429,6 +5429,11 @@ "@types/mime" "*" "@types/node" "*" +"@types/shell-quote@1.7.1": + version "1.7.1" + resolved "https://registry.yarnpkg.com/@types/shell-quote/-/shell-quote-1.7.1.tgz#2d059091214a02c29f003f591032172b2aff77e8" + integrity sha512-SWZ2Nom1pkyXCDohRSrkSKvDh8QOG9RfAsrt5/NsPQC4UQJ55eG0qClA40I+Gkez4KTQ0uDUT8ELRXThf3J5jw== + "@types/shelljs@0.8.12": version "0.8.12" resolved "https://registry.npmjs.org/@types/shelljs/-/shelljs-0.8.12.tgz#79dc9632af7d5ca1b5afb65a6bfc1422d79b5fa0" @@ -23247,7 +23252,7 @@ shell-exec@^1: resolved "https://registry.npmjs.org/shell-exec/-/shell-exec-1.1.2.tgz#d4056f96638d8406c8ab498f9f8b28938eba2dd0" integrity sha512-v2NWVDP0ws+S7miKy2oSpJ/OuL6NKuMosPNUZLDWFBlMnBtuoZxZOwxpQJwhsFZgMb+r7frpDTT8p4OSnhkpsg== -shell-quote@1.7.3, shell-quote@^1.4.3, shell-quote@^1.6.1, shell-quote@^1.7.2, shell-quote@^1.7.3: +shell-quote@1.7.3, shell-quote@1.8.1, shell-quote@^1.4.3, shell-quote@^1.6.1, shell-quote@^1.7.2, shell-quote@^1.7.3: version "1.7.3" resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.7.3.tgz#aa40edac170445b9a431e17bb62c0b881b9c4123" integrity sha512-Vpfqwm4EnqGdlsBFNmHhxhElJYrdfcxPThu+ryKS5J8L/fhAwLazFZtq+S+TWZ9ANj2piSQLGj6NQg+lKPmxrw== From 76a5432fa0a19177422c2b47176decc9d589e321 Mon Sep 17 00:00:00 2001 From: Pavel Jacko Date: Tue, 5 Sep 2023 17:16:02 +0200 Subject: [PATCH 83/83] cleaner code --- .../src/sdks/sdk-electron/index.ts | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/packages/engine-rn-electron/src/sdks/sdk-electron/index.ts b/packages/engine-rn-electron/src/sdks/sdk-electron/index.ts index 09d446f6b3..ea3a6598d4 100644 --- a/packages/engine-rn-electron/src/sdks/sdk-electron/index.ts +++ b/packages/engine-rn-electron/src/sdks/sdk-electron/index.ts @@ -71,12 +71,12 @@ const configureProject = (c: RnvContext, exitOnFail?: boolean) => if (!isPlatformActive(c, platform, resolve)) return; - const platformProjectDir = getPlatformProjectDir(c); + const platformProjectDir = getPlatformProjectDir(c)!; const engine = getEngineRunnerByPlatform(c, c.platform); - const platformBuildDir = getPlatformBuildDir(c); + const platformBuildDir = getPlatformBuildDir(c)!; const bundleAssets = getConfigProp(c, platform, 'bundleAssets') === true; - const electronConfigPath = path.join(platformBuildDir!, 'electronConfig.json'); - const packagePath = path.join(platformBuildDir!, 'package.json'); + const electronConfigPath = path.join(platformBuildDir, 'electronConfig.json'); + const packagePath = path.join(platformBuildDir, 'package.json'); // If path does not exist for png, try iconset const pngIconPath = path.join(c.paths.appConfig.dir, `assets/${platform}/resources/icon.png`); const appId = getAppId(c, platform); @@ -124,8 +124,8 @@ const configureProject = (c: RnvContext, exitOnFail?: boolean) => webPreferences: { nodeIntegration: true, enableRemoteModule: true, contextIsolation: false }, icon: (platform === MACOS || platform === LINUX) && !fsExistsSync(pngIconPath) - ? path.join(platformProjectDir!, 'resources', 'icon.icns') - : path.join(platformProjectDir!, 'resources', 'icon.png'), + ? path.join(platformProjectDir, 'resources', 'icon.icns') + : path.join(platformProjectDir, 'resources', 'icon.png'), }; const browserWindowExt = getConfigProp(c, platform, 'BrowserWindow'); if (browserWindowExt) { @@ -159,8 +159,8 @@ const configureProject = (c: RnvContext, exitOnFail?: boolean) => addSystemInjects(c, injects); writeCleanFile( - path.join(platformProjectDir!, 'main.prod.js'), - path.join(platformProjectDir!, 'main.js'), + path.join(platformProjectDir, 'main.prod.js'), + path.join(platformProjectDir, 'main.js'), injects, undefined, c @@ -192,8 +192,8 @@ const configureProject = (c: RnvContext, exitOnFail?: boolean) => addSystemInjects(c, injects); writeCleanFile( - path.join(platformProjectDir!, 'main.dev.js'), - path.join(platformProjectDir!, 'main.js'), + path.join(platformProjectDir, 'main.dev.js'), + path.join(platformProjectDir, 'main.js'), injects, undefined, c @@ -203,14 +203,14 @@ const configureProject = (c: RnvContext, exitOnFail?: boolean) => const macConfig: any = {}; if (platform === MACOS) { macConfig.mac = { - entitlements: path.join(platformProjectDir!, 'entitlements.mac.plist'), - entitlementsInherit: path.join(platformProjectDir!, 'entitlements.mac.plist'), + entitlements: path.join(platformProjectDir, 'entitlements.mac.plist'), + entitlementsInherit: path.join(platformProjectDir, 'entitlements.mac.plist'), hardenedRuntime: true, }; macConfig.mas = { - entitlements: path.join(platformProjectDir!, 'entitlements.mas.plist'), - entitlementsInherit: path.join(platformProjectDir!, 'entitlements.mas.inherit.plist'), - provisioningProfile: path.join(platformProjectDir!, 'embedded.provisionprofile'), + entitlements: path.join(platformProjectDir, 'entitlements.mas.plist'), + entitlementsInherit: path.join(platformProjectDir, 'entitlements.mas.inherit.plist'), + provisioningProfile: path.join(platformProjectDir, 'embedded.provisionprofile'), hardenedRuntime: false, }; } @@ -219,9 +219,9 @@ const configureProject = (c: RnvContext, exitOnFail?: boolean) => { appId, directories: { - app: path.join(platformBuildDir!, 'build'), - buildResources: path.join(platformProjectDir!, 'resources'), - output: path.join(platformBuildDir!, 'export'), + app: path.join(platformBuildDir, 'build'), + buildResources: path.join(platformProjectDir, 'resources'), + output: path.join(platformBuildDir, 'export'), }, files: ['!export/*'], }, @@ -244,21 +244,21 @@ const buildElectron = async (c: RnvContext) => { await buildCoreWebpackProject(c); // Webpack 5 deletes build folder but does not copy package json - const platformBuildDir = getPlatformBuildDir(c); + const platformBuildDir = getPlatformBuildDir(c)!; // workaround: electron-builder fails export in npx mode due to trying install node_modules. we trick it not to do that - mkdirSync(path.join(platformBuildDir!, 'build', 'node_modules')); + mkdirSync(path.join(platformBuildDir, 'build', 'node_modules')); - const packagePathSrc = path.join(platformBuildDir!, 'package.json'); - const packagePathDest = path.join(platformBuildDir!, 'build', 'package.json'); + const packagePathSrc = path.join(platformBuildDir, 'package.json'); + const packagePathDest = path.join(platformBuildDir, 'build', 'package.json'); copyFileSync(packagePathSrc, packagePathDest); - const mainPathSrc = path.join(platformBuildDir!, 'main.js'); - const mainPathDest = path.join(platformBuildDir!, 'build', 'main.js'); + const mainPathSrc = path.join(platformBuildDir, 'main.js'); + const mainPathDest = path.join(platformBuildDir, 'build', 'main.js'); copyFileSync(mainPathSrc, mainPathDest); - const menuPathSrc = path.join(platformBuildDir!, 'contextMenu.js'); - const menuPathDest = path.join(platformBuildDir!, 'build', 'contextMenu.js'); + const menuPathSrc = path.join(platformBuildDir, 'contextMenu.js'); + const menuPathDest = path.join(platformBuildDir, 'build', 'contextMenu.js'); copyFileSync(menuPathSrc, menuPathDest); return true; @@ -267,8 +267,8 @@ const buildElectron = async (c: RnvContext) => { const exportElectron = async (c: RnvContext) => { logTask('exportElectron'); - const platformBuildDir = getPlatformBuildDir(c); - const buildPath = path.join(platformBuildDir!, 'build', 'release'); + const platformBuildDir = getPlatformBuildDir(c)!; + const buildPath = path.join(platformBuildDir, 'build', 'release'); if (fsExistsSync(buildPath)) { logInfo(`exportElectron: removing old build ${buildPath}`); @@ -288,10 +288,10 @@ const exportElectron = async (c: RnvContext) => { } await executeAsync( c, - `${electronBuilderPath} --config ${path.join(platformBuildDir!, 'electronConfig.json')} --${c.platform}` + `${electronBuilderPath} --config ${path.join(platformBuildDir, 'electronConfig.json')} --${c.platform}` ); - logSuccess(`Your Exported App is located in ${chalk().cyan(path.join(platformBuildDir!, 'export'))} .`); + logSuccess(`Your Exported App is located in ${chalk().cyan(path.join(platformBuildDir, 'export'))} .`); }; export const runElectron = async (c: RnvContext) => { @@ -339,13 +339,13 @@ const _runElectronSimulator = async (c: RnvContext) => { // const appFolder = getAppFolder(c, c.platform); const elc = `${doResolve('electron')}/cli.js`; const bundleAssets = getConfigProp(c, c.platform, 'bundleAssets') === true; - let platformProjectDir = getPlatformProjectDir(c); + let platformProjectDir = getPlatformProjectDir(c)!; if (bundleAssets) { platformProjectDir = path.join(getPlatformBuildDir(c)!, 'build'); } - const child = spawn('node', [elc, path.join(platformProjectDir!, '/main.js')], { + const child = spawn('node', [elc, path.join(platformProjectDir, '/main.js')], { detached: true, env: process.env, stdio: 'inherit',