Skip to content

Commit

Permalink
feat: add elementTemplates as default engine
Browse files Browse the repository at this point in the history
`elementTemplates` engine is by default set to `bpmn-js-elements-template` version.
This allows templates authors to indicate compatibility with specific library versions.
  • Loading branch information
nikku authored and jarekdanielak committed Dec 12, 2024
1 parent fd23850 commit 5daf175
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 9 deletions.
6 changes: 6 additions & 0 deletions karma.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* eslint-env node */

const path = require('path');

const pkg = require('./package.json');

const {
DefinePlugin,
NormalModuleReplacementPlugin
Expand Down Expand Up @@ -93,6 +96,9 @@ module.exports = function(karma) {
plugins: [
new DefinePlugin({

// @nikku needs to be defined
'process.env.PKG_VERSION': JSON.stringify(pkg.version),

// @barmac: process.env has to be defined to make @testing-library/preact work
'process.env': {}
}),
Expand Down
33 changes: 33 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"@rollup/plugin-commonjs": "^28.0.1",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.3.0",
"@rollup/plugin-replace": "^6.0.1",
"@testing-library/preact": "^2.0.1",
"@testing-library/preact-hooks": "^1.1.0",
"assert": "^2.1.0",
Expand Down
7 changes: 7 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import commonjs from '@rollup/plugin-commonjs';
import copy from 'rollup-plugin-copy';
import json from '@rollup/plugin-json';
import resolve from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';

import {
readFileSync
Expand Down Expand Up @@ -81,6 +82,12 @@ function pgl(plugins = []) {
function corePlugins(plugins = []) {
return [
...plugins,
replace({
preventAssignment: true,
values: {
'process.env.PKG_VERSION': JSON.stringify(pkg.version)
}
}),
json(),
resolve({
mainFields: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ export default function({ templates = [] }) {
// helpers //////////////////////

function getEnginesConfig(definitions) {
const {
exporter,
exporterVersion
} = definitions;

const engines = {};

const executionPlatform = definitions.get('modeler:executionPlatform');
Expand All @@ -97,10 +92,6 @@ function getEnginesConfig(definitions) {
engines.camunda = executionPlatformVersion;
}

if (exporter === 'Camunda Modeler' && exporterVersion) {
engines.camundaDesktopModeler = exporterVersion;
}

return engines;
}

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

// eslint-disable-next-line no-undef
const packageVersion = process.env.PKG_VERSION;


/**
* Registry for element templates.
*/
Expand Down Expand Up @@ -155,6 +159,7 @@ export default class ElementTemplates {
}

setEngines(engines) {

this._engines = this._coerceEngines(engines);

this._fire('engines.changed');
Expand All @@ -169,6 +174,14 @@ export default class ElementTemplates {
*/
_coerceEngines(engines) {

// we provide <elementTemplates> engine with the current
// package version; templates may use that engine to declare
// compatibility with this library
engines = {
elementTemplates: packageVersion,
...engines
};

return reduce(engines, (validEngines, version, engine) => {

const coercedVersion = coerce(version);
Expand Down
26 changes: 26 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,9 @@ 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';

// eslint-disable-next-line no-undef
const packageVersion = process.env.PKG_VERSION;


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

Expand Down Expand Up @@ -785,6 +788,15 @@ describe('provider/cloud-element-templates - ElementTemplates', function() {

describe('getEngines', function() {

it('should provide default <elementTemplates> engine', inject(function(elementTemplates) {

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


it('should provide set engines', inject(function(elementTemplates) {

// when
Expand All @@ -795,9 +807,11 @@ describe('provider/cloud-element-templates - ElementTemplates', function() {

// then
expect(elementTemplates.getEngines()).to.eql({
'elementTemplates': packageVersion,
'camunda': '8.0.0',
'other': '100.5.0'
});

}));

});
Expand All @@ -819,6 +833,18 @@ describe('provider/cloud-element-templates - ElementTemplates', function() {
expect(spy).to.have.been.calledOnce;
}));


it('should override <elementTemplates> engine', inject(function(elementTemplates) {

// when
elementTemplates.setEngines({
elementTemplates: '1.0.0'
});

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

});


Expand Down

0 comments on commit 5daf175

Please sign in to comment.