UNPKG

@storm-software/config-tools

Version:

A package containing various utilities to support custom workspace configurations and environment management for Storm Software projects, including configuration file handling, environment variable management, and logging utilities.

82 lines (79 loc) 2.32 kB
import { findWorkspaceRoot } from "./chunk-LF3SAK2O.js"; // src/utilities/apply-workspace-tokens.ts var applyWorkspaceBaseTokens = async (option, tokenParams) => { let result = option; if (!result) { return result; } if (tokenParams) { const optionKeys = Object.keys(tokenParams); if (optionKeys.some((optionKey) => result.includes(`{${optionKey}}`))) { for (const optionKey of optionKeys) { if (result.includes(`{${optionKey}}`)) { result = result.replaceAll( `{${optionKey}}`, tokenParams?.[optionKey] || "" ); } } } } if (tokenParams.config) { const configKeys = Object.keys(tokenParams.config); if (configKeys.some((configKey) => result.includes(`{${configKey}}`))) { for (const configKey of configKeys) { if (result.includes(`{${configKey}}`)) { result = result.replaceAll( `{${configKey}}`, tokenParams.config[configKey] || "" ); } } } } if (result.includes("{workspaceRoot}")) { result = result.replaceAll( "{workspaceRoot}", tokenParams.workspaceRoot ?? tokenParams.config?.workspaceRoot ?? findWorkspaceRoot() ); } return result; }; var applyWorkspaceProjectTokens = (option, tokenParams) => { return applyWorkspaceBaseTokens(option, tokenParams); }; var applyWorkspaceTokens = async (options, tokenParams, tokenizerFn) => { if (!options) { return {}; } const result = {}; for (const option of Object.keys(options)) { if (typeof options[option] === "string") { result[option] = await Promise.resolve( tokenizerFn(options[option], tokenParams) ); } else if (Array.isArray(options[option])) { result[option] = await Promise.all( options[option].map( async (item) => typeof item === "string" ? await Promise.resolve(tokenizerFn(item, tokenParams)) : item ) ); } else if (typeof options[option] === "object") { result[option] = await applyWorkspaceTokens( options[option], tokenParams, tokenizerFn ); } else { result[option] = options[option]; } } return result; }; export { applyWorkspaceBaseTokens, applyWorkspaceProjectTokens, applyWorkspaceTokens };