import { SemanticReleaseOptions } from '../executors/semantic-release/semantic-release'; import deepMap from 'deep-map'; export interface ConfigTokensDict { relativeProjectDir: string; projectDir: string; projectName: string; workspaceDir: string; } declare global { interface String { replaceAll(searchString: string, replacementValue: string): string; } } String.prototype.replaceAll = function ( searchString: string, replacementValue: string ): string { return this.split(searchString).join(replacementValue); }; export function applyTokensToSemanticReleaseOptions( options: SemanticReleaseOptions, tokens: ConfigTokensDict ) { const replaceTokens = (value: string): string => { return value .replaceAll('${RELATIVE_PROJECT_DIR}', tokens.relativeProjectDir) .replaceAll('${PROJECT_DIR}', tokens.projectDir) .replaceAll('${PROJECT_NAME}', tokens.projectName) .replaceAll('${WORKSPACE_DIR}', tokens.workspaceDir); }; return deepMap(options, (value) => { if (typeof value === 'string') { return replaceTokens(value); } return value; }); }