Tighten init file handling, fixes some buggy edge cases by not supporting them

This commit is contained in:
Lucien Greathouse
2017-12-03 19:02:58 -08:00
parent 16676ebfa1
commit 34d5de9f2c
4 changed files with 34 additions and 6 deletions

View File

@@ -1,7 +1,8 @@
# Rojo Change Log # Rojo Change Log
## Current Master ## Current Master
* *No changes* * Tightened `init` file rules to only match script files
* Previously, Rojo would sometimes pick up the wrong file when syncing
## 0.2.2 ## 0.2.2
* Plugin only release * Plugin only release

View File

@@ -110,17 +110,17 @@ Creation of Roblox instances follows a simple set of rules. The first rule that
| `*.lua` | `ModuleScript` | `Source` will contain the file's contents | | `*.lua` | `ModuleScript` | `Source` will contain the file's contents |
| `*` | `StringValue` | `Value` will contain the file's contents | | `*` | `StringValue` | `Value` will contain the file's contents |
Any folders on the filesystem will turn into `Folder` objects unless they contain a file named `init` with any extension. Following the convention of Lua, those objects will instead be whatever the `init` file would turn into. Any folders on the filesystem will turn into `Folder` objects unless they contain a file named `init.lua`, `init.server.lua`, or `init.client.lua`. Following the convention of Lua, those objects will instead be whatever the `init` file would turn into.
For example, this file tree: For example, this file tree:
* my-game * my-game
* init.lua * init.client.lua
* foo.lua * foo.lua
Will turn into this tree in Roblox: Will turn into this tree in Roblox:
* `my-game` (`ModuleScript` with source from `my-game/init.lua`) * `my-game` (`LocalScript` with source from `my-game/init.client.lua`)
* `foo` (`ModuleScript` with source from `my-game/foo.lua`) * `foo` (`ModuleScript` with source from `my-game/foo.lua`)
## Inspiration ## Inspiration

View File

@@ -1,4 +1,4 @@
return { return {
pollingRate = 0.3, pollingRate = 0.3,
version = "0.2.2", version = "DEV",
} }

View File

@@ -1,13 +1,27 @@
local Reconciler = {} local Reconciler = {}
--[[
The set of file names that should pass as init files
These files usurp their parents.
]]
local initNames = {
["init.lua"] = true,
["init.server.lua"] = true,
["init.client.lua"] = true,
}
local function isInit(item, itemFileName) local function isInit(item, itemFileName)
if item and item.type == "dir" then if item and item.type == "dir" then
return return
end end
return not not itemFileName:find("^init%.") return initNames[itemFileName] or false
end end
--[[
Determines if the given VFS item has an init file. Yields information about
the file.
]]
local function findInit(item) local function findInit(item)
if item.type ~= "dir" then if item.type ~= "dir" then
return nil, nil return nil, nil
@@ -22,6 +36,12 @@ local function findInit(item)
return nil, nil return nil, nil
end end
--[[
Given a VFS item, returns a Name and ClassName for a corresponding Roblox
instance.
Doesn't take into account init files.
]]
local function itemToName(item, fileName) local function itemToName(item, fileName)
if item and item.type == "dir" then if item and item.type == "dir" then
return fileName, "Folder" return fileName, "Folder"
@@ -40,6 +60,10 @@ local function itemToName(item, fileName)
end end
end end
--[[
Given a VFS item, assigns all relevant values (except Name!) to a Roblox
instance.
]]
local function setValues(rbx, item, fileName) local function setValues(rbx, item, fileName)
local _, className = itemToName(item, fileName) local _, className = itemToName(item, fileName)
@@ -79,6 +103,9 @@ function Reconciler._reifyShallow(item, fileName)
end end
end end
--[[
Construct a new Roblox instance tree that corresponds to the given VFS item.
]]
function Reconciler._reify(item, fileName, parent) function Reconciler._reify(item, fileName, parent)
local rbx = Reconciler._reifyShallow(item, fileName) local rbx = Reconciler._reifyShallow(item, fileName)