The main.js generated file is modified to allow the initialisation of the thingmodel in an exported function. The most visible changes are the builder.append converted to main.append.
Then, the terminate code is put in a function terminate() so it can be exported or called in the SIGINT handler.
The SIGINT handler is modified to check whether it can run (it can't on web browsers with browersify) and it is present only when the nodejs_package annotation is not present.
Finally, if the configuration contains the nodejs_package flag/annotation, an object is returned with an object of instances and the terminate function.
Summary of the change
The
main.js
generated file is modified to allow the initialisation of the thingmodel in an exported function. The most visible changes are thebuilder.append
converted tomain.append
.Then, the terminate code is put in a
function terminate()
so it can be exported or called in theSIGINT
handler.The
SIGINT
handler is modified to check whether it can run (it can't on web browsers with browersify) and it is present only when thenodejs_package
annotation is not present.Finally, if the configuration contains the
nodejs_package
flag/annotation, an object is returned with an object of instances and the terminate function.This should work okay.