From fe7a2c5a2a5c0b5ef761b5b8bb05f774dd4a2c61 Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Thu, 16 Nov 2023 14:09:41 +0100 Subject: [PATCH] feat: add npm deploy and move backend source to `/api` folder (#3422) --- .github/workflows/release-it.yml | 7 +++ .npmignore | 27 +++++++++++ app.ts => api/app.ts | 3 +- {bin => api/bin}/www.ts | 0 {config => api/config}/app.ts | 17 +++---- {config => api/config}/store.ts | 0 {hass => api/hass}/configurations.ts | 0 {hass => api/hass}/devices.ts | 0 {lib => api/lib}/BackupManager.ts | 2 +- {lib => api/lib}/Constants.ts | 0 {lib => api/lib}/CustomPlugin.ts | 0 {lib => api/lib}/EventEmitter.ts | 0 {lib => api/lib}/Gateway.ts | 4 +- {lib => api/lib}/MqttClient.ts | 5 +- {lib => api/lib}/SocketEvents.ts | 0 {lib => api/lib}/SocketManager.ts | 0 {lib => api/lib}/ZwaveClient.ts | 7 ++- {lib => api/lib}/jsonStore.ts | 0 {lib => api/lib}/logger.ts | 0 {lib => api/lib}/utils.ts | 19 +++++--- docs/getting-started/other-methods.md | 58 +++++++++++++++++++++++ nodemon.json | 2 +- package.json | 8 ++-- src/apis/ConfigApis.js | 2 +- src/lib/axios-progress-bar.js | 55 ++++++++++++++++++++++ src/main.js | 2 - test/lib/Constants.test.ts | 2 +- test/lib/Gateway.test.ts | 4 +- test/lib/jsonStore.test.ts | 67 ++++++++++++++++----------- test/lib/logger.test.ts | 6 +-- test/lib/utils.test.ts | 17 +++---- tsconfig.json | 7 +-- yarn.lock | 34 ++++---------- 33 files changed, 246 insertions(+), 109 deletions(-) create mode 100644 .npmignore rename app.ts => api/app.ts (99%) rename {bin => api/bin}/www.ts (100%) rename {config => api/config}/app.ts (53%) rename {config => api/config}/store.ts (100%) rename {hass => api/hass}/configurations.ts (100%) rename {hass => api/hass}/devices.ts (100%) rename {lib => api/lib}/BackupManager.ts (98%) rename {lib => api/lib}/Constants.ts (100%) rename {lib => api/lib}/CustomPlugin.ts (100%) rename {lib => api/lib}/EventEmitter.ts (100%) rename {lib => api/lib}/Gateway.ts (99%) rename {lib => api/lib}/MqttClient.ts (98%) rename {lib => api/lib}/SocketEvents.ts (100%) rename {lib => api/lib}/SocketManager.ts (100%) rename {lib => api/lib}/ZwaveClient.ts (99%) rename {lib => api/lib}/jsonStore.ts (100%) rename {lib => api/lib}/logger.ts (100%) rename {lib => api/lib}/utils.ts (94%) create mode 100644 src/lib/axios-progress-bar.js diff --git a/.github/workflows/release-it.yml b/.github/workflows/release-it.yml index dbeb6b7b294..4246c19b863 100644 --- a/.github/workflows/release-it.yml +++ b/.github/workflows/release-it.yml @@ -34,9 +34,16 @@ jobs: - name: Install dependencies run: yarn install --immutable + - name: Initialize NPM config + run: | + npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + - name: Make the release env: GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} run: | git config user.email "bot@zwave-js.io" git config user.name "Z-Wave JS Bot" diff --git a/.npmignore b/.npmignore new file mode 100644 index 00000000000..67d1aadd1f0 --- /dev/null +++ b/.npmignore @@ -0,0 +1,27 @@ +.github +.vscode +.yarn +/api/ +/src/ +/certs/ +/docker/ +/docs/ +/kubernetes/ +/test/ +/pkg/ +/store/ + + +/.* +/*.ts +/*.js +/kustomization.yaml +/fakeNodes.json +/nodemon.json +/package.sh +/index.html + +/tsconfig.* + +/*.md +/*.tgz diff --git a/app.ts b/api/app.ts similarity index 99% rename from app.ts rename to api/app.ts index 368c3435b4b..a491472f833 100644 --- a/app.ts +++ b/api/app.ts @@ -1,5 +1,4 @@ import express, { Request, RequestHandler, Response, Router } from 'express' -import { version } from './package.json' import history from 'connect-history-api-fallback' import cors from 'cors' import csrf from 'csurf' @@ -1158,7 +1157,7 @@ app.post( // update versions to actual ones settings.gateway.versions = { - app: version, // don't use getVersion here as it may include commit sha + app: utils.pkgJson.version, // don't use getVersion here as it may include commit sha driver: libVersion, server: serverVersion, } diff --git a/bin/www.ts b/api/bin/www.ts similarity index 100% rename from bin/www.ts rename to api/bin/www.ts diff --git a/config/app.ts b/api/config/app.ts similarity index 53% rename from config/app.ts rename to api/config/app.ts index 10a0adecd82..8bc71f73eb5 100644 --- a/config/app.ts +++ b/api/config/app.ts @@ -10,15 +10,16 @@ export const logsDir: string = joinPath(storeDir, 'logs') export const snippetsDir: string = joinPath(storeDir, 'snippets') export const tmpDir: string = joinPath(storeDir, '.tmp') -export const backupsDir: string = process.env.BACKUPS_DIR || joinPath(storeDir, 'backups') +export const backupsDir: string = + process.env.BACKUPS_DIR || joinPath(storeDir, 'backups') export const nvmBackupsDir: string = joinPath(backupsDir, 'nvm') export const storeBackupsDir: string = joinPath(backupsDir, 'store') - -export const defaultUser: string = 'admin' -export const defaultPsw: string = 'zwave' +export const defaultUser: string = 'admin' +export const defaultPsw: string = 'zwave' // lgtm [js/hardcoded-credentials] -export const sessionSecret: string = process.env.SESSION_SECRET || 'DEFAULT_SESSION_SECRET_CHANGE_ME' -export const base: string = process.env.BASE_PATH || '/' -export const port: string | number = process.env.PORT || 8091 -export const host: string = process.env.HOST // by default undefined, so it will listen on all interfaces both ipv4 and ipv6 \ No newline at end of file +export const sessionSecret: string = + process.env.SESSION_SECRET || 'DEFAULT_SESSION_SECRET_CHANGE_ME' +export const base: string = process.env.BASE_PATH || '/' +export const port: string | number = process.env.PORT || 8091 +export const host: string = process.env.HOST // by default undefined, so it will listen on all interfaces both ipv4 and ipv6 diff --git a/config/store.ts b/api/config/store.ts similarity index 100% rename from config/store.ts rename to api/config/store.ts diff --git a/hass/configurations.ts b/api/hass/configurations.ts similarity index 100% rename from hass/configurations.ts rename to api/hass/configurations.ts diff --git a/hass/devices.ts b/api/hass/devices.ts similarity index 100% rename from hass/devices.ts rename to api/hass/devices.ts diff --git a/lib/BackupManager.ts b/api/lib/BackupManager.ts similarity index 98% rename from lib/BackupManager.ts rename to api/lib/BackupManager.ts index 5a952f84403..41107625fdd 100644 --- a/lib/BackupManager.ts +++ b/api/lib/BackupManager.ts @@ -1,5 +1,5 @@ import store from '../config/store' -import { module } from '../lib/logger' +import { module } from './logger' import jsonStore, { STORE_BACKUP_PREFIX } from './jsonStore' import Cron from 'croner' import { readdir, unlink } from 'fs/promises' diff --git a/lib/Constants.ts b/api/lib/Constants.ts similarity index 100% rename from lib/Constants.ts rename to api/lib/Constants.ts diff --git a/lib/CustomPlugin.ts b/api/lib/CustomPlugin.ts similarity index 100% rename from lib/CustomPlugin.ts rename to api/lib/CustomPlugin.ts diff --git a/lib/EventEmitter.ts b/api/lib/EventEmitter.ts similarity index 100% rename from lib/EventEmitter.ts rename to api/lib/EventEmitter.ts diff --git a/lib/Gateway.ts b/api/lib/Gateway.ts similarity index 99% rename from lib/Gateway.ts rename to api/lib/Gateway.ts index 77d9e3e2e5c..84aa1901301 100644 --- a/lib/Gateway.ts +++ b/api/lib/Gateway.ts @@ -1,10 +1,10 @@ import * as fs from 'fs' import * as path from 'path' -import * as utils from '../lib/utils' +import * as utils from './utils' import { AlarmSensorType, SetValueAPIOptions } from 'zwave-js' import { CommandClasses, ValueID } from '@zwave-js/core' import * as Constants from './Constants' -import { LogLevel, module } from '../lib/logger' +import { LogLevel, module } from './logger' import hassCfg from '../hass/configurations' import hassDevices from '../hass/devices' import { storeDir } from '../config/app' diff --git a/lib/MqttClient.ts b/api/lib/MqttClient.ts similarity index 98% rename from lib/MqttClient.ts rename to api/lib/MqttClient.ts index 3185a2dd669..43d7944e8d8 100644 --- a/lib/MqttClient.ts +++ b/api/lib/MqttClient.ts @@ -8,9 +8,8 @@ import { IStore, connect, } from 'mqtt' -import { allSettled, parseJSON, sanitizeTopic } from './utils' +import { allSettled, parseJSON, sanitizeTopic, pkgJson } from './utils' import { module } from './logger' -import { version as appVersion } from '../package.json' import { TypedEventEmitter } from './EventEmitter' import { storeDir } from '../config/app' import { ensureDir } from 'fs-extra' @@ -203,7 +202,7 @@ class MqttClient extends TypedEventEmitter { if (this.client) { this.client.publish( this.getClientTopic(MqttClient.VERSION_TOPIC), - JSON.stringify({ value: appVersion, time: Date.now() }), + JSON.stringify({ value: pkgJson.version, time: Date.now() }), { retain: this.config.retain, qos: this.config.qos }, ) } diff --git a/lib/SocketEvents.ts b/api/lib/SocketEvents.ts similarity index 100% rename from lib/SocketEvents.ts rename to api/lib/SocketEvents.ts diff --git a/lib/SocketManager.ts b/api/lib/SocketManager.ts similarity index 100% rename from lib/SocketManager.ts rename to api/lib/SocketManager.ts diff --git a/lib/ZwaveClient.ts b/api/lib/ZwaveClient.ts similarity index 99% rename from lib/ZwaveClient.ts rename to api/lib/ZwaveClient.ts index 307d13124ed..9a41331f340 100644 --- a/lib/ZwaveClient.ts +++ b/api/lib/ZwaveClient.ts @@ -110,7 +110,6 @@ import * as utils from './utils' import { serverVersion, ZwavejsServer } from '@zwave-js/server' import { ensureDir, exists, mkdirp, writeFile } from 'fs-extra' import { Server as SocketServer } from 'socket.io' -import * as pkgjson from '../package.json' import { TypedEventEmitter } from './EventEmitter' import { GatewayValue } from './Gateway' @@ -2135,7 +2134,7 @@ class ZwaveClient extends TypedEventEmitter { : true, }, userAgent: { - [pkgjson.name]: pkgjson.version, + [utils.pkgJson.name]: utils.pkgJson.version, }, } @@ -2677,9 +2676,9 @@ class ZwaveClient extends TypedEventEmitter { if (this._driver) { this._driver.enableStatistics({ applicationName: - pkgjson.name + + utils.pkgJson.name + (this.cfg.serverEnabled ? ' / zwave-js-server' : ''), - applicationVersion: pkgjson.version, + applicationVersion: utils.pkgJson.version, }) logger.info('Zwavejs usage statistics ENABLED') } diff --git a/lib/jsonStore.ts b/api/lib/jsonStore.ts similarity index 100% rename from lib/jsonStore.ts rename to api/lib/jsonStore.ts diff --git a/lib/logger.ts b/api/lib/logger.ts similarity index 100% rename from lib/logger.ts rename to api/lib/logger.ts diff --git a/lib/utils.ts b/api/lib/utils.ts similarity index 94% rename from lib/utils.ts rename to api/lib/utils.ts index e6dace95ab7..e5ef8f22c48 100644 --- a/lib/utils.ts +++ b/api/lib/utils.ts @@ -1,11 +1,13 @@ // eslint-disable-next-line one-var -import * as appRoot from 'app-root-path' -import { version } from '../package.json' import { ValueID } from 'zwave-js' -import path from 'path' +import path, { resolve } from 'path' import crypto from 'crypto' import { readFileSync } from 'fs' +// don't use import here, it will break the build +// eslint-disable-next-line @typescript-eslint/no-var-requires +export const pkgJson = require('../../package.json') + let VERSION: string export interface Snippet { @@ -77,13 +79,16 @@ export function fileDate(date?: Date) { return date.toISOString().slice(-24).replace(/\D/g, '').slice(0, 14) } +/** Where package.json is */ +export const basePath = resolve(__dirname, '..', '..') + /** * Get the base root path to application directory. When we are in a `pkg` environment * the path of the snapshot is not writable */ export function getPath(write: boolean): string { if (write && hasProperty(process, 'pkg')) return process.cwd() - else return appRoot.toString() + else return basePath } /** @@ -167,9 +172,11 @@ export function getVersion(): string { .trim() } - VERSION = `${version}${rev ? '.' + rev.substring(0, 7) : ''}` + VERSION = `${pkgJson.version}${ + rev ? '.' + rev.substring(0, 7) : '' + }` } catch { - VERSION = version + VERSION = pkgJson.version } } diff --git a/docs/getting-started/other-methods.md b/docs/getting-started/other-methods.md index c1cc379250b..7801bcc7976 100644 --- a/docs/getting-started/other-methods.md +++ b/docs/getting-started/other-methods.md @@ -34,6 +34,64 @@ sudo snap connect zwave-js-ui:hardware-observe > > Raspberry Pi users running Raspbian/Debian, read [this thread](https://github.com/zwave-js/zwave-js-ui/discussions/1216#discussion-3364776). Please ask Raspbian/Debian related-questions in this thread. +## NPM + +You can install Z-Wave JS UI from NPM: + +```bash +npm install -g zwave-js-ui +``` + +And run it with: + +```bash +zwave-js-ui +``` + +> [!WARNING] +> You **MUST** configure a custom storage path using an environment variable, otherwise settings will be lost on updates. + +Run with custom storage path: + +```bash +STORE_DIR=~/.zwave-js-ui \ +ZWAVEJS_EXTERNAL_CONFIG=~/.zwave-js-ui/.config-db \ +zwave-js-ui +``` + +If you want to run it as a service, you can use [PM2](https://pm2.keymetrics.io/): + +```bash +npm install -g pm2 +``` + +Create a file named `ecosystem.config.js` with the following content (change the paths to match your system): + +```js +module.exports = { + apps : [ + { + out_file: "/dev/null", // disable logs, use log to file when needed + error_file: "/dev/null", // disable logs, use log to file when needed + cwd: "~/", + script: "zwave-js-ui", + env: { + STORE_DIR: "~/.zwave-js-ui", + ZWAVEJS_EXTERNAL_CONFIG: "~/.zwave-js-ui/.config-db", + }, + }, + ] +} +``` + +And run it with: + +```bash +pm2 start ecosystem.config.js +pm2 save +pm2 startup +``` + ## NodeJS or PKG version The most complex way to run Z-Wave JS UI is on bare metal. To do so, you can use the packaged version (you don't need NodeJS/yarn installed) or clone this repository and build the project: diff --git a/nodemon.json b/nodemon.json index f978108a1ec..7dc6f8ae2d3 100644 --- a/nodemon.json +++ b/nodemon.json @@ -2,5 +2,5 @@ "watch": ["**/*.ts", "package.json", "tsconfig.json", "../node-zwave-js/packages/*/build/**/*.js"], "ext": "ts,json,js", "ignore": ["pkg", "store", "node_modules", "src", "dist", "server"], - "exec": "node --inspect=7004 --trace-warnings -r ./esbuild-register bin/www.ts" + "exec": "node --inspect=7004 --trace-warnings -r ./esbuild-register api/bin/www.ts" } diff --git a/package.json b/package.json index 3a9260637be..95ea72ea34b 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dev": "vite", "dev-https": "SERVER_SSL='true' yarn run dev", "dev:server": "nodemon", - "server": "ts-node -r esbuild-register bin/www.ts", + "server": "ts-node -r esbuild-register api/bin/www.ts", "fake-stick": "yarn mock-server -c server_config.js", "start": "node --preserve-symlinks server/bin/www.js", "lint": "npm-run-all 'lint:*'", @@ -81,7 +81,7 @@ "before:release": "./package.sh --release" }, "npm": { - "publish": false + "publish": true }, "plugins": { "@release-it/conventional-changelog": { @@ -119,10 +119,8 @@ "@zwave-js/server": "^1.33.0", "@zwave-js/winston-daily-rotate-file": "^4.5.6-1", "ansi_up": "^6.0.2", - "app-root-path": "^3.1.0", "archiver": "^6.0.1", "axios": "^1.5.1", - "axios-progress-bar": "^1.2.0", "connect-history-api-fallback": "2.0.0", "cookie-parser": "^1.4.6", "cors": "^2.8.5", @@ -145,6 +143,7 @@ "mqtt-jsonl-store": "^0.2.0", "multer": "^1.4.5-lts.1", "native-url": "^0.3.4", + "nprogress": "^0.2.0", "pinia": "^2.1.7", "prismjs": "^1.29.0", "qr-scanner": "^1.4.2", @@ -168,7 +167,6 @@ "@actions/github": "^6.0.0", "@babel/register": "^7.22.15", "@tsconfig/node18": "^18.2.2", - "@types/app-root-path": "^1.2.7", "@types/archiver": "^5.3.4", "@types/chai": "^4.3.9", "@types/chai-as-promised": "^7.1.7", diff --git a/src/apis/ConfigApis.js b/src/apis/ConfigApis.js index c9ad4d7d313..1d830b7f14d 100644 --- a/src/apis/ConfigApis.js +++ b/src/apis/ConfigApis.js @@ -1,5 +1,5 @@ import axios from 'axios' -import { loadProgressBar } from 'axios-progress-bar' +import loadProgressBar from '../lib/axios-progress-bar' import Router from '../router' import logger from '../lib/logger' diff --git a/src/lib/axios-progress-bar.js b/src/lib/axios-progress-bar.js new file mode 100644 index 00000000000..5120483a5bc --- /dev/null +++ b/src/lib/axios-progress-bar.js @@ -0,0 +1,55 @@ +import 'nprogress/nprogress.css' +import NProgress from 'nprogress' +import axios from 'axios' + +const calculatePercentage = (loaded, total) => Math.floor(loaded * 1.0) / total + +export default function loadProgressBar(config, instance = axios) { + let requestsCounter = 0 + + const setupStartProgress = () => { + instance.interceptors.request.use((c) => { + requestsCounter++ + NProgress.start() + return c + }) + } + + const setupUpdateProgress = () => { + const update = (e) => { + const { loaded, total } = e + + // sometimes `total` is undefined, in that case simply call `inc` without params + if (loaded !== undefined && total !== undefined) { + NProgress.set(calculatePercentage(loaded, total)) + } else { + NProgress.inc() + } + } + instance.defaults.onDownloadProgress = update + instance.defaults.onUploadProgress = update + } + + const setupStopProgress = () => { + const responseFunc = (response) => { + if (--requestsCounter === 0) { + NProgress.done() + } + return response + } + + const errorFunc = (error) => { + if (--requestsCounter === 0) { + NProgress.done() + } + return Promise.reject(error) + } + + instance.interceptors.response.use(responseFunc, errorFunc) + } + + NProgress.configure(config) + setupStartProgress() + setupUpdateProgress() + setupStopProgress() +} diff --git a/src/main.js b/src/main.js index 16144ab7878..7d2f78581d5 100644 --- a/src/main.js +++ b/src/main.js @@ -3,8 +3,6 @@ import pinia from './plugins/pinia' import vuetify from './plugins/vuetify' // path to vuetify export import router from './router' import App from './App.vue' - -import 'axios-progress-bar/dist/nprogress.css' // Custom assets CSS JS import './assets/css/main.css' diff --git a/test/lib/Constants.test.ts b/test/lib/Constants.test.ts index 9aa7ab9d0f5..c48fad0a211 100644 --- a/test/lib/Constants.test.ts +++ b/test/lib/Constants.test.ts @@ -4,7 +4,7 @@ import chai, { expect } from 'chai' // eslint-disable-next-line @typescript-eslint/no-var-requires chai.use(require('sinon-chai')) -import * as mod from '../../lib/Constants' +import * as mod from '../../api/lib/Constants' describe('#Constants', () => { describe('#productionType()', () => { diff --git a/test/lib/Gateway.test.ts b/test/lib/Gateway.test.ts index b22c72cf64f..a4108236af9 100644 --- a/test/lib/Gateway.test.ts +++ b/test/lib/Gateway.test.ts @@ -1,6 +1,6 @@ import chai, { expect } from 'chai' -import Gateway, { closeWatchers } from '../../lib/Gateway' -import { ZUINode } from '../../lib/ZwaveClient' +import Gateway, { closeWatchers } from '../../api/lib/Gateway' +import { ZUINode } from '../../api/lib/ZwaveClient' // eslint-disable-next-line @typescript-eslint/no-var-requires chai.use(require('sinon-chai')) diff --git a/test/lib/jsonStore.test.ts b/test/lib/jsonStore.test.ts index 5ca765ce7d1..c6998de8678 100644 --- a/test/lib/jsonStore.test.ts +++ b/test/lib/jsonStore.test.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/no-floating-promises */ import chai, { expect } from 'chai' import proxyquire from 'proxyquire' -import { StorageHelper } from '../../lib/jsonStore' +import { StorageHelper } from '../../api/lib/jsonStore' import sinon from 'sinon' -import { StoreFile, StoreKeys } from '../../config/store' +import { StoreFile, StoreKeys } from '../../api/config/store' // eslint-disable-next-line @typescript-eslint/no-var-requires chai.use(require('chai-as-promised')) @@ -15,11 +15,14 @@ describe('#jsonStore', () => { const config = { file: 'foo', default: { foo: 'defaultbar' } } it("doesn't throw error", () => { - const mod: StorageHelper = proxyquire('../../lib/jsonStore.ts', { - jsonfile: { - readFile: sinon.stub().rejects(Error('FOO')), + const mod: StorageHelper = proxyquire( + '../../api/lib/jsonStore.ts', + { + jsonfile: { + readFile: sinon.stub().rejects(Error('FOO')), + }, }, - }).default + ).default return expect(mod['_getFile'](config)).to.not.be.rejected }) @@ -28,11 +31,14 @@ describe('#jsonStore', () => { file: 'foo', data: { bar: 'mybar', a: 'a', b: 'c' }, } - const mod: StorageHelper = proxyquire('../../lib/jsonStore.ts', { - jsonfile: { - readFile: sinon.stub().resolves(toReturn.data), + const mod: StorageHelper = proxyquire( + '../../api/lib/jsonStore.ts', + { + jsonfile: { + readFile: sinon.stub().resolves(toReturn.data), + }, }, - }).default + ).default return expect(mod['_getFile'](config)).to.eventually.deep.equal({ file: toReturn.file, @@ -41,11 +47,14 @@ describe('#jsonStore', () => { }) it('no data, return default', () => { - const mod: StorageHelper = proxyquire('../../lib/jsonStore.ts', { - jsonfile: { - readFile: sinon.stub().resolves(null), + const mod: StorageHelper = proxyquire( + '../../api/lib/jsonStore.ts', + { + jsonfile: { + readFile: sinon.stub().resolves(null), + }, }, - }).default + ).default return expect(mod['_getFile'](config)).to.eventually.deep.equal({ file: 'foo', data: config.default, @@ -53,11 +62,14 @@ describe('#jsonStore', () => { }) it('file not found, return default', () => { - const mod: StorageHelper = proxyquire('../../lib/jsonStore.ts', { - jsonfile: { - readFile: sinon.stub().rejects({ code: 'ENOENT' }), + const mod: StorageHelper = proxyquire( + '../../api/lib/jsonStore.ts', + { + jsonfile: { + readFile: sinon.stub().rejects({ code: 'ENOENT' }), + }, }, - }).default + ).default return expect(mod['_getFile'](config)).to.eventually.deep.equal({ file: 'foo', data: config.default, @@ -78,7 +90,7 @@ describe('#jsonStore', () => { it('ok', async () => { const data = { foo: 'bar' } const mod: StorageHelper = proxyquire( - '../../lib/jsonStore.ts', + '../../api/lib/jsonStore.ts', { jsonfile: { readFile: sinon.stub().resolves(data), @@ -95,7 +107,7 @@ describe('#jsonStore', () => { it('error', async () => { const mod: StorageHelper = proxyquire( - '../../lib/jsonStore.ts', + '../../api/lib/jsonStore.ts', { jsonfile: { readFile: sinon.stub().rejects(Error('foo')), @@ -112,11 +124,14 @@ describe('#jsonStore', () => { }) describe('#get()', () => { - const mod: StorageHelper = proxyquire('../../lib/jsonStore.ts', { - jsonfile: { - readFile: sinon.stub().resolves('bar'), + const mod: StorageHelper = proxyquire( + '../../api/lib/jsonStore.ts', + { + jsonfile: { + readFile: sinon.stub().resolves('bar'), + }, }, - }).default + ).default beforeEach(async () => await mod.init(fakeStore)) @@ -138,7 +153,7 @@ describe('#jsonStore', () => { describe('#put()', () => { it('ok', () => { const mod: StorageHelper = proxyquire( - '../../lib/jsonStore.ts', + '../../api/lib/jsonStore.ts', { jsonfile: { writeFile: sinon.stub().resolves('bar'), @@ -152,7 +167,7 @@ describe('#jsonStore', () => { }) it('error', () => { const mod: StorageHelper = proxyquire( - '../../lib/jsonStore.ts', + '../../api/lib/jsonStore.ts', { jsonfile: { writeFile: sinon.stub().rejects(Error('foo')), diff --git a/test/lib/logger.test.ts b/test/lib/logger.test.ts index cdff66232e6..6e19dba4bb5 100644 --- a/test/lib/logger.test.ts +++ b/test/lib/logger.test.ts @@ -1,6 +1,6 @@ import { expect } from 'chai' -import * as utils from '../../lib/utils' -import { logsDir } from '../../config/app' +import * as utils from '../../api/lib/utils' +import { logsDir } from '../../api/config/app' import { customTransports, defaultLogFile, @@ -8,7 +8,7 @@ import { sanitizedConfig, module, setupAll, -} from '../../lib/logger' +} from '../../api/lib/logger' import winston from 'winston' function checkConfigDefaults(mod, cfg) { diff --git a/test/lib/utils.test.ts b/test/lib/utils.test.ts index 48dd08761a8..a5b8892f629 100644 --- a/test/lib/utils.test.ts +++ b/test/lib/utils.test.ts @@ -6,15 +6,15 @@ import sinon, { SinonStub } from 'sinon' chai.use(require('sinon-chai')) declare let process: NodeJS.Process & { - pkg: boolean + pkg?: boolean } const snapshotPath = '/snapshot/zui' describe('#utils', () => { describe('#getPath()', () => { - const utils = proxyquire('../../lib/utils', { - 'app-root-path': { - toString: () => snapshotPath, + const utils = proxyquire('../../api/lib/utils', { + path: { + resolve: () => snapshotPath, }, }) @@ -37,15 +37,12 @@ describe('#utils', () => { }) describe('#joinPath()', () => { - let path: { join: SinonStub } + let path: { join: SinonStub; resolve: () => string } let utils before(() => { - path = { join: sinon.stub() } - utils = proxyquire('../../lib/utils', { - 'app-root-path': { - toString: () => snapshotPath, - }, + path = { join: sinon.stub(), resolve: () => snapshotPath } + utils = proxyquire('../../api/lib/utils', { path: path, }) }) diff --git a/tsconfig.json b/tsconfig.json index c7961d43c3e..f5abd286f1a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,11 +10,6 @@ "strict": false }, "include": [ - "app.ts", - "bin/www.ts", - "config/*.ts", - "hass/*.ts", - "lib/*.ts", - "types/*.ts" + "api/**/*.ts", ], } diff --git a/yarn.lock b/yarn.lock index d97bf7b6474..d744dd256ae 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2511,13 +2511,6 @@ __metadata: languageName: node linkType: hard -"@types/app-root-path@npm:^1.2.7": - version: 1.2.7 - resolution: "@types/app-root-path@npm:1.2.7" - checksum: 288bb3af23cfa237e45d513435b4f85fb6af481065b70f5efdfe39e950de4f2b29d1fb4cdeb6773fbd247b69bc8e405dcf5a548dbe11833de3f6186570b322f7 - languageName: node - linkType: hard - "@types/archiver@npm:^5.3.4": version: 5.3.4 resolution: "@types/archiver@npm:5.3.4" @@ -3552,13 +3545,6 @@ __metadata: languageName: node linkType: hard -"app-root-path@npm:^3.1.0": - version: 3.1.0 - resolution: "app-root-path@npm:3.1.0" - checksum: e3db3957aee197143a0f6c75e39fe89b19e7244f28b4f2944f7276a9c526d2a7ab2d115b4b2d70a51a65a9a3ca17506690e5b36f75a068a7e5a13f8c092389ba - languageName: node - linkType: hard - "append-field@npm:^1.0.0": version: 1.0.0 resolution: "append-field@npm:1.0.0" @@ -3800,15 +3786,6 @@ __metadata: languageName: node linkType: hard -"axios-progress-bar@npm:^1.2.0": - version: 1.2.0 - resolution: "axios-progress-bar@npm:1.2.0" - peerDependencies: - axios: 0.x - checksum: f39ed6e6d657e80beadd536ff1fb9c38ac3e7878f8696494ba2969273cfd1cbd29904485c64f4123f8ef1b387d83e7a8ad354edfd53922d8da2e011ea1fda371 - languageName: node - linkType: hard - "axios@npm:^0.27.2": version: 0.27.2 resolution: "axios@npm:0.27.2" @@ -10111,6 +10088,13 @@ __metadata: languageName: node linkType: hard +"nprogress@npm:^0.2.0": + version: 0.2.0 + resolution: "nprogress@npm:0.2.0" + checksum: 66b7bec5d563ecf2d1c3d2815e6d5eb74ed815eee8563e0afa63d3f185ab1b9cf2ddd97e1ded263b9995c5019d26d600320e849e50f3747984daa033744619dc + languageName: node + linkType: hard + "nrf-intel-hex@npm:^1.3.0": version: 1.3.0 resolution: "nrf-intel-hex@npm:1.3.0" @@ -14386,7 +14370,6 @@ __metadata: "@mdi/js": 7.3.67 "@release-it/conventional-changelog": ^7.0.2 "@tsconfig/node18": ^18.2.2 - "@types/app-root-path": ^1.2.7 "@types/archiver": ^5.3.4 "@types/chai": ^4.3.9 "@types/chai-as-promised": ^7.1.7 @@ -14412,10 +14395,8 @@ __metadata: "@zwave-js/server": ^1.33.0 "@zwave-js/winston-daily-rotate-file": ^4.5.6-1 ansi_up: ^6.0.2 - app-root-path: ^3.1.0 archiver: ^6.0.1 axios: ^1.5.1 - axios-progress-bar: ^1.2.0 c8: ^8.0.1 chai: ^4.3.10 chai-as-promised: ^7.1.1 @@ -14458,6 +14439,7 @@ __metadata: native-url: ^0.3.4 nodemon: ^3.0.1 npm-run-all: ^4.1.5 + nprogress: ^0.2.0 pinia: ^2.1.7 prettier: ^3.0.3 prismjs: ^1.29.0