Skip to content

Commit

Permalink
Live sync fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hoontee committed Mar 27, 2024
1 parent 113399f commit fc48e36
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 32 deletions.
Binary file modified Lync/Plugin.rbxm
Binary file not shown.
73 changes: 41 additions & 32 deletions Lync/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,24 +609,26 @@ async function mapDirectory(localPath, robloxPath, flag) {
}, localPathStats.mtimeMs)
}

fs.readdirSync(localPath).forEach(async function(dirNext) {
const dirNextLower = dirNext.toLowerCase()
const localPathParentNameLower = localPathParentName.toLowerCase()
// Do not map Init files. They were just mapped on this run of mapDirectory.
switch (dirNextLower) {
case 'init.meta.json':
case 'init.meta.yaml':
case 'init.meta.toml':
case localPathParentNameLower + '.init.lua':
case localPathParentNameLower + '.init.luau':
case 'init.lua':
case 'init.luau':
break
default:
const filePathNext = localPath + '/' + dirNext
await mapDirectory(filePathNext, robloxPath + '/' + dirNext)
}
})
if (flag != 'Modified') {
fs.readdirSync(localPath).forEach(async function(dirNext) {
const dirNextLower = dirNext.toLowerCase()
const localPathParentNameLower = localPathParentName.toLowerCase()
// Do not map Init files. They were just mapped on this run of mapDirectory.
switch (dirNextLower) {
case 'init.meta.json':
case 'init.meta.yaml':
case 'init.meta.toml':
case localPathParentNameLower + '.init.lua':
case localPathParentNameLower + '.init.luau':
case 'init.lua':
case 'init.luau':
break
default:
const filePathNext = localPath + '/' + dirNext
await mapDirectory(filePathNext, robloxPath + '/' + dirNext)
}
})
}
}
}
}
Expand Down Expand Up @@ -1146,39 +1148,46 @@ function runJobs(event, localPath) {
console.log('D', cyan(localPath))
for (const key in map.tree) {

// Direct
if (map.tree[key].Path && (map.tree[key].Path == localPath || map.tree[key].Path.startsWith(localPath + '/'))) {
// Direct, non-Init
if (map.tree[key].Path == localPath && map.tree[key].InitParent != parentPathString) {
delete mTimes[localPath]
delete mTimes[map.tree[key].Path]
delete map.tree[key]
modified[key] = false
modified_playtest[key] = false
modified_sourcemap[key] = false
if (localPathIsInit(localPath) && fs.existsSync(parentPathString)) {
await mapDirectory(parentPathString, key, 'Modified')
}

// Init
if (key in map.tree && map.tree[key].InitParent == parentPathString && localPathIsInit(localPath)) {
if (fs.existsSync(parentPathString)) {
delete mTimes[localPath]
delete map.tree[key]
await mapDirectory(parentPathString, key)
}
}

// Meta
if (key in map.tree && map.tree[key].Meta && (map.tree[key].Meta == localPath || map.tree[key].Meta.startsWith(localPath + '/'))) {
if (fs.existsSync(map.tree[key].Path)) {
delete mTimes[localPath]
await mapDirectory(map.tree[key].Path, key, 'Modified')
}
}

// JSON member
if (key in map.tree && map.tree[key].ProjectJson == localPath) {
if (fs.existsSync(map.tree[key].Path)) {
await mapDirectory(map.tree[key].Path, key, 'Modified')
}
}
}

// Changed
} else if (localPathStats.isFile() && mTimes[localPath] != localPathStats.mtimeMs) {
console.log('M', cyan(localPath))
for (const key in map.tree) {
if (map.tree[key].InitParent == parentPathString) {
if (localPathIsInit(localPath) && map.tree[key].InitParent == parentPathString) {
await mapDirectory(parentPathString, key, 'Modified')
} else if (map.tree[key].Meta == localPath) {
await mapDirectory(map.tree[key].Path, key, 'Modified')
Expand All @@ -1188,9 +1197,9 @@ function runJobs(event, localPath) {
}
mTimes[localPath] = localPathStats.mtimeMs
}

} else if ((event == 'add' | event == 'addDir') && localPathStats) {

// Added
if (parentPathString in mTimes && (!localPathStats.isFile() || localPathExtensionIsMappable(localPath))) {
console.log('A', cyan(localPath))
Expand All @@ -1199,7 +1208,7 @@ function runJobs(event, localPath) {
const localPathParsed = path.parse(localPath)
const localPathName = localPathParsed.name.toLowerCase()
const localPathExt = localPathParsed.ext.toLowerCase()

// Remap adjacent matching file
if (localPathName != 'init.meta' && localPathName.endsWith('.meta') && (localPathExt == '.json' || localPathExt == '.yaml' || localPathExt == '.toml')) {
const title = localPathParsed.name.slice(0, -5)
Expand All @@ -1213,12 +1222,12 @@ function runJobs(event, localPath) {
console.error(fileError(localPath), yellow('Stray meta file'))
return
}

// Remap parent folder
} else if (localPathIsInit(localPath) || localPathName == 'init.meta' && (localPathExt == '.json' || localPathExt == '.yaml' || localPathExt == '.toml') || localPathParsed.base == 'default.project.json') {
delete map.tree[key]
await mapDirectory(parentPathString, key)

// Map only file or directory
} else {
await mapDirectory(localPath, key + '/' + localPathParsed.base)
Expand All @@ -1228,7 +1237,7 @@ function runJobs(event, localPath) {
if (!mTimes[localPath]) console.error(red('Lync bug:'), yellow('Failed to add'), cyan(localPath))
}
}

// Modify sourcemap
if (CONFIG.GenerateSourcemap && Object.keys(modified_sourcemap).length > 0) {
generateSourcemap(PROJECT_JSON, modified_sourcemap, projectJson)
Expand Down

0 comments on commit fc48e36

Please sign in to comment.