soef / iobroker.js2fs

replicate ioBroker scripts to files
MIT License
6 stars 0 forks source link

Provide more infos on debugging possibilities? #1

Open Apollon77 opened 7 years ago

Apollon77 commented 7 years ago

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?

soef commented 7 years ago

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.

Apollon77 commented 7 years ago

And you need to set adapter.config.debugSourceDir? !

And how to connect the debugger/editor to the running process?

Apollon77 commented 7 years ago

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

soef commented 7 years ago

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

jogibear9988 commented 5 years ago

This issue was moved to iobroker-community-adapters/ioBroker.js2fs-community#1