UNPKG

maests

Version:

An executable compiler for creating Maestro's yaml-flows with typescript.

28 lines (27 loc) 1.14 kB
import { existsSync, mkdirSync, writeFileSync } from "fs"; import { getTsconfig } from "get-tsconfig"; import { createJiti } from "jiti"; import { dirname, join } from "path"; const { path, config } = getTsconfig(), tsConfigDir = dirname(path), maestsDir = join(tsConfigDir, "maests"); existsSync(maestsDir) || mkdirSync(maestsDir); const createYamlOutPath = (fullTsFlowPath) => { const tsFlowPath = fullTsFlowPath.replace(`${tsConfigDir}/`, ""); return join(maestsDir, tsFlowPath.replace(".ts", ".yaml")); }, writeFileWithDirectorySync = (filePath, data) => { const dir = dirname(filePath); existsSync(dir) || mkdirSync(dir, { recursive: !0 }), writeFileSync(filePath, data); }, normalizedAlias = Object.fromEntries( Object.entries(config?.compilerOptions?.paths || {}).map(([key, value]) => { const normalizedKey = key.replace("/*", ""), normalizedValue = value[0].replace("/*", ""); return [normalizedKey, join(dirname(path), normalizedValue)]; }) ), jiti = createJiti(process.cwd(), { alias: normalizedAlias }); export { createYamlOutPath, jiti, maestsDir, tsConfigDir, writeFileWithDirectorySync };