Skip to content

Commit a652a08

Browse files
committed
(fix) Add language information to metadata
Signed-off-by: Jerome Simeon <jeromesimeon@me.com>
1 parent 1226c2c commit a652a08

File tree

33 files changed

+86
-14
lines changed

33 files changed

+86
-14
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"$class":"org.accordproject.latedeliveryandpenalty.TemplateModel","clauseId":"abfb8f76-69b5-480e-a530-7f5c87779a8c","forceMajeure":true,"penaltyDuration":{"$class":"org.accordproject.time.Duration","amount":9,"unit":"days"},"penaltyPercentage":7,"capPercentage":2,"termination":{"$class":"org.accordproject.time.Duration","amount":2,"unit":"weeks"},"fractionalPart":"days"}
1+
{"$class":"org.accordproject.latedeliveryandpenalty.TemplateModel","clauseId":"8084a7b3-28bb-4b69-9f97-f966fd8572d3","forceMajeure":true,"penaltyDuration":{"$class":"org.accordproject.time.Duration","amount":9,"unit":"days"},"penaltyPercentage":7,"capPercentage":2,"termination":{"$class":"org.accordproject.time.Duration","amount":2,"unit":"weeks"},"fractionalPart":"days"}

packages/cicero-cli/test/data/latedeliveryandpenalty/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "Late Delivery and Penalty. In case of delayed delivery except for Force Majeure cases, the Seller shall pay to the Buyer for every 9 DAY of delay penalty amounting to 7% of the total value of the Equipment whose delivery has been delayed. Any fractional part of a DAY is to be considered a full DAY. The total amount of penalty shall not however, exceed 2% of the total value of the Equipment involved in late delivery. If the delay is more than 2 WEEK, the Buyer is entitled to terminate this Contract.",
55
"cicero": {
66
"template": "clause",
7+
"language": "ergo",
78
"version": "^0.4.0"
89
}
910
}

packages/cicero-core/lib/metadata.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,14 @@ class Metadata {
7777
CLAUSE: 1
7878
};
7979

80+
const languageTypes = {
81+
ERGO: 0,
82+
JAVASCRIPT: 1
83+
};
84+
8085
// Set defaults
8186
this.type = templateTypes.CONTRACT;
87+
this.language = languageTypes.ERGO;
8288
this.targetVersion = ciceroVersion;
8389

8490
if (packageJson.cicero && packageJson.cicero.template) {
@@ -94,6 +100,19 @@ class Metadata {
94100
logger.warn('No cicero template type specified. Assuming that this is a contract template');
95101
}
96102

103+
if (packageJson.cicero && packageJson.cicero.language) {
104+
if(packageJson.cicero.language !== 'ergo' &&
105+
packageJson.cicero.language !== 'javascript'){
106+
throw new Error('A cicero template language must be either "ergo" or "javascript".');
107+
}
108+
109+
if(packageJson.cicero.language === 'javascript'){
110+
this.language = templateTypes.JAVASCRIPT;
111+
}
112+
} else {
113+
logger.warn('No cicero template language specified. Assuming that this is an ergo template');
114+
}
115+
97116
if (packageJson.cicero && packageJson.cicero.version) {
98117
if(!semver.valid(semver.coerce(packageJson.cicero.version))){
99118
throw new Error('The cicero target version must be a valid semantic version (semver) number.');
@@ -141,6 +160,14 @@ class Metadata {
141160
return this.type;
142161
}
143162

163+
/**
164+
* Returns either a 0 (for an ergo template), or 1 (for a javascript template)
165+
* @returns {number} the template language
166+
*/
167+
getLanguage(){
168+
return this.language;
169+
}
170+
144171
/**
145172
* Returns the target semantic version for this template.
146173
* i.e. which version of cicero was this template built for?

packages/cicero-core/lib/template.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class Template {
6767
* @param {object} samples - the sample text for the template in different locales
6868
*/
6969
constructor(packageJson, readme, samples) {
70-
7170
this.modelManager = new ModelManager();
7271
this.scriptManager = new ScriptManager(this.modelManager);
7372
this.introspector = new Introspector(this.modelManager);
@@ -77,7 +76,6 @@ class Template {
7776
this.grammar = null;
7877
this.grammarAst = null;
7978
this.templatizedGrammar = null;
80-
this.logicboth = false;
8179
}
8280

8381
/**
@@ -901,6 +899,9 @@ class Template {
901899
if (filePath.ext.toLowerCase() === '.ergo') {
902900
logger.debug(method, 'Compiling Ergo to JavaScript ', path);
903901
// re-get the updated modelfiles from the modelmanager (includes external dependencies)
902+
if (template.getMetadata().getLanguage() === 1) {
903+
logger.warn('Template is declared as javascript, but this is an ergo template');
904+
}
904905
const newModelFiles = [];
905906
for( const mf of template.getModelManager().getModelFiles() ) {
906907
newModelFiles.push(mf.getDefinitions());

packages/cicero-core/test/data/bad-copyright-license/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.0.1",
44
"cicero": {
55
"template": "contract",
6+
"language": "javascript",
67
"version": "^0.4.0"
78
}
89
}

packages/cicero-core/test/data/bad-locale/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "\"Dan Selman\" agrees to spend 100.0 conga coins on \"swag\"",
55
"cicero": {
66
"template": "clause",
7+
"language": "javascript",
78
"version": "^0.4.0"
89
}
910
}

packages/cicero-core/test/data/bad-logic/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "Late Delivery and Penalty. In case of delayed delivery except for Force Majeure cases, the Seller shall pay to the Buyer for every 9 DAY of delay penalty amounting to 7% of the total value of the Equipment whose delivery has been delayed. Any fractional part of a DAY is to be considered a full DAY. The total amount of penalty shall not however, exceed 2% of the total value of the Equipment involved in late delivery. If the delay is more than 2 WEEK, the Buyer is entitled to terminate this Contract.",
55
"cicero": {
66
"template": "clause",
7+
"language": "ergo",
78
"version": "^0.4.0"
89
}
910
}

packages/cicero-core/test/data/bad-property/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "\"Dan Selman\" agrees to spend 100.0 conga coins on \"swag\"",
55
"cicero": {
66
"template": "clause",
7+
"language": "javascript",
78
"version": "^0.4.0"
89
}
910
}

packages/cicero-core/test/data/conga/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "\"Dan Selman\" agrees to spend 100.0 conga coins on \"swag\"",
55
"cicero": {
66
"template": "clause",
7+
"language": "javascript",
78
"version": "^0.4.0"
89
}
910
}

packages/cicero-core/test/data/copyright-license/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.0.1",
44
"cicero": {
55
"template": "contract",
6+
"language": "javascript",
67
"version": "^0.4.0"
78
}
89
}

0 commit comments

Comments
 (0)