@platforma-sdk/tengo-builder 1.19.2 → 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.
@@ -10,8 +10,6 @@ export declare class ArtifactMap<T> {
10
10
  }
11
11
  export declare function createArtifactNameSet(): ArtifactMap<TypedArtifactName>;
12
12
  export declare class ArtifactStore<T> {
13
- private readonly nameExtractor;
14
- private readonly dev;
15
13
  private readonly dist;
16
14
  constructor(nameExtractor: (obj: T) => TypedArtifactName);
17
15
  add(mode: CompileMode, obj: T, replace?: boolean): T | undefined;
@@ -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,qBAAqB,IAAI,WAAW,CAAC,iBAAiB,CAAC,CAEtE;AAED,qBAAa,aAAa,CAAC,CAAC;IAId,OAAO,CAAC,QAAQ,CAAC,aAAa;IAH1C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAiB;IACrC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAiB;gBAET,aAAa,EAAE,CA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AC,OAAO,EAAE,cAAc,EAAE,GAAG,gBAAgB;CAsG3D"}
@@ -2,14 +2,32 @@ import { TemplatesAndLibs, TengoTemplateCompiler } from './compiler';
2
2
  import { CompileMode } from './package';
3
3
  import { ArtifactSource } from './source';
4
4
  import { default as winston } from 'winston';
5
- interface PackageJson {
6
- name: string;
7
- version: string;
8
- type: string;
5
+ interface PackageId {
6
+ /** Package name from package.json */
7
+ readonly name: string;
8
+ /** Package version from package.json */
9
+ readonly version: string;
9
10
  }
10
- export declare function getPackageInfo(): PackageJson;
11
- export declare function parseSources(logger: winston.Logger, packageInfo: PackageJson, mode: CompileMode, root: string, subdir: string): ArtifactSource[];
12
- export declare function newCompiler(logger: winston.Logger, packageInfo: PackageJson, mode: CompileMode): TengoTemplateCompiler;
11
+ interface PackageInfo extends PackageId {
12
+ /** Package type from package.json */
13
+ readonly type: string | undefined;
14
+ /** Path to package root */
15
+ readonly root: string;
16
+ /** Context of package info */
17
+ readonly context: PackageInfoContext;
18
+ /** Dependencies */
19
+ readonly dependencies: PackageInfo[];
20
+ }
21
+ type PackageInfoContext = 'root' | 'dependency' | 'devDependency';
22
+ /**
23
+ * 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
+ */
28
+ export declare function getPackageInfo(root: string, logger: winston.Logger, context?: PackageInfoContext): PackageInfo;
29
+ export declare function parseSources(logger: winston.Logger, packageId: PackageId, mode: CompileMode, root: string, subdir: string): ArtifactSource[];
30
+ export declare function newCompiler(logger: winston.Logger, packageInfo: PackageInfo, mode: CompileMode): TengoTemplateCompiler;
13
31
  export declare function compile(logger: winston.Logger, mode: CompileMode): TemplatesAndLibs;
14
32
  export declare function savePacks(logger: winston.Logger, compiled: TemplatesAndLibs, mode: CompileMode): void;
15
33
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/compiler/main.ts"],"names":[],"mappings":";AAKA,OAAO,KAAK,EAAE,gBA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27
  export declare function typedArtifactNameToString(name: TypedArtifactName): string;
28
28
  export declare function typedArtifactNamesEquals(name1: TypedArtifactName, name2: TypedArtifactName): boolean;
29
+ export declare function fullNameEquals(name1: FullArtifactName, name2: FullArtifactName): boolean;
29
30
  /** used to format artefact name while generating output files */
30
31
  export declare function artifactNameToString(name: ArtifactName): string;
31
32
  /** used to format artefact name and version while generating output files */
@@ -1 +1 @@
1
- {"version":3,"file":"package.d.ts","sourceRoot":"","sources":["../../src/compiler/package.ts"],"names":[],"mappings":"AAmBA,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC;AAEjC,MAAM,MAAM,cAAc,GAAG;IAC3B,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAC;IAEb,mEAAmE;IACnE,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC;AAElF,8CAA8C;AAC9C,MAAM,WAAW,gBAAgB;IAC/B,sBAAsB;IACtB,IAAI,EAAE,YAAY,CAAC;IAEnB,8BAA8B;IAC9B,GAAG,EAAE,MAAM,CAAC;IAEZ,4CAA4C;IAC5C,EAAE,EAAE,MAAM,CAAC;IAEX,sBAAsB;IACtB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,2BAA2B,GAAG,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;AAEzE,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,gBAAgB,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,CAAC,CAAC;AAE9E,MAAM,MAAM,WAAW,GAAG,IAAI,CAAC,gBAAgB,EAAE,KAAK,GAAG,SAAS,CAAC,CAAC;AAEpE,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,gBAAgB,EAAE,KAAK,GAAG,IAAI,CAAC,CAAC;AAEhE,wBAAgB,WAAW,CAAC,IAAI,EAAE,iBAAiB,G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gB,2BAA2B,CAAC,IAAI,EAAE,2BAA2B,GAAG,MAAM,CAErF;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,gBAAgB,GAAG,2BAA2B,CAEvF"}
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/compiler/util.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,GAAG,KAAK,CAG3C;AAED,wBAAgB,YAAY,CAAC,KAAK,GAAE,MAAgB,GAAG,OAAO,CAAC,MAAM,CAapE;AAED,wBAAgB,eAAe,IAAI,MAAM,CAexC;AAED,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,SAAS,CAAC;AAEtE,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAY/C;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAG5C"}
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/compiler/util.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,GAAG,KAAK,CAG3C;AAED,wBAAgB,YAAY,CAAC,KAAK,GAAE,MAAgB,GAAG,OAAO,CAAC,MAAM,CAiBpE;AAED,wBAAgB,eAAe,IAAI,MAAM,CAexC;AAED,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,SAAS,CAAC;AAEtE,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAa/C;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAG5C"}
package/dist/index.js CHANGED
@@ -1,25 +1,26 @@
1
- "use strict";var Me=Object.defineProperty;var Re=(s,e,t)=>e in s?Me(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var l=(s,e,t)=>Re(s,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ye=require("node:child_process"),h=require("@oclif/core"),je=require("node:path"),be=require("node:fs"),Le=require("winston"),ce=require("@milaboratories/pl-model-backend"),Ce=require("node:fs/promises"),ve=require("@milaboratories/tengo-tester"),D=require("node:process");function C(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 f=C(je),p=C(be),_=C(Le),O=C(Ce);function F(s){throw new Error("Unexpected object: "+s)}function N(s="debug"){return _.createLogger({level:s,format:_.format.printf(({level:e,message:t})=>`${e.padStart(6," ")}: ${t}`),transports:[new _.transports.Console({stderrLevels:["error","warn","info","debug"],handleExceptions:!0})]})}function Ie(){let s=process.cwd();for(;s;){const e=f.join(s,"node_modules");if(p.existsSync(e))return e;const t=f.resolve(s,"..");if(t===s)break;s=t}throw new Error("Unable to find node_modules directory.")}function $(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")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 de(s){return`${s.type}||${s.pkg}||${s.id}`}function m(s){return`${s.type}:${s.pkg}:${s.id}:${s.version}`}function g(s){return`${s.type}:${s.pkg}:${s.id}`}function fe(s,e){return s.type==e.type&&s.pkg==e.pkg&&s.id==e.id}function w(s){return`${s.pkg}:${s.id}`}function j(s){return{name:w(s),version:s.version}}function Ge(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 pe(s){return`${s.pkg}:${s.id}:${s.version}`}class Ee{constructor(e,t,r){l(this,"data");l(this,"content");this.compileMode=e,this.fullName=t;let{data:n,content:o}=r;if(n===void 0&&o===void 0)throw new Error("Neither data nor content is provided for template constructor");if(n!==void 0&&o!==void 0)throw new Error("Both data and content are provided for template constructor");n===void 0&&(n=ce.parseTemplate(o)),o===void 0&&(o=ce.serializeTemplate(n));const i=Ge(n);if(i.pkg!==t.pkg||i.id!==t.id||i.version!==t.version)throw new Error(`Compiled template name don't match it's package and file names: ${pe(i)} != ${pe(t)}`);this.data=n,this.content=o}toJSON(){return{compileMode:this.compileMode,fullName:this.fullName,data:this.data}}}class G{constructor(e){l(this,"map",new Map);this.nameExtractor=e}add(e,t=!0){const r=de(this.nameExtractor(e)),n=this.map.get(r);return n&&!t||this.map.set(r,e),n}get(e){return this.map.get(de(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 Pe(){return new G(s=>s)}class L{constructor(e){l(this,"dev");l(this,"dist");this.nameExtractor=e,this.dev=new G(e),this.dist=new G(e)}add(e,t,r=!0){switch(e){case"dist":return this.dist.add(t,r);default:F(e)}}get(e,t){switch(e){case"dist":return this.dist.get(t);default:F(e)}}array(e){const t=[];return this.forEach(e,r=>t.push(r)),t}forEach(e,t){this.dist.forEach((r,n)=>t(this.get(e,n)??r,n))}}function Ue(s,e){for(const t of s)switch(t.name){case"hash_override":{e.hashOverride=Je(t.args);break}}}function qe(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 Je(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 We{constructor(e){l(this,"libs",new L(e=>e.fullName));l(this,"software",new L(e=>e.fullName));l(this,"assets",new L(e=>e.fullName));l(this,"templates",new L(e=>e.fullName));this.compileMode=e}populateTemplateDataFromDependencies(e,t,r,n){for(const o of r)switch(o.type){case"library":{const i=this.getLibOrError(o),a=n.indexOf(w(o));if(a>=0){const u=`library import recursion detected: ${n.slice(a).join(" -> ")} -> ${w(o)}`;throw new Error(u)}const c={...j(i.fullName),src:i.src};qe(i.compilerOptions),t.libs[w(o)]=c,this.populateTemplateDataFromDependencies(e,t,i.dependencies,[...n,w(o)]);break}case"software":{const i=this.getSoftwareOrError(o);t.software[w(o)]={...j(i.fullName),src:i.src};break}case"asset":{const i=this.getAssetOrError(o);t.software[w(o)]={...j(i.fullName),src:i.src};break}case"template":{if(fe(e,o))continue;const i=this.getTemplateOrError(o);t.templates[w(o)]=i.data;break}case"test":throw new Error(`dependencies tree error: tests should never be part of template: ${g(o)} is dependency of ${w(e)}`);default:F(o.type)}}compileAndAddTemplate(e){if(e.fullName.type!=="template")throw new Error("unexpected source type");const t={type:"pl.tengo-template.v2",...j(e.fullName),templates:{},libs:{},software:{},assets:{},src:e.src};Ue(e.compilerOptions,t),this.populateTemplateDataFromDependencies(e.fullName,t,e.dependencies,[]);const r=new Ee(e.compileMode,e.fullName,{data:t});return this.addTemplate(r),r}addLib(e){const t=this.libs.add(e.compileMode,e,!1);if(t)throw new Error(`compiler already contain such library: adding = ${m(e.fullName)}, contains = ${m(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: ${w(e)}`);return t}addSoftware(e){const t=this.software.add(e.compileMode,e,!1);if(t)throw new Error(`compiler already contain info for software: adding = ${m(e.fullName)}, contains = ${m(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: ${w(e)}`);return t}addAsset(e){const t=this.assets.add(e.compileMode,e,!1);if(t)throw new Error(`compiler already contain info for asset: adding = ${m(e.fullName)}, contains = ${m(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: ${w(e)}`);return t}addTemplate(e){const t=this.templates.add(e.compileMode,e,!1);if(t)throw new Error(`compiler already contain such template: adding = ${m(e.fullName)}, contains = ${m(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: ${w(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:F(e.type)}}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: ${g(t)} test is dependency of ${m(e.fullName)}`);if(!this.getArtefact(t))throw new Error(`unresolved dependency ${g(t)} for ${m(e.fullName)}`)}})}compileAndAdd(e){const t={templates:[],libs:[],software:[],assets:[]};let r=[];for(const n of e)n.fullName.type==="library"?(this.addLib(n),t.libs.push(n)):n.fullName.type==="software"?(this.addSoftware(n),t.software.push(n)):n.fullName.type==="asset"?(this.addAsset(n),t.assets.push(n)):r.push(n);for(;r.length>0;){const n=[];for(const o of r){const i=o.dependencies.filter(a=>!this.getArtefact(a)&&!(o.fullName.type==="template"&&fe(o.fullName,a)));if(i.length>0){let a=`Unsatisfied dependencies in ${m(o.fullName)}:
2
- `;for(const c of i)a+=` - ${g(c)}
3
- `;n.push({src:o,err: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);t.templates.push(a)}catch(a){const c=a;let u=`Unsatisfied dependencies in ${m(o.fullName)}:
4
- `;u+=` - ${c.message}
5
- `,n.push({src:o,err:Error(u)})}break;case"test":break;default:F(o.fullName.type)}}if(r.length===n.length){let o="";for(const i of n)o+=`
6
- ${i.err.message}`;throw new Error(o)}r=n.map(({src:o})=>o)}return t}}const ue="[_a-zA-Z][_a-zA-Z0-9]*",x=(s,e)=>new RegExp(`\\b${s}\\.(?<fnCall>(?<fnName>`+e+')\\s*\\(\\s*"(?<templateName>[^"]+)"\\s*\\))'),ze=s=>x(s,"getTemplateId"),Be=s=>x(s,"getSoftwareInfo"),me=s=>x(s,"importTemplate"),ge=s=>x(s,"importSoftware"),Ve=s=>x(s,"importAsset"),Ze=/^\s*$/,Ke=/^\/\/tengo:[\w]/,Xe=/^\s*\/\/\s*tengo:\s*./,Ye=/\/\*.*?\*\//g,He=/^\s*(\/\/)/,Qe=/^\s*\/\*/,et=/\*\//,$e=/\s*:=\s*import\s*\(\s*"(?<moduleName>[^"]+)"\s*\)/,tt=new RegExp(`\\b(?<importName>${ue}(\\.${ue})*)${$e.source}`),st=/(?<pkgName>[^"]+)?:(?<depID>[^"]+)/,ot=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,n,o,i){this.compileMode=e,this.fullName=t,this.src=r,this.srcName=n,this.dependencies=o,this.compilerOptions=i}}function Ne(s,e,t,r,n){const o=be.readFileSync(t).toString(),{deps:i,normalized:a,opts:c}=rt(s,o,r,n);return new oe(e,r,a,t,i.array,c)}function rt(s,e,t,r){const n=Pe(),o=[],i=e.split(`
7
- `),a=[];let c={isInCommentBlock:!1,canDetectOptions:!0,tplDepREs:new Map,lineNo:0};for(const u of i){c.lineNo++;try{const d=nt(s,u,c,t.pkg,r);a.push(d.line),c=d.context,d.artifact&&n.add(d.artifact),d.option&&o.push(d.option)}catch(d){const y=d;throw new Error(`[line ${c.lineNo} in ${m(t)}]: ${y.message}
8
- ${u}`,{cause:y})}}return{normalized:a.join(`
9
- `),deps:n,opts:o}}function nt(s,e,t,r,n){if(e=e.replaceAll(Ye,""),t.isInCommentBlock)return et.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:ot(e)}}if(Xe.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(He.test(e))return{line:"",context:t,artifact:void 0,option:void 0};if(Qe.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(Ze.exec(e))return{line:e,context:t,artifact:void 0,option:void 0};t.canDetectOptions=!1;const o=$e.exec(e);if(o){const i=it(e);if(i.module==="plapi")return t.tplDepREs.has(i.module)||t.tplDepREs.set(i.module,[["template",ze(i.alias)],["software",Be(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",Ve(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[c,u]of a){const d=u.exec(e);if(!d||!d.groups)continue;const{fnCall:y,templateName:E,fnName:b}=d.groups;if(!y||!E||!b)throw Error("failed to parse template import statement");const v=he(E,c,r);if(!v)throw Error(`failed to parse artifact name in ${b} import statement`);return e=e.replace(y,`${b}("${v.pkg}:${v.id}")`),{line:e,context:t,artifact:v,option:void 0}}return{line:e,context:t,artifact:void 0,option:void 0}}function it(s){const e=tt.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=st.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 P=".plj.gz",U=".lib.tengo",q=".sw.json",J=".as.json",we=".test.tengo",W=".tpl.tengo",z=".lib.tengo",B=".sw.json",V=".as.json",at=[z,W,B,V];function M(){return JSON.parse(p.readFileSync("package.json").toString())}function Se(s,e){return f.resolve(e,s,"tengo","lib")}function ke(s,e){return f.resolve(e,s,"tengo","tpl")}function Ae(s,e){return f.resolve(e,s,"tengo","software")}function Te(s,e){return f.resolve(e,s,"tengo","asset")}function De(s,e,t,r,n=!1){const o=f.resolve(r,"package.json");if($(o)!=="file"){for(const ae of p.readdirSync(r)){const xe=$(f.join(r,ae))==="link",le=f.resolve(r,ae);$(le)==="dir"&&De(s,e,t,le,xe)}return}const i=Se("dist",r),a=ke("dist",r),c=Ae("dist",r),u=Te("dist",r),d=$(i)==="dir",y=$(a)==="dir",E=$(c)==="dir",b=$(u)==="dir";if(!d&&!y&&!E&&!b)return;const v=JSON.parse(p.readFileSync(o).toString());if(v.name!==t.name){if($(f.resolve(r,"node_modules"))==="dir"&&n)throw new Error(`nested node_modules is a sign of library dependencies version incompatibility in ${r}`);d&&lt(s,v,"dist",i,e),y&&ct(s,v,"dist",a,e),E&&dt(s,v,"dist",c,e),b&&ft(s,v,"dist",u,e)}}function lt(s,e,t,r,n){for(const o of p.readdirSync(r)){const i=f.resolve(r,o);if(!o.endsWith(U))throw new Error(`unexpected file in 'lib' folder: ${i}`);const a={type:"library",pkg:e.name,id:o.slice(0,o.length-U.length),version:e.version},c=Ne(s,t,i,a,!0);if(n.addLib(c),s.debug(`Adding dependency ${m(a)} from ${i}`),c.dependencies.length>0){s.debug("Dependencies:");for(const u of c.dependencies)s.debug(` - ${g(u)}`)}}}function ct(s,e,t,r,n){for(const o of p.readdirSync(r)){const i=f.resolve(r,o);if(!o.endsWith(P))throw new Error(`unexpected file in 'tpl' folder: ${i}`);const a={type:"template",pkg:e.name,id:o.slice(0,o.length-P.length),version:e.version},c=new Ee(t,a,{content:p.readFileSync(i)});n.addTemplate(c),s.debug(`Adding dependency ${m(a)} from ${i}`)}}function dt(s,e,t,r,n){for(const o of p.readdirSync(r)){const i=f.resolve(r,o);if(!o.endsWith(q))throw new Error(`unexpected file in 'software' folder: ${i}`);const a={type:"software",pkg:e.name,id:o.slice(0,o.length-q.length),version:e.version},c=new oe(t,a,p.readFileSync(i).toString(),i,[],[]);s.debug(`Adding dependency ${m(a)} from ${i}`),n.addSoftware(c)}}function ft(s,e,t,r,n){for(const o of p.readdirSync(r)){const i=f.resolve(r,o);if(!o.endsWith(J))throw new Error(`unexpected file in 'asset' folder: ${i}`);const a={type:"asset",pkg:e.name,id:o.slice(0,o.length-J.length),version:e.version},c=new oe(t,a,p.readFileSync(i).toString(),i,[],[]);s.debug(`Adding dependency ${m(a)} from ${i}`),n.addAsset(c)}}function R(s,e,t,r,n){const o=[];for(const i of p.readdirSync(f.join(r,n))){const a=f.join(n,i),c=f.join(r,a);if($(c)==="dir"){const b=R(s,e,t,r,a);o.push(...b);continue}const u=i==="index.lib.tengo"?`${f.dirname(a)}.lib.tengo`:a,d=pt(e,u.replaceAll(f.sep,"."));if(!d)continue;const y=f.resolve(r,a);s.debug(`Parsing ${m(d)} from ${y}`);const E=Ne(s,t,y,d,!0);if(E.dependencies.length>0){s.debug("Detected dependencies:");for(const b of E.dependencies)s.debug(` - ${g(b)}`)}o.push(E)}return o}function re(s,e,t){const r=new We(t);return De(s,r,e,Ie()),r}function pt(s,e){const t={pkg:s.name,version:s.version};return e.endsWith(z)?{...t,id:e.substring(0,e.length-z.length),type:"library"}:e.endsWith(W)?{...t,id:e.substring(0,e.length-W.length),type:"template"}:e.endsWith(B)?{...t,id:e.substring(0,e.length-B.length),type:"software"}:e.endsWith(V)?{...t,id:e.substring(0,e.length-V.length),type:"asset"}:e.endsWith(we)?{...t,id:e.substring(0,e.length-we.length),type:"test"}:null}function ut(s,e){const t=M(),r=re(s,t,e),n=R(s,t,e,"src","");if(n.length===0){const i=[];for(const a of at)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 mt(s,e,t){if(e.libs.length>0){const r=Se(t,".");p.mkdirSync(r,{recursive:!0});for(const n of e.libs){const o=f.resolve(r,n.fullName.id+U);s.info(` - writing ${o}`),p.writeFileSync(o,n.src)}}if(e.templates.length>0){const r=ke(t,".");p.mkdirSync(r,{recursive:!0});for(const n of e.templates){const o=f.resolve(r,n.fullName.id+P);s.info(` - writing ${o}`),p.writeFileSync(o,n.content)}}if(e.software.length>0){const r=Ae(t,".");p.mkdirSync(r,{recursive:!0});for(const n of e.software){const o=f.resolve(r,n.fullName.id+q);s.info(` - writing ${o}`),p.writeFileSync(o,n.src)}}if(e.assets.length>0){const r=Te(t,".");p.mkdirSync(r,{recursive:!0});for(const n of e.software){const o=f.resolve(r,n.fullName.id+J);s.info(` - writing ${o}`),p.writeFileSync(o,n.src)}}}const ne={"log-level":h.Flags.string({description:"logging level",default:"info",options:["error","warn","info","debug"]})},gt={"generate-tags":h.Flags.boolean({description:"generate tags, default false",default:!1}),"tags-file":h.Flags.file({description:'where to put ".tags" file, it should be a root of VS Code project',default:"../../.tags"}),"tags-additional-args":h.Flags.string({description:"additional flags for universal-ctags command: e.g. -e for emacs",default:[],multiple:!0,delimiter:","})},A=class A extends h.Command{async run(){const{flags:e}=await this.parse(A),t=N(e["log-level"]),r=M(),n=ut(t,"dist");mt(t,n,"dist"),t.info("");let o=`declare type TemplateFromFile = { readonly type: "from-file"; readonly path: string; };
1
+ "use strict";var Re=Object.defineProperty;var je=(s,e,t)=>e in s?Re(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var c=(s,e,t)=>je(s,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ye=require("node:child_process"),y=require("@oclif/core"),Me=require("node:path"),be=require("node:fs"),Ce=require("winston"),le=require("@milaboratories/pl-model-backend"),ce=require("@milaboratories/resolve-helper"),Le=require("node:fs/promises"),ve=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 f=P(Me),m=P(be),O=P(Ce),F=P(Le);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 n=`${e.padStart(6," ")}: ${t}`;return r?`${n}
2
+ ${r}`:n})),transports:[new O.transports.Console({stderrLevels:["error","warn","info","debug"],handleExceptions:!0})]})}function k(s){try{const e=m.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 Ie(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 de(s){return`${s.type}||${s.pkg}||${s.id}`}function g(s){return`${s.type}:${s.pkg}:${s.id}:${s.version}`}function h(s){return`${s.type}:${s.pkg}:${s.id}`}function fe(s,e){return s.type==e.type&&s.pkg==e.pkg&&s.id==e.id}function C(s,e){return s.type==e.type&&s.pkg==e.pkg&&s.id==e.id&&s.version==e.version}function b(s){return`${s.pkg}:${s.id}`}function L(s){return{name:b(s),version:s.version}}function Pe(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 pe(s){return`${s.pkg}:${s.id}:${s.version}`}class Ee{constructor(e,t,r){c(this,"data");c(this,"content");this.compileMode=e,this.fullName=t;let{data:n,content:o}=r;if(n===void 0&&o===void 0)throw new Error("Neither data nor content is provided for template constructor");if(n!==void 0&&o!==void 0)throw new Error("Both data and content are provided for template constructor");n===void 0&&(n=le.parseTemplate(o)),o===void 0&&(o=le.serializeTemplate(n));const i=Pe(n);if(i.pkg!==t.pkg||i.id!==t.id||i.version!==t.version)throw new Error(`Compiled template name don't match it's package and file names: ${pe(i)} != ${pe(t)}`);this.data=n,this.content=o}toJSON(){return{compileMode:this.compileMode,fullName:this.fullName,data:this.data}}}class $e{constructor(e){c(this,"map",new Map);this.nameExtractor=e}add(e,t=!0){const r=de(this.nameExtractor(e)),n=this.map.get(r);return n&&!t||this.map.set(r,e),n}get(e){return this.map.get(de(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 Je(){return new $e(s=>s)}class I{constructor(e){c(this,"dist");this.dist=new $e(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,n)=>t(this.get(e,n)??r,n))}}function _e(s,e){for(const t of s)switch(t.name){case"hash_override":{e.hashOverride=qe(t.args);break}}}function Ge(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 qe(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(!Ie(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 Ue{constructor(e){c(this,"libs",new I(e=>e.fullName));c(this,"software",new I(e=>e.fullName));c(this,"assets",new I(e=>e.fullName));c(this,"templates",new I(e=>e.fullName));this.compileMode=e}populateTemplateDataFromDependencies(e,t,r,n){for(const o of r)switch(o.type){case"library":{const i=this.getLibOrError(o),a=n.indexOf(b(o));if(a>=0){const p=`library import recursion detected: ${n.slice(a).join(" -> ")} -> ${b(o)}`;throw new Error(p)}const l={...L(i.fullName),src:i.src};Ge(i.compilerOptions),t.libs[b(o)]=l,this.populateTemplateDataFromDependencies(e,t,i.dependencies,[...n,b(o)]);break}case"software":{const i=this.getSoftwareOrError(o);t.software[b(o)]={...L(i.fullName),src:i.src};break}case"asset":{const i=this.getAssetOrError(o);t.software[b(o)]={...L(i.fullName),src:i.src};break}case"template":{if(fe(e,o))continue;const i=this.getTemplateOrError(o);t.templates[b(o)]=i.data;break}case"test":throw new Error(`dependencies tree error: tests should never be part of template: ${h(o)} is dependency of ${b(e)}`);default:x(o.type)}}compileAndAddTemplate(e){if(e.fullName.type!=="template")throw new Error("unexpected source type");const t={type:"pl.tengo-template.v2",...L(e.fullName),templates:{},libs:{},software:{},assets:{},src:e.src};_e(e.compilerOptions,t),this.populateTemplateDataFromDependencies(e.fullName,t,e.dependencies,[]);const r=new Ee(e.compileMode,e.fullName,{data:t});return this.addTemplate(r),r}addLib(e){const t=this.libs.add(e.compileMode,e,!1);if(t&&!C(e.fullName,t.fullName))throw new Error(`compiler already contain such library: adding = ${g(e.fullName)}, contains = ${g(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: ${b(e)}`);return t}addSoftware(e){const t=this.software.add(e.compileMode,e,!1);if(t&&!C(e.fullName,t.fullName))throw new Error(`compiler already contain info for software: adding = ${g(e.fullName)}, contains = ${g(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: ${b(e)}`);return t}addAsset(e){const t=this.assets.add(e.compileMode,e,!1);if(t&&!C(e.fullName,t.fullName))throw new Error(`compiler already contain info for asset: adding = ${g(e.fullName)}, contains = ${g(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: ${b(e)}`);return t}addTemplate(e){const t=this.templates.add(e.compileMode,e,!1);if(t&&!C(e.fullName,t.fullName))throw new Error(`compiler already contain such template: adding = ${g(e.fullName)}, contains = ${g(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: ${b(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)}}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 ${g(e.fullName)}`);if(!this.getArtefact(t))throw new Error(`unresolved dependency ${h(t)} for ${g(e.fullName)}`)}})}compileAndAdd(e){const t={templates:[],libs:[],software:[],assets:[]};let r=[];for(const n of e)n.fullName.type==="library"?(this.addLib(n),t.libs.push(n)):n.fullName.type==="software"?(this.addSoftware(n),t.software.push(n)):n.fullName.type==="asset"?(this.addAsset(n),t.assets.push(n)):r.push(n);for(;r.length>0;){const n=[];for(const o of r){const i=o.dependencies.filter(a=>!this.getArtefact(a)&&!(o.fullName.type==="template"&&fe(o.fullName,a)));if(i.length>0){let a=`Unsatisfied dependencies in ${g(o.fullName)}:
3
+ `;for(const l of i)a+=` - ${h(l)}
4
+ `;n.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);t.templates.push(a)}catch(a){const l=a;let p=`Unsatisfied dependencies in ${g(o.fullName)}:
5
+ `;p+=` - ${l.message}
6
+ `,n.push({src:o,err:Error(p)})}break;case"test":break;default:x(o.fullName.type)}}if(r.length===n.length){let o="";for(const i of n)o+=`
7
+ ${i.err.message}`;throw new Error(o)}r=n.map(({src:o})=>o)}return t}}const ue="[_a-zA-Z][_a-zA-Z0-9]*",R=(s,e)=>new RegExp(`\\b${s}\\.(?<fnCall>(?<fnName>`+e+')\\s*\\(\\s*"(?<templateName>[^"]+)"\\s*\\))'),We=s=>R(s,"getTemplateId"),ze=s=>R(s,"getSoftwareInfo"),me=s=>R(s,"importTemplate"),ge=s=>R(s,"importSoftware"),Be=s=>R(s,"importAsset"),He=/^\s*$/,Ke=/^\/\/tengo:[\w]/,Ve=/^\s*\/\/\s*tengo:\s*./,Xe=/\/\*.*?\*\//g,Ze=/^\s*(\/\/)/,Ye=/^\s*\/\*/,Qe=/\*\//,Ne=/\s*:=\s*import\s*\(\s*"(?<moduleName>[^"]+)"\s*\)/,et=new RegExp(`\\b(?<importName>${ue}(\\.${ue})*)${Ne.source}`),tt=/(?<pkgName>[^"]+)?:(?<depID>[^"]+)/,st=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 re{constructor(e,t,r,n,o,i){this.compileMode=e,this.fullName=t,this.src=r,this.srcName=n,this.dependencies=o,this.compilerOptions=i}}function ke(s,e,t,r,n){const o=be.readFileSync(t).toString(),{deps:i,normalized:a,opts:l}=ot(s,o,r,n);return new re(e,r,a,t,i.array,l)}function ot(s,e,t,r){const n=Je(),o=[],i=e.split(`
8
+ `),a=[];let l={isInCommentBlock:!1,canDetectOptions:!0,tplDepREs:new Map,lineNo:0};for(const p of i){l.lineNo++;try{const d=rt(s,p,l,t.pkg,r);a.push(d.line),l=d.context,d.artifact&&n.add(d.artifact),d.option&&o.push(d.option)}catch(d){const u=d;throw new Error(`[line ${l.lineNo} in ${g(t)}]: ${u.message}
9
+ ${p}`,{cause:u})}}return{normalized:a.join(`
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&&lt(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; };
10
11
  `;o+=`declare type TplName = ${n.templates.map(d=>'"'+d.fullName.id+'"').join(" | ")};
11
12
  `,o+=`declare const Templates: Record<TplName, TemplateFromFile>;
12
13
  `,o+=`export { Templates };
13
14
  `;let i=`module.exports = { Templates: {
14
15
  `,a=`import { resolve } from 'node:path';
15
16
  export const Templates = {
16
- `;const c=n.templates.map(d=>` '${d.fullName.id}': { type: 'from-file', path: require.resolve('./tengo/tpl/${d.fullName.id}.plj.gz') }`).join(`,
17
- `),u=n.templates.map(d=>` '${d.fullName.id}': { type: 'from-file', path: resolve(import.meta.dirname, './tengo/tpl/${d.fullName.id}.plj.gz') }`).join(`,
18
- `);i+=c,a+=u,i+=`
17
+ `;const l=n.templates.map(d=>` '${d.fullName.id}': { type: 'from-file', path: require.resolve('./tengo/tpl/${d.fullName.id}.plj.gz') }`).join(`,
18
+ `),p=n.templates.map(d=>` '${d.fullName.id}': { type: 'from-file', path: resolve(import.meta.dirname, './tengo/tpl/${d.fullName.id}.plj.gz') }`).join(`,
19
+ `);i+=l,a+=p,i+=`
19
20
  }};
20
21
  `,a+=`
21
22
  };
22
- `,await O.writeFile("dist/index.d.ts",o),r.type==="module"?(await O.writeFile("dist/index.cjs",i),await O.writeFile("dist/index.js",a)):(await O.writeFile("dist/index.js",i),await O.writeFile("dist/index.mjs",a)),ht(e),e["generate-tags"]&&wt(t,e),t.info("Template Pack build done.")}};l(A,"description","build tengo sources into single distributable pack file"),l(A,"examples",["<%= config.bin %> <%= command.id %>"]),l(A,"flags",{...ne,...gt});let Z=A;function ht(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 wt(s,e){var a;const t=f.resolve(e["tags-file"]),r=f.dirname(t),n=e["tags-additional-args"],o=yt(r);s.info(`Generating tags for tengo autocompletion from "${r}" in "${t}", additional arguments: "${n.join('" "')}".
23
+ `,await F.writeFile("dist/index.d.ts",o),r.type==="module"?(await F.writeFile("dist/index.cjs",i),await F.writeFile("dist/index.js",a)):(await F.writeFile("dist/index.js",i),await F.writeFile("dist/index.mjs",a)),gt(e),e["generate-tags"]&&ht(t,e),t.info("Template Pack build done.")}};c(A,"description","build tengo sources into single distributable pack file"),c(A,"examples",["<%= config.bin %> <%= command.id %>"]),c(A,"flags",{...ie,...mt});let V=A;function gt(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 ht(s,e){var a;const t=f.resolve(e["tags-file"]),r=f.dirname(t),n=e["tags-additional-args"],o=wt(r);s.info(`Generating tags for tengo autocompletion from "${r}" in "${t}", additional arguments: "${n.join('" "')}".
23
24
  Found ${o.length} tengo files...`);const i=ye.spawnSync("ctags",["-f",t,...n,"--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=i.error)!=null&&a.message.includes("ENOENT")){console.log(`
24
25
  pl-tengo can create tags for tengo autocompletion,
25
26
  but the program should be installed
@@ -27,17 +28,17 @@ with "brew install universal-ctags" on OSX
27
28
  or "sudo apt install universal-ctags" on Ubuntu.
28
29
 
29
30
  For vscode, you should also install ctags extension:
30
- https://marketplace.visualstudio.com/items?itemName=jaydenlin.ctags-support`);return}bt(i,"failed to generate ctags"),s.info("Generation of tags is done.")}function yt(s){const e=p.readdirSync(s,{withFileTypes:!0,recursive:!0}),t=[];return e.forEach(r=>{if(!r.isDirectory()&&r.name.endsWith(".tengo")){const n=f.join(r.parentPath,r.name).replace(s,".");t.push(n)}}),t}function bt(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 ie(s,e){const t=M(),r=R(s,t,"dist","src",""),n=re(s,t,"dist");for(const o of n.allLibs())s.debug(`Dumping to pl-tester: ${g(o.fullName)}`),e.write(JSON.stringify(o)+`
31
- `);for(const o of r)o.fullName.type==="library"&&(s.debug(`Dumping to pl-tester: ${g(o.fullName)}`),e.write(JSON.stringify(o)+`
32
- `));for(const o of n.allTemplates())s.debug(`Dumping to pl-tester: ${g(o.fullName)}`),e.write(JSON.stringify(o)+`
33
- `);for(const o of r)o.fullName.type==="template"&&(s.debug(`Dumping to pl-tester: ${g(o.fullName)} ${o.srcName}`),e.write(JSON.stringify(o)+`
34
- `));for(const o of n.allSoftware())s.debug(`Dumping to pl-tester: ${g(o.fullName)}`),e.write(JSON.stringify(o)+`
35
- `);for(const o of r)o.fullName.type==="software"&&(s.debug(`Dumping to pl-tester: ${g(o.fullName)}`),e.write(JSON.stringify(o)+`
36
- `));for(const o of n.allAssets())s.debug(`Dumping to pl-tester: ${g(o.fullName)}`),e.write(JSON.stringify(o)+`
37
- `);for(const o of r)o.fullName.type==="asset"&&(s.debug(`Dumping to pl-tester: ${g(o.fullName)}`),e.write(JSON.stringify(o)+`
38
- `));for(const o of r)o.fullName.type==="test"&&(s.debug(`Dumping to pl-tester: ${g(o.fullName)} ${o.srcName}`),e.write(JSON.stringify(o)+`
39
- `))}function vt(s,e,t){const r=M(),n=R(s,r,"dist","src","");if(!e){for(const i of n)i.fullName.type==="library"&&t.write(JSON.stringify(i)+`
40
- `);return}const o=re(s,r,"dist");for(const i of n)i.fullName.type==="library"&&o.addLib(i);for(const i of o.allLibs())t.write(JSON.stringify(i)+`
41
- `)}function I(s,e,t){const r=M(),n=R(s,r,"dist","src","");for(const o of n)o.fullName.type===t&&e.write(JSON.stringify(o)+`
42
- `)}function Et(s,e){I(s,e,"template")}function $t(s,e){I(s,e,"software")}function Nt(s,e){I(s,e,"asset")}function St(s,e){I(s,e,"test")}function Oe(s,...e){const t=ye.spawn(s,e,{stdio:["pipe","inherit","inherit"]});return t.stdin.on("error",r=>{r.code}),t}function Fe(s){return new Promise((e,t)=>{s.on("close",r=>{e(r)}),s.on("error",r=>{t(r)})})}const S=class S extends h.Command{async run(){const{flags:e,argv:t}=await this.parse(S),r=N(e["log-level"]),n=t.length==0?["./src"]:t,o=Oe(ve.TengoTesterBinaryPath,"check","--log-level",e["log-level"],"--artifacts","-",...n);try{ie(r,o.stdin)}catch(i){r.error(i)}finally{o.stdin.end();const i=await Fe(o);process.exit(i)}}};l(S,"description","check tengo sources for language processor an"),l(S,"strict",!1),l(S,"flags",{...ne}),l(S,"examples",["<%= config.bin %> <%= command.id %>"]);let K=S;const k=class k extends h.Command{async run(){const{flags:e}=await this.parse(k),t=N(e["log-level"]),r=this.argv.length==0?["./src"]:this.argv,n=Oe(ve.TengoTesterBinaryPath,"run","--log-level",e["log-level"],"--artifacts","-",...r);try{ie(t,n.stdin)}catch(o){t.error(o)}finally{n.stdin.end();const o=await Fe(n);process.exit(o)}}};l(k,"description","run tengo unit tests (.test.tengo)"),l(k,"strict",!1),l(k,"flags",{...ne}),l(k,"examples",["<%= config.bin %> <%= command.id %>"]);let X=k;class Y extends h.Command{async run(){const e=N();ie(e,D.stdout)}}l(Y,"description","parse sources in current package and dump all found artifacts to stdout"),l(Y,"examples",["<%= config.bin %> <%= command.id %>"]);class H extends h.Command{async run(){const e=N();Nt(e,D.stdout)}}l(H,"description","parse sources in current package and dump all found assets to stdout"),l(H,"examples",["<%= config.bin %> <%= command.id %>"]);const T=class T extends h.Command{async run(){const{flags:e}=await this.parse(T),t=N();vt(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:h.Flags.boolean({name:"deps",description:"add also all libraries found in node_modules"})});let Q=T;class ee extends h.Command{async run(){const e=N();$t(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 h.Command{async run(){const e=N();Et(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 h.Command{async run(){const e=N();St(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 kt={build:Z,check:K,test:X,"dump:all":Y,"dump:assets":H,"dump:libs":Q,"dump:software":ee,"dump:templates":te,"dump:tests":se};exports.COMMANDS=kt;
31
+ https://marketplace.visualstudio.com/items?itemName=jaydenlin.ctags-support`);return}yt(i,"failed to generate ctags"),s.info("Generation of tags is done.")}function wt(s){const e=m.readdirSync(s,{withFileTypes:!0,recursive:!0}),t=[];return e.forEach(r=>{if(!r.isDirectory()&&r.name.endsWith(".tengo")){const n=f.join(r.parentPath,r.name).replace(s,".");t.push(n)}}),t}function yt(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=S(process.cwd(),s),r=j(s,t,"dist","src",""),n=ne(s,t,"dist");for(const o of n.allLibs())s.debug(`Dumping to pl-tester: ${h(o.fullName)}`),e.write(JSON.stringify(o)+`
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 n.allTemplates())s.debug(`Dumping to pl-tester: ${h(o.fullName)}`),e.write(JSON.stringify(o)+`
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 n.allSoftware())s.debug(`Dumping to pl-tester: ${h(o.fullName)}`),e.write(JSON.stringify(o)+`
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 n.allAssets())s.debug(`Dumping to pl-tester: ${h(o.fullName)}`),e.write(JSON.stringify(o)+`
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
+ `));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 bt(s,e,t){const r=S(process.cwd(),s),n=j(s,r,"dist","src","");if(!e){for(const i of n)i.fullName.type==="library"&&t.write(JSON.stringify(i)+`
41
+ `);return}const o=ne(s,r,"dist");for(const i of n)i.fullName.type==="library"&&o.addLib(i);for(const i of o.allLibs())t.write(JSON.stringify(i)+`
42
+ `)}function J(s,e,t){const r=S(process.cwd(),s),n=j(s,r,"dist","src","");for(const o of n)o.fullName.type===t&&e.write(JSON.stringify(o)+`
43
+ `)}function vt(s,e){J(s,e,"template")}function Et(s,e){J(s,e,"software")}function $t(s,e){J(s,e,"asset")}function Nt(s,e){J(s,e,"test")}function Fe(s,...e){const t=ye.spawn(s,e,{stdio:["pipe","inherit","inherit"]});return t.stdin.on("error",r=>{r.code}),t}function xe(s){return new Promise((e,t)=>{s.on("close",r=>{e(r)}),s.on("error",r=>{t(r)})})}const $=class $ extends y.Command{async run(){const{flags:e,argv:t}=await this.parse($),r=E(e["log-level"]),n=t.length==0?["./src"]:t,o=Fe(ve.TengoTesterBinaryPath,"check","--log-level",e["log-level"],"--artifacts","-",...n);try{ae(r,o.stdin)}catch(i){r.error(i)}finally{o.stdin.end();const i=await xe(o);process.exit(i)}}};c($,"description","check tengo sources for language processor an"),c($,"strict",!1),c($,"flags",{...ie}),c($,"examples",["<%= config.bin %> <%= command.id %>"]);let X=$;const N=class N extends y.Command{async run(){const{flags:e}=await this.parse(N),t=E(e["log-level"]),r=this.argv.length==0?["./src"]:this.argv,n=Fe(ve.TengoTesterBinaryPath,"run","--log-level",e["log-level"],"--artifacts","-",...r);try{ae(t,n.stdin)}catch(o){t.error(o)}finally{n.stdin.end();const o=await xe(n);process.exit(o)}}};c(N,"description","run tengo unit tests (.test.tengo)"),c(N,"strict",!1),c(N,"flags",{...ie}),c(N,"examples",["<%= config.bin %> <%= command.id %>"]);let Z=N;class Y extends y.Command{async run(){const e=E();ae(e,D.stdout)}}c(Y,"description","parse sources in current package and dump all found artifacts to stdout"),c(Y,"examples",["<%= config.bin %> <%= command.id %>"]);class Q extends y.Command{async run(){const e=E();$t(e,D.stdout)}}c(Q,"description","parse sources in current package and dump all found assets to stdout"),c(Q,"examples",["<%= config.bin %> <%= command.id %>"]);const T=class T extends y.Command{async run(){const{flags:e}=await this.parse(T),t=E();bt(t,e.deps,D.stdout)}};c(T,"description","parse sources in current package and dump all found libs to stdout"),c(T,"examples",["<%= config.bin %> <%= command.id %>"]),c(T,"flags",{deps:y.Flags.boolean({name:"deps",description:"add also all libraries found in node_modules"})});let ee=T;class te extends y.Command{async run(){const e=E();Et(e,D.stdout)}}c(te,"description","parse sources in current package and dump all found software to stdout"),c(te,"examples",["<%= config.bin %> <%= command.id %>"]);class se extends y.Command{async run(){const e=E();vt(e,D.stdout)}}c(se,"description","parse sources in current package and dump all found templates to stdout"),c(se,"examples",["<%= config.bin %> <%= command.id %>"]);class oe extends y.Command{async run(){const e=E();Nt(e,D.stdout)}}c(oe,"description","parse sources in current package and dump all found tests to stdout"),c(oe,"examples",["<%= config.bin %> <%= command.id %>"]);const kt={build:V,check:X,test:Z,"dump:all":Y,"dump:assets":Q,"dump:libs":ee,"dump:software":te,"dump:templates":se,"dump:tests":oe};exports.COMMANDS=kt;
43
44
  //# sourceMappingURL=index.js.map