Compare commits

..

11 Commits

Author SHA1 Message Date
Lucien Greathouse
a86001b85c Release 0.4.10 2018-06-01 23:51:35 -07:00
Lucien Greathouse
d6dd46c467 Fix JsonModelPlugin marking paths as changed correctly 2018-06-01 23:38:49 -07:00
Lucien Greathouse
320974074c Update docs 2018-06-01 23:33:36 -07:00
Lucien Greathouse
7b824abe52 Update CHANGES 2018-06-01 23:30:59 -07:00
Lucien Greathouse
bfd33f4b8d Support init.model.json
Closes #66.
2018-06-01 23:29:39 -07:00
Lucien Greathouse
d5a21a0513 Update plugin .luacheckrc to be more strict 2018-06-01 23:11:58 -07:00
Lucien Greathouse
c894b38f06 Improve plugin API robustness 2018-06-01 23:11:50 -07:00
Lucien Greathouse
a86347ea32 Add typechecks to reconciler and improve robustness a touch 2018-06-01 22:34:11 -07:00
Lucien Greathouse
b60bfc7495 Make nil checks more robust.
This represents an evolution in how I've been thinking about Lua -- using boolean coercion
is generally a bad idea I think because it obscures the underlying types.

It also makes it so that if a boolean is eronneously passed into a function, and it
happens to be a 'false' value, it will be coerced into the nil case instead of being
reported as an error, no matter how unintuitive the resulting error might be.
2018-06-01 22:21:59 -07:00
Lucien Greathouse
4b2f27b26d Fix error when targeting invalid services 2018-06-01 22:17:54 -07:00
Lucien Greathouse
f4d7dda8e3 Make docs on JSON model versioning more explicit 2018-05-26 17:19:37 -07:00
11 changed files with 139 additions and 56 deletions

View File

@@ -1,7 +1,9 @@
# Rojo Change Log
## Current master
* *No changes*
* Added support for `init.model.json` files, which enable versioning `Tool` instances (among other things) with Rojo. ([#66](https://github.com/LPGhatguy/rojo/issues/66))
* Fixed obscure error when syncing into an invalid service.
* Fixed multiple sync processes occurring when a server ID mismatch is detected.
## 0.4.9 (May 26, 2018)
* Fixed warning when renaming or removing files that would sometimes corrupt the instance cache ([#72](https://github.com/LPGhatguy/rojo/pull/72))

View File

@@ -30,9 +30,14 @@ Rojo supports a JSON model format for representing simple models. It's designed
Rojo JSON models are stored in `.model.json` files.
Starting in Rojo version **0.4.10**, model files named `init.model.json` that are located in folders will replace that folder, much like Rojo's `init.lua` support. This can be useful to version instances like `Tool` that tend to contain several instances as well as one or more scripts.
!!! info
In the future, Rojo will support `.rbxmx` models. See [issue #7](https://github.com/LPGhatguy/rojo/issues/7) for more details and updates on this feature.
!!! warning
Prior to Rojo version **0.4.9**, the `Properties` and `Children` properties are required on all instances in JSON models!
JSON model files are fairly strict; any syntax errors will cause the model to fail to sync! They look like this:
`hello.model.json`

View File

@@ -39,10 +39,6 @@ stds.testez = {
ignore = {
"212", -- unused arguments
"421", -- shadowing local variable
"422", -- shadowing argument
"431", -- shadowing upvalue
"432", -- shadowing upvalue argument
}
std = "lua51+roblox"

View File

@@ -35,6 +35,9 @@ function Api.connect(http)
setmetatable(context, Api)
return context:_start()
:andThen(function()
return context
end)
end
function Api:_start()
@@ -60,8 +63,6 @@ function Api:_start()
self.serverId = response.serverId
self.currentTime = response.currentTime
return self
end)
end

View File

@@ -8,6 +8,9 @@ local Api = require(script.Parent.Api)
local Reconciler = require(script.Parent.Reconciler)
local Version = require(script.Parent.Version)
local MESSAGE_SERVER_CHANGED = "Rojo: The server has changed since the last request, reloading plugin..."
local MESSAGE_PLUGIN_CHANGED = "Rojo: Another instance of Rojo came online, unloading..."
local function collectMatch(source, pattern)
local result = {}
@@ -80,6 +83,7 @@ function Plugin.new()
-- object.
screenGui.AncestryChanged:Connect(function(_, parent)
if parent == nil then
warn(MESSAGE_PLUGIN_CHANGED)
self:restart()
end
end)
@@ -93,8 +97,6 @@ end
restarted.
]]
function Plugin:restart()
warn("Rojo: The server has changed since the last request, reloading plugin...")
self:stopPolling()
self._reconciler:destruct()
@@ -105,22 +107,25 @@ function Plugin:restart()
self._syncInProgress = false
end
function Plugin:api()
if not self._api then
self._api = Api.connect(self._http)
:catch(function(err)
self._api = nil
function Plugin:getApi()
if self._api == nil then
return Api.connect(self._http)
:andThen(function(api)
self._api = api
return api
end, function(err)
return Promise.reject(err)
end)
end
return self._api
return Promise.resolve(self._api)
end
function Plugin:connect()
print("Rojo: Testing connection...")
return self:api()
return self:getApi()
:andThen(function(api)
local ok, info = api:getInfo():await()
@@ -134,6 +139,7 @@ function Plugin:connect()
end)
:catch(function(err)
if err == Api.Error.ServerIdMismatch then
warn(MESSAGE_SERVER_CHANGED)
self:restart()
return self:connect()
else
@@ -204,25 +210,25 @@ function Plugin:startPolling()
return
end
print("Rojo: Polling server for changes...")
print("Rojo: Starting to poll server for changes...")
self._polling = true
self._label.Enabled = true
return self:api()
return self:getApi()
:andThen(function(api)
local syncOk, result = self:syncIn():await()
if not syncOk then
return Promise.reject(result)
end
local infoOk, info = api:getInfo():await()
if not infoOk then
return Promise.reject(info)
end
local syncOk, result = self:syncIn():await()
if not syncOk then
return Promise.reject(result)
end
while self._polling do
local changesOk, changes = api:getChanges():await()
@@ -248,12 +254,12 @@ function Plugin:startPolling()
end
end)
:catch(function(err)
self:stopPolling()
if err == Api.Error.ServerIdMismatch then
warn(MESSAGE_SERVER_CHANGED)
self:restart()
return self:startPolling()
else
self:stopPolling()
return Promise.reject(err)
end
end)
@@ -269,7 +275,7 @@ function Plugin:syncIn()
self._syncInProgress = true
print("Rojo: Syncing from server...")
return self:api()
return self:getApi()
:andThen(function(api)
local ok, info = api:getInfo():await()
@@ -292,6 +298,7 @@ function Plugin:syncIn()
self._syncInProgress = false
if err == Api.Error.ServerIdMismatch then
warn(MESSAGE_SERVER_CHANGED)
self:restart()
return self:syncIn()
else

View File

@@ -1,6 +1,9 @@
local RouteMap = require(script.Parent.RouteMap)
local function classEqual(a, b)
assert(typeof(a) == "string")
assert(typeof(b) == "string")
if a == "*" or b == "*" then
return true
end
@@ -9,6 +12,9 @@ local function classEqual(a, b)
end
local function applyProperties(target, properties)
assert(typeof(target) == "Instance")
assert(typeof(properties) == "table")
for key, property in pairs(properties) do
-- TODO: Transform property value based on property.Type
-- Right now, we assume that 'value' is primitive!
@@ -22,18 +28,19 @@ end
* Changing parent threw an error
]]
local function reparent(rbx, parent)
if rbx then
if rbx.Parent == parent then
return
end
assert(typeof(rbx) == "Instance")
assert(typeof(parent) == "Instance")
-- It's possible that 'rbx' is a service or some other object that we
-- can't change the parent of. That's the only reason why Parent would
-- fail except for rbx being previously destroyed!
pcall(function()
rbx.Parent = parent
end)
if rbx.Parent == parent then
return
end
-- Setting `Parent` can fail if:
-- * The object has been destroyed
-- * The object is a service and cannot be reparented
pcall(function()
rbx.Parent = parent
end)
end
--[[
@@ -94,22 +101,30 @@ function Reconciler:_reconcileChildren(rbx, item)
while true do
local itemChild, rbxChild = findNextChildPair(item.Children, rbxChildren, visited)
if not itemChild then
if itemChild == nil then
break
end
reparent(self:reconcile(rbxChild, itemChild), rbx)
local newRbxChild = self:reconcile(rbxChild, itemChild)
if newRbxChild ~= nil then
newRbxChild.Parent = rbx
end
end
-- Reconcile any children that were deleted
while true do
local rbxChild, itemChild = findNextChildPair(rbxChildren, item.Children, visited)
if not rbxChild then
if rbxChild == nil then
break
end
reparent(self:reconcile(rbxChild, itemChild), rbx)
local newRbxChild = self:reconcile(rbxChild, itemChild)
if newRbxChild ~= nil then
newRbxChild.Parent = rbx
end
end
end
@@ -133,7 +148,7 @@ function Reconciler:_reify(item)
reparent(self:_reify(child), rbx)
end
if item.Route then
if item.Route ~= nil then
self._routeMap:insert(item.Route, rbx)
end
@@ -153,8 +168,8 @@ end
]]
function Reconciler:reconcile(rbx, item)
-- Item was deleted
if not item then
if rbx then
if item == nil then
if rbx ~= nil then
self._routeMap:removeByRbx(rbx)
rbx:Destroy()
end
@@ -163,7 +178,7 @@ function Reconciler:reconcile(rbx, item)
end
-- Item was created!
if not rbx then
if rbx == nil then
return self:_reify(item)
end
@@ -191,13 +206,18 @@ function Reconciler:reconcileRoute(route, item, itemRoute)
local child = rbx:FindFirstChild(piece)
-- We should get services instead of making folders here.
if rbx == game and not child then
local _
_, child = pcall(game.GetService, game, piece)
if rbx == game and child == nil then
local success
success, child = pcall(game.GetService, game, piece)
-- That isn't a valid service!
if not success then
child = nil
end
end
-- We don't want to create a folder if we're reaching our target item!
if not child and i ~= #route then
if child == nil and i ~= #route then
child = Instance.new("Folder")
child.Parent = rbx
child.Name = piece
@@ -208,7 +228,7 @@ function Reconciler:reconcileRoute(route, item, itemRoute)
end
-- Let's check the route map!
if not rbx then
if rbx == nil then
rbx = self._routeMap:get(itemRoute)
end

2
server/Cargo.lock generated
View File

@@ -636,7 +636,7 @@ dependencies = [
[[package]]
name = "rojo"
version = "0.4.9"
version = "0.4.10"
dependencies = [
"clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@@ -1,6 +1,6 @@
[package]
name = "rojo"
version = "0.4.9"
version = "0.4.10"
authors = ["Lucien Greathouse <me@lpghatguy.com>"]
description = "A tool to create robust Roblox projects"
license = "MIT"

View File

@@ -10,6 +10,8 @@ lazy_static! {
static ref JSON_MODEL_PATTERN: Regex = Regex::new(r"^(.*?)\.model\.json$").unwrap();
}
static JSON_MODEL_INIT: &'static str = "init.model.json";
pub struct JsonModelPlugin;
impl JsonModelPlugin {
@@ -19,7 +21,7 @@ impl JsonModelPlugin {
}
impl Plugin for JsonModelPlugin {
fn transform_file(&self, _plugins: &PluginChain, vfs_item: &VfsItem) -> TransformFileResult {
fn transform_file(&self, plugins: &PluginChain, vfs_item: &VfsItem) -> TransformFileResult {
match vfs_item {
&VfsItem::File { ref contents, .. } => {
let rbx_name = match JSON_MODEL_PATTERN.captures(vfs_item.name()) {
@@ -41,11 +43,56 @@ impl Plugin for JsonModelPlugin {
TransformFileResult::Value(Some(rbx_item))
},
&VfsItem::Dir { .. } => TransformFileResult::Pass,
&VfsItem::Dir { ref children, .. } => {
let init_item = match children.get(JSON_MODEL_INIT) {
Some(v) => v,
None => return TransformFileResult::Pass,
};
let mut rbx_item = match self.transform_file(plugins, init_item) {
TransformFileResult::Value(Some(item)) => item,
TransformFileResult::Value(None) | TransformFileResult::Pass => {
eprintln!("Inconsistency detected in JsonModelPlugin!");
return TransformFileResult::Pass;
},
};
rbx_item.name.clear();
rbx_item.name.push_str(vfs_item.name());
for (child_name, child_item) in children {
if child_name == init_item.name() {
continue;
}
match plugins.transform_file(child_item) {
Some(child_rbx_item) => {
rbx_item.children.push(child_rbx_item);
},
_ => {},
}
}
TransformFileResult::Value(Some(rbx_item))
},
}
}
fn handle_file_change(&self, _route: &Route) -> FileChangeResult {
FileChangeResult::Pass
fn handle_file_change(&self, route: &Route) -> FileChangeResult {
let leaf = match route.last() {
Some(v) => v,
None => return FileChangeResult::Pass,
};
let is_init = leaf == JSON_MODEL_INIT;
if is_init {
let mut changed = route.clone();
changed.pop();
FileChangeResult::MarkChanged(Some(vec![changed]))
} else {
FileChangeResult::Pass
}
}
}

View File

@@ -0,0 +1 @@
print("Hello, world, from my tool!")

View File

@@ -0,0 +1,4 @@
{
"Name": "SomeTool",
"ClassName": "Tool"
}