diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7542adc7..7552a0ed 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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])
diff --git a/rojo-test/build-test-snapshots/end_to_end__tests__build__sync_rule_alone.snap b/rojo-test/build-test-snapshots/end_to_end__tests__build__sync_rule_alone.snap
new file mode 100644
index 00000000..53e329cc
--- /dev/null
+++ b/rojo-test/build-test-snapshots/end_to_end__tests__build__sync_rule_alone.snap
@@ -0,0 +1,18 @@
+---
+source: tests/tests/build.rs
+assertion_line: 102
+expression: contents
+---
+
+ -
+
+ sync_rule_alone
+
+
-
+
+ foo
+ Hello, world!
+
+
+
+
diff --git a/rojo-test/build-test-snapshots/end_to_end__tests__build__sync_rule_complex.snap b/rojo-test/build-test-snapshots/end_to_end__tests__build__sync_rule_complex.snap
new file mode 100644
index 00000000..e38050d8
--- /dev/null
+++ b/rojo-test/build-test-snapshots/end_to_end__tests__build__sync_rule_complex.snap
@@ -0,0 +1,43 @@
+---
+source: tests/tests/build.rs
+assertion_line: 104
+expression: contents
+---
+
+ -
+
+ sync_rule_complex
+
+
-
+
+ bar
+ 0
+ -- Hello, from bar (a Script)!
+
+
+ -
+
+ baz
+ -- Hello, from baz (a LocalScript)!
+
+
+ -
+
+ cat
+ Hello, from cat (a StringValue)!
+
+
+ -
+
+ foo
+ -- Hello, from foo (a ModuleScript)!
+
+
+ -
+
+ qux
+ Hello, from qux (a .rojo file that's turned into a StringValue)!
+
+
+
+
diff --git a/rojo-test/build-test-snapshots/end_to_end__tests__build__sync_rule_nested_projects.snap b/rojo-test/build-test-snapshots/end_to_end__tests__build__sync_rule_nested_projects.snap
new file mode 100644
index 00000000..6867ac37
--- /dev/null
+++ b/rojo-test/build-test-snapshots/end_to_end__tests__build__sync_rule_nested_projects.snap
@@ -0,0 +1,12 @@
+---
+source: tests/tests/build.rs
+assertion_line: 104
+expression: contents
+---
+
+ -
+
+ sync_rule_nested_projects
+
+
+
diff --git a/rojo-test/build-tests/sync_rule_alone/default.project.json b/rojo-test/build-tests/sync_rule_alone/default.project.json
new file mode 100644
index 00000000..f3a5aa34
--- /dev/null
+++ b/rojo-test/build-tests/sync_rule_alone/default.project.json
@@ -0,0 +1,12 @@
+{
+ "name": "sync_rule_alone",
+ "tree": {
+ "$path": "src"
+ },
+ "syncRules": [
+ {
+ "pattern": "*.nothing",
+ "use": "text"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/rojo-test/build-tests/sync_rule_alone/src/foo.nothing b/rojo-test/build-tests/sync_rule_alone/src/foo.nothing
new file mode 100644
index 00000000..5dd01c17
--- /dev/null
+++ b/rojo-test/build-tests/sync_rule_alone/src/foo.nothing
@@ -0,0 +1 @@
+Hello, world!
\ No newline at end of file
diff --git a/rojo-test/build-tests/sync_rule_complex/default.project.json b/rojo-test/build-tests/sync_rule_complex/default.project.json
new file mode 100644
index 00000000..62764bb4
--- /dev/null
+++ b/rojo-test/build-tests/sync_rule_complex/default.project.json
@@ -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"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/rojo-test/build-tests/sync_rule_complex/src/bar.server b/rojo-test/build-tests/sync_rule_complex/src/bar.server
new file mode 100644
index 00000000..e860bd77
--- /dev/null
+++ b/rojo-test/build-tests/sync_rule_complex/src/bar.server
@@ -0,0 +1 @@
+-- Hello, from bar (a Script)!
\ No newline at end of file
diff --git a/rojo-test/build-tests/sync_rule_complex/src/baz.client b/rojo-test/build-tests/sync_rule_complex/src/baz.client
new file mode 100644
index 00000000..4326a2a4
--- /dev/null
+++ b/rojo-test/build-tests/sync_rule_complex/src/baz.client
@@ -0,0 +1 @@
+-- Hello, from baz (a LocalScript)!
\ No newline at end of file
diff --git a/rojo-test/build-tests/sync_rule_complex/src/cat.dog.rojo2 b/rojo-test/build-tests/sync_rule_complex/src/cat.dog.rojo2
new file mode 100644
index 00000000..e185da86
--- /dev/null
+++ b/rojo-test/build-tests/sync_rule_complex/src/cat.dog.rojo2
@@ -0,0 +1 @@
+Hello, from cat (a StringValue)!
\ No newline at end of file
diff --git a/rojo-test/build-tests/sync_rule_complex/src/foo.module b/rojo-test/build-tests/sync_rule_complex/src/foo.module
new file mode 100644
index 00000000..3a55f9b2
--- /dev/null
+++ b/rojo-test/build-tests/sync_rule_complex/src/foo.module
@@ -0,0 +1 @@
+-- Hello, from foo (a ModuleScript)!
\ No newline at end of file
diff --git a/rojo-test/build-tests/sync_rule_complex/src/qux.rojo b/rojo-test/build-tests/sync_rule_complex/src/qux.rojo
new file mode 100644
index 00000000..7153477d
--- /dev/null
+++ b/rojo-test/build-tests/sync_rule_complex/src/qux.rojo
@@ -0,0 +1,9 @@
+{
+ "name": "qux",
+ "tree": {
+ "$className": "StringValue",
+ "$properties": {
+ "Value": "Hello, from qux (a .rojo file that's turned into a StringValue)!"
+ }
+ }
+}
\ No newline at end of file
diff --git a/rojo-test/build-tests/sync_rule_complex/src/rat.ignore.rojo b/rojo-test/build-tests/sync_rule_complex/src/rat.ignore.rojo
new file mode 100644
index 00000000..d80a8cc8
--- /dev/null
+++ b/rojo-test/build-tests/sync_rule_complex/src/rat.ignore.rojo
@@ -0,0 +1 @@
+This file should be ignored!
\ No newline at end of file
diff --git a/rojo-test/build-tests/sync_rule_nested_projects/default.project.json b/rojo-test/build-tests/sync_rule_nested_projects/default.project.json
new file mode 100644
index 00000000..1b6193bb
--- /dev/null
+++ b/rojo-test/build-tests/sync_rule_nested_projects/default.project.json
@@ -0,0 +1,12 @@
+{
+ "name": "sync_rule_nested_projects",
+ "tree": {
+ "$path": "nested.project.json"
+ },
+ "syncRules": [
+ {
+ "pattern": "*.rojo",
+ "use": "text"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/rojo-test/build-tests/sync_rule_nested_projects/nested.project.json b/rojo-test/build-tests/sync_rule_nested_projects/nested.project.json
new file mode 100644
index 00000000..3c5fea2c
--- /dev/null
+++ b/rojo-test/build-tests/sync_rule_nested_projects/nested.project.json
@@ -0,0 +1,12 @@
+{
+ "name": "nested",
+ "tree": {
+ "$path": "src"
+ },
+ "syncRules": [
+ {
+ "pattern": "*.txt",
+ "use": "ignore"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/rojo-test/build-tests/sync_rule_nested_projects/src/ignored.rojo b/rojo-test/build-tests/sync_rule_nested_projects/src/ignored.rojo
new file mode 100644
index 00000000..d7ed8b4f
--- /dev/null
+++ b/rojo-test/build-tests/sync_rule_nested_projects/src/ignored.rojo
@@ -0,0 +1 @@
+This shouldn't be in the built file. If it is, something is wrong.
\ No newline at end of file
diff --git a/rojo-test/build-tests/sync_rule_nested_projects/src/ignored.txt b/rojo-test/build-tests/sync_rule_nested_projects/src/ignored.txt
new file mode 100644
index 00000000..d7ed8b4f
--- /dev/null
+++ b/rojo-test/build-tests/sync_rule_nested_projects/src/ignored.txt
@@ -0,0 +1 @@
+This shouldn't be in the built file. If it is, something is wrong.
\ No newline at end of file
diff --git a/rojo-test/serve-test-snapshots/end_to_end__tests__serve__sync_rule_alone_all.snap b/rojo-test/serve-test-snapshots/end_to_end__tests__serve__sync_rule_alone_all.snap
new file mode 100644
index 00000000..e4fa4adf
--- /dev/null
+++ b/rojo-test/serve-test-snapshots/end_to_end__tests__serve__sync_rule_alone_all.snap
@@ -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
+
diff --git a/rojo-test/serve-test-snapshots/end_to_end__tests__serve__sync_rule_alone_info.snap b/rojo-test/serve-test-snapshots/end_to_end__tests__serve__sync_rule_alone_info.snap
new file mode 100644
index 00000000..514b8858
--- /dev/null
+++ b/rojo-test/serve-test-snapshots/end_to_end__tests__serve__sync_rule_alone_info.snap
@@ -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
+
diff --git a/rojo-test/serve-test-snapshots/end_to_end__tests__serve__sync_rule_complex_all.snap b/rojo-test/serve-test-snapshots/end_to_end__tests__serve__sync_rule_complex_all.snap
new file mode 100644
index 00000000..80cd76f6
--- /dev/null
+++ b/rojo-test/serve-test-snapshots/end_to_end__tests__serve__sync_rule_complex_all.snap
@@ -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
+
diff --git a/rojo-test/serve-test-snapshots/end_to_end__tests__serve__sync_rule_complex_info.snap b/rojo-test/serve-test-snapshots/end_to_end__tests__serve__sync_rule_complex_info.snap
new file mode 100644
index 00000000..3ed2b805
--- /dev/null
+++ b/rojo-test/serve-test-snapshots/end_to_end__tests__serve__sync_rule_complex_info.snap
@@ -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
+
diff --git a/rojo-test/serve-test-snapshots/end_to_end__tests__serve__sync_rule_no_extension_all.snap b/rojo-test/serve-test-snapshots/end_to_end__tests__serve__sync_rule_no_extension_all.snap
new file mode 100644
index 00000000..f3210d3c
--- /dev/null
+++ b/rojo-test/serve-test-snapshots/end_to_end__tests__serve__sync_rule_no_extension_all.snap
@@ -0,0 +1,30 @@
+---
+source: tests/tests/serve.rs
+assertion_line: 303
+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_no_extension
+ Parent: "00000000000000000000000000000000"
+ Properties: {}
+ id-3:
+ Children: []
+ ClassName: ModuleScript
+ Id: id-3
+ Metadata:
+ ignoreUnknownInstances: false
+ Name: no_extension
+ Parent: id-2
+ Properties:
+ Source:
+ String: "return {\"This file has no extension but should be a ModuleScript named `no_extension`\"}"
+messageCursor: 0
+sessionId: id-1
+
diff --git a/rojo-test/serve-test-snapshots/end_to_end__tests__serve__sync_rule_no_extension_info.snap b/rojo-test/serve-test-snapshots/end_to_end__tests__serve__sync_rule_no_extension_info.snap
new file mode 100644
index 00000000..3503e595
--- /dev/null
+++ b/rojo-test/serve-test-snapshots/end_to_end__tests__serve__sync_rule_no_extension_info.snap
@@ -0,0 +1,14 @@
+---
+source: tests/tests/serve.rs
+assertion_line: 297
+expression: redactions.redacted_yaml(info)
+---
+expectedPlaceIds: ~
+gameId: ~
+placeId: ~
+projectName: sync_rule_no_extension
+protocolVersion: 4
+rootInstanceId: id-2
+serverVersion: "[server-version]"
+sessionId: id-1
+
diff --git a/rojo-test/serve-tests/sync_rule_alone/default.project.json b/rojo-test/serve-tests/sync_rule_alone/default.project.json
new file mode 100644
index 00000000..f3a5aa34
--- /dev/null
+++ b/rojo-test/serve-tests/sync_rule_alone/default.project.json
@@ -0,0 +1,12 @@
+{
+ "name": "sync_rule_alone",
+ "tree": {
+ "$path": "src"
+ },
+ "syncRules": [
+ {
+ "pattern": "*.nothing",
+ "use": "text"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/rojo-test/serve-tests/sync_rule_alone/src/foo.nothing b/rojo-test/serve-tests/sync_rule_alone/src/foo.nothing
new file mode 100644
index 00000000..5dd01c17
--- /dev/null
+++ b/rojo-test/serve-tests/sync_rule_alone/src/foo.nothing
@@ -0,0 +1 @@
+Hello, world!
\ No newline at end of file
diff --git a/rojo-test/serve-tests/sync_rule_complex/default.project.json b/rojo-test/serve-tests/sync_rule_complex/default.project.json
new file mode 100644
index 00000000..62764bb4
--- /dev/null
+++ b/rojo-test/serve-tests/sync_rule_complex/default.project.json
@@ -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"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/rojo-test/serve-tests/sync_rule_complex/src/bar.server b/rojo-test/serve-tests/sync_rule_complex/src/bar.server
new file mode 100644
index 00000000..e860bd77
--- /dev/null
+++ b/rojo-test/serve-tests/sync_rule_complex/src/bar.server
@@ -0,0 +1 @@
+-- Hello, from bar (a Script)!
\ No newline at end of file
diff --git a/rojo-test/serve-tests/sync_rule_complex/src/baz.client b/rojo-test/serve-tests/sync_rule_complex/src/baz.client
new file mode 100644
index 00000000..4326a2a4
--- /dev/null
+++ b/rojo-test/serve-tests/sync_rule_complex/src/baz.client
@@ -0,0 +1 @@
+-- Hello, from baz (a LocalScript)!
\ No newline at end of file
diff --git a/rojo-test/serve-tests/sync_rule_complex/src/cat.dog.rojo2 b/rojo-test/serve-tests/sync_rule_complex/src/cat.dog.rojo2
new file mode 100644
index 00000000..e185da86
--- /dev/null
+++ b/rojo-test/serve-tests/sync_rule_complex/src/cat.dog.rojo2
@@ -0,0 +1 @@
+Hello, from cat (a StringValue)!
\ No newline at end of file
diff --git a/rojo-test/serve-tests/sync_rule_complex/src/foo.module b/rojo-test/serve-tests/sync_rule_complex/src/foo.module
new file mode 100644
index 00000000..3a55f9b2
--- /dev/null
+++ b/rojo-test/serve-tests/sync_rule_complex/src/foo.module
@@ -0,0 +1 @@
+-- Hello, from foo (a ModuleScript)!
\ No newline at end of file
diff --git a/rojo-test/serve-tests/sync_rule_complex/src/qux.rojo b/rojo-test/serve-tests/sync_rule_complex/src/qux.rojo
new file mode 100644
index 00000000..7153477d
--- /dev/null
+++ b/rojo-test/serve-tests/sync_rule_complex/src/qux.rojo
@@ -0,0 +1,9 @@
+{
+ "name": "qux",
+ "tree": {
+ "$className": "StringValue",
+ "$properties": {
+ "Value": "Hello, from qux (a .rojo file that's turned into a StringValue)!"
+ }
+ }
+}
\ No newline at end of file
diff --git a/rojo-test/serve-tests/sync_rule_complex/src/rat.ignore.rojo b/rojo-test/serve-tests/sync_rule_complex/src/rat.ignore.rojo
new file mode 100644
index 00000000..d80a8cc8
--- /dev/null
+++ b/rojo-test/serve-tests/sync_rule_complex/src/rat.ignore.rojo
@@ -0,0 +1 @@
+This file should be ignored!
\ No newline at end of file
diff --git a/rojo-test/serve-tests/sync_rule_no_extension/default.project.json b/rojo-test/serve-tests/sync_rule_no_extension/default.project.json
new file mode 100644
index 00000000..185c6633
--- /dev/null
+++ b/rojo-test/serve-tests/sync_rule_no_extension/default.project.json
@@ -0,0 +1,12 @@
+{
+ "name": "sync_rule_no_extension",
+ "tree": {
+ "$path": "src"
+ },
+ "syncRules": [
+ {
+ "pattern": "src/**",
+ "use": "json"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/rojo-test/serve-tests/sync_rule_no_extension/src/no_extension b/rojo-test/serve-tests/sync_rule_no_extension/src/no_extension
new file mode 100644
index 00000000..41c705c4
--- /dev/null
+++ b/rojo-test/serve-tests/sync_rule_no_extension/src/no_extension
@@ -0,0 +1 @@
+["This file has no extension but should be a ModuleScript named `no_extension`"]
\ No newline at end of file
diff --git a/src/project.rs b/src/project.rs
index 93a3cb21..1095fba2 100644
--- a/src/project.rs
+++ b/src/project.rs
@@ -8,7 +8,7 @@ use std::{
use serde::{Deserialize, Serialize};
use thiserror::Error;
-use crate::{glob::Glob, resolution::UnresolvedValue};
+use crate::{glob::Glob, resolution::UnresolvedValue, snapshot::SyncRule};
static PROJECT_FILENAME: &str = "default.project.json";
@@ -84,6 +84,12 @@ pub struct Project {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub glob_ignore_paths: Vec,
+ /// A list of mappings of globs to syncing rules. If a file matches a glob,
+ /// it will be 'transformed' into an Instance following the rule provided.
+ /// Globs are relative to the folder the project file is in.
+ #[serde(default, skip_serializing_if = "Vec::is_empty")]
+ pub sync_rules: Vec,
+
/// The path to the file that this project came from. Relative paths in the
/// project should be considered relative to the parent of this field, also
/// given by `Project::folder_location`.
diff --git a/src/snapshot/metadata.rs b/src/snapshot/metadata.rs
index 1a3273ed..1578af23 100644
--- a/src/snapshot/metadata.rs
+++ b/src/snapshot/metadata.rs
@@ -4,11 +4,14 @@ use std::{
sync::Arc,
};
+use anyhow::Context;
use serde::{Deserialize, Serialize};
use crate::{
- glob::Glob, path_serializer, project::ProjectNode,
- snapshot_middleware::emit_legacy_scripts_default,
+ glob::Glob,
+ path_serializer,
+ project::ProjectNode,
+ snapshot_middleware::{emit_legacy_scripts_default, Middleware},
};
/// Rojo-specific metadata that can be associated with an instance or a snapshot
@@ -107,6 +110,8 @@ pub struct InstanceContext {
#[serde(skip_serializing_if = "Vec::is_empty")]
pub path_ignore_rules: Arc>,
pub emit_legacy_scripts: bool,
+ #[serde(skip_serializing_if = "Vec::is_empty")]
+ pub sync_rules: Vec,
}
impl InstanceContext {
@@ -114,6 +119,7 @@ impl InstanceContext {
Self {
path_ignore_rules: Arc::new(Vec::new()),
emit_legacy_scripts: emit_legacy_scripts_default().unwrap(),
+ sync_rules: Vec::new(),
}
}
@@ -144,9 +150,28 @@ impl InstanceContext {
rules.extend(new_rules);
}
+ /// Extend the list of syncing rules in the context with the given new rules.
+ pub fn add_sync_rules(&mut self, new_rules: I)
+ where
+ I: IntoIterator- ,
+ {
+ self.sync_rules.extend(new_rules);
+ }
+
+ /// Clears all sync rules for this InstanceContext
+ pub fn clear_sync_rules(&mut self) {
+ self.sync_rules.clear();
+ }
+
pub fn set_emit_legacy_scripts(&mut self, emit_legacy_scripts: bool) {
self.emit_legacy_scripts = emit_legacy_scripts;
}
+
+ /// Returns the middleware specified by the first sync rule that
+ /// matches the provided path. This does not handle default syncing rules.
+ pub fn get_user_sync_rule(&self, path: &Path) -> Option<&SyncRule> {
+ self.sync_rules.iter().find(|&rule| rule.matches(path))
+ }
}
impl Default for InstanceContext {
@@ -216,3 +241,64 @@ impl From<&Path> for InstigatingSource {
InstigatingSource::Path(path.to_path_buf())
}
}
+
+/// Represents an user-specified rule for transforming files
+/// into Instances using a given middleware.
+#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
+pub struct SyncRule {
+ /// A pattern used to determine if a file is included in this SyncRule
+ #[serde(rename = "pattern")]
+ pub include: Glob,
+ /// A pattern used to determine if a file is excluded from this SyncRule.
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub exclude: Option,
+ /// The middleware specified by the user for this SyncRule
+ #[serde(rename = "use")]
+ pub middleware: Middleware,
+ /// A suffix to trim off of file names, including the file extension.
+ /// If not specified, the file extension is the only thing cut off.
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub suffix: Option,
+ /// The 'base' of the glob above, allowing it to be used
+ /// relative to a path instead of absolute.
+ #[serde(skip)]
+ pub base_path: PathBuf,
+}
+
+impl SyncRule {
+ /// Returns whether the given path matches this rule.
+ pub fn matches(&self, path: &Path) -> bool {
+ match path.strip_prefix(&self.base_path) {
+ Ok(suffix) => {
+ if let Some(pattern) = &self.exclude {
+ if pattern.is_match(suffix) {
+ return false;
+ }
+ }
+ self.include.is_match(suffix)
+ }
+ Err(_) => false,
+ }
+ }
+
+ pub fn file_name_for_path<'a>(&self, path: &'a Path) -> anyhow::Result<&'a str> {
+ if let Some(suffix) = &self.suffix {
+ let file_name = path
+ .file_name()
+ .and_then(|s| s.to_str())
+ .with_context(|| format!("file name of {} is invalid", path.display()))?;
+ if file_name.ends_with(suffix) {
+ let end = file_name.len().saturating_sub(suffix.len());
+ Ok(&file_name[..end])
+ } else {
+ Ok(file_name)
+ }
+ } else {
+ // If the user doesn't specify a suffix, we assume they just want
+ // the name of the file (the file_stem)
+ path.file_stem()
+ .and_then(|s| s.to_str())
+ .with_context(|| format!("file name of {} is invalid", path.display()))
+ }
+ }
+}
diff --git a/src/snapshot_middleware/csv.rs b/src/snapshot_middleware/csv.rs
index 708f1bb8..52e8ab0f 100644
--- a/src/snapshot_middleware/csv.rs
+++ b/src/snapshot_middleware/csv.rs
@@ -10,16 +10,14 @@ use crate::snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot};
use super::{
dir::{dir_meta, snapshot_dir_no_meta},
meta_file::AdjacentMetadata,
- util::PathExt,
};
pub fn snapshot_csv(
_context: &InstanceContext,
vfs: &Vfs,
path: &Path,
+ name: &str,
) -> anyhow::Result