Skip to content

Commit

Permalink
feat: add elementTemplates as default engine
Browse files Browse the repository at this point in the history
  • Loading branch information
jarekdanielak committed Dec 11, 2024
1 parent 84a37a2 commit 7414cbe
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,24 @@ export default function({ templates = [] }) {

elementTemplates.set(validTemplates);

let enginesSet = false;

function setEngines(engines) {

const isEmpty = (obj) => Object.keys(obj).length === 0;
const enginesEmpty = Object.keys(engines).length === 0;

if (isEmpty(engines) || !isEmpty(elementTemplates.getEngines())) {
if (enginesEmpty || enginesSet) {
return;
}

elementTemplates.setEngines(engines);
elementTemplates.setEngines({

// Make sure not to overwrite default engines
...elementTemplates.getEngines(),
...engines
});

enginesSet = true;
}

function isUpdateAvailable(template) {
Expand Down
7 changes: 7 additions & 0 deletions src/element-templates/ElementTemplates.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
coerce
} from 'semver';

import packageInfo from 'package.json';

/**
* Registry for element templates.
*/
Expand All @@ -41,6 +43,11 @@ export default class ElementTemplates {

this._engines = this._coerceEngines(config.engines || {});

// Provide `elementTemplates` engine as current package version.
// Templates can use this to specify compatibility with the library.
const { version } = packageInfo;
this._engines.elementTemplates = version;

eventBus.on('elementTemplates.engines.changed', event => {
this.set(this._templates);
});
Expand Down
15 changes: 15 additions & 0 deletions test/spec/cloud-element-templates/ElementTemplates.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import { findExtensions, findExtension } from 'src/cloud-element-templates/Helpe
import { getLabel } from 'bpmn-js/lib/features/label-editing/LabelUtil';
import { findMessage } from 'src/cloud-element-templates/Helper';

import packageInfo from 'package.json';


describe('provider/cloud-element-templates - ElementTemplates', function() {

Expand Down Expand Up @@ -782,6 +784,19 @@ describe('provider/cloud-element-templates - ElementTemplates', function() {

});

describe('getEngines', function() {

it('should have default <elementTemplates> engine set to package version', inject(function(elementTemplates) {

// given
const { version } = packageInfo;

// then
expect(elementTemplates.getEngines()).to.have.property('elementTemplates', version);
}));

});


describe('setEngines', function() {

Expand Down

0 comments on commit 7414cbe

Please sign in to comment.