Automatic formatting pass
This commit is contained in:
parent
afb9ceccab
commit
b7c0761822
7 changed files with 131 additions and 131 deletions
|
@ -1,12 +1,12 @@
|
|||
import CheapWatch from "cheap-watch";
|
||||
import {config} from "./config.js";
|
||||
import {EventType} from "./eventTypes.js";
|
||||
import {resolve } from "path";
|
||||
import { config } from "./config.js";
|
||||
import { EventType } from "./eventTypes.js";
|
||||
import { resolve } from "path";
|
||||
|
||||
function fileFilter(file) {
|
||||
if(config.get("allowedFiletypes").some(extension => file.path.endsWith(extension)))
|
||||
if (config.get("allowedFiletypes").some(extension => file.path.endsWith(extension)))
|
||||
return true;
|
||||
if(file.stats.isDirectory())
|
||||
if (file.stats.isDirectory())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
@ -19,15 +19,15 @@ const watch = new CheapWatch({
|
|||
|
||||
export async function setupWatch(signaller) {
|
||||
|
||||
if(!config.get("quiet")) console.log("Watching folder", resolve(config.get("scriptsFolder")))
|
||||
if (!config.get("quiet")) console.log("Watching folder", resolve(config.get("scriptsFolder")))
|
||||
|
||||
watch.on('+', fileEvent => {if (fileEvent.stats.isFile()) signaller.emit(EventType.FileChanged, fileEvent)});
|
||||
watch.on('-', fileEvent => {if (fileEvent.stats.isFile()) signaller.emit(EventType.FileDeleted, fileEvent)});
|
||||
watch.on('+', fileEvent => { if (fileEvent.stats.isFile()) signaller.emit(EventType.FileChanged, fileEvent) });
|
||||
watch.on('-', fileEvent => { if (fileEvent.stats.isFile()) signaller.emit(EventType.FileDeleted, fileEvent) });
|
||||
|
||||
// Wait 'till filewatcher is ready to go
|
||||
await watch.init();
|
||||
|
||||
if(config.get("dry")) {
|
||||
if (config.get("dry")) {
|
||||
console.log("Watch would've synchronised:\n", watch.paths)
|
||||
process.exit();
|
||||
}
|
||||
|
|
|
@ -1,48 +1,48 @@
|
|||
import {readFileSync} from "fs";
|
||||
import {config} from "../config.js";
|
||||
import {join} from "path";
|
||||
import { readFileSync } from "fs";
|
||||
import { config } from "../config.js";
|
||||
import { join } from "path";
|
||||
|
||||
let messageCounter = 0;
|
||||
|
||||
export function fileChangeEventToMsg({path}){
|
||||
export function fileChangeEventToMsg({ path }) {
|
||||
return {
|
||||
"jsonrpc":"2.0",
|
||||
"method":"pushFile",
|
||||
"params":{
|
||||
"server":"home",
|
||||
"filename":"/"+path,
|
||||
"content":readFileSync(join(config.get("scriptsFolder"), path)).toString()
|
||||
"jsonrpc": "2.0",
|
||||
"method": "pushFile",
|
||||
"params": {
|
||||
"server": "home",
|
||||
"filename": "/" + path,
|
||||
"content": readFileSync(join(config.get("scriptsFolder"), path)).toString()
|
||||
},
|
||||
"id":messageCounter++
|
||||
"id": messageCounter++
|
||||
}
|
||||
}
|
||||
|
||||
export function fileRemovalEventToMsg({path}){
|
||||
export function fileRemovalEventToMsg({ path }) {
|
||||
return {
|
||||
"jsonrpc":"2.0",
|
||||
"jsonrpc": "2.0",
|
||||
"method": "deleteFile",
|
||||
"params":{
|
||||
"params": {
|
||||
"filename": path,
|
||||
},
|
||||
"id":messageCounter++
|
||||
"id": messageCounter++
|
||||
}
|
||||
}
|
||||
|
||||
export function requestDefinitionFile(){
|
||||
export function requestDefinitionFile() {
|
||||
return {
|
||||
"jsonrpc": "2.0",
|
||||
"method": "getDefinitionFile",
|
||||
"id":messageCounter++
|
||||
"id": messageCounter++
|
||||
}
|
||||
}
|
||||
|
||||
export function requestFilenames(){
|
||||
export function requestFilenames() {
|
||||
return {
|
||||
"jsonrpc": "2.0",
|
||||
"method": "getFileNames",
|
||||
"params": {
|
||||
"server": "home",
|
||||
},
|
||||
"id":messageCounter++
|
||||
"id": messageCounter++
|
||||
}
|
||||
}
|
|
@ -8,8 +8,8 @@ import { fileChangeEventToMsg } from "./messageGenerators.js";
|
|||
export function messageHandler(signaller, msg) {
|
||||
let incoming;
|
||||
|
||||
try {incoming = JSON.parse(msg.toString());}
|
||||
catch (err) {return console.log(err);}
|
||||
try { incoming = JSON.parse(msg.toString()); }
|
||||
catch (err) { return console.log(err); }
|
||||
console.log(incoming)
|
||||
if (incoming.id == undefined) return;
|
||||
|
||||
|
@ -29,14 +29,14 @@ export function messageHandler(signaller, msg) {
|
|||
const gameFiles = incoming.result.map(file => removeLeadingSlash(file));
|
||||
|
||||
watchedFiles().forEach((stats, fileName) => {
|
||||
if(!stats.isDirectory() && !gameFiles.includes(fileName))
|
||||
signaller.emit(EventType.MessageSend, fileChangeEventToMsg({path:fileName}));
|
||||
if (!stats.isDirectory() && !gameFiles.includes(fileName))
|
||||
signaller.emit(EventType.MessageSend, fileChangeEventToMsg({ path: fileName }));
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function removeLeadingSlash(path){
|
||||
function removeLeadingSlash(path) {
|
||||
const reg = /^\//;
|
||||
return path.replace(reg, "")
|
||||
}
|
|
@ -5,7 +5,7 @@ class MessageTracker {
|
|||
push(msg) {
|
||||
this.data.set(msg.id, msg);
|
||||
|
||||
if (this.data.size > this.#maxLength){
|
||||
if (this.data.size > this.#maxLength) {
|
||||
const [firstKey] = map.keys();
|
||||
this.data.delete(firstKey);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { WebSocketServer } from 'ws';
|
||||
import {config} from "../config.js";
|
||||
import {EventType} from "../eventTypes.js"
|
||||
import { config } from "../config.js";
|
||||
import { EventType } from "../eventTypes.js"
|
||||
import { requestDefinitionFile } from './messageGenerators.js';
|
||||
import {messageTracker} from "./messageTracker.js"
|
||||
import { messageTracker } from "./messageTracker.js"
|
||||
|
||||
export function setupSocket(signaller){
|
||||
export function setupSocket(signaller) {
|
||||
|
||||
const wss = new WebSocketServer({ port: config.get("port") });
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue