Refactoring Script for Copying Notes to use EffectTS

7/5/2024

Refactoring

This is a post I'm working on about refactoring in general. I want to walk through a refactor, describe how I used MermaidJS and learn EffectTS.

I want to refactor my script for copying my Obsidian notes to content git repo to use EffectTS.

Here's a diagram of the flow written in MermaidJS.

flowchart TD
    AA[/"`Input path to file directory`"/]-->B(("`Start`"))
    AB[/Write directory path/]-->B
    B-->C[Get Directory Contents]
    C-->CD[(Files and folders)]
    CD-->CB[Iterate Directory Contents]
    EB-->C
    
    subgraph Iterate Directory Contents
        CA{Another item?}-->|Yes|D{"`File or Folder?`"} 
        D-->|File|EA{"`Is .md || .mdx?`"}
        D-->|Folder|EB["`Recursive call`"]
        EA-->|Yes|FA["`Read file`"]
        EA-->|No|CA
        FA-->G[Parse Frontmatter]
        G-->H{"`Has **published** status?`"}
        H-->|Yes|IA[Process Metadata]
        H-->|No|CA
        IA-->J[Handle Embedded Images]
        J-->K[Generate Slug]
        K-->M[(Write Processed File)]
    end

CA-->|No|BB
    M-->BB((End))
Chase Adams