Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new syncRules field project files to allow users to specify middleware to use for files #813

Merged
merged 43 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
658e538
Implement hashing for Glob
Dekkonot Oct 26, 2023
ee53ffb
Pass overloads to lua middleware
Dekkonot Oct 26, 2023
77bcfdf
Basics of type transformers
Dekkonot Oct 26, 2023
cb6cd3b
Fix script paths not being trimmed
Dekkonot Oct 26, 2023
9830ef7
Document items in middleware and make them private
Dekkonot Oct 26, 2023
ebfee15
Make snapshot middleware file extension agnostic
Dekkonot Oct 26, 2023
486c189
Test basic syncing rules
Dekkonot Oct 26, 2023
9dfb020
Unimplement Hash for Glob
Dekkonot Oct 27, 2023
5a0c24d
Trim extensions instead of just one
Dekkonot Oct 27, 2023
ee850c4
Move middleware to trim multiple extensions
Dekkonot Oct 27, 2023
7f3dfda
Add a more complex test case
Dekkonot Oct 27, 2023
0f79b0a
Add complex sync rules serve test
Dekkonot Oct 27, 2023
188168f
Add test case for nested projects using sync rules
Dekkonot Oct 27, 2023
35ff632
Move SyncRule to a system similar to ignore globs
Dekkonot Oct 27, 2023
27a98c6
Use a better test for nested project files
Dekkonot Oct 27, 2023
918e42f
Clear sync rules between projects
Dekkonot Oct 27, 2023
fb12a92
Add snapshot for nested project test
Dekkonot Oct 27, 2023
2bcf374
Add documentation to new sync rule functions
Dekkonot Oct 27, 2023
49d8bd9
Update changelog
Dekkonot Oct 27, 2023
82cc4d4
Add suffix field for sync rules
Dekkonot Oct 30, 2023
8f64cca
Support suffix for snapshot_from_path
Dekkonot Oct 30, 2023
e7dbd1d
Pass name from snapshot origin to middleware
Dekkonot Oct 30, 2023
fd8f808
Remove file_name_trim_extensions
Dekkonot Oct 30, 2023
8cab628
Adjust how file_name_for_path works
Dekkonot Oct 30, 2023
53a273f
Add test for suffix trimming
Dekkonot Oct 30, 2023
ca2b2d8
Add test for sync rules with no file extension
Dekkonot Oct 30, 2023
36d33f7
Don't process file name for Lua snapshots
Dekkonot Oct 31, 2023
0c62a6e
Fix comments
Dekkonot Oct 31, 2023
e6f7314
Remove outdated test
Dekkonot Oct 31, 2023
d8dca68
Define fields more clearly in changelog
Dekkonot Oct 31, 2023
ee105da
Add PR number to changelog
Dekkonot Oct 31, 2023
1dbfb91
Delete the SyncRuleOuter struct
Dekkonot Oct 31, 2023
540d7d6
Use struct update syntax in project snapshots
Dekkonot Oct 31, 2023
c36ad2e
Use camelCase for Middleware enum in Serde
Dekkonot Oct 31, 2023
499f79a
Change nested project test to not overwrite parent syncrule
Dekkonot Nov 7, 2023
30e38af
Rename `get_sync_rule` to `get_user_sync_rule`
Dekkonot Nov 7, 2023
282a6f2
Support exclusions in sync rules
Dekkonot Nov 7, 2023
c61d8ee
Refactor to use syncing rules for default behavior
Dekkonot Nov 7, 2023
b980fb2
Mention `exclude` in changelog + mention nested behavior
Dekkonot Nov 7, 2023
8aa9011
Place default sync rule static into function
Dekkonot Nov 8, 2023
96ab5cd
Use an iterator for `get_user_sync_rule`
Dekkonot Nov 13, 2023
9ce4634
Merge branch 'master' into transformers
Dekkonot Jan 16, 2024
61d34e9
Fix typo made in github web view
Dekkonot Jan 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,51 @@

## 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",
},
{
"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.
Dekkonot marked this conversation as resolved.
Show resolved Hide resolved

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! |


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

## [7.4.0-rc3] - October 25, 2023
* Changed `sourcemap --watch` to only generate the sourcemap when it's necessary ([#800])
* Switched script source property getter and setter to `ScriptEditorService` methods ([#801])
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!
29 changes: 29 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,29 @@
{
"name": "sync_rule_complex",
"tree": {
"$path": "src"
},
"syncRules": [
{
"pattern": "*.module",
"use": "modulescript"
},
{
"pattern": "*.server",
"use": "serverscript"
},
{
"pattern": "*.client",
"use": "clientscript"
},
{
"pattern": "*.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,12 @@
{
"name": "sync_rule_nested_projects",
"tree": {
"$path": "nested.project.json"
},
"syncRules": [
{
"pattern": "*.rojo",
"use": "text"
}
Dekkonot marked this conversation as resolved.
Show resolved Hide resolved
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "nested",
"tree": {
"$path": "src"
},
"syncRules": [
{
"pattern": "*.txt",
"use": "ignore"
},
{
"pattern": "*.rojo",
"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
Loading