UNPKG

ocat-lang

Version:

A programming language for the web design and development

34 lines (28 loc) 1.02 kB
import path from "path"; import { readFileWP } from "../utils/readFile"; import { OcatConfig } from "../types"; interface PathRules { [key: string]: string; } const loadPathRules = (config: OcatConfig): PathRules | null => { return config.path ?? null; }; const replacePlaceholders = (value: string): string => { const projectRoot = process.cwd(); const projectName = projectRoot.split("/").pop() || ""; return value .replace("${projectRoot}", projectRoot) .replace("${projectName}", projectName); }; const applyPathRules = (wppath: string, rules: PathRules): string => { let ppath = wppath; for (const key in rules) { const replacedValue = replacePlaceholders(rules[key]); ppath = ppath.replace(key, replacedValue); } return ppath; }; export const processPath = (wppath: string, config: OcatConfig): string => { const rules = loadPathRules(config); return rules ? applyPathRules(wppath, rules) : wppath; };