Compare commits

...
Sign in to create a new pull request.

18 commits

Author SHA1 Message Date
Alt
019c45580f
Merge pull request #32 from davidc789/main
Add exclude feature
2023-06-30 11:23:20 +02:00
david
cc97684069 Run prettier 2023-04-19 07:16:40 +10:00
david
ee7231af9c Added more documentation 2023-04-13 17:10:26 +10:00
david
fbab8a375f Added some documentation 2023-04-13 08:46:42 +10:00
david
544344bbb4 Bug fixes 2023-04-12 17:40:50 +10:00
david
b9467d6a57 Merge remote-tracking branch 'origin/feat/exclude' into feat/exclude
# Conflicts:
#	npx/bitburner-filesync.ts
2023-04-12 17:37:12 +10:00
david
1567a7c650 Merge remote-tracking branch 'origin/feat/exclude' into feat/exclude
# Conflicts:
#	src/fileWatch.ts
2023-04-12 17:36:27 +10:00
david
5cb38deb40 Merge remote-tracking branch 'origin/feat/exclude' into feat/exclude
# Conflicts:
#	src/fileWatch.ts
2023-04-12 17:31:19 +10:00
david
043a2d34b1 Bug fixes 2023-04-12 17:22:14 +10:00
david
2b40438341 Bug fixes 2023-04-11 21:48:05 +10:00
david
fd3392fb23 Added a prepare script to allow installing off GitHub 2023-04-11 15:04:42 +10:00
david
daf7854cd0 Bumped dependency versions to the latest 2023-04-11 14:29:05 +10:00
david
5bebc2832a Added missing type packages to eliminate build errors 2023-04-11 12:20:06 +10:00
david
2f1807812d Added folder exclusion feature and .gitattributes 2023-04-11 12:12:34 +10:00
Alt
7ff71ffbd9
Merge pull request #30 from Pustur/add-eslint
Add eslint
2022-10-12 20:29:03 +02:00
Loris Bettazza
352c083e83 Fix lint errors 2022-10-12 00:17:48 +02:00
Loris Bettazza
3901af1c18 Setup eslint config and script 2022-10-12 00:14:30 +02:00
Loris Bettazza
e5763314ff Add eslint dependencies 2022-10-12 00:14:28 +02:00
15 changed files with 2155 additions and 63 deletions

2
.eslintignore Normal file
View file

@ -0,0 +1,2 @@
node_modules/
dist/

10
.eslintrc Normal file
View 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
View 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

View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -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",

View file

@ -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",

View file

@ -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")));

View file

@ -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);

View file

@ -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;

View file

@ -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());

View file

@ -1,4 +1,4 @@
import type { Message } from "../interfaces";
import type { Message } from "../interfaces.js";
class MessageTracker {
data = new Map<number, Message>();

View file

@ -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") });

View file

@ -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");
});
});
});

View file

@ -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() {