Archi Forum

Archi Plug-ins => jArchi => Topic started by: Phil Beauvoir on February 19, 2024, 11:43:37 AM

Title: jArchi 1.6
Post by: Phil Beauvoir on February 19, 2024, 11:43:37 AM
Hello jArchi scripters!

jArchi 1.6 is available at the usual outlets.

This version includes support for Node.js modules (thanks to @Jean-Baptiste Sarrodie for that), some fixes and a few new features.

Please note that this version requires Archi 5.2 or later.

Change log - https://github.com/archimatetool/archi-scripting-plugin/wiki/Change-Log

Cheers,

Phil
Title: Re: jArchi 1.6
Post by: Alexis_H on February 20, 2024, 06:57:09 AM
Many Thanks Phil !

Very good enhancements : Node.js support should help a lot to integrate third party JS libs (eg : a unit-testing fwk for QA checks on the model, I was digging in Jasmine code to make it run outside of a browser or Node.js context.. no more headache now).
+ the line-width/color I was missing to port a 'Heatmap' jArchi script.

Alexis.

Title: Re: jArchi 1.6
Post by: Jean-Baptiste Sarrodie on February 20, 2024, 16:26:57 PM
Hi All,

Some comments on importing Node.js modules into jArchi scripts:
- By "Node.js" modules we mean CommonJS modules. So a modules doesn't have to be specifically written for Node.js: as soon as it respects CommonJS specification, it should be usable.
- Not all modules will work within Archi because Archi doesn't implement core/native/builtin (call them whatever you want) modules. A rule of thumb: the less dependencies a module have, the higher the chance it will be usable.
- Archi doesn't come with npm, so if you want to reuse real Node.js modules, you will have either to install Node.js and npm on your workstation and make sure it downloads modules at the right place. You can also download modules manually (only doable for modules with no, or really few, dependencies)
- The wiki contains an example of a very simple module, I would encourage people to do so for scripts that serve as common libraries.

Regards,

JB
Title: Re: jArchi 1.6
Post by: Phil Beauvoir on February 20, 2024, 16:31:49 PM
Thanks JB, I added your comments to the wiki (https://github.com/archimatetool/archi-scripting-plugin/wiki/Using-Node.js-modules).
Title: Re: jArchi 1.6
Post by: fanievh on February 21, 2024, 10:22:15 AM
Thank you for the new version, @Phil Beauvoir!

I noticed a change and I'm not sure if the problem is on my side.  When running @smileham CSV import script (https://gist.github.com/smileham/1e57a5946235e780dee5a824f664aa3d) which uses Papa Parse, I get this error which I didn't get with jArchi 1.5:

> Import CSV
> Loaded Papa Parse
> Please Wait...
> File Loaded
org.graalvm.polyglot.PolyglotException: ReferenceError: "Papa" is not defined
   at <js>.:program(Import from CSV.ajs:48)
   at <js>.:program(<eval>:1)
   at org.graalvm.polyglot.Context.eval(Context.java:399)
   at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:478)
   at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:446)

Any idea what could be causing this change in behaviour?
Title: Re: jArchi 1.6
Post by: Phil Beauvoir on February 21, 2024, 11:18:35 AM
Hi, yes I get the same error.

@Jean-Baptiste Sarrodie This is caused by the new property entries to support CommonJS modules. Do you know why?

I opened an issue - https://github.com/archimatetool/archi-scripting-plugin/issues/127
Title: Re: jArchi 1.6
Post by: Phil Beauvoir on February 21, 2024, 17:00:05 PM
@fanievh Please do the following:

In your script, replace the line:

load(__DIR__ + "lib/papaparse.min.js");
with:

const Papa = require(__DIR__ + "lib/papaparse.min.js");
Title: Re: jArchi 1.6
Post by: fanievh on February 22, 2024, 06:22:57 AM
Thank you very much @Phil Beauvoir, that does the trick  :)
Title: Re: jArchi 1.6
Post by: Phil Beauvoir on February 22, 2024, 12:58:29 PM
I've released jArchi 1.6.1 (available at the usual outlets). This adds an option in Scripting Preferences to enable/disable support for CommonJS. It's enabled by default so if your script is not working you should consider if it needs to reference another file using "require" rather than "load" (see my comment above).

Phil