@platforma-sdk/tengo-builder 1.17.4 → 1.17.6
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 +4 -4
- package/dist/commands/build.d.ts.map +1 -1
- package/dist/commands/check.d.ts +1 -1
- package/dist/commands/dump/all.d.ts.map +1 -1
- package/dist/commands/dump/assets.d.ts.map +1 -1
- package/dist/commands/dump/libs.d.ts.map +1 -1
- package/dist/commands/dump/software.d.ts.map +1 -1
- package/dist/commands/dump/templates.d.ts.map +1 -1
- package/dist/commands/dump/tests.d.ts.map +1 -1
- package/dist/commands/test.d.ts +1 -1
- package/dist/compiler/artifactset.d.ts.map +1 -1
- package/dist/compiler/compiler.d.ts.map +1 -1
- package/dist/compiler/compileroptions.d.ts +1 -1
- package/dist/compiler/compileroptions.d.ts.map +1 -1
- package/dist/compiler/main.d.ts.map +1 -1
- package/dist/compiler/source.d.ts.map +1 -1
- package/dist/compiler/template.d.ts +1 -47
- package/dist/compiler/template.d.ts.map +1 -1
- package/dist/compiler/test.artifacts.d.ts.map +1 -1
- package/dist/compiler/util.d.ts.map +1 -1
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +153 -150
- package/dist/index.mjs.map +1 -1
- package/dist/shared/basecmd.d.ts +4 -4
- package/dist/shared/basecmd.d.ts.map +1 -1
- package/dist/shared/dump.d.ts.map +1 -1
- package/dist/shared/proc.d.ts +2 -2
- package/dist/shared/proc.d.ts.map +1 -1
- package/package.json +5 -3
- package/src/commands/build.ts +12 -11
- package/src/commands/check.ts +2 -2
- package/src/commands/dump/all.ts +8 -8
- package/src/commands/dump/assets.ts +8 -8
- package/src/commands/dump/libs.ts +11 -12
- package/src/commands/dump/software.ts +8 -8
- package/src/commands/dump/templates.ts +8 -9
- package/src/commands/dump/tests.ts +8 -8
- package/src/commands/test.ts +1 -1
- package/src/compiler/artifactset.ts +14 -13
- package/src/compiler/compiler.ts +63 -56
- package/src/compiler/compileroptions.ts +12 -12
- package/src/compiler/main.ts +29 -27
- package/src/compiler/package.ts +1 -1
- package/src/compiler/source.ts +53 -51
- package/src/compiler/template.ts +23 -75
- package/src/compiler/test.artifacts.ts +24 -24
- package/src/compiler/util.ts +7 -5
- package/src/index.ts +1 -1
- package/src/shared/basecmd.ts +16 -16
- package/src/shared/dump.ts +22 -21
- package/src/shared/proc.ts +6 -4
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
var xe = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var l = (s, e, t) =>
|
|
4
|
-
import { spawnSync as
|
|
5
|
-
import { Flags as
|
|
2
|
+
var Fe = (s, e, t) => e in s ? xe(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
|
+
var l = (s, e, t) => Fe(s, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { spawnSync as Oe, spawn as Re } from "node:child_process";
|
|
5
|
+
import { Flags as F, Command as $ } from "@oclif/core";
|
|
6
6
|
import * as f from "node:path";
|
|
7
7
|
import * as p from "node:fs";
|
|
8
8
|
import { readFileSync as Me } from "node:fs";
|
|
9
9
|
import * as G from "winston";
|
|
10
|
-
import {
|
|
11
|
-
import Ie from "canonicalize";
|
|
10
|
+
import { parseTemplate as Le, serializeTemplate as je } from "@milaboratories/pl-model-backend";
|
|
12
11
|
import * as x from "node:fs/promises";
|
|
13
12
|
import { TengoTesterBinaryPath as we } from "@milaboratories/tengo-tester";
|
|
14
13
|
import { stdout as D } from "node:process";
|
|
15
|
-
function
|
|
14
|
+
function O(s) {
|
|
16
15
|
throw new Error("Unexpected object: " + s);
|
|
17
16
|
}
|
|
18
17
|
function N(s = "debug") {
|
|
@@ -27,7 +26,7 @@ function N(s = "debug") {
|
|
|
27
26
|
]
|
|
28
27
|
});
|
|
29
28
|
}
|
|
30
|
-
function
|
|
29
|
+
function Ie() {
|
|
31
30
|
let s = process.cwd();
|
|
32
31
|
for (; s; ) {
|
|
33
32
|
const e = f.join(s, "node_modules");
|
|
@@ -43,11 +42,12 @@ function E(s) {
|
|
|
43
42
|
const e = p.statSync(s);
|
|
44
43
|
return e.isDirectory() ? "dir" : e.isFile() ? "file" : e.isSymbolicLink() ? "link" : "unknown";
|
|
45
44
|
} catch (e) {
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
const t = e;
|
|
46
|
+
if (t.code == "ENOENT") return "absent";
|
|
47
|
+
throw t;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
function
|
|
50
|
+
function Ce(s) {
|
|
51
51
|
return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(s.toLowerCase());
|
|
52
52
|
}
|
|
53
53
|
function ce(s) {
|
|
@@ -68,7 +68,7 @@ function h(s) {
|
|
|
68
68
|
function j(s) {
|
|
69
69
|
return { name: h(s), version: s.version };
|
|
70
70
|
}
|
|
71
|
-
function
|
|
71
|
+
function Ge(s) {
|
|
72
72
|
const e = s.name.match(/^(?<pkg>[^:]*):(?<id>[^:]*)$/);
|
|
73
73
|
if (!e) throw new Error(`malformed artifact name: ${s.name}`);
|
|
74
74
|
return { pkg: e.groups.pkg, id: e.groups.id, version: s.version };
|
|
@@ -76,7 +76,6 @@ function ze(s) {
|
|
|
76
76
|
function fe(s) {
|
|
77
77
|
return `${s.pkg}:${s.id}:${s.version}`;
|
|
78
78
|
}
|
|
79
|
-
const Je = new TextDecoder(), Ue = new TextEncoder();
|
|
80
79
|
class ye {
|
|
81
80
|
constructor(e, t, r) {
|
|
82
81
|
l(this, "data");
|
|
@@ -87,19 +86,19 @@ class ye {
|
|
|
87
86
|
throw new Error("Neither data nor content is provided for template constructor");
|
|
88
87
|
if (n !== void 0 && o !== void 0)
|
|
89
88
|
throw new Error("Both data and content are provided for template constructor");
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
o === void 0 && (o = je(Ue.encode(Ie(n)), { chunkSize: 256 * 1024, level: 9 }));
|
|
93
|
-
const i = ze(n);
|
|
89
|
+
n === void 0 && (n = Le(o)), o === void 0 && (o = je(n));
|
|
90
|
+
const i = Ge(n);
|
|
94
91
|
if (i.pkg !== t.pkg || i.id !== t.id || i.version !== t.version)
|
|
95
|
-
throw new Error(
|
|
92
|
+
throw new Error(
|
|
93
|
+
`Compiled template name don't match it's package and file names: ${fe(i)} != ${fe(t)}`
|
|
94
|
+
);
|
|
96
95
|
this.data = n, this.content = o;
|
|
97
96
|
}
|
|
98
97
|
toJSON() {
|
|
99
98
|
return { compileMode: this.compileMode, fullName: this.fullName, data: this.data };
|
|
100
99
|
}
|
|
101
100
|
}
|
|
102
|
-
class
|
|
101
|
+
class U {
|
|
103
102
|
constructor(e) {
|
|
104
103
|
l(this, "map", /* @__PURE__ */ new Map());
|
|
105
104
|
this.nameExtractor = e;
|
|
@@ -119,21 +118,21 @@ class z {
|
|
|
119
118
|
this.map.forEach((t) => e(t, this.nameExtractor(t)));
|
|
120
119
|
}
|
|
121
120
|
}
|
|
122
|
-
function
|
|
123
|
-
return new
|
|
121
|
+
function Ue() {
|
|
122
|
+
return new U((s) => s);
|
|
124
123
|
}
|
|
125
124
|
class I {
|
|
126
125
|
constructor(e) {
|
|
127
126
|
l(this, "dev");
|
|
128
127
|
l(this, "dist");
|
|
129
|
-
this.nameExtractor = e, this.dev = new
|
|
128
|
+
this.nameExtractor = e, this.dev = new U(e), this.dist = new U(e);
|
|
130
129
|
}
|
|
131
130
|
add(e, t, r = !0) {
|
|
132
131
|
switch (e) {
|
|
133
132
|
case "dist":
|
|
134
133
|
return this.dist.add(t, r);
|
|
135
134
|
default:
|
|
136
|
-
|
|
135
|
+
O(e);
|
|
137
136
|
}
|
|
138
137
|
}
|
|
139
138
|
get(e, t) {
|
|
@@ -141,7 +140,7 @@ class I {
|
|
|
141
140
|
case "dist":
|
|
142
141
|
return this.dist.get(t);
|
|
143
142
|
default:
|
|
144
|
-
|
|
143
|
+
O(e);
|
|
145
144
|
}
|
|
146
145
|
}
|
|
147
146
|
array(e) {
|
|
@@ -152,16 +151,16 @@ class I {
|
|
|
152
151
|
this.dist.forEach((r, n) => t(this.get(e, n) ?? r, n));
|
|
153
152
|
}
|
|
154
153
|
}
|
|
155
|
-
function
|
|
154
|
+
function Je(s, e) {
|
|
156
155
|
for (const t of s)
|
|
157
156
|
switch (t.name) {
|
|
158
157
|
case "hash_override": {
|
|
159
|
-
e.hashOverride =
|
|
158
|
+
e.hashOverride = We(t.args);
|
|
160
159
|
break;
|
|
161
160
|
}
|
|
162
161
|
}
|
|
163
162
|
}
|
|
164
|
-
function
|
|
163
|
+
function Pe(s, e) {
|
|
165
164
|
for (const t of s)
|
|
166
165
|
switch (t.name) {
|
|
167
166
|
case "hash_override":
|
|
@@ -170,19 +169,19 @@ function _e(s, e) {
|
|
|
170
169
|
);
|
|
171
170
|
}
|
|
172
171
|
}
|
|
173
|
-
function
|
|
172
|
+
function We(s) {
|
|
174
173
|
if (s.length != 1)
|
|
175
174
|
throw new Error(
|
|
176
175
|
"hash_override compiler option expects exactly one argument: hash_override <some string>. Note, you can use only UUID as a value."
|
|
177
176
|
);
|
|
178
177
|
const e = s[0].toLowerCase();
|
|
179
|
-
if (!
|
|
178
|
+
if (!Ce(e))
|
|
180
179
|
throw new Error(
|
|
181
180
|
`hash_override must contain valid UUID as an override. As hash_override affects deduplication, it becomes completely not possible to distinguish several different templates from each other on backend's side. This means, if you set hash_override to a simple value (say, letter "a") on two completely different templates, they will be marked as interchangeable on backend's side with unpredictable consequences. UUID looks like a safe enough tradeoff between the feature usage simplicity and duplication safety`
|
|
182
181
|
);
|
|
183
182
|
return e;
|
|
184
183
|
}
|
|
185
|
-
class
|
|
184
|
+
class ze {
|
|
186
185
|
constructor(e) {
|
|
187
186
|
l(this, "libs", new I((e) => e.fullName));
|
|
188
187
|
l(this, "software", new I((e) => e.fullName));
|
|
@@ -194,44 +193,47 @@ class Be {
|
|
|
194
193
|
for (const o of r)
|
|
195
194
|
switch (o.type) {
|
|
196
195
|
case "library": {
|
|
197
|
-
const
|
|
198
|
-
if (
|
|
199
|
-
|
|
200
|
-
throw new Error(
|
|
196
|
+
const i = this.getLibOrError(o), a = n.indexOf(h(o));
|
|
197
|
+
if (a >= 0) {
|
|
198
|
+
const u = `library import recursion detected: ${n.slice(a).join(" -> ")} -> ${h(o)}`;
|
|
199
|
+
throw new Error(u);
|
|
201
200
|
}
|
|
202
|
-
const
|
|
203
|
-
...j(
|
|
204
|
-
src:
|
|
201
|
+
const c = {
|
|
202
|
+
...j(i.fullName),
|
|
203
|
+
src: i.src
|
|
205
204
|
};
|
|
206
|
-
|
|
205
|
+
Pe(i.compilerOptions), t.libs[h(o)] = c, this.populateTemplateDataFromDependencies(e, t, i.dependencies, [...n, h(o)]);
|
|
207
206
|
break;
|
|
208
207
|
}
|
|
209
|
-
case "software":
|
|
208
|
+
case "software": {
|
|
210
209
|
const i = this.getSoftwareOrError(o);
|
|
211
210
|
t.software[h(o)] = {
|
|
212
211
|
...j(i.fullName),
|
|
213
212
|
src: i.src
|
|
214
213
|
};
|
|
215
214
|
break;
|
|
216
|
-
|
|
217
|
-
|
|
215
|
+
}
|
|
216
|
+
case "asset": {
|
|
217
|
+
const i = this.getAssetOrError(o);
|
|
218
218
|
t.software[h(o)] = {
|
|
219
|
-
...j(
|
|
220
|
-
src:
|
|
219
|
+
...j(i.fullName),
|
|
220
|
+
src: i.src
|
|
221
221
|
};
|
|
222
222
|
break;
|
|
223
|
-
|
|
223
|
+
}
|
|
224
|
+
case "template": {
|
|
224
225
|
if (de(e, o))
|
|
225
226
|
continue;
|
|
226
|
-
const
|
|
227
|
-
t.templates[h(o)] =
|
|
227
|
+
const i = this.getTemplateOrError(o);
|
|
228
|
+
t.templates[h(o)] = i.data;
|
|
228
229
|
break;
|
|
230
|
+
}
|
|
229
231
|
case "test":
|
|
230
232
|
throw new Error(
|
|
231
233
|
`dependencies tree error: tests should never be part of template: ${g(o)} is dependency of ${h(e)}`
|
|
232
234
|
);
|
|
233
235
|
default:
|
|
234
|
-
|
|
236
|
+
O(o.type);
|
|
235
237
|
}
|
|
236
238
|
}
|
|
237
239
|
/** This method assumes that all dependencies are already added to the compiler's context */
|
|
@@ -247,7 +249,7 @@ class Be {
|
|
|
247
249
|
assets: {},
|
|
248
250
|
src: e.src
|
|
249
251
|
};
|
|
250
|
-
|
|
252
|
+
Je(e.compilerOptions, t), this.populateTemplateDataFromDependencies(e.fullName, t, e.dependencies, []);
|
|
251
253
|
const r = new ye(e.compileMode, e.fullName, { data: t });
|
|
252
254
|
return this.addTemplate(r), r;
|
|
253
255
|
}
|
|
@@ -348,7 +350,7 @@ class Be {
|
|
|
348
350
|
case "test":
|
|
349
351
|
return;
|
|
350
352
|
default:
|
|
351
|
-
|
|
353
|
+
O(e.type);
|
|
352
354
|
}
|
|
353
355
|
}
|
|
354
356
|
checkLibs() {
|
|
@@ -370,8 +372,7 @@ class Be {
|
|
|
370
372
|
const n = [];
|
|
371
373
|
for (const o of r) {
|
|
372
374
|
const i = o.dependencies.filter(
|
|
373
|
-
(a) => !this.getArtefact(a) &&
|
|
374
|
-
!(o.fullName.type === "template" && de(o.fullName, a))
|
|
375
|
+
(a) => !this.getArtefact(a) && !(o.fullName.type === "template" && de(o.fullName, a))
|
|
375
376
|
);
|
|
376
377
|
if (i.length > 0) {
|
|
377
378
|
let a = `Unsatisfied dependencies in ${m(o.fullName)}:
|
|
@@ -397,16 +398,17 @@ class Be {
|
|
|
397
398
|
const a = this.compileAndAddTemplate(o);
|
|
398
399
|
t.templates.push(a);
|
|
399
400
|
} catch (a) {
|
|
400
|
-
|
|
401
|
+
const c = a;
|
|
402
|
+
let u = `Unsatisfied dependencies in ${m(o.fullName)}:
|
|
401
403
|
`;
|
|
402
|
-
|
|
403
|
-
`, n.push({ src: o, err: Error(
|
|
404
|
+
u += ` - ${c.message}
|
|
405
|
+
`, n.push({ src: o, err: Error(u) });
|
|
404
406
|
}
|
|
405
407
|
break;
|
|
406
408
|
case "test":
|
|
407
409
|
break;
|
|
408
410
|
default:
|
|
409
|
-
|
|
411
|
+
O(o.fullName.type);
|
|
410
412
|
}
|
|
411
413
|
}
|
|
412
414
|
if (r.length === n.length) {
|
|
@@ -423,9 +425,9 @@ ${i.err.message}`;
|
|
|
423
425
|
}
|
|
424
426
|
const pe = "[_a-zA-Z][_a-zA-Z0-9]*", R = (s, e) => new RegExp(
|
|
425
427
|
`\\b${s}\\.(?<fnCall>(?<fnName>` + e + ')\\s*\\(\\s*"(?<templateName>[^"]+)"\\s*\\))'
|
|
426
|
-
),
|
|
428
|
+
), _e = (s) => R(s, "getTemplateId"), qe = (s) => R(s, "getSoftwareInfo"), ue = (s) => R(s, "importTemplate"), me = (s) => R(s, "importSoftware"), Be = (s) => R(s, "importAsset"), Ve = /^\s*$/, Ze = /^\/\/tengo:[\w]/, Ke = /^\s*\/\/\s*tengo:\s*./, Xe = /^\s*(\/\/)|(\/\*.*\*\/)/, Ye = /^\s*\/\*/, He = /\*\//, be = /\s*:=\s*import\s*\(\s*"(?<moduleName>[^"]+)"\s*\)/, Qe = new RegExp(
|
|
427
429
|
`\\b(?<importName>${pe}(\\.${pe})*)${be.source}`
|
|
428
|
-
),
|
|
430
|
+
), et = /(?<pkgName>[^"]+)?:(?<depID>[^"]+)/, tt = (s) => {
|
|
429
431
|
const e = s.split(" "), t = e[0].split(":");
|
|
430
432
|
if (t.length != 2)
|
|
431
433
|
throw new Error(
|
|
@@ -442,11 +444,11 @@ class oe {
|
|
|
442
444
|
}
|
|
443
445
|
}
|
|
444
446
|
function ve(s, e, t, r, n) {
|
|
445
|
-
const o = Me(t).toString(), { deps: i, normalized: a, opts: c } =
|
|
447
|
+
const o = Me(t).toString(), { deps: i, normalized: a, opts: c } = st(s, o, r, n);
|
|
446
448
|
return new oe(e, r, a, t, i.array, c);
|
|
447
449
|
}
|
|
448
|
-
function
|
|
449
|
-
const n =
|
|
450
|
+
function st(s, e, t, r) {
|
|
451
|
+
const n = Ue(), o = [], i = e.split(`
|
|
450
452
|
`), a = [];
|
|
451
453
|
let c = {
|
|
452
454
|
isInCommentBlock: !1,
|
|
@@ -457,7 +459,7 @@ function nt(s, e, t, r) {
|
|
|
457
459
|
for (const u of i) {
|
|
458
460
|
c.lineNo++;
|
|
459
461
|
try {
|
|
460
|
-
const d =
|
|
462
|
+
const d = ot(
|
|
461
463
|
s,
|
|
462
464
|
u,
|
|
463
465
|
c,
|
|
@@ -466,7 +468,8 @@ function nt(s, e, t, r) {
|
|
|
466
468
|
);
|
|
467
469
|
a.push(d.line), c = d.context, d.artifact && n.add(d.artifact), d.option && o.push(d.option);
|
|
468
470
|
} catch (d) {
|
|
469
|
-
|
|
471
|
+
const w = d;
|
|
472
|
+
throw new Error(`[line ${c.lineNo}]: ${w.message}
|
|
470
473
|
${u}`);
|
|
471
474
|
}
|
|
472
475
|
}
|
|
@@ -477,34 +480,34 @@ function nt(s, e, t, r) {
|
|
|
477
480
|
opts: o
|
|
478
481
|
};
|
|
479
482
|
}
|
|
480
|
-
function
|
|
483
|
+
function ot(s, e, t, r, n) {
|
|
481
484
|
if (t.isInCommentBlock)
|
|
482
|
-
return
|
|
483
|
-
if (
|
|
485
|
+
return He.exec(e) && (t.isInCommentBlock = !1), { line: e, context: t, artifact: void 0, option: void 0 };
|
|
486
|
+
if (Ze.exec(e)) {
|
|
484
487
|
if (!t.canDetectOptions)
|
|
485
488
|
throw s.error(
|
|
486
489
|
`[line ${t.lineNo}]: compiler option '//tengo:' was detected, but it cannot be applied as compiler options can be set only at the file header, before any code line'`
|
|
487
490
|
), new Error("tengo compiler options ('//tengo:' comments) can be set only in file header");
|
|
488
|
-
return { line: e, context: t, artifact: void 0, option:
|
|
491
|
+
return { line: e, context: t, artifact: void 0, option: tt(e) };
|
|
489
492
|
}
|
|
490
|
-
if (
|
|
493
|
+
if (Ke.exec(e) && t.canDetectOptions)
|
|
491
494
|
return s.warn(
|
|
492
495
|
`[line ${t.lineNo}]: text simillar to compiler option ('//tengo:...') was detected, but it has wrong format. Leave it as is, if you did not mean to use a line as compiler option. Or format it to '//tengo:<option>' otherwise (no spaces between '//' and 'tengo', no spaces between ':' and option name)`
|
|
493
496
|
), { line: e, context: t, artifact: void 0, option: void 0 };
|
|
494
|
-
if (
|
|
497
|
+
if (Xe.exec(e))
|
|
495
498
|
return { line: e, context: t, artifact: void 0, option: void 0 };
|
|
496
|
-
if (
|
|
499
|
+
if (Ye.exec(e))
|
|
497
500
|
return t.isInCommentBlock = !0, { line: e, context: t, artifact: void 0, option: void 0 };
|
|
498
|
-
if (
|
|
501
|
+
if (Ve.exec(e))
|
|
499
502
|
return { line: e, context: t, artifact: void 0, option: void 0 };
|
|
500
503
|
t.canDetectOptions = !1;
|
|
501
504
|
const o = be.exec(e);
|
|
502
505
|
if (o) {
|
|
503
|
-
const i =
|
|
506
|
+
const i = rt(e);
|
|
504
507
|
if (i.module === "plapi")
|
|
505
508
|
return t.tplDepREs.has(i.module) || t.tplDepREs.set(i.module, [
|
|
506
|
-
["template",
|
|
507
|
-
["software",
|
|
509
|
+
["template", _e(i.alias)],
|
|
510
|
+
["software", qe(i.alias)]
|
|
508
511
|
]), { line: e, context: t, artifact: void 0, option: void 0 };
|
|
509
512
|
(i.module === "@milaboratory/tengo-sdk:ll" || i.module === "@platforma-sdk/workflow-tengo:ll" || (r === "@milaboratory/tengo-sdk" || r === "@platforma-sdk/workflow-tengo") && i.module === ":ll") && (t.tplDepREs.has(i.module) || t.tplDepREs.set(i.module, [
|
|
510
513
|
["template", ue(i.alias)],
|
|
@@ -512,7 +515,7 @@ function it(s, e, t, r, n) {
|
|
|
512
515
|
])), (i.module === "@milaboratory/tengo-sdk:assets" || i.module === "@platforma-sdk/workflow-tengo:assets" || (r === "@milaboratory/tengo-sdk" || r === "@platforma-sdk/workflow-tengo") && i.module === ":assets") && (t.tplDepREs.has(i.module) || t.tplDepREs.set(i.module, [
|
|
513
516
|
["template", ue(i.alias)],
|
|
514
517
|
["software", me(i.alias)],
|
|
515
|
-
["asset",
|
|
518
|
+
["asset", Be(i.alias)]
|
|
516
519
|
]));
|
|
517
520
|
const a = ge(i.module, "library", r);
|
|
518
521
|
return a ? (e = e.replace(o[0], ` := import("${a.pkg}:${a.id}")`), { line: e, context: t, artifact: a, option: void 0 }) : { line: e, context: t, artifact: void 0, option: void 0 };
|
|
@@ -523,18 +526,18 @@ function it(s, e, t, r, n) {
|
|
|
523
526
|
const d = u.exec(e);
|
|
524
527
|
if (!d || !d.groups)
|
|
525
528
|
continue;
|
|
526
|
-
const { fnCall:
|
|
527
|
-
if (!
|
|
529
|
+
const { fnCall: w, templateName: v, fnName: y } = d.groups;
|
|
530
|
+
if (!w || !v || !y)
|
|
528
531
|
throw Error("failed to parse template import statement");
|
|
529
|
-
const
|
|
530
|
-
if (!
|
|
531
|
-
throw Error(`failed to parse artifact name in ${
|
|
532
|
-
return e = e.replace(
|
|
532
|
+
const b = ge(v, c, r);
|
|
533
|
+
if (!b)
|
|
534
|
+
throw Error(`failed to parse artifact name in ${y} import statement`);
|
|
535
|
+
return e = e.replace(w, `${y}("${b.pkg}:${b.id}")`), { line: e, context: t, artifact: b, option: void 0 };
|
|
533
536
|
}
|
|
534
537
|
return { line: e, context: t, artifact: void 0, option: void 0 };
|
|
535
538
|
}
|
|
536
|
-
function
|
|
537
|
-
const e =
|
|
539
|
+
function rt(s) {
|
|
540
|
+
const e = Qe.exec(s);
|
|
538
541
|
if (!e || !e.groups)
|
|
539
542
|
throw Error("failed to parse 'import' statement");
|
|
540
543
|
const { importName: t, moduleName: r } = e.groups;
|
|
@@ -546,7 +549,7 @@ function at(s) {
|
|
|
546
549
|
};
|
|
547
550
|
}
|
|
548
551
|
function ge(s, e, t) {
|
|
549
|
-
const r =
|
|
552
|
+
const r = et.exec(s);
|
|
550
553
|
if (!r)
|
|
551
554
|
return;
|
|
552
555
|
if (!r.groups)
|
|
@@ -560,7 +563,7 @@ function ge(s, e, t) {
|
|
|
560
563
|
);
|
|
561
564
|
return { type: e, pkg: n ?? t, id: o };
|
|
562
565
|
}
|
|
563
|
-
const J = ".plj.gz",
|
|
566
|
+
const J = ".plj.gz", P = ".lib.tengo", W = ".sw.json", z = ".as.json", he = ".test.tengo", _ = ".tpl.tengo", q = ".lib.tengo", B = ".sw.json", V = ".as.json", nt = [q, _, B, V];
|
|
564
567
|
function M() {
|
|
565
568
|
return JSON.parse(p.readFileSync("package.json").toString());
|
|
566
569
|
}
|
|
@@ -585,26 +588,26 @@ function ke(s, e, t, r, n = !1) {
|
|
|
585
588
|
}
|
|
586
589
|
return;
|
|
587
590
|
}
|
|
588
|
-
const i = Ee("dist", r), a = $e("dist", r), c = Ne("dist", r), u = Se("dist", r), d = E(i) === "dir",
|
|
589
|
-
if (!d && !
|
|
591
|
+
const i = Ee("dist", r), a = $e("dist", r), c = Ne("dist", r), u = Se("dist", r), d = E(i) === "dir", w = E(a) === "dir", v = E(c) === "dir", y = E(u) === "dir";
|
|
592
|
+
if (!d && !w && !v && !y)
|
|
590
593
|
return;
|
|
591
|
-
const
|
|
592
|
-
if (
|
|
594
|
+
const b = JSON.parse(p.readFileSync(o).toString());
|
|
595
|
+
if (b.name !== t.name) {
|
|
593
596
|
if (E(f.resolve(r, "node_modules")) === "dir" && n)
|
|
594
597
|
throw new Error(
|
|
595
598
|
`nested node_modules is a sign of library dependencies version incompatibility in ${r}`
|
|
596
599
|
);
|
|
597
|
-
d &&
|
|
600
|
+
d && it(s, b, "dist", i, e), w && at(s, b, "dist", a, e), v && lt(s, b, "dist", c, e), y && ct(s, b, "dist", u, e);
|
|
598
601
|
}
|
|
599
602
|
}
|
|
600
|
-
function
|
|
603
|
+
function it(s, e, t, r, n) {
|
|
601
604
|
for (const o of p.readdirSync(r)) {
|
|
602
605
|
const i = f.resolve(r, o);
|
|
603
|
-
if (!o.endsWith(
|
|
606
|
+
if (!o.endsWith(P)) throw new Error(`unexpected file in 'lib' folder: ${i}`);
|
|
604
607
|
const a = {
|
|
605
608
|
type: "library",
|
|
606
609
|
pkg: e.name,
|
|
607
|
-
id: o.slice(0, o.length -
|
|
610
|
+
id: o.slice(0, o.length - P.length),
|
|
608
611
|
version: e.version
|
|
609
612
|
}, c = ve(s, t, i, a, !0);
|
|
610
613
|
if (n.addLib(c), s.debug(`Adding dependency ${m(a)} from ${i}`), c.dependencies.length > 0) {
|
|
@@ -613,7 +616,7 @@ function ct(s, e, t, r, n) {
|
|
|
613
616
|
}
|
|
614
617
|
}
|
|
615
618
|
}
|
|
616
|
-
function
|
|
619
|
+
function at(s, e, t, r, n) {
|
|
617
620
|
for (const o of p.readdirSync(r)) {
|
|
618
621
|
const i = f.resolve(r, o);
|
|
619
622
|
if (!o.endsWith(J)) throw new Error(`unexpected file in 'tpl' folder: ${i}`);
|
|
@@ -626,29 +629,29 @@ function dt(s, e, t, r, n) {
|
|
|
626
629
|
n.addTemplate(c), s.debug(`Adding dependency ${m(a)} from ${i}`);
|
|
627
630
|
}
|
|
628
631
|
}
|
|
629
|
-
function
|
|
632
|
+
function lt(s, e, t, r, n) {
|
|
630
633
|
for (const o of p.readdirSync(r)) {
|
|
631
634
|
const i = f.resolve(r, o);
|
|
632
|
-
if (!o.endsWith(
|
|
635
|
+
if (!o.endsWith(W))
|
|
633
636
|
throw new Error(`unexpected file in 'software' folder: ${i}`);
|
|
634
637
|
const a = {
|
|
635
638
|
type: "software",
|
|
636
639
|
pkg: e.name,
|
|
637
|
-
id: o.slice(0, o.length -
|
|
640
|
+
id: o.slice(0, o.length - W.length),
|
|
638
641
|
version: e.version
|
|
639
642
|
}, c = new oe(t, a, p.readFileSync(i).toString(), i, [], []);
|
|
640
643
|
s.debug(`Adding dependency ${m(a)} from ${i}`), n.addSoftware(c);
|
|
641
644
|
}
|
|
642
645
|
}
|
|
643
|
-
function
|
|
646
|
+
function ct(s, e, t, r, n) {
|
|
644
647
|
for (const o of p.readdirSync(r)) {
|
|
645
648
|
const i = f.resolve(r, o);
|
|
646
|
-
if (!o.endsWith(
|
|
649
|
+
if (!o.endsWith(z))
|
|
647
650
|
throw new Error(`unexpected file in 'asset' folder: ${i}`);
|
|
648
651
|
const a = {
|
|
649
652
|
type: "asset",
|
|
650
653
|
pkg: e.name,
|
|
651
|
-
id: o.slice(0, o.length -
|
|
654
|
+
id: o.slice(0, o.length - z.length),
|
|
652
655
|
version: e.version
|
|
653
656
|
}, c = new oe(t, a, p.readFileSync(i).toString(), i, [], []);
|
|
654
657
|
s.debug(`Adding dependency ${m(a)} from ${i}`), n.addAsset(c);
|
|
@@ -659,29 +662,29 @@ function L(s, e, t, r, n) {
|
|
|
659
662
|
for (const i of p.readdirSync(f.join(r, n))) {
|
|
660
663
|
const a = f.join(n, i), c = f.join(r, a);
|
|
661
664
|
if (E(c) === "dir") {
|
|
662
|
-
const
|
|
663
|
-
o.push(...
|
|
665
|
+
const y = L(s, e, t, r, a);
|
|
666
|
+
o.push(...y);
|
|
664
667
|
continue;
|
|
665
668
|
}
|
|
666
|
-
const u = i === "index.lib.tengo" ? `${f.dirname(a)}.lib.tengo` : a, d =
|
|
669
|
+
const u = i === "index.lib.tengo" ? `${f.dirname(a)}.lib.tengo` : a, d = dt(e, u.replaceAll(f.sep, "."));
|
|
667
670
|
if (!d)
|
|
668
671
|
continue;
|
|
669
|
-
const
|
|
670
|
-
s.debug(`Parsing ${m(d)} from ${
|
|
671
|
-
const
|
|
672
|
-
if (
|
|
672
|
+
const w = f.resolve(r, a);
|
|
673
|
+
s.debug(`Parsing ${m(d)} from ${w}`);
|
|
674
|
+
const v = ve(s, t, w, d, !0);
|
|
675
|
+
if (v.dependencies.length > 0) {
|
|
673
676
|
s.debug("Detected dependencies:");
|
|
674
|
-
for (const
|
|
677
|
+
for (const y of v.dependencies) s.debug(` - ${g(y)}`);
|
|
675
678
|
}
|
|
676
|
-
o.push(
|
|
679
|
+
o.push(v);
|
|
677
680
|
}
|
|
678
681
|
return o;
|
|
679
682
|
}
|
|
680
683
|
function re(s, e, t) {
|
|
681
|
-
const r = new
|
|
682
|
-
return ke(s, r, e,
|
|
684
|
+
const r = new ze(t);
|
|
685
|
+
return ke(s, r, e, Ie()), r;
|
|
683
686
|
}
|
|
684
|
-
function
|
|
687
|
+
function dt(s, e) {
|
|
685
688
|
const t = { pkg: s.name, version: s.version };
|
|
686
689
|
return e.endsWith(q) ? {
|
|
687
690
|
...t,
|
|
@@ -705,11 +708,11 @@ function ut(s, e) {
|
|
|
705
708
|
type: "test"
|
|
706
709
|
} : null;
|
|
707
710
|
}
|
|
708
|
-
function
|
|
711
|
+
function ft(s, e) {
|
|
709
712
|
const t = M(), r = re(s, t, e), n = L(s, t, e, "src", "");
|
|
710
713
|
if (n.length === 0) {
|
|
711
714
|
const i = [];
|
|
712
|
-
for (const a of
|
|
715
|
+
for (const a of nt)
|
|
713
716
|
i.push(`*${a}`);
|
|
714
717
|
s.error(`Nothing to compile. Looked for ${i.join(", ")}`), process.exit(1);
|
|
715
718
|
}
|
|
@@ -717,12 +720,12 @@ function mt(s, e) {
|
|
|
717
720
|
const o = r.compileAndAdd(n);
|
|
718
721
|
return s.debug("Done."), o;
|
|
719
722
|
}
|
|
720
|
-
function
|
|
723
|
+
function pt(s, e, t) {
|
|
721
724
|
if (e.libs.length > 0) {
|
|
722
725
|
const r = Ee(t, ".");
|
|
723
726
|
p.mkdirSync(r, { recursive: !0 });
|
|
724
727
|
for (const n of e.libs) {
|
|
725
|
-
const o = f.resolve(r, n.fullName.id +
|
|
728
|
+
const o = f.resolve(r, n.fullName.id + P);
|
|
726
729
|
s.info(` - writing ${o}`), p.writeFileSync(o, n.src);
|
|
727
730
|
}
|
|
728
731
|
}
|
|
@@ -738,7 +741,7 @@ function gt(s, e, t) {
|
|
|
738
741
|
const r = Ne(t, ".");
|
|
739
742
|
p.mkdirSync(r, { recursive: !0 });
|
|
740
743
|
for (const n of e.software) {
|
|
741
|
-
const o = f.resolve(r, n.fullName.id +
|
|
744
|
+
const o = f.resolve(r, n.fullName.id + W);
|
|
742
745
|
s.info(` - writing ${o}`), p.writeFileSync(o, n.src);
|
|
743
746
|
}
|
|
744
747
|
}
|
|
@@ -746,28 +749,28 @@ function gt(s, e, t) {
|
|
|
746
749
|
const r = Se(t, ".");
|
|
747
750
|
p.mkdirSync(r, { recursive: !0 });
|
|
748
751
|
for (const n of e.software) {
|
|
749
|
-
const o = f.resolve(r, n.fullName.id +
|
|
752
|
+
const o = f.resolve(r, n.fullName.id + z);
|
|
750
753
|
s.info(` - writing ${o}`), p.writeFileSync(o, n.src);
|
|
751
754
|
}
|
|
752
755
|
}
|
|
753
756
|
}
|
|
754
757
|
const ne = {
|
|
755
|
-
"log-level":
|
|
758
|
+
"log-level": F.string({
|
|
756
759
|
description: "logging level",
|
|
757
760
|
default: "info",
|
|
758
761
|
options: ["error", "warn", "info", "debug"]
|
|
759
762
|
})
|
|
760
|
-
},
|
|
761
|
-
"generate-tags":
|
|
763
|
+
}, ut = {
|
|
764
|
+
"generate-tags": F.boolean({
|
|
762
765
|
description: "generate tags, default false",
|
|
763
766
|
default: !1
|
|
764
767
|
}),
|
|
765
|
-
"tags-file":
|
|
768
|
+
"tags-file": F.file({
|
|
766
769
|
description: 'where to put ".tags" file, it should be a root of VS Code project',
|
|
767
770
|
default: "../../.tags"
|
|
768
771
|
// usually a user opens a directory with all blocks
|
|
769
772
|
}),
|
|
770
|
-
"tags-additional-args":
|
|
773
|
+
"tags-additional-args": F.string({
|
|
771
774
|
description: "additional flags for universal-ctags command: e.g. -e for emacs",
|
|
772
775
|
default: [],
|
|
773
776
|
multiple: !0,
|
|
@@ -775,8 +778,8 @@ const ne = {
|
|
|
775
778
|
})
|
|
776
779
|
}, A = class A extends $ {
|
|
777
780
|
async run() {
|
|
778
|
-
const { flags: e } = await this.parse(A), t = N(e["log-level"]), r = M(), n =
|
|
779
|
-
|
|
781
|
+
const { flags: e } = await this.parse(A), t = N(e["log-level"]), r = M(), n = ft(t, "dist");
|
|
782
|
+
pt(t, n, "dist"), t.info("");
|
|
780
783
|
let o = `declare type TemplateFromFile = { readonly type: "from-file"; readonly path: string; };
|
|
781
784
|
`;
|
|
782
785
|
o += `declare type TplName = ${n.templates.map((d) => '"' + d.fullName.id + '"').join(" | ")};
|
|
@@ -798,25 +801,25 @@ export const Templates = {
|
|
|
798
801
|
}};
|
|
799
802
|
`, a += `
|
|
800
803
|
};
|
|
801
|
-
`, await x.writeFile("dist/index.d.ts", o), r.type === "module" ? (await x.writeFile("dist/index.cjs", i), await x.writeFile("dist/index.js", a)) : (await x.writeFile("dist/index.js", i), await x.writeFile("dist/index.mjs", a)),
|
|
804
|
+
`, await x.writeFile("dist/index.d.ts", o), r.type === "module" ? (await x.writeFile("dist/index.cjs", i), await x.writeFile("dist/index.js", a)) : (await x.writeFile("dist/index.js", i), await x.writeFile("dist/index.mjs", a)), mt(e), e["generate-tags"] && gt(t, e), t.info("Template Pack build done.");
|
|
802
805
|
}
|
|
803
806
|
};
|
|
804
807
|
l(A, "description", "build tengo sources into single distributable pack file"), l(A, "examples", ["<%= config.bin %> <%= command.id %>"]), l(A, "flags", {
|
|
805
808
|
...ne,
|
|
806
|
-
...
|
|
809
|
+
...ut
|
|
807
810
|
});
|
|
808
811
|
let Z = A;
|
|
809
|
-
function
|
|
812
|
+
function mt(s) {
|
|
810
813
|
process.env.GENERATE_TAGS != null && (s["generate-tags"] = process.env.GENERATE_TAGS == "true"), process.env.TAGS_FILE != null && (s["tags-file"] = process.env.TAGS_FILE), process.env.TAGS_ADDITIONAL_ARGS != null && (s["tags-additional-args"] = process.env.TAGS_ADDITIONAL_ARGS.split(","));
|
|
811
814
|
}
|
|
812
|
-
function
|
|
815
|
+
function gt(s, e) {
|
|
813
816
|
var a;
|
|
814
|
-
const t = f.resolve(e["tags-file"]), r = f.dirname(t), n = e["tags-additional-args"], o =
|
|
817
|
+
const t = f.resolve(e["tags-file"]), r = f.dirname(t), n = e["tags-additional-args"], o = ht(r);
|
|
815
818
|
s.info(
|
|
816
|
-
`Generating tags for tengo autocompletion from "${r}" in "${t}", additional arguments: "${n}".
|
|
819
|
+
`Generating tags for tengo autocompletion from "${r}" in "${t}", additional arguments: "${n.join('" "')}".
|
|
817
820
|
Found ${o.length} tengo files...`
|
|
818
821
|
);
|
|
819
|
-
const i =
|
|
822
|
+
const i = Oe(
|
|
820
823
|
"ctags",
|
|
821
824
|
[
|
|
822
825
|
"-f",
|
|
@@ -848,9 +851,9 @@ For vscode, you should also install ctags extension:
|
|
|
848
851
|
https://marketplace.visualstudio.com/items?itemName=jaydenlin.ctags-support`);
|
|
849
852
|
return;
|
|
850
853
|
}
|
|
851
|
-
|
|
854
|
+
wt(i, "failed to generate ctags"), s.info("Generation of tags is done.");
|
|
852
855
|
}
|
|
853
|
-
function
|
|
856
|
+
function ht(s) {
|
|
854
857
|
const e = p.readdirSync(s, { withFileTypes: !0, recursive: !0 }), t = [];
|
|
855
858
|
return e.forEach((r) => {
|
|
856
859
|
if (!r.isDirectory() && r.name.endsWith(".tengo")) {
|
|
@@ -859,7 +862,7 @@ function bt(s) {
|
|
|
859
862
|
}
|
|
860
863
|
}), t;
|
|
861
864
|
}
|
|
862
|
-
function
|
|
865
|
+
function wt(s, e) {
|
|
863
866
|
s.error && console.log(s.error);
|
|
864
867
|
const t = e;
|
|
865
868
|
s.status !== 0 && console.log(`WARN: ${t} the build will continue as-is`);
|
|
@@ -912,7 +915,7 @@ function ie(s, e) {
|
|
|
912
915
|
), e.write(JSON.stringify(o) + `
|
|
913
916
|
`));
|
|
914
917
|
}
|
|
915
|
-
function
|
|
918
|
+
function yt(s, e, t) {
|
|
916
919
|
const r = M(), n = L(s, r, "dist", "src", "");
|
|
917
920
|
if (!e) {
|
|
918
921
|
for (const i of n)
|
|
@@ -933,16 +936,16 @@ function C(s, e, t) {
|
|
|
933
936
|
o.fullName.type === t && e.write(JSON.stringify(o) + `
|
|
934
937
|
`);
|
|
935
938
|
}
|
|
936
|
-
function
|
|
939
|
+
function bt(s, e) {
|
|
937
940
|
C(s, e, "template");
|
|
938
941
|
}
|
|
939
|
-
function
|
|
942
|
+
function vt(s, e) {
|
|
940
943
|
C(s, e, "software");
|
|
941
944
|
}
|
|
942
|
-
function
|
|
945
|
+
function Et(s, e) {
|
|
943
946
|
C(s, e, "asset");
|
|
944
947
|
}
|
|
945
|
-
function
|
|
948
|
+
function $t(s, e) {
|
|
946
949
|
C(s, e, "test");
|
|
947
950
|
}
|
|
948
951
|
function Ae(s, ...e) {
|
|
@@ -1023,37 +1026,37 @@ l(Y, "description", "parse sources in current package and dump all found artifac
|
|
|
1023
1026
|
class H extends $ {
|
|
1024
1027
|
async run() {
|
|
1025
1028
|
const e = N();
|
|
1026
|
-
|
|
1029
|
+
Et(e, D);
|
|
1027
1030
|
}
|
|
1028
1031
|
}
|
|
1029
|
-
l(H, "description", "parse sources in current package and dump all found
|
|
1032
|
+
l(H, "description", "parse sources in current package and dump all found assets to stdout"), l(H, "examples", [
|
|
1030
1033
|
"<%= config.bin %> <%= command.id %>"
|
|
1031
1034
|
]);
|
|
1032
1035
|
const T = class T extends $ {
|
|
1033
1036
|
async run() {
|
|
1034
1037
|
const { flags: e } = await this.parse(T), t = N();
|
|
1035
|
-
|
|
1038
|
+
yt(t, e.deps, D);
|
|
1036
1039
|
}
|
|
1037
1040
|
};
|
|
1038
|
-
l(T, "description", "parse sources in current package and dump all found
|
|
1041
|
+
l(T, "description", "parse sources in current package and dump all found libs to stdout"), l(T, "examples", [
|
|
1039
1042
|
"<%= config.bin %> <%= command.id %>"
|
|
1040
1043
|
]), l(T, "flags", {
|
|
1041
|
-
deps:
|
|
1044
|
+
deps: F.boolean({ name: "deps", description: "add also all libraries found in node_modules" })
|
|
1042
1045
|
});
|
|
1043
1046
|
let Q = T;
|
|
1044
1047
|
class ee extends $ {
|
|
1045
1048
|
async run() {
|
|
1046
1049
|
const e = N();
|
|
1047
|
-
|
|
1050
|
+
vt(e, D);
|
|
1048
1051
|
}
|
|
1049
1052
|
}
|
|
1050
|
-
l(ee, "description", "parse sources in current package and dump all found
|
|
1053
|
+
l(ee, "description", "parse sources in current package and dump all found software to stdout"), l(ee, "examples", [
|
|
1051
1054
|
"<%= config.bin %> <%= command.id %>"
|
|
1052
1055
|
]);
|
|
1053
1056
|
class te extends $ {
|
|
1054
1057
|
async run() {
|
|
1055
1058
|
const e = N();
|
|
1056
|
-
|
|
1059
|
+
bt(e, D);
|
|
1057
1060
|
}
|
|
1058
1061
|
}
|
|
1059
1062
|
l(te, "description", "parse sources in current package and dump all found templates to stdout"), l(te, "examples", [
|
|
@@ -1062,13 +1065,13 @@ l(te, "description", "parse sources in current package and dump all found templa
|
|
|
1062
1065
|
class se extends $ {
|
|
1063
1066
|
async run() {
|
|
1064
1067
|
const e = N();
|
|
1065
|
-
|
|
1068
|
+
$t(e, D);
|
|
1066
1069
|
}
|
|
1067
1070
|
}
|
|
1068
1071
|
l(se, "description", "parse sources in current package and dump all found tests to stdout"), l(se, "examples", [
|
|
1069
1072
|
"<%= config.bin %> <%= command.id %>"
|
|
1070
1073
|
]);
|
|
1071
|
-
const
|
|
1074
|
+
const Ot = {
|
|
1072
1075
|
build: Z,
|
|
1073
1076
|
check: K,
|
|
1074
1077
|
test: X,
|
|
@@ -1080,6 +1083,6 @@ const jt = {
|
|
|
1080
1083
|
"dump:tests": se
|
|
1081
1084
|
};
|
|
1082
1085
|
export {
|
|
1083
|
-
|
|
1086
|
+
Ot as COMMANDS
|
|
1084
1087
|
};
|
|
1085
1088
|
//# sourceMappingURL=index.mjs.map
|