@platforma-sdk/tengo-builder 1.14.12 → 1.15.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/dump/assets.d.ts +7 -0
- package/dist/commands/dump/assets.d.ts.map +1 -0
- package/dist/compiler/compiler.d.ts +6 -0
- package/dist/compiler/compiler.d.ts.map +1 -1
- package/dist/compiler/main.d.ts.map +1 -1
- package/dist/compiler/package.d.ts +1 -1
- package/dist/compiler/package.d.ts.map +1 -1
- package/dist/compiler/source.d.ts.map +1 -1
- package/dist/compiler/template.d.ts +10 -0
- package/dist/compiler/template.d.ts.map +1 -1
- package/dist/compiler/test.artifacts.d.ts +2 -1
- package/dist/compiler/test.artifacts.d.ts.map +1 -1
- package/dist/index.d.ts +20 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +451 -370
- package/dist/index.mjs.map +1 -1
- package/dist/shared/dump.d.ts +1 -0
- package/dist/shared/dump.d.ts.map +1 -1
- package/package.json +7 -6
- package/src/commands/dump/assets.ts +17 -0
- package/src/compiler/compiler.ts +51 -1
- package/src/compiler/main.ts +48 -2
- package/src/compiler/package.ts +1 -1
- package/src/compiler/source.test.ts +15 -8
- package/src/compiler/source.ts +5 -1
- package/src/compiler/template.test.ts +2 -0
- package/src/compiler/template.ts +11 -0
- package/src/compiler/test.artifacts.ts +9 -1
- package/src/index.ts +24 -1
- package/src/shared/dump.ts +40 -21
- package/dist/commands/index.d.ts +0 -19
- package/dist/commands/index.d.ts.map +0 -1
- package/src/commands/index.ts +0 -21
package/dist/index.mjs
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var l = (t, e, r) =>
|
|
4
|
-
import { spawnSync as
|
|
5
|
-
import { Flags as
|
|
1
|
+
var Te = Object.defineProperty;
|
|
2
|
+
var xe = (t, e, r) => e in t ? Te(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
3
|
+
var l = (t, e, r) => xe(t, typeof e != "symbol" ? e + "" : e, r);
|
|
4
|
+
import { spawnSync as De, spawn as Fe } from "node:child_process";
|
|
5
|
+
import { Flags as M, Command as v } from "@oclif/core";
|
|
6
6
|
import * as f from "node:path";
|
|
7
|
-
import * as
|
|
8
|
-
import { readFileSync as
|
|
9
|
-
import { gunzipSync as
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import * as
|
|
13
|
-
import { TengoTesterBinaryPath as
|
|
14
|
-
import { stdout as
|
|
7
|
+
import * as p from "node:fs";
|
|
8
|
+
import { readFileSync as Me } from "node:fs";
|
|
9
|
+
import { gunzipSync as Oe, gzipSync as Re } from "node:zlib";
|
|
10
|
+
import je from "canonicalize";
|
|
11
|
+
import J from "winston";
|
|
12
|
+
import * as F from "node:fs/promises";
|
|
13
|
+
import { TengoTesterBinaryPath as ge } from "@milaboratories/tengo-tester";
|
|
14
|
+
import { stdout as x } from "node:process";
|
|
15
15
|
function O(t) {
|
|
16
16
|
throw new Error("Unexpected object: " + t);
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function Le() {
|
|
19
19
|
let t = process.cwd();
|
|
20
20
|
for (; t; ) {
|
|
21
21
|
const e = f.join(t, "node_modules");
|
|
22
|
-
if (
|
|
22
|
+
if (p.existsSync(e)) return e;
|
|
23
23
|
const r = f.resolve(t, "..");
|
|
24
24
|
if (r === t) break;
|
|
25
25
|
t = r;
|
|
26
26
|
}
|
|
27
27
|
throw new Error("Unable to find node_modules directory.");
|
|
28
28
|
}
|
|
29
|
-
function
|
|
29
|
+
function $(t) {
|
|
30
30
|
try {
|
|
31
|
-
const e =
|
|
31
|
+
const e = p.statSync(t);
|
|
32
32
|
return e.isDirectory() ? "dir" : e.isFile() ? "file" : e.isSymbolicLink() ? "link" : "unknown";
|
|
33
33
|
} catch (e) {
|
|
34
34
|
if (e.code == "ENOENT") return "absent";
|
|
35
35
|
throw e;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function ae(t) {
|
|
39
39
|
return `${t.type}||${t.pkg}||${t.id}`;
|
|
40
40
|
}
|
|
41
41
|
function m(t) {
|
|
@@ -44,58 +44,58 @@ function m(t) {
|
|
|
44
44
|
function g(t) {
|
|
45
45
|
return `${t.type}:${t.pkg}:${t.id}`;
|
|
46
46
|
}
|
|
47
|
-
function
|
|
47
|
+
function le(t, e) {
|
|
48
48
|
return t.type == e.type && t.pkg == e.pkg && t.id == e.id;
|
|
49
49
|
}
|
|
50
|
-
function
|
|
50
|
+
function h(t) {
|
|
51
51
|
return `${t.pkg}:${t.id}`;
|
|
52
52
|
}
|
|
53
|
-
function
|
|
54
|
-
return { name:
|
|
53
|
+
function I(t) {
|
|
54
|
+
return { name: h(t), version: t.version };
|
|
55
55
|
}
|
|
56
|
-
function
|
|
56
|
+
function Ie(t) {
|
|
57
57
|
const e = t.name.match(/^(?<pkg>[^:]*):(?<id>[^:]*)$/);
|
|
58
58
|
if (!e)
|
|
59
59
|
throw new Error(`malformed artifact name: ${t.name}`);
|
|
60
60
|
return { pkg: e.groups.pkg, id: e.groups.id, version: t.version };
|
|
61
61
|
}
|
|
62
|
-
function
|
|
62
|
+
function ce(t) {
|
|
63
63
|
return `${t.pkg}:${t.id}:${t.version}`;
|
|
64
64
|
}
|
|
65
|
-
const
|
|
66
|
-
class
|
|
67
|
-
constructor(e, r,
|
|
65
|
+
const Ce = new TextDecoder(), Ge = new TextEncoder();
|
|
66
|
+
class he {
|
|
67
|
+
constructor(e, r, o) {
|
|
68
68
|
l(this, "data");
|
|
69
69
|
l(this, "content");
|
|
70
70
|
this.compileMode = e, this.fullName = r;
|
|
71
|
-
let { data: n, content:
|
|
72
|
-
if (n === void 0 &&
|
|
71
|
+
let { data: n, content: s } = o;
|
|
72
|
+
if (n === void 0 && s === void 0)
|
|
73
73
|
throw new Error("Neither data nor content is provided for template constructor");
|
|
74
|
-
if (n !== void 0 &&
|
|
74
|
+
if (n !== void 0 && s !== void 0)
|
|
75
75
|
throw new Error("Both data and content are provided for template constructor");
|
|
76
|
-
if (n === void 0 && (n = JSON.parse(
|
|
76
|
+
if (n === void 0 && (n = JSON.parse(Ce.decode(Oe(s))), n.type !== "pl.tengo-template.v2"))
|
|
77
77
|
throw new Error("malformed template");
|
|
78
|
-
|
|
79
|
-
const i =
|
|
78
|
+
s === void 0 && (s = Re(Ge.encode(je(n))));
|
|
79
|
+
const i = Ie(n);
|
|
80
80
|
if (i.pkg !== r.pkg || i.id !== r.id || i.version !== r.version)
|
|
81
|
-
throw new Error(`Compiled template name don't match it's package and file names: ${
|
|
82
|
-
this.data = n, this.content =
|
|
81
|
+
throw new Error(`Compiled template name don't match it's package and file names: ${ce(i)} != ${ce(r)}`);
|
|
82
|
+
this.data = n, this.content = s;
|
|
83
83
|
}
|
|
84
84
|
toJSON() {
|
|
85
85
|
return { compileMode: this.compileMode, fullName: this.fullName, data: this.data };
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
class
|
|
88
|
+
class z {
|
|
89
89
|
constructor(e) {
|
|
90
90
|
l(this, "map", /* @__PURE__ */ new Map());
|
|
91
91
|
this.nameExtractor = e;
|
|
92
92
|
}
|
|
93
93
|
add(e, r = !0) {
|
|
94
|
-
const
|
|
95
|
-
return n && !r || this.map.set(
|
|
94
|
+
const o = ae(this.nameExtractor(e)), n = this.map.get(o);
|
|
95
|
+
return n && !r || this.map.set(o, e), n;
|
|
96
96
|
}
|
|
97
97
|
get(e) {
|
|
98
|
-
return this.map.get(
|
|
98
|
+
return this.map.get(ae(e));
|
|
99
99
|
}
|
|
100
100
|
get array() {
|
|
101
101
|
const e = [];
|
|
@@ -105,19 +105,19 @@ class C {
|
|
|
105
105
|
this.map.forEach((r) => e(r, this.nameExtractor(r)));
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
function
|
|
109
|
-
return new
|
|
108
|
+
function Je() {
|
|
109
|
+
return new z((t) => t);
|
|
110
110
|
}
|
|
111
|
-
class
|
|
111
|
+
class C {
|
|
112
112
|
constructor(e) {
|
|
113
113
|
l(this, "dev");
|
|
114
114
|
l(this, "dist");
|
|
115
|
-
this.nameExtractor = e, this.dev = new
|
|
115
|
+
this.nameExtractor = e, this.dev = new z(e), this.dist = new z(e);
|
|
116
116
|
}
|
|
117
|
-
add(e, r,
|
|
117
|
+
add(e, r, o = !0) {
|
|
118
118
|
switch (e) {
|
|
119
119
|
case "dist":
|
|
120
|
-
return this.dist.add(r,
|
|
120
|
+
return this.dist.add(r, o);
|
|
121
121
|
default:
|
|
122
122
|
O(e);
|
|
123
123
|
}
|
|
@@ -132,52 +132,60 @@ class I {
|
|
|
132
132
|
}
|
|
133
133
|
array(e) {
|
|
134
134
|
const r = [];
|
|
135
|
-
return this.forEach(e, (
|
|
135
|
+
return this.forEach(e, (o) => r.push(o)), r;
|
|
136
136
|
}
|
|
137
137
|
forEach(e, r) {
|
|
138
|
-
this.dist.forEach((
|
|
138
|
+
this.dist.forEach((o, n) => r(this.get(e, n) ?? o, n));
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
|
-
class
|
|
141
|
+
class ze {
|
|
142
142
|
constructor(e) {
|
|
143
|
-
l(this, "libs", new
|
|
144
|
-
l(this, "software", new
|
|
145
|
-
l(this, "
|
|
143
|
+
l(this, "libs", new C((e) => e.fullName));
|
|
144
|
+
l(this, "software", new C((e) => e.fullName));
|
|
145
|
+
l(this, "assets", new C((e) => e.fullName));
|
|
146
|
+
l(this, "templates", new C((e) => e.fullName));
|
|
146
147
|
this.compileMode = e;
|
|
147
148
|
}
|
|
148
|
-
populateTemplateDataFromDependencies(e, r,
|
|
149
|
-
for (const
|
|
150
|
-
switch (
|
|
149
|
+
populateTemplateDataFromDependencies(e, r, o, n) {
|
|
150
|
+
for (const s of o)
|
|
151
|
+
switch (s.type) {
|
|
151
152
|
case "library":
|
|
152
|
-
const i = this.getLibOrError(
|
|
153
|
+
const i = this.getLibOrError(s), a = n.indexOf(h(s));
|
|
153
154
|
if (a >= 0) {
|
|
154
|
-
let
|
|
155
|
-
throw new Error(
|
|
155
|
+
let y = `library import recursion detected: ${n.slice(a).join(" -> ")} -> ${h(s)}`;
|
|
156
|
+
throw new Error(y);
|
|
156
157
|
}
|
|
157
|
-
r.libs[
|
|
158
|
-
...
|
|
158
|
+
r.libs[h(s)] = {
|
|
159
|
+
...I(i.fullName),
|
|
159
160
|
src: i.src
|
|
160
|
-
}, this.populateTemplateDataFromDependencies(e, r, i.dependencies, [...n,
|
|
161
|
+
}, this.populateTemplateDataFromDependencies(e, r, i.dependencies, [...n, h(s)]);
|
|
161
162
|
break;
|
|
162
163
|
case "software":
|
|
163
|
-
const c = this.getSoftwareOrError(
|
|
164
|
-
r.software[
|
|
165
|
-
...
|
|
164
|
+
const c = this.getSoftwareOrError(s);
|
|
165
|
+
r.software[h(s)] = {
|
|
166
|
+
...I(c.fullName),
|
|
166
167
|
src: c.src
|
|
167
168
|
};
|
|
168
169
|
break;
|
|
170
|
+
case "asset":
|
|
171
|
+
const d = this.getAssetOrError(s);
|
|
172
|
+
r.software[h(s)] = {
|
|
173
|
+
...I(d.fullName),
|
|
174
|
+
src: d.src
|
|
175
|
+
};
|
|
176
|
+
break;
|
|
169
177
|
case "template":
|
|
170
|
-
if (
|
|
178
|
+
if (le(e, s))
|
|
171
179
|
continue;
|
|
172
|
-
const
|
|
173
|
-
r.templates[
|
|
180
|
+
const u = this.getTemplateOrError(s);
|
|
181
|
+
r.templates[h(s)] = u.data;
|
|
174
182
|
break;
|
|
175
183
|
case "test":
|
|
176
184
|
throw new Error(
|
|
177
|
-
`dependencies tree error: tests should never be part of template: ${g(
|
|
185
|
+
`dependencies tree error: tests should never be part of template: ${g(s)} is dependency of ${h(e)}`
|
|
178
186
|
);
|
|
179
187
|
default:
|
|
180
|
-
O(
|
|
188
|
+
O(s.type);
|
|
181
189
|
}
|
|
182
190
|
}
|
|
183
191
|
/** This method assumes that all dependencies are already added to the compiler's context */
|
|
@@ -186,15 +194,16 @@ class Le {
|
|
|
186
194
|
throw new Error("unexpected source type");
|
|
187
195
|
const r = {
|
|
188
196
|
type: "pl.tengo-template.v2",
|
|
189
|
-
...
|
|
197
|
+
...I(e.fullName),
|
|
190
198
|
templates: {},
|
|
191
199
|
libs: {},
|
|
192
200
|
software: {},
|
|
201
|
+
assets: {},
|
|
193
202
|
src: e.src
|
|
194
203
|
};
|
|
195
204
|
this.populateTemplateDataFromDependencies(e.fullName, r, e.dependencies, []);
|
|
196
|
-
const
|
|
197
|
-
return this.addTemplate(
|
|
205
|
+
const o = new he(e.compileMode, e.fullName, { data: r });
|
|
206
|
+
return this.addTemplate(o), o;
|
|
198
207
|
}
|
|
199
208
|
addLib(e) {
|
|
200
209
|
const r = this.libs.add(e.compileMode, e, !1);
|
|
@@ -214,7 +223,7 @@ class Le {
|
|
|
214
223
|
getLibOrError(e) {
|
|
215
224
|
const r = this.getLib(e);
|
|
216
225
|
if (!r)
|
|
217
|
-
throw new Error(`library not found: ${
|
|
226
|
+
throw new Error(`library not found: ${h(e)}`);
|
|
218
227
|
return r;
|
|
219
228
|
}
|
|
220
229
|
addSoftware(e) {
|
|
@@ -235,7 +244,28 @@ class Le {
|
|
|
235
244
|
getSoftwareOrError(e) {
|
|
236
245
|
const r = this.getSoftware(e);
|
|
237
246
|
if (!r)
|
|
238
|
-
throw new Error(`software info not found: ${
|
|
247
|
+
throw new Error(`software info not found: ${h(e)}`);
|
|
248
|
+
return r;
|
|
249
|
+
}
|
|
250
|
+
addAsset(e) {
|
|
251
|
+
const r = this.assets.add(e.compileMode, e, !1);
|
|
252
|
+
if (r)
|
|
253
|
+
throw new Error(
|
|
254
|
+
`compiler already contain info for asset: adding = ${m(e.fullName)}, contains = ${m(r.fullName)}`
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
allAssets() {
|
|
258
|
+
return this.assets.array(this.compileMode);
|
|
259
|
+
}
|
|
260
|
+
getAsset(e) {
|
|
261
|
+
if (e.type !== "asset")
|
|
262
|
+
throw new Error(`illegal artifact type: got ${e.type} instead of 'asset`);
|
|
263
|
+
return this.assets.get(this.compileMode, e);
|
|
264
|
+
}
|
|
265
|
+
getAssetOrError(e) {
|
|
266
|
+
const r = this.getAsset(e);
|
|
267
|
+
if (!r)
|
|
268
|
+
throw new Error(`asset info not found: ${h(e)}`);
|
|
239
269
|
return r;
|
|
240
270
|
}
|
|
241
271
|
addTemplate(e) {
|
|
@@ -256,7 +286,7 @@ class Le {
|
|
|
256
286
|
getTemplateOrError(e) {
|
|
257
287
|
const r = this.getTemplate(e);
|
|
258
288
|
if (!r)
|
|
259
|
-
throw new Error(`template not found: ${
|
|
289
|
+
throw new Error(`template not found: ${h(e)}`);
|
|
260
290
|
return r;
|
|
261
291
|
}
|
|
262
292
|
getArtefact(e) {
|
|
@@ -267,6 +297,8 @@ class Le {
|
|
|
267
297
|
return this.getLib(e);
|
|
268
298
|
case "software":
|
|
269
299
|
return this.getSoftware(e);
|
|
300
|
+
case "asset":
|
|
301
|
+
return this.getAsset(e);
|
|
270
302
|
case "test":
|
|
271
303
|
return;
|
|
272
304
|
default:
|
|
@@ -284,79 +316,82 @@ class Le {
|
|
|
284
316
|
});
|
|
285
317
|
}
|
|
286
318
|
compileAndAdd(e) {
|
|
287
|
-
const r = { templates: [], libs: [], software: [] };
|
|
288
|
-
let
|
|
319
|
+
const r = { templates: [], libs: [], software: [], assets: [] };
|
|
320
|
+
let o = [];
|
|
289
321
|
for (const n of e)
|
|
290
|
-
n.fullName.type === "library" ? (this.addLib(n), r.libs.push(n)) : n.fullName.type === "software" ? (this.addSoftware(n), r.software.push(n)) :
|
|
291
|
-
for (;
|
|
322
|
+
n.fullName.type === "library" ? (this.addLib(n), r.libs.push(n)) : n.fullName.type === "software" ? (this.addSoftware(n), r.software.push(n)) : n.fullName.type === "asset" ? (this.addAsset(n), r.assets.push(n)) : o.push(n);
|
|
323
|
+
for (; o.length > 0; ) {
|
|
292
324
|
const n = [];
|
|
293
|
-
for (const
|
|
294
|
-
const i =
|
|
325
|
+
for (const s of o) {
|
|
326
|
+
const i = s.dependencies.filter(
|
|
295
327
|
(a) => !this.getArtefact(a) && // allow self reference for templates
|
|
296
|
-
!(
|
|
328
|
+
!(s.fullName.type === "template" && le(s.fullName, a))
|
|
297
329
|
);
|
|
298
330
|
if (i.length > 0) {
|
|
299
|
-
let a = `Unsatisfied dependencies in ${m(
|
|
331
|
+
let a = `Unsatisfied dependencies in ${m(s.fullName)}:
|
|
300
332
|
`;
|
|
301
333
|
for (const c of i)
|
|
302
334
|
a += ` - ${g(c)}
|
|
303
335
|
`;
|
|
304
|
-
n.push({ src:
|
|
336
|
+
n.push({ src: s, err: Error(a) });
|
|
305
337
|
continue;
|
|
306
338
|
}
|
|
307
|
-
switch (
|
|
339
|
+
switch (s.fullName.type) {
|
|
308
340
|
case "library":
|
|
309
|
-
this.addLib(
|
|
341
|
+
this.addLib(s), r.libs.push(s);
|
|
310
342
|
break;
|
|
311
343
|
case "software":
|
|
312
|
-
this.addSoftware(
|
|
344
|
+
this.addSoftware(s), r.software.push(s);
|
|
345
|
+
break;
|
|
346
|
+
case "asset":
|
|
347
|
+
this.addAsset(s), r.assets.push(s);
|
|
313
348
|
break;
|
|
314
349
|
case "template":
|
|
315
350
|
try {
|
|
316
|
-
const a = this.compileAndAddTemplate(
|
|
351
|
+
const a = this.compileAndAddTemplate(s);
|
|
317
352
|
r.templates.push(a);
|
|
318
353
|
} catch (a) {
|
|
319
|
-
let c = `Unsatisfied dependencies in ${m(
|
|
354
|
+
let c = `Unsatisfied dependencies in ${m(s.fullName)}:
|
|
320
355
|
`;
|
|
321
356
|
c += ` - ${a.message}
|
|
322
|
-
`, n.push({ src:
|
|
357
|
+
`, n.push({ src: s, err: Error(c) });
|
|
323
358
|
}
|
|
324
359
|
break;
|
|
325
360
|
case "test":
|
|
326
361
|
break;
|
|
327
362
|
default:
|
|
328
|
-
O(
|
|
363
|
+
O(s.fullName.type);
|
|
329
364
|
}
|
|
330
365
|
}
|
|
331
|
-
if (
|
|
332
|
-
let
|
|
366
|
+
if (o.length === n.length) {
|
|
367
|
+
let s = "";
|
|
333
368
|
for (const i of n)
|
|
334
|
-
|
|
369
|
+
s += `
|
|
335
370
|
${i.err.message}`;
|
|
336
|
-
throw new Error(
|
|
371
|
+
throw new Error(s);
|
|
337
372
|
}
|
|
338
|
-
|
|
373
|
+
o = n.map(({ src: s }) => s);
|
|
339
374
|
}
|
|
340
375
|
return r;
|
|
341
376
|
}
|
|
342
377
|
}
|
|
343
|
-
const
|
|
378
|
+
const fe = "[_a-zA-Z][_a-zA-Z0-9]*", R = (t, e) => new RegExp(
|
|
344
379
|
`\\b${t}\\.(?<fnCall>(?<fnName>` + e + ')\\s*\\(\\s*"(?<templateName>[^"]+)"\\s*\\))'
|
|
345
|
-
),
|
|
346
|
-
`\\b(?<importName>${
|
|
347
|
-
),
|
|
348
|
-
class
|
|
349
|
-
constructor(e, r,
|
|
350
|
-
this.compileMode = e, this.fullName = r, this.src =
|
|
380
|
+
), We = (t) => R(t, "getTemplateId"), Pe = (t) => R(t, "getSoftwareInfo"), de = (t) => R(t, "importTemplate"), pe = (t) => R(t, "importSoftware"), Ue = (t) => R(t, "importAsset"), qe = /^\s*(\/\/)|(\/\*.*\*\/)/, Be = /^\s*\/\*/, Ve = /\*\//, we = /\s*:=\s*import\s*\(\s*"(?<moduleName>[^"]+)"\s*\)/, Ze = new RegExp(
|
|
381
|
+
`\\b(?<importName>${fe}(\\.${fe})*)${we.source}`
|
|
382
|
+
), Ke = /(?<pkgName>[^"]+)?:(?<depID>[^"]+)/;
|
|
383
|
+
class te {
|
|
384
|
+
constructor(e, r, o, n, s) {
|
|
385
|
+
this.compileMode = e, this.fullName = r, this.src = o, this.srcName = n, this.dependencies = s;
|
|
351
386
|
}
|
|
352
387
|
}
|
|
353
|
-
function
|
|
354
|
-
const n =
|
|
355
|
-
return new
|
|
388
|
+
function ye(t, e, r, o) {
|
|
389
|
+
const n = Me(e).toString(), { deps: s, normalized: i } = Xe(n, r, o);
|
|
390
|
+
return new te(t, r, i, e, s.array);
|
|
356
391
|
}
|
|
357
|
-
function
|
|
358
|
-
const
|
|
359
|
-
`),
|
|
392
|
+
function Xe(t, e, r) {
|
|
393
|
+
const o = Je(), n = t.split(`
|
|
394
|
+
`), s = [];
|
|
360
395
|
let i = {
|
|
361
396
|
isInCommentBlock: !1,
|
|
362
397
|
tplDepREs: /* @__PURE__ */ new Map()
|
|
@@ -364,332 +399,358 @@ function Ue(t, e, r) {
|
|
|
364
399
|
for (const c of n) {
|
|
365
400
|
a++;
|
|
366
401
|
try {
|
|
367
|
-
const d =
|
|
402
|
+
const d = He(
|
|
368
403
|
c,
|
|
369
404
|
i,
|
|
370
405
|
e.pkg,
|
|
371
406
|
r
|
|
372
407
|
);
|
|
373
|
-
|
|
408
|
+
s.push(d.line), i = d.context, d.artifact && o.add(d.artifact);
|
|
374
409
|
} catch (d) {
|
|
375
410
|
throw new Error(`[line ${a}]: ${d.message}
|
|
376
411
|
${c}`);
|
|
377
412
|
}
|
|
378
413
|
}
|
|
379
414
|
return {
|
|
380
|
-
normalized:
|
|
415
|
+
normalized: s.join(`
|
|
381
416
|
`),
|
|
382
|
-
deps:
|
|
417
|
+
deps: o
|
|
383
418
|
};
|
|
384
419
|
}
|
|
385
|
-
function
|
|
420
|
+
function He(t, e, r, o) {
|
|
386
421
|
if (e.isInCommentBlock)
|
|
387
|
-
return
|
|
388
|
-
if (
|
|
422
|
+
return Ve.exec(t) && (e.isInCommentBlock = !1), { line: t, context: e, artifact: void 0 };
|
|
423
|
+
if (qe.exec(t))
|
|
389
424
|
return { line: t, context: e, artifact: void 0 };
|
|
390
|
-
if (
|
|
425
|
+
if (Be.exec(t))
|
|
391
426
|
return e.isInCommentBlock = !0, { line: t, context: e, artifact: void 0 };
|
|
392
|
-
const n =
|
|
427
|
+
const n = we.exec(t);
|
|
393
428
|
if (n) {
|
|
394
|
-
const
|
|
395
|
-
if (
|
|
396
|
-
return e.tplDepREs.has(
|
|
397
|
-
["template",
|
|
398
|
-
["software",
|
|
429
|
+
const s = Qe(t);
|
|
430
|
+
if (s.module === "plapi")
|
|
431
|
+
return e.tplDepREs.has(s.module) || e.tplDepREs.set(s.module, [
|
|
432
|
+
["template", We(s.alias)],
|
|
433
|
+
["software", Pe(s.alias)]
|
|
399
434
|
]), { line: t, context: e, artifact: void 0 };
|
|
400
|
-
(
|
|
401
|
-
["template",
|
|
402
|
-
["software",
|
|
403
|
-
])), (
|
|
404
|
-
["template",
|
|
405
|
-
["software",
|
|
435
|
+
(s.module === "@milaboratory/tengo-sdk:ll" || s.module === "@platforma-sdk/workflow-tengo:ll" || (r === "@milaboratory/tengo-sdk" || r === "@platforma-sdk/workflow-tengo") && s.module === ":ll") && (e.tplDepREs.has(s.module) || e.tplDepREs.set(s.module, [
|
|
436
|
+
["template", de(s.alias)],
|
|
437
|
+
["software", pe(s.alias)]
|
|
438
|
+
])), (s.module === "@milaboratory/tengo-sdk:assets" || s.module === "@platforma-sdk/workflow-tengo:assets" || (r === "@milaboratory/tengo-sdk" || r === "@platforma-sdk/workflow-tengo") && s.module === ":assets") && (e.tplDepREs.has(s.module) || e.tplDepREs.set(s.module, [
|
|
439
|
+
["template", de(s.alias)],
|
|
440
|
+
["software", pe(s.alias)],
|
|
441
|
+
["asset", Ue(s.alias)]
|
|
406
442
|
]));
|
|
407
|
-
const i =
|
|
443
|
+
const i = ue(s.module, "library", r);
|
|
408
444
|
return i ? (t = t.replace(n[0], ` := import("${i.pkg}:${i.id}")`), { line: t, context: e, artifact: i }) : { line: t, context: e, artifact: void 0 };
|
|
409
445
|
}
|
|
410
446
|
if (e.tplDepREs.size > 0)
|
|
411
|
-
for (const [
|
|
447
|
+
for (const [s, i] of e.tplDepREs)
|
|
412
448
|
for (const [a, c] of i) {
|
|
413
449
|
const d = c.exec(t);
|
|
414
450
|
if (!d || !d.groups)
|
|
415
451
|
continue;
|
|
416
|
-
const { fnCall:
|
|
417
|
-
if (!
|
|
452
|
+
const { fnCall: u, templateName: y, fnName: b } = d.groups;
|
|
453
|
+
if (!u || !y || !b)
|
|
418
454
|
throw Error("failed to parse template import statement");
|
|
419
|
-
const w =
|
|
455
|
+
const w = ue(y, a, r);
|
|
420
456
|
if (!w)
|
|
421
|
-
throw Error(`failed to parse artifact name in ${
|
|
422
|
-
return t = t.replace(
|
|
457
|
+
throw Error(`failed to parse artifact name in ${b} import statement`);
|
|
458
|
+
return t = t.replace(u, `${b}("${w.pkg}:${w.id}")`), { line: t, context: e, artifact: w };
|
|
423
459
|
}
|
|
424
460
|
return { line: t, context: e, artifact: void 0 };
|
|
425
461
|
}
|
|
426
|
-
function
|
|
427
|
-
const e =
|
|
462
|
+
function Qe(t) {
|
|
463
|
+
const e = Ze.exec(t);
|
|
428
464
|
if (!e || !e.groups)
|
|
429
465
|
throw Error("failed to parse 'import' statement");
|
|
430
|
-
const { importName: r, moduleName:
|
|
431
|
-
if (!r || !
|
|
466
|
+
const { importName: r, moduleName: o } = e.groups;
|
|
467
|
+
if (!r || !o)
|
|
432
468
|
throw Error("failed to parse 'import' statement");
|
|
433
469
|
return {
|
|
434
|
-
module:
|
|
470
|
+
module: o,
|
|
435
471
|
alias: r
|
|
436
472
|
};
|
|
437
473
|
}
|
|
438
|
-
function
|
|
439
|
-
const
|
|
440
|
-
if (!
|
|
474
|
+
function ue(t, e, r) {
|
|
475
|
+
const o = Ke.exec(t);
|
|
476
|
+
if (!o)
|
|
441
477
|
return;
|
|
442
|
-
if (!
|
|
478
|
+
if (!o.groups)
|
|
443
479
|
throw Error(
|
|
444
480
|
"failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'"
|
|
445
481
|
);
|
|
446
|
-
const { pkgName: n, depID:
|
|
447
|
-
if (!
|
|
482
|
+
const { pkgName: n, depID: s } = o.groups;
|
|
483
|
+
if (!s)
|
|
448
484
|
throw Error(
|
|
449
485
|
"failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'"
|
|
450
486
|
);
|
|
451
|
-
return { type: e, pkg: n ?? r, id:
|
|
487
|
+
return { type: e, pkg: n ?? r, id: s };
|
|
452
488
|
}
|
|
453
|
-
const
|
|
489
|
+
const W = ".plj.gz", P = ".lib.tengo", T = ".sw.json", me = ".test.tengo", U = ".tpl.tengo", q = ".lib.tengo", B = ".sw.json", Ye = [q, U, B];
|
|
454
490
|
function E(t = "debug") {
|
|
455
|
-
return
|
|
491
|
+
return J.createLogger({
|
|
456
492
|
level: t,
|
|
457
|
-
format:
|
|
493
|
+
format: J.format.printf(({ level: e, message: r }) => `${e.padStart(6, " ")}: ${r}`),
|
|
458
494
|
transports: [
|
|
459
|
-
new
|
|
495
|
+
new J.transports.Console({
|
|
460
496
|
stderrLevels: ["error", "warn", "info", "debug"],
|
|
461
497
|
handleExceptions: !0
|
|
462
498
|
})
|
|
463
499
|
]
|
|
464
500
|
});
|
|
465
501
|
}
|
|
466
|
-
function
|
|
467
|
-
return JSON.parse(
|
|
502
|
+
function j() {
|
|
503
|
+
return JSON.parse(p.readFileSync("package.json").toString());
|
|
468
504
|
}
|
|
469
|
-
function
|
|
505
|
+
function be(t, e) {
|
|
470
506
|
return f.resolve(e, t, "tengo", "lib");
|
|
471
507
|
}
|
|
472
|
-
function
|
|
508
|
+
function $e(t, e) {
|
|
473
509
|
return f.resolve(e, t, "tengo", "tpl");
|
|
474
510
|
}
|
|
475
|
-
function
|
|
511
|
+
function ve(t, e) {
|
|
476
512
|
return f.resolve(e, t, "tengo", "software");
|
|
477
513
|
}
|
|
478
|
-
function
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
514
|
+
function Ee(t, e) {
|
|
515
|
+
return f.resolve(e, t, "tengo", "asset");
|
|
516
|
+
}
|
|
517
|
+
function Ne(t, e, r, o, n = !1) {
|
|
518
|
+
const s = f.resolve(o, "package.json");
|
|
519
|
+
if ($(s) !== "file") {
|
|
520
|
+
for (const ne of p.readdirSync(o)) {
|
|
521
|
+
const Ae = $(f.join(o, ne)) === "link", ie = f.resolve(o, ne);
|
|
522
|
+
$(ie) === "dir" && Ne(t, e, r, ie, Ae);
|
|
484
523
|
}
|
|
485
524
|
return;
|
|
486
525
|
}
|
|
487
|
-
const i =
|
|
488
|
-
if (!
|
|
526
|
+
const i = be("dist", o), a = $e("dist", o), c = ve("dist", o), d = Ee("dist", o), u = $(i) === "dir", y = $(a) === "dir", b = $(c) === "dir", w = $(d) === "dir";
|
|
527
|
+
if (!u && !y && !b && !w)
|
|
489
528
|
return;
|
|
490
|
-
const
|
|
491
|
-
if (
|
|
492
|
-
if (
|
|
529
|
+
const D = JSON.parse(p.readFileSync(s).toString());
|
|
530
|
+
if (D.name !== r.name) {
|
|
531
|
+
if ($(f.resolve(o, "node_modules")) === "dir" && n)
|
|
493
532
|
throw new Error(
|
|
494
|
-
`nested node_modules is a sign of library dependencies version incompatibility in ${
|
|
533
|
+
`nested node_modules is a sign of library dependencies version incompatibility in ${o}`
|
|
495
534
|
);
|
|
496
|
-
|
|
535
|
+
u && _e(t, D, "dist", i, e), y && et(t, D, "dist", a, e), b && tt(t, D, "dist", c, e), w && st(t, D, "dist", d, e);
|
|
497
536
|
}
|
|
498
537
|
}
|
|
499
|
-
function
|
|
500
|
-
for (const
|
|
501
|
-
const i = f.resolve(
|
|
502
|
-
if (!
|
|
538
|
+
function _e(t, e, r, o, n) {
|
|
539
|
+
for (const s of p.readdirSync(o)) {
|
|
540
|
+
const i = f.resolve(o, s);
|
|
541
|
+
if (!s.endsWith(P)) throw new Error(`unexpected file in 'lib' folder: ${i}`);
|
|
503
542
|
const a = {
|
|
504
543
|
type: "library",
|
|
505
544
|
pkg: e.name,
|
|
506
|
-
id:
|
|
545
|
+
id: s.slice(0, s.length - P.length),
|
|
507
546
|
version: e.version
|
|
508
|
-
}, c =
|
|
547
|
+
}, c = ye(r, i, a, !0);
|
|
509
548
|
if (n.addLib(c), t.debug(`Adding dependency ${m(a)} from ${i}`), c.dependencies.length > 0) {
|
|
510
549
|
t.debug("Dependencies:");
|
|
511
550
|
for (const d of c.dependencies) t.debug(` - ${g(d)}`);
|
|
512
551
|
}
|
|
513
552
|
}
|
|
514
553
|
}
|
|
515
|
-
function
|
|
516
|
-
for (const
|
|
517
|
-
const i = f.resolve(
|
|
518
|
-
if (!
|
|
554
|
+
function et(t, e, r, o, n) {
|
|
555
|
+
for (const s of p.readdirSync(o)) {
|
|
556
|
+
const i = f.resolve(o, s);
|
|
557
|
+
if (!s.endsWith(W)) throw new Error(`unexpected file in 'tpl' folder: ${i}`);
|
|
519
558
|
const a = {
|
|
520
559
|
type: "template",
|
|
521
560
|
pkg: e.name,
|
|
522
|
-
id:
|
|
561
|
+
id: s.slice(0, s.length - W.length),
|
|
523
562
|
version: e.version
|
|
524
|
-
}, c = new
|
|
563
|
+
}, c = new he(r, a, { content: p.readFileSync(i) });
|
|
525
564
|
n.addTemplate(c), t.debug(`Adding dependency ${m(a)} from ${i}`);
|
|
526
565
|
}
|
|
527
566
|
}
|
|
528
|
-
function
|
|
529
|
-
for (const
|
|
530
|
-
const i = f.resolve(
|
|
531
|
-
if (!
|
|
567
|
+
function tt(t, e, r, o, n) {
|
|
568
|
+
for (const s of p.readdirSync(o)) {
|
|
569
|
+
const i = f.resolve(o, s);
|
|
570
|
+
if (!s.endsWith(T))
|
|
532
571
|
throw new Error(`unexpected file in 'software' folder: ${i}`);
|
|
533
572
|
const a = {
|
|
534
573
|
type: "software",
|
|
535
574
|
pkg: e.name,
|
|
536
|
-
id:
|
|
575
|
+
id: s.slice(0, s.length - T.length),
|
|
537
576
|
version: e.version
|
|
538
|
-
}, c = new
|
|
539
|
-
|
|
577
|
+
}, c = new te(r, a, p.readFileSync(i).toString(), i, []);
|
|
578
|
+
t.debug(`Adding dependency ${m(a)} from ${i}`), n.addSoftware(c);
|
|
540
579
|
}
|
|
541
580
|
}
|
|
542
|
-
function
|
|
543
|
-
const o
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
581
|
+
function st(t, e, r, o, n) {
|
|
582
|
+
for (const s of p.readdirSync(o)) {
|
|
583
|
+
const i = f.resolve(o, s);
|
|
584
|
+
if (!s.endsWith(T))
|
|
585
|
+
throw new Error(`unexpected file in 'asset' folder: ${i}`);
|
|
586
|
+
const a = {
|
|
587
|
+
type: "asset",
|
|
588
|
+
pkg: e.name,
|
|
589
|
+
id: s.slice(0, s.length - T.length),
|
|
590
|
+
version: e.version
|
|
591
|
+
}, c = new te(r, a, p.readFileSync(i).toString(), i, []);
|
|
592
|
+
t.debug(`Adding dependency ${m(a)} from ${i}`), n.addAsset(c);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
function L(t, e, r, o, n) {
|
|
596
|
+
const s = [];
|
|
597
|
+
for (const i of p.readdirSync(f.join(o, n))) {
|
|
598
|
+
const a = f.join(n, i), c = f.join(o, a);
|
|
599
|
+
if ($(c) === "dir") {
|
|
600
|
+
const w = L(t, e, r, o, a);
|
|
601
|
+
s.push(...w);
|
|
549
602
|
continue;
|
|
550
603
|
}
|
|
551
|
-
const d = i === "index.lib.tengo" ? `${f.basename(n)}.lib.tengo` : a,
|
|
552
|
-
if (!
|
|
604
|
+
const d = i === "index.lib.tengo" ? `${f.basename(n)}.lib.tengo` : a, u = rt(e, d.replaceAll(f.sep, "."));
|
|
605
|
+
if (!u)
|
|
553
606
|
continue;
|
|
554
|
-
const
|
|
555
|
-
t.debug(`Parsing ${m(
|
|
556
|
-
const
|
|
557
|
-
if (
|
|
607
|
+
const y = f.resolve(o, a);
|
|
608
|
+
t.debug(`Parsing ${m(u)} from ${y}`);
|
|
609
|
+
const b = ye(r, y, u, !0);
|
|
610
|
+
if (b.dependencies.length > 0) {
|
|
558
611
|
t.debug("Detected dependencies:");
|
|
559
|
-
for (const w of
|
|
612
|
+
for (const w of b.dependencies) t.debug(` - ${g(w)}`);
|
|
560
613
|
}
|
|
561
|
-
|
|
614
|
+
s.push(b);
|
|
562
615
|
}
|
|
563
|
-
return
|
|
616
|
+
return s;
|
|
564
617
|
}
|
|
565
|
-
function
|
|
566
|
-
const
|
|
567
|
-
return
|
|
618
|
+
function se(t, e, r) {
|
|
619
|
+
const o = new ze(r);
|
|
620
|
+
return Ne(t, o, e, Le()), o;
|
|
568
621
|
}
|
|
569
|
-
function
|
|
622
|
+
function rt(t, e) {
|
|
570
623
|
const r = { pkg: t.name, version: t.version };
|
|
571
|
-
return e.endsWith(
|
|
624
|
+
return e.endsWith(q) ? {
|
|
572
625
|
...r,
|
|
573
|
-
id: e.substring(0, e.length -
|
|
626
|
+
id: e.substring(0, e.length - q.length),
|
|
574
627
|
type: "library"
|
|
575
|
-
} : e.endsWith(P) ? {
|
|
576
|
-
...r,
|
|
577
|
-
id: e.substring(0, e.length - P.length),
|
|
578
|
-
type: "template"
|
|
579
628
|
} : e.endsWith(U) ? {
|
|
580
629
|
...r,
|
|
581
630
|
id: e.substring(0, e.length - U.length),
|
|
631
|
+
type: "template"
|
|
632
|
+
} : e.endsWith(B) ? {
|
|
633
|
+
...r,
|
|
634
|
+
id: e.substring(0, e.length - B.length),
|
|
582
635
|
type: "software"
|
|
583
|
-
} : e.endsWith(
|
|
636
|
+
} : e.endsWith(me) ? {
|
|
584
637
|
...r,
|
|
585
|
-
id: e.substring(0, e.length -
|
|
638
|
+
id: e.substring(0, e.length - me.length),
|
|
586
639
|
type: "test"
|
|
587
640
|
} : null;
|
|
588
641
|
}
|
|
589
|
-
function
|
|
590
|
-
const r =
|
|
642
|
+
function ot(t, e) {
|
|
643
|
+
const r = j(), o = se(t, r, e), n = L(t, r, e, "src", "");
|
|
591
644
|
if (n.length === 0) {
|
|
592
645
|
const i = [];
|
|
593
|
-
for (const a of
|
|
646
|
+
for (const a of Ye)
|
|
594
647
|
i.push(`*${a}`);
|
|
595
648
|
t.error(`Nothing to compile. Looked for ${i.join(", ")}`), process.exit(1);
|
|
596
649
|
}
|
|
597
650
|
t.info(`Compiling '${e}'...`);
|
|
598
|
-
const
|
|
599
|
-
return t.debug("Done."),
|
|
651
|
+
const s = o.compileAndAdd(n);
|
|
652
|
+
return t.debug("Done."), s;
|
|
600
653
|
}
|
|
601
|
-
function
|
|
654
|
+
function nt(t, e, r) {
|
|
602
655
|
if (e.libs.length > 0) {
|
|
603
|
-
const
|
|
604
|
-
|
|
656
|
+
const o = be(r, ".");
|
|
657
|
+
p.mkdirSync(o, { recursive: !0 });
|
|
605
658
|
for (const n of e.libs) {
|
|
606
|
-
const
|
|
607
|
-
t.info(` - writing ${
|
|
659
|
+
const s = f.resolve(o, n.fullName.id + P);
|
|
660
|
+
t.info(` - writing ${s}`), p.writeFileSync(s, n.src);
|
|
608
661
|
}
|
|
609
662
|
}
|
|
610
663
|
if (e.templates.length > 0) {
|
|
611
|
-
const
|
|
612
|
-
|
|
664
|
+
const o = $e(r, ".");
|
|
665
|
+
p.mkdirSync(o, { recursive: !0 });
|
|
613
666
|
for (const n of e.templates) {
|
|
614
|
-
const
|
|
615
|
-
t.info(` - writing ${
|
|
667
|
+
const s = f.resolve(o, n.fullName.id + W);
|
|
668
|
+
t.info(` - writing ${s}`), p.writeFileSync(s, n.content);
|
|
616
669
|
}
|
|
617
670
|
}
|
|
618
671
|
if (e.software.length > 0) {
|
|
619
|
-
const
|
|
620
|
-
|
|
672
|
+
const o = ve(r, ".");
|
|
673
|
+
p.mkdirSync(o, { recursive: !0 });
|
|
674
|
+
for (const n of e.software) {
|
|
675
|
+
const s = f.resolve(o, n.fullName.id + T);
|
|
676
|
+
t.info(` - writing ${s}`), p.writeFileSync(s, n.src);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
if (e.assets.length > 0) {
|
|
680
|
+
const o = Ee(r, ".");
|
|
681
|
+
p.mkdirSync(o, { recursive: !0 });
|
|
621
682
|
for (const n of e.software) {
|
|
622
|
-
const
|
|
623
|
-
t.info(` - writing ${
|
|
683
|
+
const s = f.resolve(o, n.fullName.id + T);
|
|
684
|
+
t.info(` - writing ${s}`), p.writeFileSync(s, n.src);
|
|
624
685
|
}
|
|
625
686
|
}
|
|
626
687
|
}
|
|
627
|
-
const
|
|
628
|
-
"log-level":
|
|
688
|
+
const re = {
|
|
689
|
+
"log-level": M.string({
|
|
629
690
|
description: "logging level",
|
|
630
691
|
default: "info",
|
|
631
692
|
options: ["error", "warn", "info", "debug"]
|
|
632
693
|
})
|
|
633
|
-
},
|
|
634
|
-
"generate-tags":
|
|
694
|
+
}, it = {
|
|
695
|
+
"generate-tags": M.boolean({
|
|
635
696
|
description: "generate tags, default false",
|
|
636
697
|
default: !1
|
|
637
698
|
}),
|
|
638
|
-
"tags-file":
|
|
699
|
+
"tags-file": M.file({
|
|
639
700
|
description: 'where to put ".tags" file, it should be a root of VS Code project',
|
|
640
701
|
default: "../../.tags"
|
|
641
702
|
// usually a user opens a directory with all blocks
|
|
642
703
|
}),
|
|
643
|
-
"tags-additional-args":
|
|
704
|
+
"tags-additional-args": M.string({
|
|
644
705
|
description: "additional flags for universal-ctags command: e.g. -e for emacs",
|
|
645
706
|
default: [],
|
|
646
707
|
multiple: !0,
|
|
647
708
|
delimiter: ","
|
|
648
709
|
})
|
|
649
|
-
},
|
|
710
|
+
}, k = class k extends v {
|
|
650
711
|
async run() {
|
|
651
|
-
const { flags: e } = await this.parse(
|
|
652
|
-
|
|
653
|
-
let
|
|
712
|
+
const { flags: e } = await this.parse(k), r = E(e["log-level"]), o = j(), n = ot(r, "dist");
|
|
713
|
+
nt(r, n, "dist"), r.info("");
|
|
714
|
+
let s = `declare type TemplateFromFile = { readonly type: "from-file"; readonly path: string; };
|
|
654
715
|
`;
|
|
655
|
-
|
|
656
|
-
`,
|
|
657
|
-
`,
|
|
716
|
+
s += `declare type TplName = ${n.templates.map((u) => '"' + u.fullName.id + '"').join(" | ")};
|
|
717
|
+
`, s += `declare const Templates: Record<TplName, TemplateFromFile>;
|
|
718
|
+
`, s += `export { Templates };
|
|
658
719
|
`;
|
|
659
720
|
let i = `module.exports = { Templates: {
|
|
660
721
|
`, a = `import { resolve } from 'node:path';
|
|
661
722
|
export const Templates = {
|
|
662
723
|
`;
|
|
663
724
|
const c = n.templates.map(
|
|
664
|
-
(
|
|
725
|
+
(u) => ` '${u.fullName.id}': { type: 'from-file', path: require.resolve('./tengo/tpl/${u.fullName.id}.plj.gz') }`
|
|
665
726
|
).join(`,
|
|
666
727
|
`), d = n.templates.map(
|
|
667
|
-
(
|
|
728
|
+
(u) => ` '${u.fullName.id}': { type: 'from-file', path: resolve(import.meta.dirname, './tengo/tpl/${u.fullName.id}.plj.gz') }`
|
|
668
729
|
).join(`,
|
|
669
730
|
`);
|
|
670
731
|
i += c, a += d, i += `
|
|
671
732
|
}};
|
|
672
733
|
`, a += `
|
|
673
734
|
};
|
|
674
|
-
`, await
|
|
735
|
+
`, await F.writeFile("dist/index.d.ts", s), o.type === "module" ? (await F.writeFile("dist/index.cjs", i), await F.writeFile("dist/index.js", a)) : (await F.writeFile("dist/index.js", i), await F.writeFile("dist/index.mjs", a)), at(e), e["generate-tags"] && lt(r, e), r.info("Template Pack build done.");
|
|
675
736
|
}
|
|
676
737
|
};
|
|
677
|
-
l(
|
|
678
|
-
...
|
|
679
|
-
...
|
|
738
|
+
l(k, "description", "build tengo sources into single distributable pack file"), l(k, "examples", ["<%= config.bin %> <%= command.id %>"]), l(k, "flags", {
|
|
739
|
+
...re,
|
|
740
|
+
...it
|
|
680
741
|
});
|
|
681
|
-
let
|
|
682
|
-
function
|
|
742
|
+
let V = k;
|
|
743
|
+
function at(t) {
|
|
683
744
|
process.env.GENERATE_TAGS != null && (t["generate-tags"] = process.env.GENERATE_TAGS == "true"), process.env.TAGS_FILE != null && (t["tags-file"] = process.env.TAGS_FILE), process.env.TAGS_ADDITIONAL_ARGS != null && (t["tags-additional-args"] = process.env.TAGS_ADDITIONAL_ARGS.split(","));
|
|
684
745
|
}
|
|
685
|
-
function
|
|
746
|
+
function lt(t, e) {
|
|
686
747
|
var a;
|
|
687
|
-
const r = f.resolve(e["tags-file"]),
|
|
748
|
+
const r = f.resolve(e["tags-file"]), o = f.dirname(r), n = e["tags-additional-args"], s = ct(o);
|
|
688
749
|
t.info(
|
|
689
|
-
`Generating tags for tengo autocompletion from "${
|
|
690
|
-
Found ${
|
|
750
|
+
`Generating tags for tengo autocompletion from "${o}" in "${r}", additional arguments: "${n}".
|
|
751
|
+
Found ${s.length} tengo files...`
|
|
691
752
|
);
|
|
692
|
-
const i =
|
|
753
|
+
const i = De(
|
|
693
754
|
"ctags",
|
|
694
755
|
[
|
|
695
756
|
"-f",
|
|
@@ -702,12 +763,12 @@ Found ${o.length} tengo files...`
|
|
|
702
763
|
"--kinddef-tengo=c,constant,constant",
|
|
703
764
|
'--regex-tengo=/^\\s*(.*) := ("|\\{).*/\\1/c/',
|
|
704
765
|
"-R",
|
|
705
|
-
...
|
|
766
|
+
...s
|
|
706
767
|
],
|
|
707
768
|
{
|
|
708
769
|
env: process.env,
|
|
709
770
|
stdio: "inherit",
|
|
710
|
-
cwd:
|
|
771
|
+
cwd: o
|
|
711
772
|
}
|
|
712
773
|
);
|
|
713
774
|
if ((a = i.error) != null && a.message.includes("ENOENT")) {
|
|
@@ -721,112 +782,122 @@ For vscode, you should also install ctags extension:
|
|
|
721
782
|
https://marketplace.visualstudio.com/items?itemName=jaydenlin.ctags-support`);
|
|
722
783
|
return;
|
|
723
784
|
}
|
|
724
|
-
|
|
785
|
+
ft(i, "failed to generate ctags"), t.info("Generation of tags is done.");
|
|
725
786
|
}
|
|
726
|
-
function
|
|
727
|
-
const e =
|
|
728
|
-
return e.forEach((
|
|
729
|
-
if (!
|
|
730
|
-
const n = f.join(
|
|
787
|
+
function ct(t) {
|
|
788
|
+
const e = p.readdirSync(t, { withFileTypes: !0, recursive: !0 }), r = [];
|
|
789
|
+
return e.forEach((o) => {
|
|
790
|
+
if (!o.isDirectory() && o.name.endsWith(".tengo")) {
|
|
791
|
+
const n = f.join(o.parentPath, o.name).replace(t, ".");
|
|
731
792
|
r.push(n);
|
|
732
793
|
}
|
|
733
794
|
}), r;
|
|
734
795
|
}
|
|
735
|
-
function
|
|
796
|
+
function ft(t, e) {
|
|
736
797
|
t.error && console.log(t.error);
|
|
737
798
|
const r = e;
|
|
738
799
|
t.status !== 0 && console.log(`WARN: ${r} the build will continue as-is`);
|
|
739
800
|
}
|
|
740
|
-
function
|
|
741
|
-
const r =
|
|
742
|
-
for (const
|
|
801
|
+
function oe(t, e) {
|
|
802
|
+
const r = j(), o = L(t, r, "dist", "src", ""), n = se(t, r, "dist");
|
|
803
|
+
for (const s of n.allLibs())
|
|
804
|
+
t.debug(
|
|
805
|
+
`Dumping to pl-tester: ${g(s.fullName)}`
|
|
806
|
+
), e.write(JSON.stringify(s) + `
|
|
807
|
+
`);
|
|
808
|
+
for (const s of o)
|
|
809
|
+
s.fullName.type === "library" && (t.debug(
|
|
810
|
+
`Dumping to pl-tester: ${g(s.fullName)}`
|
|
811
|
+
), e.write(JSON.stringify(s) + `
|
|
812
|
+
`));
|
|
813
|
+
for (const s of n.allTemplates())
|
|
743
814
|
t.debug(
|
|
744
|
-
`Dumping to pl-tester: ${g(
|
|
745
|
-
), e.write(JSON.stringify(
|
|
815
|
+
`Dumping to pl-tester: ${g(s.fullName)}`
|
|
816
|
+
), e.write(JSON.stringify(s) + `
|
|
746
817
|
`);
|
|
747
|
-
for (const
|
|
748
|
-
|
|
749
|
-
`Dumping to pl-tester: ${g(
|
|
750
|
-
), e.write(JSON.stringify(
|
|
818
|
+
for (const s of o)
|
|
819
|
+
s.fullName.type === "template" && (t.debug(
|
|
820
|
+
`Dumping to pl-tester: ${g(s.fullName)} ${s.srcName}`
|
|
821
|
+
), e.write(JSON.stringify(s) + `
|
|
751
822
|
`));
|
|
752
|
-
for (const
|
|
823
|
+
for (const s of n.allSoftware())
|
|
753
824
|
t.debug(
|
|
754
|
-
`Dumping to pl-tester: ${g(
|
|
755
|
-
), e.write(JSON.stringify(
|
|
825
|
+
`Dumping to pl-tester: ${g(s.fullName)}`
|
|
826
|
+
), e.write(JSON.stringify(s) + `
|
|
756
827
|
`);
|
|
757
|
-
for (const
|
|
758
|
-
|
|
759
|
-
`Dumping to pl-tester: ${g(
|
|
760
|
-
), e.write(JSON.stringify(
|
|
828
|
+
for (const s of o)
|
|
829
|
+
s.fullName.type === "software" && (t.debug(
|
|
830
|
+
`Dumping to pl-tester: ${g(s.fullName)}`
|
|
831
|
+
), e.write(JSON.stringify(s) + `
|
|
761
832
|
`));
|
|
762
|
-
for (const
|
|
833
|
+
for (const s of n.allAssets())
|
|
763
834
|
t.debug(
|
|
764
|
-
`Dumping to pl-tester: ${g(
|
|
765
|
-
), e.write(JSON.stringify(
|
|
835
|
+
`Dumping to pl-tester: ${g(s.fullName)}`
|
|
836
|
+
), e.write(JSON.stringify(s) + `
|
|
766
837
|
`);
|
|
767
|
-
for (const
|
|
768
|
-
|
|
769
|
-
`Dumping to pl-tester: ${g(
|
|
770
|
-
), e.write(JSON.stringify(
|
|
838
|
+
for (const s of o)
|
|
839
|
+
s.fullName.type === "asset" && (t.debug(
|
|
840
|
+
`Dumping to pl-tester: ${g(s.fullName)}`
|
|
841
|
+
), e.write(JSON.stringify(s) + `
|
|
771
842
|
`));
|
|
772
|
-
for (const
|
|
773
|
-
|
|
774
|
-
`Dumping to pl-tester: ${g(
|
|
775
|
-
), e.write(JSON.stringify(
|
|
843
|
+
for (const s of o)
|
|
844
|
+
s.fullName.type === "test" && (t.debug(
|
|
845
|
+
`Dumping to pl-tester: ${g(s.fullName)} ${s.srcName}`
|
|
846
|
+
), e.write(JSON.stringify(s) + `
|
|
776
847
|
`));
|
|
777
848
|
}
|
|
778
|
-
function
|
|
779
|
-
const
|
|
849
|
+
function dt(t, e, r) {
|
|
850
|
+
const o = j(), n = L(t, o, "dist", "src", "");
|
|
780
851
|
if (!e) {
|
|
781
852
|
for (const i of n)
|
|
782
853
|
i.fullName.type === "library" && r.write(JSON.stringify(i) + `
|
|
783
854
|
`);
|
|
784
855
|
return;
|
|
785
856
|
}
|
|
786
|
-
const
|
|
857
|
+
const s = se(t, o, "dist");
|
|
787
858
|
for (const i of n)
|
|
788
|
-
i.fullName.type === "library" &&
|
|
789
|
-
for (const i of
|
|
859
|
+
i.fullName.type === "library" && s.addLib(i);
|
|
860
|
+
for (const i of s.allLibs())
|
|
790
861
|
r.write(JSON.stringify(i) + `
|
|
791
862
|
`);
|
|
792
863
|
}
|
|
793
|
-
function
|
|
794
|
-
const
|
|
795
|
-
for (const
|
|
796
|
-
|
|
864
|
+
function G(t, e, r) {
|
|
865
|
+
const o = j(), n = L(t, o, "dist", "src", "");
|
|
866
|
+
for (const s of n)
|
|
867
|
+
s.fullName.type === r && e.write(JSON.stringify(s) + `
|
|
797
868
|
`);
|
|
798
869
|
}
|
|
799
|
-
function
|
|
800
|
-
|
|
801
|
-
for (const n of s)
|
|
802
|
-
n.fullName.type === "software" && e.write(JSON.stringify(n) + `
|
|
803
|
-
`);
|
|
870
|
+
function pt(t, e) {
|
|
871
|
+
G(t, e, "template");
|
|
804
872
|
}
|
|
805
|
-
function
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
873
|
+
function ut(t, e) {
|
|
874
|
+
G(t, e, "software");
|
|
875
|
+
}
|
|
876
|
+
function mt(t, e) {
|
|
877
|
+
G(t, e, "asset");
|
|
810
878
|
}
|
|
811
|
-
function
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
879
|
+
function gt(t, e) {
|
|
880
|
+
G(t, e, "test");
|
|
881
|
+
}
|
|
882
|
+
function Se(t, ...e) {
|
|
883
|
+
const r = Fe(t, e, { stdio: ["pipe", "inherit", "inherit"] });
|
|
884
|
+
return r.stdin.on("error", (o) => {
|
|
885
|
+
o.code;
|
|
815
886
|
}), r;
|
|
816
887
|
}
|
|
817
|
-
function
|
|
888
|
+
function ke(t) {
|
|
818
889
|
return new Promise((e, r) => {
|
|
819
|
-
t.on("close", (
|
|
820
|
-
e(
|
|
821
|
-
}), t.on("error", (
|
|
822
|
-
r(
|
|
890
|
+
t.on("close", (o) => {
|
|
891
|
+
e(o);
|
|
892
|
+
}), t.on("error", (o) => {
|
|
893
|
+
r(o);
|
|
823
894
|
});
|
|
824
895
|
});
|
|
825
896
|
}
|
|
826
|
-
const N = class N extends
|
|
897
|
+
const N = class N extends v {
|
|
827
898
|
async run() {
|
|
828
|
-
const { flags: e, argv: r } = await this.parse(N),
|
|
829
|
-
|
|
899
|
+
const { flags: e, argv: r } = await this.parse(N), o = E(e["log-level"]), n = r.length == 0 ? ["./src"] : r, s = Se(
|
|
900
|
+
ge,
|
|
830
901
|
"check",
|
|
831
902
|
"--log-level",
|
|
832
903
|
e["log-level"],
|
|
@@ -835,12 +906,12 @@ const N = class N extends $ {
|
|
|
835
906
|
...n
|
|
836
907
|
);
|
|
837
908
|
try {
|
|
838
|
-
|
|
909
|
+
oe(o, s.stdin);
|
|
839
910
|
} catch (i) {
|
|
840
|
-
|
|
911
|
+
o.error(i);
|
|
841
912
|
} finally {
|
|
842
|
-
|
|
843
|
-
const i = await
|
|
913
|
+
s.stdin.end();
|
|
914
|
+
const i = await ke(s);
|
|
844
915
|
process.exit(i);
|
|
845
916
|
}
|
|
846
917
|
}
|
|
@@ -848,91 +919,101 @@ const N = class N extends $ {
|
|
|
848
919
|
l(N, "description", "check tengo sources for language processor an"), // static override args = {
|
|
849
920
|
// "log-level": Args.string({description: 'logging level'}),
|
|
850
921
|
// }
|
|
851
|
-
l(N, "strict", !1), l(N, "flags", { ...
|
|
852
|
-
let
|
|
853
|
-
const S = class S extends
|
|
922
|
+
l(N, "strict", !1), l(N, "flags", { ...re }), l(N, "examples", ["<%= config.bin %> <%= command.id %>"]);
|
|
923
|
+
let Z = N;
|
|
924
|
+
const S = class S extends v {
|
|
854
925
|
async run() {
|
|
855
|
-
const { flags: e } = await this.parse(S), r = E(e["log-level"]),
|
|
856
|
-
|
|
926
|
+
const { flags: e } = await this.parse(S), r = E(e["log-level"]), o = this.argv.length == 0 ? ["./src"] : this.argv, n = Se(
|
|
927
|
+
ge,
|
|
857
928
|
"run",
|
|
858
929
|
"--log-level",
|
|
859
930
|
e["log-level"],
|
|
860
931
|
"--artifacts",
|
|
861
932
|
"-",
|
|
862
|
-
...
|
|
933
|
+
...o
|
|
863
934
|
);
|
|
864
935
|
try {
|
|
865
|
-
|
|
866
|
-
} catch (
|
|
867
|
-
r.error(
|
|
936
|
+
oe(r, n.stdin);
|
|
937
|
+
} catch (s) {
|
|
938
|
+
r.error(s);
|
|
868
939
|
} finally {
|
|
869
940
|
n.stdin.end();
|
|
870
|
-
const
|
|
871
|
-
process.exit(
|
|
941
|
+
const s = await ke(n);
|
|
942
|
+
process.exit(s);
|
|
872
943
|
}
|
|
873
944
|
}
|
|
874
945
|
};
|
|
875
|
-
l(S, "description", "run tengo unit tests (.test.tengo)"), l(S, "strict", !1), l(S, "flags", { ...
|
|
876
|
-
let
|
|
877
|
-
class
|
|
946
|
+
l(S, "description", "run tengo unit tests (.test.tengo)"), l(S, "strict", !1), l(S, "flags", { ...re }), l(S, "examples", ["<%= config.bin %> <%= command.id %>"]);
|
|
947
|
+
let K = S;
|
|
948
|
+
class X extends v {
|
|
949
|
+
async run() {
|
|
950
|
+
const e = E();
|
|
951
|
+
oe(e, x);
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
l(X, "description", "parse sources in current package and dump all found artifacts to stdout"), l(X, "examples", [
|
|
955
|
+
"<%= config.bin %> <%= command.id %>"
|
|
956
|
+
]);
|
|
957
|
+
class H extends v {
|
|
878
958
|
async run() {
|
|
879
959
|
const e = E();
|
|
880
|
-
|
|
960
|
+
mt(e, x);
|
|
881
961
|
}
|
|
882
962
|
}
|
|
883
|
-
l(
|
|
963
|
+
l(H, "description", "parse sources in current package and dump all found tests to stdout"), l(H, "examples", [
|
|
884
964
|
"<%= config.bin %> <%= command.id %>"
|
|
885
965
|
]);
|
|
886
|
-
const A = class A extends
|
|
966
|
+
const A = class A extends v {
|
|
887
967
|
async run() {
|
|
888
968
|
const { flags: e } = await this.parse(A), r = E();
|
|
889
|
-
|
|
969
|
+
dt(r, e.deps, x);
|
|
890
970
|
}
|
|
891
971
|
};
|
|
892
972
|
l(A, "description", "parse sources in current package and dump all found templates to stdout"), l(A, "examples", [
|
|
893
973
|
"<%= config.bin %> <%= command.id %>"
|
|
894
974
|
]), l(A, "flags", {
|
|
895
|
-
deps:
|
|
975
|
+
deps: M.boolean({ name: "deps", description: "add also all libraries found in node_modules" })
|
|
896
976
|
});
|
|
897
|
-
let
|
|
898
|
-
class
|
|
977
|
+
let Q = A;
|
|
978
|
+
class Y extends v {
|
|
899
979
|
async run() {
|
|
900
980
|
const e = E();
|
|
901
|
-
|
|
981
|
+
ut(e, x);
|
|
902
982
|
}
|
|
903
983
|
}
|
|
904
|
-
l(
|
|
984
|
+
l(Y, "description", "parse sources in current package and dump all found tests to stdout"), l(Y, "examples", [
|
|
905
985
|
"<%= config.bin %> <%= command.id %>"
|
|
906
986
|
]);
|
|
907
|
-
class
|
|
987
|
+
class _ extends v {
|
|
908
988
|
async run() {
|
|
909
989
|
const e = E();
|
|
910
|
-
|
|
990
|
+
pt(e, x);
|
|
911
991
|
}
|
|
912
992
|
}
|
|
913
|
-
l(
|
|
993
|
+
l(_, "description", "parse sources in current package and dump all found templates to stdout"), l(_, "examples", [
|
|
914
994
|
"<%= config.bin %> <%= command.id %>"
|
|
915
995
|
]);
|
|
916
|
-
class
|
|
996
|
+
class ee extends v {
|
|
917
997
|
async run() {
|
|
918
998
|
const e = E();
|
|
919
|
-
|
|
999
|
+
gt(e, x);
|
|
920
1000
|
}
|
|
921
1001
|
}
|
|
922
|
-
l(
|
|
1002
|
+
l(ee, "description", "parse sources in current package and dump all found tests to stdout"), l(ee, "examples", [
|
|
923
1003
|
"<%= config.bin %> <%= command.id %>"
|
|
924
1004
|
]);
|
|
925
|
-
const
|
|
926
|
-
build:
|
|
927
|
-
check:
|
|
928
|
-
test:
|
|
929
|
-
"dump
|
|
930
|
-
"dump
|
|
931
|
-
"dump
|
|
932
|
-
"dump
|
|
933
|
-
"dump
|
|
1005
|
+
const At = {
|
|
1006
|
+
build: V,
|
|
1007
|
+
check: Z,
|
|
1008
|
+
test: K,
|
|
1009
|
+
"dump:all": X,
|
|
1010
|
+
"dump:assets": H,
|
|
1011
|
+
"dump:libs": Q,
|
|
1012
|
+
"dump:software": Y,
|
|
1013
|
+
"dump:templates": _,
|
|
1014
|
+
"dump:tests": ee
|
|
934
1015
|
};
|
|
935
1016
|
export {
|
|
936
|
-
|
|
1017
|
+
At as COMMANDS
|
|
937
1018
|
};
|
|
938
1019
|
//# sourceMappingURL=index.mjs.map
|