Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement a CLI application to do local tests instead of run.ts #5565

Draft
wants to merge 32 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6983dcb
feat: implement CLI for local testing
AlCalzone Feb 28, 2023
9d03726
feat: implement CLI for local testing
AlCalzone Mar 1, 2023
016843d
feat: better menu and logs
AlCalzone Mar 1, 2023
8b05913
chore: reduce bundle size
AlCalzone Mar 1, 2023
f363caf
refactor: dynamic menu
AlCalzone Mar 2, 2023
e04d482
refactor: move menu item creation to hook
AlCalzone Mar 2, 2023
a5b488e
fix: stuff
AlCalzone Mar 2, 2023
c0d2b45
chore: upgrade ink to 4.0 (WIP)
AlCalzone Mar 2, 2023
9891d8b
chore: wtf ESM
AlCalzone Mar 2, 2023
6a7021d
feat: stuff
AlCalzone Mar 2, 2023
a7fbdbd
feat: device table (WIP)
AlCalzone Mar 3, 2023
eed1ef8
fix: ooops
AlCalzone Mar 3, 2023
a227291
chore: un-hide some .yarn files
AlCalzone Mar 3, 2023
443dcc8
chore: upgrade to Ink 4.0
AlCalzone Mar 3, 2023
28d3a1e
feat: work on devices table
AlCalzone Mar 3, 2023
0a183a7
feat: node selection
AlCalzone Mar 4, 2023
5d6239a
feat: unknown model, remove failed node
AlCalzone Mar 10, 2023
037a28b
feat: exclude nodes, event handlers
AlCalzone Mar 10, 2023
617fac3
feat: include/exclude
AlCalzone Mar 11, 2023
c74163d
fix: confirm exit layout
AlCalzone Mar 11, 2023
611cbfd
feat: replace node, re-interview
AlCalzone Mar 13, 2023
fb03359
feat: run scripts
AlCalzone Mar 13, 2023
ccc97ee
feat: device details page
AlCalzone Mar 13, 2023
d6a916e
fix: switch to ink fork with lines
AlCalzone Mar 13, 2023
83ece38
fix: debounce showing/hiding the log
AlCalzone Mar 14, 2023
087f60e
Merge branch 'master' into cli
AlCalzone Mar 15, 2023
67fe68c
feat: support setting RF region
AlCalzone Mar 15, 2023
d929509
feat: work in progress on CLI
AlCalzone Mar 20, 2023
c72cc58
Merge branch 'master' into cli
AlCalzone Apr 5, 2023
6920221
chore: upgrade ink
AlCalzone Apr 17, 2023
9507856
Merge branch 'master' into cli
AlCalzone Jul 6, 2023
5a98f62
Merge branch 'master' into cli
AlCalzone Jul 24, 2023
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
22 changes: 21 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,30 @@
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Start CLI",
"request": "launch",
"runtimeExecutable": "yarn",
"runtimeArgs": [
"node",
"--async-stack-traces",
"${workspaceFolder}/packages/cli/build/cli.js",
"--start"
],
"env": {
"NODE_ENV": "development"
// "DEV": "true"
},
"skipFiles": ["<node_internals>/**"],
"type": "node",
"console": "integratedTerminal",
"sourceMaps": true,
"preLaunchTask": "npm: build:cli"
},
{
"type": "node",
"request": "launch",
"name": "Debug locally",
"port": 9229,
"runtimeExecutable": "yarn",
"runtimeArgs": [
"node",
Expand All @@ -27,6 +46,7 @@
"sourceMaps": true,
"preLaunchTask": "npm: build"
},

{
"type": "node",
"request": "launch",
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
".husky/_/**/*": true,
"packages/config/config/devices/index.json": true,
"packages/*/package-lock.json": true,
".yarn/*": true,
".yarn/*.*": true,
".yarn/patches": false,
".yarn/releases": false,
".yarn/plugins": false,
Expand Down
16 changes: 16 additions & 0 deletions .vscode/typescriptreact.code-snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"React Functional Component": {
"prefix": "rfc",
"body": [
"import { Text } from \"ink\";",
"",
"export interface ${0:$TM_FILENAME_BASE}Props {",
"\t// TODO:",
"}",
"",
"export const ${0:$TM_FILENAME_BASE}: React.FC<${0:$TM_FILENAME_BASE}Props> = (props) => {",
"\treturn <Text>TODO</Text>;",
"};"
]
}
}
9 changes: 9 additions & 0 deletions .yarn/patches/react-devtools-core-npm-4.27.2-7a013e485e.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
diff --git a/dist/backend.js b/dist/backend.js
index 3eecd3041e688f887bb491b793ba653e3d74a23a..9ad2645340f0dc4fe1e95802839980d9eac7c328 100644
--- a/dist/backend.js
+++ b/dist/backend.js
@@ -1,3 +1,4 @@
+var window = globalThis;
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
13 changes: 13 additions & 0 deletions .yarn/patches/yoga-layout-prebuilt-npm-1.10.0-855b15449f.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/yoga-layout/build/Release/nbind.js b/yoga-layout/build/Release/nbind.js
index 0853309f9e0bd49d3e585db266442210d9538d1e..73e3fc4e416b3e3a177107f92a0fd10979177e16 100644
--- a/yoga-layout/build/Release/nbind.js
+++ b/yoga-layout/build/Release/nbind.js
@@ -1143,7 +1143,7 @@
}
}_nbind.addMethod = addMethod;function throwError(message) {
throw new Error(message);
- }_nbind.throwError = throwError;_nbind.bigEndian = false;_a = _typeModule(_typeModule), _nbind.Type = _a.Type, _nbind.makeType = _a.makeType, _nbind.getComplexType = _a.getComplexType, _nbind.structureList = _a.structureList;var BindType = function (_super) {
+ }_nbind.throwError = throwError;_nbind.bigEndian = false;var _a = _typeModule(_typeModule); _nbind.Type = _a.Type, _nbind.makeType = _a.makeType, _nbind.getComplexType = _a.getComplexType, _nbind.structureList = _a.structureList;var BindType = function (_super) {
__extends(BindType, _super);function BindType() {
var _this = _super !== null && _super.apply(this, arguments) || this;_this.heap = HEAPU32;_this.ptrSize = 4;return _this;
}BindType.prototype.needsWireRead = function (policyTbl) {
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
"RoboPhred (https://github.com/RoboPhred)"
],
"license": "MIT",
"homepage": "https://github.com/AlCalzone/node-zwave-js#readme",
"homepage": "https://github.com/zwave-js/node-zwave-js#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/AlCalzone/node-zwave-js.git"
"url": "git+https://github.com/zwave-js/node-zwave-js.git"
},
"bugs": {
"url": "https://github.com/AlCalzone/node-zwave-js/issues"
"url": "https://github.com/zwave-js/node-zwave-js/issues"
},
"funding": {
"url": "https://github.com/sponsors/AlCalzone/"
Expand Down Expand Up @@ -48,6 +48,7 @@
"@typescript-eslint/eslint-plugin": "^5.61.0",
"@typescript-eslint/parser": "^5.61.0",
"@zwave-js/cc": "workspace:*",
"@zwave-js/cli": "workspace:*",
"@zwave-js/config": "workspace:*",
"@zwave-js/core": "workspace:*",
"@zwave-js/flash": "workspace:*",
Expand Down Expand Up @@ -87,14 +88,17 @@
"resolutions": {
"minimist": "^1.2.6",
"colors": "1.4.0",
"[email protected]": "patch:ts-patch@npm%3A3.0.0-rc2#./.yarn/patches/ts-patch-npm-3.0.0-rc2-74c7730519.patch"
"yoga-layout-prebuilt@^1.9.6": "patch:yoga-layout-prebuilt@npm%3A1.10.0#./.yarn/patches/yoga-layout-prebuilt-npm-1.10.0-855b15449f.patch",
"react-devtools-core@^4.27.2": "patch:react-devtools-core@npm%3A4.27.2#./.yarn/patches/react-devtools-core-npm-4.27.2-7a013e485e.patch",
"@alcalzone/ink-table@^1.0.0": "patch:@alcalzone/ink-table@npm%3A1.0.0#./.yarn/patches/@alcalzone-ink-table-npm-1.0.0-65fbd8d761.patch"
},
"scripts": {
"w": "yarn ts maintenance/watch.ts",
"foreach": "yarn workspaces foreach -pvi --exclude @zwave-js/repo",
"clean": "yarn turbo run clean",
"build": "yarn turbo run build:turbo --",
"build:turbo": "yarn ts maintenance/build.ts",
"build:cli": "yarn workspace @zwave-js/cli run build:dev",
"watch": "yarn w build",
"test:ts": "FORCE_COLOR=1 yarn turbo run test:ts ${TURBO_FLAGS:-'--concurrency=1'} --",
"test": "yarn w test:ts",
Expand Down
6 changes: 3 additions & 3 deletions packages/cc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
"email": "[email protected]"
},
"license": "MIT",
"homepage": "https://github.com/AlCalzone/node-zwave-js#readme",
"homepage": "https://github.com/zwave-js/node-zwave-js#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/AlCalzone/node-zwave-js.git"
"url": "git+https://github.com/zwave-js/node-zwave-js.git"
},
"bugs": {
"url": "https://github.com/AlCalzone/node-zwave-js/issues"
"url": "https://github.com/zwave-js/node-zwave-js/issues"
},
"funding": {
"url": "https://github.com/sponsors/AlCalzone/"
Expand Down
9 changes: 9 additions & 0 deletions packages/cli/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
extends: "../.eslintrc.js",
parserOptions: {
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
sourceType: "module", // Allows for the use of imports
project: "tsconfig.json",
tsconfigRootDir: __dirname,
},
};
21 changes: 21 additions & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Z-Wave JS: Firmware Flasher

CLI utility to flash the firmware on Z-Wave controllers

**WARNING:** Flashing the wrong firmware may brick your controller. Use at your own risk!

## Usage

You can either execute the current version directly from `npm` using

```
npx @zwave-js/flash@latest <port> <filename> [--verbose]
```

or you can execute the version in the checked out repository by executing

```
yarn ts packages/flash/src/cli.ts <port> <filename> [--verbose]
```

The `--verbose` flag will cause the driver logs to be printed to console.
2 changes: 2 additions & 0 deletions packages/cli/bin/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
await import("../build/cli.js");
33 changes: 33 additions & 0 deletions packages/cli/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

DEFINE_NODEENV="--define:process.env.NODE_ENV=\"production\""
MINIFY="--minify"

while [[ $# -gt 0 ]]; do
case $1 in
--dev)
DEFINE_NODEENV=""
MINIFY=""
shift # past argument
;;
-*|--*)
echo "Unknown option $1"
exit 1
;;
esac
done

esbuild src/cli.tsx \
$DEFINE_NODEENV \
--outfile=build/cli.js \
--platform=node \
--target=node16 \
--format=esm \
--bundle \
$MINIFY \
--sourcemap \
--external:zwave-js \
--external:react-devtools-core \
--external:yoga-wasm-web \
--banner:js="import { createRequire } from 'module'; var require = require || createRequire(import.meta.url);"
# Fix esbuild not being able to do dynamic require() in ESM mode
74 changes: 74 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"name": "@zwave-js/cli",
"version": "10.10.0",
"description": "CLI for Z-Wave JS",
"keywords": [],
"publishConfig": {
"access": "public"
},
"type": "module",
"module": "build/cli.js",
"types": "script.d.ts",
"files": [
"bin/",
"build/**/*.{js,d.ts,map}"
],
"bin": "bin/cli.js",
"author": {
"name": "AlCalzone",
"email": "[email protected]"
},
"license": "MIT",
"homepage": "https://github.com/zwave-js/node-zwave-js#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/zwave-js/node-zwave-js.git"
},
"bugs": {
"url": "https://github.com/zwave-js/node-zwave-js/issues"
},
"funding": {
"url": "https://github.com/sponsors/AlCalzone/"
},
"engines": {
"node": ">=14.13.0"
},
"scripts": {
"ts": "yarn node --loader esbuild-register/loader -r esbuild-register",
"build": "./build.sh",
"build:dev": "./build.sh --dev",
"clean": "del-cli build/ \"*.tsbuildinfo\"",
"lint:ts": "eslint --ext .ts --rule \"prettier/prettier: off\" \"src/**/*.ts\"",
"lint:ts:fix": "yarn run lint:ts --fix",
"lint:prettier": "prettier -c \"src/**/*.ts\"",
"lint:prettier:fix": "yarn run lint:prettier -w"
},
"dependencies": {
"@zwave-js/core": "workspace:*",
"@zwave-js/shared": "workspace:*",
"yoga-wasm-web": "~0.3.3",
"zwave-js": "workspace:*"
},
"devDependencies": {
"@alcalzone/ink-table": "~1.1.0",
"@esm2cjs/p-queue": "^7.3.0",
"@types/ink-spinner": "^3.0.1",
"@types/ink-text-input": "^2.0.2",
"@types/node": "^14.18.36",
"@types/react": "^18",
"ansi-colors": "^4.1.3",
"del-cli": "^5.0.0",
"esbuild": "0.15.7",
"esbuild-register": "^3.4.2",
"ink": "https://github.com/AlCalzone/ink#pixels-stable",
"ink-select-input": "^5.0.0",
"ink-spinner": "^5.0.0",
"ink-text-input": "^5.0.0",
"ink-use-stdout-dimensions": "^1.0.5",
"prettier": "^2.8.1",
"react": "^18.2.0",
"react-devtools-core": "^4.27.2",
"typescript": "4.9.5",
"winston": "^3.8.2"
}
}
10 changes: 10 additions & 0 deletions packages/cli/script.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { Driver } from "zwave-js";
import type { IDialogsContext } from "./src/hooks/useDialogs";

export interface ScriptContext {
driver: Driver;
showError: IDialogsContext["showError"];
showWarning: IDialogsContext["showWarning"];
showSuccess: IDialogsContext["showSuccess"];
queryInput: IDialogsContext["queryInput"];
}
Loading