Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const R = require('ramda')
const { readFileSync } = require('fs')
const { dirname, isAbsolute, join, resolve } = require('path')
const assert = require('assert')
const yaml = require('js-yaml')
const parsing = require('@uiengine/util/src/parsing')
const Markdown = require('@uiengine/util/src/markdown')
const { invalidateRequireCache } = require('@uiengine/util/src/file')
const { markSample } = require('@uiengine/util/src/message')
const { UiengineInputError } = require('@uiengine/util/src/error')
const renderMarkdown = Markdown.parseString
const fromExternalFile = (embeddingFilePath, sourcePaths, filePath) => {
const isYAML = filePath.match(/\.ya?ml$/)
const isJS = filePath.match(/\.js(on)?$/)
const isMarkdown = filePath.match(/\.(md|markdown)?$/)
if (isYAML) {
const string = readFileSync(filePath, 'utf8')
return parseString(string, filePath, sourcePaths)
} else if (isMarkdown) {
const string = readFileSync(filePath, 'utf8')
return renderMarkdown(string, filePath, sourcePaths)
} else if (isJS) {
// invalidate require cache so that changes are reflected
invalidateRequireCache(filePath)
return require(filePath)