bpmn-moddle 0.12.3 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.travis.yml +2 -5
- package/lib/simple.js +3 -2
- package/package.json +5 -5
- package/resources/bpmn/json/bpmn.json +9 -7
- package/resources/bpmn/json/bpmndi.json +1 -1
- package/resources/bpmn-io/json/bioc.json +41 -0
- package/.npmignore +0 -6
- package/test/expect.js +0 -7
- package/test/fixtures/bpmn/activity-children.bpmn +0 -23
- package/test/fixtures/bpmn/callActivity-calledElement.part.bpmn +0 -7
- package/test/fixtures/bpmn/catch-event-dataOutputAssociations.part.bpmn +0 -5
- package/test/fixtures/bpmn/category.bpmn +0 -28
- package/test/fixtures/bpmn/complex.bpmn +0 -3680
- package/test/fixtures/bpmn/conversation-children.bpmn +0 -23
- package/test/fixtures/bpmn/data-object-reference.bpmn +0 -17
- package/test/fixtures/bpmn/definitions-children.bpmn +0 -13
- package/test/fixtures/bpmn/di/bpmnDiagram-extension.part.bpmn +0 -17
- package/test/fixtures/bpmn/di/bpmnDiagram.part.bpmn +0 -12
- package/test/fixtures/bpmn/di/bpmnEdge-waypoint.part.bpmn +0 -4
- package/test/fixtures/bpmn/di/bpmnEdge.part.bpmn +0 -5
- package/test/fixtures/bpmn/di/bpmnShape.part.bpmn +0 -4
- package/test/fixtures/bpmn/di-extension.bpmn +0 -26
- package/test/fixtures/bpmn/documentation-extension-elements.bpmn +0 -15
- package/test/fixtures/bpmn/documentation.bpmn +0 -11
- package/test/fixtures/bpmn/empty-definitions-default-ns.bpmn +0 -4
- package/test/fixtures/bpmn/empty-definitions.bpmn +0 -5
- package/test/fixtures/bpmn/error/binary.png +0 -0
- package/test/fixtures/bpmn/error/categoryValue.bpmn +0 -27
- package/test/fixtures/bpmn/error/di-no-bpmn-element.bpmn +0 -13
- package/test/fixtures/bpmn/error/duplicate-ids.bpmn +0 -8
- package/test/fixtures/bpmn/error/extension-definition-missing.bpmn +0 -6
- package/test/fixtures/bpmn/error/no-xml.txt +0 -1
- package/test/fixtures/bpmn/error/undeclared-ns-child.bpmn +0 -6
- package/test/fixtures/bpmn/error/unrecognized-child.bpmn +0 -6
- package/test/fixtures/bpmn/escalation-error.bpmn +0 -6
- package/test/fixtures/bpmn/event-references.part.bpmn +0 -6
- package/test/fixtures/bpmn/extension/camunda/inputOutput-list.part.bpmn +0 -9
- package/test/fixtures/bpmn/extension/camunda/inputOutput-map.part.bpmn +0 -12
- package/test/fixtures/bpmn/extension/camunda/inputOutput-mixed.part.bpmn +0 -13
- package/test/fixtures/bpmn/extension/camunda/inputOutput-plain.part.bpmn +0 -3
- package/test/fixtures/bpmn/extension/camunda/inputOutput-script.part.bpmn +0 -9
- package/test/fixtures/bpmn/extension/camunda/inputOutput.bpmn +0 -22
- package/test/fixtures/bpmn/extension/drools.part.bpmn +0 -9
- package/test/fixtures/bpmn/extension-attributes.bpmn +0 -20
- package/test/fixtures/bpmn/extension-elements.bpmn +0 -9
- package/test/fixtures/bpmn/inputOutputSpecification-children.bpmn +0 -19
- package/test/fixtures/bpmn/interface-implementationRef.part.bpmn +0 -2
- package/test/fixtures/bpmn/itemDefinition-structureRef.part.bpmn +0 -2
- package/test/fixtures/bpmn/lane-childLaneSets.part.bpmn +0 -8
- package/test/fixtures/bpmn/lane-children.bpmn +0 -46
- package/test/fixtures/bpmn/multiInstanceLoopCharacteristics-completionCondition.part.bpmn +0 -5
- package/test/fixtures/bpmn/multiInstanceLoopCharacteristics.bpmn +0 -181
- package/test/fixtures/bpmn/operation-implementationRef.part.bpmn +0 -2
- package/test/fixtures/bpmn/operation-messageRef.bpmn +0 -12
- package/test/fixtures/bpmn/participant-interfaceRef.bpmn +0 -20
- package/test/fixtures/bpmn/potentialOwner.bpmn +0 -11
- package/test/fixtures/bpmn/process-children.bpmn +0 -24
- package/test/fixtures/bpmn/scriptTask-script.part.bpmn +0 -4
- package/test/fixtures/bpmn/sequenceFlow-conditionExpression.part.bpmn +0 -5
- package/test/fixtures/bpmn/simple-default-ns.bpmn +0 -31
- package/test/fixtures/bpmn/simple.bpmn +0 -31
- package/test/fixtures/bpmn/sub-process-flow-nodes.part.bpmn +0 -8
- package/test/fixtures/bpmn/sub-process.part.bpmn +0 -10
- package/test/fixtures/bpmn/subprocess-flow-nodes-outgoing.part.bpmn +0 -16
- package/test/fixtures/bpmn/throw-event-dataInputAssociations.part.bpmn +0 -5
- package/test/fixtures/bpmn/timerEventDefinition.part.bpmn +0 -5
- package/test/fixtures/bpmn/vendor/signavio-complex-no-extensions.bpmn +0 -2151
- package/test/fixtures/bpmn/vendor/yaoqiang-event-definitions.bpmn +0 -396
- package/test/fixtures/bpmn/vendor.xsd +0 -14
- package/test/fixtures/bpmn/xsi-type.bpmn +0 -61
- package/test/fixtures/json/model/camunda.json +0 -224
- package/test/fixtures/json/model/drools.json +0 -24
- package/test/fixtures/xsd/BPMN20.xsd +0 -39
- package/test/fixtures/xsd/Vendor.xsd +0 -14
- package/test/helper.js +0 -23
- package/test/integration/camunda/read.js +0 -203
- package/test/integration/camunda/roundtrip.js +0 -48
- package/test/integration/camunda/write.js +0 -249
- package/test/integration/misc.js +0 -107
- package/test/matchers.js +0 -19
- package/test/spec/adapter/cmof/builder.js +0 -194
- package/test/spec/adapter/cmof/generate-simple.js +0 -548
- package/test/spec/bpmn-moddle.js +0 -208
- package/test/spec/xml/edit.js +0 -76
- package/test/spec/xml/read.js +0 -986
- package/test/spec/xml/roundtrip.js +0 -497
- package/test/spec/xml/write.js +0 -927
- package/test/xml-helper.js +0 -39
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var assign = require('lodash/object/assign'),
|
|
4
|
-
isFunction = require('lodash/lang/isFunction');
|
|
5
|
-
|
|
6
|
-
var Helper = require('../../helper');
|
|
7
|
-
|
|
8
|
-
var camundaPackage = require('../../fixtures/json/model/camunda');
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
describe('bpmn-moddle - integration', function() {
|
|
12
|
-
|
|
13
|
-
describe('camunda extension', function() {
|
|
14
|
-
|
|
15
|
-
describe('write', function() {
|
|
16
|
-
|
|
17
|
-
var moddle = Helper.createModdle({ camunda: camundaPackage });
|
|
18
|
-
|
|
19
|
-
function write(element, options, callback) {
|
|
20
|
-
if (isFunction(options)) {
|
|
21
|
-
callback = options;
|
|
22
|
-
options = {};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// skip preamble for tests
|
|
26
|
-
options = assign({ preamble: false }, options);
|
|
27
|
-
|
|
28
|
-
moddle.toXML(element, options, callback);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
describe('should export camunda types', function() {
|
|
33
|
-
|
|
34
|
-
it('ServiceTaskLike', function(done) {
|
|
35
|
-
|
|
36
|
-
// given
|
|
37
|
-
var serviceTask = moddle.create('bpmn:ServiceTask', { javaDelegate: 'FOO' });
|
|
38
|
-
|
|
39
|
-
// assume
|
|
40
|
-
expect(serviceTask.$instanceOf('camunda:ServiceTaskLike')).to.be.true;
|
|
41
|
-
|
|
42
|
-
var expectedXML =
|
|
43
|
-
'<bpmn:serviceTask xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" ' +
|
|
44
|
-
'xmlns:camunda="http://activiti.org/bpmn" ' +
|
|
45
|
-
'camunda:javaDelegate="FOO" />';
|
|
46
|
-
|
|
47
|
-
// when
|
|
48
|
-
write(serviceTask, function(err, result) {
|
|
49
|
-
|
|
50
|
-
if (err) {
|
|
51
|
-
return done(err);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// then
|
|
55
|
-
expect(result).to.eql(expectedXML);
|
|
56
|
-
|
|
57
|
-
done(err);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
it('InputOutput - list', function(done) {
|
|
63
|
-
|
|
64
|
-
// given
|
|
65
|
-
var outputParameter = moddle.create('camunda:OutputParameter', {
|
|
66
|
-
name: 'var1',
|
|
67
|
-
definition: moddle.create('camunda:List', {
|
|
68
|
-
items: [
|
|
69
|
-
moddle.create('camunda:Value', { value: '${1+1}' }),
|
|
70
|
-
moddle.create('camunda:Value', { value: '${1+2}' }),
|
|
71
|
-
moddle.create('camunda:Value', { value: '${1+3}' })
|
|
72
|
-
]
|
|
73
|
-
})
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
var inputOutput = moddle.create('camunda:InputOutput', {
|
|
77
|
-
outputParameters: [ outputParameter ]
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
var expectedXML =
|
|
82
|
-
'<camunda:inputOutput xmlns:camunda="http://activiti.org/bpmn">' +
|
|
83
|
-
'<camunda:outputParameter name="var1">' +
|
|
84
|
-
'<camunda:list>' +
|
|
85
|
-
'<camunda:value>${1+1}</camunda:value>' +
|
|
86
|
-
'<camunda:value>${1+2}</camunda:value>' +
|
|
87
|
-
'<camunda:value>${1+3}</camunda:value>' +
|
|
88
|
-
'</camunda:list>' +
|
|
89
|
-
'</camunda:outputParameter>' +
|
|
90
|
-
'</camunda:inputOutput>';
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
// when
|
|
94
|
-
write(inputOutput, function(err, result) {
|
|
95
|
-
|
|
96
|
-
if (err) {
|
|
97
|
-
return done(err);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// then
|
|
101
|
-
expect(result).to.eql(expectedXML);
|
|
102
|
-
|
|
103
|
-
done(err);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
it('InputOutput - map', function(done) {
|
|
109
|
-
|
|
110
|
-
// given
|
|
111
|
-
var inputParameter = moddle.create('camunda:InputParameter', {
|
|
112
|
-
name: 'var1',
|
|
113
|
-
definition: moddle.create('camunda:Map', {
|
|
114
|
-
entries: [
|
|
115
|
-
moddle.create('camunda:Entry', {
|
|
116
|
-
key: 'a',
|
|
117
|
-
value: moddle.create('camunda:List', {
|
|
118
|
-
items: [
|
|
119
|
-
moddle.create('camunda:Value', { value: 'stringInListNestedInMap' }),
|
|
120
|
-
moddle.create('camunda:Value', { value: '${ \'b\' }' })
|
|
121
|
-
]
|
|
122
|
-
})
|
|
123
|
-
})
|
|
124
|
-
]
|
|
125
|
-
})
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
var inputOutput = moddle.create('camunda:InputOutput', {
|
|
129
|
-
inputParameters: [ inputParameter ]
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
var expectedXML =
|
|
134
|
-
'<camunda:inputOutput xmlns:camunda="http://activiti.org/bpmn">' +
|
|
135
|
-
'<camunda:inputParameter name="var1">' +
|
|
136
|
-
'<camunda:map>' +
|
|
137
|
-
'<camunda:entry key="a">' +
|
|
138
|
-
'<camunda:list>' +
|
|
139
|
-
'<camunda:value>stringInListNestedInMap</camunda:value>' +
|
|
140
|
-
'<camunda:value><![CDATA[${ \'b\' }]]></camunda:value>' +
|
|
141
|
-
'</camunda:list>' +
|
|
142
|
-
'</camunda:entry>' +
|
|
143
|
-
'</camunda:map>' +
|
|
144
|
-
'</camunda:inputParameter>' +
|
|
145
|
-
'</camunda:inputOutput>';
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
// when
|
|
149
|
-
write(inputOutput, function(err, result) {
|
|
150
|
-
|
|
151
|
-
if (err) {
|
|
152
|
-
return done(err);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// then
|
|
156
|
-
expect(result).to.eql(expectedXML);
|
|
157
|
-
|
|
158
|
-
done(err);
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
it('InputOutput - mixed', function(done) {
|
|
164
|
-
|
|
165
|
-
// given
|
|
166
|
-
var inputParameter = moddle.create('camunda:InputParameter', {
|
|
167
|
-
name: 'var1',
|
|
168
|
-
definition: moddle.create('camunda:List', {
|
|
169
|
-
items: [
|
|
170
|
-
moddle.create('camunda:Value', { value: 'constantStringValue' }),
|
|
171
|
-
moddle.create('camunda:Value', { value: '${ \'elValue\' }' }),
|
|
172
|
-
moddle.create('camunda:Script', { source: '\n return "scriptValue";\n ' })
|
|
173
|
-
]
|
|
174
|
-
})
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
var inputOutput = moddle.create('camunda:InputOutput', {
|
|
178
|
-
inputParameters: [ inputParameter ]
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
var expectedXML =
|
|
183
|
-
'<camunda:inputOutput xmlns:camunda="http://activiti.org/bpmn">' +
|
|
184
|
-
'<camunda:inputParameter name="var1">' +
|
|
185
|
-
'<camunda:list>' +
|
|
186
|
-
'<camunda:value>constantStringValue</camunda:value>' +
|
|
187
|
-
'<camunda:value><![CDATA[${ \'elValue\' }]]></camunda:value>' +
|
|
188
|
-
'<camunda:script><![CDATA[\n return "scriptValue";\n ]]></camunda:script>' +
|
|
189
|
-
'</camunda:list>' +
|
|
190
|
-
'</camunda:inputParameter>' +
|
|
191
|
-
'</camunda:inputOutput>';
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
// when
|
|
195
|
-
write(inputOutput, function(err, result) {
|
|
196
|
-
|
|
197
|
-
if (err) {
|
|
198
|
-
return done(err);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// then
|
|
202
|
-
expect(result).to.eql(expectedXML);
|
|
203
|
-
|
|
204
|
-
done(err);
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
it('InputOutput - plain', function(done) {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
// given
|
|
213
|
-
var inputParameter = moddle.create('camunda:InputParameter', {
|
|
214
|
-
name: 'var2',
|
|
215
|
-
value: 'stringConstantValue'
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
var inputOutput = moddle.create('camunda:InputOutput', {
|
|
219
|
-
inputParameters: [ inputParameter ]
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
var expectedXML =
|
|
224
|
-
'<camunda:inputOutput xmlns:camunda="http://activiti.org/bpmn">' +
|
|
225
|
-
'<camunda:inputParameter name="var2">stringConstantValue</camunda:inputParameter>' +
|
|
226
|
-
'</camunda:inputOutput>';
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
// when
|
|
230
|
-
write(inputOutput, function(err, result) {
|
|
231
|
-
|
|
232
|
-
if (err) {
|
|
233
|
-
return done(err);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// then
|
|
237
|
-
expect(result).to.eql(expectedXML);
|
|
238
|
-
|
|
239
|
-
done(err);
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
});
|
package/test/integration/misc.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var Helper = require('../helper');
|
|
4
|
-
|
|
5
|
-
var droolsPackage = require('../fixtures/json/model/drools');
|
|
6
|
-
|
|
7
|
-
var isFunction = require('lodash/lang/isFunction'),
|
|
8
|
-
assign = require('lodash/object/assign');
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
describe('bpmn-moddle - integration', function() {
|
|
12
|
-
|
|
13
|
-
describe('drools:import element', function() {
|
|
14
|
-
|
|
15
|
-
var moddle = Helper.createModdle({ drools: droolsPackage });
|
|
16
|
-
|
|
17
|
-
function read(xml, root, opts, callback) {
|
|
18
|
-
return moddle.fromXML(xml, root, opts, callback);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function fromFile(file, root, opts, callback) {
|
|
22
|
-
var contents = Helper.readFile('test/fixtures/bpmn/' + file);
|
|
23
|
-
return read(contents, root, opts, callback);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function write(element, options, callback) {
|
|
27
|
-
if (isFunction(options)) {
|
|
28
|
-
callback = options;
|
|
29
|
-
options = {};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// skip preamble for tests
|
|
33
|
-
options = assign({ preamble: false }, options);
|
|
34
|
-
|
|
35
|
-
moddle.toXML(element, options, callback);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
it('should import', function(done) {
|
|
40
|
-
|
|
41
|
-
// when
|
|
42
|
-
fromFile('extension/drools.part.bpmn', 'bpmn:Process', function(err, result) {
|
|
43
|
-
|
|
44
|
-
var expected = {
|
|
45
|
-
$type: 'bpmn:Process',
|
|
46
|
-
id: 'Evaluation',
|
|
47
|
-
isExecutable: false,
|
|
48
|
-
extensionElements: {
|
|
49
|
-
$type: 'bpmn:ExtensionElements',
|
|
50
|
-
values: [
|
|
51
|
-
{
|
|
52
|
-
$type: 'drools:Import',
|
|
53
|
-
name: 'com.example.model.User'
|
|
54
|
-
}
|
|
55
|
-
]
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
// then
|
|
60
|
-
expect(result).to.jsonEqual(expected);
|
|
61
|
-
|
|
62
|
-
done(err);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
it('should export', function(done) {
|
|
69
|
-
|
|
70
|
-
// given
|
|
71
|
-
var importElement = moddle.create('drools:Import', {
|
|
72
|
-
name: 'com.example.model.User'
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
var processElement = moddle.create('bpmn:Process', {
|
|
76
|
-
extensionElements: moddle.create('bpmn:ExtensionElements', {
|
|
77
|
-
values: [
|
|
78
|
-
importElement
|
|
79
|
-
]
|
|
80
|
-
})
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
var expectedXML =
|
|
84
|
-
'<bpmn:process xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" ' +
|
|
85
|
-
'xmlns:drools="http://www.jboss.org/drools">' +
|
|
86
|
-
'<bpmn:extensionElements>' +
|
|
87
|
-
'<drools:import name="com.example.model.User" />' +
|
|
88
|
-
'</bpmn:extensionElements>' +
|
|
89
|
-
'</bpmn:process>';
|
|
90
|
-
|
|
91
|
-
// when
|
|
92
|
-
write(processElement, function(err, result) {
|
|
93
|
-
|
|
94
|
-
if (err) {
|
|
95
|
-
return done(err);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// then
|
|
99
|
-
expect(result).to.eql(expectedXML);
|
|
100
|
-
|
|
101
|
-
done(err);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
});
|
package/test/matchers.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = function(chai, utils) {
|
|
4
|
-
|
|
5
|
-
utils.addMethod(chai.Assertion.prototype, 'jsonEqual', function(comparison) {
|
|
6
|
-
|
|
7
|
-
var actual = JSON.stringify(this._obj);
|
|
8
|
-
var expected = JSON.stringify(comparison);
|
|
9
|
-
|
|
10
|
-
this.assert(
|
|
11
|
-
actual == expected,
|
|
12
|
-
'expected #{this} to deep equal #{act}',
|
|
13
|
-
'expected #{this} not to deep equal #{act}',
|
|
14
|
-
comparison, // expected
|
|
15
|
-
this._obj, // actual
|
|
16
|
-
true // show diff
|
|
17
|
-
);
|
|
18
|
-
});
|
|
19
|
-
};
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var _ = require('lodash'),
|
|
4
|
-
fs = require('fs'),
|
|
5
|
-
path = require('path');
|
|
6
|
-
|
|
7
|
-
var CmofParser = require('cmof-parser');
|
|
8
|
-
|
|
9
|
-
var Helper = require('../../../helper');
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function Builder() {
|
|
13
|
-
|
|
14
|
-
var desc;
|
|
15
|
-
|
|
16
|
-
var hooks = {
|
|
17
|
-
'preSerialize': []
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
function getPackage() {
|
|
21
|
-
var elementsById = desc.byId;
|
|
22
|
-
return elementsById['_0'];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function findProperty(properties, name) {
|
|
26
|
-
var property = _.find(properties, function(d) {
|
|
27
|
-
return d.name === name;
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
return property && {
|
|
31
|
-
property: property,
|
|
32
|
-
idx: properties.indexOf(property)
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function reorderProperties(desc, propertyNames) {
|
|
37
|
-
var properties = desc.properties;
|
|
38
|
-
|
|
39
|
-
var last;
|
|
40
|
-
|
|
41
|
-
_.forEach(propertyNames, function(name) {
|
|
42
|
-
|
|
43
|
-
var descriptor = findProperty(properties, name);
|
|
44
|
-
|
|
45
|
-
if (!descriptor) {
|
|
46
|
-
throw new Error('property <' + name + '> does not exist');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (last) {
|
|
50
|
-
// remove from old position
|
|
51
|
-
properties.splice(descriptor.idx, 1);
|
|
52
|
-
|
|
53
|
-
// update descriptor position
|
|
54
|
-
descriptor.idx = last.idx + 1;
|
|
55
|
-
|
|
56
|
-
// add at new position
|
|
57
|
-
properties.splice(descriptor.idx, 0, descriptor.property);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
last = descriptor;
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function swapProperties(desc, prop1, prop2) {
|
|
65
|
-
var props = desc.properties;
|
|
66
|
-
|
|
67
|
-
function findProperty(name) {
|
|
68
|
-
return _.find(props, function(d) {
|
|
69
|
-
return d.name === name;
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
var p1 = findProperty(prop1);
|
|
74
|
-
var p2 = findProperty(prop2);
|
|
75
|
-
|
|
76
|
-
var idx1 = props.indexOf(p1);
|
|
77
|
-
var idx2 = props.indexOf(p2);
|
|
78
|
-
|
|
79
|
-
props[idx1] = p2;
|
|
80
|
-
props[idx2] = p1;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function exportTo(file) {
|
|
84
|
-
|
|
85
|
-
var pkg = getPackage();
|
|
86
|
-
|
|
87
|
-
var str = JSON.stringify(pkg, null, ' ');
|
|
88
|
-
|
|
89
|
-
_.forEach(hooks.preSerialize, function(fn) {
|
|
90
|
-
str = fn(str);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
fs.writeFileSync(file, str);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function preSerialize(fn) {
|
|
97
|
-
hooks.preSerialize.push(fn);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function rename(oldType, newType) {
|
|
101
|
-
preSerialize(function(str) {
|
|
102
|
-
return str.replace(new RegExp(oldType, 'g'), newType);
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function alter(elementName, extension) {
|
|
107
|
-
|
|
108
|
-
var elementParts = elementName.split('#');
|
|
109
|
-
|
|
110
|
-
var elementsById = desc.byId;
|
|
111
|
-
|
|
112
|
-
var element = elementsById[elementParts[0]];
|
|
113
|
-
|
|
114
|
-
if (!element) {
|
|
115
|
-
throw new Error('[transform] element <' + elementParts[0] + '> does not exist');
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (elementParts[1]) {
|
|
119
|
-
var property = _.find(element.properties, function(p) {
|
|
120
|
-
return p.name === elementParts[1];
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
if (!property) {
|
|
124
|
-
throw new Error('[transform] property <' + elementParts[0] + '#' + elementParts[1] + '> does not exist');
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (_.isFunction(extension)) {
|
|
128
|
-
extension.call(element, property);
|
|
129
|
-
} else {
|
|
130
|
-
_.extend(property, extension);
|
|
131
|
-
}
|
|
132
|
-
} else {
|
|
133
|
-
if (_.isFunction(extension)) {
|
|
134
|
-
extension.call(element, element);
|
|
135
|
-
} else {
|
|
136
|
-
_.extend(element, extension);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function cleanIDs() {
|
|
142
|
-
|
|
143
|
-
preSerialize(function(str) {
|
|
144
|
-
|
|
145
|
-
// remove "id": "Something" lines
|
|
146
|
-
return str.replace(/,\n\s+"id": "[^"]+"/g, '');
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function cleanAssociations() {
|
|
151
|
-
|
|
152
|
-
preSerialize(function(str) {
|
|
153
|
-
|
|
154
|
-
// remove "association": "Something" lines
|
|
155
|
-
return str.replace(/,\n\s+"association": "[^"]+"/g, '');
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function parse(file, postParse, done) {
|
|
160
|
-
|
|
161
|
-
new CmofParser({ clean: true }).parseFile(file, function(err, _desc) {
|
|
162
|
-
if (err) {
|
|
163
|
-
done(err);
|
|
164
|
-
} else {
|
|
165
|
-
desc = _desc;
|
|
166
|
-
|
|
167
|
-
try {
|
|
168
|
-
postParse(getPackage(), desc);
|
|
169
|
-
done(null);
|
|
170
|
-
} catch (e) {
|
|
171
|
-
done(e);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function write(dest) {
|
|
178
|
-
var dir = path.dirname(dest);
|
|
179
|
-
Helper.ensureDirExists(dir);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
this.parse = parse;
|
|
183
|
-
this.alter = alter;
|
|
184
|
-
this.rename = rename;
|
|
185
|
-
this.reorderProperties = reorderProperties;
|
|
186
|
-
this.swapProperties = swapProperties;
|
|
187
|
-
|
|
188
|
-
this.cleanIDs = cleanIDs;
|
|
189
|
-
this.cleanAssociations = cleanAssociations;
|
|
190
|
-
|
|
191
|
-
this.exportTo = exportTo;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
module.exports = Builder;
|