Skip to content

Commit 76193b1

Browse files
Merge pull request #324 from MagicMirrorOrg/develop
2 parents 4a0714d + 52de5c6 commit 76193b1

File tree

18 files changed

+242
-19
lines changed

18 files changed

+242
-19
lines changed

.vuepress/config.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,23 @@ export default {
6767
text: "Module Development",
6868
collapsible: true,
6969
children: [
70-
"/development/introduction.md",
71-
"/development/core-module-file.md",
72-
"/development/node-helper.md",
73-
"/development/helper-methods.md",
74-
"/development/logger.md",
75-
"/development/notifications.md",
76-
"/development/weather-provider.md",
77-
"/development/documentation.md",
70+
"/module-development/introduction.md",
71+
"/module-development/core-module-file.md",
72+
"/module-development/node-helper.md",
73+
"/module-development/helper-methods.md",
74+
"/module-development/logger.md",
75+
"/module-development/notifications.md",
76+
"/module-development/weather-provider.md",
77+
"/module-development/documentation.md",
78+
],
79+
},
80+
{
81+
text: "Core Development",
82+
collapsible: true,
83+
children: [
84+
"/core-development/introduction.md",
85+
"/core-development/testing.md",
86+
"/core-development/debugging.md",
7887
],
7988
},
8089
{

.vuepress/enhanceApp.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default ({ router }) => {
2+
router.addRoutes([
3+
{ path: '/development/introduction.html', redirect: '/module-development/introduction.html' },
4+
{ path: '/development/core-module-file.html', redirect: '/module-development/core-module-file.html' },
5+
{ path: '/development/node-helper.html', redirect: '/module-development/node-helper.html' },
6+
{ path: '/development/helper-methods.html', redirect: '/module-development/helper-methods.html' },
7+
{ path: '/development/logger.html', redirect: '/module-development/logger.html' },
8+
{ path: '/development/notifications.html', redirect: '/module-development/notifications.html' },
9+
{ path: '/development/weather-provider.html', redirect: '/module-development/weather-provider.html' },
10+
{ path: '/development/documentation.html', redirect: '/module-development/documentation.html' }
11+
])
12+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Introduction
33
---
44

5-
![MagicMirror²: The open source modular smart mirror platform. ](./.vuepress/public/header.png)
5+
![MagicMirror²: The open source modular smart mirror platform. ](/header.png)
66

77
<p style="text-align: center">
88
<a href="https://choosealicense.com/licenses/mit">

core-development/debugging.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
---
2+
title: Debugging
3+
---
4+
5+
# Core Development Documentation: Debugging
6+
7+
Tips and tricks for debugging MagicMirror²,
8+
9+
## Make sure dependencies are up-to-date
10+
11+
When you pull a branch, exceptions can be thrown when running MagicMirror²:
12+
13+
```
14+
App threw an error during load
15+
Error: Cannot find module 'ansis'
16+
Require stack:
17+
```
18+
19+
If this happens, make sure that dependencies have been updated to latest by
20+
executing `npm install`.
21+
22+
## Breakpoints
23+
24+
Node.js has support for
25+
[built-in breakpoints](https://nodejs.org/api/debugger.html), or
26+
[VSCode](https://code.visualstudio.com/) allows for visual breakpoints and
27+
inspecting of objects.
28+
29+
Developer consoles in browsers and the Electron app (typically CTRL+SHIFT+I to
30+
toggle open/close) can be used to set client-side breakpoints, step through
31+
scripts and inspect variables.
32+
33+
## Logging
34+
35+
While there are no log files produced by the server, info is reported in two
36+
different places:
37+
38+
- The console when running from `npm run start` or `npm run server`.
39+
- This is separated into two streams, `console.log()` is output as the
40+
`stdout` stream, and
41+
- `console.error()` is output as the `stderr` stream.
42+
- These can be redirected to files when starting the server. `>` will redirect
43+
`stdout`, and `2>` will redirect `stderr`. `2>&1` will combine both streams:
44+
`npm run start > out.log 2>&1`
45+
- The browser's developer console (typically CTRL+SHIFT+I to toggle open/close)
46+
will have output from scripts that run on the browser.
47+
48+
The [MMM-Logging](https://github.com/shbatm/MMM-Logging) module can help to
49+
gather logs and output to a file, but at a performance cost.
50+
51+
Debug logging is disabled by default, and can be very verbose. It can be enabled
52+
in the _config/config.js_ file by adding `"DEBUG"` to the `logLevel` key:
53+
54+
```js
55+
let config = {
56+
// ...
57+
logLevel: ["INFO", "LOG", "WARN", "ERROR", "DEBUG"], // Add "DEBUG" for even more logging
58+
// ...
59+
};
60+
```
61+
62+
If you are using `pm2` to launch MagicMirror², you can use the `logs` command to
63+
display lines from each of the `stderr` and `stdout` streams, but not interlaced
64+
by time:
65+
66+
```sh
67+
pm2 logs --lines=15 # will show 15 lines each from stdout and stderr
68+
```
69+
70+
There is no capability to identify the module that is producing console output.
71+
However, most browsers have the ability to filter logs by a string.
72+
73+
## Date
74+
75+
It can be very useful to set the current date to debug calendar issues. In order
76+
to do this, override `Date.now` with a lambda in _config/config.js_:
77+
78+
```js
79+
Date.now = () => new Date("2023-12-31T14:05:32").valueOf();
80+
```
81+
82+
This will cause every request for the current time to return the specified time,
83+
at least for the core and built-in modules.
84+
85+
Several tests use this to override the current time for the test. See
86+
`startApplication()` in _tests/electron/helpers/global-setup.js_ as it has a
87+
`systemDate` argument to override the system date for tests.
88+
89+
**NOTE:** Some modules may use `new Date()` to get the current date/time, though
90+
this is not recommended. If this is the case, the external module will not work
91+
correctly for date debugging.
92+
93+
## Timezone
94+
95+
The `TZ` environment variable can be used to specify a valid
96+
[canonical timezone name](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
97+
from the [tz database](https://en.wikipedia.org/wiki/Tz_database).
98+
99+
Several tests do this, such as this example in
100+
_tests/electron/helpers/global-setup.js_:
101+
102+
```js
103+
process.env.TZ = "GMT";
104+
```
105+
106+
The _package.json_ could also be modified to force a timezone for a given
107+
script, such as `start:dev`:
108+
109+
```json
110+
"start:dev": "TZ=Europe/Madrid ./node_modules/.bin/electron js/electron.js dev"
111+
```
112+
113+
Or when running from the command line (Linux example):
114+
115+
```sh
116+
TZ=Europe/Madrid npm run start:dev
117+
```

core-development/introduction.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: Introduction
3+
---
4+
5+
# Core Development Documentation
6+
7+
This documentation describes core MagicMirror² development.
8+
9+
## General
10+
11+
MagicMirror² is a community-driven development effort, and
12+
[contributions](../about/contributing.md) are welcome!
13+
14+
In general, new features and bug fixes should be tracked against an
15+
[issue in the MagicMirror repo](https://github.com/MagicMirrorOrg/MagicMirror/issues).
16+
It is always a good idea to search existing issues to see if a problem you're
17+
experiencing has already been reported, or if someone has already suggested a
18+
feature you'd like to propose. Creating or finding an issue also starts the
19+
discussion and helps build consensus around your proposed fix or feature.
20+
21+
The MagicMirror² core is
22+
[developed on GitHub](https://github.com/MagicMirrorOrg/MagicMirror/) out of the
23+
_develop_ branch. To begin developing MagicMirror² core, please fork the GitHub
24+
project and create a new branch based off of the _develop_ branch.
25+
26+
When your development is ready for review and testing, create a new _Pull
27+
Request_ targeting the _develop_ branch. The development team and other
28+
contributors will be able to review your changes and provide feedback, and the
29+
test system will run automated tests against your changes. Make sure to mention
30+
the issue(s) that your Pull Request solves.
31+
32+
## Development Environment
33+
34+
Although Node.js applications are typically platform-independent, many of the
35+
scripts created for MagicMirror² are Linux-based. While Windows/Mac development
36+
is possible, you may run into issues. (Improvements here are welcome!)
37+
38+
You will need to have [Node.js installed](https://nodejs.org/en/download). When
39+
doing Linux development, on newer distributions Node.js is available from
40+
package managers.
41+
42+
Many Node.js or experienced Javascript developers have an environment that works
43+
for them. New developers to Node.js / Electron can download
44+
[VSCode for free](https://code.visualstudio.com/download) and use many
45+
extensions available for debugging and developing Javascript.
46+
47+
Also checkout
48+
[Building Node.js Apps with VSCode](https://code.visualstudio.com/docs/nodejs/nodejs-tutorial).

core-development/testing.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: Testing
3+
---
4+
5+
# Core Development Documentation: Testing
6+
7+
Unit tests are important to ensure the quality of the project as changes occur.
8+
9+
All tests are located in the
10+
[_tests_ top-level directory](https://github.com/MagicMirrorOrg/MagicMirror/tree/master/tests).
11+
12+
## Hierarchy of Tests
13+
14+
Below the _tests_ directory are other directories that organize the tests:
15+
16+
- _configs_ - Configuration files for tests.
17+
- _e2e_ - End-to-end tests that start and run MagicMirror² in various
18+
configurations.
19+
- _electron_ - Electron application tests.
20+
- _mocks_ - Mock-up data for tests.
21+
- _unit_ - Unit tests for utilities and smaller portions of MagicMirror².
22+
- _utils_ - Testing utilities.
23+
24+
## Writing a Test
25+
26+
Almost all pull requests must have test coverage of changes. Usually, it is
27+
easier to find an existing test and extend it to test your new functionality.
28+
29+
For example, if you were writing a test for a fix in the Calendar module, you
30+
might locate _tests/e2e/modules/calendar_spec.js_ and add an additional test
31+
there.
32+
33+
If you have questions about how to write a test, you can also ask in the
34+
[MagicMirror forums](https://forum.magicmirror.builders/).
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ information in your README file.**
2121
- What external API's it depends upon, including web links to those
2222
- Whether the API/request require a key and the user limitations of those. (Is
2323
it free?)
24+
- **Do not use `new Date()` for the current timestamp, instead prefer
25+
`new Date(Date.now())` as it can be more
26+
[easily overridden for debugging](../core-development/debugging.html#Date)**.
2427

2528
Surely this also help you get better recognition and feedback for your work.
2629

0 commit comments

Comments
 (0)