Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed

Conversation

dwinkler-oebb
Copy link

Hi @Phillipus,

This pull request is a following up my question in #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:

  • Add support for jArchi RunScriptHandler via Command
  • Add "$.fs.cleanFolder" function for cleaning a folder under the git workdirectory (e.g. "Views")

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: archimatetool/archi-modelrepository-plugin#183 and i configured ExportSVG as script name:
image

@Phillipus
Copy link
Member

@Phillipus
Copy link
Member

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

I'll close this one for now.

@Phillipus Phillipus closed this Jan 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants