@platforma-sdk/tengo-builder 2.4.13 → 2.4.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/bin/run.js +5 -5
- package/dist/commands/build.cjs +36 -36
- package/dist/commands/build.cjs.map +1 -1
- package/dist/commands/build.d.ts +5 -5
- package/dist/commands/build.js +36 -36
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/check.cjs +5 -5
- package/dist/commands/check.cjs.map +1 -1
- package/dist/commands/check.d.ts +2 -2
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +5 -5
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/dump/artifacts.cjs +4 -6
- package/dist/commands/dump/artifacts.cjs.map +1 -1
- package/dist/commands/dump/artifacts.d.ts +2 -2
- package/dist/commands/dump/artifacts.d.ts.map +1 -1
- package/dist/commands/dump/artifacts.js +4 -6
- package/dist/commands/dump/artifacts.js.map +1 -1
- package/dist/commands/dump/software.cjs +3 -5
- package/dist/commands/dump/software.cjs.map +1 -1
- package/dist/commands/dump/software.d.ts +2 -2
- package/dist/commands/dump/software.d.ts.map +1 -1
- package/dist/commands/dump/software.js +3 -5
- package/dist/commands/dump/software.js.map +1 -1
- package/dist/commands/test.cjs +5 -5
- package/dist/commands/test.cjs.map +1 -1
- package/dist/commands/test.d.ts +2 -2
- package/dist/commands/test.d.ts.map +1 -1
- package/dist/commands/test.js +5 -5
- package/dist/commands/test.js.map +1 -1
- package/dist/compiler/artifactset.cjs +2 -2
- package/dist/compiler/artifactset.cjs.map +1 -1
- package/dist/compiler/artifactset.d.ts +1 -1
- package/dist/compiler/artifactset.d.ts.map +1 -1
- package/dist/compiler/artifactset.js +2 -2
- package/dist/compiler/artifactset.js.map +1 -1
- package/dist/compiler/compiler.cjs +37 -34
- package/dist/compiler/compiler.cjs.map +1 -1
- package/dist/compiler/compiler.d.ts +3 -3
- package/dist/compiler/compiler.d.ts.map +1 -1
- package/dist/compiler/compiler.js +37 -34
- package/dist/compiler/compiler.js.map +1 -1
- package/dist/compiler/compileroptions.cjs +12 -12
- package/dist/compiler/compileroptions.cjs.map +1 -1
- package/dist/compiler/compileroptions.d.ts +2 -2
- package/dist/compiler/compileroptions.js +12 -12
- package/dist/compiler/compileroptions.js.map +1 -1
- package/dist/compiler/main.cjs +58 -58
- package/dist/compiler/main.cjs.map +1 -1
- package/dist/compiler/main.d.ts +6 -6
- package/dist/compiler/main.d.ts.map +1 -1
- package/dist/compiler/main.js +58 -58
- package/dist/compiler/main.js.map +1 -1
- package/dist/compiler/package.cjs +5 -2
- package/dist/compiler/package.cjs.map +1 -1
- package/dist/compiler/package.d.ts +6 -6
- package/dist/compiler/package.d.ts.map +1 -1
- package/dist/compiler/package.js +5 -2
- package/dist/compiler/package.js.map +1 -1
- package/dist/compiler/source.cjs +50 -52
- package/dist/compiler/source.cjs.map +1 -1
- package/dist/compiler/source.d.ts +2 -2
- package/dist/compiler/source.d.ts.map +1 -1
- package/dist/compiler/source.js +50 -52
- package/dist/compiler/source.js.map +1 -1
- package/dist/compiler/template.cjs +7 -7
- package/dist/compiler/template.cjs.map +1 -1
- package/dist/compiler/template.d.ts +2 -2
- package/dist/compiler/template.d.ts.map +1 -1
- package/dist/compiler/template.js +7 -7
- package/dist/compiler/template.js.map +1 -1
- package/dist/compiler/test.artifacts.d.ts +1 -1
- package/dist/compiler/test.artifacts.d.ts.map +1 -1
- package/dist/compiler/util.cjs +12 -12
- package/dist/compiler/util.cjs.map +1 -1
- package/dist/compiler/util.d.ts +2 -2
- package/dist/compiler/util.js +12 -12
- package/dist/compiler/util.js.map +1 -1
- package/dist/index.cjs +5 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/shared/basecmd.cjs +15 -15
- package/dist/shared/basecmd.cjs.map +1 -1
- package/dist/shared/basecmd.d.ts +4 -4
- package/dist/shared/basecmd.js +15 -15
- package/dist/shared/basecmd.js.map +1 -1
- package/dist/shared/dump.cjs +28 -28
- package/dist/shared/dump.cjs.map +1 -1
- package/dist/shared/dump.d.ts +2 -2
- package/dist/shared/dump.d.ts.map +1 -1
- package/dist/shared/dump.js +28 -28
- package/dist/shared/dump.js.map +1 -1
- package/dist/shared/proc.cjs +5 -5
- package/dist/shared/proc.cjs.map +1 -1
- package/dist/shared/proc.d.ts +2 -2
- package/dist/shared/proc.js +5 -5
- package/dist/shared/proc.js.map +1 -1
- package/package.json +21 -19
- package/src/commands/build.ts +57 -55
- package/src/commands/check.ts +15 -12
- package/src/commands/dump/artifacts.ts +11 -15
- package/src/commands/dump/software.ts +9 -10
- package/src/commands/test.ts +15 -12
- package/src/compiler/artifactset.ts +7 -9
- package/src/compiler/compiler.test.ts +134 -137
- package/src/compiler/compiler.ts +62 -62
- package/src/compiler/compileroptions.ts +15 -15
- package/src/compiler/main.test.ts +23 -23
- package/src/compiler/main.ts +83 -100
- package/src/compiler/package.ts +14 -12
- package/src/compiler/source.test.ts +191 -183
- package/src/compiler/source.ts +106 -79
- package/src/compiler/template.test.ts +50 -49
- package/src/compiler/template.ts +11 -21
- package/src/compiler/test.artifacts.ts +47 -47
- package/src/compiler/util.ts +17 -17
- package/src/index.ts +10 -10
- package/src/shared/basecmd.ts +16 -16
- package/src/shared/dump.ts +49 -70
- package/src/shared/proc.ts +8 -8
package/src/compiler/main.ts
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import * as path from
|
|
4
|
-
import * as fs from
|
|
5
|
-
import { pathType } from
|
|
6
|
-
import type { TemplatesAndLibs } from
|
|
7
|
-
import { TengoTemplateCompiler } from
|
|
8
|
-
import { getSha256 } from
|
|
9
|
-
import type {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} from
|
|
16
|
-
import { ArtifactSource, parseSourceFile } from './source';
|
|
17
|
-
import { newTemplateFromContent, templateToSource } from './template';
|
|
18
|
-
import type winston from 'winston';
|
|
19
|
-
import { tryResolve, tryResolveOrError } from '@milaboratories/resolve-helper';
|
|
20
|
-
import { serializeTemplate } from '@milaboratories/pl-model-backend';
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import * as fs from "node:fs";
|
|
5
|
+
import { pathType } from "./util";
|
|
6
|
+
import type { TemplatesAndLibs } from "./compiler";
|
|
7
|
+
import { TengoTemplateCompiler } from "./compiler";
|
|
8
|
+
import { getSha256 } from "./source";
|
|
9
|
+
import type { CompileMode, FullArtifactName } from "./package";
|
|
10
|
+
import { fullNameToString, typedArtifactNameToString } from "./package";
|
|
11
|
+
import { ArtifactSource, parseSourceFile } from "./source";
|
|
12
|
+
import { newTemplateFromContent, templateToSource } from "./template";
|
|
13
|
+
import type winston from "winston";
|
|
14
|
+
import { tryResolve, tryResolveOrError } from "@milaboratories/resolve-helper";
|
|
15
|
+
import { serializeTemplate } from "@milaboratories/pl-model-backend";
|
|
21
16
|
|
|
22
17
|
interface PackageId {
|
|
23
18
|
/** Package name from package.json */
|
|
@@ -45,20 +40,20 @@ interface PackageJson {
|
|
|
45
40
|
devDependencies: Record<string, string>;
|
|
46
41
|
}
|
|
47
42
|
|
|
48
|
-
const compiledTplSuffix =
|
|
49
|
-
const compiledLibSuffix =
|
|
50
|
-
const compiledSoftwareSuffix =
|
|
51
|
-
const compiledAssetSuffix =
|
|
43
|
+
const compiledTplSuffix = ".plj.gz";
|
|
44
|
+
const compiledLibSuffix = ".lib.tengo";
|
|
45
|
+
const compiledSoftwareSuffix = ".sw.json";
|
|
46
|
+
const compiledAssetSuffix = ".as.json";
|
|
52
47
|
|
|
53
48
|
// We need to keep track of dependencies for correct tgo-test CLI utility configuraiton.
|
|
54
49
|
// It is much simpler to do this here, than duplicate all tle logic regarding dependencies
|
|
55
50
|
// in go code.
|
|
56
|
-
const srcTestSuffix =
|
|
51
|
+
const srcTestSuffix = ".test.tengo";
|
|
57
52
|
|
|
58
|
-
const srcTplSuffix =
|
|
59
|
-
const srcLibSuffix =
|
|
60
|
-
const srcSoftwareSuffix =
|
|
61
|
-
const srcAssetSuffix =
|
|
53
|
+
const srcTplSuffix = ".tpl.tengo";
|
|
54
|
+
const srcLibSuffix = ".lib.tengo";
|
|
55
|
+
const srcSoftwareSuffix = ".sw.json";
|
|
56
|
+
const srcAssetSuffix = ".as.json";
|
|
62
57
|
const compilableSuffixes = [srcLibSuffix, srcTplSuffix, srcSoftwareSuffix, srcAssetSuffix];
|
|
63
58
|
|
|
64
59
|
/**
|
|
@@ -75,21 +70,22 @@ function resolvePackageJsonPackage(root: string, depPackageName: string): string
|
|
|
75
70
|
if (resolved) {
|
|
76
71
|
let depth = 0;
|
|
77
72
|
do {
|
|
78
|
-
const p = path.join(resolved,
|
|
79
|
-
if (pathType(p) ===
|
|
80
|
-
return p;
|
|
73
|
+
const p = path.join(resolved, "package.json");
|
|
74
|
+
if (pathType(p) === "file") return p;
|
|
81
75
|
depth++;
|
|
82
76
|
resolved = path.dirname(resolved);
|
|
83
|
-
} while (depth < 7 && path.basename(resolved) !==
|
|
77
|
+
} while (depth < 7 && path.basename(resolved) !== "node_modules");
|
|
84
78
|
}
|
|
85
79
|
|
|
86
80
|
// Second approach: trying to find package.json in the package dir.
|
|
87
81
|
const resolved2 = tryResolveOrError(root, `${depPackageName}/package.json`);
|
|
88
82
|
if (resolved2.result === undefined) {
|
|
89
|
-
if (resolved2.err ===
|
|
83
|
+
if (resolved2.err === "ERR_PACKAGE_PATH_NOT_EXPORTED")
|
|
90
84
|
// tolerating not-exported package.json for dev dependencies
|
|
91
85
|
return undefined;
|
|
92
|
-
throw new Error(
|
|
86
|
+
throw new Error(
|
|
87
|
+
`Can't resolve package.json for package ${depPackageName ?? "."} relative to ${root}`,
|
|
88
|
+
);
|
|
93
89
|
}
|
|
94
90
|
return resolved2.result;
|
|
95
91
|
}
|
|
@@ -99,13 +95,12 @@ export function resolvePackageJsonRoot(root: string): string {
|
|
|
99
95
|
throw new Error(`Root path must be absolute: ${root}`);
|
|
100
96
|
}
|
|
101
97
|
|
|
102
|
-
const p = path.join(root,
|
|
103
|
-
if (pathType(p) ===
|
|
104
|
-
return p;
|
|
98
|
+
const p = path.join(root, "package.json");
|
|
99
|
+
if (pathType(p) === "file") return p;
|
|
105
100
|
throw new Error(`Can't resolve package.json in ${root}`);
|
|
106
101
|
}
|
|
107
102
|
|
|
108
|
-
type PackageInfoContext =
|
|
103
|
+
type PackageInfoContext = "root" | "dependency" | "devDependency";
|
|
109
104
|
|
|
110
105
|
/**
|
|
111
106
|
* Get package info from package.json and all dependencies.
|
|
@@ -113,7 +108,7 @@ type PackageInfoContext = 'root' | 'dependency' | 'devDependency';
|
|
|
113
108
|
export function getPackageInfo(
|
|
114
109
|
root: string,
|
|
115
110
|
logger: winston.Logger,
|
|
116
|
-
context: PackageInfoContext =
|
|
111
|
+
context: PackageInfoContext = "root",
|
|
117
112
|
): PackageInfo {
|
|
118
113
|
const packageJsonPath = resolvePackageJsonRoot(root);
|
|
119
114
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString()) as PackageJson;
|
|
@@ -121,17 +116,17 @@ export function getPackageInfo(
|
|
|
121
116
|
// resolving dependencies
|
|
122
117
|
const depInfos: PackageInfo[] = [];
|
|
123
118
|
|
|
124
|
-
if (packageJson.dependencies && context !==
|
|
119
|
+
if (packageJson.dependencies && context !== "devDependency") {
|
|
125
120
|
for (const dep of Object.keys(packageJson.dependencies)) {
|
|
126
121
|
const depPackageJson = resolvePackageJsonPackage(root, dep);
|
|
127
122
|
if (depPackageJson === undefined)
|
|
128
123
|
throw new Error(`Can't resolve package.json for dependency ${dep} of ${root}`);
|
|
129
124
|
const depRoot = path.dirname(depPackageJson);
|
|
130
|
-
depInfos.push(getPackageInfo(depRoot, logger,
|
|
125
|
+
depInfos.push(getPackageInfo(depRoot, logger, "dependency"));
|
|
131
126
|
}
|
|
132
127
|
}
|
|
133
128
|
|
|
134
|
-
if (packageJson.devDependencies && context ===
|
|
129
|
+
if (packageJson.devDependencies && context === "root") {
|
|
135
130
|
for (const dep of Object.keys(packageJson.devDependencies)) {
|
|
136
131
|
const depPackageJson = resolvePackageJsonPackage(root, dep);
|
|
137
132
|
if (depPackageJson === undefined) {
|
|
@@ -140,7 +135,7 @@ export function getPackageInfo(
|
|
|
140
135
|
continue;
|
|
141
136
|
}
|
|
142
137
|
const depRoot = path.dirname(depPackageJson);
|
|
143
|
-
depInfos.push(getPackageInfo(depRoot, logger,
|
|
138
|
+
depInfos.push(getPackageInfo(depRoot, logger, "devDependency"));
|
|
144
139
|
}
|
|
145
140
|
}
|
|
146
141
|
|
|
@@ -155,19 +150,19 @@ export function getPackageInfo(
|
|
|
155
150
|
}
|
|
156
151
|
|
|
157
152
|
function resolveLibsDst(mode: CompileMode, root: string) {
|
|
158
|
-
return path.resolve(root, mode,
|
|
153
|
+
return path.resolve(root, mode, "tengo", "lib");
|
|
159
154
|
}
|
|
160
155
|
|
|
161
156
|
function resolveTemplatesDst(mode: CompileMode, root: string) {
|
|
162
|
-
return path.resolve(root, mode,
|
|
157
|
+
return path.resolve(root, mode, "tengo", "tpl");
|
|
163
158
|
}
|
|
164
159
|
|
|
165
160
|
function resolveSoftwareDst(mode: CompileMode, root: string) {
|
|
166
|
-
return path.resolve(root, mode,
|
|
161
|
+
return path.resolve(root, mode, "tengo", "software");
|
|
167
162
|
}
|
|
168
163
|
|
|
169
164
|
function resolveAssetsDst(mode: CompileMode, root: string) {
|
|
170
|
-
return path.resolve(root, mode,
|
|
165
|
+
return path.resolve(root, mode, "tengo", "asset");
|
|
171
166
|
}
|
|
172
167
|
|
|
173
168
|
function loadDependencies(
|
|
@@ -175,23 +170,22 @@ function loadDependencies(
|
|
|
175
170
|
compiler: TengoTemplateCompiler,
|
|
176
171
|
packageInfo: PackageInfo,
|
|
177
172
|
): void {
|
|
178
|
-
for (const dep of packageInfo.dependencies)
|
|
179
|
-
loadDependencies(logger, compiler, dep);
|
|
173
|
+
for (const dep of packageInfo.dependencies) loadDependencies(logger, compiler, dep);
|
|
180
174
|
|
|
181
|
-
if (packageInfo.context ===
|
|
175
|
+
if (packageInfo.context === "root")
|
|
182
176
|
// we are not reading compiled files for root package
|
|
183
177
|
return;
|
|
184
178
|
|
|
185
179
|
// we are in package folder
|
|
186
|
-
const libDistFolder = resolveLibsDst(
|
|
187
|
-
const tplDistFolder = resolveTemplatesDst(
|
|
188
|
-
const softwareDistFolder = resolveSoftwareDst(
|
|
189
|
-
const assetDistFolder = resolveAssetsDst(
|
|
180
|
+
const libDistFolder = resolveLibsDst("dist", packageInfo.root);
|
|
181
|
+
const tplDistFolder = resolveTemplatesDst("dist", packageInfo.root);
|
|
182
|
+
const softwareDistFolder = resolveSoftwareDst("dist", packageInfo.root);
|
|
183
|
+
const assetDistFolder = resolveAssetsDst("dist", packageInfo.root);
|
|
190
184
|
|
|
191
|
-
const libDistExists = pathType(libDistFolder) ===
|
|
192
|
-
const tplDistExists = pathType(tplDistFolder) ===
|
|
193
|
-
const softwareDistExists = pathType(softwareDistFolder) ===
|
|
194
|
-
const assetDistExists = pathType(assetDistFolder) ===
|
|
185
|
+
const libDistExists = pathType(libDistFolder) === "dir";
|
|
186
|
+
const tplDistExists = pathType(tplDistFolder) === "dir";
|
|
187
|
+
const softwareDistExists = pathType(softwareDistFolder) === "dir";
|
|
188
|
+
const assetDistExists = pathType(assetDistFolder) === "dir";
|
|
195
189
|
|
|
196
190
|
if (!libDistExists && !tplDistExists && !softwareDistExists && !assetDistExists)
|
|
197
191
|
// if neither of tengo-specific folders detected, skipping package
|
|
@@ -200,19 +194,19 @@ function loadDependencies(
|
|
|
200
194
|
const packageId = { name: packageInfo.name, version: packageInfo.version };
|
|
201
195
|
|
|
202
196
|
if (libDistExists) {
|
|
203
|
-
loadLibsFromDir(logger, packageId,
|
|
197
|
+
loadLibsFromDir(logger, packageId, "dist", libDistFolder, compiler);
|
|
204
198
|
}
|
|
205
199
|
|
|
206
200
|
if (tplDistExists) {
|
|
207
|
-
loadTemplatesFromDir(logger, packageId,
|
|
201
|
+
loadTemplatesFromDir(logger, packageId, "dist", tplDistFolder, compiler);
|
|
208
202
|
}
|
|
209
203
|
|
|
210
204
|
if (softwareDistExists) {
|
|
211
|
-
loadSoftwareFromDir(logger, packageId,
|
|
205
|
+
loadSoftwareFromDir(logger, packageId, "dist", softwareDistFolder, compiler);
|
|
212
206
|
}
|
|
213
207
|
|
|
214
208
|
if (assetDistExists) {
|
|
215
|
-
loadAssetsFromDir(logger, packageId,
|
|
209
|
+
loadAssetsFromDir(logger, packageId, "dist", assetDistFolder, compiler);
|
|
216
210
|
}
|
|
217
211
|
}
|
|
218
212
|
|
|
@@ -227,7 +221,7 @@ function loadLibsFromDir(
|
|
|
227
221
|
const file = path.resolve(folder, f);
|
|
228
222
|
if (!f.endsWith(compiledLibSuffix)) throw new Error(`unexpected file in 'lib' folder: ${file}`);
|
|
229
223
|
const fullName: FullArtifactName = {
|
|
230
|
-
type:
|
|
224
|
+
type: "library",
|
|
231
225
|
pkg: packageId.name,
|
|
232
226
|
id: f.slice(0, f.length - compiledLibSuffix.length),
|
|
233
227
|
version: packageId.version,
|
|
@@ -236,7 +230,7 @@ function loadLibsFromDir(
|
|
|
236
230
|
compiler.addLib(src);
|
|
237
231
|
logger.debug(`Adding dependency ${fullNameToString(fullName)} from ${file}`);
|
|
238
232
|
if (src.dependencies.length > 0) {
|
|
239
|
-
logger.debug(
|
|
233
|
+
logger.debug("Dependencies:");
|
|
240
234
|
for (const dep of src.dependencies) logger.debug(` - ${typedArtifactNameToString(dep)}`);
|
|
241
235
|
}
|
|
242
236
|
}
|
|
@@ -254,7 +248,7 @@ function loadTemplatesFromDir(
|
|
|
254
248
|
const file = path.resolve(folder, f);
|
|
255
249
|
if (!f.endsWith(compiledTplSuffix)) throw new Error(`unexpected file in 'tpl' folder: ${file}`);
|
|
256
250
|
const fullName: FullArtifactName = {
|
|
257
|
-
type:
|
|
251
|
+
type: "template",
|
|
258
252
|
pkg: packageId.name,
|
|
259
253
|
id: f.slice(0, f.length - compiledTplSuffix.length),
|
|
260
254
|
version: packageId.version,
|
|
@@ -277,7 +271,7 @@ function loadSoftwareFromDir(
|
|
|
277
271
|
if (!f.endsWith(compiledSoftwareSuffix))
|
|
278
272
|
throw new Error(`unexpected file in 'software' folder: ${file}`);
|
|
279
273
|
const fullName: FullArtifactName = {
|
|
280
|
-
type:
|
|
274
|
+
type: "software",
|
|
281
275
|
pkg: packageId.name,
|
|
282
276
|
id: f.slice(0, f.length - compiledSoftwareSuffix.length),
|
|
283
277
|
version: packageId.version,
|
|
@@ -285,15 +279,7 @@ function loadSoftwareFromDir(
|
|
|
285
279
|
|
|
286
280
|
const source = fs.readFileSync(file).toString();
|
|
287
281
|
|
|
288
|
-
const software = new ArtifactSource(
|
|
289
|
-
mode,
|
|
290
|
-
fullName,
|
|
291
|
-
getSha256(source),
|
|
292
|
-
source,
|
|
293
|
-
file,
|
|
294
|
-
[],
|
|
295
|
-
[],
|
|
296
|
-
);
|
|
282
|
+
const software = new ArtifactSource(mode, fullName, getSha256(source), source, file, [], []);
|
|
297
283
|
|
|
298
284
|
logger.debug(`Adding dependency ${fullNameToString(fullName)} from ${file}`);
|
|
299
285
|
compiler.addSoftware(software);
|
|
@@ -312,7 +298,7 @@ function loadAssetsFromDir(
|
|
|
312
298
|
if (!f.endsWith(compiledAssetSuffix))
|
|
313
299
|
throw new Error(`unexpected file in 'asset' folder: ${file}`);
|
|
314
300
|
const fullName: FullArtifactName = {
|
|
315
|
-
type:
|
|
301
|
+
type: "asset",
|
|
316
302
|
pkg: packageId.name,
|
|
317
303
|
id: f.slice(0, f.length - compiledAssetSuffix.length),
|
|
318
304
|
version: packageId.version,
|
|
@@ -320,15 +306,7 @@ function loadAssetsFromDir(
|
|
|
320
306
|
|
|
321
307
|
const source = fs.readFileSync(file).toString();
|
|
322
308
|
|
|
323
|
-
const asset = new ArtifactSource(
|
|
324
|
-
mode,
|
|
325
|
-
fullName,
|
|
326
|
-
getSha256(source),
|
|
327
|
-
source,
|
|
328
|
-
file,
|
|
329
|
-
[],
|
|
330
|
-
[],
|
|
331
|
-
);
|
|
309
|
+
const asset = new ArtifactSource(mode, fullName, getSha256(source), source, file, [], []);
|
|
332
310
|
|
|
333
311
|
logger.debug(`Adding dependency ${fullNameToString(fullName)} from ${file}`);
|
|
334
312
|
compiler.addAsset(asset);
|
|
@@ -348,16 +326,17 @@ export function parseSources(
|
|
|
348
326
|
const inRootPath = path.join(subdir, f); // path to item inside given <root>
|
|
349
327
|
const fullPath = path.join(root, inRootPath); // full path to item from CWD (or abs path, if <root> is abs path)
|
|
350
328
|
|
|
351
|
-
if (pathType(fullPath) ===
|
|
329
|
+
if (pathType(fullPath) === "dir") {
|
|
352
330
|
const nested = parseSources(logger, packageId, mode, root, inRootPath);
|
|
353
331
|
sources.push(...nested);
|
|
354
332
|
continue;
|
|
355
333
|
}
|
|
356
334
|
|
|
357
335
|
// Handling index.lib.tengo files: rename them to <package-name>.lib.tengo
|
|
358
|
-
const artifactName =
|
|
336
|
+
const artifactName =
|
|
337
|
+
f === "index.lib.tengo" ? `${path.dirname(inRootPath)}.lib.tengo` : inRootPath;
|
|
359
338
|
|
|
360
|
-
const fullName = fullNameFromFileName(packageId, artifactName.replaceAll(path.sep,
|
|
339
|
+
const fullName = fullNameFromFileName(packageId, artifactName.replaceAll(path.sep, "."));
|
|
361
340
|
if (!fullName) {
|
|
362
341
|
logger.info(`Skipping unknown file type: ${artifactName}`);
|
|
363
342
|
continue; // skip unknown file types
|
|
@@ -373,7 +352,7 @@ export function parseSources(
|
|
|
373
352
|
logger.debug(`Parsing ${fullNameToString(fullName)} from ${file}`);
|
|
374
353
|
const newSrc = parseSourceFile(logger, mode, file, fullName, true);
|
|
375
354
|
if (newSrc.dependencies.length > 0) {
|
|
376
|
-
logger.debug(
|
|
355
|
+
logger.debug("Detected dependencies:");
|
|
377
356
|
for (const dep of newSrc.dependencies) logger.debug(` - ${typedArtifactNameToString(dep)}`);
|
|
378
357
|
}
|
|
379
358
|
|
|
@@ -405,7 +384,7 @@ export function fullNameFromFileName(
|
|
|
405
384
|
return {
|
|
406
385
|
...pkgAndVersion,
|
|
407
386
|
id: artifactName.substring(0, artifactName.length - srcLibSuffix.length),
|
|
408
|
-
type:
|
|
387
|
+
type: "library",
|
|
409
388
|
};
|
|
410
389
|
}
|
|
411
390
|
|
|
@@ -413,7 +392,7 @@ export function fullNameFromFileName(
|
|
|
413
392
|
return {
|
|
414
393
|
...pkgAndVersion,
|
|
415
394
|
id: artifactName.substring(0, artifactName.length - srcTplSuffix.length),
|
|
416
|
-
type:
|
|
395
|
+
type: "template",
|
|
417
396
|
};
|
|
418
397
|
}
|
|
419
398
|
|
|
@@ -421,7 +400,7 @@ export function fullNameFromFileName(
|
|
|
421
400
|
return {
|
|
422
401
|
...pkgAndVersion,
|
|
423
402
|
id: artifactName.substring(0, artifactName.length - srcSoftwareSuffix.length),
|
|
424
|
-
type:
|
|
403
|
+
type: "software",
|
|
425
404
|
};
|
|
426
405
|
}
|
|
427
406
|
|
|
@@ -429,7 +408,7 @@ export function fullNameFromFileName(
|
|
|
429
408
|
return {
|
|
430
409
|
...pkgAndVersion,
|
|
431
410
|
id: artifactName.substring(0, artifactName.length - srcAssetSuffix.length),
|
|
432
|
-
type:
|
|
411
|
+
type: "asset",
|
|
433
412
|
};
|
|
434
413
|
}
|
|
435
414
|
|
|
@@ -437,16 +416,20 @@ export function fullNameFromFileName(
|
|
|
437
416
|
return {
|
|
438
417
|
...pkgAndVersion,
|
|
439
418
|
id: artifactName.substring(0, artifactName.length - srcTestSuffix.length),
|
|
440
|
-
type:
|
|
419
|
+
type: "test",
|
|
441
420
|
};
|
|
442
421
|
}
|
|
443
422
|
|
|
444
423
|
return null;
|
|
445
424
|
}
|
|
446
425
|
|
|
447
|
-
export function compile(
|
|
426
|
+
export function compile(
|
|
427
|
+
logger: winston.Logger,
|
|
428
|
+
packageInfo: PackageInfo,
|
|
429
|
+
mode: CompileMode,
|
|
430
|
+
): TemplatesAndLibs {
|
|
448
431
|
const compiler = newCompiler(logger, packageInfo, mode);
|
|
449
|
-
const sources = parseSources(logger, packageInfo, mode,
|
|
432
|
+
const sources = parseSources(logger, packageInfo, mode, "src", "");
|
|
450
433
|
|
|
451
434
|
// checking that we have something to do
|
|
452
435
|
if (sources.length === 0) {
|
|
@@ -455,7 +438,7 @@ export function compile(logger: winston.Logger, packageInfo: PackageInfo, mode:
|
|
|
455
438
|
lookFor.push(`*${suffix}`);
|
|
456
439
|
}
|
|
457
440
|
|
|
458
|
-
logger.error(`Nothing to compile. Looked for ${lookFor.join(
|
|
441
|
+
logger.error(`Nothing to compile. Looked for ${lookFor.join(", ")}`);
|
|
459
442
|
process.exit(1);
|
|
460
443
|
}
|
|
461
444
|
|
|
@@ -470,7 +453,7 @@ export function compile(logger: winston.Logger, packageInfo: PackageInfo, mode:
|
|
|
470
453
|
export function savePacks(logger: winston.Logger, compiled: TemplatesAndLibs, mode: CompileMode) {
|
|
471
454
|
// writing libs
|
|
472
455
|
if (compiled.libs.length > 0) {
|
|
473
|
-
const libOutput = resolveLibsDst(mode,
|
|
456
|
+
const libOutput = resolveLibsDst(mode, ".");
|
|
474
457
|
fs.mkdirSync(libOutput, { recursive: true });
|
|
475
458
|
for (const lib of compiled.libs) {
|
|
476
459
|
const file = path.resolve(libOutput, lib.fullName.id + compiledLibSuffix);
|
|
@@ -481,7 +464,7 @@ export function savePacks(logger: winston.Logger, compiled: TemplatesAndLibs, mo
|
|
|
481
464
|
|
|
482
465
|
// writing templates
|
|
483
466
|
if (compiled.templates.length > 0) {
|
|
484
|
-
const tplOutput = resolveTemplatesDst(mode,
|
|
467
|
+
const tplOutput = resolveTemplatesDst(mode, ".");
|
|
485
468
|
fs.mkdirSync(tplOutput, { recursive: true });
|
|
486
469
|
for (const tpl of compiled.templates) {
|
|
487
470
|
const file = path.resolve(tplOutput, tpl.fullName.id + compiledTplSuffix);
|
|
@@ -492,7 +475,7 @@ export function savePacks(logger: winston.Logger, compiled: TemplatesAndLibs, mo
|
|
|
492
475
|
|
|
493
476
|
// writing software
|
|
494
477
|
if (compiled.software.length > 0) {
|
|
495
|
-
const swOutput = resolveSoftwareDst(mode,
|
|
478
|
+
const swOutput = resolveSoftwareDst(mode, ".");
|
|
496
479
|
fs.mkdirSync(swOutput, { recursive: true });
|
|
497
480
|
for (const sw of compiled.software) {
|
|
498
481
|
const file = path.resolve(swOutput, sw.fullName.id + compiledSoftwareSuffix);
|
|
@@ -503,7 +486,7 @@ export function savePacks(logger: winston.Logger, compiled: TemplatesAndLibs, mo
|
|
|
503
486
|
|
|
504
487
|
// writing assets
|
|
505
488
|
if (compiled.assets.length > 0) {
|
|
506
|
-
const swOutput = resolveAssetsDst(mode,
|
|
489
|
+
const swOutput = resolveAssetsDst(mode, ".");
|
|
507
490
|
fs.mkdirSync(swOutput, { recursive: true });
|
|
508
491
|
for (const sw of compiled.software) {
|
|
509
492
|
const file = path.resolve(swOutput, sw.fullName.id + compiledAssetSuffix);
|
package/src/compiler/package.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
export type CompileMode =
|
|
20
|
+
export type CompileMode = "dist";
|
|
21
21
|
|
|
22
22
|
export type CompilerOption = {
|
|
23
23
|
/** Option name, like 'hash_override' */
|
|
@@ -27,7 +27,7 @@ export type CompilerOption = {
|
|
|
27
27
|
args: string[];
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
export type ArtifactType =
|
|
30
|
+
export type ArtifactType = "library" | "template" | "test" | "software" | "asset";
|
|
31
31
|
|
|
32
32
|
/** Artifact Name including package version */
|
|
33
33
|
export interface FullArtifactName {
|
|
@@ -44,13 +44,13 @@ export interface FullArtifactName {
|
|
|
44
44
|
version: string;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
export type FullArtifactNameWithoutType = Omit<FullArtifactName,
|
|
47
|
+
export type FullArtifactNameWithoutType = Omit<FullArtifactName, "type">;
|
|
48
48
|
|
|
49
|
-
export type TypedArtifactName = Pick<FullArtifactName,
|
|
49
|
+
export type TypedArtifactName = Pick<FullArtifactName, "type" | "pkg" | "id">;
|
|
50
50
|
|
|
51
|
-
export type PackageName = Pick<FullArtifactName,
|
|
51
|
+
export type PackageName = Pick<FullArtifactName, "pkg" | "version">;
|
|
52
52
|
|
|
53
|
-
export type ArtifactName = Pick<FullArtifactName,
|
|
53
|
+
export type ArtifactName = Pick<FullArtifactName, "pkg" | "id">;
|
|
54
54
|
|
|
55
55
|
export function artifactKey(name: TypedArtifactName): string {
|
|
56
56
|
return `${name.type}||${name.pkg}||${name.id}`;
|
|
@@ -72,11 +72,13 @@ export function typedArtifactNamesEquals(
|
|
|
72
72
|
return name1.type == name2.type && name1.pkg == name2.pkg && name1.id == name2.id;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
export function fullNameEquals(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
export function fullNameEquals(name1: FullArtifactName, name2: FullArtifactName): boolean {
|
|
76
|
+
return (
|
|
77
|
+
name1.type == name2.type &&
|
|
78
|
+
name1.pkg == name2.pkg &&
|
|
79
|
+
name1.id == name2.id &&
|
|
80
|
+
name1.version == name2.version
|
|
81
|
+
);
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
/** used to format artefact name while generating output files */
|
|
@@ -99,7 +101,7 @@ export function parseArtefactNameAndVersion(nameAndVersion: {
|
|
|
99
101
|
}): FullArtifactNameWithoutType {
|
|
100
102
|
const match = nameAndVersion.name.match(/^(?<pkg>[^:]*):(?<id>[^:]*)$/);
|
|
101
103
|
if (!match) throw new Error(`malformed artifact name: ${nameAndVersion.name}`);
|
|
102
|
-
return { pkg: match.groups![
|
|
104
|
+
return { pkg: match.groups!["pkg"], id: match.groups!["id"], version: nameAndVersion.version };
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
export function fullNameWithoutTypeToString(name: FullArtifactNameWithoutType): string {
|