Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d49c471

Browse files
committed
feat(docs): update migration and plugin documentation
- Removed outdated notes from migration guide. - Enhanced clarity in plugin documentation with detailed examples. - Added new sections on plugin lifecycle and authoring plugins.
1 parent c9aa7ed commit d49c471

File tree

3 files changed

+135
-18
lines changed

3 files changed

+135
-18
lines changed

docs/assets/content/migrate.md

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,6 @@ Here's the list of breaking changes for the `perla.json` file
9999

100100
## Config Additions
101101

102-
- runConfiguration ->
103-
104-
New: perla now supports running/testing apps in production/development mode, the default is production as it will only pick up dependencies required by the application at runtime, development mode is chosen by the test command to pick up libraries that are only relevant for testing, you can also use development mode to add uility libraries that should only run at dev time like rxjs-spy (to debug rxjs observables)
105-
106-
```diff
107-
+ "runConfiguration": "production"
108-
109-
# or
110-
+ "runConfiguration": "development"
111-
```
112-
113102
- provider ->
114103

115104
New: In v0 we had a couple of providers but we had custom mechanisms to fetch dependencies and update the import map, for v1 we will leverage completely the [jspm generator api] so we use the same providers to accomplish the same effect, pease refer to the [package manager] documentation for more information
@@ -126,7 +115,7 @@ Here's the list of breaking changes for the `perla.json` file
126115

127116
- plugins ->
128117

129-
**_NEW_**: At last! Plugins are here to stay, and while they are not as powerful as the ones existing in other tools like vite, snowpack, rollup, webpack, But given what we've got, it is a start for future versions
118+
**_NEW_**: At last! Plugins are here to stay. While they are not as powerful as the ones existing in other tools like vite, snowpack, rollup, webpack, But given what we've got, it is a start for future versions
130119
please refer to the [plugins] documentation for more information
131120

132121
- testing ->
@@ -192,9 +181,9 @@ Here's the list of breaking changes for the `perla.json` file
192181
+ "includes: [ "assets/images/*", "documents/*/*.html" ]
193182
+ }
194183

195-
# Experimental: copy files that live within the virtual file system to the output directory
184+
# Copy files that live within the virtual file system to the output directory
196185
+ "build": {
197-
+ "includes: [ "vfs:src/*/*.html" ]
186+
+ "includes: [ "vfs:**/*.html" ]
198187
+ }
199188
```
200189

@@ -258,7 +247,7 @@ Here's the list of breaking changes for the `perla.json` file
258247

259248
### Deprecated Configuration Options
260249

261-
The following configuration options are still present in the schema for backward compatibility, but are **deprecated** and should not be used in new `perla.json` files. If you are migrating, you should remove or replace these options as described below:
250+
The following configuration options are still present in the schema, but are **deprecated** and should not be used in new `perla.json` files. If you are migrating, you should remove or replace these options as described below:
262251

263252
#### Top-level deprecated options
264253

Lines changed: 130 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,131 @@
1-
> **_NOTE_**: This documentation is still being updated to reflect changes for V1, the contents may be outdated while this notice is still present
2-
31
# Plugins
2+
3+
Perla supports plugins to extend build and serve functionality. Plugins must be authored manually as F# script files and placed in the `.perla/plugins` directory of your project.
4+
5+
## Using Plugins
6+
7+
Add plugins to your `perla.json` configuration by specifying the plugin name:
8+
9+
```json
10+
{
11+
"plugins": ["markdown-plugin"]
12+
}
13+
```
14+
15+
Perla will automatically look for plugins in the `.perla/plugins` directory of your project. Each plugin is registered with a name specified in the plugin definition.
16+
17+
## Plugin API
18+
19+
The Perla plugin API provides several types and functions to help you create plugins:
20+
21+
### FileTransform
22+
23+
The core data structure that plugins operate on:
24+
25+
```fsharp
26+
type FileTransform = {
27+
/// The text of the file, this will change between plugin transformations
28+
content: string
29+
/// The extension this file is currently holding
30+
/// this will change between plugin transformations
31+
/// It also serves for plugin authors to determine
32+
/// if their plugin should act on this particular file
33+
extension: string
34+
/// Full path to the source file
35+
fileLocation: string
36+
}
37+
```
38+
39+
### FilePredicate
40+
41+
A function that determines whether a plugin should process a file:
42+
43+
```fsharp
44+
/// A function predicate that allows the plugin author
45+
/// to signal if the file should be processed by the plugin or not
46+
type FilePredicate = string -> bool
47+
```
48+
49+
### Transform Functions
50+
51+
Perla supports multiple types of transform functions:
52+
53+
```fsharp
54+
/// A Synchronous function that takes the content of the file and its extension
55+
/// and returns the processed content and the new extension after processing the file
56+
type Transform = FileTransform -> FileTransform
57+
58+
/// A Task<'T> based asynchronous function
59+
type TransformTask = FileTransform -> Task<FileTransform>
60+
61+
/// An Async<'T> based asynchronous function
62+
type TransformAsync = FileTransform -> Async<FileTransform>
63+
64+
/// A ValueTask<'T> based function (used internally by Perla)
65+
type TransformAction = FileTransform -> ValueTask<FileTransform>
66+
```
67+
68+
If a transform function cannot modify the content for any reason, it should return the original `FileTransform` and log the error to the console rather than crashing.
69+
70+
### Plugin Builder
71+
72+
Plugins are defined using a computation expression builder:
73+
74+
```fsharp
75+
plugin "plugin-name" {
76+
should_process_file (fun extension -> /* predicate logic */)
77+
with_transform (fun file -> /* transform logic */)
78+
}
79+
```
80+
81+
The builder supports these operations:
82+
- `should_process_file`: Defines a predicate to determine if a file should be processed
83+
- `with_transform`: Defines the transformation to apply to matching files
84+
85+
Note that if you provide multiple instances of the same operation, only the first one will be used by Perla.
86+
87+
## Authoring Plugins
88+
89+
Plugins are written in F# as script files (`.fsx`). Each plugin exports logic using the Perla plugin API. The plugin receives hooks to process files during build or serve.
90+
91+
Example plugin (`.perla/plugins/markdown.fsx`):
92+
93+
```fsharp
94+
#r "nuget: Markdig, 0.41.3"
95+
#r "nuget: Perla.Plugins, 1.0.0-beta-030"
96+
97+
open Perla.Plugins
98+
open Markdig
99+
100+
let pipeline =
101+
lazy
102+
(MarkdownPipelineBuilder()
103+
.UseAdvancedExtensions()
104+
.UsePreciseSourceLocation()
105+
.Build())
106+
107+
let shouldProcess: FilePredicate =
108+
fun extension -> [ ".md"; ".markdown" ] |> List.contains extension
109+
110+
let transform: Transform =
111+
fun args -> {
112+
args with
113+
content = Markdown.ToHtml(args.content, pipeline.Value)
114+
extension = ".html"
115+
}
116+
117+
plugin "markdown-plugin" {
118+
should_process_file shouldProcess
119+
with_transform transform
120+
}
121+
```
122+
123+
## Plugin Lifecycle
124+
125+
1. Perla loads plugins from the `.perla/plugins` directory at startup
126+
2. Each plugin is registered with its specified name
127+
3. During build or serve, for each file:
128+
- Perla checks each plugin's `should_process_file` predicate
129+
- If the predicate returns true, the file is passed to the plugin's transform function
130+
- The transform function processes the file and returns the modified content and extension
131+
- The transformed file is then passed to the next matching plugin or written to disk

tests/Perla.Tests/FileSystem.Tests.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ let ``CopyGlobs should copy files matching local file system patterns``() =
626626
}
627627

628628
// Execute CopyGlobs
629-
fsManager.CopyGlobs(buildConfig)
629+
fsManager.CopyGlobs(buildConfig, outputTempDir.Path)
630630

631631
// Verify files were copied
632632
let expectedTestFile = Path.Combine(UMX.untag outputTempDir.Path, "test.txt")

0 commit comments

Comments
 (0)