Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ module.exports = {
parserOptions: {
sourceType: "script",
},
plugins: ["node", "prettier", "security"],
extends: [
"eslint:recommended",
"plugin:node/recommended",
"plugin:security/recommended",
"plugin:import/recommended",
"plugin:prettier/recommended",
],
settings: {
node: {
allowModules: ["@agnoc/core", "@agnoc/cli"],
tryExtensions: [".js", ".ts", ".json"],
},
},
};
2 changes: 2 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ module.exports = function (api) {
const plugins = [
["@babel/plugin-proposal-decorators", { legacy: true }],
["@babel/plugin-proposal-class-properties", { loose: true }],
["@babel/plugin-proposal-private-methods", { loose: true }],
["@babel/plugin-proposal-private-property-in-object", { loose: true }],
[
"babel-plugin-module-resolver",
{
Expand Down
38 changes: 38 additions & 0 deletions get_map.txt

Large diffs are not rendered by default.

68 changes: 37 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,48 +25,53 @@
}
},
"devDependencies": {
"@babel/cli": "^7.14.5",
"@babel/core": "^7.14.6",
"@babel/plugin-proposal-class-properties": "^7.14.5",
"@babel/plugin-proposal-decorators": "^7.14.5",
"@babel/preset-env": "^7.14.5",
"@babel/preset-typescript": "^7.14.5",
"@babel/register": "^7.14.5",
"@commitlint/cli": "^12.1.4",
"@commitlint/config-conventional": "^12.1.4",
"@babel/cli": "^7.17.6",
"@babel/core": "^7.17.5",
"@babel/plugin-proposal-class-properties": "^7.16.7",
"@babel/plugin-proposal-decorators": "^7.17.2",
"@babel/preset-env": "^7.16.11",
"@babel/preset-typescript": "^7.16.7",
"@babel/register": "^7.17.0",
"@commitlint/cli": "^16.2.1",
"@commitlint/config-conventional": "^16.2.1",
"@tsconfig/node14": "^1.0.1",
"@types/chai": "^4.2.18",
"@types/debug": "^4.1.5",
"@types/mocha": "^8.2.2",
"@types/mock-fs": "^4.13.0",
"@types/node": "^15.12.2",
"@types/sinon": "^10.0.2",
"@types/sinon-chai": "^3.2.5",
"@typescript-eslint/eslint-plugin": "^4.27.0",
"@typescript-eslint/parser": "^4.27.0",
"@types/chai": "^4.3.0",
"@types/debug": "^4.1.7",
"@types/express": "^4.17.13",
"@types/mocha": "^9.1.0",
"@types/mock-fs": "^4.13.1",
"@types/node": "^17.0.21",
"@types/sinon": "^10.0.11",
"@types/sinon-chai": "^3.2.8",
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^5.14.0",
"@typescript-eslint/parser": "^5.14.0",
"babel-plugin-module-resolver": "^4.1.0",
"chai": "^4.3.4",
"chai": "^4.3.6",
"commitizen": "^4.2.4",
"core-js": "^3.14.0",
"core-js": "^3.21.1",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^7.28.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-chai-friendly": "^0.7.1",
"eslint-plugin-mocha": "^9.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-babel-module": "^5.3.1",
"eslint-import-resolver-typescript": "^2.5.0",
"eslint-plugin-chai-friendly": "^0.7.2",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-mocha": "^10.0.3",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-security": "^1.4.0",
"husky": "^6.0.0",
"hygen": "^6.1.0",
"husky": "^7.0.4",
"hygen": "^6.2.0",
"json": "^11.0.0",
"lerna": "^4.0.0",
"lint-staged": ">=11.0.0",
"lint-staged": ">=12.3.5",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"prettier": "2.3.1",
"sinon": "^11.1.1",
"prettier": "2.5.1",
"sinon": "^13.0.1",
"sinon-chai": "^3.7.0",
"typescript": "^4.3.2"
"typescript": "^4.6.2"
},
"engines": {
"node": ">=12.3"
Expand All @@ -77,5 +82,6 @@
"lint-staged": {
"*.{js,ts}": "eslint --fix",
"*.{md,json,yaml,yml}": "prettier -w"
}
},
"dependencies": {}
}
20 changes: 18 additions & 2 deletions packages/cli/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,45 @@ const path = require("path");
module.exports = {
overrides: [
{
files: ["src/**/*.{js,ts}", "test/**/*.{js,ts}"],
files: ["src/**/*.{js,ts}", "test/**/*.{js,ts}", "types/**/*.ts"],
parserOptions: {
ecmaVersion: 2020,
project: path.resolve(__dirname, "../../tsconfig.json"),
sourceType: "module",
},
plugins: ["@typescript-eslint", "node", "prettier", "security"],
extends: [
"eslint:recommended",
"plugin:node/recommended",
"plugin:security/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:prettier/recommended",
],
settings: {
node: {
tryExtensions: [".js", ".ts", ".json"],
},
"import/resolver": {
"babel-module": {
extensions: [".js", ".ts", ".json"],
alias: {
"^(@agnoc/[^/]+)/(?!lib)(.+)$": "\\1/src/\\2",
},
},
},
},
rules: {
"import/order": 1,
"node/no-unsupported-features/es-syntax": 0,
"security/detect-object-injection": 0,
"@typescript-eslint/no-unused-vars": [
1,
{
varsIgnorePattern: "^_",
},
],
},
},
],
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
"pcap": "^3.1.0"
},
"devDependencies": {
"chai": "^4.3.4",
"chai": "^4.3.6",
"execa": "^5.1.1",
"mocha": "^9.0.0",
"mock-fs": "^5.0.0",
"sinon": "^11.1.1",
"mocha": "^9.2.2",
"mock-fs": "^5.1.2",
"sinon": "^13.0.1",
"sinon-chai": "^3.7.0"
},
"engines": {
Expand Down
45 changes: 29 additions & 16 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Command } from "commander";
import cli from "cli-ux";
import chalk from "chalk";
import { version } from "../package.json";
import { decode } from "./commands/decode.command";
import { encode } from "./commands/encode.command";
import { read } from "./commands/read.command";
import { wlan } from "./commands/wlan.command";
import { wlanConfig } from "./commands/wlan-config.command";
import cli from "cli-ux";
import chalk from "chalk";

process.on("unhandledRejection", (e) => {
console.error(e);
Expand All @@ -26,15 +26,15 @@ function handleError(e: Error): void {
stdio.stderr.write(chalk.red(e.message + "\n"));
}

program.name("agnoc").version(version);
program.name("agnoc").version(version as string);

program
.command("decode <file>")
.description("decodes a flow file from binary to stdout", {
file: "file to decode, use '-' to read from stdin.",
})
.option("-j, --json", "json output")
.action((file, options) =>
.action((file: string, options: { json: true | undefined }) =>
decode(file, {
...options,
...stdio,
Expand All @@ -46,9 +46,8 @@ program
.description("encode a json file to binary to stdout", {
file: "file to encode, use '-' to read from stdin.",
})
.action((file, options) =>
.action((file: string) =>
encode(file, {
...options,
...stdio,
})
);
Expand All @@ -59,7 +58,7 @@ program
file: "file to read, use '-' to read from stdin.",
})
.option("-j, --json", "json output")
.action((file, options) =>
.action((file: string, options: { json: true | undefined }) =>
read(file, {
...options,
...stdio,
Expand All @@ -74,8 +73,16 @@ program
})
.option("-i, --iface <iface>", "network interface used to connect")
.option("-t, --timeout <timeout>", "connect timeout in milliseconds", "10000")
.action((ssid, pass, options) =>
wlan(ssid, pass, options).catch(handleError)
.action(
(
ssid: string,
pass: string,
options: { iface: string | undefined; timeout: string | undefined }
) =>
wlan(ssid, pass, {
iface: options.iface || null,
timeout: Number(options.timeout),
}).catch(handleError)
);

program
Expand All @@ -85,13 +92,19 @@ program
pass: "wifi password",
})
.option("-t, --timeout <timeout>", "connect timeout in milliseconds", "10000")
.action(async (ssid, pass, { timeout }) => {
cli.action.start("Configuring wifi settings in the robot");
await wlanConfig(ssid, pass, { timeout: Number(timeout) }).catch(
handleError
);
cli.action.stop();
});
.action(
async (
ssid: string,
pass: string,
options: { timeout: string | undefined }
) => {
cli.action.start("Configuring wifi settings in the robot");
await wlanConfig(ssid, pass, { timeout: Number(options.timeout) }).catch(
handleError
);
cli.action.stop();
}
);

program.addHelpCommand("help [command]", "display help for command");

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/wlan-config.command.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Socket } from "net";
import { BufferWriter } from "@agnoc/core/streams/buffer-writer.stream";
import { writeWord } from "@agnoc/core/utils/stream.util";
import { Socket } from "net";
import { debug as debugFactory } from "@agnoc/core/utils/debug.util";

function buildHeaders() {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/streams/json-transform.stream.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ObjectLiteral } from "@agnoc/core/types/object-literal.type";
import { Transform, TransformCallback } from "stream";
import { ObjectLiteral } from "@agnoc/core/types/object-literal.type";

export class JSONTransform extends Transform {
private buffer = "";
Expand All @@ -23,7 +23,7 @@ export class JSONTransform extends Transform {
try {
obj = JSON.parse(this.buffer) as ObjectLiteral;
} catch (e) {
return done(e);
return done(e as Error);
}

this.push(obj);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/streams/packet-decode-transform.stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class PacketDecodeTransform extends Transform {

this.push(packet);
} catch (e) {
return done(e);
return done(e as Error);
}

this.buffer = this.buffer.slice(size);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/streams/tcp-reader.stream.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Readable } from "stream";
import {
Decode,
LiveSessionOptions,
PacketWithHeader,
PcapSession,
} from "pcap";
import { Readable } from "stream";

interface TCPReaderOptions {
createSession(
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/utils/to-json-stream.util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Transform } from "stream";
import { OPDecoderLiteral } from "@agnoc/core/constants/opcodes.constant";
import { isObject } from "@agnoc/core/utils/is-object.util";
import { Packet } from "@agnoc/core/value-objects/packet.value-object";
import { Transform } from "stream";
import { ArrayTransform } from "../streams/array-transform.stream";

function filterProperties(_: string, value: unknown) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/utils/to-string-stream.util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Transform } from "stream";
import { OPDecoderLiteral } from "@agnoc/core/constants/opcodes.constant";
import { Packet } from "@agnoc/core/value-objects/packet.value-object";
import { Transform } from "stream";

export function toStringStream(): Transform[] {
return [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Duplex, PassThrough } from "stream";
import { describe, it } from "mocha";
import { expect } from "chai";
import { decode } from "../../../src/commands/decode.command";
import { Duplex, PassThrough } from "stream";
import mockFS from "mock-fs";
import { decode } from "../../../src/commands/decode.command";
import { readStream } from "../../helpers/read-stream.helper";

declare module "mocha" {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Duplex, PassThrough } from "stream";
import { describe, it } from "mocha";
import { expect } from "chai";
import { encode } from "../../../src/commands/encode.command";
import { Duplex, PassThrough } from "stream";
import mockFS from "mock-fs";
import { encode } from "../../../src/commands/encode.command";
import { readStream } from "../../helpers/read-stream.helper";

declare module "mocha" {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"outDir": "lib",
"tsBuildInfoFile": ".build-cache/tsconfig.build.tsbuildinfo"
},
"include": ["src", "typings.d.ts"],
"include": ["src", "types", "typings.d.ts"],
"references": [{ "path": "../core/tsconfig.build.json" }]
}
File renamed without changes.
Loading