Skip to content

Commit

Permalink
Add a new syncRules field project files to allow users to specify m…
Browse files Browse the repository at this point in the history
…iddleware to use for files (rojo-rbx#813)
  • Loading branch information
Dekkonot authored Jan 20, 2024
1 parent c0a96e3 commit 73828af
Show file tree
Hide file tree
Showing 48 changed files with 915 additions and 138 deletions.
49 changes: 49 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,55 @@

## Unreleased Changes

* Projects may now specify rules for syncing files as if they had a different file extension. ([#813])
This is specified via a new field on project files, `syncRules`:

```json
{
"syncRules": [
{
"pattern": "*.foo",
"use": "text",
"exclude": "*.exclude.foo",
},
{
"pattern": "*.bar.baz",
"use": "json",
"suffix": ".bar.baz",
},
],
"name": "SyncRulesAreCool",
"tree": {
"$path": "src"
}
}
```

The `pattern` field is a glob used to match the sync rule to files. If present, the `suffix` field allows you to specify parts of a file's name get cut off by Rojo to name the Instance, including the file extension. If it isn't specified, Rojo will only cut off the first part of the file extension, up to the first dot.

Additionally, the `exclude` field allows files to be excluded from the sync rule if they match a pattern specified by it. If it's not present, all files that match `pattern` will be modified using the sync rule.

The `use` field corresponds to one of the potential file type that Rojo will currently include in a project. Files that match the provided pattern will be treated as if they had the file extension for that file type. A full list is below:

| `use` value | file extension |
|:---------------|:----------------|
| `serverScript` | `.server.lua` |
| `clientScript` | `.client.lua` |
| `moduleScript` | `.lua` |
| `json` | `.json` |
| `toml` | `.toml` |
| `csv` | `.csv` |
| `text` | `.txt` |
| `jsonModel` | `.model.json` |
| `rbxm` | `.rbxm` |
| `rbxmx` | `.rbxmx` |
| `project` | `.project.json` |
| `ignore` | None! |

**All** sync rules are reset between project files, so they must be specified in each one when nesting them. This is to ensure that nothing can break other projects by changing how files are synced!

[#813]: https://github.com/rojo-rbx/rojo/pull/813

## [7.4.0] - January 16, 2024
* Improved the visualization for array properties like Tags ([#829])
* Significantly improved performance of `rojo serve`, `rojo build --watch`, and `rojo sourcemap --watch` on macOS. ([#830])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
source: tests/tests/build.rs
assertion_line: 102
expression: contents
---
<roblox version="4">
<Item class="Folder" referent="0">
<Properties>
<string name="Name">sync_rule_alone</string>
</Properties>
<Item class="StringValue" referent="1">
<Properties>
<string name="Name">foo</string>
<string name="Value">Hello, world!</string>
</Properties>
</Item>
</Item>
</roblox>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
source: tests/tests/build.rs
assertion_line: 104
expression: contents
---
<roblox version="4">
<Item class="Folder" referent="0">
<Properties>
<string name="Name">sync_rule_complex</string>
</Properties>
<Item class="Script" referent="1">
<Properties>
<string name="Name">bar</string>
<token name="RunContext">0</token>
<string name="Source">-- Hello, from bar (a Script)!</string>
</Properties>
</Item>
<Item class="LocalScript" referent="2">
<Properties>
<string name="Name">baz</string>
<string name="Source">-- Hello, from baz (a LocalScript)!</string>
</Properties>
</Item>
<Item class="StringValue" referent="3">
<Properties>
<string name="Name">cat</string>
<string name="Value">Hello, from cat (a StringValue)!</string>
</Properties>
</Item>
<Item class="ModuleScript" referent="4">
<Properties>
<string name="Name">foo</string>
<string name="Source">-- Hello, from foo (a ModuleScript)!</string>
</Properties>
</Item>
<Item class="StringValue" referent="5">
<Properties>
<string name="Name">qux</string>
<string name="Value">Hello, from qux (a .rojo file that's turned into a StringValue)!</string>
</Properties>
</Item>
</Item>
</roblox>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: tests/tests/build.rs
assertion_line: 104
expression: contents
---
<roblox version="4">
<Item class="Folder" referent="0">
<Properties>
<string name="Name">sync_rule_nested_projects</string>
</Properties>
</Item>
</roblox>
12 changes: 12 additions & 0 deletions rojo-test/build-tests/sync_rule_alone/default.project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "sync_rule_alone",
"tree": {
"$path": "src"
},
"syncRules": [
{
"pattern": "*.nothing",
"use": "text"
}
]
}
1 change: 1 addition & 0 deletions rojo-test/build-tests/sync_rule_alone/src/foo.nothing
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello, world!
30 changes: 30 additions & 0 deletions rojo-test/build-tests/sync_rule_complex/default.project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "sync_rule_complex",
"tree": {
"$path": "src"
},
"syncRules": [
{
"pattern": "*.module",
"use": "moduleScript"
},
{
"pattern": "*.server",
"use": "serverScript"
},
{
"pattern": "*.client",
"use": "clientScript"
},
{
"pattern": "*.rojo",
"exclude": "*.ignore.rojo",
"use": "project"
},
{
"pattern": "*.dog.rojo2",
"use": "text",
"suffix": ".dog.rojo2"
}
]
}
1 change: 1 addition & 0 deletions rojo-test/build-tests/sync_rule_complex/src/bar.server
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- Hello, from bar (a Script)!
1 change: 1 addition & 0 deletions rojo-test/build-tests/sync_rule_complex/src/baz.client
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- Hello, from baz (a LocalScript)!
1 change: 1 addition & 0 deletions rojo-test/build-tests/sync_rule_complex/src/cat.dog.rojo2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello, from cat (a StringValue)!
1 change: 1 addition & 0 deletions rojo-test/build-tests/sync_rule_complex/src/foo.module
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- Hello, from foo (a ModuleScript)!
9 changes: 9 additions & 0 deletions rojo-test/build-tests/sync_rule_complex/src/qux.rojo
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "qux",
"tree": {
"$className": "StringValue",
"$properties": {
"Value": "Hello, from qux (a .rojo file that's turned into a StringValue)!"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file should be ignored!
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "sync_rule_nested_projects",
"tree": {
"$path": "nested.project.json"
},
"syncRules": [
{
"pattern": "*.rojo",
"use": "text"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "nested",
"tree": {
"$path": "src"
},
"syncRules": [
{
"pattern": "*.txt",
"use": "ignore"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This shouldn't be in the built file. If it is, something is wrong.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This shouldn't be in the built file. If it is, something is wrong.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
source: tests/tests/serve.rs
assertion_line: 268
expression: "read_response.intern_and_redact(&mut redactions, root_id)"
---
instances:
id-2:
Children:
- id-3
ClassName: Folder
Id: id-2
Metadata:
ignoreUnknownInstances: false
Name: sync_rule_alone
Parent: "00000000000000000000000000000000"
Properties: {}
id-3:
Children: []
ClassName: StringValue
Id: id-3
Metadata:
ignoreUnknownInstances: false
Name: foo
Parent: id-2
Properties:
Value:
String: "Hello, world!"
messageCursor: 0
sessionId: id-1

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: tests/tests/serve.rs
assertion_line: 265
expression: redactions.redacted_yaml(info)
---
expectedPlaceIds: ~
gameId: ~
placeId: ~
projectName: sync_rule_alone
protocolVersion: 4
rootInstanceId: id-2
serverVersion: "[server-version]"
sessionId: id-1

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
source: tests/tests/serve.rs
assertion_line: 284
expression: "read_response.intern_and_redact(&mut redactions, root_id)"
---
instances:
id-2:
Children:
- id-3
- id-4
- id-5
- id-6
- id-7
ClassName: Folder
Id: id-2
Metadata:
ignoreUnknownInstances: false
Name: sync_rule_complex
Parent: "00000000000000000000000000000000"
Properties: {}
id-3:
Children: []
ClassName: Script
Id: id-3
Metadata:
ignoreUnknownInstances: false
Name: bar
Parent: id-2
Properties:
RunContext:
Enum: 0
Source:
String: "-- Hello, from bar (a Script)!"
id-4:
Children: []
ClassName: LocalScript
Id: id-4
Metadata:
ignoreUnknownInstances: false
Name: baz
Parent: id-2
Properties:
Source:
String: "-- Hello, from baz (a LocalScript)!"
id-5:
Children: []
ClassName: StringValue
Id: id-5
Metadata:
ignoreUnknownInstances: false
Name: cat
Parent: id-2
Properties:
Value:
String: "Hello, from cat (a StringValue)!"
id-6:
Children: []
ClassName: ModuleScript
Id: id-6
Metadata:
ignoreUnknownInstances: false
Name: foo
Parent: id-2
Properties:
Source:
String: "-- Hello, from foo (a ModuleScript)!"
id-7:
Children: []
ClassName: StringValue
Id: id-7
Metadata:
ignoreUnknownInstances: true
Name: qux
Parent: id-2
Properties:
Value:
String: "Hello, from qux (a .rojo file that's turned into a StringValue)!"
messageCursor: 0
sessionId: id-1

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: tests/tests/serve.rs
assertion_line: 281
expression: redactions.redacted_yaml(info)
---
expectedPlaceIds: ~
gameId: ~
placeId: ~
projectName: sync_rule_complex
protocolVersion: 4
rootInstanceId: id-2
serverVersion: "[server-version]"
sessionId: id-1

Loading

0 comments on commit 73828af

Please sign in to comment.