docs: diagrams plugin tooling (#5741)
* added plugin * updated plugin + added component * dummy data TO BE REMOVED * (wip) workflow generator tool * add workflow generator tooling * updated the generator tool * added code file creation * fix design of diagrams * configured diagram theme * added build script * removed comments + unnecessary files * general fixes * refactored plugin * added README + more output types
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
export default function (str: string): string {
|
||||
return str.replaceAll(`"`, "#quot;").replaceAll("-", "–")
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export const SPACING = "\t"
|
||||
|
||||
export function getLinePrefix(indentation = 0): string {
|
||||
return `\n${SPACING.repeat(indentation)}`
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
export default function (length = 4) {
|
||||
let result = ""
|
||||
const characters =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
||||
const charactersLength = characters.length
|
||||
let counter = 0
|
||||
while (counter < length) {
|
||||
result += characters.charAt(Math.floor(Math.random() * charactersLength))
|
||||
counter += 1
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import { statSync, readFileSync } from "fs"
|
||||
import * as glob from "glob"
|
||||
import path from "path"
|
||||
import { fileURLToPath } from "url"
|
||||
|
||||
type FileInfo = {
|
||||
workflowId: string
|
||||
code: string
|
||||
}
|
||||
|
||||
export default async function (
|
||||
workflowPath: string
|
||||
): Promise<Map<string, string>> {
|
||||
const workflowDefinitions = new Map<string, string>()
|
||||
const fileStat = statSync(workflowPath)
|
||||
if (fileStat.isFile()) {
|
||||
const fileInfo = await importFile(workflowPath)
|
||||
if (fileInfo.workflowId.length && fileInfo.code.length) {
|
||||
workflowDefinitions.set(fileInfo.workflowId, fileInfo.code)
|
||||
}
|
||||
} else {
|
||||
const files = glob.sync(`${workflowPath}/**/*.{ts,js}`, {})
|
||||
await Promise.all(
|
||||
files.map(async (file) => {
|
||||
const fileInfo = await importFile(file)
|
||||
if (fileInfo.workflowId.length && fileInfo.code.length) {
|
||||
workflowDefinitions.set(fileInfo.workflowId, fileInfo.code)
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
return workflowDefinitions
|
||||
}
|
||||
|
||||
function getRelativeImportPath(filePath: string) {
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
return path.relative(path.dirname(__filename), filePath)
|
||||
}
|
||||
|
||||
async function importFile(filePath: string): Promise<FileInfo> {
|
||||
const fileInfo: FileInfo = {
|
||||
workflowId: "",
|
||||
code: "",
|
||||
}
|
||||
|
||||
const relativeFilePath = getRelativeImportPath(filePath)
|
||||
const imported = await import(relativeFilePath)
|
||||
|
||||
fileInfo.code = readFileSync(filePath, "utf-8")
|
||||
|
||||
if (imported.default) {
|
||||
switch (typeof imported.default) {
|
||||
case "function":
|
||||
fileInfo.workflowId = getWorkflowName(imported.default) || ""
|
||||
break
|
||||
case "object":
|
||||
Object.values(imported.default).find((exportedVariable: unknown) => {
|
||||
fileInfo.workflowId = getWorkflowName(exportedVariable) || ""
|
||||
return fileInfo.workflowId.length !== 0
|
||||
})
|
||||
}
|
||||
} else if (typeof imported === "object") {
|
||||
Object.values(imported).find((exportedVariable: unknown) => {
|
||||
fileInfo.workflowId = getWorkflowName(exportedVariable) || ""
|
||||
return fileInfo.workflowId.length !== 0
|
||||
})
|
||||
}
|
||||
|
||||
return fileInfo
|
||||
}
|
||||
|
||||
function getWorkflowName(variable: unknown): string | undefined {
|
||||
return typeof variable === "function" &&
|
||||
"getName" in variable &&
|
||||
typeof variable.getName === "function"
|
||||
? variable.getName()
|
||||
: undefined
|
||||
}
|
||||
Reference in New Issue
Block a user