@platforma-sdk/tengo-builder 2.1.14 → 2.1.15

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.
Files changed (132) hide show
  1. package/bin/run.js +6 -0
  2. package/dist/commands/build.cjs +172 -0
  3. package/dist/commands/build.cjs.map +1 -0
  4. package/dist/commands/build.d.ts +4 -6
  5. package/dist/commands/build.js +149 -0
  6. package/dist/commands/build.js.map +1 -0
  7. package/dist/commands/check.cjs +39 -0
  8. package/dist/commands/check.cjs.map +1 -0
  9. package/dist/commands/check.d.ts +1 -3
  10. package/dist/commands/check.js +37 -0
  11. package/dist/commands/check.js.map +1 -0
  12. package/dist/commands/dump/all.cjs +20 -0
  13. package/dist/commands/dump/all.cjs.map +1 -0
  14. package/dist/commands/dump/all.d.ts +0 -1
  15. package/dist/commands/dump/all.js +18 -0
  16. package/dist/commands/dump/all.js.map +1 -0
  17. package/dist/commands/dump/assets.cjs +20 -0
  18. package/dist/commands/dump/assets.cjs.map +1 -0
  19. package/dist/commands/dump/assets.d.ts +0 -1
  20. package/dist/commands/dump/assets.js +18 -0
  21. package/dist/commands/dump/assets.js.map +1 -0
  22. package/dist/commands/dump/libs.cjs +24 -0
  23. package/dist/commands/dump/libs.cjs.map +1 -0
  24. package/dist/commands/dump/libs.d.ts +1 -3
  25. package/dist/commands/dump/libs.js +22 -0
  26. package/dist/commands/dump/libs.js.map +1 -0
  27. package/dist/commands/dump/software.cjs +20 -0
  28. package/dist/commands/dump/software.cjs.map +1 -0
  29. package/dist/commands/dump/software.d.ts +0 -1
  30. package/dist/commands/dump/software.js +18 -0
  31. package/dist/commands/dump/software.js.map +1 -0
  32. package/dist/commands/dump/templates.cjs +20 -0
  33. package/dist/commands/dump/templates.cjs.map +1 -0
  34. package/dist/commands/dump/templates.d.ts +0 -1
  35. package/dist/commands/dump/templates.js +18 -0
  36. package/dist/commands/dump/templates.js.map +1 -0
  37. package/dist/commands/dump/tests.cjs +20 -0
  38. package/dist/commands/dump/tests.cjs.map +1 -0
  39. package/dist/commands/dump/tests.d.ts +0 -1
  40. package/dist/commands/dump/tests.js +18 -0
  41. package/dist/commands/dump/tests.js.map +1 -0
  42. package/dist/commands/test.cjs +36 -0
  43. package/dist/commands/test.cjs.map +1 -0
  44. package/dist/commands/test.d.ts +1 -3
  45. package/dist/commands/test.js +34 -0
  46. package/dist/commands/test.js.map +1 -0
  47. package/dist/compiler/artifactset.cjs +75 -0
  48. package/dist/compiler/artifactset.cjs.map +1 -0
  49. package/dist/compiler/artifactset.d.ts +0 -1
  50. package/dist/compiler/artifactset.js +71 -0
  51. package/dist/compiler/artifactset.js.map +1 -0
  52. package/dist/compiler/compiler.cjs +314 -0
  53. package/dist/compiler/compiler.cjs.map +1 -0
  54. package/dist/compiler/compiler.d.ts +0 -1
  55. package/dist/compiler/compiler.js +312 -0
  56. package/dist/compiler/compiler.js.map +1 -0
  57. package/dist/compiler/compileroptions.cjs +45 -0
  58. package/dist/compiler/compileroptions.cjs.map +1 -0
  59. package/dist/compiler/compileroptions.d.ts +0 -1
  60. package/dist/compiler/compileroptions.js +41 -0
  61. package/dist/compiler/compileroptions.js.map +1 -0
  62. package/dist/compiler/main.cjs +387 -0
  63. package/dist/compiler/main.cjs.map +1 -0
  64. package/dist/compiler/main.d.ts +0 -1
  65. package/dist/compiler/main.js +359 -0
  66. package/dist/compiler/main.js.map +1 -0
  67. package/dist/compiler/package.cjs +65 -0
  68. package/dist/compiler/package.cjs.map +1 -0
  69. package/dist/compiler/package.d.ts +0 -1
  70. package/dist/compiler/package.js +55 -0
  71. package/dist/compiler/package.js.map +1 -0
  72. package/dist/compiler/source.cjs +292 -0
  73. package/dist/compiler/source.cjs.map +1 -0
  74. package/dist/compiler/source.d.ts +0 -1
  75. package/dist/compiler/source.js +285 -0
  76. package/dist/compiler/source.js.map +1 -0
  77. package/dist/compiler/template.cjs +48 -0
  78. package/dist/compiler/template.cjs.map +1 -0
  79. package/dist/compiler/template.d.ts +0 -1
  80. package/dist/compiler/template.js +44 -0
  81. package/dist/compiler/template.js.map +1 -0
  82. package/dist/compiler/test.artifacts.d.ts +0 -1
  83. package/dist/compiler/util.cjs +75 -0
  84. package/dist/compiler/util.cjs.map +1 -0
  85. package/dist/compiler/util.d.ts +0 -1
  86. package/dist/compiler/util.js +50 -0
  87. package/dist/compiler/util.js.map +1 -0
  88. package/dist/index.cjs +28 -0
  89. package/dist/index.cjs.map +1 -0
  90. package/dist/index.d.ts +0 -1
  91. package/dist/index.js +23 -41
  92. package/dist/index.js.map +1 -1
  93. package/dist/shared/basecmd.cjs +31 -0
  94. package/dist/shared/basecmd.cjs.map +1 -0
  95. package/dist/shared/basecmd.d.ts +4 -6
  96. package/dist/shared/basecmd.js +28 -0
  97. package/dist/shared/basecmd.js.map +1 -0
  98. package/dist/shared/dump.cjs +117 -0
  99. package/dist/shared/dump.cjs.map +1 -0
  100. package/dist/shared/dump.d.ts +0 -1
  101. package/dist/shared/dump.js +110 -0
  102. package/dist/shared/dump.js.map +1 -0
  103. package/dist/shared/proc.cjs +26 -0
  104. package/dist/shared/proc.cjs.map +1 -0
  105. package/dist/shared/proc.d.ts +0 -1
  106. package/dist/shared/proc.js +23 -0
  107. package/dist/shared/proc.js.map +1 -0
  108. package/package.json +13 -10
  109. package/dist/commands/build.d.ts.map +0 -1
  110. package/dist/commands/check.d.ts.map +0 -1
  111. package/dist/commands/dump/all.d.ts.map +0 -1
  112. package/dist/commands/dump/assets.d.ts.map +0 -1
  113. package/dist/commands/dump/libs.d.ts.map +0 -1
  114. package/dist/commands/dump/software.d.ts.map +0 -1
  115. package/dist/commands/dump/templates.d.ts.map +0 -1
  116. package/dist/commands/dump/tests.d.ts.map +0 -1
  117. package/dist/commands/test.d.ts.map +0 -1
  118. package/dist/compiler/artifactset.d.ts.map +0 -1
  119. package/dist/compiler/compiler.d.ts.map +0 -1
  120. package/dist/compiler/compileroptions.d.ts.map +0 -1
  121. package/dist/compiler/main.d.ts.map +0 -1
  122. package/dist/compiler/package.d.ts.map +0 -1
  123. package/dist/compiler/source.d.ts.map +0 -1
  124. package/dist/compiler/template.d.ts.map +0 -1
  125. package/dist/compiler/test.artifacts.d.ts.map +0 -1
  126. package/dist/compiler/util.d.ts.map +0 -1
  127. package/dist/index.d.ts.map +0 -1
  128. package/dist/index.mjs +0 -1198
  129. package/dist/index.mjs.map +0 -1
  130. package/dist/shared/basecmd.d.ts.map +0 -1
  131. package/dist/shared/dump.d.ts.map +0 -1
  132. package/dist/shared/proc.d.ts.map +0 -1
@@ -0,0 +1,359 @@
1
+ import * as path from 'node:path';
2
+ import * as fs from 'node:fs';
3
+ import { pathType } from './util.js';
4
+ import { TengoTemplateCompiler } from './compiler.js';
5
+ import { parseSourceFile, ArtifactSource, getSha256 } from './source.js';
6
+ import { fullNameToString, typedArtifactNameToString } from './package.js';
7
+ import { newTemplateFromContent, templateToSource } from './template.js';
8
+ import { tryResolve, tryResolveOrError } from '@milaboratories/resolve-helper';
9
+ import { serializeTemplate } from '@milaboratories/pl-model-backend';
10
+
11
+ const compiledTplSuffix = '.plj.gz';
12
+ const compiledLibSuffix = '.lib.tengo';
13
+ const compiledSoftwareSuffix = '.sw.json';
14
+ const compiledAssetSuffix = '.as.json';
15
+ // We need to keep track of dependencies for correct tgo-test CLI utility configuraiton.
16
+ // It is much simpler to do this here, than duplicate all tle logic regarding dependencies
17
+ // in go code.
18
+ const srcTestSuffix = '.test.tengo';
19
+ const srcTplSuffix = '.tpl.tengo';
20
+ const srcLibSuffix = '.lib.tengo';
21
+ const srcSoftwareSuffix = '.sw.json';
22
+ const srcAssetSuffix = '.as.json';
23
+ const compilableSuffixes = [srcLibSuffix, srcTplSuffix, srcSoftwareSuffix, srcAssetSuffix];
24
+ /**
25
+ * Resolves path to package.json file of the given dependency package.
26
+ */
27
+ function resolvePackageJsonPackage(root, depPackageName) {
28
+ if (!path.isAbsolute(root)) {
29
+ throw new Error(`Root path must be absolute: ${root}`);
30
+ }
31
+ // First approach: resolving package's main entry point and try to find package.json
32
+ // in dir tree upwards.
33
+ let resolved = tryResolve(root, depPackageName);
34
+ if (resolved) {
35
+ let depth = 0;
36
+ do {
37
+ const p = path.join(resolved, 'package.json');
38
+ if (pathType(p) === 'file')
39
+ return p;
40
+ depth++;
41
+ resolved = path.dirname(resolved);
42
+ } while (depth < 7 && path.basename(resolved) !== 'node_modules');
43
+ }
44
+ // Second approach: trying to find package.json in the package dir.
45
+ const resolved2 = tryResolveOrError(root, `${depPackageName}/package.json`);
46
+ if (resolved2.result === undefined) {
47
+ if (resolved2.err === 'ERR_PACKAGE_PATH_NOT_EXPORTED')
48
+ // tolerating not-exported package.json for dev dependencies
49
+ return undefined;
50
+ throw new Error(`Can't resolve package.json for package ${depPackageName ?? '.'} relative to ${root}`);
51
+ }
52
+ return resolved2.result;
53
+ }
54
+ function resolvePackageJsonRoot(root) {
55
+ if (!path.isAbsolute(root)) {
56
+ throw new Error(`Root path must be absolute: ${root}`);
57
+ }
58
+ const p = path.join(root, 'package.json');
59
+ if (pathType(p) === 'file')
60
+ return p;
61
+ throw new Error(`Can't resolve package.json in ${root}`);
62
+ }
63
+ /**
64
+ * Get package info from package.json and all dependencies.
65
+ */
66
+ function getPackageInfo(root, logger, context = 'root') {
67
+ const packageJsonPath = resolvePackageJsonRoot(root);
68
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString());
69
+ // resolving dependencies
70
+ const depInfos = [];
71
+ if (packageJson.dependencies && context !== 'devDependency') {
72
+ for (const dep of Object.keys(packageJson.dependencies)) {
73
+ const depPackageJson = resolvePackageJsonPackage(root, dep);
74
+ if (depPackageJson === undefined)
75
+ throw new Error(`Can't resolve package.json for dependency ${dep} of ${root}`);
76
+ const depRoot = path.dirname(depPackageJson);
77
+ depInfos.push(getPackageInfo(depRoot, logger, 'dependency'));
78
+ }
79
+ }
80
+ if (packageJson.devDependencies && context === 'root') {
81
+ for (const dep of Object.keys(packageJson.devDependencies)) {
82
+ const depPackageJson = resolvePackageJsonPackage(root, dep);
83
+ if (depPackageJson === undefined) {
84
+ logger.warn(`Can't resolve package.json for dev dependency ${dep} of ${root}`);
85
+ // tolerating not-exported package.json for dev dependencies
86
+ continue;
87
+ }
88
+ const depRoot = path.dirname(depPackageJson);
89
+ depInfos.push(getPackageInfo(depRoot, logger, 'devDependency'));
90
+ }
91
+ }
92
+ return {
93
+ name: packageJson.name,
94
+ version: packageJson.version,
95
+ type: packageJson.type,
96
+ dependencies: depInfos,
97
+ root,
98
+ context,
99
+ };
100
+ }
101
+ function resolveLibsDst(mode, root) {
102
+ return path.resolve(root, mode, 'tengo', 'lib');
103
+ }
104
+ function resolveTemplatesDst(mode, root) {
105
+ return path.resolve(root, mode, 'tengo', 'tpl');
106
+ }
107
+ function resolveSoftwareDst(mode, root) {
108
+ return path.resolve(root, mode, 'tengo', 'software');
109
+ }
110
+ function resolveAssetsDst(mode, root) {
111
+ return path.resolve(root, mode, 'tengo', 'asset');
112
+ }
113
+ function loadDependencies(logger, compiler, packageInfo) {
114
+ for (const dep of packageInfo.dependencies)
115
+ loadDependencies(logger, compiler, dep);
116
+ if (packageInfo.context === 'root')
117
+ // we are not reading compiled files for root package
118
+ return;
119
+ // we are in package folder
120
+ const libDistFolder = resolveLibsDst('dist', packageInfo.root);
121
+ const tplDistFolder = resolveTemplatesDst('dist', packageInfo.root);
122
+ const softwareDistFolder = resolveSoftwareDst('dist', packageInfo.root);
123
+ const assetDistFolder = resolveAssetsDst('dist', packageInfo.root);
124
+ const libDistExists = pathType(libDistFolder) === 'dir';
125
+ const tplDistExists = pathType(tplDistFolder) === 'dir';
126
+ const softwareDistExists = pathType(softwareDistFolder) === 'dir';
127
+ const assetDistExists = pathType(assetDistFolder) === 'dir';
128
+ if (!libDistExists && !tplDistExists && !softwareDistExists && !assetDistExists)
129
+ // if neither of tengo-specific folders detected, skipping package
130
+ return;
131
+ const packageId = { name: packageInfo.name, version: packageInfo.version };
132
+ if (libDistExists) {
133
+ loadLibsFromDir(logger, packageId, 'dist', libDistFolder, compiler);
134
+ }
135
+ if (tplDistExists) {
136
+ loadTemplatesFromDir(logger, packageId, 'dist', tplDistFolder, compiler);
137
+ }
138
+ if (softwareDistExists) {
139
+ loadSoftwareFromDir(logger, packageId, 'dist', softwareDistFolder, compiler);
140
+ }
141
+ if (assetDistExists) {
142
+ loadAssetsFromDir(logger, packageId, 'dist', assetDistFolder, compiler);
143
+ }
144
+ }
145
+ function loadLibsFromDir(logger, packageId, mode, folder, compiler) {
146
+ for (const f of fs.readdirSync(folder)) {
147
+ const file = path.resolve(folder, f);
148
+ if (!f.endsWith(compiledLibSuffix))
149
+ throw new Error(`unexpected file in 'lib' folder: ${file}`);
150
+ const fullName = {
151
+ type: 'library',
152
+ pkg: packageId.name,
153
+ id: f.slice(0, f.length - compiledLibSuffix.length),
154
+ version: packageId.version,
155
+ };
156
+ const src = parseSourceFile(logger, mode, file, fullName, true);
157
+ compiler.addLib(src);
158
+ logger.debug(`Adding dependency ${fullNameToString(fullName)} from ${file}`);
159
+ if (src.dependencies.length > 0) {
160
+ logger.debug('Dependencies:');
161
+ for (const dep of src.dependencies)
162
+ logger.debug(` - ${typedArtifactNameToString(dep)}`);
163
+ }
164
+ }
165
+ }
166
+ function loadTemplatesFromDir(logger, packageId, mode, folder, compiler) {
167
+ // adding templates
168
+ for (const f of fs.readdirSync(folder)) {
169
+ const file = path.resolve(folder, f);
170
+ if (!f.endsWith(compiledTplSuffix))
171
+ throw new Error(`unexpected file in 'tpl' folder: ${file}`);
172
+ const fullName = {
173
+ type: 'template',
174
+ pkg: packageId.name,
175
+ id: f.slice(0, f.length - compiledTplSuffix.length),
176
+ version: packageId.version,
177
+ };
178
+ const tpl = newTemplateFromContent(mode, fullName, fs.readFileSync(file));
179
+ compiler.addTemplate(templateToSource(tpl));
180
+ logger.debug(`Adding dependency ${fullNameToString(fullName)} from ${file}`);
181
+ }
182
+ }
183
+ function loadSoftwareFromDir(logger, packageId, mode, folder, compiler) {
184
+ for (const f of fs.readdirSync(folder)) {
185
+ const file = path.resolve(folder, f);
186
+ if (!f.endsWith(compiledSoftwareSuffix))
187
+ throw new Error(`unexpected file in 'software' folder: ${file}`);
188
+ const fullName = {
189
+ type: 'software',
190
+ pkg: packageId.name,
191
+ id: f.slice(0, f.length - compiledSoftwareSuffix.length),
192
+ version: packageId.version,
193
+ };
194
+ const source = fs.readFileSync(file).toString();
195
+ const software = new ArtifactSource(mode, fullName, getSha256(source), source, file, [], []);
196
+ logger.debug(`Adding dependency ${fullNameToString(fullName)} from ${file}`);
197
+ compiler.addSoftware(software);
198
+ }
199
+ }
200
+ function loadAssetsFromDir(logger, packageId, mode, folder, compiler) {
201
+ for (const f of fs.readdirSync(folder)) {
202
+ const file = path.resolve(folder, f);
203
+ if (!f.endsWith(compiledAssetSuffix))
204
+ throw new Error(`unexpected file in 'asset' folder: ${file}`);
205
+ const fullName = {
206
+ type: 'asset',
207
+ pkg: packageId.name,
208
+ id: f.slice(0, f.length - compiledAssetSuffix.length),
209
+ version: packageId.version,
210
+ };
211
+ const source = fs.readFileSync(file).toString();
212
+ const asset = new ArtifactSource(mode, fullName, getSha256(source), source, file, [], []);
213
+ logger.debug(`Adding dependency ${fullNameToString(fullName)} from ${file}`);
214
+ compiler.addAsset(asset);
215
+ }
216
+ }
217
+ function parseSources(logger, packageId, mode, root, subdir) {
218
+ const sources = [];
219
+ for (const f of fs.readdirSync(path.join(root, subdir))) {
220
+ const inRootPath = path.join(subdir, f); // path to item inside given <root>
221
+ const fullPath = path.join(root, inRootPath); // full path to item from CWD (or abs path, if <root> is abs path)
222
+ if (pathType(fullPath) === 'dir') {
223
+ const nested = parseSources(logger, packageId, mode, root, inRootPath);
224
+ sources.push(...nested);
225
+ continue;
226
+ }
227
+ // Handling index.lib.tengo files: rename them to <package-name>.lib.tengo
228
+ const artifactName = f === 'index.lib.tengo' ? `${path.dirname(inRootPath)}.lib.tengo` : inRootPath;
229
+ const fullName = fullNameFromFileName(packageId, artifactName.replaceAll(path.sep, '.'));
230
+ if (!fullName) {
231
+ logger.info(`Skipping unknown file type: ${artifactName}`);
232
+ continue; // skip unknown file types
233
+ }
234
+ // if (subdir != '') {
235
+ // // prettier-ignore
236
+ // throw new Error(`Templates and libraries should reside only inside '${root}' dir.
237
+ // You are free to have any file and dirs structure inside '${root}' keeping other files where you want,
238
+ // but regarding ${compilableSuffixes.join(', ')}, the flat file structure is mandatory.`);
239
+ // }
240
+ const file = path.resolve(root, inRootPath);
241
+ logger.debug(`Parsing ${fullNameToString(fullName)} from ${file}`);
242
+ const newSrc = parseSourceFile(logger, mode, file, fullName, true);
243
+ if (newSrc.dependencies.length > 0) {
244
+ logger.debug('Detected dependencies:');
245
+ for (const dep of newSrc.dependencies)
246
+ logger.debug(` - ${typedArtifactNameToString(dep)}`);
247
+ }
248
+ sources.push(newSrc);
249
+ }
250
+ return sources;
251
+ }
252
+ function newCompiler(logger, packageInfo, mode) {
253
+ const compiler = new TengoTemplateCompiler(mode);
254
+ // collect all data (templates, libs and software) from dependency tree
255
+ loadDependencies(logger, compiler, packageInfo);
256
+ return compiler;
257
+ }
258
+ function fullNameFromFileName(packageId, artifactName) {
259
+ const pkgAndVersion = { pkg: packageId.name, version: packageId.version };
260
+ if (artifactName.endsWith(srcLibSuffix)) {
261
+ return {
262
+ ...pkgAndVersion,
263
+ id: artifactName.substring(0, artifactName.length - srcLibSuffix.length),
264
+ type: 'library',
265
+ };
266
+ }
267
+ if (artifactName.endsWith(srcTplSuffix)) {
268
+ return {
269
+ ...pkgAndVersion,
270
+ id: artifactName.substring(0, artifactName.length - srcTplSuffix.length),
271
+ type: 'template',
272
+ };
273
+ }
274
+ if (artifactName.endsWith(srcSoftwareSuffix)) {
275
+ return {
276
+ ...pkgAndVersion,
277
+ id: artifactName.substring(0, artifactName.length - srcSoftwareSuffix.length),
278
+ type: 'software',
279
+ };
280
+ }
281
+ if (artifactName.endsWith(srcAssetSuffix)) {
282
+ return {
283
+ ...pkgAndVersion,
284
+ id: artifactName.substring(0, artifactName.length - srcAssetSuffix.length),
285
+ type: 'asset',
286
+ };
287
+ }
288
+ if (artifactName.endsWith(srcTestSuffix)) {
289
+ return {
290
+ ...pkgAndVersion,
291
+ id: artifactName.substring(0, artifactName.length - srcTestSuffix.length),
292
+ type: 'test',
293
+ };
294
+ }
295
+ return null;
296
+ }
297
+ function compile(logger, packageInfo, mode) {
298
+ const compiler = newCompiler(logger, packageInfo, mode);
299
+ const sources = parseSources(logger, packageInfo, mode, 'src', '');
300
+ // checking that we have something to do
301
+ if (sources.length === 0) {
302
+ const lookFor = [];
303
+ for (const suffix of compilableSuffixes) {
304
+ lookFor.push(`*${suffix}`);
305
+ }
306
+ logger.error(`Nothing to compile. Looked for ${lookFor.join(', ')}`);
307
+ process.exit(1);
308
+ }
309
+ // compilation
310
+ logger.info(`Compiling '${mode}'...`);
311
+ const compiled = compiler.compileAndAdd(sources);
312
+ logger.debug(`Done.`);
313
+ return compiled;
314
+ }
315
+ function savePacks(logger, compiled, mode) {
316
+ // writing libs
317
+ if (compiled.libs.length > 0) {
318
+ const libOutput = resolveLibsDst(mode, '.');
319
+ fs.mkdirSync(libOutput, { recursive: true });
320
+ for (const lib of compiled.libs) {
321
+ const file = path.resolve(libOutput, lib.fullName.id + compiledLibSuffix);
322
+ logger.info(` - writing ${file}`);
323
+ fs.writeFileSync(file, lib.src);
324
+ }
325
+ }
326
+ // writing templates
327
+ if (compiled.templates.length > 0) {
328
+ const tplOutput = resolveTemplatesDst(mode, '.');
329
+ fs.mkdirSync(tplOutput, { recursive: true });
330
+ for (const tpl of compiled.templates) {
331
+ const file = path.resolve(tplOutput, tpl.fullName.id + compiledTplSuffix);
332
+ logger.info(` - writing ${file}`);
333
+ fs.writeFileSync(file, serializeTemplate(tpl.data));
334
+ }
335
+ }
336
+ // writing software
337
+ if (compiled.software.length > 0) {
338
+ const swOutput = resolveSoftwareDst(mode, '.');
339
+ fs.mkdirSync(swOutput, { recursive: true });
340
+ for (const sw of compiled.software) {
341
+ const file = path.resolve(swOutput, sw.fullName.id + compiledSoftwareSuffix);
342
+ logger.info(` - writing ${file}`);
343
+ fs.writeFileSync(file, sw.src);
344
+ }
345
+ }
346
+ // writing assets
347
+ if (compiled.assets.length > 0) {
348
+ const swOutput = resolveAssetsDst(mode, '.');
349
+ fs.mkdirSync(swOutput, { recursive: true });
350
+ for (const sw of compiled.software) {
351
+ const file = path.resolve(swOutput, sw.fullName.id + compiledAssetSuffix);
352
+ logger.info(` - writing ${file}`);
353
+ fs.writeFileSync(file, sw.src);
354
+ }
355
+ }
356
+ }
357
+
358
+ export { compile, fullNameFromFileName, getPackageInfo, newCompiler, parseSources, resolvePackageJsonRoot, savePacks };
359
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sources":["../../src/compiler/main.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport * as path from 'node:path';\nimport * as fs from 'node:fs';\nimport { pathType } from './util';\nimport type { TemplatesAndLibs } from './compiler';\nimport { TengoTemplateCompiler } from './compiler';\nimport { getSha256 } from './source';\nimport type {\n CompileMode,\n FullArtifactName } from './package';\nimport {\n fullNameToString,\n typedArtifactNameToString,\n} from './package';\nimport { ArtifactSource, parseSourceFile } from './source';\nimport { newTemplateFromContent, templateToSource } from './template';\nimport type winston from 'winston';\nimport { tryResolve, tryResolveOrError } from '@milaboratories/resolve-helper';\nimport { serializeTemplate } from '@milaboratories/pl-model-backend';\n\ninterface PackageId {\n /** Package name from package.json */\n readonly name: string;\n /** Package version from package.json */\n readonly version: string;\n}\n\ninterface PackageInfo extends PackageId {\n /** Package type from package.json */\n readonly type: string | undefined;\n /** Path to package root */\n readonly root: string;\n /** Context of package info */\n readonly context: PackageInfoContext;\n /** Dependencies */\n readonly dependencies: PackageInfo[];\n}\n\ninterface PackageJson {\n name: string;\n version: string;\n type: string | undefined;\n dependencies: Record<string, string>;\n devDependencies: Record<string, string>;\n}\n\nconst compiledTplSuffix = '.plj.gz';\nconst compiledLibSuffix = '.lib.tengo';\nconst compiledSoftwareSuffix = '.sw.json';\nconst compiledAssetSuffix = '.as.json';\n\n// We need to keep track of dependencies for correct tgo-test CLI utility configuraiton.\n// It is much simpler to do this here, than duplicate all tle logic regarding dependencies\n// in go code.\nconst srcTestSuffix = '.test.tengo';\n\nconst srcTplSuffix = '.tpl.tengo';\nconst srcLibSuffix = '.lib.tengo';\nconst srcSoftwareSuffix = '.sw.json';\nconst srcAssetSuffix = '.as.json';\nconst compilableSuffixes = [srcLibSuffix, srcTplSuffix, srcSoftwareSuffix, srcAssetSuffix];\n\n/**\n * Resolves path to package.json file of the given dependency package.\n */\nfunction resolvePackageJsonPackage(root: string, depPackageName: string): string | undefined {\n if (!path.isAbsolute(root)) {\n throw new Error(`Root path must be absolute: ${root}`);\n }\n\n // First approach: resolving package's main entry point and try to find package.json\n // in dir tree upwards.\n let resolved = tryResolve(root, depPackageName);\n if (resolved) {\n let depth = 0;\n do {\n const p = path.join(resolved, 'package.json');\n if (pathType(p) === 'file')\n return p;\n depth++;\n resolved = path.dirname(resolved);\n } while (depth < 7 && path.basename(resolved) !== 'node_modules');\n }\n\n // Second approach: trying to find package.json in the package dir.\n const resolved2 = tryResolveOrError(root, `${depPackageName}/package.json`);\n if (resolved2.result === undefined) {\n if (resolved2.err === 'ERR_PACKAGE_PATH_NOT_EXPORTED')\n // tolerating not-exported package.json for dev dependencies\n return undefined;\n throw new Error(`Can't resolve package.json for package ${depPackageName ?? '.'} relative to ${root}`);\n }\n return resolved2.result;\n}\n\nexport function resolvePackageJsonRoot(root: string): string {\n if (!path.isAbsolute(root)) {\n throw new Error(`Root path must be absolute: ${root}`);\n }\n\n const p = path.join(root, 'package.json');\n if (pathType(p) === 'file')\n return p;\n throw new Error(`Can't resolve package.json in ${root}`);\n}\n\ntype PackageInfoContext = 'root' | 'dependency' | 'devDependency';\n\n/**\n * Get package info from package.json and all dependencies.\n */\nexport function getPackageInfo(\n root: string,\n logger: winston.Logger,\n context: PackageInfoContext = 'root',\n): PackageInfo {\n const packageJsonPath = resolvePackageJsonRoot(root);\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString()) as PackageJson;\n\n // resolving dependencies\n const depInfos: PackageInfo[] = [];\n\n if (packageJson.dependencies && context !== 'devDependency') {\n for (const dep of Object.keys(packageJson.dependencies)) {\n const depPackageJson = resolvePackageJsonPackage(root, dep);\n if (depPackageJson === undefined)\n throw new Error(`Can't resolve package.json for dependency ${dep} of ${root}`);\n const depRoot = path.dirname(depPackageJson);\n depInfos.push(getPackageInfo(depRoot, logger, 'dependency'));\n }\n }\n\n if (packageJson.devDependencies && context === 'root') {\n for (const dep of Object.keys(packageJson.devDependencies)) {\n const depPackageJson = resolvePackageJsonPackage(root, dep);\n if (depPackageJson === undefined) {\n logger.warn(`Can't resolve package.json for dev dependency ${dep} of ${root}`);\n // tolerating not-exported package.json for dev dependencies\n continue;\n }\n const depRoot = path.dirname(depPackageJson);\n depInfos.push(getPackageInfo(depRoot, logger, 'devDependency'));\n }\n }\n\n return {\n name: packageJson.name,\n version: packageJson.version,\n type: packageJson.type,\n dependencies: depInfos,\n root,\n context,\n };\n}\n\nfunction resolveLibsDst(mode: CompileMode, root: string) {\n return path.resolve(root, mode, 'tengo', 'lib');\n}\n\nfunction resolveTemplatesDst(mode: CompileMode, root: string) {\n return path.resolve(root, mode, 'tengo', 'tpl');\n}\n\nfunction resolveSoftwareDst(mode: CompileMode, root: string) {\n return path.resolve(root, mode, 'tengo', 'software');\n}\n\nfunction resolveAssetsDst(mode: CompileMode, root: string) {\n return path.resolve(root, mode, 'tengo', 'asset');\n}\n\nfunction loadDependencies(\n logger: winston.Logger,\n compiler: TengoTemplateCompiler,\n packageInfo: PackageInfo,\n): void {\n for (const dep of packageInfo.dependencies)\n loadDependencies(logger, compiler, dep);\n\n if (packageInfo.context === 'root')\n // we are not reading compiled files for root package\n return;\n\n // we are in package folder\n const libDistFolder = resolveLibsDst('dist', packageInfo.root);\n const tplDistFolder = resolveTemplatesDst('dist', packageInfo.root);\n const softwareDistFolder = resolveSoftwareDst('dist', packageInfo.root);\n const assetDistFolder = resolveAssetsDst('dist', packageInfo.root);\n\n const libDistExists = pathType(libDistFolder) === 'dir';\n const tplDistExists = pathType(tplDistFolder) === 'dir';\n const softwareDistExists = pathType(softwareDistFolder) === 'dir';\n const assetDistExists = pathType(assetDistFolder) === 'dir';\n\n if (!libDistExists && !tplDistExists && !softwareDistExists && !assetDistExists)\n // if neither of tengo-specific folders detected, skipping package\n return;\n\n const packageId = { name: packageInfo.name, version: packageInfo.version };\n\n if (libDistExists) {\n loadLibsFromDir(logger, packageId, 'dist', libDistFolder, compiler);\n }\n\n if (tplDistExists) {\n loadTemplatesFromDir(logger, packageId, 'dist', tplDistFolder, compiler);\n }\n\n if (softwareDistExists) {\n loadSoftwareFromDir(logger, packageId, 'dist', softwareDistFolder, compiler);\n }\n\n if (assetDistExists) {\n loadAssetsFromDir(logger, packageId, 'dist', assetDistFolder, compiler);\n }\n}\n\nfunction loadLibsFromDir(\n logger: winston.Logger,\n packageId: PackageId,\n mode: CompileMode,\n folder: string,\n compiler: TengoTemplateCompiler,\n) {\n for (const f of fs.readdirSync(folder)) {\n const file = path.resolve(folder, f);\n if (!f.endsWith(compiledLibSuffix)) throw new Error(`unexpected file in 'lib' folder: ${file}`);\n const fullName: FullArtifactName = {\n type: 'library',\n pkg: packageId.name,\n id: f.slice(0, f.length - compiledLibSuffix.length),\n version: packageId.version,\n };\n const src = parseSourceFile(logger, mode, file, fullName, true);\n compiler.addLib(src);\n logger.debug(`Adding dependency ${fullNameToString(fullName)} from ${file}`);\n if (src.dependencies.length > 0) {\n logger.debug('Dependencies:');\n for (const dep of src.dependencies) logger.debug(` - ${typedArtifactNameToString(dep)}`);\n }\n }\n}\n\nfunction loadTemplatesFromDir(\n logger: winston.Logger,\n packageId: PackageId,\n mode: CompileMode,\n folder: string,\n compiler: TengoTemplateCompiler,\n) {\n // adding templates\n for (const f of fs.readdirSync(folder)) {\n const file = path.resolve(folder, f);\n if (!f.endsWith(compiledTplSuffix)) throw new Error(`unexpected file in 'tpl' folder: ${file}`);\n const fullName: FullArtifactName = {\n type: 'template',\n pkg: packageId.name,\n id: f.slice(0, f.length - compiledTplSuffix.length),\n version: packageId.version,\n };\n const tpl = newTemplateFromContent(mode, fullName, fs.readFileSync(file));\n compiler.addTemplate(templateToSource(tpl));\n logger.debug(`Adding dependency ${fullNameToString(fullName)} from ${file}`);\n }\n}\n\nfunction loadSoftwareFromDir(\n logger: winston.Logger,\n packageId: PackageId,\n mode: CompileMode,\n folder: string,\n compiler: TengoTemplateCompiler,\n) {\n for (const f of fs.readdirSync(folder)) {\n const file = path.resolve(folder, f);\n if (!f.endsWith(compiledSoftwareSuffix))\n throw new Error(`unexpected file in 'software' folder: ${file}`);\n const fullName: FullArtifactName = {\n type: 'software',\n pkg: packageId.name,\n id: f.slice(0, f.length - compiledSoftwareSuffix.length),\n version: packageId.version,\n };\n\n const source = fs.readFileSync(file).toString();\n\n const software = new ArtifactSource(\n mode,\n fullName,\n getSha256(source),\n source,\n file,\n [],\n [],\n );\n\n logger.debug(`Adding dependency ${fullNameToString(fullName)} from ${file}`);\n compiler.addSoftware(software);\n }\n}\n\nfunction loadAssetsFromDir(\n logger: winston.Logger,\n packageId: PackageId,\n mode: CompileMode,\n folder: string,\n compiler: TengoTemplateCompiler,\n) {\n for (const f of fs.readdirSync(folder)) {\n const file = path.resolve(folder, f);\n if (!f.endsWith(compiledAssetSuffix))\n throw new Error(`unexpected file in 'asset' folder: ${file}`);\n const fullName: FullArtifactName = {\n type: 'asset',\n pkg: packageId.name,\n id: f.slice(0, f.length - compiledAssetSuffix.length),\n version: packageId.version,\n };\n\n const source = fs.readFileSync(file).toString();\n\n const asset = new ArtifactSource(\n mode,\n fullName,\n getSha256(source),\n source,\n file,\n [],\n [],\n );\n\n logger.debug(`Adding dependency ${fullNameToString(fullName)} from ${file}`);\n compiler.addAsset(asset);\n }\n}\n\nexport function parseSources(\n logger: winston.Logger,\n packageId: PackageId,\n mode: CompileMode,\n root: string,\n subdir: string,\n): ArtifactSource[] {\n const sources: ArtifactSource[] = [];\n\n for (const f of fs.readdirSync(path.join(root, subdir))) {\n const inRootPath = path.join(subdir, f); // path to item inside given <root>\n const fullPath = path.join(root, inRootPath); // full path to item from CWD (or abs path, if <root> is abs path)\n\n if (pathType(fullPath) === 'dir') {\n const nested = parseSources(logger, packageId, mode, root, inRootPath);\n sources.push(...nested);\n continue;\n }\n\n // Handling index.lib.tengo files: rename them to <package-name>.lib.tengo\n const artifactName = f === 'index.lib.tengo' ? `${path.dirname(inRootPath)}.lib.tengo` : inRootPath;\n\n const fullName = fullNameFromFileName(packageId, artifactName.replaceAll(path.sep, '.'));\n if (!fullName) {\n logger.info(`Skipping unknown file type: ${artifactName}`);\n continue; // skip unknown file types\n }\n\n // if (subdir != '') {\n // // prettier-ignore\n // throw new Error(`Templates and libraries should reside only inside '${root}' dir.\n // You are free to have any file and dirs structure inside '${root}' keeping other files where you want,\n // but regarding ${compilableSuffixes.join(', ')}, the flat file structure is mandatory.`);\n // }\n\n const file = path.resolve(root, inRootPath);\n logger.debug(`Parsing ${fullNameToString(fullName)} from ${file}`);\n const newSrc = parseSourceFile(logger, mode, file, fullName, true);\n if (newSrc.dependencies.length > 0) {\n logger.debug('Detected dependencies:');\n for (const dep of newSrc.dependencies) logger.debug(` - ${typedArtifactNameToString(dep)}`);\n }\n\n sources.push(newSrc);\n }\n\n return sources;\n}\n\nexport function newCompiler(\n logger: winston.Logger,\n packageInfo: PackageInfo,\n mode: CompileMode,\n): TengoTemplateCompiler {\n const compiler = new TengoTemplateCompiler(mode);\n\n // collect all data (templates, libs and software) from dependency tree\n loadDependencies(logger, compiler, packageInfo);\n\n return compiler;\n}\n\nexport function fullNameFromFileName(\n packageId: PackageId,\n artifactName: string,\n): FullArtifactName | null {\n const pkgAndVersion = { pkg: packageId.name, version: packageId.version };\n if (artifactName.endsWith(srcLibSuffix)) {\n return {\n ...pkgAndVersion,\n id: artifactName.substring(0, artifactName.length - srcLibSuffix.length),\n type: 'library',\n };\n }\n\n if (artifactName.endsWith(srcTplSuffix)) {\n return {\n ...pkgAndVersion,\n id: artifactName.substring(0, artifactName.length - srcTplSuffix.length),\n type: 'template',\n };\n }\n\n if (artifactName.endsWith(srcSoftwareSuffix)) {\n return {\n ...pkgAndVersion,\n id: artifactName.substring(0, artifactName.length - srcSoftwareSuffix.length),\n type: 'software',\n };\n }\n\n if (artifactName.endsWith(srcAssetSuffix)) {\n return {\n ...pkgAndVersion,\n id: artifactName.substring(0, artifactName.length - srcAssetSuffix.length),\n type: 'asset',\n };\n }\n\n if (artifactName.endsWith(srcTestSuffix)) {\n return {\n ...pkgAndVersion,\n id: artifactName.substring(0, artifactName.length - srcTestSuffix.length),\n type: 'test',\n };\n }\n\n return null;\n}\n\nexport function compile(logger: winston.Logger, packageInfo: PackageInfo, mode: CompileMode): TemplatesAndLibs {\n const compiler = newCompiler(logger, packageInfo, mode);\n const sources = parseSources(logger, packageInfo, mode, 'src', '');\n\n // checking that we have something to do\n if (sources.length === 0) {\n const lookFor: string[] = [];\n for (const suffix of compilableSuffixes) {\n lookFor.push(`*${suffix}`);\n }\n\n logger.error(`Nothing to compile. Looked for ${lookFor.join(', ')}`);\n process.exit(1);\n }\n\n // compilation\n logger.info(`Compiling '${mode}'...`);\n const compiled = compiler.compileAndAdd(sources);\n logger.debug(`Done.`);\n\n return compiled;\n}\n\nexport function savePacks(logger: winston.Logger, compiled: TemplatesAndLibs, mode: CompileMode) {\n // writing libs\n if (compiled.libs.length > 0) {\n const libOutput = resolveLibsDst(mode, '.');\n fs.mkdirSync(libOutput, { recursive: true });\n for (const lib of compiled.libs) {\n const file = path.resolve(libOutput, lib.fullName.id + compiledLibSuffix);\n logger.info(` - writing ${file}`);\n fs.writeFileSync(file, lib.src);\n }\n }\n\n // writing templates\n if (compiled.templates.length > 0) {\n const tplOutput = resolveTemplatesDst(mode, '.');\n fs.mkdirSync(tplOutput, { recursive: true });\n for (const tpl of compiled.templates) {\n const file = path.resolve(tplOutput, tpl.fullName.id + compiledTplSuffix);\n logger.info(` - writing ${file}`);\n fs.writeFileSync(file, serializeTemplate(tpl.data));\n }\n }\n\n // writing software\n if (compiled.software.length > 0) {\n const swOutput = resolveSoftwareDst(mode, '.');\n fs.mkdirSync(swOutput, { recursive: true });\n for (const sw of compiled.software) {\n const file = path.resolve(swOutput, sw.fullName.id + compiledSoftwareSuffix);\n logger.info(` - writing ${file}`);\n fs.writeFileSync(file, sw.src);\n }\n }\n\n // writing assets\n if (compiled.assets.length > 0) {\n const swOutput = resolveAssetsDst(mode, '.');\n fs.mkdirSync(swOutput, { recursive: true });\n for (const sw of compiled.software) {\n const file = path.resolve(swOutput, sw.fullName.id + compiledAssetSuffix);\n logger.info(` - writing ${file}`);\n fs.writeFileSync(file, sw.src);\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AA+CA,MAAM,iBAAiB,GAAG,SAAS;AACnC,MAAM,iBAAiB,GAAG,YAAY;AACtC,MAAM,sBAAsB,GAAG,UAAU;AACzC,MAAM,mBAAmB,GAAG,UAAU;AAEtC;AACA;AACA;AACA,MAAM,aAAa,GAAG,aAAa;AAEnC,MAAM,YAAY,GAAG,YAAY;AACjC,MAAM,YAAY,GAAG,YAAY;AACjC,MAAM,iBAAiB,GAAG,UAAU;AACpC,MAAM,cAAc,GAAG,UAAU;AACjC,MAAM,kBAAkB,GAAG,CAAC,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,cAAc,CAAC;AAE1F;;AAEG;AACH,SAAS,yBAAyB,CAAC,IAAY,EAAE,cAAsB,EAAA;IACrE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;AAC1B,QAAA,MAAM,IAAI,KAAK,CAAC,+BAA+B,IAAI,CAAA,CAAE,CAAC;IACxD;;;IAIA,IAAI,QAAQ,GAAG,UAAU,CAAC,IAAI,EAAE,cAAc,CAAC;IAC/C,IAAI,QAAQ,EAAE;QACZ,IA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,GAAG,CAAC,EAAE;QAC9B,MAAM,QAAQ,GAAG,gBAAgB,CAAC,IAAI,EAAE,GAAG,CAAC;QAC5C,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAC3C,QAAA,KAAK,MAAM,EAAE,IAAI,QAAQ,CAAC,QAAQ,EAAE;AAClC,YAAA,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,GAAG,mBAAmB,CAAC;AACzE,YAAA,MAAM,CAAC,IAAI,CAAC,eAAe,IAAI,CAAA,CAAE,CAAC;YAClC,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC;QAChC;IACF;AACF;;;;"}
@@ -0,0 +1,65 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ Package "@milaboratory/current-tengo-package".
5
+
6
+ Structure:
7
+
8
+ src/
9
+ local-template.pl.tengo <- this one will be compiled and put into ./dist/tengo/tpl/local-template.pl.pkg
10
+ local-library.tengo <- this one will be normalized and put into ./dist/tengo/lib/local-library.tengo
11
+ main.tpl.tengo <- this one will be compiled into ./dist/tengo/tpl/main.pl.pkg and published by external tool
12
+
13
+ Code of "main.tpl.tengo":
14
+
15
+ plapi := import("plapi")
16
+
17
+ plapi.getTemplateId("@milaboratory/some-tengo-template") // -> getTemplateId("@milaboratory/some-tengo-template:main")
18
+ import("@milaboratory/some-tengo-library") // -> import("@milaboratory/some-tengo-library:main")
19
+
20
+ */
21
+ function artifactKey(name) {
22
+ return `${name.type}||${name.pkg}||${name.id}`;
23
+ }
24
+ function fullNameToString(name) {
25
+ return `${name.type}:${name.pkg}:${name.id}:${name.version}`;
26
+ }
27
+ /** used for exceptions */
28
+ function typedArtifactNameToString(name) {
29
+ return `${name.type}:${name.pkg}:${name.id}`;
30
+ }
31
+ function typedArtifactNamesEquals(name1, name2) {
32
+ return name1.type == name2.type && name1.pkg == name2.pkg && name1.id == name2.id;
33
+ }
34
+ function fullNameEquals(name1, name2) {
35
+ return name1.type == name2.type && name1.pkg == name2.pkg && name1.id == name2.id && name1.version == name2.version;
36
+ }
37
+ /** used to format artefact name while generating output files */
38
+ function artifactNameToString(name) {
39
+ return `${name.pkg}:${name.id}`;
40
+ }
41
+ /** used to format artefact name and version while generating output files */
42
+ function formatArtefactNameAndVersion(name) {
43
+ return { name: artifactNameToString(name), version: name.version };
44
+ }
45
+ /** used to format artefact name and version while generating output files */
46
+ function parseArtefactNameAndVersion(nameAndVersion) {
47
+ const match = nameAndVersion.name.match(/^(?<pkg>[^:]*):(?<id>[^:]*)$/);
48
+ if (!match)
49
+ throw new Error(`malformed artifact name: ${nameAndVersion.name}`);
50
+ return { pkg: match.groups['pkg'], id: match.groups['id'], version: nameAndVersion.version };
51
+ }
52
+ function fullNameWithoutTypeToString(name) {
53
+ return `${name.pkg}:${name.id}:${name.version}`;
54
+ }
55
+
56
+ exports.artifactKey = artifactKey;
57
+ exports.artifactNameToString = artifactNameToString;
58
+ exports.formatArtefactNameAndVersion = formatArtefactNameAndVersion;
59
+ exports.fullNameEquals = fullNameEquals;
60
+ exports.fullNameToString = fullNameToString;
61
+ exports.fullNameWithoutTypeToString = fullNameWithoutTypeToString;
62
+ exports.parseArtefactNameAndVersion = parseArtefactNameAndVersion;
63
+ exports.typedArtifactNameToString = typedArtifactNameToString;
64
+ exports.typedArtifactNamesEquals = typedArtifactNamesEquals;
65
+ //# sourceMappingURL=package.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.cjs","sources":["../../src/compiler/package.ts"],"sourcesContent":["/*\n Package \"@milaboratory/current-tengo-package\".\n\n Structure:\n\n src/\n local-template.pl.tengo <- this one will be compiled and put into ./dist/tengo/tpl/local-template.pl.pkg\n local-library.tengo <- this one will be normalized and put into ./dist/tengo/lib/local-library.tengo\n main.tpl.tengo <- this one will be compiled into ./dist/tengo/tpl/main.pl.pkg and published by external tool\n\n Code of \"main.tpl.tengo\":\n\n plapi := import(\"plapi\")\n\n plapi.getTemplateId(\"@milaboratory/some-tengo-template\") // -> getTemplateId(\"@milaboratory/some-tengo-template:main\")\n import(\"@milaboratory/some-tengo-library\") // -> import(\"@milaboratory/some-tengo-library:main\")\n\n */\n\nexport type CompileMode = 'dist';\n\nexport type CompilerOption = {\n /** Option name, like 'hash_override' */\n name: string; // we can't use strict literals typing here as we will break compatibility of the code through the lifetime of the compiler.\n\n /** Arguments of the option. Everything that follows option name */\n args: string[];\n};\n\nexport type ArtifactType = 'library' | 'template' | 'test' | 'software' | 'asset';\n\n/** Artifact Name including package version */\nexport interface FullArtifactName {\n /** Dependency type */\n type: ArtifactType;\n\n /** Fully qualified package */\n pkg: string;\n\n /** Id of the artifact inside the package */\n id: string;\n\n /** Package version */\n version: string;\n}\n\nexport type FullArtifactNameWithoutType = Omit<FullArtifactName, 'type'>;\n\nexport type TypedArtifactName = Pick<FullArtifactName, 'type' | 'pkg' | 'id'>;\n\nexport type PackageName = Pick<FullArtifactName, 'pkg' | 'version'>;\n\nexport type ArtifactName = Pick<FullArtifactName, 'pkg' | 'id'>;\n\nexport function artifactKey(name: TypedArtifactName): string {\n return `${name.type}||${name.pkg}||${name.id}`;\n}\n\nexport function fullNameToString(name: FullArtifactName): string {\n return `${name.type}:${name.pkg}:${name.id}:${name.version}`;\n}\n\n/** used for exceptions */\nexport function typedArtifactNameToString(name: TypedArtifactName): string {\n return `${name.type}:${name.pkg}:${name.id}`;\n}\n\nexport function typedArtifactNamesEquals(\n name1: TypedArtifactName,\n name2: TypedArtifactName,\n): boolean {\n return name1.type == name2.type && name1.pkg == name2.pkg && name1.id == name2.id;\n}\n\nexport function fullNameEquals(\n name1: FullArtifactName,\n name2: FullArtifactName,\n): boolean {\n return name1.type == name2.type && name1.pkg == name2.pkg && name1.id == name2.id && name1.version == name2.version;\n}\n\n/** used to format artefact name while generating output files */\nexport function artifactNameToString(name: ArtifactName): string {\n return `${name.pkg}:${name.id}`;\n}\n\n/** used to format artefact name and version while generating output files */\nexport function formatArtefactNameAndVersion(name: FullArtifactName): {\n name: string;\n version: string;\n} {\n return { name: artifactNameToString(name), version: name.version };\n}\n\n/** used to format artefact name and version while generating output files */\nexport function parseArtefactNameAndVersion(nameAndVersion: {\n name: string;\n version: string;\n}): FullArtifactNameWithoutType {\n const match = nameAndVersion.name.match(/^(?<pkg>[^:]*):(?<id>[^:]*)$/);\n if (!match) throw new Error(`malformed artifact name: ${nameAndVersion.name}`);\n return { pkg: match.groups!['pkg'], id: match.groups!['id'], version: nameAndVersion.version };\n}\n\nexport function fullNameWithoutTypeToString(name: FullArtifactNameWithoutType): string {\n return `${name.pkg}:${name.id}:${name.version}`;\n}\n\nexport function fullNameWithoutType(name: FullArtifactName): FullArtifactNameWithoutType {\n return { pkg: name.pkg, id: name.id, version: name.version };\n}\n"],"names":[],"mappings":";;AAAA;;;;;;;;;;;;;;;;;AAiBG;AAqCG,SAAU,WAAW,CAAC,IAAuB,EAAA;AACjD,IAAA,OAAO,CAAA,EAAG,IAAI,CAAC,IAAI,CAAA,EAAA,EAAK,IAAI,CAAC,GAAG,CAAA,EAAA,EAAK,IAAI,CAAC,EAAE,EAAE;AAChD;AAEM,SAAU,gBAAgB,CAAC,IAAsB,EAAA;AACrD,IAAA,OAAO,GAAG,IAAI,CAAC,IAAI,CAAA,CAAA,EAAI,IAAI,CAAC,GAAG,CAAA,CAAA,EAAI,IAAI,CAAC,EAAE,CAAA,CAAA,EAAI,IAAI,CAAC,OAAO,EAAE;AAC9D;AAEA;AACM,SAAU,yBAAyB,CAAC,IAAuB,EAAA;AAC/D,IAAA,OAAO,CAAA,EAAG,IAAI,CAAC,IAAI,CAAA,CAAA,EAAI,IAAI,CAAC,GAAG,CAAA,CAAA,EAAI,IAAI,CAAC,EAAE,EAAE;AAC9C;AAEM,SAAU,wBAAwB,CACtC,KAAwB,EACxB,KAAwB,EAAA;IAExB,OAAO,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC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jD;;;;;;;;;;;;"}
@@ -41,4 +41,3 @@ export declare function parseArtefactNameAndVersion(nameAndVersion: {
41
41
  }): FullArtifactNameWithoutType;
42
42
  export declare function fullNameWithoutTypeToString(name: FullArtifactNameWithoutType): string;
43
43
  export declare function fullNameWithoutType(name: FullArtifactName): FullArtifactNameWithoutType;
44
- //# sourceMappingURL=package.d.ts.map
@@ -0,0 +1,55 @@
1
+ /*
2
+ Package "@milaboratory/current-tengo-package".
3
+
4
+ Structure:
5
+
6
+ src/
7
+ local-template.pl.tengo <- this one will be compiled and put into ./dist/tengo/tpl/local-template.pl.pkg
8
+ local-library.tengo <- this one will be normalized and put into ./dist/tengo/lib/local-library.tengo
9
+ main.tpl.tengo <- this one will be compiled into ./dist/tengo/tpl/main.pl.pkg and published by external tool
10
+
11
+ Code of "main.tpl.tengo":
12
+
13
+ plapi := import("plapi")
14
+
15
+ plapi.getTemplateId("@milaboratory/some-tengo-template") // -> getTemplateId("@milaboratory/some-tengo-template:main")
16
+ import("@milaboratory/some-tengo-library") // -> import("@milaboratory/some-tengo-library:main")
17
+
18
+ */
19
+ function artifactKey(name) {
20
+ return `${name.type}||${name.pkg}||${name.id}`;
21
+ }
22
+ function fullNameToString(name) {
23
+ return `${name.type}:${name.pkg}:${name.id}:${name.version}`;
24
+ }
25
+ /** used for exceptions */
26
+ function typedArtifactNameToString(name) {
27
+ return `${name.type}:${name.pkg}:${name.id}`;
28
+ }
29
+ function typedArtifactNamesEquals(name1, name2) {
30
+ return name1.type == name2.type && name1.pkg == name2.pkg && name1.id == name2.id;
31
+ }
32
+ function fullNameEquals(name1, name2) {
33
+ return name1.type == name2.type && name1.pkg == name2.pkg && name1.id == name2.id && name1.version == name2.version;
34
+ }
35
+ /** used to format artefact name while generating output files */
36
+ function artifactNameToString(name) {
37
+ return `${name.pkg}:${name.id}`;
38
+ }
39
+ /** used to format artefact name and version while generating output files */
40
+ function formatArtefactNameAndVersion(name) {
41
+ return { name: artifactNameToString(name), version: name.version };
42
+ }
43
+ /** used to format artefact name and version while generating output files */
44
+ function parseArtefactNameAndVersion(nameAndVersion) {
45
+ const match = nameAndVersion.name.match(/^(?<pkg>[^:]*):(?<id>[^:]*)$/);
46
+ if (!match)
47
+ throw new Error(`malformed artifact name: ${nameAndVersion.name}`);
48
+ return { pkg: match.groups['pkg'], id: match.groups['id'], version: nameAndVersion.version };
49
+ }
50
+ function fullNameWithoutTypeToString(name) {
51
+ return `${name.pkg}:${name.id}:${name.version}`;
52
+ }
53
+
54
+ export { artifactKey, artifactNameToString, formatArtefactNameAndVersion, fullNameEquals, fullNameToString, fullNameWithoutTypeToString, parseArtefactNameAndVersion, typedArtifactNameToString, typedArtifactNamesEquals };
55
+ //# sourceMappingURL=package.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.js","sources":["../../src/compiler/package.ts"],"sourcesContent":["/*\n Package \"@milaboratory/current-tengo-package\".\n\n Structure:\n\n src/\n local-template.pl.tengo <- this one will be compiled and put into ./dist/tengo/tpl/local-template.pl.pkg\n local-library.tengo <- this one will be normalized and put into ./dist/tengo/lib/local-library.tengo\n main.tpl.tengo <- this one will be compiled into ./dist/tengo/tpl/main.pl.pkg and published by external tool\n\n Code of \"main.tpl.tengo\":\n\n plapi := import(\"plapi\")\n\n plapi.getTemplateId(\"@milaboratory/some-tengo-template\") // -> getTemplateId(\"@milaboratory/some-tengo-template:main\")\n import(\"@milaboratory/some-tengo-library\") // -> import(\"@milaboratory/some-tengo-library:main\")\n\n */\n\nexport type CompileMode = 'dist';\n\nexport type CompilerOption = {\n /** Option name, like 'hash_override' */\n name: string; // we can't use strict literals typing here as we will break compatibility of the code through the lifetime of the compiler.\n\n /** Arguments of the option. Everything that follows option name */\n args: string[];\n};\n\nexport type ArtifactType = 'library' | 'template' | 'test' | 'software' | 'asset';\n\n/** Artifact Name including package version */\nexport interface FullArtifactName {\n /** Dependency type */\n type: ArtifactType;\n\n /** Fully qualified package */\n pkg: string;\n\n /** Id of the artifact inside the package */\n id: string;\n\n /** Package version */\n version: string;\n}\n\nexport type FullArtifactNameWithoutType = Omit<FullArtifactName, 'type'>;\n\nexport type TypedArtifactName = Pick<FullArtifactName, 'type' | 'pkg' | 'id'>;\n\nexport type PackageName = Pick<FullArtifactName, 'pkg' | 'version'>;\n\nexport type ArtifactName = Pick<FullArtifactName, 'pkg' | 'id'>;\n\nexport function artifactKey(name: TypedArtifactName): string {\n return `${name.type}||${name.pkg}||${name.id}`;\n}\n\nexport function fullNameToString(name: FullArtifactName): string {\n return `${name.type}:${name.pkg}:${name.id}:${name.version}`;\n}\n\n/** used for exceptions */\nexport function typedArtifactNameToString(name: TypedArtifactName): string {\n return `${name.type}:${name.pkg}:${name.id}`;\n}\n\nexport function typedArtifactNamesEquals(\n name1: TypedArtifactName,\n name2: TypedArtifactName,\n): boolean {\n return name1.type == name2.type && name1.pkg == name2.pkg && name1.id == name2.id;\n}\n\nexport function fullNameEquals(\n name1: FullArtifactName,\n name2: FullArtifactName,\n): boolean {\n return name1.type == name2.type && name1.pkg == name2.pkg && name1.id == name2.id && name1.version == name2.version;\n}\n\n/** used to format artefact name while generating output files */\nexport function artifactNameToString(name: ArtifactName): string {\n return `${name.pkg}:${name.id}`;\n}\n\n/** used to format artefact name and version while generating output files */\nexport function formatArtefactNameAndVersion(name: FullArtifactName): {\n name: string;\n version: string;\n} {\n return { name: artifactNameToString(name), version: name.version };\n}\n\n/** used to format artefact name and version while generating output files */\nexport function parseArtefactNameAndVersion(nameAndVersion: {\n name: string;\n version: string;\n}): FullArtifactNameWithoutType {\n const match = nameAndVersion.name.match(/^(?<pkg>[^:]*):(?<id>[^:]*)$/);\n if (!match) throw new Error(`malformed artifact name: ${nameAndVersion.name}`);\n return { pkg: match.groups!['pkg'], id: match.groups!['id'], version: nameAndVersion.version };\n}\n\nexport function fullNameWithoutTypeToString(name: FullArtifactNameWithoutType): string {\n return `${name.pkg}:${name.id}:${name.version}`;\n}\n\nexport function fullNameWithoutType(name: FullArtifactName): FullArtifactNameWith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