Compare commits
18 commits
manual-pus
...
main
Author | SHA1 | Date | |
---|---|---|---|
![]() |
019c45580f | ||
![]() |
cc97684069 | ||
![]() |
ee7231af9c | ||
![]() |
fbab8a375f | ||
![]() |
544344bbb4 | ||
![]() |
b9467d6a57 | ||
![]() |
1567a7c650 | ||
![]() |
5cb38deb40 | ||
![]() |
043a2d34b1 | ||
![]() |
2b40438341 | ||
![]() |
fd3392fb23 | ||
![]() |
daf7854cd0 | ||
![]() |
5bebc2832a | ||
![]() |
2f1807812d | ||
![]() |
7ff71ffbd9 | ||
![]() |
352c083e83 | ||
![]() |
3901af1c18 | ||
![]() |
e5763314ff |
15 changed files with 2155 additions and 63 deletions
2
.eslintignore
Normal file
2
.eslintignore
Normal file
|
@ -0,0 +1,2 @@
|
|||
node_modules/
|
||||
dist/
|
10
.eslintrc
Normal file
10
.eslintrc
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"plugins": ["@typescript-eslint"],
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended"
|
||||
]
|
||||
}
|
26
.gitattributes
vendored
Normal file
26
.gitattributes
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
# js / ts files
|
||||
*.js text
|
||||
*.ts text
|
||||
|
||||
# Config text files
|
||||
*.jsonc text
|
||||
*.json text
|
||||
*.yml text
|
||||
.eslintrc text
|
||||
.eslintignore text
|
||||
.gitignore text
|
||||
.gitattributes text
|
||||
.prettierignore text
|
||||
.prettierrc text
|
||||
|
||||
# Standard text files
|
||||
*.txt text
|
||||
*.md text
|
||||
*.sh text eol=lf
|
||||
*.bat text eol=crlf
|
||||
LICENSE text
|
||||
|
||||
# Binary files
|
||||
*.gif binary
|
||||
*.jpg binary
|
||||
*.png binary
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env -S node --experimental-specifier-resolution=node
|
||||
import { start } from "../src/index";
|
||||
#!/usr/bin/env -S node
|
||||
import { start } from "../src/index.js";
|
||||
|
||||
await start();
|
||||
|
|
2073
package-lock.json
generated
2073
package-lock.json
generated
File diff suppressed because it is too large
Load diff
15
package.json
15
package.json
|
@ -6,10 +6,12 @@
|
|||
"bin": "./dist/npx/bitburner-filesync.js",
|
||||
"main": "./dist/npx/bitburner-filesync.js",
|
||||
"scripts": {
|
||||
"prepare": "npm run build",
|
||||
"build": "tsc --build --verbose --pretty",
|
||||
"clean": "tsc --build --clean",
|
||||
"format": "prettier -w .",
|
||||
"format:report": "prettier -c .",
|
||||
"lint": "eslint . --ext .ts",
|
||||
"test:all": "tsc && nyc mocha --recursive test",
|
||||
"test:single": "mocha",
|
||||
"start": "ts-node npx/bitburner-filesync.ts"
|
||||
|
@ -31,7 +33,7 @@
|
|||
"homepage": "https://github.com/bitburner-official/bitburner-filesync#readme",
|
||||
"dependencies": {
|
||||
"cheap-watch": "^1.0.4",
|
||||
"convict": "^6.2.3",
|
||||
"convict": "^6.2.4",
|
||||
"signal-js": "^3.0.1",
|
||||
"typescript": "^4.8.4",
|
||||
"ws": "^8.8.1"
|
||||
|
@ -46,8 +48,17 @@
|
|||
"@types/sinon": "^10.0.13",
|
||||
"@types/sinon-chai": "^3.2.8",
|
||||
"@types/ws": "^8.5.3",
|
||||
"@typescript-eslint/eslint-plugin": "^5.40.0",
|
||||
"@typescript-eslint/parser": "^5.40.0",
|
||||
"@types/parse-json": "^4.0.0",
|
||||
"@types/react": "^18.0.34",
|
||||
"@types/react-is": "^17.0.3",
|
||||
"@types/react-transition-group": "^4.4.5",
|
||||
"@types/prop-types": "^15.7.5",
|
||||
"@types/scheduler": "^0.16.3",
|
||||
"chai": "^4.3.6",
|
||||
"mocha": "^10.0.0",
|
||||
"eslint": "^8.25.0",
|
||||
"mocha": "^10.1.0",
|
||||
"nyc": "^15.1.0",
|
||||
"prettier": "^2.7.1",
|
||||
"sinon": "^14.0.0",
|
||||
|
|
|
@ -2,7 +2,7 @@ import convict from "convict";
|
|||
import { existsSync } from "fs";
|
||||
|
||||
// Define a schema
|
||||
export let config = convict({
|
||||
export const config = convict({
|
||||
allowedFiletypes: {
|
||||
doc: "Filetypes that are synchronized to the game.",
|
||||
format: "Array",
|
||||
|
@ -28,6 +28,11 @@ export let config = convict({
|
|||
env: "BB_SCRIPTFOLDER",
|
||||
arg: "folder",
|
||||
},
|
||||
exclude: {
|
||||
doc: "A list of folders or files to exclude from the sync.",
|
||||
format: "Array",
|
||||
default: [".vscode", ".idea", ".github"],
|
||||
},
|
||||
quiet: {
|
||||
doc: "Log less internal events to stdout.",
|
||||
format: "Boolean",
|
||||
|
|
|
@ -1,21 +1,45 @@
|
|||
import CheapWatch from "cheap-watch";
|
||||
import { config } from "./config";
|
||||
import { EventType } from "./eventTypes";
|
||||
import { config } from "./config.js";
|
||||
import { EventType } from "./eventTypes.js";
|
||||
import { mkdir } from "fs/promises";
|
||||
import { resolve } from "path";
|
||||
import { resolve, relative, isAbsolute } from "path";
|
||||
import type { Signal } from "signal-js";
|
||||
import type { File } from "./interfaces";
|
||||
import type { File } from "./interfaces.js";
|
||||
|
||||
/**
|
||||
* Returns true if a directory is a subdirectory of a parent directory (not necessarily strict).
|
||||
* @param dir The directory to perform the check on.
|
||||
* @param parent The parent directory.
|
||||
*/
|
||||
function isSubDirOf(dir: string, parent: string) {
|
||||
const relPath = relative(resolve(parent), resolve(dir));
|
||||
return !!relPath && !relPath.startsWith("..") && !isAbsolute(relPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given file should be watched.
|
||||
* @param file The provided file.
|
||||
*/
|
||||
function fileFilter(file: File) {
|
||||
// If the file is excluded, skip all other checks and ignore it.
|
||||
if (config.get("exclude").some((x) => isSubDirOf(file.path, x))) return false;
|
||||
if (config.get("allowedFiletypes").some((extension) => file.path.endsWith(extension))) return true;
|
||||
if (file.stats.isDirectory()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard for {@code NodeJS.ErrnoException}.
|
||||
* @param err
|
||||
*/
|
||||
function isError(err: unknown): err is NodeJS.ErrnoException {
|
||||
return (err as NodeJS.ErrnoException).code !== undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the file watch.
|
||||
* @param signaller The signal event emitter.
|
||||
*/
|
||||
export async function setupWatch(signaller: Signal) {
|
||||
try {
|
||||
await mkdir(resolve(config.get("scriptsFolder")));
|
||||
|
|
17
src/index.ts
17
src/index.ts
|
@ -1,6 +1,6 @@
|
|||
import { setupWatch } from "./fileWatch";
|
||||
import { config, loadConfig } from "./config";
|
||||
import { setupSocket } from "./networking/webSocket";
|
||||
import { setupWatch } from "./fileWatch.js";
|
||||
import { config, loadConfig } from "./config.js";
|
||||
import { setupSocket } from "./networking/webSocket.js";
|
||||
import signal from "signal-js";
|
||||
import { RawData } from "ws";
|
||||
import {
|
||||
|
@ -8,11 +8,14 @@ import {
|
|||
fileRemovalEventToMsg,
|
||||
requestFilenames,
|
||||
requestDefinitionFile,
|
||||
} from "./networking/messageGenerators";
|
||||
import { EventType } from "./eventTypes";
|
||||
import { messageHandler } from "./networking/messageHandler";
|
||||
import { FileEvent } from "./interfaces";
|
||||
} from "./networking/messageGenerators.js";
|
||||
import { EventType } from "./eventTypes.js";
|
||||
import { messageHandler } from "./networking/messageHandler.js";
|
||||
import { FileEvent } from "./interfaces.js";
|
||||
|
||||
/**
|
||||
* Starts the file watcher.
|
||||
*/
|
||||
export async function start() {
|
||||
loadConfig();
|
||||
const watch = await setupWatch(signal);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { readFileSync } from "fs";
|
||||
import { config } from "../config";
|
||||
import { config } from "../config.js";
|
||||
import { join } from "path";
|
||||
import type { FileEvent, Message } from "../interfaces";
|
||||
import type { FileEvent, Message } from "../interfaces.js";
|
||||
|
||||
let messageCounter = 0;
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { messageTracker } from "./messageTracker";
|
||||
import { messageTracker } from "./messageTracker.js";
|
||||
import { Stats, writeFile } from "fs";
|
||||
import { RawData } from "ws";
|
||||
import { config } from "../config";
|
||||
import { EventType } from "../eventTypes";
|
||||
import { fileChangeEventToMsg } from "./messageGenerators";
|
||||
import { config } from "../config.js";
|
||||
import { EventType } from "../eventTypes.js";
|
||||
import { fileChangeEventToMsg } from "./messageGenerators.js";
|
||||
import type { Signal } from "signal-js";
|
||||
import { Message } from "../interfaces";
|
||||
import { Message } from "../interfaces.js";
|
||||
|
||||
function deserialize(data: RawData): Message {
|
||||
const msg = JSON.parse(data.toString());
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import type { Message } from "../interfaces";
|
||||
import type { Message } from "../interfaces.js";
|
||||
|
||||
class MessageTracker {
|
||||
data = new Map<number, Message>();
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import type { Signal } from "signal-js";
|
||||
import { WebSocketServer } from "ws";
|
||||
import { config } from "../config";
|
||||
import { EventType } from "../eventTypes";
|
||||
import { Message } from "../interfaces";
|
||||
import { messageTracker } from "./messageTracker";
|
||||
import { config } from "../config.js";
|
||||
import { EventType } from "../eventTypes.js";
|
||||
import { Message } from "../interfaces.js";
|
||||
import { messageTracker } from "./messageTracker.js";
|
||||
|
||||
export function setupSocket(signaller: Signal) {
|
||||
const wss = new WebSocketServer({ port: config.get("port") });
|
||||
|
|
|
@ -37,7 +37,7 @@ describe("messageGenerators", () => {
|
|||
const msg = fileRemovalEventToMsg({ path: "sub/test.js" });
|
||||
const result = (msg?.params as FileData).filename;
|
||||
|
||||
if (result && result.hasOwnProperty("filename")) expect(result).to.eq("/sub/test.js");
|
||||
if (result && Object.prototype.hasOwnProperty.call(result, "filename")) expect(result).to.eq("/sub/test.js");
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -46,7 +46,7 @@ describe("messageGenerators", () => {
|
|||
const msg = fileRemovalEventToMsg({ path: "test.js" });
|
||||
const result = (msg?.params as FileData).filename;
|
||||
|
||||
if (result && result.hasOwnProperty("filename")) expect(result).to.eq("test.js");
|
||||
if (result && Object.prototype.hasOwnProperty.call(result, "filename")) expect(result).to.eq("test.js");
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -55,7 +55,7 @@ describe("messageGenerators", () => {
|
|||
const msg = fileRemovalEventToMsg({ path: "/sub/test.js" });
|
||||
const result = (msg?.params as FileData).filename;
|
||||
|
||||
if (result && result.hasOwnProperty("filename")) expect(result).to.eq("/sub/test.js");
|
||||
if (result && Object.prototype.hasOwnProperty.call(result, "filename")) expect(result).to.eq("/sub/test.js");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import chai from "chai";
|
||||
import { createSandbox, stub } from "sinon";
|
||||
import { createSandbox } from "sinon";
|
||||
import sinonChai from "sinon-chai";
|
||||
|
||||
export async function mochaGlobalSetup() {
|
||||
|
|
Loading…
Add table
Reference in a new issue