Skip to content
Merged
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
50 changes: 50 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Release Workflow

on:
release:
types: [published]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [18]
include:
- os: ubuntu-latest
output-path: build/dist/server
output-name: server.psi.ubuntu
- os: windows-latest
output-path: build/dist/server.exe
output-name: server.psi.win
- os: macos-latest
output-path: build/dist/server
output-name: server.psi.macos

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm install

- name: Run script from package.json
run: |
cd PSI
npm run build

- name: Upload build artifact
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{ matrix.output-path }}
asset_name: ${{ matrix.output-name }}
asset_content_type: application/octet-stream
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Node Stuff
**/node_modules/*
**/dist/*
**/build/*

# Yarn config and stuff
**/.yarn/*
Expand All @@ -21,3 +21,4 @@

PSI/server.js
PSI/package-lock.json
package-lock.json
76 changes: 76 additions & 0 deletions PSI/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
module.exports = {
extends: ['eslint:recommended'],
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
allowImportExportEverywhere: true
},
env: {
node: true,
browser: true,
es2021: true
},
rules: {
'@typescript-eslint/no-this-alias': 0,
'@typescript-eslint/no-non-null-assertion': 0,
quotes: ['error', 'single', { avoidEscape: true }],
'prefer-const': 2,
'constructor-super': 2,
'for-direction': 2,
'getter-return': 2,
'no-async-promise-executor': 0,
'no-class-assign': 2,
'no-compare-neg-zero': 2,
'no-cond-assign': 2,
'no-const-assign': 2,
'no-constant-condition': 2,
'no-control-regex': 2,
'no-debugger': 2,
'no-delete-var': 2,
'no-dupe-args': 2,
'no-dupe-class-members': 2,
'no-dupe-else-if': 2,
'no-dupe-keys': 2,
'no-duplicate-case': 2,
'no-empty': 2,
'no-empty-character-class': 2,
'no-empty-pattern': 2,
'no-ex-assign': 2,
'no-extra-boolean-cast': 2,
'no-extra-semi': 2,
'no-fallthrough': 2,
'no-func-assign': 2,
'no-global-assign': 2,
'no-import-assign': 2,
'no-inner-declarations': 2,
'no-invalid-regexp': 2,
'no-irregular-whitespace': 2,
'no-misleading-character-class': 2,
'no-mixed-spaces-and-tabs': 0,
'no-new-symbol': 2,
'no-obj-calls': 2,
'no-octal': 2,
'no-prototype-builtins': 2,
'no-redeclare': 2,
'no-regex-spaces': 2,
'no-self-assign': 2,
'no-setter-return': 2,
'no-shadow-restricted-names': 2,
'no-sparse-arrays': 2,
'no-this-before-super': 2,
'no-undef': 2,
'no-unexpected-multiline': 2,
'no-unreachable': 2,
'no-unsafe-finally': 2,
'no-unsafe-negation': 2,
'no-unused-labels': 2,
'no-unused-vars': 1,
'no-useless-catch': 2,
'no-useless-escape': 2,
'no-with': 2,
'require-yield': 2,
'use-isnan': 2,
'valid-typeof': 2,
'no-case-declarations': 2
}
};
11 changes: 11 additions & 0 deletions PSI/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
arrowParens: 'always',
printWidth: 120,
semi: true,
singleQuote: true,
tabWidth: 2,
trailingComma: 'none',
useTabs: true,
endOfLine: 'lf',
bracketSpacing: true
};
124 changes: 124 additions & 0 deletions PSI/esb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
const esbuild = require('esbuild');
const { cp, readFile, writeFile } = require('fs/promises');
const { exists } = require('fs-extra');
const outputDir = 'build';
const outfile = `${outputDir}/server.js`;
const { join } = require('path');

const externals = [
'@serialport/bindings-cpp/prebuilds',
'zwave-js/package.json',
'@zwave-js/config/package.json',
'@zwave-js/config/config',
'@zwave-js/config/build',
'@zwave-js/server/package.json'
];

const nativeNodeModulesPlugin = {
name: 'native-node-modules',
setup(build) {
build.onResolve({ filter: /\.node$/, namespace: 'file' }, (args) => ({
path: require.resolve(args.path, { paths: [args.resolveDir] }),
namespace: 'node-file'
}));

build.onLoad({ filter: /.*/, namespace: 'node-file' }, (args) => ({
contents: `
import path from ${JSON.stringify(args.path)}
try { module.exports = require(path) }
catch {}
`
}));

build.onResolve({ filter: /\.node$/, namespace: 'node-file' }, (args) => ({
path: args.path,
namespace: 'file'
}));

const opts = build.initialOptions;
opts.loader = opts.loader || {};
opts.loader['.node'] = 'file';
}
};

const run = async () => {
const config = {
entryPoints: ['./server_source.js'],
plugins: [nativeNodeModulesPlugin],
bundle: true,
platform: 'node',
target: 'node18',
outfile,
external: externals
};
await esbuild.build(config);

const patchedServer = (await readFile(outfile, 'utf-8'))
.replace(/__dirname, "\.\.\/"/g, '__dirname, "./node_modules/@serialport/bindings-cpp"')
.replace('../../package.json', './node_modules/@zwave-js/server/package.json');

await writeFile(outfile, patchedServer);

for (const ext of externals) {
const path = ext.startsWith('./') ? ext : `node_modules/${ext}`;
if (await exists(path)) {
await cp(path, `${outputDir}/${path}`, { recursive: true });
}
}

let PKGFile;
let PackagePatch;

const getPath = (path) => {
return join(outputDir, path, 'package.json');
};

const patch = (Package) => {
delete Package.dependencies;
delete Package.devDependencies;
delete Package.scripts;
delete Package.exports;
delete Package.optionalDependencies;
};

/* Root Package File */
PKGFile = './package.json';
PackagePatch = require(PKGFile);
delete PackagePatch.dependencies;
delete PackagePatch.devDependencies;
delete PackagePatch.optionalDependencies;
PackagePatch.scripts = {
start: 'node server.js'
};
PackagePatch.bin = 'server.js';
PackagePatch.pkg = {
assets: ['node_modules/**']
};
await writeFile(`${outputDir}/package.json`, JSON.stringify(PackagePatch, null, 2));

/* Config Package File */
PKGFile = getPath('node_modules/@zwave-js/config');
console.log(`Patching ${PKGFile}`);
PackagePatch = require(`./${PKGFile}`);
patch(PackagePatch);
await writeFile(PKGFile, JSON.stringify(PackagePatch, null, 2));

/* ZwaveJS Package File */
PKGFile = getPath('node_modules/zwave-js');
console.log(`Patching ${PKGFile}`);
PackagePatch = require(`./${PKGFile}`);
patch(PackagePatch);
await writeFile(PKGFile, JSON.stringify(PackagePatch, null, 2));

/* Server Package File */
PKGFile = getPath('node_modules/@zwave-js/server');
console.log(`Patching ${PKGFile}`);
PackagePatch = require(`./${PKGFile}`);
patch(PackagePatch);
await writeFile(PKGFile, JSON.stringify(PackagePatch, null, 2));
};

run().catch((err) => {
console.error(err);
process.exit(1);
});
45 changes: 23 additions & 22 deletions PSI/package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
{
"version": "4.0.0",
"name": "server",
"bin": "./server.js",
"dependencies": {
"@zwave-js/server": "1.35.0",
"zwave-js": "12.5.6"
},
"devDependencies": {
"@yao-pkg/pkg": "^5.11.5",
"esbuild": "^0.20.2"
},
"scripts": {
"build": "npm run do_esbuild && npm run do_pkgbuild",
"do_esbuild": "esbuild server_source.js --bundle --outfile=server.js --platform=node --target=node18 --external:@serialport/* --external:@zwave-js/config --external:zwave-js/package.json",
"do_pkgbuild": "pkg . --compress gzip -t host --targets node18"
},
"pkg": {
"assets": "./node_modules/@serialport/bindings-cpp/prebuilds/**/*",
"outputPath": "dist"
}
}
{
"version": "4.0.0",
"name": "server",
"bin": "./server.js",
"dependencies": {
"@zwave-js/server": "1.40.2",
"zwave-js": "14.3.7"
},
"devDependencies": {
"@yao-pkg/pkg": "^6.2.0",
"esbuild": "^0.24.2",
"eslint": "^8.57.0",
"prettier": "^3.4.2"
},
"scripts": {
"build": "npm run do_esbuild && npm run do_pkgbuild",
"do_esbuild": "node esb.js",
"do_pkgbuild": "pkg ./build/package.json --compress gzip -t host --targets node18 --output ./build/dist/server",
"test": "export WS_PORT=7070 SERIAL_PORT=/dev/tty.usbmodem214301 CONFIG=$(<./test_config.json) && ./build/dist/server",
"lint": "eslint --ext .js .",
"lint:fix": "eslint --fix --ext .js . && prettier -w ."
}
}
Loading