@platforma-sdk/tengo-builder 1.19.1 → 2.0.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/compiler/artifactset.d.ts +0 -2
- package/dist/compiler/artifactset.d.ts.map +1 -1
- package/dist/compiler/compiler.d.ts.map +1 -1
- package/dist/compiler/main.d.ts +25 -7
- package/dist/compiler/main.d.ts.map +1 -1
- package/dist/compiler/package.d.ts +1 -0
- package/dist/compiler/package.d.ts.map +1 -1
- package/dist/compiler/util.d.ts.map +1 -1
- package/dist/index.js +27 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +337 -296
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
- package/src/commands/build.ts +1 -1
- package/src/compiler/artifactset.ts +3 -3
- package/src/compiler/compiler.ts +6 -5
- package/src/compiler/main.ts +131 -62
- package/src/compiler/package.ts +7 -0
- package/src/compiler/util.ts +8 -3
- package/src/shared/dump.ts +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { spawnSync as
|
|
5
|
-
import { Flags as F, Command as
|
|
1
|
+
var De = Object.defineProperty;
|
|
2
|
+
var Oe = (s, e, t) => e in s ? De(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
|
+
var c = (s, e, t) => Oe(s, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { spawnSync as xe, spawn as Fe } 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 * as
|
|
10
|
-
import { parseTemplate as
|
|
7
|
+
import * as m from "node:fs";
|
|
8
|
+
import { readFileSync as Re } from "node:fs";
|
|
9
|
+
import * as O from "winston";
|
|
10
|
+
import { parseTemplate as je, serializeTemplate as Me } from "@milaboratories/pl-model-backend";
|
|
11
|
+
import { tryResolve as Le, tryResolveOrError as Ce } from "@milaboratories/resolve-helper";
|
|
11
12
|
import * as x from "node:fs/promises";
|
|
12
|
-
import { TengoTesterBinaryPath as
|
|
13
|
+
import { TengoTesterBinaryPath as he } from "@milaboratories/tengo-tester";
|
|
13
14
|
import { stdout as D } from "node:process";
|
|
14
|
-
function
|
|
15
|
+
function R(s) {
|
|
15
16
|
throw new Error("Unexpected object: " + s);
|
|
16
17
|
}
|
|
17
|
-
function
|
|
18
|
-
return
|
|
18
|
+
function E(s = "debug") {
|
|
19
|
+
return O.createLogger({
|
|
19
20
|
level: s,
|
|
20
|
-
format:
|
|
21
|
+
format: O.format.combine(
|
|
22
|
+
O.format.errors({ stack: !0 }),
|
|
23
|
+
O.format.printf(({ level: e, message: t, stack: r }) => {
|
|
24
|
+
const n = `${e.padStart(6, " ")}: ${t}`;
|
|
25
|
+
return r ? `${n}
|
|
26
|
+
${r}` : n;
|
|
27
|
+
})
|
|
28
|
+
),
|
|
21
29
|
transports: [
|
|
22
|
-
new
|
|
30
|
+
new O.transports.Console({
|
|
23
31
|
stderrLevels: ["error", "warn", "info", "debug"],
|
|
24
32
|
handleExceptions: !0
|
|
25
33
|
})
|
|
26
34
|
]
|
|
27
35
|
});
|
|
28
36
|
}
|
|
29
|
-
function
|
|
30
|
-
let s = process.cwd();
|
|
31
|
-
for (; s; ) {
|
|
32
|
-
const e = f.join(s, "node_modules");
|
|
33
|
-
if (p.existsSync(e)) return e;
|
|
34
|
-
const t = f.resolve(s, "..");
|
|
35
|
-
if (t === s) break;
|
|
36
|
-
s = t;
|
|
37
|
-
}
|
|
38
|
-
throw new Error("Unable to find node_modules directory.");
|
|
39
|
-
}
|
|
40
|
-
function E(s) {
|
|
37
|
+
function k(s) {
|
|
41
38
|
try {
|
|
42
|
-
const e =
|
|
39
|
+
const e = m.statSync(s);
|
|
43
40
|
return e.isDirectory() ? "dir" : e.isFile() ? "file" : e.isSymbolicLink() ? "link" : "unknown";
|
|
44
41
|
} catch (e) {
|
|
45
42
|
const t = e;
|
|
46
|
-
if (t.code == "ENOENT") return "absent";
|
|
43
|
+
if (t.code == "ENOENT" || t.code == "ENOTDIR") return "absent";
|
|
47
44
|
throw t;
|
|
48
45
|
}
|
|
49
46
|
}
|
|
50
|
-
function
|
|
47
|
+
function Ie(s) {
|
|
51
48
|
return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(s.toLowerCase());
|
|
52
49
|
}
|
|
53
|
-
function
|
|
50
|
+
function le(s) {
|
|
54
51
|
return `${s.type}||${s.pkg}||${s.id}`;
|
|
55
52
|
}
|
|
56
|
-
function
|
|
53
|
+
function g(s) {
|
|
57
54
|
return `${s.type}:${s.pkg}:${s.id}:${s.version}`;
|
|
58
55
|
}
|
|
59
|
-
function
|
|
56
|
+
function h(s) {
|
|
60
57
|
return `${s.type}:${s.pkg}:${s.id}`;
|
|
61
58
|
}
|
|
62
|
-
function
|
|
59
|
+
function ce(s, e) {
|
|
63
60
|
return s.type == e.type && s.pkg == e.pkg && s.id == e.id;
|
|
64
61
|
}
|
|
65
|
-
function
|
|
62
|
+
function C(s, e) {
|
|
63
|
+
return s.type == e.type && s.pkg == e.pkg && s.id == e.id && s.version == e.version;
|
|
64
|
+
}
|
|
65
|
+
function y(s) {
|
|
66
66
|
return `${s.pkg}:${s.id}`;
|
|
67
67
|
}
|
|
68
|
-
function
|
|
69
|
-
return { name:
|
|
68
|
+
function I(s) {
|
|
69
|
+
return { name: y(s), version: s.version };
|
|
70
70
|
}
|
|
71
|
-
function
|
|
71
|
+
function Je(s) {
|
|
72
72
|
const e = s.name.match(/^(?<pkg>[^:]*):(?<id>[^:]*)$/);
|
|
73
73
|
if (!e) throw new Error(`malformed artifact name: ${s.name}`);
|
|
74
74
|
return { pkg: e.groups.pkg, id: e.groups.id, version: s.version };
|
|
75
75
|
}
|
|
76
|
-
function
|
|
76
|
+
function de(s) {
|
|
77
77
|
return `${s.pkg}:${s.id}:${s.version}`;
|
|
78
78
|
}
|
|
79
|
-
class
|
|
79
|
+
class we {
|
|
80
80
|
constructor(e, t, r) {
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
c(this, "data");
|
|
82
|
+
c(this, "content");
|
|
83
83
|
this.compileMode = e, this.fullName = t;
|
|
84
84
|
let { data: n, content: o } = r;
|
|
85
85
|
if (n === void 0 && o === void 0)
|
|
86
86
|
throw new Error("Neither data nor content is provided for template constructor");
|
|
87
87
|
if (n !== void 0 && o !== void 0)
|
|
88
88
|
throw new Error("Both data and content are provided for template constructor");
|
|
89
|
-
n === void 0 && (n =
|
|
90
|
-
const i =
|
|
89
|
+
n === void 0 && (n = je(o)), o === void 0 && (o = Me(n));
|
|
90
|
+
const i = Je(n);
|
|
91
91
|
if (i.pkg !== t.pkg || i.id !== t.id || i.version !== t.version)
|
|
92
92
|
throw new Error(
|
|
93
|
-
`Compiled template name don't match it's package and file names: ${
|
|
93
|
+
`Compiled template name don't match it's package and file names: ${de(i)} != ${de(t)}`
|
|
94
94
|
);
|
|
95
95
|
this.data = n, this.content = o;
|
|
96
96
|
}
|
|
@@ -98,17 +98,17 @@ class ye {
|
|
|
98
98
|
return { compileMode: this.compileMode, fullName: this.fullName, data: this.data };
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
-
class
|
|
101
|
+
class ye {
|
|
102
102
|
constructor(e) {
|
|
103
|
-
|
|
103
|
+
c(this, "map", /* @__PURE__ */ new Map());
|
|
104
104
|
this.nameExtractor = e;
|
|
105
105
|
}
|
|
106
106
|
add(e, t = !0) {
|
|
107
|
-
const r =
|
|
107
|
+
const r = le(this.nameExtractor(e)), n = this.map.get(r);
|
|
108
108
|
return n && !t || this.map.set(r, e), n;
|
|
109
109
|
}
|
|
110
110
|
get(e) {
|
|
111
|
-
return this.map.get(
|
|
111
|
+
return this.map.get(le(e));
|
|
112
112
|
}
|
|
113
113
|
get array() {
|
|
114
114
|
const e = [];
|
|
@@ -118,21 +118,21 @@ class U {
|
|
|
118
118
|
this.map.forEach((t) => e(t, this.nameExtractor(t)));
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
function
|
|
122
|
-
return new
|
|
121
|
+
function Pe() {
|
|
122
|
+
return new ye((s) => s);
|
|
123
123
|
}
|
|
124
|
-
class
|
|
124
|
+
class J {
|
|
125
125
|
constructor(e) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
this.
|
|
126
|
+
// private readonly dev: ArtifactMap<T>;
|
|
127
|
+
c(this, "dist");
|
|
128
|
+
this.dist = new ye(e);
|
|
129
129
|
}
|
|
130
130
|
add(e, t, r = !0) {
|
|
131
131
|
switch (e) {
|
|
132
132
|
case "dist":
|
|
133
133
|
return this.dist.add(t, r);
|
|
134
134
|
default:
|
|
135
|
-
|
|
135
|
+
R(e);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
get(e, t) {
|
|
@@ -140,7 +140,7 @@ class I {
|
|
|
140
140
|
case "dist":
|
|
141
141
|
return this.dist.get(t);
|
|
142
142
|
default:
|
|
143
|
-
|
|
143
|
+
R(e);
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
array(e) {
|
|
@@ -151,7 +151,7 @@ class I {
|
|
|
151
151
|
this.dist.forEach((r, n) => t(this.get(e, n) ?? r, n));
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
|
-
function
|
|
154
|
+
function Ge(s, e) {
|
|
155
155
|
for (const t of s)
|
|
156
156
|
switch (t.name) {
|
|
157
157
|
case "hash_override": {
|
|
@@ -160,7 +160,7 @@ function Je(s, e) {
|
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
-
function
|
|
163
|
+
function Ue(s, e) {
|
|
164
164
|
for (const t of s)
|
|
165
165
|
switch (t.name) {
|
|
166
166
|
case "hash_override":
|
|
@@ -175,7 +175,7 @@ function We(s) {
|
|
|
175
175
|
"hash_override compiler option expects exactly one argument: hash_override <some string>. Note, you can use only UUID as a value."
|
|
176
176
|
);
|
|
177
177
|
const e = s[0].toLowerCase();
|
|
178
|
-
if (!
|
|
178
|
+
if (!Ie(e))
|
|
179
179
|
throw new Error(
|
|
180
180
|
`hash_override must contain valid UUID as an override. As hash_override affects deduplication, it becomes completely not possible to distinguish several different templates from each other on backend's side. This means, if you set hash_override to a simple value (say, letter "a") on two completely different templates, they will be marked as interchangeable on backend's side with unpredictable consequences. UUID looks like a safe enough tradeoff between the feature usage simplicity and duplication safety`
|
|
181
181
|
);
|
|
@@ -183,57 +183,57 @@ function We(s) {
|
|
|
183
183
|
}
|
|
184
184
|
class ze {
|
|
185
185
|
constructor(e) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
186
|
+
c(this, "libs", new J((e) => e.fullName));
|
|
187
|
+
c(this, "software", new J((e) => e.fullName));
|
|
188
|
+
c(this, "assets", new J((e) => e.fullName));
|
|
189
|
+
c(this, "templates", new J((e) => e.fullName));
|
|
190
190
|
this.compileMode = e;
|
|
191
191
|
}
|
|
192
192
|
populateTemplateDataFromDependencies(e, t, r, n) {
|
|
193
193
|
for (const o of r)
|
|
194
194
|
switch (o.type) {
|
|
195
195
|
case "library": {
|
|
196
|
-
const i = this.getLibOrError(o), a = n.indexOf(
|
|
196
|
+
const i = this.getLibOrError(o), a = n.indexOf(y(o));
|
|
197
197
|
if (a >= 0) {
|
|
198
|
-
const
|
|
199
|
-
throw new Error(
|
|
198
|
+
const p = `library import recursion detected: ${n.slice(a).join(" -> ")} -> ${y(o)}`;
|
|
199
|
+
throw new Error(p);
|
|
200
200
|
}
|
|
201
|
-
const
|
|
202
|
-
...
|
|
201
|
+
const l = {
|
|
202
|
+
...I(i.fullName),
|
|
203
203
|
src: i.src
|
|
204
204
|
};
|
|
205
|
-
|
|
205
|
+
Ue(i.compilerOptions), t.libs[y(o)] = l, this.populateTemplateDataFromDependencies(e, t, i.dependencies, [...n, y(o)]);
|
|
206
206
|
break;
|
|
207
207
|
}
|
|
208
208
|
case "software": {
|
|
209
209
|
const i = this.getSoftwareOrError(o);
|
|
210
|
-
t.software[
|
|
211
|
-
...
|
|
210
|
+
t.software[y(o)] = {
|
|
211
|
+
...I(i.fullName),
|
|
212
212
|
src: i.src
|
|
213
213
|
};
|
|
214
214
|
break;
|
|
215
215
|
}
|
|
216
216
|
case "asset": {
|
|
217
217
|
const i = this.getAssetOrError(o);
|
|
218
|
-
t.software[
|
|
219
|
-
...
|
|
218
|
+
t.software[y(o)] = {
|
|
219
|
+
...I(i.fullName),
|
|
220
220
|
src: i.src
|
|
221
221
|
};
|
|
222
222
|
break;
|
|
223
223
|
}
|
|
224
224
|
case "template": {
|
|
225
|
-
if (
|
|
225
|
+
if (ce(e, o))
|
|
226
226
|
continue;
|
|
227
227
|
const i = this.getTemplateOrError(o);
|
|
228
|
-
t.templates[
|
|
228
|
+
t.templates[y(o)] = i.data;
|
|
229
229
|
break;
|
|
230
230
|
}
|
|
231
231
|
case "test":
|
|
232
232
|
throw new Error(
|
|
233
|
-
`dependencies tree error: tests should never be part of template: ${
|
|
233
|
+
`dependencies tree error: tests should never be part of template: ${h(o)} is dependency of ${y(e)}`
|
|
234
234
|
);
|
|
235
235
|
default:
|
|
236
|
-
|
|
236
|
+
R(o.type);
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
239
|
/** This method assumes that all dependencies are already added to the compiler's context */
|
|
@@ -242,22 +242,22 @@ class ze {
|
|
|
242
242
|
throw new Error("unexpected source type");
|
|
243
243
|
const t = {
|
|
244
244
|
type: "pl.tengo-template.v2",
|
|
245
|
-
...
|
|
245
|
+
...I(e.fullName),
|
|
246
246
|
templates: {},
|
|
247
247
|
libs: {},
|
|
248
248
|
software: {},
|
|
249
249
|
assets: {},
|
|
250
250
|
src: e.src
|
|
251
251
|
};
|
|
252
|
-
|
|
253
|
-
const r = new
|
|
252
|
+
Ge(e.compilerOptions, t), this.populateTemplateDataFromDependencies(e.fullName, t, e.dependencies, []);
|
|
253
|
+
const r = new we(e.compileMode, e.fullName, { data: t });
|
|
254
254
|
return this.addTemplate(r), r;
|
|
255
255
|
}
|
|
256
256
|
addLib(e) {
|
|
257
257
|
const t = this.libs.add(e.compileMode, e, !1);
|
|
258
|
-
if (t)
|
|
258
|
+
if (t && !C(e.fullName, t.fullName))
|
|
259
259
|
throw new Error(
|
|
260
|
-
`compiler already contain such library: adding = ${
|
|
260
|
+
`compiler already contain such library: adding = ${g(e.fullName)}, contains = ${g(t.fullName)}`
|
|
261
261
|
);
|
|
262
262
|
}
|
|
263
263
|
allLibs() {
|
|
@@ -271,14 +271,14 @@ class ze {
|
|
|
271
271
|
getLibOrError(e) {
|
|
272
272
|
const t = this.getLib(e);
|
|
273
273
|
if (!t)
|
|
274
|
-
throw new Error(`library not found: ${
|
|
274
|
+
throw new Error(`library not found: ${y(e)}`);
|
|
275
275
|
return t;
|
|
276
276
|
}
|
|
277
277
|
addSoftware(e) {
|
|
278
278
|
const t = this.software.add(e.compileMode, e, !1);
|
|
279
|
-
if (t)
|
|
279
|
+
if (t && !C(e.fullName, t.fullName))
|
|
280
280
|
throw new Error(
|
|
281
|
-
`compiler already contain info for software: adding = ${
|
|
281
|
+
`compiler already contain info for software: adding = ${g(e.fullName)}, contains = ${g(t.fullName)}`
|
|
282
282
|
);
|
|
283
283
|
}
|
|
284
284
|
allSoftware() {
|
|
@@ -292,14 +292,14 @@ class ze {
|
|
|
292
292
|
getSoftwareOrError(e) {
|
|
293
293
|
const t = this.getSoftware(e);
|
|
294
294
|
if (!t)
|
|
295
|
-
throw new Error(`software info not found: ${
|
|
295
|
+
throw new Error(`software info not found: ${y(e)}`);
|
|
296
296
|
return t;
|
|
297
297
|
}
|
|
298
298
|
addAsset(e) {
|
|
299
299
|
const t = this.assets.add(e.compileMode, e, !1);
|
|
300
|
-
if (t)
|
|
300
|
+
if (t && !C(e.fullName, t.fullName))
|
|
301
301
|
throw new Error(
|
|
302
|
-
`compiler already contain info for asset: adding = ${
|
|
302
|
+
`compiler already contain info for asset: adding = ${g(e.fullName)}, contains = ${g(t.fullName)}`
|
|
303
303
|
);
|
|
304
304
|
}
|
|
305
305
|
allAssets() {
|
|
@@ -313,14 +313,14 @@ class ze {
|
|
|
313
313
|
getAssetOrError(e) {
|
|
314
314
|
const t = this.getAsset(e);
|
|
315
315
|
if (!t)
|
|
316
|
-
throw new Error(`asset info not found: ${
|
|
316
|
+
throw new Error(`asset info not found: ${y(e)}`);
|
|
317
317
|
return t;
|
|
318
318
|
}
|
|
319
319
|
addTemplate(e) {
|
|
320
320
|
const t = this.templates.add(e.compileMode, e, !1);
|
|
321
|
-
if (t)
|
|
321
|
+
if (t && !C(e.fullName, t.fullName))
|
|
322
322
|
throw new Error(
|
|
323
|
-
`compiler already contain such template: adding = ${
|
|
323
|
+
`compiler already contain such template: adding = ${g(e.fullName)}, contains = ${g(t.fullName)}`
|
|
324
324
|
);
|
|
325
325
|
}
|
|
326
326
|
allTemplates() {
|
|
@@ -334,7 +334,7 @@ class ze {
|
|
|
334
334
|
getTemplateOrError(e) {
|
|
335
335
|
const t = this.getTemplate(e);
|
|
336
336
|
if (!t)
|
|
337
|
-
throw new Error(`template not found: ${
|
|
337
|
+
throw new Error(`template not found: ${y(e)}`);
|
|
338
338
|
return t;
|
|
339
339
|
}
|
|
340
340
|
getArtefact(e) {
|
|
@@ -350,16 +350,16 @@ class ze {
|
|
|
350
350
|
case "test":
|
|
351
351
|
return;
|
|
352
352
|
default:
|
|
353
|
-
|
|
353
|
+
R(e.type);
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
356
|
checkLibs() {
|
|
357
357
|
this.libs.forEach(this.compileMode, (e) => {
|
|
358
358
|
for (const t of e.dependencies) {
|
|
359
359
|
if (t.type === "test")
|
|
360
|
-
throw new Error(`test should never be dependency of production code: ${
|
|
360
|
+
throw new Error(`test should never be dependency of production code: ${h(t)} test is dependency of ${g(e.fullName)}`);
|
|
361
361
|
if (!this.getArtefact(t))
|
|
362
|
-
throw new Error(`unresolved dependency ${
|
|
362
|
+
throw new Error(`unresolved dependency ${h(t)} for ${g(e.fullName)}`);
|
|
363
363
|
}
|
|
364
364
|
});
|
|
365
365
|
}
|
|
@@ -372,15 +372,15 @@ class ze {
|
|
|
372
372
|
const n = [];
|
|
373
373
|
for (const o of r) {
|
|
374
374
|
const i = o.dependencies.filter(
|
|
375
|
-
(a) => !this.getArtefact(a) && !(o.fullName.type === "template" &&
|
|
375
|
+
(a) => !this.getArtefact(a) && !(o.fullName.type === "template" && ce(o.fullName, a))
|
|
376
376
|
);
|
|
377
377
|
if (i.length > 0) {
|
|
378
|
-
let a = `Unsatisfied dependencies in ${
|
|
378
|
+
let a = `Unsatisfied dependencies in ${g(o.fullName)}:
|
|
379
379
|
`;
|
|
380
|
-
for (const
|
|
381
|
-
a += ` - ${
|
|
380
|
+
for (const l of i)
|
|
381
|
+
a += ` - ${h(l)}
|
|
382
382
|
`;
|
|
383
|
-
n.push({ src: o, err: Error(a) });
|
|
383
|
+
n.push({ src: o, err: new Error(a) });
|
|
384
384
|
continue;
|
|
385
385
|
}
|
|
386
386
|
switch (o.fullName.type) {
|
|
@@ -398,17 +398,17 @@ class ze {
|
|
|
398
398
|
const a = this.compileAndAddTemplate(o);
|
|
399
399
|
t.templates.push(a);
|
|
400
400
|
} catch (a) {
|
|
401
|
-
const
|
|
402
|
-
let
|
|
401
|
+
const l = a;
|
|
402
|
+
let p = `Unsatisfied dependencies in ${g(o.fullName)}:
|
|
403
403
|
`;
|
|
404
|
-
|
|
405
|
-
`, n.push({ src: o, err: Error(
|
|
404
|
+
p += ` - ${l.message}
|
|
405
|
+
`, n.push({ src: o, err: Error(p) });
|
|
406
406
|
}
|
|
407
407
|
break;
|
|
408
408
|
case "test":
|
|
409
409
|
break;
|
|
410
410
|
default:
|
|
411
|
-
|
|
411
|
+
R(o.fullName.type);
|
|
412
412
|
}
|
|
413
413
|
}
|
|
414
414
|
if (r.length === n.length) {
|
|
@@ -423,10 +423,10 @@ ${i.err.message}`;
|
|
|
423
423
|
return t;
|
|
424
424
|
}
|
|
425
425
|
}
|
|
426
|
-
const
|
|
426
|
+
const fe = "[_a-zA-Z][_a-zA-Z0-9]*", j = (s, e) => new RegExp(
|
|
427
427
|
`\\b${s}\\.(?<fnCall>(?<fnName>` + e + ')\\s*\\(\\s*"(?<templateName>[^"]+)"\\s*\\))'
|
|
428
|
-
), _e = (s) =>
|
|
429
|
-
`\\b(?<importName>${
|
|
428
|
+
), _e = (s) => j(s, "getTemplateId"), qe = (s) => j(s, "getSoftwareInfo"), pe = (s) => j(s, "importTemplate"), ue = (s) => j(s, "importSoftware"), Be = (s) => j(s, "importAsset"), Ke = /^\s*$/, Ve = /^\/\/tengo:[\w]/, Xe = /^\s*\/\/\s*tengo:\s*./, Ze = /\/\*.*?\*\//g, He = /^\s*(\/\/)/, Ye = /^\s*\/\*/, Qe = /\*\//, be = /\s*:=\s*import\s*\(\s*"(?<moduleName>[^"]+)"\s*\)/, et = new RegExp(
|
|
429
|
+
`\\b(?<importName>${fe}(\\.${fe})*)${be.source}`
|
|
430
430
|
), tt = /(?<pkgName>[^"]+)?:(?<depID>[^"]+)/, st = (s) => {
|
|
431
431
|
const e = s.split(" "), t = e[0].split(":");
|
|
432
432
|
if (t.length != 2)
|
|
@@ -438,39 +438,39 @@ const pe = "[_a-zA-Z][_a-zA-Z0-9]*", R = (s, e) => new RegExp(
|
|
|
438
438
|
args: e.slice(1)
|
|
439
439
|
};
|
|
440
440
|
};
|
|
441
|
-
class
|
|
441
|
+
class re {
|
|
442
442
|
constructor(e, t, r, n, o, i) {
|
|
443
443
|
this.compileMode = e, this.fullName = t, this.src = r, this.srcName = n, this.dependencies = o, this.compilerOptions = i;
|
|
444
444
|
}
|
|
445
445
|
}
|
|
446
446
|
function ve(s, e, t, r, n) {
|
|
447
|
-
const o =
|
|
448
|
-
return new
|
|
447
|
+
const o = Re(t).toString(), { deps: i, normalized: a, opts: l } = ot(s, o, r, n);
|
|
448
|
+
return new re(e, r, a, t, i.array, l);
|
|
449
449
|
}
|
|
450
450
|
function ot(s, e, t, r) {
|
|
451
|
-
const n =
|
|
451
|
+
const n = Pe(), o = [], i = e.split(`
|
|
452
452
|
`), a = [];
|
|
453
|
-
let
|
|
453
|
+
let l = {
|
|
454
454
|
isInCommentBlock: !1,
|
|
455
455
|
canDetectOptions: !0,
|
|
456
456
|
tplDepREs: /* @__PURE__ */ new Map(),
|
|
457
457
|
lineNo: 0
|
|
458
458
|
};
|
|
459
|
-
for (const
|
|
460
|
-
|
|
459
|
+
for (const p of i) {
|
|
460
|
+
l.lineNo++;
|
|
461
461
|
try {
|
|
462
462
|
const d = rt(
|
|
463
463
|
s,
|
|
464
|
-
|
|
465
|
-
|
|
464
|
+
p,
|
|
465
|
+
l,
|
|
466
466
|
t.pkg,
|
|
467
467
|
r
|
|
468
468
|
);
|
|
469
|
-
a.push(d.line),
|
|
469
|
+
a.push(d.line), l = d.context, d.artifact && n.add(d.artifact), d.option && o.push(d.option);
|
|
470
470
|
} catch (d) {
|
|
471
|
-
const
|
|
472
|
-
throw new Error(`[line ${
|
|
473
|
-
${
|
|
471
|
+
const u = d;
|
|
472
|
+
throw new Error(`[line ${l.lineNo} in ${g(t)}]: ${u.message}
|
|
473
|
+
${p}`, { cause: u });
|
|
474
474
|
}
|
|
475
475
|
}
|
|
476
476
|
return {
|
|
@@ -481,26 +481,26 @@ function ot(s, e, t, r) {
|
|
|
481
481
|
};
|
|
482
482
|
}
|
|
483
483
|
function rt(s, e, t, r, n) {
|
|
484
|
-
if (e = e.replaceAll(
|
|
484
|
+
if (e = e.replaceAll(Ze, ""), t.isInCommentBlock)
|
|
485
485
|
return Qe.exec(e) && (t.isInCommentBlock = !1), { line: "", context: t, artifact: void 0, option: void 0 };
|
|
486
|
-
if (
|
|
486
|
+
if (Ve.exec(e)) {
|
|
487
487
|
if (!t.canDetectOptions)
|
|
488
488
|
throw s.error(
|
|
489
489
|
`[line ${t.lineNo}]: compiler option '//tengo:' was detected, but it cannot be applied as compiler options can be set only at the file header, before any code line'`
|
|
490
490
|
), new Error("tengo compiler options ('//tengo:' comments) can be set only in file header");
|
|
491
491
|
return { line: e, context: t, artifact: void 0, option: st(e) };
|
|
492
492
|
}
|
|
493
|
-
if (
|
|
493
|
+
if (Xe.exec(e) && t.canDetectOptions)
|
|
494
494
|
return s.warn(
|
|
495
495
|
`[line ${t.lineNo}]: text simillar to compiler option ('//tengo:...') was detected, but it has wrong format. Leave it as is, if you did not mean to use a line as compiler option. Or format it to '//tengo:<option>' otherwise (no spaces between '//' and 'tengo', no spaces between ':' and option name)`
|
|
496
496
|
), { line: e, context: t, artifact: void 0, option: void 0 };
|
|
497
|
-
if (
|
|
497
|
+
if (He.test(e))
|
|
498
498
|
return { line: "", context: t, artifact: void 0, option: void 0 };
|
|
499
|
-
if (
|
|
499
|
+
if (Ye.exec(e))
|
|
500
500
|
return t.isInCommentBlock = !0, { line: "", context: t, artifact: void 0, option: void 0 };
|
|
501
501
|
if (e.includes("/*"))
|
|
502
502
|
throw new Error("malformed multiline comment");
|
|
503
|
-
if (
|
|
503
|
+
if (Ke.exec(e))
|
|
504
504
|
return { line: e, context: t, artifact: void 0, option: void 0 };
|
|
505
505
|
t.canDetectOptions = !1;
|
|
506
506
|
const o = be.exec(e);
|
|
@@ -512,29 +512,29 @@ function rt(s, e, t, r, n) {
|
|
|
512
512
|
["software", qe(i.alias)]
|
|
513
513
|
]), { line: e, context: t, artifact: void 0, option: void 0 };
|
|
514
514
|
(i.module === "@milaboratory/tengo-sdk:ll" || i.module === "@platforma-sdk/workflow-tengo:ll" || (r === "@milaboratory/tengo-sdk" || r === "@platforma-sdk/workflow-tengo") && i.module === ":ll") && (t.tplDepREs.has(i.module) || t.tplDepREs.set(i.module, [
|
|
515
|
-
["template",
|
|
516
|
-
["software",
|
|
515
|
+
["template", pe(i.alias)],
|
|
516
|
+
["software", ue(i.alias)]
|
|
517
517
|
])), (i.module === "@milaboratory/tengo-sdk:assets" || i.module === "@platforma-sdk/workflow-tengo:assets" || (r === "@milaboratory/tengo-sdk" || r === "@platforma-sdk/workflow-tengo") && i.module === ":assets") && (t.tplDepREs.has(i.module) || t.tplDepREs.set(i.module, [
|
|
518
|
-
["template",
|
|
519
|
-
["software",
|
|
518
|
+
["template", pe(i.alias)],
|
|
519
|
+
["software", ue(i.alias)],
|
|
520
520
|
["asset", Be(i.alias)]
|
|
521
521
|
]));
|
|
522
|
-
const a =
|
|
522
|
+
const a = me(i.module, "library", r);
|
|
523
523
|
return a ? (e = e.replace(o[0], ` := import("${a.pkg}:${a.id}")`), { line: e, context: t, artifact: a, option: void 0 }) : { line: e, context: t, artifact: void 0, option: void 0 };
|
|
524
524
|
}
|
|
525
525
|
if (t.tplDepREs.size > 0)
|
|
526
526
|
for (const [i, a] of t.tplDepREs)
|
|
527
|
-
for (const [
|
|
528
|
-
const d =
|
|
527
|
+
for (const [l, p] of a) {
|
|
528
|
+
const d = p.exec(e);
|
|
529
529
|
if (!d || !d.groups)
|
|
530
530
|
continue;
|
|
531
|
-
const { fnCall:
|
|
532
|
-
if (!
|
|
531
|
+
const { fnCall: u, templateName: w, fnName: b } = d.groups;
|
|
532
|
+
if (!u || !w || !b)
|
|
533
533
|
throw Error("failed to parse template import statement");
|
|
534
|
-
const
|
|
535
|
-
if (!
|
|
536
|
-
throw Error(`failed to parse artifact name in ${
|
|
537
|
-
return e = e.replace(
|
|
534
|
+
const L = me(w, l, r);
|
|
535
|
+
if (!L)
|
|
536
|
+
throw Error(`failed to parse artifact name in ${b} import statement`);
|
|
537
|
+
return e = e.replace(u, `${b}("${L.pkg}:${L.id}")`), { line: e, context: t, artifact: L, option: void 0 };
|
|
538
538
|
}
|
|
539
539
|
return { line: e, context: t, artifact: void 0, option: void 0 };
|
|
540
540
|
}
|
|
@@ -550,7 +550,7 @@ function nt(s) {
|
|
|
550
550
|
alias: t
|
|
551
551
|
};
|
|
552
552
|
}
|
|
553
|
-
function
|
|
553
|
+
function me(s, e, t) {
|
|
554
554
|
const r = tt.exec(s);
|
|
555
555
|
if (!r)
|
|
556
556
|
return;
|
|
@@ -565,9 +565,58 @@ function ge(s, e, t) {
|
|
|
565
565
|
);
|
|
566
566
|
return { type: e, pkg: n ?? t, id: o };
|
|
567
567
|
}
|
|
568
|
-
const
|
|
569
|
-
function
|
|
570
|
-
|
|
568
|
+
const U = ".plj.gz", W = ".lib.tengo", z = ".sw.json", _ = ".as.json", ge = ".test.tengo", q = ".tpl.tengo", B = ".lib.tengo", K = ".sw.json", V = ".as.json", it = [B, q, K, V];
|
|
569
|
+
function G(s, e) {
|
|
570
|
+
if (!f.isAbsolute(s))
|
|
571
|
+
throw new Error(`Root path must be absolute: ${s}`);
|
|
572
|
+
if (!e) {
|
|
573
|
+
const n = f.join(s, "package.json");
|
|
574
|
+
if (k(n) === "file")
|
|
575
|
+
return n;
|
|
576
|
+
throw new Error(`Can't resolve package.json in ${s}`);
|
|
577
|
+
}
|
|
578
|
+
let t = Le(s, e);
|
|
579
|
+
if (t) {
|
|
580
|
+
let n = 0;
|
|
581
|
+
do {
|
|
582
|
+
const o = f.join(t, "package.json");
|
|
583
|
+
if (k(o) === "file")
|
|
584
|
+
return o;
|
|
585
|
+
n++, t = f.dirname(t);
|
|
586
|
+
} while (n < 7 && f.basename(t) !== "node_modules");
|
|
587
|
+
}
|
|
588
|
+
const r = Ce(s, `${e}/package.json`);
|
|
589
|
+
if (r.result === void 0) {
|
|
590
|
+
if (r.err === "ERR_PACKAGE_PATH_NOT_EXPORTED")
|
|
591
|
+
return;
|
|
592
|
+
throw new Error(`Can't resolve package.json for package ${e ?? "."} relative to ${s}`);
|
|
593
|
+
}
|
|
594
|
+
return r.result;
|
|
595
|
+
}
|
|
596
|
+
function S(s, e, t = "root") {
|
|
597
|
+
const r = G(s);
|
|
598
|
+
if (!r)
|
|
599
|
+
throw new Error(`Can't resolve package.json for root package ${s}`);
|
|
600
|
+
const { name: n, version: o, type: i, dependencies: a, devDependencies: l } = JSON.parse(m.readFileSync(r).toString()), p = [];
|
|
601
|
+
if (a && t !== "devDependency")
|
|
602
|
+
for (const u of Object.keys(a)) {
|
|
603
|
+
const w = G(s, u);
|
|
604
|
+
if (w === void 0)
|
|
605
|
+
throw new Error(`Can't resolve package.json for dependency ${u} of ${s}`);
|
|
606
|
+
const b = f.dirname(w);
|
|
607
|
+
p.push(S(b, e, "dependency"));
|
|
608
|
+
}
|
|
609
|
+
if (l && t === "root")
|
|
610
|
+
for (const u of Object.keys(l)) {
|
|
611
|
+
const w = G(s, u);
|
|
612
|
+
if (w === void 0) {
|
|
613
|
+
e.warn(`Can't resolve package.json for dev dependency ${u} of ${s}`);
|
|
614
|
+
continue;
|
|
615
|
+
}
|
|
616
|
+
const b = f.dirname(w);
|
|
617
|
+
p.push(S(b, e, "devDependency"));
|
|
618
|
+
}
|
|
619
|
+
return { name: n, version: o, type: i, dependencies: p, root: s, context: t };
|
|
571
620
|
}
|
|
572
621
|
function Ee(s, e) {
|
|
573
622
|
return f.resolve(e, s, "tengo", "lib");
|
|
@@ -578,140 +627,132 @@ function $e(s, e) {
|
|
|
578
627
|
function Ne(s, e) {
|
|
579
628
|
return f.resolve(e, s, "tengo", "software");
|
|
580
629
|
}
|
|
581
|
-
function
|
|
630
|
+
function ke(s, e) {
|
|
582
631
|
return f.resolve(e, s, "tengo", "asset");
|
|
583
632
|
}
|
|
584
|
-
function
|
|
585
|
-
const
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
const De = E(f.join(r, ae)) === "link", le = f.resolve(r, ae);
|
|
589
|
-
E(le) === "dir" && ke(s, e, t, le, De);
|
|
590
|
-
}
|
|
633
|
+
function Se(s, e, t) {
|
|
634
|
+
for (const w of t.dependencies)
|
|
635
|
+
Se(s, e, w);
|
|
636
|
+
if (t.context === "root")
|
|
591
637
|
return;
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
if (!d && !w && !v && !y)
|
|
638
|
+
const r = Ee("dist", t.root), n = $e("dist", t.root), o = Ne("dist", t.root), i = ke("dist", t.root), a = k(r) === "dir", l = k(n) === "dir", p = k(o) === "dir", d = k(i) === "dir";
|
|
639
|
+
if (!a && !l && !p && !d)
|
|
595
640
|
return;
|
|
596
|
-
const
|
|
597
|
-
|
|
598
|
-
if (E(f.resolve(r, "node_modules")) === "dir" && n)
|
|
599
|
-
throw new Error(
|
|
600
|
-
`nested node_modules is a sign of library dependencies version incompatibility in ${r}`
|
|
601
|
-
);
|
|
602
|
-
d && at(s, b, "dist", i, e), w && lt(s, b, "dist", a, e), v && ct(s, b, "dist", c, e), y && dt(s, b, "dist", u, e);
|
|
603
|
-
}
|
|
641
|
+
const u = { name: t.name, version: t.version };
|
|
642
|
+
a && at(s, u, "dist", r, e), l && lt(s, u, "dist", n, e), p && ct(s, u, "dist", o, e), d && dt(s, u, "dist", i, e);
|
|
604
643
|
}
|
|
605
644
|
function at(s, e, t, r, n) {
|
|
606
|
-
for (const o of
|
|
645
|
+
for (const o of m.readdirSync(r)) {
|
|
607
646
|
const i = f.resolve(r, o);
|
|
608
|
-
if (!o.endsWith(
|
|
647
|
+
if (!o.endsWith(W)) throw new Error(`unexpected file in 'lib' folder: ${i}`);
|
|
609
648
|
const a = {
|
|
610
649
|
type: "library",
|
|
611
650
|
pkg: e.name,
|
|
612
|
-
id: o.slice(0, o.length -
|
|
651
|
+
id: o.slice(0, o.length - W.length),
|
|
613
652
|
version: e.version
|
|
614
|
-
},
|
|
615
|
-
if (n.addLib(
|
|
653
|
+
}, l = ve(s, t, i, a, !0);
|
|
654
|
+
if (n.addLib(l), s.debug(`Adding dependency ${g(a)} from ${i}`), l.dependencies.length > 0) {
|
|
616
655
|
s.debug("Dependencies:");
|
|
617
|
-
for (const
|
|
656
|
+
for (const p of l.dependencies) s.debug(` - ${h(p)}`);
|
|
618
657
|
}
|
|
619
658
|
}
|
|
620
659
|
}
|
|
621
660
|
function lt(s, e, t, r, n) {
|
|
622
|
-
for (const o of
|
|
661
|
+
for (const o of m.readdirSync(r)) {
|
|
623
662
|
const i = f.resolve(r, o);
|
|
624
|
-
if (!o.endsWith(
|
|
663
|
+
if (!o.endsWith(U)) throw new Error(`unexpected file in 'tpl' folder: ${i}`);
|
|
625
664
|
const a = {
|
|
626
665
|
type: "template",
|
|
627
666
|
pkg: e.name,
|
|
628
|
-
id: o.slice(0, o.length -
|
|
667
|
+
id: o.slice(0, o.length - U.length),
|
|
629
668
|
version: e.version
|
|
630
|
-
},
|
|
631
|
-
n.addTemplate(
|
|
669
|
+
}, l = new we(t, a, { content: m.readFileSync(i) });
|
|
670
|
+
n.addTemplate(l), s.debug(`Adding dependency ${g(a)} from ${i}`);
|
|
632
671
|
}
|
|
633
672
|
}
|
|
634
673
|
function ct(s, e, t, r, n) {
|
|
635
|
-
for (const o of
|
|
674
|
+
for (const o of m.readdirSync(r)) {
|
|
636
675
|
const i = f.resolve(r, o);
|
|
637
|
-
if (!o.endsWith(
|
|
676
|
+
if (!o.endsWith(z))
|
|
638
677
|
throw new Error(`unexpected file in 'software' folder: ${i}`);
|
|
639
678
|
const a = {
|
|
640
679
|
type: "software",
|
|
641
680
|
pkg: e.name,
|
|
642
|
-
id: o.slice(0, o.length -
|
|
681
|
+
id: o.slice(0, o.length - z.length),
|
|
643
682
|
version: e.version
|
|
644
|
-
},
|
|
645
|
-
s.debug(`Adding dependency ${
|
|
683
|
+
}, l = new re(t, a, m.readFileSync(i).toString(), i, [], []);
|
|
684
|
+
s.debug(`Adding dependency ${g(a)} from ${i}`), n.addSoftware(l);
|
|
646
685
|
}
|
|
647
686
|
}
|
|
648
687
|
function dt(s, e, t, r, n) {
|
|
649
|
-
for (const o of
|
|
688
|
+
for (const o of m.readdirSync(r)) {
|
|
650
689
|
const i = f.resolve(r, o);
|
|
651
|
-
if (!o.endsWith(
|
|
690
|
+
if (!o.endsWith(_))
|
|
652
691
|
throw new Error(`unexpected file in 'asset' folder: ${i}`);
|
|
653
692
|
const a = {
|
|
654
693
|
type: "asset",
|
|
655
694
|
pkg: e.name,
|
|
656
|
-
id: o.slice(0, o.length -
|
|
695
|
+
id: o.slice(0, o.length - _.length),
|
|
657
696
|
version: e.version
|
|
658
|
-
},
|
|
659
|
-
s.debug(`Adding dependency ${
|
|
697
|
+
}, l = new re(t, a, m.readFileSync(i).toString(), i, [], []);
|
|
698
|
+
s.debug(`Adding dependency ${g(a)} from ${i}`), n.addAsset(l);
|
|
660
699
|
}
|
|
661
700
|
}
|
|
662
|
-
function
|
|
701
|
+
function M(s, e, t, r, n) {
|
|
663
702
|
const o = [];
|
|
664
|
-
for (const i of
|
|
665
|
-
const a = f.join(n, i),
|
|
666
|
-
if (
|
|
667
|
-
const
|
|
668
|
-
o.push(...
|
|
703
|
+
for (const i of m.readdirSync(f.join(r, n))) {
|
|
704
|
+
const a = f.join(n, i), l = f.join(r, a);
|
|
705
|
+
if (k(l) === "dir") {
|
|
706
|
+
const b = M(s, e, t, r, a);
|
|
707
|
+
o.push(...b);
|
|
669
708
|
continue;
|
|
670
709
|
}
|
|
671
|
-
const
|
|
672
|
-
if (!d)
|
|
710
|
+
const p = i === "index.lib.tengo" ? `${f.dirname(a)}.lib.tengo` : a, d = ft(e, p.replaceAll(f.sep, "."));
|
|
711
|
+
if (!d) {
|
|
712
|
+
s.info(`Skipping unknown file type: ${p}`);
|
|
673
713
|
continue;
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
714
|
+
}
|
|
715
|
+
const u = f.resolve(r, a);
|
|
716
|
+
s.debug(`Parsing ${g(d)} from ${u}`);
|
|
717
|
+
const w = ve(s, t, u, d, !0);
|
|
718
|
+
if (w.dependencies.length > 0) {
|
|
678
719
|
s.debug("Detected dependencies:");
|
|
679
|
-
for (const
|
|
720
|
+
for (const b of w.dependencies) s.debug(` - ${h(b)}`);
|
|
680
721
|
}
|
|
681
|
-
o.push(
|
|
722
|
+
o.push(w);
|
|
682
723
|
}
|
|
683
724
|
return o;
|
|
684
725
|
}
|
|
685
|
-
function
|
|
726
|
+
function ne(s, e, t) {
|
|
686
727
|
const r = new ze(t);
|
|
687
|
-
return
|
|
728
|
+
return Se(s, r, e), r;
|
|
688
729
|
}
|
|
689
730
|
function ft(s, e) {
|
|
690
731
|
const t = { pkg: s.name, version: s.version };
|
|
691
|
-
return e.endsWith(
|
|
732
|
+
return e.endsWith(B) ? {
|
|
692
733
|
...t,
|
|
693
|
-
id: e.substring(0, e.length -
|
|
734
|
+
id: e.substring(0, e.length - B.length),
|
|
694
735
|
type: "library"
|
|
695
|
-
} : e.endsWith(
|
|
736
|
+
} : e.endsWith(q) ? {
|
|
696
737
|
...t,
|
|
697
|
-
id: e.substring(0, e.length -
|
|
738
|
+
id: e.substring(0, e.length - q.length),
|
|
698
739
|
type: "template"
|
|
699
|
-
} : e.endsWith(
|
|
740
|
+
} : e.endsWith(K) ? {
|
|
700
741
|
...t,
|
|
701
|
-
id: e.substring(0, e.length -
|
|
742
|
+
id: e.substring(0, e.length - K.length),
|
|
702
743
|
type: "software"
|
|
703
744
|
} : e.endsWith(V) ? {
|
|
704
745
|
...t,
|
|
705
746
|
id: e.substring(0, e.length - V.length),
|
|
706
747
|
type: "asset"
|
|
707
|
-
} : e.endsWith(
|
|
748
|
+
} : e.endsWith(ge) ? {
|
|
708
749
|
...t,
|
|
709
|
-
id: e.substring(0, e.length -
|
|
750
|
+
id: e.substring(0, e.length - ge.length),
|
|
710
751
|
type: "test"
|
|
711
752
|
} : null;
|
|
712
753
|
}
|
|
713
754
|
function pt(s, e) {
|
|
714
|
-
const t =
|
|
755
|
+
const t = S(process.cwd(), s), r = ne(s, t, e), n = M(s, t, e, "src", "");
|
|
715
756
|
if (n.length === 0) {
|
|
716
757
|
const i = [];
|
|
717
758
|
for (const a of it)
|
|
@@ -725,38 +766,38 @@ function pt(s, e) {
|
|
|
725
766
|
function ut(s, e, t) {
|
|
726
767
|
if (e.libs.length > 0) {
|
|
727
768
|
const r = Ee(t, ".");
|
|
728
|
-
|
|
769
|
+
m.mkdirSync(r, { recursive: !0 });
|
|
729
770
|
for (const n of e.libs) {
|
|
730
|
-
const o = f.resolve(r, n.fullName.id +
|
|
731
|
-
s.info(` - writing ${o}`),
|
|
771
|
+
const o = f.resolve(r, n.fullName.id + W);
|
|
772
|
+
s.info(` - writing ${o}`), m.writeFileSync(o, n.src);
|
|
732
773
|
}
|
|
733
774
|
}
|
|
734
775
|
if (e.templates.length > 0) {
|
|
735
776
|
const r = $e(t, ".");
|
|
736
|
-
|
|
777
|
+
m.mkdirSync(r, { recursive: !0 });
|
|
737
778
|
for (const n of e.templates) {
|
|
738
|
-
const o = f.resolve(r, n.fullName.id +
|
|
739
|
-
s.info(` - writing ${o}`),
|
|
779
|
+
const o = f.resolve(r, n.fullName.id + U);
|
|
780
|
+
s.info(` - writing ${o}`), m.writeFileSync(o, n.content);
|
|
740
781
|
}
|
|
741
782
|
}
|
|
742
783
|
if (e.software.length > 0) {
|
|
743
784
|
const r = Ne(t, ".");
|
|
744
|
-
|
|
785
|
+
m.mkdirSync(r, { recursive: !0 });
|
|
745
786
|
for (const n of e.software) {
|
|
746
|
-
const o = f.resolve(r, n.fullName.id +
|
|
747
|
-
s.info(` - writing ${o}`),
|
|
787
|
+
const o = f.resolve(r, n.fullName.id + z);
|
|
788
|
+
s.info(` - writing ${o}`), m.writeFileSync(o, n.src);
|
|
748
789
|
}
|
|
749
790
|
}
|
|
750
791
|
if (e.assets.length > 0) {
|
|
751
|
-
const r =
|
|
752
|
-
|
|
792
|
+
const r = ke(t, ".");
|
|
793
|
+
m.mkdirSync(r, { recursive: !0 });
|
|
753
794
|
for (const n of e.software) {
|
|
754
|
-
const o = f.resolve(r, n.fullName.id +
|
|
755
|
-
s.info(` - writing ${o}`),
|
|
795
|
+
const o = f.resolve(r, n.fullName.id + _);
|
|
796
|
+
s.info(` - writing ${o}`), m.writeFileSync(o, n.src);
|
|
756
797
|
}
|
|
757
798
|
}
|
|
758
799
|
}
|
|
759
|
-
const
|
|
800
|
+
const ie = {
|
|
760
801
|
"log-level": F.string({
|
|
761
802
|
description: "logging level",
|
|
762
803
|
default: "info",
|
|
@@ -778,9 +819,9 @@ const ne = {
|
|
|
778
819
|
multiple: !0,
|
|
779
820
|
delimiter: ","
|
|
780
821
|
})
|
|
781
|
-
}, A = class A extends
|
|
822
|
+
}, A = class A extends v {
|
|
782
823
|
async run() {
|
|
783
|
-
const { flags: e } = await this.parse(A), t =
|
|
824
|
+
const { flags: e } = await this.parse(A), t = E(e["log-level"]), r = S(process.cwd(), t), n = pt(t, "dist");
|
|
784
825
|
ut(t, n, "dist"), t.info("");
|
|
785
826
|
let o = `declare type TemplateFromFile = { readonly type: "from-file"; readonly path: string; };
|
|
786
827
|
`;
|
|
@@ -792,25 +833,25 @@ const ne = {
|
|
|
792
833
|
`, a = `import { resolve } from 'node:path';
|
|
793
834
|
export const Templates = {
|
|
794
835
|
`;
|
|
795
|
-
const
|
|
836
|
+
const l = n.templates.map(
|
|
796
837
|
(d) => ` '${d.fullName.id}': { type: 'from-file', path: require.resolve('./tengo/tpl/${d.fullName.id}.plj.gz') }`
|
|
797
838
|
).join(`,
|
|
798
|
-
`),
|
|
839
|
+
`), p = n.templates.map(
|
|
799
840
|
(d) => ` '${d.fullName.id}': { type: 'from-file', path: resolve(import.meta.dirname, './tengo/tpl/${d.fullName.id}.plj.gz') }`
|
|
800
841
|
).join(`,
|
|
801
842
|
`);
|
|
802
|
-
i +=
|
|
843
|
+
i += l, a += p, i += `
|
|
803
844
|
}};
|
|
804
845
|
`, a += `
|
|
805
846
|
};
|
|
806
847
|
`, await x.writeFile("dist/index.d.ts", o), r.type === "module" ? (await x.writeFile("dist/index.cjs", i), await x.writeFile("dist/index.js", a)) : (await x.writeFile("dist/index.js", i), await x.writeFile("dist/index.mjs", a)), gt(e), e["generate-tags"] && ht(t, e), t.info("Template Pack build done.");
|
|
807
848
|
}
|
|
808
849
|
};
|
|
809
|
-
|
|
810
|
-
...
|
|
850
|
+
c(A, "description", "build tengo sources into single distributable pack file"), c(A, "examples", ["<%= config.bin %> <%= command.id %>"]), c(A, "flags", {
|
|
851
|
+
...ie,
|
|
811
852
|
...mt
|
|
812
853
|
});
|
|
813
|
-
let
|
|
854
|
+
let X = A;
|
|
814
855
|
function gt(s) {
|
|
815
856
|
process.env.GENERATE_TAGS != null && (s["generate-tags"] = process.env.GENERATE_TAGS == "true"), process.env.TAGS_FILE != null && (s["tags-file"] = process.env.TAGS_FILE), process.env.TAGS_ADDITIONAL_ARGS != null && (s["tags-additional-args"] = process.env.TAGS_ADDITIONAL_ARGS.split(","));
|
|
816
857
|
}
|
|
@@ -821,7 +862,7 @@ function ht(s, e) {
|
|
|
821
862
|
`Generating tags for tengo autocompletion from "${r}" in "${t}", additional arguments: "${n.join('" "')}".
|
|
822
863
|
Found ${o.length} tengo files...`
|
|
823
864
|
);
|
|
824
|
-
const i =
|
|
865
|
+
const i = xe(
|
|
825
866
|
"ctags",
|
|
826
867
|
[
|
|
827
868
|
"-f",
|
|
@@ -856,7 +897,7 @@ https://marketplace.visualstudio.com/items?itemName=jaydenlin.ctags-support`);
|
|
|
856
897
|
yt(i, "failed to generate ctags"), s.info("Generation of tags is done.");
|
|
857
898
|
}
|
|
858
899
|
function wt(s) {
|
|
859
|
-
const e =
|
|
900
|
+
const e = m.readdirSync(s, { withFileTypes: !0, recursive: !0 }), t = [];
|
|
860
901
|
return e.forEach((r) => {
|
|
861
902
|
if (!r.isDirectory() && r.name.endsWith(".tengo")) {
|
|
862
903
|
const n = f.join(r.parentPath, r.name).replace(s, ".");
|
|
@@ -869,89 +910,89 @@ function yt(s, e) {
|
|
|
869
910
|
const t = e;
|
|
870
911
|
s.status !== 0 && console.log(`WARN: ${t} the build will continue as-is`);
|
|
871
912
|
}
|
|
872
|
-
function
|
|
873
|
-
const t =
|
|
913
|
+
function ae(s, e) {
|
|
914
|
+
const t = S(process.cwd(), s), r = M(s, t, "dist", "src", ""), n = ne(s, t, "dist");
|
|
874
915
|
for (const o of n.allLibs())
|
|
875
916
|
s.debug(
|
|
876
|
-
`Dumping to pl-tester: ${
|
|
917
|
+
`Dumping to pl-tester: ${h(o.fullName)}`
|
|
877
918
|
), e.write(JSON.stringify(o) + `
|
|
878
919
|
`);
|
|
879
920
|
for (const o of r)
|
|
880
921
|
o.fullName.type === "library" && (s.debug(
|
|
881
|
-
`Dumping to pl-tester: ${
|
|
922
|
+
`Dumping to pl-tester: ${h(o.fullName)}`
|
|
882
923
|
), e.write(JSON.stringify(o) + `
|
|
883
924
|
`));
|
|
884
925
|
for (const o of n.allTemplates())
|
|
885
926
|
s.debug(
|
|
886
|
-
`Dumping to pl-tester: ${
|
|
927
|
+
`Dumping to pl-tester: ${h(o.fullName)}`
|
|
887
928
|
), e.write(JSON.stringify(o) + `
|
|
888
929
|
`);
|
|
889
930
|
for (const o of r)
|
|
890
931
|
o.fullName.type === "template" && (s.debug(
|
|
891
|
-
`Dumping to pl-tester: ${
|
|
932
|
+
`Dumping to pl-tester: ${h(o.fullName)} ${o.srcName}`
|
|
892
933
|
), e.write(JSON.stringify(o) + `
|
|
893
934
|
`));
|
|
894
935
|
for (const o of n.allSoftware())
|
|
895
936
|
s.debug(
|
|
896
|
-
`Dumping to pl-tester: ${
|
|
937
|
+
`Dumping to pl-tester: ${h(o.fullName)}`
|
|
897
938
|
), e.write(JSON.stringify(o) + `
|
|
898
939
|
`);
|
|
899
940
|
for (const o of r)
|
|
900
941
|
o.fullName.type === "software" && (s.debug(
|
|
901
|
-
`Dumping to pl-tester: ${
|
|
942
|
+
`Dumping to pl-tester: ${h(o.fullName)}`
|
|
902
943
|
), e.write(JSON.stringify(o) + `
|
|
903
944
|
`));
|
|
904
945
|
for (const o of n.allAssets())
|
|
905
946
|
s.debug(
|
|
906
|
-
`Dumping to pl-tester: ${
|
|
947
|
+
`Dumping to pl-tester: ${h(o.fullName)}`
|
|
907
948
|
), e.write(JSON.stringify(o) + `
|
|
908
949
|
`);
|
|
909
950
|
for (const o of r)
|
|
910
951
|
o.fullName.type === "asset" && (s.debug(
|
|
911
|
-
`Dumping to pl-tester: ${
|
|
952
|
+
`Dumping to pl-tester: ${h(o.fullName)}`
|
|
912
953
|
), e.write(JSON.stringify(o) + `
|
|
913
954
|
`));
|
|
914
955
|
for (const o of r)
|
|
915
956
|
o.fullName.type === "test" && (s.debug(
|
|
916
|
-
`Dumping to pl-tester: ${
|
|
957
|
+
`Dumping to pl-tester: ${h(o.fullName)} ${o.srcName}`
|
|
917
958
|
), e.write(JSON.stringify(o) + `
|
|
918
959
|
`));
|
|
919
960
|
}
|
|
920
961
|
function bt(s, e, t) {
|
|
921
|
-
const r =
|
|
962
|
+
const r = S(process.cwd(), s), n = M(s, r, "dist", "src", "");
|
|
922
963
|
if (!e) {
|
|
923
964
|
for (const i of n)
|
|
924
965
|
i.fullName.type === "library" && t.write(JSON.stringify(i) + `
|
|
925
966
|
`);
|
|
926
967
|
return;
|
|
927
968
|
}
|
|
928
|
-
const o =
|
|
969
|
+
const o = ne(s, r, "dist");
|
|
929
970
|
for (const i of n)
|
|
930
971
|
i.fullName.type === "library" && o.addLib(i);
|
|
931
972
|
for (const i of o.allLibs())
|
|
932
973
|
t.write(JSON.stringify(i) + `
|
|
933
974
|
`);
|
|
934
975
|
}
|
|
935
|
-
function
|
|
936
|
-
const r =
|
|
976
|
+
function P(s, e, t) {
|
|
977
|
+
const r = S(process.cwd(), s), n = M(s, r, "dist", "src", "");
|
|
937
978
|
for (const o of n)
|
|
938
979
|
o.fullName.type === t && e.write(JSON.stringify(o) + `
|
|
939
980
|
`);
|
|
940
981
|
}
|
|
941
982
|
function vt(s, e) {
|
|
942
|
-
|
|
983
|
+
P(s, e, "template");
|
|
943
984
|
}
|
|
944
985
|
function Et(s, e) {
|
|
945
|
-
|
|
986
|
+
P(s, e, "software");
|
|
946
987
|
}
|
|
947
988
|
function $t(s, e) {
|
|
948
|
-
|
|
989
|
+
P(s, e, "asset");
|
|
949
990
|
}
|
|
950
991
|
function Nt(s, e) {
|
|
951
|
-
|
|
992
|
+
P(s, e, "test");
|
|
952
993
|
}
|
|
953
994
|
function Ae(s, ...e) {
|
|
954
|
-
const t =
|
|
995
|
+
const t = Fe(s, e, { stdio: ["pipe", "inherit", "inherit"] });
|
|
955
996
|
return t.stdin.on("error", (r) => {
|
|
956
997
|
r.code;
|
|
957
998
|
}), t;
|
|
@@ -965,10 +1006,10 @@ function Te(s) {
|
|
|
965
1006
|
});
|
|
966
1007
|
});
|
|
967
1008
|
}
|
|
968
|
-
const
|
|
1009
|
+
const $ = class $ extends v {
|
|
969
1010
|
async run() {
|
|
970
|
-
const { flags: e, argv: t } = await this.parse(
|
|
971
|
-
|
|
1011
|
+
const { flags: e, argv: t } = await this.parse($), r = E(e["log-level"]), n = t.length == 0 ? ["./src"] : t, o = Ae(
|
|
1012
|
+
he,
|
|
972
1013
|
"check",
|
|
973
1014
|
"--log-level",
|
|
974
1015
|
e["log-level"],
|
|
@@ -977,7 +1018,7 @@ const S = class S extends $ {
|
|
|
977
1018
|
...n
|
|
978
1019
|
);
|
|
979
1020
|
try {
|
|
980
|
-
|
|
1021
|
+
ae(r, o.stdin);
|
|
981
1022
|
} catch (i) {
|
|
982
1023
|
r.error(i);
|
|
983
1024
|
} finally {
|
|
@@ -987,15 +1028,15 @@ const S = class S extends $ {
|
|
|
987
1028
|
}
|
|
988
1029
|
}
|
|
989
1030
|
};
|
|
990
|
-
|
|
1031
|
+
c($, "description", "check tengo sources for language processor an"), // static override args = {
|
|
991
1032
|
// "log-level": Args.string({description: 'logging level'}),
|
|
992
1033
|
// }
|
|
993
|
-
|
|
994
|
-
let
|
|
995
|
-
const
|
|
1034
|
+
c($, "strict", !1), c($, "flags", { ...ie }), c($, "examples", ["<%= config.bin %> <%= command.id %>"]);
|
|
1035
|
+
let Z = $;
|
|
1036
|
+
const N = class N extends v {
|
|
996
1037
|
async run() {
|
|
997
|
-
const { flags: e } = await this.parse(
|
|
998
|
-
|
|
1038
|
+
const { flags: e } = await this.parse(N), t = E(e["log-level"]), r = this.argv.length == 0 ? ["./src"] : this.argv, n = Ae(
|
|
1039
|
+
he,
|
|
999
1040
|
"run",
|
|
1000
1041
|
"--log-level",
|
|
1001
1042
|
e["log-level"],
|
|
@@ -1004,7 +1045,7 @@ const k = class k extends $ {
|
|
|
1004
1045
|
...r
|
|
1005
1046
|
);
|
|
1006
1047
|
try {
|
|
1007
|
-
|
|
1048
|
+
ae(t, n.stdin);
|
|
1008
1049
|
} catch (o) {
|
|
1009
1050
|
t.error(o);
|
|
1010
1051
|
} finally {
|
|
@@ -1014,75 +1055,75 @@ const k = class k extends $ {
|
|
|
1014
1055
|
}
|
|
1015
1056
|
}
|
|
1016
1057
|
};
|
|
1017
|
-
|
|
1018
|
-
let
|
|
1019
|
-
class Y extends
|
|
1058
|
+
c(N, "description", "run tengo unit tests (.test.tengo)"), c(N, "strict", !1), c(N, "flags", { ...ie }), c(N, "examples", ["<%= config.bin %> <%= command.id %>"]);
|
|
1059
|
+
let H = N;
|
|
1060
|
+
class Y extends v {
|
|
1020
1061
|
async run() {
|
|
1021
|
-
const e =
|
|
1022
|
-
|
|
1062
|
+
const e = E();
|
|
1063
|
+
ae(e, D);
|
|
1023
1064
|
}
|
|
1024
1065
|
}
|
|
1025
|
-
|
|
1066
|
+
c(Y, "description", "parse sources in current package and dump all found artifacts to stdout"), c(Y, "examples", [
|
|
1026
1067
|
"<%= config.bin %> <%= command.id %>"
|
|
1027
1068
|
]);
|
|
1028
|
-
class
|
|
1069
|
+
class Q extends v {
|
|
1029
1070
|
async run() {
|
|
1030
|
-
const e =
|
|
1071
|
+
const e = E();
|
|
1031
1072
|
$t(e, D);
|
|
1032
1073
|
}
|
|
1033
1074
|
}
|
|
1034
|
-
|
|
1075
|
+
c(Q, "description", "parse sources in current package and dump all found assets to stdout"), c(Q, "examples", [
|
|
1035
1076
|
"<%= config.bin %> <%= command.id %>"
|
|
1036
1077
|
]);
|
|
1037
|
-
const T = class T extends
|
|
1078
|
+
const T = class T extends v {
|
|
1038
1079
|
async run() {
|
|
1039
|
-
const { flags: e } = await this.parse(T), t =
|
|
1080
|
+
const { flags: e } = await this.parse(T), t = E();
|
|
1040
1081
|
bt(t, e.deps, D);
|
|
1041
1082
|
}
|
|
1042
1083
|
};
|
|
1043
|
-
|
|
1084
|
+
c(T, "description", "parse sources in current package and dump all found libs to stdout"), c(T, "examples", [
|
|
1044
1085
|
"<%= config.bin %> <%= command.id %>"
|
|
1045
|
-
]),
|
|
1086
|
+
]), c(T, "flags", {
|
|
1046
1087
|
deps: F.boolean({ name: "deps", description: "add also all libraries found in node_modules" })
|
|
1047
1088
|
});
|
|
1048
|
-
let
|
|
1049
|
-
class
|
|
1089
|
+
let ee = T;
|
|
1090
|
+
class te extends v {
|
|
1050
1091
|
async run() {
|
|
1051
|
-
const e =
|
|
1092
|
+
const e = E();
|
|
1052
1093
|
Et(e, D);
|
|
1053
1094
|
}
|
|
1054
1095
|
}
|
|
1055
|
-
|
|
1096
|
+
c(te, "description", "parse sources in current package and dump all found software to stdout"), c(te, "examples", [
|
|
1056
1097
|
"<%= config.bin %> <%= command.id %>"
|
|
1057
1098
|
]);
|
|
1058
|
-
class
|
|
1099
|
+
class se extends v {
|
|
1059
1100
|
async run() {
|
|
1060
|
-
const e =
|
|
1101
|
+
const e = E();
|
|
1061
1102
|
vt(e, D);
|
|
1062
1103
|
}
|
|
1063
1104
|
}
|
|
1064
|
-
|
|
1105
|
+
c(se, "description", "parse sources in current package and dump all found templates to stdout"), c(se, "examples", [
|
|
1065
1106
|
"<%= config.bin %> <%= command.id %>"
|
|
1066
1107
|
]);
|
|
1067
|
-
class
|
|
1108
|
+
class oe extends v {
|
|
1068
1109
|
async run() {
|
|
1069
|
-
const e =
|
|
1110
|
+
const e = E();
|
|
1070
1111
|
Nt(e, D);
|
|
1071
1112
|
}
|
|
1072
1113
|
}
|
|
1073
|
-
|
|
1114
|
+
c(oe, "description", "parse sources in current package and dump all found tests to stdout"), c(oe, "examples", [
|
|
1074
1115
|
"<%= config.bin %> <%= command.id %>"
|
|
1075
1116
|
]);
|
|
1076
1117
|
const Rt = {
|
|
1077
|
-
build:
|
|
1078
|
-
check:
|
|
1079
|
-
test:
|
|
1118
|
+
build: X,
|
|
1119
|
+
check: Z,
|
|
1120
|
+
test: H,
|
|
1080
1121
|
"dump:all": Y,
|
|
1081
|
-
"dump:assets":
|
|
1082
|
-
"dump:libs":
|
|
1083
|
-
"dump:software":
|
|
1084
|
-
"dump:templates":
|
|
1085
|
-
"dump:tests":
|
|
1122
|
+
"dump:assets": Q,
|
|
1123
|
+
"dump:libs": ee,
|
|
1124
|
+
"dump:software": te,
|
|
1125
|
+
"dump:templates": se,
|
|
1126
|
+
"dump:tests": oe
|
|
1086
1127
|
};
|
|
1087
1128
|
export {
|
|
1088
1129
|
Rt as COMMANDS
|