@platforma-sdk/tengo-builder 1.14.13 → 1.15.1
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 +10 -8
- 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 +445 -360
- 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 +9 -9
- package/src/commands/dump/assets.ts +17 -0
- package/src/compiler/compiler.ts +51 -1
- package/src/compiler/main.ts +59 -3
- 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 +12 -8
- package/src/shared/dump.ts +40 -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 F, Command as
|
|
1
|
+
var De = Object.defineProperty;
|
|
2
|
+
var Fe = (t, e, r) => e in t ? De(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
3
|
+
var l = (t, e, r) => Fe(t, typeof e != "symbol" ? e + "" : e, r);
|
|
4
|
+
import { spawnSync as Me, spawn as Oe } from "node:child_process";
|
|
5
|
+
import { Flags as F, 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
|
|
7
|
+
import * as p from "node:fs";
|
|
8
|
+
import { readFileSync as Re } from "node:fs";
|
|
9
|
+
import { gunzipSync as je, gzipSync as Le } from "node:zlib";
|
|
10
|
+
import Ie from "canonicalize";
|
|
11
|
+
import G from "winston";
|
|
12
12
|
import * as D from "node:fs/promises";
|
|
13
|
-
import { TengoTesterBinaryPath as
|
|
14
|
-
import { stdout as
|
|
15
|
-
function
|
|
13
|
+
import { TengoTesterBinaryPath as we } from "@milaboratories/tengo-tester";
|
|
14
|
+
import { stdout as T } from "node:process";
|
|
15
|
+
function M(t) {
|
|
16
16
|
throw new Error("Unexpected object: " + t);
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function Ce() {
|
|
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 ce(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 fe(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
53
|
function L(t) {
|
|
54
|
-
return { name:
|
|
54
|
+
return { name: h(t), version: t.version };
|
|
55
55
|
}
|
|
56
|
-
function
|
|
56
|
+
function Ge(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 de(t) {
|
|
63
63
|
return `${t.pkg}:${t.id}:${t.version}`;
|
|
64
64
|
}
|
|
65
|
-
const
|
|
66
|
-
class
|
|
67
|
-
constructor(e, r,
|
|
65
|
+
const Je = new TextDecoder(), ze = new TextEncoder();
|
|
66
|
+
class ye {
|
|
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(Je.decode(je(s))), n.type !== "pl.tengo-template.v2"))
|
|
77
77
|
throw new Error("malformed template");
|
|
78
|
-
|
|
79
|
-
const i =
|
|
78
|
+
s === void 0 && (s = Le(ze.encode(Ie(n))));
|
|
79
|
+
const i = Ge(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: ${de(i)} != ${de(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 J {
|
|
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 = ce(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(ce(e));
|
|
99
99
|
}
|
|
100
100
|
get array() {
|
|
101
101
|
const e = [];
|
|
@@ -105,21 +105,21 @@ class C {
|
|
|
105
105
|
this.map.forEach((r) => e(r, this.nameExtractor(r)));
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
function
|
|
109
|
-
return new
|
|
108
|
+
function We() {
|
|
109
|
+
return new J((t) => t);
|
|
110
110
|
}
|
|
111
111
|
class I {
|
|
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 J(e), this.dist = new J(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
|
+
M(e);
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
get(e, r) {
|
|
@@ -127,57 +127,65 @@ class I {
|
|
|
127
127
|
case "dist":
|
|
128
128
|
return this.dist.get(r);
|
|
129
129
|
default:
|
|
130
|
-
|
|
130
|
+
M(e);
|
|
131
131
|
}
|
|
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 Pe {
|
|
142
142
|
constructor(e) {
|
|
143
143
|
l(this, "libs", new I((e) => e.fullName));
|
|
144
144
|
l(this, "software", new I((e) => e.fullName));
|
|
145
|
+
l(this, "assets", new I((e) => e.fullName));
|
|
145
146
|
l(this, "templates", new I((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
|
+
r.libs[h(s)] = {
|
|
158
159
|
...L(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[
|
|
164
|
+
const c = this.getSoftwareOrError(s);
|
|
165
|
+
r.software[h(s)] = {
|
|
165
166
|
...L(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
|
+
...L(d.fullName),
|
|
174
|
+
src: d.src
|
|
175
|
+
};
|
|
176
|
+
break;
|
|
169
177
|
case "template":
|
|
170
|
-
if (
|
|
178
|
+
if (fe(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
|
-
|
|
188
|
+
M(s.type);
|
|
181
189
|
}
|
|
182
190
|
}
|
|
183
191
|
/** This method assumes that all dependencies are already added to the compiler's context */
|
|
@@ -190,11 +198,12 @@ class Le {
|
|
|
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 ye(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,10 +297,12 @@ 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:
|
|
273
|
-
|
|
305
|
+
M(e.type);
|
|
274
306
|
}
|
|
275
307
|
}
|
|
276
308
|
checkLibs() {
|
|
@@ -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" && fe(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
|
-
|
|
363
|
+
M(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 pe = "[_a-zA-Z][_a-zA-Z0-9]*", O = (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
|
+
), Ue = (t) => O(t, "getTemplateId"), qe = (t) => O(t, "getSoftwareInfo"), ue = (t) => O(t, "importTemplate"), me = (t) => O(t, "importSoftware"), Be = (t) => O(t, "importAsset"), Ve = /^\s*(\/\/)|(\/\*.*\*\/)/, Ze = /^\s*\/\*/, Ke = /\*\//, be = /\s*:=\s*import\s*\(\s*"(?<moduleName>[^"]+)"\s*\)/, Xe = new RegExp(
|
|
381
|
+
`\\b(?<importName>${pe}(\\.${pe})*)${be.source}`
|
|
382
|
+
), He = /(?<pkgName>[^"]+)?:(?<depID>[^"]+)/;
|
|
383
|
+
class re {
|
|
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 $e(t, e, r, o) {
|
|
389
|
+
const n = Re(e).toString(), { deps: s, normalized: i } = Qe(n, r, o);
|
|
390
|
+
return new re(t, r, i, e, s.array);
|
|
356
391
|
}
|
|
357
|
-
function
|
|
358
|
-
const
|
|
359
|
-
`),
|
|
392
|
+
function Qe(t, e, r) {
|
|
393
|
+
const o = We(), n = t.split(`
|
|
394
|
+
`), s = [];
|
|
360
395
|
let i = {
|
|
361
396
|
isInCommentBlock: !1,
|
|
362
397
|
tplDepREs: /* @__PURE__ */ new Map()
|
|
@@ -364,273 +399,303 @@ function Ue(t, e, r) {
|
|
|
364
399
|
for (const c of n) {
|
|
365
400
|
a++;
|
|
366
401
|
try {
|
|
367
|
-
const d =
|
|
402
|
+
const d = Ye(
|
|
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 Ye(t, e, r, o) {
|
|
386
421
|
if (e.isInCommentBlock)
|
|
387
|
-
return
|
|
388
|
-
if (
|
|
422
|
+
return Ke.exec(t) && (e.isInCommentBlock = !1), { line: t, context: e, artifact: void 0 };
|
|
423
|
+
if (Ve.exec(t))
|
|
389
424
|
return { line: t, context: e, artifact: void 0 };
|
|
390
|
-
if (
|
|
425
|
+
if (Ze.exec(t))
|
|
391
426
|
return e.isInCommentBlock = !0, { line: t, context: e, artifact: void 0 };
|
|
392
|
-
const n =
|
|
427
|
+
const n = be.exec(t);
|
|
393
428
|
if (n) {
|
|
394
|
-
const
|
|
395
|
-
if (
|
|
396
|
-
return e.tplDepREs.has(
|
|
397
|
-
["template",
|
|
398
|
-
["software",
|
|
429
|
+
const s = _e(t);
|
|
430
|
+
if (s.module === "plapi")
|
|
431
|
+
return e.tplDepREs.has(s.module) || e.tplDepREs.set(s.module, [
|
|
432
|
+
["template", Ue(s.alias)],
|
|
433
|
+
["software", qe(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", ue(s.alias)],
|
|
437
|
+
["software", me(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", ue(s.alias)],
|
|
440
|
+
["software", me(s.alias)],
|
|
441
|
+
["asset", Be(s.alias)]
|
|
406
442
|
]));
|
|
407
|
-
const i =
|
|
443
|
+
const i = ge(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 = ge(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 _e(t) {
|
|
463
|
+
const e = Xe.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 ge(t, e, r) {
|
|
475
|
+
const o = He.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 z = ".plj.gz", W = ".lib.tengo", P = ".sw.json", U = ".as.json", he = ".test.tengo", q = ".tpl.tengo", B = ".lib.tengo", V = ".sw.json", Z = ".as.json", et = [B, q, V, Z];
|
|
454
490
|
function E(t = "debug") {
|
|
455
|
-
return
|
|
491
|
+
return G.createLogger({
|
|
456
492
|
level: t,
|
|
457
|
-
format:
|
|
493
|
+
format: G.format.printf(({ level: e, message: r }) => `${e.padStart(6, " ")}: ${r}`),
|
|
458
494
|
transports: [
|
|
459
|
-
new
|
|
495
|
+
new G.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 R() {
|
|
503
|
+
return JSON.parse(p.readFileSync("package.json").toString());
|
|
468
504
|
}
|
|
469
|
-
function
|
|
505
|
+
function ve(t, e) {
|
|
470
506
|
return f.resolve(e, t, "tengo", "lib");
|
|
471
507
|
}
|
|
472
|
-
function
|
|
508
|
+
function Ee(t, e) {
|
|
473
509
|
return f.resolve(e, t, "tengo", "tpl");
|
|
474
510
|
}
|
|
475
|
-
function
|
|
511
|
+
function Ne(t, e) {
|
|
476
512
|
return f.resolve(e, t, "tengo", "software");
|
|
477
513
|
}
|
|
478
|
-
function
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
514
|
+
function Se(t, e) {
|
|
515
|
+
return f.resolve(e, t, "tengo", "asset");
|
|
516
|
+
}
|
|
517
|
+
function ke(t, e, r, o, n = !1) {
|
|
518
|
+
const s = f.resolve(o, "package.json");
|
|
519
|
+
if ($(s) !== "file") {
|
|
520
|
+
for (const ae of p.readdirSync(o)) {
|
|
521
|
+
const xe = $(f.join(o, ae)) === "link", le = f.resolve(o, ae);
|
|
522
|
+
$(le) === "dir" && ke(t, e, r, le, xe);
|
|
484
523
|
}
|
|
485
524
|
return;
|
|
486
525
|
}
|
|
487
|
-
const i =
|
|
488
|
-
if (!
|
|
526
|
+
const i = ve("dist", o), a = Ee("dist", o), c = Ne("dist", o), d = Se("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 x = JSON.parse(p.readFileSync(s).toString());
|
|
530
|
+
if (x.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 && tt(t, x, "dist", i, e), y && st(t, x, "dist", a, e), b && rt(t, x, "dist", c, e), w && ot(t, x, "dist", d, e);
|
|
497
536
|
}
|
|
498
537
|
}
|
|
499
|
-
function
|
|
500
|
-
for (const
|
|
501
|
-
const i = f.resolve(
|
|
502
|
-
if (!
|
|
538
|
+
function tt(t, e, r, o, n) {
|
|
539
|
+
for (const s of p.readdirSync(o)) {
|
|
540
|
+
const i = f.resolve(o, s);
|
|
541
|
+
if (!s.endsWith(W)) 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 - W.length),
|
|
507
546
|
version: e.version
|
|
508
|
-
}, c =
|
|
547
|
+
}, c = $e(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 st(t, e, r, o, n) {
|
|
555
|
+
for (const s of p.readdirSync(o)) {
|
|
556
|
+
const i = f.resolve(o, s);
|
|
557
|
+
if (!s.endsWith(z)) 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 - z.length),
|
|
523
562
|
version: e.version
|
|
524
|
-
}, c = new
|
|
563
|
+
}, c = new ye(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 rt(t, e, r, o, n) {
|
|
568
|
+
for (const s of p.readdirSync(o)) {
|
|
569
|
+
const i = f.resolve(o, s);
|
|
570
|
+
if (!s.endsWith(P))
|
|
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 - P.length),
|
|
576
|
+
version: e.version
|
|
577
|
+
}, c = new re(r, a, p.readFileSync(i).toString(), i, []);
|
|
578
|
+
t.debug(`Adding dependency ${m(a)} from ${i}`), n.addSoftware(c);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
function ot(t, e, r, o, n) {
|
|
582
|
+
for (const s of p.readdirSync(o)) {
|
|
583
|
+
const i = f.resolve(o, s);
|
|
584
|
+
if (!s.endsWith(U))
|
|
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 - U.length),
|
|
537
590
|
version: e.version
|
|
538
|
-
}, c = new
|
|
539
|
-
|
|
591
|
+
}, c = new re(r, a, p.readFileSync(i).toString(), i, []);
|
|
592
|
+
t.debug(`Adding dependency ${m(a)} from ${i}`), n.addAsset(c);
|
|
540
593
|
}
|
|
541
594
|
}
|
|
542
|
-
function
|
|
543
|
-
const
|
|
544
|
-
for (const i of
|
|
545
|
-
const a = f.join(n, i), c = f.join(
|
|
546
|
-
if (
|
|
547
|
-
const w =
|
|
548
|
-
|
|
595
|
+
function j(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 = j(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 = nt(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 = $e(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 oe(t, e, r) {
|
|
619
|
+
const o = new Pe(r);
|
|
620
|
+
return ke(t, o, e, Ce()), o;
|
|
568
621
|
}
|
|
569
|
-
function
|
|
622
|
+
function nt(t, e) {
|
|
570
623
|
const r = { pkg: t.name, version: t.version };
|
|
571
|
-
return e.endsWith(
|
|
624
|
+
return e.endsWith(B) ? {
|
|
572
625
|
...r,
|
|
573
|
-
id: e.substring(0, e.length -
|
|
626
|
+
id: e.substring(0, e.length - B.length),
|
|
574
627
|
type: "library"
|
|
575
|
-
} : e.endsWith(
|
|
628
|
+
} : e.endsWith(q) ? {
|
|
576
629
|
...r,
|
|
577
|
-
id: e.substring(0, e.length -
|
|
630
|
+
id: e.substring(0, e.length - q.length),
|
|
578
631
|
type: "template"
|
|
579
|
-
} : e.endsWith(
|
|
632
|
+
} : e.endsWith(V) ? {
|
|
580
633
|
...r,
|
|
581
|
-
id: e.substring(0, e.length -
|
|
634
|
+
id: e.substring(0, e.length - V.length),
|
|
582
635
|
type: "software"
|
|
583
|
-
} : e.endsWith(
|
|
636
|
+
} : e.endsWith(Z) ? {
|
|
637
|
+
...r,
|
|
638
|
+
id: e.substring(0, e.length - Z.length),
|
|
639
|
+
type: "asset"
|
|
640
|
+
} : e.endsWith(he) ? {
|
|
584
641
|
...r,
|
|
585
|
-
id: e.substring(0, e.length -
|
|
642
|
+
id: e.substring(0, e.length - he.length),
|
|
586
643
|
type: "test"
|
|
587
644
|
} : null;
|
|
588
645
|
}
|
|
589
|
-
function
|
|
590
|
-
const r =
|
|
646
|
+
function it(t, e) {
|
|
647
|
+
const r = R(), o = oe(t, r, e), n = j(t, r, e, "src", "");
|
|
591
648
|
if (n.length === 0) {
|
|
592
649
|
const i = [];
|
|
593
|
-
for (const a of
|
|
650
|
+
for (const a of et)
|
|
594
651
|
i.push(`*${a}`);
|
|
595
652
|
t.error(`Nothing to compile. Looked for ${i.join(", ")}`), process.exit(1);
|
|
596
653
|
}
|
|
597
654
|
t.info(`Compiling '${e}'...`);
|
|
598
|
-
const
|
|
599
|
-
return t.debug("Done."),
|
|
655
|
+
const s = o.compileAndAdd(n);
|
|
656
|
+
return t.debug("Done."), s;
|
|
600
657
|
}
|
|
601
|
-
function
|
|
658
|
+
function at(t, e, r) {
|
|
602
659
|
if (e.libs.length > 0) {
|
|
603
|
-
const
|
|
604
|
-
|
|
660
|
+
const o = ve(r, ".");
|
|
661
|
+
p.mkdirSync(o, { recursive: !0 });
|
|
605
662
|
for (const n of e.libs) {
|
|
606
|
-
const
|
|
607
|
-
t.info(` - writing ${
|
|
663
|
+
const s = f.resolve(o, n.fullName.id + W);
|
|
664
|
+
t.info(` - writing ${s}`), p.writeFileSync(s, n.src);
|
|
608
665
|
}
|
|
609
666
|
}
|
|
610
667
|
if (e.templates.length > 0) {
|
|
611
|
-
const
|
|
612
|
-
|
|
668
|
+
const o = Ee(r, ".");
|
|
669
|
+
p.mkdirSync(o, { recursive: !0 });
|
|
613
670
|
for (const n of e.templates) {
|
|
614
|
-
const
|
|
615
|
-
t.info(` - writing ${
|
|
671
|
+
const s = f.resolve(o, n.fullName.id + z);
|
|
672
|
+
t.info(` - writing ${s}`), p.writeFileSync(s, n.content);
|
|
616
673
|
}
|
|
617
674
|
}
|
|
618
675
|
if (e.software.length > 0) {
|
|
619
|
-
const
|
|
620
|
-
|
|
676
|
+
const o = Ne(r, ".");
|
|
677
|
+
p.mkdirSync(o, { recursive: !0 });
|
|
678
|
+
for (const n of e.software) {
|
|
679
|
+
const s = f.resolve(o, n.fullName.id + P);
|
|
680
|
+
t.info(` - writing ${s}`), p.writeFileSync(s, n.src);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
if (e.assets.length > 0) {
|
|
684
|
+
const o = Se(r, ".");
|
|
685
|
+
p.mkdirSync(o, { recursive: !0 });
|
|
621
686
|
for (const n of e.software) {
|
|
622
|
-
const
|
|
623
|
-
t.info(` - writing ${
|
|
687
|
+
const s = f.resolve(o, n.fullName.id + U);
|
|
688
|
+
t.info(` - writing ${s}`), p.writeFileSync(s, n.src);
|
|
624
689
|
}
|
|
625
690
|
}
|
|
626
691
|
}
|
|
627
|
-
const
|
|
692
|
+
const ne = {
|
|
628
693
|
"log-level": F.string({
|
|
629
694
|
description: "logging level",
|
|
630
695
|
default: "info",
|
|
631
696
|
options: ["error", "warn", "info", "debug"]
|
|
632
697
|
})
|
|
633
|
-
},
|
|
698
|
+
}, lt = {
|
|
634
699
|
"generate-tags": F.boolean({
|
|
635
700
|
description: "generate tags, default false",
|
|
636
701
|
default: !1
|
|
@@ -646,50 +711,50 @@ const _ = {
|
|
|
646
711
|
multiple: !0,
|
|
647
712
|
delimiter: ","
|
|
648
713
|
})
|
|
649
|
-
},
|
|
714
|
+
}, k = class k extends v {
|
|
650
715
|
async run() {
|
|
651
|
-
const { flags: e } = await this.parse(
|
|
652
|
-
|
|
653
|
-
let
|
|
716
|
+
const { flags: e } = await this.parse(k), r = E(e["log-level"]), o = R(), n = it(r, "dist");
|
|
717
|
+
at(r, n, "dist"), r.info("");
|
|
718
|
+
let s = `declare type TemplateFromFile = { readonly type: "from-file"; readonly path: string; };
|
|
654
719
|
`;
|
|
655
|
-
|
|
656
|
-
`,
|
|
657
|
-
`,
|
|
720
|
+
s += `declare type TplName = ${n.templates.map((u) => '"' + u.fullName.id + '"').join(" | ")};
|
|
721
|
+
`, s += `declare const Templates: Record<TplName, TemplateFromFile>;
|
|
722
|
+
`, s += `export { Templates };
|
|
658
723
|
`;
|
|
659
724
|
let i = `module.exports = { Templates: {
|
|
660
725
|
`, a = `import { resolve } from 'node:path';
|
|
661
726
|
export const Templates = {
|
|
662
727
|
`;
|
|
663
728
|
const c = n.templates.map(
|
|
664
|
-
(
|
|
729
|
+
(u) => ` '${u.fullName.id}': { type: 'from-file', path: require.resolve('./tengo/tpl/${u.fullName.id}.plj.gz') }`
|
|
665
730
|
).join(`,
|
|
666
731
|
`), d = n.templates.map(
|
|
667
|
-
(
|
|
732
|
+
(u) => ` '${u.fullName.id}': { type: 'from-file', path: resolve(import.meta.dirname, './tengo/tpl/${u.fullName.id}.plj.gz') }`
|
|
668
733
|
).join(`,
|
|
669
734
|
`);
|
|
670
735
|
i += c, a += d, i += `
|
|
671
736
|
}};
|
|
672
737
|
`, a += `
|
|
673
738
|
};
|
|
674
|
-
`, await D.writeFile("dist/index.d.ts",
|
|
739
|
+
`, await D.writeFile("dist/index.d.ts", s), o.type === "module" ? (await D.writeFile("dist/index.cjs", i), await D.writeFile("dist/index.js", a)) : (await D.writeFile("dist/index.js", i), await D.writeFile("dist/index.mjs", a)), ct(e), e["generate-tags"] && ft(r, e), r.info("Template Pack build done.");
|
|
675
740
|
}
|
|
676
741
|
};
|
|
677
|
-
l(
|
|
678
|
-
...
|
|
679
|
-
...
|
|
742
|
+
l(k, "description", "build tengo sources into single distributable pack file"), l(k, "examples", ["<%= config.bin %> <%= command.id %>"]), l(k, "flags", {
|
|
743
|
+
...ne,
|
|
744
|
+
...lt
|
|
680
745
|
});
|
|
681
|
-
let
|
|
682
|
-
function
|
|
746
|
+
let K = k;
|
|
747
|
+
function ct(t) {
|
|
683
748
|
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
749
|
}
|
|
685
|
-
function
|
|
750
|
+
function ft(t, e) {
|
|
686
751
|
var a;
|
|
687
|
-
const r = f.resolve(e["tags-file"]),
|
|
752
|
+
const r = f.resolve(e["tags-file"]), o = f.dirname(r), n = e["tags-additional-args"], s = dt(o);
|
|
688
753
|
t.info(
|
|
689
|
-
`Generating tags for tengo autocompletion from "${
|
|
690
|
-
Found ${
|
|
754
|
+
`Generating tags for tengo autocompletion from "${o}" in "${r}", additional arguments: "${n}".
|
|
755
|
+
Found ${s.length} tengo files...`
|
|
691
756
|
);
|
|
692
|
-
const i =
|
|
757
|
+
const i = Me(
|
|
693
758
|
"ctags",
|
|
694
759
|
[
|
|
695
760
|
"-f",
|
|
@@ -702,12 +767,12 @@ Found ${o.length} tengo files...`
|
|
|
702
767
|
"--kinddef-tengo=c,constant,constant",
|
|
703
768
|
'--regex-tengo=/^\\s*(.*) := ("|\\{).*/\\1/c/',
|
|
704
769
|
"-R",
|
|
705
|
-
...
|
|
770
|
+
...s
|
|
706
771
|
],
|
|
707
772
|
{
|
|
708
773
|
env: process.env,
|
|
709
774
|
stdio: "inherit",
|
|
710
|
-
cwd:
|
|
775
|
+
cwd: o
|
|
711
776
|
}
|
|
712
777
|
);
|
|
713
778
|
if ((a = i.error) != null && a.message.includes("ENOENT")) {
|
|
@@ -721,112 +786,122 @@ For vscode, you should also install ctags extension:
|
|
|
721
786
|
https://marketplace.visualstudio.com/items?itemName=jaydenlin.ctags-support`);
|
|
722
787
|
return;
|
|
723
788
|
}
|
|
724
|
-
|
|
789
|
+
pt(i, "failed to generate ctags"), t.info("Generation of tags is done.");
|
|
725
790
|
}
|
|
726
|
-
function
|
|
727
|
-
const e =
|
|
728
|
-
return e.forEach((
|
|
729
|
-
if (!
|
|
730
|
-
const n = f.join(
|
|
791
|
+
function dt(t) {
|
|
792
|
+
const e = p.readdirSync(t, { withFileTypes: !0, recursive: !0 }), r = [];
|
|
793
|
+
return e.forEach((o) => {
|
|
794
|
+
if (!o.isDirectory() && o.name.endsWith(".tengo")) {
|
|
795
|
+
const n = f.join(o.parentPath, o.name).replace(t, ".");
|
|
731
796
|
r.push(n);
|
|
732
797
|
}
|
|
733
798
|
}), r;
|
|
734
799
|
}
|
|
735
|
-
function
|
|
800
|
+
function pt(t, e) {
|
|
736
801
|
t.error && console.log(t.error);
|
|
737
802
|
const r = e;
|
|
738
803
|
t.status !== 0 && console.log(`WARN: ${r} the build will continue as-is`);
|
|
739
804
|
}
|
|
740
|
-
function
|
|
741
|
-
const r =
|
|
742
|
-
for (const
|
|
805
|
+
function ie(t, e) {
|
|
806
|
+
const r = R(), o = j(t, r, "dist", "src", ""), n = oe(t, r, "dist");
|
|
807
|
+
for (const s of n.allLibs())
|
|
743
808
|
t.debug(
|
|
744
|
-
`Dumping to pl-tester: ${g(
|
|
745
|
-
), e.write(JSON.stringify(
|
|
809
|
+
`Dumping to pl-tester: ${g(s.fullName)}`
|
|
810
|
+
), e.write(JSON.stringify(s) + `
|
|
746
811
|
`);
|
|
747
|
-
for (const
|
|
748
|
-
|
|
749
|
-
`Dumping to pl-tester: ${g(
|
|
750
|
-
), e.write(JSON.stringify(
|
|
812
|
+
for (const s of o)
|
|
813
|
+
s.fullName.type === "library" && (t.debug(
|
|
814
|
+
`Dumping to pl-tester: ${g(s.fullName)}`
|
|
815
|
+
), e.write(JSON.stringify(s) + `
|
|
751
816
|
`));
|
|
752
|
-
for (const
|
|
817
|
+
for (const s of n.allTemplates())
|
|
753
818
|
t.debug(
|
|
754
|
-
`Dumping to pl-tester: ${g(
|
|
755
|
-
), e.write(JSON.stringify(
|
|
819
|
+
`Dumping to pl-tester: ${g(s.fullName)}`
|
|
820
|
+
), e.write(JSON.stringify(s) + `
|
|
756
821
|
`);
|
|
757
|
-
for (const
|
|
758
|
-
|
|
759
|
-
`Dumping to pl-tester: ${g(
|
|
760
|
-
), e.write(JSON.stringify(
|
|
822
|
+
for (const s of o)
|
|
823
|
+
s.fullName.type === "template" && (t.debug(
|
|
824
|
+
`Dumping to pl-tester: ${g(s.fullName)} ${s.srcName}`
|
|
825
|
+
), e.write(JSON.stringify(s) + `
|
|
761
826
|
`));
|
|
762
|
-
for (const
|
|
827
|
+
for (const s of n.allSoftware())
|
|
763
828
|
t.debug(
|
|
764
|
-
`Dumping to pl-tester: ${g(
|
|
765
|
-
), e.write(JSON.stringify(
|
|
829
|
+
`Dumping to pl-tester: ${g(s.fullName)}`
|
|
830
|
+
), e.write(JSON.stringify(s) + `
|
|
766
831
|
`);
|
|
767
|
-
for (const
|
|
768
|
-
|
|
769
|
-
`Dumping to pl-tester: ${g(
|
|
770
|
-
), e.write(JSON.stringify(
|
|
832
|
+
for (const s of o)
|
|
833
|
+
s.fullName.type === "software" && (t.debug(
|
|
834
|
+
`Dumping to pl-tester: ${g(s.fullName)}`
|
|
835
|
+
), e.write(JSON.stringify(s) + `
|
|
771
836
|
`));
|
|
772
|
-
for (const
|
|
773
|
-
|
|
774
|
-
`Dumping to pl-tester: ${g(
|
|
775
|
-
), e.write(JSON.stringify(
|
|
837
|
+
for (const s of n.allAssets())
|
|
838
|
+
t.debug(
|
|
839
|
+
`Dumping to pl-tester: ${g(s.fullName)}`
|
|
840
|
+
), e.write(JSON.stringify(s) + `
|
|
841
|
+
`);
|
|
842
|
+
for (const s of o)
|
|
843
|
+
s.fullName.type === "asset" && (t.debug(
|
|
844
|
+
`Dumping to pl-tester: ${g(s.fullName)}`
|
|
845
|
+
), e.write(JSON.stringify(s) + `
|
|
846
|
+
`));
|
|
847
|
+
for (const s of o)
|
|
848
|
+
s.fullName.type === "test" && (t.debug(
|
|
849
|
+
`Dumping to pl-tester: ${g(s.fullName)} ${s.srcName}`
|
|
850
|
+
), e.write(JSON.stringify(s) + `
|
|
776
851
|
`));
|
|
777
852
|
}
|
|
778
|
-
function
|
|
779
|
-
const
|
|
853
|
+
function ut(t, e, r) {
|
|
854
|
+
const o = R(), n = j(t, o, "dist", "src", "");
|
|
780
855
|
if (!e) {
|
|
781
856
|
for (const i of n)
|
|
782
857
|
i.fullName.type === "library" && r.write(JSON.stringify(i) + `
|
|
783
858
|
`);
|
|
784
859
|
return;
|
|
785
860
|
}
|
|
786
|
-
const
|
|
861
|
+
const s = oe(t, o, "dist");
|
|
787
862
|
for (const i of n)
|
|
788
|
-
i.fullName.type === "library" &&
|
|
789
|
-
for (const i of
|
|
863
|
+
i.fullName.type === "library" && s.addLib(i);
|
|
864
|
+
for (const i of s.allLibs())
|
|
790
865
|
r.write(JSON.stringify(i) + `
|
|
791
866
|
`);
|
|
792
867
|
}
|
|
793
|
-
function
|
|
794
|
-
const
|
|
795
|
-
for (const
|
|
796
|
-
|
|
868
|
+
function C(t, e, r) {
|
|
869
|
+
const o = R(), n = j(t, o, "dist", "src", "");
|
|
870
|
+
for (const s of n)
|
|
871
|
+
s.fullName.type === r && e.write(JSON.stringify(s) + `
|
|
797
872
|
`);
|
|
798
873
|
}
|
|
799
|
-
function
|
|
800
|
-
|
|
801
|
-
for (const n of s)
|
|
802
|
-
n.fullName.type === "software" && e.write(JSON.stringify(n) + `
|
|
803
|
-
`);
|
|
874
|
+
function mt(t, e) {
|
|
875
|
+
C(t, e, "template");
|
|
804
876
|
}
|
|
805
|
-
function
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
877
|
+
function gt(t, e) {
|
|
878
|
+
C(t, e, "software");
|
|
879
|
+
}
|
|
880
|
+
function ht(t, e) {
|
|
881
|
+
C(t, e, "asset");
|
|
882
|
+
}
|
|
883
|
+
function wt(t, e) {
|
|
884
|
+
C(t, e, "test");
|
|
810
885
|
}
|
|
811
|
-
function
|
|
812
|
-
const r =
|
|
813
|
-
return r.stdin.on("error", (
|
|
814
|
-
|
|
886
|
+
function Ae(t, ...e) {
|
|
887
|
+
const r = Oe(t, e, { stdio: ["pipe", "inherit", "inherit"] });
|
|
888
|
+
return r.stdin.on("error", (o) => {
|
|
889
|
+
o.code;
|
|
815
890
|
}), r;
|
|
816
891
|
}
|
|
817
|
-
function
|
|
892
|
+
function Te(t) {
|
|
818
893
|
return new Promise((e, r) => {
|
|
819
|
-
t.on("close", (
|
|
820
|
-
e(
|
|
821
|
-
}), t.on("error", (
|
|
822
|
-
r(
|
|
894
|
+
t.on("close", (o) => {
|
|
895
|
+
e(o);
|
|
896
|
+
}), t.on("error", (o) => {
|
|
897
|
+
r(o);
|
|
823
898
|
});
|
|
824
899
|
});
|
|
825
900
|
}
|
|
826
|
-
const N = class N extends
|
|
901
|
+
const N = class N extends v {
|
|
827
902
|
async run() {
|
|
828
|
-
const { flags: e, argv: r } = await this.parse(N),
|
|
829
|
-
|
|
903
|
+
const { flags: e, argv: r } = await this.parse(N), o = E(e["log-level"]), n = r.length == 0 ? ["./src"] : r, s = Ae(
|
|
904
|
+
we,
|
|
830
905
|
"check",
|
|
831
906
|
"--log-level",
|
|
832
907
|
e["log-level"],
|
|
@@ -835,12 +910,12 @@ const N = class N extends $ {
|
|
|
835
910
|
...n
|
|
836
911
|
);
|
|
837
912
|
try {
|
|
838
|
-
|
|
913
|
+
ie(o, s.stdin);
|
|
839
914
|
} catch (i) {
|
|
840
|
-
|
|
915
|
+
o.error(i);
|
|
841
916
|
} finally {
|
|
842
|
-
|
|
843
|
-
const i = await
|
|
917
|
+
s.stdin.end();
|
|
918
|
+
const i = await Te(s);
|
|
844
919
|
process.exit(i);
|
|
845
920
|
}
|
|
846
921
|
}
|
|
@@ -848,45 +923,54 @@ const N = class N extends $ {
|
|
|
848
923
|
l(N, "description", "check tengo sources for language processor an"), // static override args = {
|
|
849
924
|
// "log-level": Args.string({description: 'logging level'}),
|
|
850
925
|
// }
|
|
851
|
-
l(N, "strict", !1), l(N, "flags", { ...
|
|
852
|
-
let
|
|
853
|
-
const S = class S extends
|
|
926
|
+
l(N, "strict", !1), l(N, "flags", { ...ne }), l(N, "examples", ["<%= config.bin %> <%= command.id %>"]);
|
|
927
|
+
let X = N;
|
|
928
|
+
const S = class S extends v {
|
|
854
929
|
async run() {
|
|
855
|
-
const { flags: e } = await this.parse(S), r = E(e["log-level"]),
|
|
856
|
-
|
|
930
|
+
const { flags: e } = await this.parse(S), r = E(e["log-level"]), o = this.argv.length == 0 ? ["./src"] : this.argv, n = Ae(
|
|
931
|
+
we,
|
|
857
932
|
"run",
|
|
858
933
|
"--log-level",
|
|
859
934
|
e["log-level"],
|
|
860
935
|
"--artifacts",
|
|
861
936
|
"-",
|
|
862
|
-
...
|
|
937
|
+
...o
|
|
863
938
|
);
|
|
864
939
|
try {
|
|
865
|
-
|
|
866
|
-
} catch (
|
|
867
|
-
r.error(
|
|
940
|
+
ie(r, n.stdin);
|
|
941
|
+
} catch (s) {
|
|
942
|
+
r.error(s);
|
|
868
943
|
} finally {
|
|
869
944
|
n.stdin.end();
|
|
870
|
-
const
|
|
871
|
-
process.exit(
|
|
945
|
+
const s = await Te(n);
|
|
946
|
+
process.exit(s);
|
|
872
947
|
}
|
|
873
948
|
}
|
|
874
949
|
};
|
|
875
|
-
l(S, "description", "run tengo unit tests (.test.tengo)"), l(S, "strict", !1), l(S, "flags", { ...
|
|
876
|
-
let
|
|
877
|
-
class
|
|
950
|
+
l(S, "description", "run tengo unit tests (.test.tengo)"), l(S, "strict", !1), l(S, "flags", { ...ne }), l(S, "examples", ["<%= config.bin %> <%= command.id %>"]);
|
|
951
|
+
let H = S;
|
|
952
|
+
class Q extends v {
|
|
953
|
+
async run() {
|
|
954
|
+
const e = E();
|
|
955
|
+
ie(e, T);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
l(Q, "description", "parse sources in current package and dump all found artifacts to stdout"), l(Q, "examples", [
|
|
959
|
+
"<%= config.bin %> <%= command.id %>"
|
|
960
|
+
]);
|
|
961
|
+
class Y extends v {
|
|
878
962
|
async run() {
|
|
879
963
|
const e = E();
|
|
880
|
-
|
|
964
|
+
ht(e, T);
|
|
881
965
|
}
|
|
882
966
|
}
|
|
883
|
-
l(
|
|
967
|
+
l(Y, "description", "parse sources in current package and dump all found tests to stdout"), l(Y, "examples", [
|
|
884
968
|
"<%= config.bin %> <%= command.id %>"
|
|
885
969
|
]);
|
|
886
|
-
const A = class A extends
|
|
970
|
+
const A = class A extends v {
|
|
887
971
|
async run() {
|
|
888
972
|
const { flags: e } = await this.parse(A), r = E();
|
|
889
|
-
|
|
973
|
+
ut(r, e.deps, T);
|
|
890
974
|
}
|
|
891
975
|
};
|
|
892
976
|
l(A, "description", "parse sources in current package and dump all found templates to stdout"), l(A, "examples", [
|
|
@@ -894,45 +978,46 @@ l(A, "description", "parse sources in current package and dump all found templat
|
|
|
894
978
|
]), l(A, "flags", {
|
|
895
979
|
deps: F.boolean({ name: "deps", description: "add also all libraries found in node_modules" })
|
|
896
980
|
});
|
|
897
|
-
let
|
|
898
|
-
class
|
|
981
|
+
let _ = A;
|
|
982
|
+
class ee extends v {
|
|
899
983
|
async run() {
|
|
900
984
|
const e = E();
|
|
901
|
-
|
|
985
|
+
gt(e, T);
|
|
902
986
|
}
|
|
903
987
|
}
|
|
904
|
-
l(
|
|
988
|
+
l(ee, "description", "parse sources in current package and dump all found tests to stdout"), l(ee, "examples", [
|
|
905
989
|
"<%= config.bin %> <%= command.id %>"
|
|
906
990
|
]);
|
|
907
|
-
class
|
|
991
|
+
class te extends v {
|
|
908
992
|
async run() {
|
|
909
993
|
const e = E();
|
|
910
|
-
|
|
994
|
+
mt(e, T);
|
|
911
995
|
}
|
|
912
996
|
}
|
|
913
|
-
l(
|
|
997
|
+
l(te, "description", "parse sources in current package and dump all found templates to stdout"), l(te, "examples", [
|
|
914
998
|
"<%= config.bin %> <%= command.id %>"
|
|
915
999
|
]);
|
|
916
|
-
class
|
|
1000
|
+
class se extends v {
|
|
917
1001
|
async run() {
|
|
918
1002
|
const e = E();
|
|
919
|
-
|
|
1003
|
+
wt(e, T);
|
|
920
1004
|
}
|
|
921
1005
|
}
|
|
922
|
-
l(
|
|
1006
|
+
l(se, "description", "parse sources in current package and dump all found tests to stdout"), l(se, "examples", [
|
|
923
1007
|
"<%= config.bin %> <%= command.id %>"
|
|
924
1008
|
]);
|
|
925
|
-
const
|
|
926
|
-
build:
|
|
927
|
-
check:
|
|
928
|
-
test:
|
|
929
|
-
"dump:all":
|
|
930
|
-
"dump:
|
|
931
|
-
"dump:
|
|
932
|
-
"dump:
|
|
933
|
-
"dump:
|
|
1009
|
+
const xt = {
|
|
1010
|
+
build: K,
|
|
1011
|
+
check: X,
|
|
1012
|
+
test: H,
|
|
1013
|
+
"dump:all": Q,
|
|
1014
|
+
"dump:assets": Y,
|
|
1015
|
+
"dump:libs": _,
|
|
1016
|
+
"dump:software": ee,
|
|
1017
|
+
"dump:templates": te,
|
|
1018
|
+
"dump:tests": se
|
|
934
1019
|
};
|
|
935
1020
|
export {
|
|
936
|
-
|
|
1021
|
+
xt as COMMANDS
|
|
937
1022
|
};
|
|
938
1023
|
//# sourceMappingURL=index.mjs.map
|