Skip to content

Commit

Permalink
fix: CI failure
Browse files Browse the repository at this point in the history
  • Loading branch information
solvedDev committed Sep 29, 2022
1 parent d5b2da0 commit b7a98b9
Showing 1 changed file with 48 additions and 43 deletions.
91 changes: 48 additions & 43 deletions src/CLIWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ export class CLIWatcher {
const wsServer = new WebSocketServer()
if (reloadPort) {
wsServer.start(reloadPort)
console.log(`Auto Reloader: WebSocket is running on port ${reloadPort}.`)
console.log(`Auto Reloader: Connect in Minecraft by running "/connect localhost:${reloadPort}".`)
console.log(
`Auto Reloader: WebSocket is running on port ${reloadPort}.`
)
console.log(
`Auto Reloader: Connect in Minecraft by running "/connect localhost:${reloadPort}".`
)
}

for await (const event of watcher) {
Expand Down Expand Up @@ -55,52 +59,53 @@ export class CLIWatcher {
)
}

updateChangedFiles = debounce(
async (wss?: WebSocketServer) => {
for (const file of this.filesToUpdate) {
let stats
try {
stats = Deno.statSync(
path.join(this.dash.projectRoot, file)
)
} catch {
this.filesToUpdate.delete(file)
this.filesToUnlink.add(file)
return
}

if (!stats.isFile) this.filesToUpdate.delete(file)
updateChangedFiles = debounce(async (wss?: WebSocketServer) => {
for (const file of this.filesToUpdate) {
let stats
try {
stats = Deno.statSync(path.join(this.dash.projectRoot, file))
} catch {
this.filesToUpdate.delete(file)
this.filesToUnlink.add(file)
return
}

if (this.filesToUpdate.size > 0) {
await this.dash.updateFiles([...this.filesToUpdate])
}
if (!stats.isFile) this.filesToUpdate.delete(file)
}

if (this.filesToUpdate.size > 0) {
await this.dash.updateFiles([...this.filesToUpdate])
}

if (this.filesToUnlink.size > 0) {
console.log(
'Dash: Unlinking',
[...this.filesToUnlink].join(', ')
if (this.filesToUnlink.size > 0) {
console.log('Dash: Unlinking', [...this.filesToUnlink].join(', '))
await this.dash.unlinkMultiple([...this.filesToUnlink])
}
if (wss && wss.isStarted) {
const isScriptOrFunction = (p: string) =>
path.extname(p) === '.mcfunction' ||
path.extname(p) === '.js' ||
path.extname(p) === '.ts'
if (
[...this.filesToUpdate, ...this.filesToUnlink].some((file) =>
isScriptOrFunction(file)
)
await this.dash.unlinkMultiple([...this.filesToUnlink])
}
if (wss && wss.isStarted) {
const isScriptOrFunction = (p: string) => path.extname(p) === '.mcfunction' || path.extname(p) === '.js' || path.extname(p) === '.ts'
if ([...this.filesToUpdate, ...this.filesToUnlink].some(file => isScriptOrFunction(file))) {
const { status, message } = await wss.runCommand('reload') ?? {}
if (status === 0) {
wss.runCommand('tellraw @s {"rawtext":[{"text":"Dash Auto Reloader has reloaded functions and scripts"}]}')
} else {
wss.runCommand(`tellraw @s {"rawtext":[{"text":"Dash Auto Reloader failed to reload functions and scripts. \nError message: ${message}"}]}`)
}
) {
const { status, message } =
(await wss.runCommand('reload')) ?? {}
if (status === 0) {
wss.runCommand(
'tellraw @s {"rawtext":[{"text":"Dash Auto Reloader has reloaded functions and scripts"}]}'
)
} else {
wss.runCommand(
`tellraw @s {"rawtext":[{"text":"Dash Auto Reloader failed to reload functions and scripts. \nError message: ${message}"}]}`
)
}
}

this.filesToUpdate.clear()
this.filesToUnlink.clear()
},
200,
{
trailing: true,
}
)

this.filesToUpdate.clear()
this.filesToUnlink.clear()
}, 200)
}

0 comments on commit b7a98b9

Please sign in to comment.