dpnishant / appmon

Documentation:
http://dpnishant.github.io/appmon
Apache License 2.0
1.56k stars 276 forks source link

How to avoid code-reuse in scripts? #36

Closed markszabo closed 6 years ago

markszabo commented 7 years ago

I'm about to develop several, very similar scripts for iOS and I would like to avoid code-reuse. Is there a way of putting commonly used functions into a separate js file (eg tools.js) and include this file in each script? I want to be able to run all scripts with -s folder but also any individual script with -s folder/script12.js.

Currently I check if the needed functions are defined and if not display a warning asking the user to also include tools.js (please run the script with the additional -s tools.js parameter), but it would be better to make it automatically.

If there is no solution right now, what came to my mind is to have an import statement in the beginning of the js files as a comment, e.g.: //import tools.js and then in appmon.py - merge_scripts() check for this line and also include the imported files to merged.js. If you think this is a good feature, I would be happy to implement it and send a PR.

Best regards, Mark

dpnishant commented 7 years ago

Thanks @markszabo

Currently the design is such that you either include/use one script at a time or a directory containing many scripts. So if you want to use a bunch of scripts but not all of them, then you copy the desired scripts into a new directory and then include that directory such that only the desired scripts are instrumented and not all of them.

I would also like to move all the duplicate code (mostly utility functions) into a single script called utilities.js (let's say).

Does that answer your question?

dpnishant commented 6 years ago

The issue was resolved with the PR.