@platforma-sdk/tengo-builder 2.0.3 → 2.1.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/commands/build.d.ts.map +1 -1
- package/dist/compiler/artifactset.d.ts +4 -0
- package/dist/compiler/artifactset.d.ts.map +1 -1
- package/dist/compiler/compiler.d.ts +11 -9
- package/dist/compiler/compiler.d.ts.map +1 -1
- package/dist/compiler/compileroptions.d.ts +3 -3
- package/dist/compiler/compileroptions.d.ts.map +1 -1
- package/dist/compiler/main.d.ts +4 -5
- package/dist/compiler/main.d.ts.map +1 -1
- package/dist/compiler/source.d.ts +24 -4
- package/dist/compiler/source.d.ts.map +1 -1
- package/dist/compiler/template.d.ts +17 -13
- package/dist/compiler/template.d.ts.map +1 -1
- package/dist/compiler/test.artifacts.d.ts +2 -0
- package/dist/compiler/test.artifacts.d.ts.map +1 -1
- package/dist/index.js +29 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +473 -410
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -8
- package/src/commands/build.ts +31 -27
- package/src/compiler/artifactset.ts +4 -0
- package/src/compiler/compiler.test.ts +276 -17
- package/src/compiler/compiler.ts +87 -60
- package/src/compiler/compileroptions.ts +3 -3
- package/src/compiler/main.test.ts +45 -0
- package/src/compiler/main.ts +76 -36
- package/src/compiler/source.test.ts +324 -1
- package/src/compiler/source.ts +47 -42
- package/src/compiler/template.test.ts +22 -14
- package/src/compiler/template.ts +85 -38
- package/src/compiler/test.artifacts.ts +10 -0
package/src/compiler/template.ts
CHANGED
|
@@ -7,49 +7,96 @@ import {
|
|
|
7
7
|
fullNameWithoutTypeToString,
|
|
8
8
|
parseArtefactNameAndVersion,
|
|
9
9
|
} from './package';
|
|
10
|
-
import type {
|
|
10
|
+
import type { CompiledTemplateV3 } from '@milaboratories/pl-model-backend';
|
|
11
11
|
import {
|
|
12
12
|
parseTemplate,
|
|
13
13
|
serializeTemplate,
|
|
14
14
|
} from '@milaboratories/pl-model-backend';
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
16
|
+
/** Just a holder for template data, compilation options, full name and source code.
|
|
17
|
+
* It mimics ArtifactSource interface.
|
|
18
|
+
*/
|
|
19
|
+
export type TemplateWithSource = {
|
|
20
|
+
readonly compileMode: CompileMode;
|
|
21
|
+
readonly fullName: FullArtifactName;
|
|
22
|
+
readonly source: string;
|
|
23
|
+
readonly data: CompiledTemplateV3;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export function newTemplateWithSource(
|
|
27
|
+
compileMode: CompileMode,
|
|
28
|
+
fullName: FullArtifactName,
|
|
29
|
+
data: CompiledTemplateV3,
|
|
30
|
+
source: string,
|
|
31
|
+
): TemplateWithSource {
|
|
32
|
+
validateTemplateName(fullName, data);
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
compileMode,
|
|
36
|
+
fullName,
|
|
37
|
+
data,
|
|
38
|
+
source,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type Template = {
|
|
43
|
+
readonly compileMode: CompileMode;
|
|
44
|
+
readonly fullName: FullArtifactName;
|
|
45
|
+
readonly data: CompiledTemplateV3;
|
|
46
|
+
readonly content: Uint8Array;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export function newTemplateFromData(
|
|
50
|
+
compileMode: CompileMode,
|
|
51
|
+
fullName: FullArtifactName,
|
|
52
|
+
data: CompiledTemplateV3,
|
|
53
|
+
): Template {
|
|
54
|
+
validateTemplateName(fullName, data);
|
|
55
|
+
return {
|
|
56
|
+
compileMode,
|
|
57
|
+
fullName,
|
|
58
|
+
data,
|
|
59
|
+
content: serializeTemplate(data),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
51
62
|
|
|
52
|
-
|
|
53
|
-
|
|
63
|
+
export function newTemplateFromContent(
|
|
64
|
+
compileMode: CompileMode,
|
|
65
|
+
fullName: FullArtifactName,
|
|
66
|
+
content: Uint8Array,
|
|
67
|
+
): Template {
|
|
68
|
+
const data = parseTemplate(content);
|
|
69
|
+
if (data.type !== 'pl.tengo-template.v3') {
|
|
70
|
+
throw new Error('malformed v3 template');
|
|
54
71
|
}
|
|
72
|
+
|
|
73
|
+
validateTemplateName(fullName, data);
|
|
74
|
+
return {
|
|
75
|
+
compileMode,
|
|
76
|
+
fullName,
|
|
77
|
+
data,
|
|
78
|
+
content,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function templateToSource(tpl: Template): TemplateWithSource {
|
|
83
|
+
return {
|
|
84
|
+
compileMode: tpl.compileMode,
|
|
85
|
+
fullName: tpl.fullName,
|
|
86
|
+
data: tpl.data,
|
|
87
|
+
source: tpl.data.hashToSource[tpl.data.template.sourceHash],
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function validateTemplateName(fullName: FullArtifactName, data: CompiledTemplateV3) {
|
|
91
|
+
const nameFromData: FullArtifactNameWithoutType = parseArtefactNameAndVersion(data.template);
|
|
92
|
+
|
|
93
|
+
if (
|
|
94
|
+
nameFromData.pkg !== fullName.pkg
|
|
95
|
+
|| nameFromData.id !== fullName.id
|
|
96
|
+
|| nameFromData.version !== fullName.version
|
|
97
|
+
)
|
|
98
|
+
throw new Error(
|
|
99
|
+
`Compiled template name don't match it's package and file names: `
|
|
100
|
+
+ `${fullNameWithoutTypeToString(nameFromData)} != ${fullNameWithoutTypeToString(fullName)}`,
|
|
101
|
+
);
|
|
55
102
|
}
|
|
@@ -202,6 +202,16 @@ export const testPackage1Soft1Src = `
|
|
|
202
202
|
some software contents. Template builder should pass it 'as-is'
|
|
203
203
|
`;
|
|
204
204
|
|
|
205
|
+
export const testPackage1Asset1Name: FullArtifactName = {
|
|
206
|
+
type: 'asset',
|
|
207
|
+
pkg: 'current-package',
|
|
208
|
+
id: 'asset-1',
|
|
209
|
+
version: '1.2.3',
|
|
210
|
+
};
|
|
211
|
+
export const testPackage1Asset1Src = `
|
|
212
|
+
some asset contents. Template builder should pass it 'as-is'
|
|
213
|
+
`;
|
|
214
|
+
|
|
205
215
|
export const testPackage1Lib2Name: FullArtifactName = {
|
|
206
216
|
type: 'library',
|
|
207
217
|
pkg: 'package1',
|