@homebridge/plugin-ui-utils 1.0.3 → 1.0.4-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +133 -132
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -6
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +8 -11
- package/dist/server.js.map +1 -1
- package/dist/ui.d.ts.map +1 -1
- package/dist/ui.interface.d.ts +20 -20
- package/dist/ui.interface.d.ts.map +1 -1
- package/dist/ui.interface.js +1 -2
- package/dist/ui.js +32 -19
- package/dist/ui.js.map +1 -1
- package/dist/ui.mock.d.ts +5 -3
- package/dist/ui.mock.d.ts.map +1 -1
- package/dist/ui.mock.js +7 -12
- package/dist/ui.mock.js.map +1 -1
- package/package.json +32 -26
- package/CHANGELOG.md +0 -33
- package/DEVELOPMENT.md +0 -133
- package/tsconfig.ui.json +0 -13
package/DEVELOPMENT.md
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
# Homebridge Custom UI Development FAQ
|
|
2
|
-
|
|
3
|
-
## How to get started developing locally?
|
|
4
|
-
|
|
5
|
-
You're probably used to using
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
npm run watch
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
in your plugin's root directory to test functionality while iterating. In order to do something similar when working on your UI, you'll need to install homebridge-ui-config-x as a dev dependency, and then start the homebridge-config-ui-x service itself.
|
|
12
|
-
|
|
13
|
-
```
|
|
14
|
-
npm i --save-dev homebridge-config-ui-x
|
|
15
|
-
npx homebridge-config-ui-x
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
Open your browser to port 8080 (default) or the port you've specified. Your `server.js` is started when you click "Settings" in the Plugins view, and terminated when you close the view. To "refresh" the view, you only need to dismiss the model and re-open.
|
|
19
|
-
|
|
20
|
-
## How to prevent asset caching during development?
|
|
21
|
-
|
|
22
|
-
1. Open DevTools
|
|
23
|
-
2. Go to the "Network" tab
|
|
24
|
-
3. Check the "Disable Cache" checkbox at the top
|
|
25
|
-
|
|
26
|
-
Caching will now be disabled whenever the DevTools are open.
|
|
27
|
-
|
|
28
|
-
See https://stackoverflow.com/a/7000899.
|
|
29
|
-
|
|
30
|
-
## How to use the Angular / Vue / Webpack development server?
|
|
31
|
-
|
|
32
|
-
To facilitate streamlined development when using compiled frameworks such as Angular or Vue, the Homebridge UI allows you to load your custom user interface directly from your development server.
|
|
33
|
-
|
|
34
|
-
To do this you will need to `private` to `true` in the plugin's `package.json`.
|
|
35
|
-
|
|
36
|
-
The Homebridge UI will only allow you to load content from a development webserver with this attribute is set. This is to prevent published plugins from using the feature (either accidentally or intentionally).
|
|
37
|
-
|
|
38
|
-
You will need to remove this flag before you can publish your plugin to npm.
|
|
39
|
-
|
|
40
|
-
```json
|
|
41
|
-
{
|
|
42
|
-
"private": true,
|
|
43
|
-
"name": "homebridge-example",
|
|
44
|
-
...
|
|
45
|
-
}
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
Next, set the path to your development server in the `config.schema.json` using the `customUiDevServer` attribute:
|
|
49
|
-
|
|
50
|
-
```json
|
|
51
|
-
{
|
|
52
|
-
"pluginAlias": "homebridge-example",
|
|
53
|
-
"pluginType": "platform",
|
|
54
|
-
"customUi": true,
|
|
55
|
-
"customUiDevServer": "http://localhost:4200",
|
|
56
|
-
...
|
|
57
|
-
}
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
Finally, ensure you are starting your development server without "Live Reload" enabled.
|
|
61
|
-
|
|
62
|
-
**Angular**:
|
|
63
|
-
|
|
64
|
-
```
|
|
65
|
-
ng serve --no-live-reload
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
**Vue**, in the `vue.config.js` file:
|
|
69
|
-
|
|
70
|
-
```js
|
|
71
|
-
module: {
|
|
72
|
-
rules: [
|
|
73
|
-
{
|
|
74
|
-
test: /\.vue$/,
|
|
75
|
-
loader: 'vue-loader',
|
|
76
|
-
options: {
|
|
77
|
-
hotReload: false // disables Hot Reload
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
]
|
|
81
|
-
}
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
You will need to restart the Homebridge UI after making changes to the dev server configuration.
|
|
85
|
-
|
|
86
|
-
## How to get TypeScript types for `window.homebridge`?
|
|
87
|
-
|
|
88
|
-
Import this into your project, it will register the types for the `window.homebridge` object:
|
|
89
|
-
|
|
90
|
-
```ts
|
|
91
|
-
import '@homebridge/plugin-ui-utils/dist/ui.interface'
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
## How to test `window.homebridge` using Jest / Karma etc.?
|
|
95
|
-
|
|
96
|
-
As `window.homebridge` is injected at run time, you will need to mock the object in your tests. This package provides a class that helps you do this, `MockHomebridgePluginUi`.
|
|
97
|
-
|
|
98
|
-
:warning: Do not include `MockHomebridgePluginUi` in your production build!
|
|
99
|
-
|
|
100
|
-
Here is a simple example using Jest:
|
|
101
|
-
|
|
102
|
-
```ts
|
|
103
|
-
// example.spec.ts
|
|
104
|
-
import { MockHomebridgePluginUi } from '@homebridge/plugin-ui-utils/dist/ui.mock'
|
|
105
|
-
|
|
106
|
-
describe('TestCustomUi', () => {
|
|
107
|
-
let homebridge: MockHomebridgePluginUi;
|
|
108
|
-
|
|
109
|
-
beforeEach(() => {
|
|
110
|
-
homebridge = new MockHomebridgePluginUi();
|
|
111
|
-
window.homebridge = homebridge;
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('should return the plugin config and schema when called', async () => {
|
|
115
|
-
// mock the config
|
|
116
|
-
homebridge.mockPluginConfig = [
|
|
117
|
-
{
|
|
118
|
-
platform: 'homebridge-example'
|
|
119
|
-
}
|
|
120
|
-
];
|
|
121
|
-
|
|
122
|
-
// mock the schema
|
|
123
|
-
homebridge.mockPluginSchema = {
|
|
124
|
-
pluginAlias: 'homebridge-example',
|
|
125
|
-
pluginType: 'platform'
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
expect(await window.homebridge.getPluginConfig()).toHaveLength(1);
|
|
129
|
-
expect(await window.homebridge.getPluginConfigSchema()).toHaveProperty('pluginAlias');
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
});
|
|
133
|
-
```
|