@platforma-sdk/tengo-builder 2.0.3 → 2.1.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/build.d.ts.map +1 -1
- package/dist/compiler/artifactset.d.ts +4 -0
- package/dist/compiler/artifactset.d.ts.map +1 -1
- package/dist/compiler/compiler.d.ts +11 -9
- package/dist/compiler/compiler.d.ts.map +1 -1
- package/dist/compiler/compileroptions.d.ts +3 -3
- package/dist/compiler/compileroptions.d.ts.map +1 -1
- package/dist/compiler/main.d.ts +4 -5
- package/dist/compiler/main.d.ts.map +1 -1
- package/dist/compiler/source.d.ts +24 -4
- package/dist/compiler/source.d.ts.map +1 -1
- package/dist/compiler/template.d.ts +17 -13
- package/dist/compiler/template.d.ts.map +1 -1
- package/dist/compiler/test.artifacts.d.ts +2 -0
- package/dist/compiler/test.artifacts.d.ts.map +1 -1
- package/dist/index.js +29 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +473 -410
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -8
- package/src/commands/build.ts +31 -27
- package/src/compiler/artifactset.ts +4 -0
- package/src/compiler/compiler.test.ts +276 -17
- package/src/compiler/compiler.ts +87 -60
- package/src/compiler/compileroptions.ts +3 -3
- package/src/compiler/main.test.ts +45 -0
- package/src/compiler/main.ts +76 -36
- package/src/compiler/source.test.ts +324 -1
- package/src/compiler/source.ts +47 -42
- package/src/compiler/template.test.ts +22 -14
- package/src/compiler/template.ts +85 -38
- package/src/compiler/test.artifacts.ts +10 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAUtC,MAAM,CAAC,OAAO,OAAO,KAAM,SAAQ,OAAO;IACxC,OAAgB,WAAW,SAA6D;IAExF,OAAgB,QAAQ,WAA2C;IAEnE,OAAgB,KAAK;;;;;MAGnB;IAEW,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAyBlC"}
|
|
@@ -9,6 +9,10 @@ export declare class ArtifactMap<T> {
|
|
|
9
9
|
forEach(callback: (value: T, key: TypedArtifactName) => void): void;
|
|
10
10
|
}
|
|
11
11
|
export declare function createArtifactNameSet(): ArtifactMap<TypedArtifactName>;
|
|
12
|
+
/**
|
|
13
|
+
* ArtifactStore is a store for artifacts that are compiled for different modes.
|
|
14
|
+
* It is used to collect all artifacts from the dependency tree and compile them for different modes.
|
|
15
|
+
*/
|
|
12
16
|
export declare class ArtifactStore<T> {
|
|
13
17
|
private readonly dist;
|
|
14
18
|
constructor(nameExtractor: (obj: T) => TypedArtifactName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"artifactset.d.ts","sourceRoot":"","sources":["../../src/compiler/artifactset.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAIhE,qBAAa,WAAW,CAAC,CAAC;IAGZ,OAAO,CAAC,QAAQ,CAAC,aAAa;IAF1C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAwB;gBAEf,aAAa,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,iBAAiB;IAGzE,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,OAAO,GAAE,OAAc,GAAG,CAAC,GAAG,SAAS;IASnD,GAAG,CAAC,IAAI,EAAE,iBAAiB,GAAG,CAAC,GAAG,SAAS;IAI3C,IAAI,KAAK,IAAI,CAAC,EAAE,CAIf;IAED,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,iBAAiB,KAAK,IAAI;CAG7D;AAED,wBAAgB,q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AAC,CAEtE;AAED;;;GAGG;AACH,qBAAa,aAAa,CAAC,CAAC;IAE1B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAiB;gBAE1B,aAAa,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,iBAAiB;IAKxD,GAAG,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,EAAE,OAAO,GAAE,OAAc,GAAG,CAAC,GAAG,SAAS;IAUtE,GAAG,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,iBAAiB,GAAG,CAAC,GAAG,SAAS;IAU9D,KAAK,CAAC,IAAI,EAAE,WAAW,GAAG,CAAC,EAAE;IAM7B,OAAO,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,iBAAiB,KAAK,IAAI;CAGhF"}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { ArtifactSource } from './source';
|
|
2
|
-
import {
|
|
2
|
+
import { TemplateWithSource } from './template';
|
|
3
3
|
import { TypedArtifactName, CompileMode } from './package';
|
|
4
|
+
/** A compilation result. */
|
|
4
5
|
export interface TemplatesAndLibs {
|
|
5
|
-
templates:
|
|
6
|
+
templates: TemplateWithSource[];
|
|
6
7
|
libs: ArtifactSource[];
|
|
7
8
|
software: ArtifactSource[];
|
|
8
9
|
assets: ArtifactSource[];
|
|
9
10
|
}
|
|
10
11
|
export declare class TengoTemplateCompiler {
|
|
11
12
|
private readonly compileMode;
|
|
12
|
-
constructor(compileMode: CompileMode);
|
|
13
13
|
private readonly libs;
|
|
14
14
|
private readonly software;
|
|
15
15
|
private readonly assets;
|
|
16
16
|
private readonly templates;
|
|
17
|
+
constructor(compileMode: CompileMode);
|
|
18
|
+
/** Recursively add dependencies to the template. */
|
|
17
19
|
private populateTemplateDataFromDependencies;
|
|
18
20
|
/** This method assumes that all dependencies are already added to the compiler's context */
|
|
19
21
|
private compileAndAddTemplate;
|
|
@@ -21,6 +23,7 @@ export declare class TengoTemplateCompiler {
|
|
|
21
23
|
allLibs(): ArtifactSource[];
|
|
22
24
|
getLib(name: TypedArtifactName): ArtifactSource | undefined;
|
|
23
25
|
getLibOrError(name: TypedArtifactName): ArtifactSource;
|
|
26
|
+
checkLibs(): void;
|
|
24
27
|
addSoftware(software: ArtifactSource): void;
|
|
25
28
|
allSoftware(): ArtifactSource[];
|
|
26
29
|
getSoftware(name: TypedArtifactName): ArtifactSource | undefined;
|
|
@@ -29,12 +32,11 @@ export declare class TengoTemplateCompiler {
|
|
|
29
32
|
allAssets(): ArtifactSource[];
|
|
30
33
|
getAsset(name: TypedArtifactName): ArtifactSource | undefined;
|
|
31
34
|
getAssetOrError(name: TypedArtifactName): ArtifactSource;
|
|
32
|
-
addTemplate(tpl:
|
|
33
|
-
allTemplates():
|
|
34
|
-
getTemplate(name: TypedArtifactName):
|
|
35
|
-
getTemplateOrError(name: TypedArtifactName):
|
|
36
|
-
getArtefact(name: TypedArtifactName): ArtifactSource |
|
|
37
|
-
checkLibs(): void;
|
|
35
|
+
addTemplate(tpl: TemplateWithSource): void;
|
|
36
|
+
allTemplates(): TemplateWithSource[];
|
|
37
|
+
getTemplate(name: TypedArtifactName): TemplateWithSource | undefined;
|
|
38
|
+
getTemplateOrError(name: TypedArtifactName): TemplateWithSource;
|
|
39
|
+
getArtefact(name: TypedArtifactName): ArtifactSource | TemplateWithSource | undefined;
|
|
38
40
|
compileAndAdd(sources: ArtifactSource[]): TemplatesAndLibs;
|
|
39
41
|
}
|
|
40
42
|
//# sourceMappingURL=compiler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../../src/compiler/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../../src/compiler/compiler.ts"],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E,iBAAiB,GAAG,cAAc,GAAG,SAAS;IAO7D,eAAe,CAAC,IAAI,EAAE,iBAAiB,GAAG,cAAc;IAOxD,WAAW,CAAC,GAAG,EAAE,kBAAkB;IAQnC,YAAY,IAAI,kBAAkB,EAAE;IAIpC,WAAW,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB,GAAG,SAAS;IAMpE,kBAAkB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAO/D,WAAW,CAAC,IAAI,EAAE,iBAAiB,GAAG,cAAc,GAAG,kBAAkB,GAAG,SAAS;IAmBrF,aAAa,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,gBAAgB;CA8G3D"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TemplateDataV3, TemplateLibDataV3 } from '@milaboratories/pl-model-backend';
|
|
2
2
|
import { CompilerOption } from './package';
|
|
3
|
-
export declare function applyTemplateCompilerOptions(opts: CompilerOption[], tpl:
|
|
4
|
-
export declare function applyLibraryCompilerOptions(opts: CompilerOption[], lib:
|
|
3
|
+
export declare function applyTemplateCompilerOptions(opts: CompilerOption[], tpl: TemplateDataV3): void;
|
|
4
|
+
export declare function applyLibraryCompilerOptions(opts: CompilerOption[], lib: TemplateLibDataV3): void;
|
|
5
5
|
export declare function hashOverride(args: string[]): string;
|
|
6
6
|
//# sourceMappingURL=compileroptions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compileroptions.d.ts","sourceRoot":"","sources":["../../src/compiler/compileroptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"compileroptions.d.ts","sourceRoot":"","sources":["../../src/compiler/compileroptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAC1F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAGhD,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,cAAc,EAAE,EAAE,GAAG,EAAE,cAAc,QASvF;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,cAAc,EAAE,EAAE,GAAG,EAAE,iBAAiB,QAazF;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAoBnD"}
|
package/dist/compiler/main.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TemplatesAndLibs, TengoTemplateCompiler } from './compiler';
|
|
2
|
-
import { CompileMode } from './package';
|
|
2
|
+
import { CompileMode, FullArtifactName } from './package';
|
|
3
3
|
import { ArtifactSource } from './source';
|
|
4
4
|
import { default as winston } from 'winston';
|
|
5
5
|
interface PackageId {
|
|
@@ -18,17 +18,16 @@ interface PackageInfo extends PackageId {
|
|
|
18
18
|
/** Dependencies */
|
|
19
19
|
readonly dependencies: PackageInfo[];
|
|
20
20
|
}
|
|
21
|
+
export declare function resolvePackageJsonRoot(root: string): string;
|
|
21
22
|
type PackageInfoContext = 'root' | 'dependency' | 'devDependency';
|
|
22
23
|
/**
|
|
23
24
|
* Get package info from package.json and all dependencies.
|
|
24
|
-
* @param root - Root directory of the package.
|
|
25
|
-
* @param cion
|
|
26
|
-
* @returns Package info.
|
|
27
25
|
*/
|
|
28
26
|
export declare function getPackageInfo(root: string, logger: winston.Logger, context?: PackageInfoContext): PackageInfo;
|
|
29
27
|
export declare function parseSources(logger: winston.Logger, packageId: PackageId, mode: CompileMode, root: string, subdir: string): ArtifactSource[];
|
|
30
28
|
export declare function newCompiler(logger: winston.Logger, packageInfo: PackageInfo, mode: CompileMode): TengoTemplateCompiler;
|
|
31
|
-
export declare function
|
|
29
|
+
export declare function fullNameFromFileName(packageId: PackageId, artifactName: string): FullArtifactName | null;
|
|
30
|
+
export declare function compile(logger: winston.Logger, packageInfo: PackageInfo, mode: CompileMode): TemplatesAndLibs;
|
|
32
31
|
export declare function savePacks(logger: winston.Logger, compiled: TemplatesAndLibs, mode: CompileMode): void;
|
|
33
32
|
export {};
|
|
34
33
|
//# sourceMappingURL=main.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/compiler/main.ts"],"names":[],"mappings":";AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/compiler/main.ts"],"names":[],"mappings":";AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAKtC,OAAO,EAAE,cAAc,EAAmB,MAAM,UAAU,CAAC;AAE3D,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAInC,UAAU,SAAS;IACjB,qCAAqC;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,wCAAwC;IACxC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,UAAU,WAAY,SAAQ,SAAS;IACrC,qCAAqC;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,2BAA2B;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,8BAA8B;IAC9B,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,mBAAmB;IACnB,QAAQ,CAAC,YAAY,EAAE,WAAW,EAAE,CAAC;CACtC;AA2DD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAS3D;AAED,KAAK,kBAAkB,GAAG,MAAM,GAAG,YAAY,GAAG,eAAe,CAAC;AAElE;;GAEG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,OAAO,CAAC,MAAM,EACtB,OAAO,GAAE,kBAA2B,GACnC,WAAW,CAsCb;AAuLD,wBAAgB,YAAY,CAC1B,MAAM,EAAE,OAAO,CAAC,MAAM,EACtB,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,WAAW,EACjB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACb,cAAc,EAAE,CAyClB;AAED,wBAAgB,WAAW,CACzB,MAAM,EAAE,OAAO,CAAC,MAAM,EACtB,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,WAAW,GAChB,qBAAqB,CAOvB;AAED,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,MAAM,GACnB,gBAAgB,GAAG,IAAI,CA2CzB;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,GAAG,gBAAgB,CAqB7G;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,QA4C9F"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { TypedArtifactName, FullArtifactName, ArtifactType, CompileMode, CompilerOption } from './package';
|
|
2
|
+
import { MiLogger } from '@milaboratories/ts-helpers';
|
|
3
|
+
export declare const newGetTemplateIdRE: (moduleName: string) => RegExp;
|
|
4
|
+
export declare const newGetSoftwareInfoRE: (moduleName: string) => RegExp;
|
|
3
5
|
export declare class ArtifactSource {
|
|
4
6
|
/** The mode this artifact was built (dev or dist) */
|
|
5
7
|
readonly compileMode: CompileMode;
|
|
6
8
|
/** Full artifact id, including package version */
|
|
7
9
|
readonly fullName: FullArtifactName;
|
|
10
|
+
/** Hash of the source code */
|
|
11
|
+
readonly sourceHash: string;
|
|
8
12
|
/** Normalized source code */
|
|
9
13
|
readonly src: string;
|
|
10
14
|
/** Path to source file where artifact came from */
|
|
@@ -18,6 +22,8 @@ export declare class ArtifactSource {
|
|
|
18
22
|
compileMode: CompileMode,
|
|
19
23
|
/** Full artifact id, including package version */
|
|
20
24
|
fullName: FullArtifactName,
|
|
25
|
+
/** Hash of the source code */
|
|
26
|
+
sourceHash: string,
|
|
21
27
|
/** Normalized source code */
|
|
22
28
|
src: string,
|
|
23
29
|
/** Path to source file where artifact came from */
|
|
@@ -27,6 +33,20 @@ export declare class ArtifactSource {
|
|
|
27
33
|
/** Additional compiler options detected in source code */
|
|
28
34
|
compilerOptions: CompilerOption[]);
|
|
29
35
|
}
|
|
30
|
-
export declare function parseSourceFile(logger:
|
|
31
|
-
export declare function parseSource(logger:
|
|
36
|
+
export declare function parseSourceFile(logger: MiLogger, mode: CompileMode, srcFile: string, fullSourceName: FullArtifactName, normalize: boolean): ArtifactSource;
|
|
37
|
+
export declare function parseSource(logger: MiLogger, mode: CompileMode, src: string, fullSourceName: FullArtifactName, normalize: boolean): ArtifactSource;
|
|
38
|
+
interface sourceParserContext {
|
|
39
|
+
isInCommentBlock: boolean;
|
|
40
|
+
canDetectOptions: boolean;
|
|
41
|
+
tplDepREs: Map<string, [ArtifactType, RegExp][]>;
|
|
42
|
+
lineNo: number;
|
|
43
|
+
}
|
|
44
|
+
export declare function parseSingleSourceLine(logger: MiLogger, line: string, context: sourceParserContext, localPackageName: string, globalizeImports?: boolean): {
|
|
45
|
+
line: string;
|
|
46
|
+
context: sourceParserContext;
|
|
47
|
+
artifact: TypedArtifactName | undefined;
|
|
48
|
+
option: CompilerOption | undefined;
|
|
49
|
+
};
|
|
50
|
+
export declare function getSha256(source: string): string;
|
|
51
|
+
export {};
|
|
32
52
|
//# sourceMappingURL=source.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/compiler/source.ts"],"names":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EACjB,GAAG,EAAE,MAAM,EACX,cAAc,EAAE,gBAAgB,EAChC,SAAS,EAAE,OAAO,GACjB,cAAc,CAIhB;AAsED,UAAU,mBAAmB;IAC3B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,YAAY,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IACjD,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,QAAQ,EAChB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,mBAAmB,EAC5B,gBAAgB,EAAE,MAAM,EACxB,gBAAgB,CAAC,EAAE,OAAO,GACzB;IACC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,mBAAmB,CAAC;IAC7B,QAAQ,EAAE,iBAAiB,GAAG,SAAS,CAAC;IACxC,MAAM,EAAE,cAAc,GAAG,SAAS,CAAC;CACpC,CA2IF;AAmDD,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEhD"}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { CompileMode, FullArtifactName } from './package';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { CompiledTemplateV3 } from '@milaboratories/pl-model-backend';
|
|
3
|
+
/** Just a holder for template data, compilation options, full name and source code.
|
|
4
|
+
* It mimics ArtifactSource interface.
|
|
5
|
+
*/
|
|
6
|
+
export type TemplateWithSource = {
|
|
4
7
|
readonly compileMode: CompileMode;
|
|
5
8
|
readonly fullName: FullArtifactName;
|
|
6
|
-
readonly
|
|
9
|
+
readonly source: string;
|
|
10
|
+
readonly data: CompiledTemplateV3;
|
|
11
|
+
};
|
|
12
|
+
export declare function newTemplateWithSource(compileMode: CompileMode, fullName: FullArtifactName, data: CompiledTemplateV3, source: string): TemplateWithSource;
|
|
13
|
+
export type Template = {
|
|
14
|
+
readonly compileMode: CompileMode;
|
|
15
|
+
readonly fullName: FullArtifactName;
|
|
16
|
+
readonly data: CompiledTemplateV3;
|
|
7
17
|
readonly content: Uint8Array;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
toJSON(): {
|
|
13
|
-
compileMode: "dist";
|
|
14
|
-
fullName: FullArtifactName;
|
|
15
|
-
data: TemplateData;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
+
};
|
|
19
|
+
export declare function newTemplateFromData(compileMode: CompileMode, fullName: FullArtifactName, data: CompiledTemplateV3): Template;
|
|
20
|
+
export declare function newTemplateFromContent(compileMode: CompileMode, fullName: FullArtifactName, content: Uint8Array): Template;
|
|
21
|
+
export declare function templateToSource(tpl: Template): TemplateWithSource;
|
|
18
22
|
//# sourceMappingURL=template.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../src/compiler/template.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAEjB,MAAM,WAAW,CAAC;AAKnB,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../src/compiler/template.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAEjB,MAAM,WAAW,CAAC;AAKnB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAM3E;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;CACnC,CAAC;AAEF,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,gBAAgB,EAC1B,IAAI,EAAE,kBAAkB,EACxB,MAAM,EAAE,MAAM,GACb,kBAAkB,CASpB;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IACpC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;CAC9B,CAAC;AAEF,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,gBAAgB,EAC1B,IAAI,EAAE,kBAAkB,GACvB,QAAQ,CAQV;AAED,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,UAAU,GAClB,QAAQ,CAaV;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,QAAQ,GAAG,kBAAkB,CAOlE"}
|
|
@@ -28,6 +28,8 @@ export declare const testPackage1Lib1Name: FullArtifactName;
|
|
|
28
28
|
export declare const testPackage1Lib1Src = "\nexport {\n \"some\": \"value1\"\n}\n";
|
|
29
29
|
export declare const testPackage1Soft1Name: FullArtifactName;
|
|
30
30
|
export declare const testPackage1Soft1Src = "\nsome software contents. Template builder should pass it 'as-is'\n";
|
|
31
|
+
export declare const testPackage1Asset1Name: FullArtifactName;
|
|
32
|
+
export declare const testPackage1Asset1Src = "\nsome asset contents. Template builder should pass it 'as-is'\n";
|
|
31
33
|
export declare const testPackage1Lib2Name: FullArtifactName;
|
|
32
34
|
export declare const testPackage1Lib2Src = "\nlib := import(\"package1:other-lib-1\")\nexport {\n \"some\": \"value123\",\n \"theTpl\": getTemplateId(\"package1:template-3\")\n}\n";
|
|
33
35
|
export declare const testPackage1Tpl3Name: FullArtifactName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test.artifacts.d.ts","sourceRoot":"","sources":["../../src/compiler/test.artifac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|
package/dist/index.js
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
${r}`:
|
|
3
|
-
`;for(const
|
|
4
|
-
`;
|
|
5
|
-
`;
|
|
6
|
-
`,
|
|
7
|
-
${
|
|
8
|
-
`),a=[];let
|
|
9
|
-
${
|
|
10
|
-
`),deps:n,opts:o}}function rt(s,e,t,r,n){if(e=e.replaceAll(Xe,""),t.isInCommentBlock)return Qe.exec(e)&&(t.isInCommentBlock=!1),{line:"",context:t,artifact:void 0,option:void 0};if(Ke.exec(e)){if(!t.canDetectOptions)throw s.error(`[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'`),new Error("tengo compiler options ('//tengo:' comments) can be set only in file header");return{line:e,context:t,artifact:void 0,option:st(e)}}if(Ve.exec(e)&&t.canDetectOptions)return s.warn(`[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)`),{line:e,context:t,artifact:void 0,option:void 0};if(Ze.test(e))return{line:"",context:t,artifact:void 0,option:void 0};if(Ye.exec(e))return t.isInCommentBlock=!0,{line:"",context:t,artifact:void 0,option:void 0};if(e.includes("/*"))throw new Error("malformed multiline comment");if(He.exec(e))return{line:e,context:t,artifact:void 0,option:void 0};t.canDetectOptions=!1;const o=Ne.exec(e);if(o){const i=nt(e);if(i.module==="plapi")return t.tplDepREs.has(i.module)||t.tplDepREs.set(i.module,[["template",We(i.alias)],["software",ze(i.alias)]]),{line:e,context:t,artifact:void 0,option:void 0};(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,[["template",me(i.alias)],["software",ge(i.alias)]])),(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,[["template",me(i.alias)],["software",ge(i.alias)],["asset",Be(i.alias)]]));const a=he(i.module,"library",r);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}}if(t.tplDepREs.size>0)for(const[i,a]of t.tplDepREs)for(const[l,p]of a){const d=p.exec(e);if(!d||!d.groups)continue;const{fnCall:u,templateName:w,fnName:v}=d.groups;if(!u||!w||!v)throw Error("failed to parse template import statement");const M=he(w,l,r);if(!M)throw Error(`failed to parse artifact name in ${v} import statement`);return e=e.replace(u,`${v}("${M.pkg}:${M.id}")`),{line:e,context:t,artifact:M,option:void 0}}return{line:e,context:t,artifact:void 0,option:void 0}}function nt(s){const e=et.exec(s);if(!e||!e.groups)throw Error("failed to parse 'import' statement");const{importName:t,moduleName:r}=e.groups;if(!t||!r)throw Error("failed to parse 'import' statement");return{module:r,alias:t}}function he(s,e,t){const r=tt.exec(s);if(!r)return;if(!r.groups)throw Error("failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'");const{pkgName:n,depID:o}=r.groups;if(!o)throw Error("failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'");return{type:e,pkg:n??t,id:o}}const G=".plj.gz",q=".lib.tengo",U=".sw.json",W=".as.json",we=".test.tengo",z=".tpl.tengo",B=".lib.tengo",H=".sw.json",K=".as.json",it=[B,z,H,K];function _(s,e){if(!f.isAbsolute(s))throw new Error(`Root path must be absolute: ${s}`);if(!e){const n=f.join(s,"package.json");if(k(n)==="file")return n;throw new Error(`Can't resolve package.json in ${s}`)}let t=ce.tryResolve(s,e);if(t){let n=0;do{const o=f.join(t,"package.json");if(k(o)==="file")return o;n++,t=f.dirname(t)}while(n<7&&f.basename(t)!=="node_modules")}const r=ce.tryResolveOrError(s,`${e}/package.json`);if(r.result===void 0){if(r.err==="ERR_PACKAGE_PATH_NOT_EXPORTED")return;throw new Error(`Can't resolve package.json for package ${e??"."} relative to ${s}`)}return r.result}function S(s,e,t="root"){const r=_(s);if(!r)throw new Error(`Can't resolve package.json for root package ${s}`);const{name:n,version:o,type:i,dependencies:a,devDependencies:l}=JSON.parse(m.readFileSync(r).toString()),p=[];if(a&&t!=="devDependency")for(const u of Object.keys(a)){const w=_(s,u);if(w===void 0)throw new Error(`Can't resolve package.json for dependency ${u} of ${s}`);const v=f.dirname(w);p.push(S(v,e,"dependency"))}if(l&&t==="root")for(const u of Object.keys(l)){const w=_(s,u);if(w===void 0){e.warn(`Can't resolve package.json for dev dependency ${u} of ${s}`);continue}const v=f.dirname(w);p.push(S(v,e,"devDependency"))}return{name:n,version:o,type:i,dependencies:p,root:s,context:t}}function Se(s,e){return f.resolve(e,s,"tengo","lib")}function Ae(s,e){return f.resolve(e,s,"tengo","tpl")}function Te(s,e){return f.resolve(e,s,"tengo","software")}function De(s,e){return f.resolve(e,s,"tengo","asset")}function Oe(s,e,t){for(const w of t.dependencies)Oe(s,e,w);if(t.context==="root")return;const r=Se("dist",t.root),n=Ae("dist",t.root),o=Te("dist",t.root),i=De("dist",t.root),a=k(r)==="dir",l=k(n)==="dir",p=k(o)==="dir",d=k(i)==="dir";if(!a&&!l&&!p&&!d)return;const u={name:t.name,version:t.version};a&&at(s,u,"dist",r,e),l&<(s,u,"dist",n,e),p&&ct(s,u,"dist",o,e),d&&dt(s,u,"dist",i,e)}function at(s,e,t,r,n){for(const o of m.readdirSync(r)){const i=f.resolve(r,o);if(!o.endsWith(q))throw new Error(`unexpected file in 'lib' folder: ${i}`);const a={type:"library",pkg:e.name,id:o.slice(0,o.length-q.length),version:e.version},l=ke(s,t,i,a,!0);if(n.addLib(l),s.debug(`Adding dependency ${g(a)} from ${i}`),l.dependencies.length>0){s.debug("Dependencies:");for(const p of l.dependencies)s.debug(` - ${h(p)}`)}}}function lt(s,e,t,r,n){for(const o of m.readdirSync(r)){const i=f.resolve(r,o);if(!o.endsWith(G))throw new Error(`unexpected file in 'tpl' folder: ${i}`);const a={type:"template",pkg:e.name,id:o.slice(0,o.length-G.length),version:e.version},l=new Ee(t,a,{content:m.readFileSync(i)});n.addTemplate(l),s.debug(`Adding dependency ${g(a)} from ${i}`)}}function ct(s,e,t,r,n){for(const o of m.readdirSync(r)){const i=f.resolve(r,o);if(!o.endsWith(U))throw new Error(`unexpected file in 'software' folder: ${i}`);const a={type:"software",pkg:e.name,id:o.slice(0,o.length-U.length),version:e.version},l=new re(t,a,m.readFileSync(i).toString(),i,[],[]);s.debug(`Adding dependency ${g(a)} from ${i}`),n.addSoftware(l)}}function dt(s,e,t,r,n){for(const o of m.readdirSync(r)){const i=f.resolve(r,o);if(!o.endsWith(W))throw new Error(`unexpected file in 'asset' folder: ${i}`);const a={type:"asset",pkg:e.name,id:o.slice(0,o.length-W.length),version:e.version},l=new re(t,a,m.readFileSync(i).toString(),i,[],[]);s.debug(`Adding dependency ${g(a)} from ${i}`),n.addAsset(l)}}function j(s,e,t,r,n){const o=[];for(const i of m.readdirSync(f.join(r,n))){const a=f.join(n,i),l=f.join(r,a);if(k(l)==="dir"){const v=j(s,e,t,r,a);o.push(...v);continue}const p=i==="index.lib.tengo"?`${f.dirname(a)}.lib.tengo`:a,d=ft(e,p.replaceAll(f.sep,"."));if(!d){s.info(`Skipping unknown file type: ${p}`);continue}const u=f.resolve(r,a);s.debug(`Parsing ${g(d)} from ${u}`);const w=ke(s,t,u,d,!0);if(w.dependencies.length>0){s.debug("Detected dependencies:");for(const v of w.dependencies)s.debug(` - ${h(v)}`)}o.push(w)}return o}function ne(s,e,t){const r=new Ue(t);return Oe(s,r,e),r}function ft(s,e){const t={pkg:s.name,version:s.version};return e.endsWith(B)?{...t,id:e.substring(0,e.length-B.length),type:"library"}:e.endsWith(z)?{...t,id:e.substring(0,e.length-z.length),type:"template"}:e.endsWith(H)?{...t,id:e.substring(0,e.length-H.length),type:"software"}:e.endsWith(K)?{...t,id:e.substring(0,e.length-K.length),type:"asset"}:e.endsWith(we)?{...t,id:e.substring(0,e.length-we.length),type:"test"}:null}function pt(s,e){const t=S(process.cwd(),s),r=ne(s,t,e),n=j(s,t,e,"src","");if(n.length===0){const i=[];for(const a of it)i.push(`*${a}`);s.error(`Nothing to compile. Looked for ${i.join(", ")}`),process.exit(1)}s.info(`Compiling '${e}'...`);const o=r.compileAndAdd(n);return s.debug("Done."),o}function ut(s,e,t){if(e.libs.length>0){const r=Se(t,".");m.mkdirSync(r,{recursive:!0});for(const n of e.libs){const o=f.resolve(r,n.fullName.id+q);s.info(` - writing ${o}`),m.writeFileSync(o,n.src)}}if(e.templates.length>0){const r=Ae(t,".");m.mkdirSync(r,{recursive:!0});for(const n of e.templates){const o=f.resolve(r,n.fullName.id+G);s.info(` - writing ${o}`),m.writeFileSync(o,n.content)}}if(e.software.length>0){const r=Te(t,".");m.mkdirSync(r,{recursive:!0});for(const n of e.software){const o=f.resolve(r,n.fullName.id+U);s.info(` - writing ${o}`),m.writeFileSync(o,n.src)}}if(e.assets.length>0){const r=De(t,".");m.mkdirSync(r,{recursive:!0});for(const n of e.software){const o=f.resolve(r,n.fullName.id+W);s.info(` - writing ${o}`),m.writeFileSync(o,n.src)}}}const ie={"log-level":y.Flags.string({description:"logging level",default:"info",options:["error","warn","info","debug"]})},mt={"generate-tags":y.Flags.boolean({description:"generate tags, default false",default:!1}),"tags-file":y.Flags.file({description:'where to put ".tags" file, it should be a root of VS Code project',default:"../../.tags"}),"tags-additional-args":y.Flags.string({description:"additional flags for universal-ctags command: e.g. -e for emacs",default:[],multiple:!0,delimiter:","})},A=class A extends y.Command{async run(){const{flags:e}=await this.parse(A),t=E(e["log-level"]),r=S(process.cwd(),t),n=pt(t,"dist");ut(t,n,"dist"),t.info("");let o=`declare type TemplateFromFile = { readonly type: "from-file"; readonly path: string; };
|
|
11
|
-
`;
|
|
12
|
-
`,
|
|
13
|
-
`,
|
|
14
|
-
`;let
|
|
15
|
-
`,
|
|
1
|
+
"use strict";var je=Object.defineProperty;var Ce=(s,e,t)=>e in s?je(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var l=(s,e,t)=>Ce(s,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ye=require("node:child_process"),w=require("@oclif/core"),Me=require("node:path"),be=require("node:fs"),Le=require("winston"),ve=require("@milaboratories/pl-model-backend"),Ie=require("node:crypto"),ce=require("@milaboratories/resolve-helper"),Pe=require("node:fs/promises"),Ee=require("@milaboratories/tengo-tester"),D=require("node:process");function P(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>s[t]})}}return e.default=s,Object.freeze(e)}const d=P(Me),p=P(be),O=P(Le),F=P(Pe);function x(s){throw new Error("Unexpected object: "+s)}function E(s="debug"){return O.createLogger({level:s,format:O.format.combine(O.format.errors({stack:!0}),O.format.printf(({level:e,message:t,stack:r})=>{const i=`${e.padStart(6," ")}: ${t}`;return r?`${i}
|
|
2
|
+
${r}`:i})),transports:[new O.transports.Console({stderrLevels:["error","warn","info","debug"],handleExceptions:!0})]})}function S(s){try{const e=p.statSync(s);return e.isDirectory()?"dir":e.isFile()?"file":e.isSymbolicLink()?"link":"unknown"}catch(e){const t=e;if(t.code=="ENOENT"||t.code=="ENOTDIR")return"absent";throw t}}function _e(s){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())}function le(s){return`${s.type}||${s.pkg}||${s.id}`}function u(s){return`${s.type}:${s.pkg}:${s.id}:${s.version}`}function h(s){return`${s.type}:${s.pkg}:${s.id}`}function de(s,e){return s.type==e.type&&s.pkg==e.pkg&&s.id==e.id}function M(s,e){return s.type==e.type&&s.pkg==e.pkg&&s.id==e.id&&s.version==e.version}function y(s){return`${s.pkg}:${s.id}`}function L(s){return{name:y(s),version:s.version}}function Je(s){const e=s.name.match(/^(?<pkg>[^:]*):(?<id>[^:]*)$/);if(!e)throw new Error(`malformed artifact name: ${s.name}`);return{pkg:e.groups.pkg,id:e.groups.id,version:s.version}}function fe(s){return`${s.pkg}:${s.id}:${s.version}`}function He(s,e,t,r){return $e(e,t),{compileMode:s,fullName:e,data:t,source:r}}function Ge(s,e,t){const r=ve.parseTemplate(t);if(r.type!=="pl.tengo-template.v3")throw new Error("malformed v3 template");return $e(e,r),{compileMode:s,fullName:e,data:r,content:t}}function qe(s){return{compileMode:s.compileMode,fullName:s.fullName,data:s.data,source:s.data.hashToSource[s.data.template.sourceHash]}}function $e(s,e){const t=Je(e.template);if(t.pkg!==s.pkg||t.id!==s.id||t.version!==s.version)throw new Error(`Compiled template name don't match it's package and file names: ${fe(t)} != ${fe(s)}`)}class Ne{constructor(e){l(this,"map",new Map);this.nameExtractor=e}add(e,t=!0){const r=le(this.nameExtractor(e)),i=this.map.get(r);return i&&!t||this.map.set(r,e),i}get(e){return this.map.get(le(e))}get array(){const e=[];return this.map.forEach(t=>e.push(t)),e}forEach(e){this.map.forEach(t=>e(t,this.nameExtractor(t)))}}function We(){return new Ne(s=>s)}class I{constructor(e){l(this,"dist");this.dist=new Ne(e)}add(e,t,r=!0){switch(e){case"dist":return this.dist.add(t,r);default:x(e)}}get(e,t){switch(e){case"dist":return this.dist.get(t);default:x(e)}}array(e){const t=[];return this.forEach(e,r=>t.push(r)),t}forEach(e,t){this.dist.forEach((r,i)=>t(this.get(e,i)??r,i))}}function Ue(s,e){for(const t of s)switch(t.name){case"hash_override":{e.hashOverride=Be(t.args);break}}}function ze(s,e){for(const t of s)switch(t.name){case"hash_override":throw new Error("hash_override compiler option can be used ONLY on template level. Even in templates it is already dangerous enough to potentially break everything in Platforma Backend. In libraries with the transitive dependencies resolution and flattening of libraries list on template level, it becomes so unpredictibally disasterous, that we are doomed to never find the ends of a knot if anything goes wrong.")}}function Be(s){if(s.length!=1)throw new Error("hash_override compiler option expects exactly one argument: hash_override <some string>. Note, you can use only UUID as a value.");const e=s[0].toLowerCase();if(!_e(e))throw new Error(`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`);return e}class Ke{constructor(e){l(this,"libs",new I(e=>e.fullName));l(this,"software",new I(e=>e.fullName));l(this,"assets",new I(e=>e.fullName));l(this,"templates",new I(e=>e.fullName));this.compileMode=e}populateTemplateDataFromDependencies(e,t,r,i){for(const o of r)switch(o.type){case"library":{const n=this.getLibOrError(o),a=i.indexOf(y(o));if(a>=0){const f=`library import recursion detected: ${i.slice(a).join(" -> ")} -> ${y(o)}`;throw new Error(f)}const c={...L(n.fullName),sourceHash:n.sourceHash};ze(n.compilerOptions),t.template.libs[y(o)]=c,t.hashToSource[c.sourceHash]=n.src,this.populateTemplateDataFromDependencies(e,t,n.dependencies,[...i,y(o)]);break}case"software":{const n=this.getSoftwareOrError(o);t.template.software[y(o)]={...L(n.fullName),sourceHash:n.sourceHash},t.hashToSource[n.sourceHash]=n.src;break}case"asset":{const n=this.getAssetOrError(o);t.template.software[y(o)]={...L(n.fullName),sourceHash:n.sourceHash},t.hashToSource[n.sourceHash]=n.src;break}case"template":{if(de(e,o))continue;const n=this.getTemplateOrError(o);t.template.templates[y(o)]=n.data.template,t.hashToSource[n.data.template.sourceHash]=n.source;for(const[a,c]of Object.entries(n.data.hashToSource))t.hashToSource[a]=c;break}case"test":throw new Error(`dependencies tree error: tests should never be part of template: ${h(o)} is dependency of ${y(e)}`);default:x(o.type)}}compileAndAddTemplate(e){if(e.fullName.type!=="template")throw new Error("unexpected source type");const t={type:"pl.tengo-template.v3",hashToSource:{[e.sourceHash]:e.src},template:{...L(e.fullName),templates:{},libs:{},software:{},assets:{},sourceHash:e.sourceHash}};return Ue(e.compilerOptions,t.template),this.populateTemplateDataFromDependencies(e.fullName,t,e.dependencies,[]),t}addLib(e){const t=this.libs.add(e.compileMode,e,!1);if(t&&!M(e.fullName,t.fullName))throw new Error(`compiler already contain such library: adding = ${u(e.fullName)}, contains = ${u(t.fullName)}`)}allLibs(){return this.libs.array(this.compileMode)}getLib(e){if(e.type!=="library")throw new Error(`illegal artifact type: got ${e.type} instead of 'library`);return this.libs.get(this.compileMode,e)}getLibOrError(e){const t=this.getLib(e);if(!t)throw new Error(`library not found: ${y(e)}`);return t}checkLibs(){this.libs.forEach(this.compileMode,e=>{for(const t of e.dependencies){if(t.type==="test")throw new Error(`test should never be dependency of production code: ${h(t)} test is dependency of ${u(e.fullName)}`);if(!this.getArtefact(t))throw new Error(`unresolved dependency ${h(t)} for ${u(e.fullName)}`)}})}addSoftware(e){const t=this.software.add(e.compileMode,e,!1);if(t&&!M(e.fullName,t.fullName))throw new Error(`compiler already contain info for software: adding = ${u(e.fullName)}, contains = ${u(t.fullName)}`)}allSoftware(){return this.software.array(this.compileMode)}getSoftware(e){if(e.type!=="software")throw new Error(`illegal artifact type: got ${e.type} instead of 'software`);return this.software.get(this.compileMode,e)}getSoftwareOrError(e){const t=this.getSoftware(e);if(!t)throw new Error(`software info not found: ${y(e)}`);return t}addAsset(e){const t=this.assets.add(e.compileMode,e,!1);if(t&&!M(e.fullName,t.fullName))throw new Error(`compiler already contain info for asset: adding = ${u(e.fullName)}, contains = ${u(t.fullName)}`)}allAssets(){return this.assets.array(this.compileMode)}getAsset(e){if(e.type!=="asset")throw new Error(`illegal artifact type: got ${e.type} instead of 'asset`);return this.assets.get(this.compileMode,e)}getAssetOrError(e){const t=this.getAsset(e);if(!t)throw new Error(`asset info not found: ${y(e)}`);return t}addTemplate(e){const t=this.templates.add(e.compileMode,e,!1);if(t&&!M(e.fullName,t.fullName))throw new Error(`compiler already contain such template: adding = ${u(e.fullName)}, contains = ${u(t.fullName)}`)}allTemplates(){return this.templates.array(this.compileMode)}getTemplate(e){if(e.type!=="template")throw new Error(`illegal artifact type: got ${e.type} instead of 'template`);return this.templates.get(this.compileMode,e)}getTemplateOrError(e){const t=this.getTemplate(e);if(!t)throw new Error(`template not found: ${y(e)}`);return t}getArtefact(e){switch(e.type){case"template":return this.getTemplate(e);case"library":return this.getLib(e);case"software":return this.getSoftware(e);case"asset":return this.getAsset(e);case"test":return;default:x(e.type)}}compileAndAdd(e){const t={templates:[],libs:[],software:[],assets:[]};let r=[];for(const i of e)i.fullName.type==="library"?(this.addLib(i),t.libs.push(i)):i.fullName.type==="software"?(this.addSoftware(i),t.software.push(i)):i.fullName.type==="asset"?(this.addAsset(i),t.assets.push(i)):r.push(i);for(;r.length>0;){const i=[];for(const o of r){const n=o.dependencies.filter(a=>!this.getArtefact(a)&&!(o.fullName.type==="template"&&de(o.fullName,a)));if(n.length>0){let a=`Unsatisfied dependencies in ${u(o.fullName)}:
|
|
3
|
+
`;for(const c of n)a+=` - ${h(c)}
|
|
4
|
+
`;i.push({src:o,err:new Error(a)});continue}switch(o.fullName.type){case"library":this.addLib(o),t.libs.push(o);break;case"software":this.addSoftware(o),t.software.push(o);break;case"asset":this.addAsset(o),t.assets.push(o);break;case"template":try{const a=this.compileAndAddTemplate(o),c=He(o.compileMode,o.fullName,a,o.src);this.addTemplate(c),t.templates.push(c)}catch(a){const c=a;let f=`Unsatisfied dependencies in ${u(o.fullName)}:
|
|
5
|
+
`;f+=` - ${c.message}
|
|
6
|
+
`,i.push({src:o,err:Error(f)})}break;case"test":break;default:x(o.fullName.type)}}if(r.length===i.length){let o="";for(const n of i)o+=`
|
|
7
|
+
${n.err.message}`;throw new Error(o)}r=i.map(({src:o})=>o)}return t}}const pe="[_a-zA-Z][_a-zA-Z0-9]*",R=(s,e)=>new RegExp(`\\b${s}\\.(?<fnCall>(?<fnName>`+e+')\\s*\\(\\s*"(?<templateName>[^"]+)"\\s*\\))'),Ve=s=>R(s,"getTemplateId"),Xe=s=>R(s,"getSoftwareInfo"),ue=s=>R(s,"importTemplate"),me=s=>R(s,"importSoftware"),Ze=s=>R(s,"importAsset"),Ye=/^\s*$/,Qe=/^\/\/tengo:[\w]/,et=/^\s*\/\/\s*tengo:\s*./,tt=/\/\*.*?\*\//g,st=/^\s*(\/\/)/,ot=/^\s*\/\*/,rt=/\*\//,Se=/\s*:=\s*import\s*\(\s*"(?<moduleName>[^"]+)"\s*\)/,nt=new RegExp(`\\b(?<importName>${pe}(\\.${pe})*)${Se.source}`),it=/(?<pkgName>[^"]+)?:(?<depID>[^"]+)/,at=s=>{const e=s.split(" "),t=e[0].split(":");if(t.length!=2)throw new Error("compiler option format is wrong: expect to have option name after 'tengo:' prefix, like 'tengo:MyOption'");return{name:t[1],args:e.slice(1)}};class oe{constructor(e,t,r,i,o,n,a){this.compileMode=e,this.fullName=t,this.sourceHash=r,this.src=i,this.srcName=o,this.dependencies=n,this.compilerOptions=a}}function ke(s,e,t,r,i){const o=be.readFileSync(t).toString(),{deps:n,normalized:a,opts:c}=ct(s,o,r,i);return new oe(e,r,re(a),a,t,n.array,c)}function ct(s,e,t,r){const i=We(),o=[],n=e.split(`
|
|
8
|
+
`),a=[];let c={isInCommentBlock:!1,canDetectOptions:!0,tplDepREs:new Map,lineNo:0};for(const f of n){c.lineNo++;try{const{line:g,context:m,artifact:b,option:v}=lt(s,f,c,t.pkg,r);a.push(g),c=m,b&&i.add(b),v&&o.push(v)}catch(g){const m=g;throw new Error(`[line ${c.lineNo} in ${u(t)}]: ${m.message}
|
|
9
|
+
${f}`,{cause:m})}}return{normalized:a.join(`
|
|
10
|
+
`),deps:i,opts:o}}function lt(s,e,t,r,i){if(e=e.replaceAll(tt,""),t.isInCommentBlock)return rt.exec(e)&&(t.isInCommentBlock=!1),{line:"",context:t,artifact:void 0,option:void 0};if(Qe.exec(e)){if(!t.canDetectOptions)throw s.error(`[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'`),new Error("tengo compiler options ('//tengo:' comments) can be set only in file header");return{line:e,context:t,artifact:void 0,option:at(e)}}if(et.exec(e)&&t.canDetectOptions)return s.warn(`[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)`),{line:e,context:t,artifact:void 0,option:void 0};if(st.test(e))return{line:"",context:t,artifact:void 0,option:void 0};if(ot.exec(e))return t.isInCommentBlock=!0,{line:"",context:t,artifact:void 0,option:void 0};if(e.includes("/*"))throw new Error("malformed multiline comment");if(Ye.exec(e))return{line:e,context:t,artifact:void 0,option:void 0};t.canDetectOptions=!1;const o=Se.exec(e);if(o){const n=dt(e);if(n.module==="plapi")return t.tplDepREs.has(n.module)||t.tplDepREs.set(n.module,[["template",Ve(n.alias)],["software",Xe(n.alias)]]),{line:e,context:t,artifact:void 0,option:void 0};(n.module==="@milaboratory/tengo-sdk:ll"||n.module==="@platforma-sdk/workflow-tengo:ll"||(r==="@milaboratory/tengo-sdk"||r==="@platforma-sdk/workflow-tengo")&&n.module===":ll")&&(t.tplDepREs.has(n.module)||t.tplDepREs.set(n.module,[["template",ue(n.alias)],["software",me(n.alias)]])),(n.module==="@milaboratory/tengo-sdk:assets"||n.module==="@platforma-sdk/workflow-tengo:assets"||(r==="@milaboratory/tengo-sdk"||r==="@platforma-sdk/workflow-tengo")&&n.module===":assets")&&(t.tplDepREs.has(n.module)||t.tplDepREs.set(n.module,[["template",ue(n.alias)],["software",me(n.alias)],["asset",Ze(n.alias)]]));const a=he(n.module,"library",r);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}}if(t.tplDepREs.size>0)for(const[n,a]of t.tplDepREs)for(const[c,f]of a){const g=f.exec(e);if(!g||!g.groups)continue;const{fnCall:m,templateName:b,fnName:v}=g.groups;if(!m||!b||!v)throw Error("failed to parse template import statement");const C=he(b,c,r);if(!C)throw Error(`failed to parse artifact name in ${v} import statement`);return e=e.replace(m,`${v}("${C.pkg}:${C.id}")`),{line:e,context:t,artifact:C,option:void 0}}return{line:e,context:t,artifact:void 0,option:void 0}}function dt(s){const e=nt.exec(s);if(!e||!e.groups)throw Error("failed to parse 'import' statement");const{importName:t,moduleName:r}=e.groups;if(!t||!r)throw Error("failed to parse 'import' statement");return{module:r,alias:t}}function he(s,e,t){const r=it.exec(s);if(!r)return;if(!r.groups)throw Error("failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'");const{pkgName:i,depID:o}=r.groups;if(!o)throw Error("failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'");return{type:e,pkg:i??t,id:o}}function re(s){return Ie.createHash("sha256").update(s).digest("hex")}const J=".plj.gz",H=".lib.tengo",G=".sw.json",q=".as.json",ge=".test.tengo",W=".tpl.tengo",U=".lib.tengo",z=".sw.json",B=".as.json",ft=[U,W,z,B];function we(s,e){if(!d.isAbsolute(s))throw new Error(`Root path must be absolute: ${s}`);let t=ce.tryResolve(s,e);if(t){let i=0;do{const o=d.join(t,"package.json");if(S(o)==="file")return o;i++,t=d.dirname(t)}while(i<7&&d.basename(t)!=="node_modules")}const r=ce.tryResolveOrError(s,`${e}/package.json`);if(r.result===void 0){if(r.err==="ERR_PACKAGE_PATH_NOT_EXPORTED")return;throw new Error(`Can't resolve package.json for package ${e??"."} relative to ${s}`)}return r.result}function pt(s){if(!d.isAbsolute(s))throw new Error(`Root path must be absolute: ${s}`);const e=d.join(s,"package.json");if(S(e)==="file")return e;throw new Error(`Can't resolve package.json in ${s}`)}function A(s,e,t="root"){const r=pt(s),i=JSON.parse(p.readFileSync(r).toString()),o=[];if(i.dependencies&&t!=="devDependency")for(const n of Object.keys(i.dependencies)){const a=we(s,n);if(a===void 0)throw new Error(`Can't resolve package.json for dependency ${n} of ${s}`);const c=d.dirname(a);o.push(A(c,e,"dependency"))}if(i.devDependencies&&t==="root")for(const n of Object.keys(i.devDependencies)){const a=we(s,n);if(a===void 0){e.warn(`Can't resolve package.json for dev dependency ${n} of ${s}`);continue}const c=d.dirname(a);o.push(A(c,e,"devDependency"))}return{name:i.name,version:i.version,type:i.type,dependencies:o,root:s,context:t}}function Te(s,e){return d.resolve(e,s,"tengo","lib")}function Ae(s,e){return d.resolve(e,s,"tengo","tpl")}function De(s,e){return d.resolve(e,s,"tengo","software")}function Oe(s,e){return d.resolve(e,s,"tengo","asset")}function Fe(s,e,t){for(const b of t.dependencies)Fe(s,e,b);if(t.context==="root")return;const r=Te("dist",t.root),i=Ae("dist",t.root),o=De("dist",t.root),n=Oe("dist",t.root),a=S(r)==="dir",c=S(i)==="dir",f=S(o)==="dir",g=S(n)==="dir";if(!a&&!c&&!f&&!g)return;const m={name:t.name,version:t.version};a&&ut(s,m,"dist",r,e),c&&mt(s,m,"dist",i,e),f&&ht(s,m,"dist",o,e),g&>(s,m,"dist",n,e)}function ut(s,e,t,r,i){for(const o of p.readdirSync(r)){const n=d.resolve(r,o);if(!o.endsWith(H))throw new Error(`unexpected file in 'lib' folder: ${n}`);const a={type:"library",pkg:e.name,id:o.slice(0,o.length-H.length),version:e.version},c=ke(s,t,n,a,!0);if(i.addLib(c),s.debug(`Adding dependency ${u(a)} from ${n}`),c.dependencies.length>0){s.debug("Dependencies:");for(const f of c.dependencies)s.debug(` - ${h(f)}`)}}}function mt(s,e,t,r,i){for(const o of p.readdirSync(r)){const n=d.resolve(r,o);if(!o.endsWith(J))throw new Error(`unexpected file in 'tpl' folder: ${n}`);const a={type:"template",pkg:e.name,id:o.slice(0,o.length-J.length),version:e.version},c=Ge(t,a,p.readFileSync(n));i.addTemplate(qe(c)),s.debug(`Adding dependency ${u(a)} from ${n}`)}}function ht(s,e,t,r,i){for(const o of p.readdirSync(r)){const n=d.resolve(r,o);if(!o.endsWith(G))throw new Error(`unexpected file in 'software' folder: ${n}`);const a={type:"software",pkg:e.name,id:o.slice(0,o.length-G.length),version:e.version},c=p.readFileSync(n).toString(),f=new oe(t,a,re(c),c,n,[],[]);s.debug(`Adding dependency ${u(a)} from ${n}`),i.addSoftware(f)}}function gt(s,e,t,r,i){for(const o of p.readdirSync(r)){const n=d.resolve(r,o);if(!o.endsWith(q))throw new Error(`unexpected file in 'asset' folder: ${n}`);const a={type:"asset",pkg:e.name,id:o.slice(0,o.length-q.length),version:e.version},c=p.readFileSync(n).toString(),f=new oe(t,a,re(c),c,n,[],[]);s.debug(`Adding dependency ${u(a)} from ${n}`),i.addAsset(f)}}function j(s,e,t,r,i){const o=[];for(const n of p.readdirSync(d.join(r,i))){const a=d.join(i,n),c=d.join(r,a);if(S(c)==="dir"){const v=j(s,e,t,r,a);o.push(...v);continue}const f=n==="index.lib.tengo"?`${d.dirname(a)}.lib.tengo`:a,g=wt(e,f.replaceAll(d.sep,"."));if(!g){s.info(`Skipping unknown file type: ${f}`);continue}const m=d.resolve(r,a);s.debug(`Parsing ${u(g)} from ${m}`);const b=ke(s,t,m,g,!0);if(b.dependencies.length>0){s.debug("Detected dependencies:");for(const v of b.dependencies)s.debug(` - ${h(v)}`)}o.push(b)}return o}function ne(s,e,t){const r=new Ke(t);return Fe(s,r,e),r}function wt(s,e){const t={pkg:s.name,version:s.version};return e.endsWith(U)?{...t,id:e.substring(0,e.length-U.length),type:"library"}:e.endsWith(W)?{...t,id:e.substring(0,e.length-W.length),type:"template"}:e.endsWith(z)?{...t,id:e.substring(0,e.length-z.length),type:"software"}:e.endsWith(B)?{...t,id:e.substring(0,e.length-B.length),type:"asset"}:e.endsWith(ge)?{...t,id:e.substring(0,e.length-ge.length),type:"test"}:null}function yt(s,e,t){const r=ne(s,e,t),i=j(s,e,t,"src","");if(i.length===0){const n=[];for(const a of ft)n.push(`*${a}`);s.error(`Nothing to compile. Looked for ${n.join(", ")}`),process.exit(1)}s.info(`Compiling '${t}'...`);const o=r.compileAndAdd(i);return s.debug("Done."),o}function bt(s,e,t){if(e.libs.length>0){const r=Te(t,".");p.mkdirSync(r,{recursive:!0});for(const i of e.libs){const o=d.resolve(r,i.fullName.id+H);s.info(` - writing ${o}`),p.writeFileSync(o,i.src)}}if(e.templates.length>0){const r=Ae(t,".");p.mkdirSync(r,{recursive:!0});for(const i of e.templates){const o=d.resolve(r,i.fullName.id+J);s.info(` - writing ${o}`),p.writeFileSync(o,ve.serializeTemplate(i.data))}}if(e.software.length>0){const r=De(t,".");p.mkdirSync(r,{recursive:!0});for(const i of e.software){const o=d.resolve(r,i.fullName.id+G);s.info(` - writing ${o}`),p.writeFileSync(o,i.src)}}if(e.assets.length>0){const r=Oe(t,".");p.mkdirSync(r,{recursive:!0});for(const i of e.software){const o=d.resolve(r,i.fullName.id+q);s.info(` - writing ${o}`),p.writeFileSync(o,i.src)}}}const ie={"log-level":w.Flags.string({description:"logging level",default:"info",options:["error","warn","info","debug"]})},vt={"generate-tags":w.Flags.boolean({description:"generate tags, default false",default:!1}),"tags-file":w.Flags.file({description:'where to put ".tags" file, it should be a root of VS Code project',default:"../../.tags"}),"tags-additional-args":w.Flags.string({description:"additional flags for universal-ctags command: e.g. -e for emacs",default:[],multiple:!0,delimiter:","})},k=class k extends w.Command{async run(){const{flags:e}=await this.parse(k),t=E(e["log-level"]),r=A(process.cwd(),t),i=yt(t,r,"dist");bt(t,i,"dist"),t.info("Template Pack build done.");const{dts:o,cjs:n,mjs:a}=Et(i);await F.writeFile("dist/index.d.ts",o),r.type==="module"?(await F.writeFile("dist/index.cjs",n),await F.writeFile("dist/index.js",a)):(await F.writeFile("dist/index.js",n),await F.writeFile("dist/index.mjs",a)),$t(e),e["generate-tags"]&&Nt(t,e),t.info("Template Pack build done.")}};l(k,"description","build tengo sources into single distributable pack file"),l(k,"examples",["<%= config.bin %> <%= command.id %>"]),l(k,"flags",{...ie,...vt});let K=k;function Et(s){let e=`declare type TemplateFromFile = { readonly type: "from-file"; readonly path: string; };
|
|
11
|
+
`;e+=`declare type TplName = ${s.templates.map(n=>'"'+n.fullName.id+'"').join(" | ")};
|
|
12
|
+
`,e+=`declare const Templates: Record<TplName, TemplateFromFile>;
|
|
13
|
+
`,e+=`export { Templates };
|
|
14
|
+
`;let t=`module.exports = { Templates: {
|
|
15
|
+
`,r=`import { resolve } from 'node:path';
|
|
16
16
|
export const Templates = {
|
|
17
|
-
`;const
|
|
18
|
-
`),
|
|
19
|
-
`);i
|
|
17
|
+
`;const i=s.templates.map(n=>` '${n.fullName.id}': { type: 'from-file', path: require.resolve('./tengo/tpl/${n.fullName.id}.plj.gz') }`).join(`,
|
|
18
|
+
`),o=s.templates.map(n=>` '${n.fullName.id}': { type: 'from-file', path: resolve(import.meta.dirname, './tengo/tpl/${n.fullName.id}.plj.gz') }`).join(`,
|
|
19
|
+
`);return t+=i,r+=o,t+=`
|
|
20
20
|
}};
|
|
21
|
-
`,
|
|
21
|
+
`,r+=`
|
|
22
22
|
};
|
|
23
|
-
`,
|
|
24
|
-
Found ${o.length} tengo files...`);const
|
|
23
|
+
`,{dts:e,cjs:t,mjs:r}}function $t(s){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(","))}function Nt(s,e){var a;const t=d.resolve(e["tags-file"]),r=d.dirname(t),i=e["tags-additional-args"],o=St(r);s.info(`Generating tags for tengo autocompletion from "${r}" in "${t}", additional arguments: "${i.join('" "')}".
|
|
24
|
+
Found ${o.length} tengo files...`);const n=ye.spawnSync("ctags",["-f",t,...i,"--langdef=tengo","--map-tengo=+.tengo","--kinddef-tengo=f,function,function","--regex-tengo=/^\\s*(.*)(:| :=| =) ?func.*/\\1/f/","--kinddef-tengo=c,constant,constant",'--regex-tengo=/^\\s*(.*) := ("|\\{).*/\\1/c/',"-R",...o],{env:process.env,stdio:"inherit",cwd:r});if((a=n.error)!=null&&a.message.includes("ENOENT")){console.log(`
|
|
25
25
|
pl-tengo can create tags for tengo autocompletion,
|
|
26
26
|
but the program should be installed
|
|
27
27
|
with "brew install universal-ctags" on OSX
|
|
28
28
|
or "sudo apt install universal-ctags" on Ubuntu.
|
|
29
29
|
|
|
30
30
|
For vscode, you should also install ctags extension:
|
|
31
|
-
https://marketplace.visualstudio.com/items?itemName=jaydenlin.ctags-support`);return}
|
|
31
|
+
https://marketplace.visualstudio.com/items?itemName=jaydenlin.ctags-support`);return}kt(n,"failed to generate ctags"),s.info("Generation of tags is done.")}function St(s){const e=p.readdirSync(s,{withFileTypes:!0,recursive:!0}),t=[];return e.forEach(r=>{if(!r.isDirectory()&&r.name.endsWith(".tengo")){const i=d.join(r.parentPath,r.name).replace(s,".");t.push(i)}}),t}function kt(s,e){s.error&&console.log(s.error);const t=e;s.status!==0&&console.log(`WARN: ${t} the build will continue as-is`)}function ae(s,e){const t=A(process.cwd(),s),r=j(s,t,"dist","src",""),i=ne(s,t,"dist");for(const o of i.allLibs())s.debug(`Dumping to pl-tester: ${h(o.fullName)}`),e.write(JSON.stringify(o)+`
|
|
32
32
|
`);for(const o of r)o.fullName.type==="library"&&(s.debug(`Dumping to pl-tester: ${h(o.fullName)}`),e.write(JSON.stringify(o)+`
|
|
33
|
-
`));for(const o of
|
|
33
|
+
`));for(const o of i.allTemplates())s.debug(`Dumping to pl-tester: ${h(o.fullName)}`),e.write(JSON.stringify(o)+`
|
|
34
34
|
`);for(const o of r)o.fullName.type==="template"&&(s.debug(`Dumping to pl-tester: ${h(o.fullName)} ${o.srcName}`),e.write(JSON.stringify(o)+`
|
|
35
|
-
`));for(const o of
|
|
35
|
+
`));for(const o of i.allSoftware())s.debug(`Dumping to pl-tester: ${h(o.fullName)}`),e.write(JSON.stringify(o)+`
|
|
36
36
|
`);for(const o of r)o.fullName.type==="software"&&(s.debug(`Dumping to pl-tester: ${h(o.fullName)}`),e.write(JSON.stringify(o)+`
|
|
37
|
-
`));for(const o of
|
|
37
|
+
`));for(const o of i.allAssets())s.debug(`Dumping to pl-tester: ${h(o.fullName)}`),e.write(JSON.stringify(o)+`
|
|
38
38
|
`);for(const o of r)o.fullName.type==="asset"&&(s.debug(`Dumping to pl-tester: ${h(o.fullName)}`),e.write(JSON.stringify(o)+`
|
|
39
39
|
`));for(const o of r)o.fullName.type==="test"&&(s.debug(`Dumping to pl-tester: ${h(o.fullName)} ${o.srcName}`),e.write(JSON.stringify(o)+`
|
|
40
|
-
`))}function
|
|
41
|
-
`);return}const o=ne(s,r,"dist");for(const
|
|
42
|
-
`)}function
|
|
43
|
-
`)}function
|
|
40
|
+
`))}function Tt(s,e,t){const r=A(process.cwd(),s),i=j(s,r,"dist","src","");if(!e){for(const n of i)n.fullName.type==="library"&&t.write(JSON.stringify(n)+`
|
|
41
|
+
`);return}const o=ne(s,r,"dist");for(const n of i)n.fullName.type==="library"&&o.addLib(n);for(const n of o.allLibs())t.write(JSON.stringify(n)+`
|
|
42
|
+
`)}function _(s,e,t){const r=A(process.cwd(),s),i=j(s,r,"dist","src","");for(const o of i)o.fullName.type===t&&e.write(JSON.stringify(o)+`
|
|
43
|
+
`)}function At(s,e){_(s,e,"template")}function Dt(s,e){_(s,e,"software")}function Ot(s,e){_(s,e,"asset")}function Ft(s,e){_(s,e,"test")}function xe(s,...e){const t=ye.spawn(s,e,{stdio:["pipe","inherit","inherit"]});return t.stdin.on("error",r=>{r.code}),t}function Re(s){return new Promise((e,t)=>{s.on("close",r=>{e(r)}),s.on("error",r=>{t(r)})})}const $=class $ extends w.Command{async run(){const{flags:e,argv:t}=await this.parse($),r=E(e["log-level"]),i=t.length==0?["./src"]:t,o=xe(Ee.TengoTesterBinaryPath,"check","--log-level",e["log-level"],"--artifacts","-",...i);try{ae(r,o.stdin)}catch(n){r.error(n)}finally{o.stdin.end();const n=await Re(o);process.exit(n)}}};l($,"description","check tengo sources for language processor an"),l($,"strict",!1),l($,"flags",{...ie}),l($,"examples",["<%= config.bin %> <%= command.id %>"]);let V=$;const N=class N extends w.Command{async run(){const{flags:e}=await this.parse(N),t=E(e["log-level"]),r=this.argv.length==0?["./src"]:this.argv,i=xe(Ee.TengoTesterBinaryPath,"run","--log-level",e["log-level"],"--artifacts","-",...r);try{ae(t,i.stdin)}catch(o){t.error(o)}finally{i.stdin.end();const o=await Re(i);process.exit(o)}}};l(N,"description","run tengo unit tests (.test.tengo)"),l(N,"strict",!1),l(N,"flags",{...ie}),l(N,"examples",["<%= config.bin %> <%= command.id %>"]);let X=N;class Z extends w.Command{async run(){const e=E();ae(e,D.stdout)}}l(Z,"description","parse sources in current package and dump all found artifacts to stdout"),l(Z,"examples",["<%= config.bin %> <%= command.id %>"]);class Y extends w.Command{async run(){const e=E();Ot(e,D.stdout)}}l(Y,"description","parse sources in current package and dump all found assets to stdout"),l(Y,"examples",["<%= config.bin %> <%= command.id %>"]);const T=class T extends w.Command{async run(){const{flags:e}=await this.parse(T),t=E();Tt(t,e.deps,D.stdout)}};l(T,"description","parse sources in current package and dump all found libs to stdout"),l(T,"examples",["<%= config.bin %> <%= command.id %>"]),l(T,"flags",{deps:w.Flags.boolean({name:"deps",description:"add also all libraries found in node_modules"})});let Q=T;class ee extends w.Command{async run(){const e=E();Dt(e,D.stdout)}}l(ee,"description","parse sources in current package and dump all found software to stdout"),l(ee,"examples",["<%= config.bin %> <%= command.id %>"]);class te extends w.Command{async run(){const e=E();At(e,D.stdout)}}l(te,"description","parse sources in current package and dump all found templates to stdout"),l(te,"examples",["<%= config.bin %> <%= command.id %>"]);class se extends w.Command{async run(){const e=E();Ft(e,D.stdout)}}l(se,"description","parse sources in current package and dump all found tests to stdout"),l(se,"examples",["<%= config.bin %> <%= command.id %>"]);const xt={build:K,check:V,test:X,"dump:all":Z,"dump:assets":Y,"dump:libs":Q,"dump:software":ee,"dump:templates":te,"dump:tests":se};exports.COMMANDS=xt;
|
|
44
44
|
//# sourceMappingURL=index.js.map
|