Home

Awesome

EasyBuild.FileSystemProvider

NuGet

EasyBuild.FileSystemProvider is a library that provides a set of F# Type Providers to provide a typed representation of files and directories based on your project structure or a virtual file system.

Why?

In every project of mine, I need to orchestrate tasks like building, testing, etc. which involves working with files and directories. The standard way of doing it is by using hardcoded string but it is easy to break. You also need to remember what is current working directory or relative path you are working with.

To fix this problem, I created this library that provides 2 F# Type Providers:

When to use each one?

Use RelativeFileSystemProvider when you want to access files and directories that are tracked in your project. For example, you want to access the path of your fsproj file or a public assets folder.

Use VirtualFileSystemProvider when you want to access files and directories that are not tracked in your project. For example, you want to use a destination folder or access a obj, bin folder.

Installation

dotnet add package EasyBuild.FileSystemProvider

Usage

RelativeFileSystemProvider

Provide a representation based on your file system structure.

open EasyBuild.FileSystemProvider

// Path the relative path you want to work with
// You can use `"."` or `""` to represent the current directory

type Workspace = RelativeFileSystem<".">

type SourceWorkspace = RelativeFileSystem<"./src/">

Each folder have 2 special properties and 1 static method:

Example:

Imagine you have the following project structure:

/home/project/
├── client/
│   ├── index.html
│   └── app.js
└── docs/
// Workspace represents the root folder `/home/project/`
type Workspace = RelativeFileSystem<".">

Workspace.client.``index.html`` // gives you "/home/project/client/index.html"
Workspace.client.``.`` // gives you "/home/project/client"
Workspace.client.``..``.docs // gives you "/home/project/docs"
// etc.

[!WARNING] At the time of writing, RelativeFileSystemProvider does not watch you filesystem for changes. In order for your IDE, to pick changes, you either need to restart it or make a change to RelativeFileSystemProvider<"."> to force a refresh.

This is planned to be improved in the future

VirtualFileSystemProvider

Provide a representation based on a virtual file system.

open EasyBuild.FileSystemProvider

type VirtualWorkspace =
    VirtualFileSystem<
        ".",    // Relative path for the root folder
        """
dist
    client
        index.html
        app.js
docs/
public
    style.css
    """
     >

Template format:

[!NOTE] You can use any number of spaces or tabs for indentation.

```text
dist
    client
        index.html
        app.js
docs/
public
    style.css
```

Example:

We consider that you are initializing the VirtualWorkspace at /home/project/.

// VirtualWorkspace represents the root folder `/home/project/`
type VirtualWorkspace =
    VirtualFileSystem<
        ".",
        """
dist
    client
        index.html
        app.js
docs/
public
    style.css
    """
     >

VirtualWorkspace.dist.client.``index.html`` // gives you "/home/project/dist/client/index.html"
VirtualWorkspace.dist.client.``.`` // gives you "/home/project/dist/client"
VirtualWorkspace.dist.``..``.docs.``.`` // gives you "/home/project/docs"

Contributing

If you want to contribute to this project, and see errors in the build because of the Type Providers, it is possible that you need to build them manually once.

  1. dotnet build src
    
  2. Reload the project in your IDE

  3. Everything should be fine now