@accordproject/template-engine 2.2.0 → 2.3.0
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/dist/index.d.ts +7 -77
- package/dist/index.js +38 -736
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -736
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/runtime.tgz +0 -0
package/dist/index.js
CHANGED
|
@@ -6,15 +6,13 @@ var concertoCore = require('@accordproject/concerto-core');
|
|
|
6
6
|
var dayjs = require('dayjs');
|
|
7
7
|
var utc = require('dayjs/plugin/utc');
|
|
8
8
|
var markdownCommon = require('@accordproject/markdown-common');
|
|
9
|
-
var markdownTemplate = require('@accordproject/markdown-template');
|
|
10
9
|
var vfs = require('@typescript/vfs');
|
|
11
10
|
var twoslash = require('@typescript/twoslash');
|
|
12
11
|
var concertoCodegen = require('@accordproject/concerto-codegen');
|
|
13
12
|
var concertoUtil = require('@accordproject/concerto-util');
|
|
14
|
-
var
|
|
13
|
+
var markdownTemplate = require('@accordproject/markdown-template');
|
|
15
14
|
var fs = require('fs');
|
|
16
|
-
var
|
|
17
|
-
var stream = require('stream');
|
|
15
|
+
var lzstring = require('lz-string');
|
|
18
16
|
|
|
19
17
|
function _interopNamespaceDefault(e) {
|
|
20
18
|
var n = Object.create(null);
|
|
@@ -34,7 +32,6 @@ function _interopNamespaceDefault(e) {
|
|
|
34
32
|
}
|
|
35
33
|
|
|
36
34
|
var lzstring__namespace = /*#__PURE__*/_interopNamespaceDefault(lzstring);
|
|
37
|
-
var tar__namespace = /*#__PURE__*/_interopNamespaceDefault(tar);
|
|
38
35
|
|
|
39
36
|
function booleanDrafter(value) {
|
|
40
37
|
if (value) {
|
|
@@ -221,6 +218,37 @@ const NAVIGATION_NODES = [
|
|
|
221
218
|
`${markdownCommon.TemplateMarkModel.NAMESPACE}.OptionalDefinition`,
|
|
222
219
|
`${markdownCommon.TemplateMarkModel.NAMESPACE}.ClauseDefinition`
|
|
223
220
|
];
|
|
221
|
+
|
|
222
|
+
function ensureDirSync(path) {
|
|
223
|
+
!fs.existsSync(path) && fs.mkdirSync(path, { recursive: true });
|
|
224
|
+
}
|
|
225
|
+
function removeSync(path) {
|
|
226
|
+
fs.rmSync(path, { recursive: true, force: true });
|
|
227
|
+
}
|
|
228
|
+
function writeFunctionToString(templateClass, functionName, returnType, code) {
|
|
229
|
+
let result = "";
|
|
230
|
+
result += "/// ---cut---\n";
|
|
231
|
+
result += `export function ${functionName}(data:TemplateModel.I${templateClass.getName()}, library:any, options:GenerationOptions) : ${returnType} {
|
|
232
|
+
`;
|
|
233
|
+
result += " const now = dayjs(options?.now);\n";
|
|
234
|
+
result += " const locale = options?.locale;\n";
|
|
235
|
+
templateClass.getProperties().forEach((p) => {
|
|
236
|
+
result += ` const ${p.getName()} = data.${p.getName()};
|
|
237
|
+
`;
|
|
238
|
+
});
|
|
239
|
+
result += " " + code.trim() + "\n";
|
|
240
|
+
result += "}\n";
|
|
241
|
+
result += "\n";
|
|
242
|
+
return result;
|
|
243
|
+
}
|
|
244
|
+
function nameUserCode(templateMarkDom) {
|
|
245
|
+
return traverse(templateMarkDom).map(function(x) {
|
|
246
|
+
if (x && (x.$class === `${markdownCommon.TemplateMarkModel.NAMESPACE}.ConditionalDefinition` && x.condition || `${markdownCommon.TemplateMarkModel.NAMESPACE}.ClauseDefinition` && x.condition)) {
|
|
247
|
+
x.functionName = `condition_${this.path.join("_")}`;
|
|
248
|
+
}
|
|
249
|
+
this.update(x);
|
|
250
|
+
});
|
|
251
|
+
}
|
|
224
252
|
function getTemplateClassDeclaration(modelManager, templateConceptFqn) {
|
|
225
253
|
const introspector = new concertoCore.Introspector(modelManager);
|
|
226
254
|
try {
|
|
@@ -331,34 +359,6 @@ var CodeType = /* @__PURE__ */ ((CodeType2) => {
|
|
|
331
359
|
return CodeType2;
|
|
332
360
|
})(CodeType || {});
|
|
333
361
|
|
|
334
|
-
function ensureDirSync(path) {
|
|
335
|
-
!fs.existsSync(path) && fs.mkdirSync(path, { recursive: true });
|
|
336
|
-
}
|
|
337
|
-
function writeFunctionToString(templateClass, functionName, returnType, code) {
|
|
338
|
-
let result = "";
|
|
339
|
-
result += "/// ---cut---\n";
|
|
340
|
-
result += `export function ${functionName}(data:TemplateModel.I${templateClass.getName()}, library:any, options:GenerationOptions) : ${returnType} {
|
|
341
|
-
`;
|
|
342
|
-
result += " const now = dayjs(options?.now);\n";
|
|
343
|
-
result += " const locale = options?.locale;\n";
|
|
344
|
-
templateClass.getProperties().forEach((p) => {
|
|
345
|
-
result += ` const ${p.getName()} = data.${p.getName()};
|
|
346
|
-
`;
|
|
347
|
-
});
|
|
348
|
-
result += " " + code.trim() + "\n";
|
|
349
|
-
result += "}\n";
|
|
350
|
-
result += "\n";
|
|
351
|
-
return result;
|
|
352
|
-
}
|
|
353
|
-
function nameUserCode(templateMarkDom) {
|
|
354
|
-
return traverse(templateMarkDom).map(function(x) {
|
|
355
|
-
if (x && (x.$class === `${markdownCommon.TemplateMarkModel.NAMESPACE}.ConditionalDefinition` && x.condition || `${markdownCommon.TemplateMarkModel.NAMESPACE}.ClauseDefinition` && x.condition)) {
|
|
356
|
-
x.functionName = `condition_${this.path.join("_")}`;
|
|
357
|
-
}
|
|
358
|
-
this.update(x);
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
|
|
362
362
|
const CODE_NODES = [
|
|
363
363
|
`${markdownCommon.TemplateMarkModel.NAMESPACE}.FormulaDefinition`,
|
|
364
364
|
`${markdownCommon.TemplateMarkModel.NAMESPACE}.ConditionalDefinition`,
|
|
@@ -730,708 +730,10 @@ class TemplateMarkInterpreter {
|
|
|
730
730
|
}
|
|
731
731
|
}
|
|
732
732
|
|
|
733
|
-
function writeDebug(fw, level, concept) {
|
|
734
|
-
fw.writeLine(level, `// ${concertoCore.ModelUtil.getShortName(concept.$class)} ${concept.name ? `(${concept.name})` : ""}`);
|
|
735
|
-
}
|
|
736
|
-
const RUNTIME_DIR = "runtime";
|
|
737
|
-
function writeImports(fw, level, templateClass) {
|
|
738
|
-
fw.writeLine(level, `import * as CommonMark from './${markdownCommon.CommonMarkModel.NAMESPACE}';`);
|
|
739
|
-
fw.writeLine(level, `import * as CiceroMark from './${markdownCommon.CiceroMarkModel.NAMESPACE}';`);
|
|
740
|
-
fw.writeLine(level, `import * as TemplateModel from './${templateClass.getNamespace()}';`);
|
|
741
|
-
fw.writeLine(level, "import * as UserCode from './usercode';");
|
|
742
|
-
fw.writeLine(level, `import { getDrafter as $getDrafter } from './${RUNTIME_DIR}/drafting';`);
|
|
743
|
-
fw.writeLine(level, `import * as Runtime from './${RUNTIME_DIR}/TypeScriptRuntime';`);
|
|
744
|
-
}
|
|
745
|
-
function writeProlog(fw, level, templateClass) {
|
|
746
|
-
fw.writeLine(level, `export function generator(data:TemplateModel.I${templateClass.getName()}, library:any, options:Runtime.GenerationOptions) : CommonMark.IDocument {`);
|
|
747
|
-
fw.writeLine(level, `const docNode = {$class: '${markdownCommon.CommonMarkModel.NAMESPACE}.Document', xmlns: '${markdownCommon.CommonMarkModel.NAMESPACE}', nodes: []} as CommonMark.INode;`);
|
|
748
|
-
fw.writeLine(level, "const $nodes:CommonMark.INode[] = [];");
|
|
749
|
-
fw.writeLine(level, "const $data:any[] = [];");
|
|
750
|
-
fw.writeLine(level, "let $result:any = docNode;");
|
|
751
|
-
fw.writeLine(level, "Runtime.push($data, data);");
|
|
752
|
-
}
|
|
753
|
-
function writeEpilog(fw, level) {
|
|
754
|
-
fw.writeLine(level, "return $result as CommonMark.IDocument;");
|
|
755
|
-
fw.writeLine(level, "}");
|
|
756
|
-
}
|
|
757
|
-
function writeOpenGenerateScope(fw, level) {
|
|
758
|
-
fw.writeLine(level, "$result = (() => {");
|
|
759
|
-
}
|
|
760
|
-
function writeCloseGenerateScope(fw, level) {
|
|
761
|
-
fw.writeLine(level, "})();");
|
|
762
|
-
fw.writeLine(level, "Runtime.addChild($nodes, $result);");
|
|
763
|
-
}
|
|
764
|
-
function writeOpenNodeScope(fw, level) {
|
|
765
|
-
fw.writeLine(level, "Runtime.push($nodes, $result);");
|
|
766
|
-
}
|
|
767
|
-
function writeCloseNodeScope(fw, level) {
|
|
768
|
-
fw.writeLine(level, "$result = Runtime.pop($nodes);");
|
|
769
|
-
}
|
|
770
|
-
function writeOpenDataScope(fw, level, name, allowUndefined = false) {
|
|
771
|
-
fw.writeLine(level, `Runtime.push($data, Runtime.peekProperty($data, '${name}', ${allowUndefined}));`);
|
|
772
|
-
}
|
|
773
|
-
function writeCloseDataScope(fw, level) {
|
|
774
|
-
fw.writeLine(level, "Runtime.pop($data);");
|
|
775
|
-
}
|
|
776
|
-
function getTypeScriptType(ctoFqn) {
|
|
777
|
-
const ns = concertoCore.ModelUtil.getNamespace(ctoFqn);
|
|
778
|
-
const type = concertoCore.ModelUtil.getShortName(ctoFqn);
|
|
779
|
-
if (ns === markdownCommon.CommonMarkModel.NAMESPACE) {
|
|
780
|
-
return `CommonMark.I${type}`;
|
|
781
|
-
} else if (ns === markdownCommon.CiceroMarkModel.NAMESPACE) {
|
|
782
|
-
return `CiceroMark.I${type}`;
|
|
783
|
-
} else if (ns === markdownCommon.TemplateMarkModel.NAMESPACE) {
|
|
784
|
-
return `CiceroMark.I${type.substring(0, type.length - "Definition".length)}`;
|
|
785
|
-
} else {
|
|
786
|
-
throw new Error(`No type mapping for ${ctoFqn}`);
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
function makeCiceroMark(templateMarkNode, deep = false) {
|
|
790
|
-
if (!templateMarkNode.$class) {
|
|
791
|
-
throw new Error("Not a concerto type.");
|
|
792
|
-
}
|
|
793
|
-
const json = JSON.parse(JSON.stringify(templateMarkNode));
|
|
794
|
-
delete json.elementType;
|
|
795
|
-
if (!deep) {
|
|
796
|
-
delete json.nodes;
|
|
797
|
-
} else {
|
|
798
|
-
if (json.nodes) {
|
|
799
|
-
json.nodes = json.nodes.map((n) => makeCiceroMark(n, deep));
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
const ns = concertoCore.ModelUtil.getNamespace(json.$class);
|
|
803
|
-
const type = concertoCore.ModelUtil.getShortName(json.$class);
|
|
804
|
-
if (ns === markdownCommon.TemplateMarkModel.NAMESPACE) {
|
|
805
|
-
json.$class = `${markdownCommon.CiceroMarkModel.NAMESPACE}.${type.substring(0, type.length - "Definition".length)}`;
|
|
806
|
-
}
|
|
807
|
-
return json;
|
|
808
|
-
}
|
|
809
|
-
class AbstractComplexCompiler {
|
|
810
|
-
leaf;
|
|
811
|
-
constructor(leaf) {
|
|
812
|
-
this.leaf = leaf;
|
|
813
|
-
}
|
|
814
|
-
isLeaf() {
|
|
815
|
-
return this.leaf;
|
|
816
|
-
}
|
|
817
|
-
enter(fw, level, templateMarkNode) {
|
|
818
|
-
writeDebug(fw, level, templateMarkNode);
|
|
819
|
-
writeOpenNodeScope(fw, level);
|
|
820
|
-
}
|
|
821
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
822
|
-
exit(fw, level) {
|
|
823
|
-
writeCloseNodeScope(fw, level);
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
class AbstractSimpleCompiler extends AbstractComplexCompiler {
|
|
827
|
-
constructor(leaf) {
|
|
828
|
-
super(leaf);
|
|
829
|
-
}
|
|
830
|
-
generate(fw, level, templateMarkNode) {
|
|
831
|
-
const node = this.getNode(templateMarkNode);
|
|
832
|
-
if (this.isLeaf()) {
|
|
833
|
-
node.nodes = [];
|
|
834
|
-
}
|
|
835
|
-
writeOpenGenerateScope(fw, level);
|
|
836
|
-
fw.writeLine(level, `return ${JSON.stringify(node)} as ${getTypeScriptType(node.$class)};`);
|
|
837
|
-
writeCloseGenerateScope(fw, level);
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
class PassThrough extends AbstractSimpleCompiler {
|
|
841
|
-
constructor(leaf) {
|
|
842
|
-
super(leaf);
|
|
843
|
-
}
|
|
844
|
-
getNode(templateMarkNode) {
|
|
845
|
-
return makeCiceroMark(templateMarkNode);
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
class Ignore {
|
|
849
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
850
|
-
enter(fw, level, templateMarkNode) {
|
|
851
|
-
}
|
|
852
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
853
|
-
generate(fw, level, templateMarkNode) {
|
|
854
|
-
}
|
|
855
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
856
|
-
exit(fw, level, templateMarkNode) {
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
|
|
860
|
-
class Clause extends AbstractComplexCompiler {
|
|
861
|
-
static TYPE = `${markdownCommon.TemplateMarkModel.NAMESPACE}.ClauseDefinition`;
|
|
862
|
-
constructor() {
|
|
863
|
-
super(false);
|
|
864
|
-
}
|
|
865
|
-
enter(fw, level, templateMarkNode) {
|
|
866
|
-
writeDebug(fw, level, templateMarkNode);
|
|
867
|
-
writeOpenNodeScope(fw, level);
|
|
868
|
-
writeOpenDataScope(fw, level, templateMarkNode.name);
|
|
869
|
-
}
|
|
870
|
-
generate(fw, level, templateMarkNode) {
|
|
871
|
-
const clone = makeCiceroMark(templateMarkNode);
|
|
872
|
-
delete clone.condition;
|
|
873
|
-
delete clone.functionName;
|
|
874
|
-
const para = { $class: `${markdownCommon.CommonMarkModel.NAMESPACE}.Paragraph` };
|
|
875
|
-
writeOpenGenerateScope(fw, level);
|
|
876
|
-
if (templateMarkNode.condition) {
|
|
877
|
-
fw.writeLine(level, `const isTrue:boolean = UserCode.${templateMarkNode.functionName}(data,library,options)`);
|
|
878
|
-
} else {
|
|
879
|
-
fw.writeLine(level, "const isTrue:boolean = true;");
|
|
880
|
-
}
|
|
881
|
-
fw.writeLine(level, "if(isTrue) {");
|
|
882
|
-
fw.writeLine(level, `return ${JSON.stringify(clone)} as ${getTypeScriptType(clone.$class)};`);
|
|
883
|
-
fw.writeLine(level, "}");
|
|
884
|
-
fw.writeLine(level, "else {");
|
|
885
|
-
fw.writeLine(level, `return ${JSON.stringify(para)} as ${getTypeScriptType(para.$class)};`);
|
|
886
|
-
fw.writeLine(level, "}");
|
|
887
|
-
writeCloseGenerateScope(fw, level);
|
|
888
|
-
delete templateMarkNode.condition;
|
|
889
|
-
}
|
|
890
|
-
exit(fw, level) {
|
|
891
|
-
writeCloseDataScope(fw, level);
|
|
892
|
-
writeCloseNodeScope(fw, level);
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
class Conditional extends AbstractComplexCompiler {
|
|
897
|
-
static TYPE = `${markdownCommon.TemplateMarkModel.NAMESPACE}.ConditionalDefinition`;
|
|
898
|
-
constructor() {
|
|
899
|
-
super(false);
|
|
900
|
-
}
|
|
901
|
-
generate(fw, level, templateMarkNode) {
|
|
902
|
-
const clone = makeCiceroMark(templateMarkNode, true);
|
|
903
|
-
delete clone.condition;
|
|
904
|
-
delete clone.dependencies;
|
|
905
|
-
delete clone.functionName;
|
|
906
|
-
clone.isTrue = true;
|
|
907
|
-
writeOpenGenerateScope(fw, level);
|
|
908
|
-
if (templateMarkNode.condition) {
|
|
909
|
-
fw.writeLine(level, `const isTrue:boolean = UserCode.${templateMarkNode.functionName}(data,library,options)`);
|
|
910
|
-
} else {
|
|
911
|
-
writeOpenDataScope(fw, level, templateMarkNode.name);
|
|
912
|
-
fw.writeLine(level, "const isTrue:boolean = Runtime.peek($data);");
|
|
913
|
-
writeCloseDataScope(fw, level);
|
|
914
|
-
}
|
|
915
|
-
fw.writeLine(level, `const curNode = ${JSON.stringify(clone)} as ${getTypeScriptType(templateMarkNode.$class)};`);
|
|
916
|
-
fw.writeLine(level, "(curNode as CiceroMark.IConditional).isTrue = isTrue;");
|
|
917
|
-
fw.writeLine(level, "return curNode;");
|
|
918
|
-
writeCloseGenerateScope(fw, level);
|
|
919
|
-
delete templateMarkNode.condition;
|
|
920
|
-
delete templateMarkNode.whenTrue;
|
|
921
|
-
delete templateMarkNode.whenFalse;
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
class ContractDefinition extends AbstractSimpleCompiler {
|
|
926
|
-
static TYPE = `${markdownCommon.TemplateMarkModel.NAMESPACE}.ContractDefinition`;
|
|
927
|
-
constructor() {
|
|
928
|
-
super(false);
|
|
929
|
-
}
|
|
930
|
-
getNode(templateMarkNode) {
|
|
931
|
-
return {
|
|
932
|
-
$class: `${markdownCommon.CiceroMarkModel.NAMESPACE}.Contract`,
|
|
933
|
-
name: templateMarkNode.name,
|
|
934
|
-
nodes: []
|
|
935
|
-
};
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
class FormattedVariable extends AbstractComplexCompiler {
|
|
940
|
-
static TYPE = `${markdownCommon.TemplateMarkModel.NAMESPACE}.FormattedVariableDefinition`;
|
|
941
|
-
constructor() {
|
|
942
|
-
super(true);
|
|
943
|
-
}
|
|
944
|
-
generate(fw, level, templateMarkNode) {
|
|
945
|
-
const clone = makeCiceroMark(templateMarkNode);
|
|
946
|
-
writeOpenGenerateScope(fw, level);
|
|
947
|
-
if (templateMarkNode.name !== "this") {
|
|
948
|
-
writeOpenDataScope(fw, level, templateMarkNode.name);
|
|
949
|
-
}
|
|
950
|
-
fw.writeLine(level, `const drafter = $getDrafter('${templateMarkNode.elementType}');`);
|
|
951
|
-
fw.writeLine(level, `const text = drafter ? drafter(Runtime.peek($data), '${templateMarkNode.format}') : JSON.stringify(Runtime.peek($data)) as string;`);
|
|
952
|
-
if (templateMarkNode.name !== "this") {
|
|
953
|
-
writeCloseDataScope(fw, level);
|
|
954
|
-
}
|
|
955
|
-
fw.writeLine(level, `const variable:any = ${JSON.stringify(clone)};`);
|
|
956
|
-
fw.writeLine(level, "variable.value = text;");
|
|
957
|
-
fw.writeLine(level, `return variable as ${getTypeScriptType(clone.$class)};`);
|
|
958
|
-
writeCloseGenerateScope(fw, level);
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
class Formula extends AbstractComplexCompiler {
|
|
963
|
-
static TYPE = `${markdownCommon.TemplateMarkModel.NAMESPACE}.FormulaDefinition`;
|
|
964
|
-
constructor() {
|
|
965
|
-
super(true);
|
|
966
|
-
}
|
|
967
|
-
generate(fw, level, templateMarkNode) {
|
|
968
|
-
const clone = makeCiceroMark(templateMarkNode);
|
|
969
|
-
writeOpenGenerateScope(fw, level);
|
|
970
|
-
fw.writeLine(level, `const formulaResult = UserCode.${templateMarkNode.name}(data,library,options);`);
|
|
971
|
-
fw.writeLine(level, "const text = JSON.stringify(formulaResult);");
|
|
972
|
-
fw.writeLine(level, `const formula:any = ${JSON.stringify(clone)};`);
|
|
973
|
-
fw.writeLine(level, "formula.value = text;");
|
|
974
|
-
fw.writeLine(level, `formula.code = ${JSON.stringify(templateMarkNode.code.contents)};`);
|
|
975
|
-
fw.writeLine(level, `return formula as ${getTypeScriptType(clone.$class)};`);
|
|
976
|
-
writeCloseGenerateScope(fw, level);
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
|
|
980
|
-
class Join extends AbstractComplexCompiler {
|
|
981
|
-
static TYPE = `${markdownCommon.TemplateMarkModel.NAMESPACE}.JoinDefinition`;
|
|
982
|
-
constructor() {
|
|
983
|
-
super(true);
|
|
984
|
-
}
|
|
985
|
-
generate(fw, level, templateMarkNode) {
|
|
986
|
-
writeOpenGenerateScope(fw, level);
|
|
987
|
-
writeOpenDataScope(fw, level, templateMarkNode.name);
|
|
988
|
-
fw.writeLine(level, `const joinDef = ${JSON.stringify(templateMarkNode)};`);
|
|
989
|
-
fw.writeLine(level, "const text = Runtime.joinList(Runtime.peek($data), joinDef, options);");
|
|
990
|
-
writeCloseDataScope(fw, level);
|
|
991
|
-
fw.writeLine(level, `return { $class: '${markdownCommon.CommonMarkModel.NAMESPACE}.Text', text: text } as ${getTypeScriptType(markdownCommon.CommonMarkModel.NAMESPACE + ".Text")};`);
|
|
992
|
-
writeCloseGenerateScope(fw, level);
|
|
993
|
-
delete templateMarkNode.nodes;
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
class ListBlock extends AbstractComplexCompiler {
|
|
998
|
-
static TYPE = `${markdownCommon.TemplateMarkModel.NAMESPACE}.ListBlockDefinition`;
|
|
999
|
-
constructor() {
|
|
1000
|
-
super(false);
|
|
1001
|
-
}
|
|
1002
|
-
enter(fw, level, templateMarkNode) {
|
|
1003
|
-
writeDebug(fw, level, templateMarkNode);
|
|
1004
|
-
writeOpenNodeScope(fw, level);
|
|
1005
|
-
writeOpenDataScope(fw, level, templateMarkNode.name);
|
|
1006
|
-
}
|
|
1007
|
-
generate(fw, level, templateMarkNode, doIt) {
|
|
1008
|
-
if (templateMarkNode?.nodes?.[0]) {
|
|
1009
|
-
const clone = makeCiceroMark(templateMarkNode?.nodes?.[0]);
|
|
1010
|
-
writeOpenGenerateScope(fw, level);
|
|
1011
|
-
fw.writeLine(level, `const result = ${JSON.stringify(clone)} as ${getTypeScriptType(templateMarkNode.$class)};`);
|
|
1012
|
-
fw.writeLine(level, "Runtime.peek($data).forEach( (item:any) => {");
|
|
1013
|
-
fw.writeLine(level, "Runtime.push($data,item);");
|
|
1014
|
-
if (templateMarkNode.nodes?.[0].nodes?.[0]) {
|
|
1015
|
-
doIt(fw, level + 1, templateMarkNode.nodes[0].nodes[0]);
|
|
1016
|
-
delete templateMarkNode.nodes;
|
|
1017
|
-
}
|
|
1018
|
-
fw.writeLine(level, "Runtime.pop($data);");
|
|
1019
|
-
fw.writeLine(level, "});");
|
|
1020
|
-
fw.writeLine(level, "return result;");
|
|
1021
|
-
writeCloseGenerateScope(fw, level);
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
exit(fw, level) {
|
|
1025
|
-
writeCloseDataScope(fw, level);
|
|
1026
|
-
writeCloseNodeScope(fw, level);
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
class Optional extends AbstractComplexCompiler {
|
|
1031
|
-
static TYPE = `${markdownCommon.TemplateMarkModel.NAMESPACE}.OptionalDefinition`;
|
|
1032
|
-
constructor() {
|
|
1033
|
-
super(false);
|
|
1034
|
-
}
|
|
1035
|
-
enter(fw, level, templateMarkNode) {
|
|
1036
|
-
writeDebug(fw, level, templateMarkNode);
|
|
1037
|
-
writeOpenNodeScope(fw, level);
|
|
1038
|
-
writeOpenDataScope(fw, level, templateMarkNode.name, true);
|
|
1039
|
-
}
|
|
1040
|
-
generate(fw, level, templateMarkNode, doIt) {
|
|
1041
|
-
const clone = makeCiceroMark(templateMarkNode);
|
|
1042
|
-
delete clone.nodes;
|
|
1043
|
-
delete clone.whenSome;
|
|
1044
|
-
delete clone.whenNone;
|
|
1045
|
-
writeOpenGenerateScope(fw, level);
|
|
1046
|
-
fw.writeLine(level, `const result = ${JSON.stringify(clone)} as ${getTypeScriptType(templateMarkNode.$class)};`);
|
|
1047
|
-
fw.writeLine(level, "const hasSome:boolean = !(Runtime.peek($data) === null || Runtime.peek($data) === undefined);");
|
|
1048
|
-
fw.writeLine(level, "(result as CiceroMark.IOptional).hasSome = hasSome;");
|
|
1049
|
-
fw.writeLine(level, "if(hasSome) {");
|
|
1050
|
-
doIt(fw, level + 1, { $class: `${markdownCommon.CommonMarkModel.NAMESPACE}.Paragraph`, nodes: templateMarkNode.whenSome });
|
|
1051
|
-
fw.writeLine(level, "(result as CiceroMark.IOptional).whenSome = $result.nodes[0];");
|
|
1052
|
-
fw.writeLine(level, "(result as CiceroMark.IOptional).whenNone = $result.nodes[0];");
|
|
1053
|
-
fw.writeLine(level, "return result;");
|
|
1054
|
-
fw.writeLine(level, "}");
|
|
1055
|
-
fw.writeLine(level, "else {");
|
|
1056
|
-
doIt(fw, level + 1, { $class: `${markdownCommon.CommonMarkModel.NAMESPACE}.Paragraph`, nodes: templateMarkNode.whenNone });
|
|
1057
|
-
fw.writeLine(level, "(result as CiceroMark.IOptional).whenNone = $result.nodes[0];");
|
|
1058
|
-
fw.writeLine(level, "(result as CiceroMark.IOptional).whenSome = $result.nodes[0];");
|
|
1059
|
-
fw.writeLine(level, "return result;");
|
|
1060
|
-
fw.writeLine(level, "}");
|
|
1061
|
-
writeCloseGenerateScope(fw, level);
|
|
1062
|
-
delete templateMarkNode.nodes;
|
|
1063
|
-
delete templateMarkNode.whenSome;
|
|
1064
|
-
delete templateMarkNode.whenNone;
|
|
1065
|
-
}
|
|
1066
|
-
exit(fw, level) {
|
|
1067
|
-
writeCloseDataScope(fw, level);
|
|
1068
|
-
writeCloseNodeScope(fw, level);
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
|
|
1072
|
-
class Variable extends AbstractComplexCompiler {
|
|
1073
|
-
static TYPE = `${markdownCommon.TemplateMarkModel.NAMESPACE}.VariableDefinition`;
|
|
1074
|
-
constructor() {
|
|
1075
|
-
super(true);
|
|
1076
|
-
}
|
|
1077
|
-
generate(fw, level, templateMarkNode) {
|
|
1078
|
-
const clone = makeCiceroMark(templateMarkNode);
|
|
1079
|
-
writeOpenGenerateScope(fw, level);
|
|
1080
|
-
if (templateMarkNode.name !== "this") {
|
|
1081
|
-
writeOpenDataScope(fw, level, templateMarkNode.name);
|
|
1082
|
-
}
|
|
1083
|
-
fw.writeLine(level, "const text = JSON.stringify(Runtime.peek($data)) as string;");
|
|
1084
|
-
if (templateMarkNode.name !== "this") {
|
|
1085
|
-
writeCloseDataScope(fw, level);
|
|
1086
|
-
}
|
|
1087
|
-
fw.writeLine(level, `const variable:any = ${JSON.stringify(clone)};`);
|
|
1088
|
-
fw.writeLine(level, "variable.value = text;");
|
|
1089
|
-
fw.writeLine(level, `return variable as ${getTypeScriptType(clone.$class)};`);
|
|
1090
|
-
writeCloseGenerateScope(fw, level);
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1094
|
-
class With extends AbstractComplexCompiler {
|
|
1095
|
-
static TYPE = `${markdownCommon.TemplateMarkModel.NAMESPACE}.WithDefinition`;
|
|
1096
|
-
constructor() {
|
|
1097
|
-
super(false);
|
|
1098
|
-
}
|
|
1099
|
-
enter(fw, level, templateMarkNode) {
|
|
1100
|
-
writeDebug(fw, level, templateMarkNode);
|
|
1101
|
-
writeOpenDataScope(fw, level, templateMarkNode.name);
|
|
1102
|
-
}
|
|
1103
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
|
|
1104
|
-
generate(fw, level, templateMarkNode) {
|
|
1105
|
-
}
|
|
1106
|
-
exit(fw, level) {
|
|
1107
|
-
writeCloseDataScope(fw, level);
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
|
|
1111
|
-
class EnumVariable extends AbstractComplexCompiler {
|
|
1112
|
-
static TYPE = `${markdownCommon.TemplateMarkModel.NAMESPACE}.EnumVariableDefinition`;
|
|
1113
|
-
constructor() {
|
|
1114
|
-
super(true);
|
|
1115
|
-
}
|
|
1116
|
-
generate(fw, level, templateMarkNode) {
|
|
1117
|
-
const clone = makeCiceroMark(templateMarkNode);
|
|
1118
|
-
writeOpenGenerateScope(fw, level);
|
|
1119
|
-
if (templateMarkNode.name !== "this") {
|
|
1120
|
-
writeOpenDataScope(fw, level, templateMarkNode.name);
|
|
1121
|
-
}
|
|
1122
|
-
fw.writeLine(level, "const text = JSON.stringify(Runtime.peek($data)) as string;");
|
|
1123
|
-
if (templateMarkNode.name !== "this") {
|
|
1124
|
-
writeCloseDataScope(fw, level);
|
|
1125
|
-
}
|
|
1126
|
-
fw.writeLine(level, `const variable:any = ${JSON.stringify(clone)};`);
|
|
1127
|
-
fw.writeLine(level, "variable.value = text;");
|
|
1128
|
-
fw.writeLine(level, `return variable as ${getTypeScriptType(clone.$class)};`);
|
|
1129
|
-
writeCloseGenerateScope(fw, level);
|
|
1130
|
-
}
|
|
1131
|
-
}
|
|
1132
|
-
|
|
1133
|
-
const NODE_COMPILERS = {};
|
|
1134
|
-
NODE_COMPILERS[ContractDefinition.TYPE] = new ContractDefinition();
|
|
1135
|
-
NODE_COMPILERS[Variable.TYPE] = new Variable();
|
|
1136
|
-
NODE_COMPILERS[EnumVariable.TYPE] = new EnumVariable();
|
|
1137
|
-
NODE_COMPILERS[FormattedVariable.TYPE] = new FormattedVariable();
|
|
1138
|
-
NODE_COMPILERS[Formula.TYPE] = new Formula();
|
|
1139
|
-
NODE_COMPILERS[Conditional.TYPE] = new Conditional();
|
|
1140
|
-
NODE_COMPILERS[Join.TYPE] = new Join();
|
|
1141
|
-
NODE_COMPILERS[With.TYPE] = new With();
|
|
1142
|
-
NODE_COMPILERS[Clause.TYPE] = new Clause();
|
|
1143
|
-
NODE_COMPILERS[Optional.TYPE] = new Optional();
|
|
1144
|
-
NODE_COMPILERS[ListBlock.TYPE] = new ListBlock();
|
|
1145
|
-
NODE_COMPILERS[`${markdownCommon.TemplateMarkModel.NAMESPACE}.Code`] = new Ignore();
|
|
1146
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.Document`] = new Ignore();
|
|
1147
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.Paragraph`] = new PassThrough(false);
|
|
1148
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.Text`] = new PassThrough(true);
|
|
1149
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.Attribute`] = new PassThrough(false);
|
|
1150
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.TagInfo`] = new PassThrough(false);
|
|
1151
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.CodeBlock`] = new PassThrough(false);
|
|
1152
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.Code`] = new PassThrough(false);
|
|
1153
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.HtmlInline`] = new PassThrough(false);
|
|
1154
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.HtmlBlock`] = new PassThrough(false);
|
|
1155
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.Emph`] = new PassThrough(false);
|
|
1156
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.Strong`] = new PassThrough(false);
|
|
1157
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.BlockQuote`] = new PassThrough(false);
|
|
1158
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.Heading`] = new PassThrough(false);
|
|
1159
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.ThematicBreak`] = new PassThrough(false);
|
|
1160
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.Softbreak`] = new PassThrough(false);
|
|
1161
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.Linebreak`] = new PassThrough(false);
|
|
1162
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.Link`] = new PassThrough(false);
|
|
1163
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.Image`] = new PassThrough(false);
|
|
1164
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.List`] = new PassThrough(false);
|
|
1165
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.Item`] = new PassThrough(false);
|
|
1166
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.Table`] = new PassThrough(false);
|
|
1167
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.TableHead`] = new PassThrough(false);
|
|
1168
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.TableBody`] = new PassThrough(false);
|
|
1169
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.TableRow`] = new PassThrough(false);
|
|
1170
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.TableRow`] = new PassThrough(false);
|
|
1171
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.HeaderCell`] = new PassThrough(false);
|
|
1172
|
-
NODE_COMPILERS[`${markdownCommon.CommonMarkModel.NAMESPACE}.TableCell`] = new PassThrough(false);
|
|
1173
|
-
function getCompiler(fqn) {
|
|
1174
|
-
const compiler = NODE_COMPILERS[fqn];
|
|
1175
|
-
if (!compiler) {
|
|
1176
|
-
throw new Error(`No compiler found for node ${fqn}`);
|
|
1177
|
-
}
|
|
1178
|
-
return compiler;
|
|
1179
|
-
}
|
|
1180
|
-
|
|
1181
|
-
const RUNTIME_TGZ_BASE64 = "H4sIAAAAAAAAA+0dy24bydFnfUXHMJacNT18iwC1sleiaFsriTJEab22Yey2ZprkrIczk3mYZhReNsgxXxHkkCBAkFzyRoAgue9xj0GAnPMLqX7Mk8OHSEo2NlMHi9NTXV1dVVPVVd0zlouOrRRVG/dczegX79wElEqlRr2O4G+5US/Tv/Cjyv4KQHfKtVq92qht18qlO6VyvdJooDv1G+EmAZ7jYhtYsT3DIPbqdPyJ+H8/AIjKNPo7CjLT//nYIl3F1iz3zDNcbUhk19kcHyCP7Vptlv7r5Uotqf9GvULtZXMszIb/c/0XP95CH6NjTSGGQ1TkGSqxkTsgaM/CCvwRdwroc2I7mmmgilxCeYpwV9y6K+1QEmPTQ0M8RobpIs8hQENzUE/TCSLvFGK5SDOQYg4tXcOGQtBIcwdsHEFFpjReCBrmpYsBHUMHC656UUSEXUCl2APXtZrF4mg0kjFjVjbtflHnaE7x+LDV7nTbD4Bh0eHC0InjIJv80NNsmOzlGGELGFLwJbCp4xEybYT7NoF7rkkZHtkadYsF5Jg9d4RtQsmomuPa2qXnxuTlswezjiKAxLCB7u510WH3Ltrf6x52C5TI88Pzp6cX5+j53tnZXuf8sN1Fp2eoddo5ODw/PO3A1WO013mBjg47BwVEQFowDnln2XQGwKZGJUlUJrYuITEWeiZnybGIovU0BaZm9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MuZ+ZXAc4x0wH8CQd/+owj/TbQS5sx+N1v5O8C5bVOecfT46Bjl0/9v7//SyDDF5zHk0Bep2xix4EsnrDrb//87e/kXLYSuUWYH/83UwmYH/9r1XLy+++VcqNWyeL/upDF/yz+3/r5Hzn+DsmS54Dm9IotM8JacTQ1oeUA9snvuPsKvt3OT+t8znJv8Slh8TmACG0//d7ZmiyqLvgfGECYj8OM2TCjpYLEW0jhu0qJvkvUFYJCQuK7BrzOEK8sxAUgpeyGpx4TkiMSojupORRsnMtRGUV30bvj4aWpc33gQJLs0+ZpNRVFlFOmEVNn7zDq8fnTHnzUvDL/HSsWt4KvRu+iU6YG+Q0ZO/moPUkywzzt5RUp+JQ2a0IPd0spdRdBiEkmQeoV6/d6zsf1BQ1l2YP/qWaGUV97S4yVbS291HWtQtcMg+TP9Dx7XO60woxTcFEbDf8DAJ/pCITnHI7oGYeI1UwbtCTN6NpqtWjntB7LHCWZI/lbU9OsemTq51FW0dfcCuVC21iuWrnY52UFzHUg/ft/t3r+n73rmfz+Y2U7W/+vC9n6P1v/3+b5T+485se6CM5q0Sv2ra7Y2/ez1hP++c/39BRmkEEGGXyY8D/30+R/AHYAAA==";
|
|
1182
|
-
|
|
1183
|
-
class TemplateMarkToTypeScriptCompiler {
|
|
1184
|
-
modelManager;
|
|
1185
|
-
templateClass;
|
|
1186
|
-
constructor(modelManager, templateConceptFqn) {
|
|
1187
|
-
this.modelManager = modelManager;
|
|
1188
|
-
this.templateClass = getTemplateClassDeclaration(this.modelManager, templateConceptFqn);
|
|
1189
|
-
}
|
|
1190
|
-
writeFunction(fw, functionName, returnType, code) {
|
|
1191
|
-
fw.writeLine(0, writeFunctionToString(this.templateClass, functionName, returnType, code));
|
|
1192
|
-
}
|
|
1193
|
-
/**
|
|
1194
|
-
* Get a model manager with templatemark model
|
|
1195
|
-
* @param {string} outputDir the output directory
|
|
1196
|
-
* @returns {ModelManager} the model manager
|
|
1197
|
-
*/
|
|
1198
|
-
getTemplateMarkModelManager() {
|
|
1199
|
-
const modelManager = new concertoCore.ModelManager({ strict: true });
|
|
1200
|
-
modelManager.addCTOModel(markdownCommon.ConcertoMetaModel.MODEL, "concertometamodel.cto");
|
|
1201
|
-
modelManager.addCTOModel(markdownCommon.CommonMarkModel.MODEL, "commonmark.cto");
|
|
1202
|
-
modelManager.addCTOModel(markdownCommon.TemplateMarkModel.MODEL, "templatemark.cto");
|
|
1203
|
-
return modelManager;
|
|
1204
|
-
}
|
|
1205
|
-
/**
|
|
1206
|
-
* Get a model manager with templatemark model
|
|
1207
|
-
* @param {string} outputDir the output directory
|
|
1208
|
-
* @returns {ModelManager} the model manager
|
|
1209
|
-
*/
|
|
1210
|
-
getCiceroMarkModelManager() {
|
|
1211
|
-
const modelManager = new concertoCore.ModelManager({ strict: true });
|
|
1212
|
-
modelManager.addCTOModel(markdownCommon.ConcertoMetaModel.MODEL, "concertometamodel.cto");
|
|
1213
|
-
modelManager.addCTOModel(markdownCommon.CommonMarkModel.MODEL, "commonmark.cto");
|
|
1214
|
-
modelManager.addCTOModel(markdownCommon.CiceroMarkModel.MODEL, "ciceromark.cto");
|
|
1215
|
-
return modelManager;
|
|
1216
|
-
}
|
|
1217
|
-
generateTypeScript(modelManager, outputDir) {
|
|
1218
|
-
const tsVisitor = new concertoCodegen.CodeGen.TypescriptVisitor();
|
|
1219
|
-
const parameters = {
|
|
1220
|
-
fileWriter: new concertoUtil.FileWriter(outputDir)
|
|
1221
|
-
};
|
|
1222
|
-
modelManager.accept(tsVisitor, parameters);
|
|
1223
|
-
}
|
|
1224
|
-
generateSampleData(modelManager, outputDir) {
|
|
1225
|
-
const factory = new concertoCore.Factory(modelManager);
|
|
1226
|
-
const instance = factory.newResource(
|
|
1227
|
-
this.templateClass.getNamespace(),
|
|
1228
|
-
this.templateClass.getName(),
|
|
1229
|
-
this.templateClass.isIdentified() ? "sample" : void 0,
|
|
1230
|
-
{ generate: "sample", includeOptionalFields: true }
|
|
1231
|
-
);
|
|
1232
|
-
fs.writeFileSync(`${outputDir}/sample.json`, JSON.stringify(instance, null, 2));
|
|
1233
|
-
}
|
|
1234
|
-
/**
|
|
1235
|
-
* The main iteration function over templatemark. This function
|
|
1236
|
-
* looks up an INodeCompiler that can handle each templatemark node
|
|
1237
|
-
* and delegates to it for code generation.
|
|
1238
|
-
* Note that the result of code generation (a CiceroMark node) is left in
|
|
1239
|
-
* the $result global varianble.
|
|
1240
|
-
* @param {FileWriter} fw the file writer to use
|
|
1241
|
-
* @param {number} level the indentation level
|
|
1242
|
-
* @param {object} templateMark the templatemark node to iterate over
|
|
1243
|
-
*/
|
|
1244
|
-
static doIt(fw, level, templateMark) {
|
|
1245
|
-
fw.writeLine(level, `// start processing ${concertoCore.ModelUtil.getShortName(templateMark.$class)}`);
|
|
1246
|
-
traverse(templateMark).forEach(function(context) {
|
|
1247
|
-
if (typeof context === "object" && context.$class && typeof context.$class === "string") {
|
|
1248
|
-
const nodeClass = context.$class;
|
|
1249
|
-
const compiler = getCompiler(nodeClass);
|
|
1250
|
-
const sourceLevel = level + 1;
|
|
1251
|
-
this.before(() => {
|
|
1252
|
-
compiler.enter(fw, sourceLevel, context);
|
|
1253
|
-
compiler.generate(fw, sourceLevel, context, TemplateMarkToTypeScriptCompiler.doIt);
|
|
1254
|
-
});
|
|
1255
|
-
this.after(() => {
|
|
1256
|
-
compiler.exit(fw, sourceLevel, context);
|
|
1257
|
-
});
|
|
1258
|
-
}
|
|
1259
|
-
});
|
|
1260
|
-
fw.writeLine(level, `// end processing ${concertoCore.ModelUtil.getShortName(templateMark.$class)}`);
|
|
1261
|
-
}
|
|
1262
|
-
/**
|
|
1263
|
-
* Converts a TemplateMark document to typescript code that is parameterised
|
|
1264
|
-
* by the 'data' argument.
|
|
1265
|
-
*
|
|
1266
|
-
* The strategy is to traverse the template mark json, converting each node into
|
|
1267
|
-
* typescript statements that add an equivalent ciceromark node. Variables will
|
|
1268
|
-
* pull values from 'data'.
|
|
1269
|
-
*
|
|
1270
|
-
* Conditionals and formulae will call the functions produced by
|
|
1271
|
-
* compileUserCode.
|
|
1272
|
-
*
|
|
1273
|
-
* Note that code generation process is itself recursive, for example, when
|
|
1274
|
-
* a list definition node is encountered the list must be iterated over
|
|
1275
|
-
* based on a variable value coming from data, and code must be
|
|
1276
|
-
* generated to produce each list item.
|
|
1277
|
-
*
|
|
1278
|
-
* All internal variables are prefixed with '$' to ensure (?)
|
|
1279
|
-
* that they cannot collide with end user variable names.
|
|
1280
|
-
*
|
|
1281
|
-
* @param {IDocument} templateMark the TemplateMark Concerto resource
|
|
1282
|
-
* @param {string} outputDir the output directory for code
|
|
1283
|
-
*/
|
|
1284
|
-
compileGenerator(templateMark, outputDir) {
|
|
1285
|
-
const fw = new concertoUtil.FileWriter(outputDir);
|
|
1286
|
-
fw.openFile("index.ts");
|
|
1287
|
-
fw.writeLine(0, "// generated code");
|
|
1288
|
-
fw.writeLine(0, "import { readFileSync } from 'fs';");
|
|
1289
|
-
fw.writeLine(0, "import { generator } from './generator';");
|
|
1290
|
-
fw.writeLine(0, "if(process.argv.length === 3) {");
|
|
1291
|
-
fw.writeLine(1, "const result = generator( JSON.parse(readFileSync(process.argv[2], 'utf-8')), {}, {});");
|
|
1292
|
-
fw.writeLine(1, "console.log(JSON.stringify(result, null, 2));");
|
|
1293
|
-
fw.writeLine(0, "}");
|
|
1294
|
-
fw.writeLine(0, "else {");
|
|
1295
|
-
fw.writeLine(1, "console.log('First argument is path to JSON data file');");
|
|
1296
|
-
fw.writeLine(0, "}");
|
|
1297
|
-
fw.closeFile();
|
|
1298
|
-
fw.openFile("generator.ts");
|
|
1299
|
-
fw.writeLine(0, "// generated code, do not modify");
|
|
1300
|
-
fw.writeLine(0, "");
|
|
1301
|
-
fw.writeLine(0, "// IMPORTS");
|
|
1302
|
-
writeImports(fw, 0, this.templateClass);
|
|
1303
|
-
fw.writeLine(0, "");
|
|
1304
|
-
fw.writeLine(0, "// GENERATOR");
|
|
1305
|
-
writeProlog(fw, 0, this.templateClass);
|
|
1306
|
-
TemplateMarkToTypeScriptCompiler.doIt(fw, 1, templateMark);
|
|
1307
|
-
writeEpilog(fw, 0);
|
|
1308
|
-
fw.closeFile();
|
|
1309
|
-
}
|
|
1310
|
-
/**
|
|
1311
|
-
* Decompresses the base64 zipped runtime into an output folder.
|
|
1312
|
-
* @param {string} outputDir the output directory to copy the runtime to
|
|
1313
|
-
*/
|
|
1314
|
-
copyRuntime(outputDir) {
|
|
1315
|
-
ensureDirSync(`${outputDir}/${RUNTIME_DIR}`);
|
|
1316
|
-
const runtimeBuffer = Buffer.from(RUNTIME_TGZ_BASE64, "base64");
|
|
1317
|
-
const s = new stream.Readable();
|
|
1318
|
-
s.push(runtimeBuffer);
|
|
1319
|
-
s.push(null);
|
|
1320
|
-
s.pipe(
|
|
1321
|
-
tar__namespace.x({
|
|
1322
|
-
strip: 2,
|
|
1323
|
-
C: `${outputDir}/${RUNTIME_DIR}`
|
|
1324
|
-
})
|
|
1325
|
-
);
|
|
1326
|
-
}
|
|
1327
|
-
/**
|
|
1328
|
-
* Create package.json for the generated code
|
|
1329
|
-
* @param {string} outputDir the output directory to copy the runtime to
|
|
1330
|
-
*/
|
|
1331
|
-
createPackage(outputDir) {
|
|
1332
|
-
const packageJson = {
|
|
1333
|
-
"name": "generated",
|
|
1334
|
-
"version": "1.0.0",
|
|
1335
|
-
"description": "TypeScript code generated from TemplateMark",
|
|
1336
|
-
"engines": {
|
|
1337
|
-
"node": ">=14",
|
|
1338
|
-
"npm": ">=6"
|
|
1339
|
-
},
|
|
1340
|
-
"keywords": [
|
|
1341
|
-
"accord project",
|
|
1342
|
-
"template",
|
|
1343
|
-
"templatemark"
|
|
1344
|
-
],
|
|
1345
|
-
"dependencies": {
|
|
1346
|
-
"dayjs": "1.11.7",
|
|
1347
|
-
"jsonpath": "^1.1.1"
|
|
1348
|
-
},
|
|
1349
|
-
"devDependencies": {
|
|
1350
|
-
"@types/node": "^20.2.0",
|
|
1351
|
-
"ts-node": "^10.9.1",
|
|
1352
|
-
"typescript": "^5.0.2",
|
|
1353
|
-
"@types/jsonpath": "^0.2.0"
|
|
1354
|
-
},
|
|
1355
|
-
"scripts": {
|
|
1356
|
-
"start": "ts-node index.ts sample.json"
|
|
1357
|
-
}
|
|
1358
|
-
};
|
|
1359
|
-
fs.writeFileSync(`${outputDir}/package.json`, JSON.stringify(packageJson, null, 2));
|
|
1360
|
-
}
|
|
1361
|
-
compile(templateMark, outputDir, options) {
|
|
1362
|
-
ensureDirSync(outputDir);
|
|
1363
|
-
this.generateSampleData(this.modelManager, outputDir);
|
|
1364
|
-
this.generateTypeScript(this.modelManager, outputDir);
|
|
1365
|
-
this.generateTypeScript(this.getTemplateMarkModelManager(), outputDir);
|
|
1366
|
-
this.generateTypeScript(this.getCiceroMarkModelManager(), outputDir);
|
|
1367
|
-
const namedTemplateMark = nameUserCode(templateMark.toJSON ? templateMark.toJSON() : templateMark);
|
|
1368
|
-
this.compileUserCode(namedTemplateMark, outputDir);
|
|
1369
|
-
if (!options?.skipCopyRuntime) {
|
|
1370
|
-
this.copyRuntime(outputDir);
|
|
1371
|
-
}
|
|
1372
|
-
if (!options?.skipGenerator) {
|
|
1373
|
-
this.createPackage(outputDir);
|
|
1374
|
-
this.compileGenerator(namedTemplateMark, outputDir);
|
|
1375
|
-
}
|
|
1376
|
-
}
|
|
1377
|
-
compileUserCode(templateMark, outputDir) {
|
|
1378
|
-
const fw = new concertoUtil.FileWriter(outputDir);
|
|
1379
|
-
fw.openFile("usercode.ts");
|
|
1380
|
-
fw.writeLine(0, "// generated code, do not modify");
|
|
1381
|
-
fw.writeLine(0, "");
|
|
1382
|
-
fw.writeLine(0, "// IMPORTS");
|
|
1383
|
-
fw.writeLine(0, `import * as TemplateModel from './${this.templateClass.getNamespace()}';`);
|
|
1384
|
-
fw.writeLine(0, "import dayjs from 'dayjs';");
|
|
1385
|
-
fw.writeLine(0, "import jp from 'jsonpath';");
|
|
1386
|
-
fw.writeLine(0, "import {GenerationOptions} from './runtime/TypeScriptRuntime';");
|
|
1387
|
-
fw.writeLine(0, "");
|
|
1388
|
-
const templateMarkDom = templateMark;
|
|
1389
|
-
const functionNodes = traverse(templateMarkDom).reduce(function(acc, x) {
|
|
1390
|
-
if (x && x.$class === `${markdownCommon.TemplateMarkModel.NAMESPACE}.FormulaDefinition`) {
|
|
1391
|
-
acc.push({
|
|
1392
|
-
name: x.name,
|
|
1393
|
-
code: x.code
|
|
1394
|
-
});
|
|
1395
|
-
}
|
|
1396
|
-
return acc;
|
|
1397
|
-
}, []);
|
|
1398
|
-
const conditionalNodes = traverse(templateMarkDom).reduce(function(acc, x) {
|
|
1399
|
-
if (x && x.$class === `${markdownCommon.TemplateMarkModel.NAMESPACE}.ConditionalDefinition` && x.condition) {
|
|
1400
|
-
acc.push({
|
|
1401
|
-
name: x.functionName,
|
|
1402
|
-
code: x.condition
|
|
1403
|
-
});
|
|
1404
|
-
}
|
|
1405
|
-
return acc;
|
|
1406
|
-
}, []);
|
|
1407
|
-
const clauseNodes = traverse(templateMarkDom).reduce(function(acc, x) {
|
|
1408
|
-
if (x && x.$class === `${markdownCommon.TemplateMarkModel.NAMESPACE}.ClauseDefinition` && x.condition) {
|
|
1409
|
-
acc.push({
|
|
1410
|
-
name: x.functionName,
|
|
1411
|
-
code: x.condition
|
|
1412
|
-
});
|
|
1413
|
-
}
|
|
1414
|
-
return acc;
|
|
1415
|
-
}, []);
|
|
1416
|
-
fw.writeLine(0, "// FORMULAE");
|
|
1417
|
-
functionNodes.forEach((fun) => {
|
|
1418
|
-
this.writeFunction(fw, `${fun.name}`, "any", fun.code.contents);
|
|
1419
|
-
});
|
|
1420
|
-
fw.writeLine(0, "");
|
|
1421
|
-
fw.writeLine(0, "// CONDITIONALS");
|
|
1422
|
-
conditionalNodes.forEach((fun) => {
|
|
1423
|
-
this.writeFunction(fw, `${fun.name}`, "boolean", fun.code.contents);
|
|
1424
|
-
});
|
|
1425
|
-
fw.writeLine(0, "");
|
|
1426
|
-
fw.writeLine(0, "// CLAUSES");
|
|
1427
|
-
clauseNodes.forEach((fun) => {
|
|
1428
|
-
this.writeFunction(fw, `${fun.name}`, "boolean", fun.code.contents);
|
|
1429
|
-
});
|
|
1430
|
-
fw.writeLine(0, "");
|
|
1431
|
-
fw.closeFile();
|
|
1432
|
-
}
|
|
1433
|
-
}
|
|
1434
|
-
|
|
1435
733
|
exports.TemplateMarkInterpreter = TemplateMarkInterpreter;
|
|
1436
|
-
exports.
|
|
734
|
+
exports.ensureDirSync = ensureDirSync;
|
|
735
|
+
exports.getTemplateClassDeclaration = getTemplateClassDeclaration;
|
|
736
|
+
exports.nameUserCode = nameUserCode;
|
|
737
|
+
exports.removeSync = removeSync;
|
|
738
|
+
exports.writeFunctionToString = writeFunctionToString;
|
|
1437
739
|
//# sourceMappingURL=index.js.map
|