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