archimatetool / archi-scripting-plugin

jArchi - Scripting for Archi: ArchiMate Modelling Tool
https://www.archimatetool.com
118 stars 33 forks source link

coarchi integration via command + new "$.fs.cleanFolder" function #100

Closed dwinkler-oebb closed 2 years ago

dwinkler-oebb commented 2 years ago

Hi @Phillipus,

This pull request is a following up my question in archimatetool/archi-scripting-plugin#77 (comment)

Btw, I am planning to use this feature when a user publishes a Change via the "coArchi" Plugin to the git Repo. Is there some way of "event hook" for "before commit" or "after push" to hook into this workflow with a jArchi script?

Thanks in advance!

For realizing my envisioned Archi workflow it prepared this pull request since there is currently no integration of jArchi & coArchi.

This pull-request realizes the following:

As an example how i use this new integration between jArchi & coArchi is the following jArchi script ExportSVG.ajs:

/*
 * JArchi Script "Export SVG & PNG pre-commit"
 */

console.clear();
console.log("Export all views as PNG [pre-commit]...");
console.log($('archimate-diagram-model').first());

function getFolderStruct(o, delim) {
    var folder_struct = '';
    $('#'+o.id).parents().each(function(p) {
        if (p.type == 'folder') {
            folder_struct = p.name.replaceAll(" ","-") + delim + folder_struct;
        }
    });
    console.log(folder_struct);
    return folder_struct;
}

function getFolderRoot(o) {
  var svgpath = false;
  var rootpath = o.model.getPath();
  var delim = "";
  if (rootpath.indexOf("/.git/temp.archimate") !== -1) {
    delim = "/";
    svgpath = rootpath.replace("/.git/temp.archimate", "/");
  } else if (rootpath.indexOf("\\.git\\temp.archimate") !== -1) {
    delim = "\\";
    svgpath = rootpath.replace("\\.git\\temp.archimate", "\\");
  }
  return svgpath;
}

function emptyFolder() {
  var model = $('archimate-diagram-model').first();
  var root = getFolderRoot(model)
  if (root != false) {
    var delim = root.charAt(root.length-1);
    console.log("delim", delim);
    console.log("Empty folder", root);
    $.fs.cleanFolder(root + "Views")
  }
}

emptyFolder();

$('archimate-diagram-model').each(function(o) {
  console.log("Exporting " + o.name + " ...");
  var svgpath = getFolderRoot(o);
  var delim = svgpath.charAt(svgpath.length-1);
  var filepath = getFolderStruct(o, delim);
  var filename = o.name.replaceAll(" ","-");
  svgpath += filepath + filename;

  console.log(" to " + svgpath  + ".png");
  if (svgpath) {
    $.model.renderViewToSVG(o, svgpath + ".svg", true);
    $.model.renderViewToFile(o, svgpath + ".png", "PNG", {scale: 1, margin: 20});
  }
});

In my workflow I use the pre-commit coArchi integration from my pull-request: https://github.com/archimatetool/archi-modelrepository-plugin/pull/183 and i configured ExportSVG as script name: image

Phillipus commented 2 years ago

Please see https://github.com/archimatetool/archi-modelrepository-plugin/pull/183#issuecomment-992501108

Phillipus commented 2 years ago

Please see archimatetool/archi-modelrepository-plugin#183 (comment)

I'll close this one for now.