Open jogibear9988 opened 5 years ago
From @soef on July 14, 2017 9:28
Hi, to debug the scripts, there is a smal change in the iobroker.javascript adapter necessary. In existing function prepareScript insert this (the last line is a modified line of the existing line): var sourceFn = name; if (adapter.config.debugSourceDir) { var fn = name.replace(/^script.js./, '').replace(/./g, '/'); sourceFn = mods.path.join(adapter.config.debugSourceDir, fn + '.js'); } scripts[name] = compile(globalScript + obj.common.source, sourceFn);
To get the correct line numbers in the script to debug, you can write //!!debug in the first line of the script. Then the js2fs adapter will add the global source. To remove the global source write //!!reload in the first line. I'm using Webstorm to edit and debug.
From @Apollon77 on July 14, 2017 9:44
And you need to set adapter.config.debugSourceDir? !
And how to connect the debugger/editor to the running process?
From @Apollon77 on July 14, 2017 11:1
PS: How the adapter behave when he is started and the files on fs has changed? Will they be overwritten with the one from iobroker or what happends?
I think to install an iobroker-Slave on my development laptop, so that he is connected to iobroker master when I'm at home or at VPN. When not on VPN/Home the slave will disconnect and adapter will be stopped. But the files are still on local disk. So question is: When I change files while adapter is not running ... what happends when I come back online? :-) From code I assume that all scripts are overwritten on disk with the ones from iobroker store
From @soef on July 17, 2017 15:11
Hi, to debug, you have to debug the javascript adapter. local or connect per remote debug.
On the first start of the adapter, the adapter will extend the common section of all script objects with a mtime (timestamp) value. On the first start, all will be set the current date and time. Then there is a subscription watching all script ojects. On change from ioBroker.admin the mtime field will be modified.
On file side there is also a file watcher. If there are changes on one side the newest timestamp will win. Also deleting, renaming or creating scripts on both sides will be synced.
Just now I don't check offline scenario. Bud I think if you restart the adapter it will work.
Some words to debugging: You have to load the replicated file to set breakpoints. In the automaticly by webstorm loaded source you can step, but you can not modify oder set breakpoints. You cann also use the debugger; function from node.js
From @Apollon77 on July 11, 2017 14:21
I understand that the adapter writes als JS as files to a local directory on the iobroker host. this is cool.
How should debugging it work? How to setup?
Copied from original issue: soef/iobroker.js2fs#1