\\nIndex File
\\n\\n\\n\\n```fsharp\\nmodule Index.Util\\n\\nopen System\\nopen System.IO\\nopen System.Text.RegularExpressions\\n\\ntype FileInformation = {\\n FilePath : string\\n Lines : string []\\n} with\\n static member create(filePath: string, lines: string []) = {\\n FilePath = filePath\\n Lines = lines\\n }\\n\\nlet getAllFiles(path: string, extension: string) = \\n let options = EnumerationOptions()\\n options.RecurseSubdirectories <- true\\n IO.Directory.EnumerateFiles(path,extension,options)\\n |> Seq.filter (fun s -> s.Contains(\\"fable_modules\\") |> not)\\n |> Array.ofSeq\\n\\nlet findClasses (rootPath: string) (cois: string []) (regexPattern: string -> string) (filePaths: seq) = \\n let files = [|\\n for fp in filePaths do\\n yield FileInformation.create(fp, System.IO.File.ReadAllLines (fp))\\n |]\\n let importStatements = ResizeArray()\\n let findClass (className: string) = \\n /// maybe set this as default if you do not want any whitelist\\n let classNameDefault = @\\"[a-zA-Z_0-9]\\"\\n let pattern = Regex.Escape(className) |> regexPattern\\n let regex = Regex(pattern)\\n let mutable found = false\\n let mutable result = None\\n let enum = files.GetEnumerator()\\n while not found && enum.MoveNext() do\\n let fileInfo = enum.Current :?> FileInformation\\n for line in fileInfo.Lines do\\n let m = regex.Match(line)\\n match m.Success with\\n | true -> \\n found <- true\\n result <- Some <| (className, IO.Path.GetRelativePath(rootPath,fileInfo.FilePath))\\n | false ->\\n ()\\n match result with\\n | None ->\\n failwithf \\"Unable to find %s\\" className\\n | Some r ->\\n importStatements.Add r\\n for coi in cois do findClass coi\\n importStatements\\n |> Array.ofSeq\\n\\nlet writeIndexFile (path: string) (fileName: string) (content: string) =\\n let filePath = Path.Combine(path, fileName)\\n File.WriteAllText(filePath, content)\\n```\\n\\n\\n\\n```fsharp\\nmodule Index.JS\\n\\nlet private getAllJsFiles (path: string) fileExtension = \\n Util.getAllFiles(path,$\\"*.{fileExtension}\\")\\n\\nlet private pattern (className: string) = sprintf @\\"^export class (?%s)+[\\\\s{].*({)?\\" className\\n\\nlet private findJsClasses (rootPath: string) (whiteList: string []) (filePaths: string []) = \\n Util.findClasses rootPath whiteList pattern filePaths\\n\\nopen System.Text\\n\\nlet private createImportStatements (info: (string*string) []) =\\n let sb = StringBuilder()\\n let importCollection = info |> Array.groupBy snd |> Array.map (fun (p,a) -> p, a |> Array.map fst )\\n for filePath, imports in importCollection do\\n let p = filePath.Replace(\\"\\\\\\\\\\",\\"/\\").Replace(\\"ts\\",\\"js\\")\\n sb.Append \\"export { \\" |> ignore\\n sb.AppendJoin(\\", \\", imports) |> ignore\\n sb.Append \\" } from \\" |> ignore\\n sb.Append (sprintf \\"\\\\\\"./%s\\\\\\"\\" p) |> ignore\\n sb.Append \\";\\" |> ignore\\n sb.AppendLine() |> ignore\\n sb.ToString()\\n\\nlet private generateIndexfile (rootPath: string, fileName: string, whiteList: string [], fileExtension: string) =\\n getAllJsFiles rootPath fileExtension\\n |> findJsClasses rootPath whiteList\\n |> createImportStatements\\n |> Util.writeIndexFile rootPath fileName\\n\\nlet generate(rootPath: string) (ts: bool) = \\n let extension = if ts then \\"ts\\" else \\"js\\"\\n generateIndexfile(rootPath, $\\"index.{extension}\\", WhiteList.WhiteList, extension)\\n```\\n\\n\\n\\n```fsharp\\nlet private getAllJsFiles(path: string) = \\n Util.getAllFiles(path,\\"*.py\\")\\n\\nlet private pattern (className: string) = sprintf @\\"^class (?%s)+(\\\\(|:).*$\\" className\\n\\nlet private findPyClasses (rootPath: string) (whiteList: string []) (filePaths: string []) = \\n Util.findClasses rootPath whiteList pattern filePaths\\n\\nopen System.Text\\n\\nlet private createImportStatements (info: (string*string) []) =\\n let sb = StringBuilder()\\n let importCollection = info |> Array.groupBy snd |> Array.map (fun (p,a) -> p, a |> Array.map fst )\\n for filePath, imports in importCollection do\\n let p = filePath |> Path.GetFileNameWithoutExtension\\n sb.Append (sprintf \\"from .%s import \\" p) |> ignore\\n sb.AppendJoin(\\", \\", imports) |> ignore\\n sb.AppendLine() |> ignore\\n sb.ToString()\\n\\nlet private generateIndexfile (rootPath: string, fileName: string, whiteList: string []) =\\n getAllJsFiles(rootPath)\\n |> findPyClasses rootPath whiteList\\n |> createImportStatements\\n |> Util.writeIndexFile rootPath fileName\\n\\nlet generate(rootPath: string) (name: string) = \\n // code to make camelcase to snakecase\\n /// This is because we currently snake_case everything that does not start with a capital letter\\n let camelCaseToSnakeCase (str: string) = \\n if Char.IsUpper str.[0] then\\n str \\n else\\n str \\n |> Seq.fold (fun (acc: string) c -> \\n if Char.IsUpper c then \\n acc + \\"_\\" + string (Char.ToLower c) \\n else \\n acc + string c\\n ) \\"\\"\\n let snake_case_white_list = WhiteList.WhiteList |> Array.map camelCaseToSnakeCase\\n generateIndexfile(rootPath, name, snake_case_white_list)\\n```\\n\\n\\n```fsharp\\nmodule Index.WhiteList\\n\\nlet WhiteList = [|\\n \\"SirenElement\\"\\n // ThemeVaruiables\\n \\"themeVariable\\"\\n \\"quadrantTheme\\"; \\n \\"gitTheme\\"; \\n \\"timelineTheme\\"; \\n \\"xyChartTheme\\"; \\n \\"pieTheme\\";\\n // Config\\n \\"graphConfig\\";\\n \\"flowchartConfig\\"; \\n \\"sequenceConfig\\"; \\n \\"ganttConfig\\"; \\n \\"journeyConfig\\"; \\n \\"timelineConfig\\"; \\n \\"classConfig\\"; \\n \\"stateConfig\\"; \\n \\"erConfig\\"; \\n \\"quadrantChartConfig\\"; \\n \\"pieConfig\\"; \\n \\"sankeyConfig\\"; \\n \\"xyChartConfig\\"; \\n \\"mindmapConfig\\"; \\n \\"gitGraphConfig\\"; \\n \\"requirementConfig\\"; \\n // Graphs and Helpers\\n \\"formatting\\"; \\n \\"direction\\"; \\n \\"flowchart\\"; \\n \\"notePosition\\"; \\n \\"sequence\\"; \\n \\"classMemberVisibility\\"; \\n \\"classMemberClassifier\\"; \\n \\"classDirection\\"; \\n \\"classCardinality\\"; \\n \\"classRltsType\\"; \\n \\"classDiagram\\"; \\n \\"stateDiagram\\"; \\n \\"erKey\\"; \\n \\"erCardinality\\"; \\n \\"erDiagram\\"; \\n \\"journey\\"; \\n \\"ganttTime\\"; \\n \\"ganttTags\\"; \\n \\"ganttUnit\\"; \\n \\"gantt\\"; \\n \\"pieChart\\"; \\n \\"quadrant\\"; \\n \\"rqRisk\\"; \\n \\"rqMethod\\"; \\n \\"requirement\\"; \\n \\"gitType\\"; \\n \\"git\\"; \\n \\"mindmap\\"; \\n \\"timeline\\"; \\n \\"sankey\\"; \\n \\"xyChart\\"; \\n \\"block\\"; \\n \\"theme\\"; \\n \\"siren\\"; \\n|]\\n```\\n\\n\\n\\n
\\n \\n\\nThe resulting files look like this:\\n\\n