Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ElenaDiachenko committed Jan 17, 2025
1 parent 999e85c commit 6dcae8e
Show file tree
Hide file tree
Showing 29 changed files with 503 additions and 2 deletions.
15 changes: 15 additions & 0 deletions packages/core/src/configs/appConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ import { ConfigFileApp } from '../schema/types';

const IGNORE_FOLDERS = ['.git'];

/**
* Lists all application configuration folders in the specified directory or project's appConfigsDir
*
* @param ignoreHiddenConfigs - If true, excludes configurations marked as hidden in their renative.json file
* @param appConfigsDirPath - Optional custom path to look for app configs. If not provided, uses project's appConfigsDir
* @returns Array of folder names containing valid app configurations
*
* The function:
* 1. Validates project path exists
* 2. Scans the specified directory for subdirectories
* 3. Filters out ignored folders (like .git)
* 4. If ignoreHiddenConfigs is true, checks each folder's renative.json file
* and excludes those marked with hidden: true
* 5. Returns an array of valid app config folder names
*/
export const listAppConfigsFoldersSync = (ignoreHiddenConfigs: boolean, appConfigsDirPath?: string) => {
logDefault('listAppConfigsFoldersSync', `ignoreHiddenConfigs:${!!ignoreHiddenConfigs}`);
const c = getContext();
Expand Down
19 changes: 18 additions & 1 deletion packages/core/src/configs/buildConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
fsExistsSync,
formatBytes,
mkdirSync,
writeFileSync
writeFileSync,
} from '../system/fs';
import { chalk, logDefault, logWarning, logDebug } from '../logger';
import { getContext } from '../context/provider';
Expand Down Expand Up @@ -45,6 +45,23 @@ const getEnginesPluginDelta = () => {
return enginePlugins;
};

/**
* Generates a build configuration by merging multiple configuration files and plugins.
*
* This function:
* 1. Retrieves the current context and any engine plugin deltas
* 2. Defines merge paths for both public and private configurations:
* - Workspace configurations
* - Project configurations
* - App configurations
* - Local configurations
* - Private configurations
* 3. Creates corresponding merge files arrays that contain the actual configuration content
* 4. Calls _generateBuildConfig to process and save the merged configuration
*
* The configuration files are merged in a specific order, with later files
* taking precedence over earlier ones in the merge sequence.
*/
export const generateBuildConfig = () => {
logDebug('generateBuildConfig');

Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/configs/configLocal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ import { getContext } from '../context/provider';
import { logDefault } from '../logger';
import { writeFileSync } from '../system/fs';

/**
* Generates or updates the local configuration file for the project.
*
* This function manages the local configuration by either updating or resetting
* the current application configuration ID. It operates on the configLocal object
* within the project files and persists changes to the filesystem.
*
* @param resetAppId - Optional boolean flag. When true, removes the currentAppConfigId
* from the configuration. When false or undefined, sets the
* currentAppConfigId to the current runtime appId.
*/
export const generateLocalConfig = (resetAppId?: boolean) => {
logDefault('generateLocalConfig', `resetAppId:${!!resetAppId}`);
const c = getContext();
Expand Down
15 changes: 15 additions & 0 deletions packages/core/src/configs/platformAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ import { getConfigProp } from '../context/contextProps';
import { logDefault } from '../logger';
import { getContext } from '../context/provider';

/**
* Generates runtime configuration for platform assets by merging various config sources.
*
* This function:
* 1. Retrieves the current context
* 2. Merges multiple configuration layers in the following order:
* - Base asset config
* - Runtime build config
* - Common runtime config
* - Platform-specific runtime config
* - Runtime config from config props
* 3. If assets directory exists, sanitizes the merged config and writes it to the assets config file
*
* @returns {Promise<boolean>} Returns true when the operation completes successfully
*/
export const generatePlatformAssetsRuntimeConfig = async () => {
logDefault('generateRuntimeConfig');
const c = getContext();
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/enums/platformName.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/**
* Supported platforms:
* - Web: web, webtv, chromecast
* - Mobile: ios, android, kaios, tizenmobile
* - TV: androidtv, firetv, tvos
* - Desktop: macos, linux, windows
* - Smart TV: tizen, webos
* - Wearable: androidwear, tizenwatch
* - Gaming: xbox
*/

export const RnvPlatformName = {
web: 'web',
ios: 'ios',
Expand Down
38 changes: 38 additions & 0 deletions packages/core/src/platforms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ export const generatePlatformChoices = () => {
return options;
};

/**
* Cleans the platform build directory for a specific platform or all platforms.
*
* This function removes build artifacts from the project's build directory. It can either
* clean a single platform's build or all platforms' builds depending on the parameters.
*
* @param platform - The RnvPlatform to clean. This is the specific platform whose build directory will be cleaned.
* @param cleanAllPlatforms - Optional boolean flag. If true, cleans build directories for all supported platforms
* in the build config. If false or undefined, only cleans the specified platform.
*
* @returns A Promise that resolves when all cleaning tasks are complete.
*
* @example
* // Clean only iOS platform
* await cleanPlatformBuild('ios');
*
* // Clean all platforms
* await cleanPlatformBuild('ios', true);
*/
export const cleanPlatformBuild = async (platform: RnvPlatform, cleanAllPlatforms?: boolean) => {
logDebug('cleanPlatformBuild');

Expand All @@ -41,6 +60,25 @@ export const cleanPlatformBuild = async (platform: RnvPlatform, cleanAllPlatform
await Promise.all(cleanTasks);
};

/**
* Creates a platform build for the specified platform by copying the necessary template files
* to the appropriate build directory.
*
* This function sets up the build environment for a given platform by copying files from the
* platform's template directory to the application's build directory. It ensures that the
* platform is supported and that the necessary directories are defined before proceeding with
* the file operations.
*
* @param platform - The RnvPlatform for which to create the build. This specifies the target
* platform whose build environment will be prepared.
*
* @returns A Promise that resolves when the platform build creation is complete. If the platform
* is not supported or if required paths are not defined, the Promise will be rejected.
*
* @example
* // Create a platform build for iOS
* await createPlatformBuild('ios');
*/
export const createPlatformBuild = (platform: RnvPlatform) =>
new Promise<void>((resolve, reject) => {
logDefault('createPlatformBuild');
Expand Down
101 changes: 101 additions & 0 deletions packages/core/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ const _getPluginScope = (plugin: ConfigPluginSchema | string): RnvPluginScope =>
return { scope: 'rnv' };
};

/**
* Retrieves and merges the configuration of a specified plugin.
*
* This function fetches the plugin configuration from the build configuration using the provided
* plugin key. It then merges the plugin configurations across different scopes, if available,
* and returns the final merged configuration.
*
* @param {RnvContext} c - The context object containing the build configuration and other contextual data.
* @param {string} key - The key identifying the plugin to retrieve and merge.
* @returns {RnvPlugin | null} - The merged plugin configuration, or null if the plugin is not found.
*/
export const getMergedPlugin = (c: RnvContext, key: string) => {
logDebug(`getMergedPlugin:${key}`);

Expand Down Expand Up @@ -175,6 +186,29 @@ const _applyPackageDependency = (deps: Record<string, string>, key: string, vers
}
};

/**
* Configures the plugins for the current project by ensuring that the necessary
* dependencies are correctly set in the project's package.json file.
*
* This function performs the following tasks:
* - Retrieves the current context and configuration.
* - Skips the process if the `skipDependencyCheck` option is set.
* - Ensures that the project's package.json has a dependencies object.
* - Iterates over each plugin defined in the build configuration.
* - For each plugin, checks if it is enabled and supported on the current platform.
* - Validates the version of each plugin against the version specified in package.json.
* - If a mismatch is found, creates a dependency mutation record.
* - If a plugin is missing from package.json, creates a mutation to add it.
* - Handles npm dependencies specified within each plugin.
* - Detects conflicts between top-level and plugin-specific dependencies.
* - Creates mutation records for missing or mismatched npm dependencies.
*
* The function does not modify the package.json directly if the context indicates
* that the current project is a template or if the `skipDependencyCheck` option
* is set. Instead, it logs warnings and prepares mutations for later processing.
*
* @returns {Promise<boolean>} - Resolves to true when the process is complete.
*/
export const configurePlugins = async () => {
logDefault('configurePlugins');

Expand Down Expand Up @@ -455,6 +489,20 @@ const _resolvePluginDependencies = async (
return true;
};

/**
* Parses and processes the plugins defined in the build configuration.
*
* This function iterates over the plugins specified in the build configuration,
* applying the provided callback function to each active plugin. It considers the
* inclusion and exclusion lists specified in the configuration, as well as platform
* support and deprecation status of each plugin.
*
* @param {PluginCallback} pluginCallback - A callback function to be invoked for each active plugin.
* @param {boolean} [ignorePlatformObjectCheck=false] - If true, bypasses platform-specific checks.
* @param {boolean} [includeDisabledOrExcludedPlugins=false] - If true, includes plugins that are
* disabled or excluded in the processing.
*/

export const parsePlugins = (
pluginCallback: PluginCallback,
ignorePlatformObjectCheck?: boolean,
Expand Down Expand Up @@ -784,6 +832,19 @@ const _applyOverrideFiles = (source: string, dest: string, dir: string) => {
logInfo(`${chalk().gray(dest)} overriden by: ${chalk().gray(source.split('node_modules').pop())}`);
};

/**
* Overrides the contents of a file based on specified regex patterns.
*
* This function reads the contents of a specified file, applies regex-based overrides,
* and writes the modified content back to the file. If the file has been modified before,
* it reverts to the original content before applying new overrides. It also maintains a backup
* of the original file content and tracks applied overrides to avoid redundant operations.
*
* @param {string} dest - The file path to apply overrides to.
* @param {Record<string, string>} override - A map of regex patterns and their replacements.
* @param {string} [overridePath=''] - The path to the override source, used for logging.
* @param {string} fileKey - A unique key representing the file, used for tracking overrides.
*/
export const overrideFileContents = (
dest: string,
override: Record<string, string>,
Expand Down Expand Up @@ -1094,6 +1155,25 @@ export const checkForPluginDependencies = async (postInjectHandler?: AsyncCallba

// const getPluginPlatformFromString = (p: string): RnvPluginPlatform => p as RnvPluginPlatform;

/**
* Overrides the template plugins for the current project.
* This function applies overrides to the plugins defined in the project configuration.
* It performs the following tasks:
* - Logs the start of the override process.
* - Retrieves the current context and options.
* - Checks if the `skipOverridesCheck` option is set, and if so, skips the override process.
* - Retrieves the directories for scoped and app-specific plugin templates.
* - Iterates over each plugin using the `parsePlugins` function.
* - For each plugin, checks if template overrides are disabled.
* - If not disabled, applies overrides from scoped plugin directories.
* - Applies overrides from app-specific plugin directories.
* - Logs a message if plugin template overrides are disabled for a plugin.
* The function ensures that the correct overrides are applied based on the plugin's scope
* and configuration settings. Overrides are not applied if the `skipOverridesCheck` option
* is specified in the program options.
*
* @returns {Promise<boolean>} - Resolves to true when the override process is complete.
*/
export const overrideTemplatePlugins = async () => {
logDefault('overrideTemplatePlugins');

Expand Down Expand Up @@ -1132,6 +1212,27 @@ export const overrideTemplatePlugins = async () => {
return true;
};

/**
* Copies plugin templates synchronously to the application folder.
*
* This function iterates over all plugins defined in the context and copies their respective
* template folders to the application's destination folder. The function performs the following tasks:
*
* - Constructs the destination path for the application folder.
* - Iterates over each plugin using the `parsePlugins` function.
* - For each plugin, creates an array of override options based on the plugin's properties.
* - Copies folder contents from various source paths to the destination path:
* - Project configuration plugin paths.
* - Private project configuration plugin paths.
* - Application configuration plugin paths.
* - Private application configuration plugin paths.
* - Scoped plugin template paths.
*
* The function ensures that the folder contents are merged recursively and any dynamic properties
* specified in the plugin's configuration are replaced in the destination files.
*
* @param {RnvContext} c - The context object containing configuration and paths.
*/
export const copyTemplatePluginsSync = (c: RnvContext) => {
const destPath = path.join(getAppFolder());

Expand Down
17 changes: 17 additions & 0 deletions packages/core/src/projects/appConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@ import { logDefault, logWarning } from '../logger';
import { generateConfigPropInjects } from '../system/injectors';
import { getContext } from '../context/provider';

/**
* Copies various build-related folders to a destination path, merging configurations and handling deprecated paths.
* This function performs the following operations:
* 1. Logs the start of the copy process.
* 2. Retrieves the current context, which contains configuration and runtime properties.
* 3. Checks if the current platform is active; if not, the function exits early.
* 4. Defines the destination path where folders will be copied.
* 5. Retrieves timestamp paths configuration and generates configuration property injects.
* 6. Merges project configuration folders into the destination path.
* 7. Handles deprecated shared folder paths for web-hosted platforms and logs a warning if used.
* 8. Merges additional app configuration folders, if they exist, into the destination path.
* 9. Merges private app configuration folders from the workspace into the destination path.
* 10. Copies template plugins using the current context.
* 11. Resolves the promise upon completion of all operations.
* The function utilizes various helper functions for path management and folder copying,
* ensuring that configuration properties and timestamp paths are correctly injected.
*/
export const copyBuildsFolder = () =>
new Promise<void>((resolve) => {
logDefault('copyBuildsFolder');
Expand Down
13 changes: 13 additions & 0 deletions packages/core/src/projects/fonts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ import { RnvContext } from '../context/types';
import { parsePlugins } from '../plugins';
import { resolveRelativePackage } from './utils';

/**
* Parses font files from various directories and applies a callback function to each font found.
* This function performs the following operations:
* 1. Logs the start of the font parsing process.
* 2. Retrieves the current context which includes the build configuration and paths.
* 3. Checks the project's build configuration for a fonts directory and applies the callback to each font found.
* 4. Checks the app configuration for multiple font directories and applies the callback to each font found.
* If no directories are specified, it checks for a single fonts directory.
* 5. Parses additional font sources specified in the configuration properties and applies the callback.
* 6. Parses font sources specified in plugin configurations and applies the callback.
*
* @param callback A function to be called for each font found. It receives the font name and its directory as arguments.
*/
export const parseFonts = (callback: ParseFontsCallback) => {
logDefault('parseFonts');

Expand Down
21 changes: 21 additions & 0 deletions packages/core/src/templates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,33 @@ export const configureTemplateFiles = async () => {
}
};

/**
* Checks if the template specified in the context's build configuration is installed.
*
* This function retrieves the current context and attempts to resolve the template
* name specified in the build configuration's templateConfig. If the template name
* is present and resolvable, the function returns the resolved path; otherwise, it
* returns false, indicating that the template is not installed.
*
* @returns {string | false} - The resolved path of the template if installed, or false if not.
*/
export const isTemplateInstalled = () => {
const ctx = getContext();
const tplName = ctx.buildConfig.templateConfig?.name;
return tplName ? doResolve(tplName) : false;
};

/**
* Applies the template configuration to the current project.
* This function retrieves the current context and checks if the project is marked as a template.
* If it is, the function exits early. If the project configuration is not loaded, an error is logged,
* and the function returns false. It also checks if the required template is installed; if not,
* it ensures that the project and node modules exist before proceeding. Finally, it applies the
* template by calling the internal `_applyTemplate` function with the current context.
*
* @returns {Promise<boolean>} - A promise that resolves to true if the template is applied successfully,
* or false if the project configuration is not loaded.
*/
export const applyTemplate = async () => {
const c = getContext();
logDefault('applyTemplate');
Expand Down
10 changes: 10 additions & 0 deletions packages/engine-core/src/tasks/app/taskAppConfigure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,16 @@ const appConfigure = async () => {
return true;
};

/**
* CLI command `npx rnv run app` triggers this task, which configures the project with the specified appConfig.
* This task performs the following actions:
* - Detects available appConfigs.
* - Resolves the correct appConfig for the current context.
* - Updates Renative configuration files.
* - Ensures required dependencies are installed.
*
* @returns {Promise<boolean>} Returns true when the task completes successfully.
*/
export default createTask({
description: 'Configure project with specific appConfig',
fn: async ({ ctx }) => {
Expand Down
Loading

0 comments on commit 6dcae8e

Please sign in to comment.