Developing the core of nRF Connect for Desktop is a bit different than developing an app for it.
As you have read in the architecture summary the
core is split up over two projects:
pc-nrfconnect-launcher
and
pc-nrfconnect-shared
.
These projects are responsible for multiple things. So there could be several motivations for working on it: Most probably you want to change the launcher or code that is common for the apps.
Besides the general prerequisites you may need some additional ones for developing the core:
Install additionally required packages for building the project on Ubuntu Linux:
apt-get install build-essential python2.7 libudev-dev libgconf-2-4
Install additionally required tools and configurations using Microsoft's
windows-build-tools
from an elevated PowerShell or CMD.exe (run as
Administrator):
npm install --global --production windows-build-tools
With macOS you already should have everything installed when you fulfill the general prerequisites.
The project depends on pc-ble-driver-js and pc-nrfjprog-js which are native modules. Pre-compiled binaries for these modules are provided for recent Node.js versions on Windows, macOS, and Linux. However, if binaries do not exist for your platform/Node.js version, then refer to the pc-ble-driver-js README which describes requirements for compilation.
Fetch the source from
https://github.com/NordicSemiconductor/pc-nrfconnect-launcher
and like on most Node.js projects, you need to install the dependencies once at
the beginning with npm install
and only need to repeat that later if the
dependencies change.
Start the continuous compilation by running:
npm run watch
This will transpile and bundle all code into the dist
directory. The process
will watch for changes to source code, and re-bundle to dist
on each change.
Now, open a separate terminal window and run:
npm run app
This will open Electron, which loads its content from dist
. This instance also
uses the apps it finds in your ~/.nrfconnect-apps
directory. Thus if you also
have a binary installation of nRF Connect for Desktop or
develop local apps, the same apps will show up in this
instance too.
Developing common code in pc-nrfconnect-shared
When you are developing common code in pc-nrfconnect-shared
and you want to
check the changes quickly in the launcher or an app the steps above are not
sufficient, because by default the launcher will include a released version of
pc-nrfconnect-shared
from GitHub, not your local one. But with some additional
effort you can achieve this by leveraging
npm-link
:
- Have both,
pc-nrfconnect-launcher
andpc-nrfconnect-shared
checked out into directories next to each other. - In the directory
pc-nrfconnect-launcher
run
npm install; npm link ../pc-nrfconnect-shared
- In the directory
pc-nrfconnect-shared
run
npm ci --prod
With this setup, you can make changes in pc-nrfconnect-shared
, then recompile
pc-nrfconnect-launcher
(pc-nrfconnect-shared
does not need to be compiled),
and immediately see the effects of the changes in pc-nrfconnect-shared
.
Usually the best setup is again to use npm run dev
in
pc-nrfconnect-launcher
, as described above in
“Running the launcher from source”.
If you forget to run npm ci --prod
in pc-nrfconnect-shared
, you may get
errors because of conflicting package versions, especially of react
and
react-redux
.
If you later run npm install
in the directory pc-nrfconnect-launcher
(e.g.
because you install additional packages), the link to pc-nrfconnect-shared
often gets lost. In that case you usually have to repeat running
npm link ../pc-nrfconnect-shared
in the directory pc-nrfconnect-launcher
and
then npm ci --prod
in the directory pc-nrfconnect-shared
.
If you later run npm install
in the directory pc-nrfconnect-shared
(e.g.
because you install additional packages there), you may need to repeat running
npm ci --prod
in that directory.
Because npm ci --prod
does not install the development dependencies, you
cannot run the tests successfully in pc-nrfconnect-shared
at that moment.
Before you want to run the tests again, execute npm ci
and you will also have
the development dependencies installed again.
Relevant scripts for different testing needs:
npm run check
: Run static checks on the sourcenpm test
: Run the unit tests oncenpm run test-e2e
: The launcher additionally included end-to-end tests
During development the React DevTools and the Redux DevTools are really handy. The easiest way to install them is to run
npm run install-devtools
when you have the source of the core checked out as described above. You only need to run this command once, the tools will stay installed in subsequent runs of Electron.
If you want to remove all dev tools later run
npm run remove-devtools