@platforma-sdk/tengo-builder 1.15.0 → 1.16.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.
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/compiler/main.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAEL,WAAW,EAIZ,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,cAAc,EAAmB,MAAM,UAAU,CAAC;AAE3D,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAgBD,wBAAgB,YAAY,CAAC,KAAK,GAAE,MAAgB,GAAG,OAAO,CAAC,MAAM,CAapE;AAED,wBAAgB,cAAc,IAAI,WAAW,CAG5C;AAwLD,wBAAgB,YAAY,CAC1B,MAAM,EAAE,OAAO,CAAC,MAAM,EACtB,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,WAAW,EACjB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACb,cAAc,EAAE,CAwClB;AAED,wBAAgB,WAAW,CACzB,MAAM,EAAE,OAAO,CAAC,MAAM,EACtB,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,WAAW,GAChB,qBAAqB,CAOvB;AA0CD,wBAAgB,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,gBAAgB,CAsBnF;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,QA4C9F"}
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/compiler/main.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAEL,WAAW,EAIZ,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,cAAc,EAAmB,MAAM,UAAU,CAAC;AAE3D,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAkBD,wBAAgB,YAAY,CAAC,KAAK,GAAE,MAAgB,GAAG,OAAO,CAAC,MAAM,CAapE;AAED,wBAAgB,cAAc,IAAI,WAAW,CAG5C;AAwLD,wBAAgB,YAAY,CAC1B,MAAM,EAAE,OAAO,CAAC,MAAM,EACtB,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,WAAW,EACjB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACb,cAAc,EAAE,CAwClB;AAED,wBAAgB,WAAW,CACzB,MAAM,EAAE,OAAO,CAAC,MAAM,EACtB,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,WAAW,GAChB,qBAAqB,CAOvB;AAkDD,wBAAgB,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,gBAAgB,CAsBnF;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,QA4C9F"}
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
- "use strict";var xe=Object.defineProperty;var Oe=(t,e,r)=>e in t?xe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var l=(t,e,r)=>Oe(t,typeof e!="symbol"?e+"":e,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const he=require("node:child_process"),h=require("@oclif/core"),Me=require("node:path"),we=require("node:fs"),ae=require("node:zlib"),je=require("canonicalize"),G=require("winston"),Re=require("node:fs/promises"),ye=require("@milaboratories/tengo-tester"),D=require("node:process");function ee(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const o=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,o.get?o:{enumerable:!0,get:()=>t[r]})}}return e.default=t,Object.freeze(e)}const d=ee(Me),p=ee(we),x=ee(Re);function O(t){throw new Error("Unexpected object: "+t)}function Le(){let t=process.cwd();for(;t;){const e=d.join(t,"node_modules");if(p.existsSync(e))return e;const r=d.resolve(t,"..");if(r===t)break;t=r}throw new Error("Unable to find node_modules directory.")}function v(t){try{const e=p.statSync(t);return e.isDirectory()?"dir":e.isFile()?"file":e.isSymbolicLink()?"link":"unknown"}catch(e){if(e.code=="ENOENT")return"absent";throw e}}function le(t){return`${t.type}||${t.pkg}||${t.id}`}function m(t){return`${t.type}:${t.pkg}:${t.id}:${t.version}`}function g(t){return`${t.type}:${t.pkg}:${t.id}`}function ce(t,e){return t.type==e.type&&t.pkg==e.pkg&&t.id==e.id}function w(t){return`${t.pkg}:${t.id}`}function L(t){return{name:w(t),version:t.version}}function Ce(t){const e=t.name.match(/^(?<pkg>[^:]*):(?<id>[^:]*)$/);if(!e)throw new Error(`malformed artifact name: ${t.name}`);return{pkg:e.groups.pkg,id:e.groups.id,version:t.version}}function de(t){return`${t.pkg}:${t.id}:${t.version}`}const Ie=new TextDecoder,Ge=new TextEncoder;class be{constructor(e,r,o){l(this,"data");l(this,"content");this.compileMode=e,this.fullName=r;let{data:n,content:s}=o;if(n===void 0&&s===void 0)throw new Error("Neither data nor content is provided for template constructor");if(n!==void 0&&s!==void 0)throw new Error("Both data and content are provided for template constructor");if(n===void 0&&(n=JSON.parse(Ie.decode(ae.gunzipSync(s))),n.type!=="pl.tengo-template.v2"))throw new Error("malformed template");s===void 0&&(s=ae.gzipSync(Ge.encode(je(n))));const i=Ce(n);if(i.pkg!==r.pkg||i.id!==r.id||i.version!==r.version)throw new Error(`Compiled template name don't match it's package and file names: ${de(i)} != ${de(r)}`);this.data=n,this.content=s}toJSON(){return{compileMode:this.compileMode,fullName:this.fullName,data:this.data}}}class z{constructor(e){l(this,"map",new Map);this.nameExtractor=e}add(e,r=!0){const o=le(this.nameExtractor(e)),n=this.map.get(o);return n&&!r||this.map.set(o,e),n}get(e){return this.map.get(le(e))}get array(){const e=[];return this.map.forEach(r=>e.push(r)),e}forEach(e){this.map.forEach(r=>e(r,this.nameExtractor(r)))}}function ze(){return new z(t=>t)}class C{constructor(e){l(this,"dev");l(this,"dist");this.nameExtractor=e,this.dev=new z(e),this.dist=new z(e)}add(e,r,o=!0){switch(e){case"dist":return this.dist.add(r,o);default:O(e)}}get(e,r){switch(e){case"dist":return this.dist.get(r);default:O(e)}}array(e){const r=[];return this.forEach(e,o=>r.push(o)),r}forEach(e,r){this.dist.forEach((o,n)=>r(this.get(e,n)??o,n))}}class Pe{constructor(e){l(this,"libs",new C(e=>e.fullName));l(this,"software",new C(e=>e.fullName));l(this,"assets",new C(e=>e.fullName));l(this,"templates",new C(e=>e.fullName));this.compileMode=e}populateTemplateDataFromDependencies(e,r,o,n){for(const s of o)switch(s.type){case"library":const i=this.getLibOrError(s),a=n.indexOf(w(s));if(a>=0){let b=`library import recursion detected: ${n.slice(a).join(" -> ")} -> ${w(s)}`;throw new Error(b)}r.libs[w(s)]={...L(i.fullName),src:i.src},this.populateTemplateDataFromDependencies(e,r,i.dependencies,[...n,w(s)]);break;case"software":const c=this.getSoftwareOrError(s);r.software[w(s)]={...L(c.fullName),src:c.src};break;case"asset":const f=this.getAssetOrError(s);r.software[w(s)]={...L(f.fullName),src:f.src};break;case"template":if(ce(e,s))continue;const u=this.getTemplateOrError(s);r.templates[w(s)]=u.data;break;case"test":throw new Error(`dependencies tree error: tests should never be part of template: ${g(s)} is dependency of ${w(e)}`);default:O(s.type)}}compileAndAddTemplate(e){if(e.fullName.type!=="template")throw new Error("unexpected source type");const r={type:"pl.tengo-template.v2",...L(e.fullName),templates:{},libs:{},software:{},assets:{},src:e.src};this.populateTemplateDataFromDependencies(e.fullName,r,e.dependencies,[]);const o=new be(e.compileMode,e.fullName,{data:r});return this.addTemplate(o),o}addLib(e){const r=this.libs.add(e.compileMode,e,!1);if(r)throw new Error(`compiler already contain such library: adding = ${m(e.fullName)}, contains = ${m(r.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 r=this.getLib(e);if(!r)throw new Error(`library not found: ${w(e)}`);return r}addSoftware(e){const r=this.software.add(e.compileMode,e,!1);if(r)throw new Error(`compiler already contain info for software: adding = ${m(e.fullName)}, contains = ${m(r.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 r=this.getSoftware(e);if(!r)throw new Error(`software info not found: ${w(e)}`);return r}addAsset(e){const r=this.assets.add(e.compileMode,e,!1);if(r)throw new Error(`compiler already contain info for asset: adding = ${m(e.fullName)}, contains = ${m(r.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 r=this.getAsset(e);if(!r)throw new Error(`asset info not found: ${w(e)}`);return r}addTemplate(e){const r=this.templates.add(e.compileMode,e,!1);if(r)throw new Error(`compiler already contain such template: adding = ${m(e.fullName)}, contains = ${m(r.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 r=this.getTemplate(e);if(!r)throw new Error(`template not found: ${w(e)}`);return r}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:O(e.type)}}checkLibs(){this.libs.forEach(this.compileMode,e=>{for(const r of e.dependencies){if(r.type==="test")throw new Error(`test should never be dependency of production code: ${g(r)} test is dependency of ${m(e.fullName)}`);if(!this.getArtefact(r))throw new Error(`unresolved dependency ${g(r)} for ${m(e.fullName)}`)}})}compileAndAdd(e){const r={templates:[],libs:[],software:[],assets:[]};let o=[];for(const n of e)n.fullName.type==="library"?(this.addLib(n),r.libs.push(n)):n.fullName.type==="software"?(this.addSoftware(n),r.software.push(n)):n.fullName.type==="asset"?(this.addAsset(n),r.assets.push(n)):o.push(n);for(;o.length>0;){const n=[];for(const s of o){const i=s.dependencies.filter(a=>!this.getArtefact(a)&&!(s.fullName.type==="template"&&ce(s.fullName,a)));if(i.length>0){let a=`Unsatisfied dependencies in ${m(s.fullName)}:
1
+ "use strict";var Me=Object.defineProperty;var je=(t,e,r)=>e in t?Me(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var l=(t,e,r)=>je(t,typeof e!="symbol"?e+"":e,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ye=require("node:child_process"),h=require("@oclif/core"),Re=require("node:path"),be=require("node:fs"),ce=require("node:zlib"),Le=require("canonicalize"),I=require("winston"),Ce=require("node:fs/promises"),$e=require("@milaboratories/tengo-tester"),T=require("node:process");function se(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const o=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,o.get?o:{enumerable:!0,get:()=>t[r]})}}return e.default=t,Object.freeze(e)}const d=se(Re),p=se(be),F=se(Ce);function x(t){throw new Error("Unexpected object: "+t)}function Ie(){let t=process.cwd();for(;t;){const e=d.join(t,"node_modules");if(p.existsSync(e))return e;const r=d.resolve(t,"..");if(r===t)break;t=r}throw new Error("Unable to find node_modules directory.")}function v(t){try{const e=p.statSync(t);return e.isDirectory()?"dir":e.isFile()?"file":e.isSymbolicLink()?"link":"unknown"}catch(e){if(e.code=="ENOENT")return"absent";throw e}}function de(t){return`${t.type}||${t.pkg}||${t.id}`}function m(t){return`${t.type}:${t.pkg}:${t.id}:${t.version}`}function g(t){return`${t.type}:${t.pkg}:${t.id}`}function fe(t,e){return t.type==e.type&&t.pkg==e.pkg&&t.id==e.id}function w(t){return`${t.pkg}:${t.id}`}function R(t){return{name:w(t),version:t.version}}function Ge(t){const e=t.name.match(/^(?<pkg>[^:]*):(?<id>[^:]*)$/);if(!e)throw new Error(`malformed artifact name: ${t.name}`);return{pkg:e.groups.pkg,id:e.groups.id,version:t.version}}function pe(t){return`${t.pkg}:${t.id}:${t.version}`}const ze=new TextDecoder,Pe=new TextEncoder;class ve{constructor(e,r,o){l(this,"data");l(this,"content");this.compileMode=e,this.fullName=r;let{data:n,content:s}=o;if(n===void 0&&s===void 0)throw new Error("Neither data nor content is provided for template constructor");if(n!==void 0&&s!==void 0)throw new Error("Both data and content are provided for template constructor");if(n===void 0&&(n=JSON.parse(ze.decode(ce.gunzipSync(s))),n.type!=="pl.tengo-template.v2"))throw new Error("malformed template");s===void 0&&(s=ce.gzipSync(Pe.encode(Le(n))));const i=Ge(n);if(i.pkg!==r.pkg||i.id!==r.id||i.version!==r.version)throw new Error(`Compiled template name don't match it's package and file names: ${pe(i)} != ${pe(r)}`);this.data=n,this.content=s}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,r=!0){const o=de(this.nameExtractor(e)),n=this.map.get(o);return n&&!r||this.map.set(o,e),n}get(e){return this.map.get(de(e))}get array(){const e=[];return this.map.forEach(r=>e.push(r)),e}forEach(e){this.map.forEach(r=>e(r,this.nameExtractor(r)))}}function Je(){return new G(t=>t)}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,r,o=!0){switch(e){case"dist":return this.dist.add(r,o);default:x(e)}}get(e,r){switch(e){case"dist":return this.dist.get(r);default:x(e)}}array(e){const r=[];return this.forEach(e,o=>r.push(o)),r}forEach(e,r){this.dist.forEach((o,n)=>r(this.get(e,n)??o,n))}}class qe{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,r,o,n){for(const s of o)switch(s.type){case"library":const i=this.getLibOrError(s),a=n.indexOf(w(s));if(a>=0){let b=`library import recursion detected: ${n.slice(a).join(" -> ")} -> ${w(s)}`;throw new Error(b)}r.libs[w(s)]={...R(i.fullName),src:i.src},this.populateTemplateDataFromDependencies(e,r,i.dependencies,[...n,w(s)]);break;case"software":const c=this.getSoftwareOrError(s);r.software[w(s)]={...R(c.fullName),src:c.src};break;case"asset":const f=this.getAssetOrError(s);r.software[w(s)]={...R(f.fullName),src:f.src};break;case"template":if(fe(e,s))continue;const u=this.getTemplateOrError(s);r.templates[w(s)]=u.data;break;case"test":throw new Error(`dependencies tree error: tests should never be part of template: ${g(s)} is dependency of ${w(e)}`);default:x(s.type)}}compileAndAddTemplate(e){if(e.fullName.type!=="template")throw new Error("unexpected source type");const r={type:"pl.tengo-template.v2",...R(e.fullName),templates:{},libs:{},software:{},assets:{},src:e.src};this.populateTemplateDataFromDependencies(e.fullName,r,e.dependencies,[]);const o=new ve(e.compileMode,e.fullName,{data:r});return this.addTemplate(o),o}addLib(e){const r=this.libs.add(e.compileMode,e,!1);if(r)throw new Error(`compiler already contain such library: adding = ${m(e.fullName)}, contains = ${m(r.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 r=this.getLib(e);if(!r)throw new Error(`library not found: ${w(e)}`);return r}addSoftware(e){const r=this.software.add(e.compileMode,e,!1);if(r)throw new Error(`compiler already contain info for software: adding = ${m(e.fullName)}, contains = ${m(r.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 r=this.getSoftware(e);if(!r)throw new Error(`software info not found: ${w(e)}`);return r}addAsset(e){const r=this.assets.add(e.compileMode,e,!1);if(r)throw new Error(`compiler already contain info for asset: adding = ${m(e.fullName)}, contains = ${m(r.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 r=this.getAsset(e);if(!r)throw new Error(`asset info not found: ${w(e)}`);return r}addTemplate(e){const r=this.templates.add(e.compileMode,e,!1);if(r)throw new Error(`compiler already contain such template: adding = ${m(e.fullName)}, contains = ${m(r.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 r=this.getTemplate(e);if(!r)throw new Error(`template not found: ${w(e)}`);return r}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 r of e.dependencies){if(r.type==="test")throw new Error(`test should never be dependency of production code: ${g(r)} test is dependency of ${m(e.fullName)}`);if(!this.getArtefact(r))throw new Error(`unresolved dependency ${g(r)} for ${m(e.fullName)}`)}})}compileAndAdd(e){const r={templates:[],libs:[],software:[],assets:[]};let o=[];for(const n of e)n.fullName.type==="library"?(this.addLib(n),r.libs.push(n)):n.fullName.type==="software"?(this.addSoftware(n),r.software.push(n)):n.fullName.type==="asset"?(this.addAsset(n),r.assets.push(n)):o.push(n);for(;o.length>0;){const n=[];for(const s of o){const i=s.dependencies.filter(a=>!this.getArtefact(a)&&!(s.fullName.type==="template"&&fe(s.fullName,a)));if(i.length>0){let a=`Unsatisfied dependencies in ${m(s.fullName)}:
2
2
  `;for(const c of i)a+=` - ${g(c)}
3
3
  `;n.push({src:s,err:Error(a)});continue}switch(s.fullName.type){case"library":this.addLib(s),r.libs.push(s);break;case"software":this.addSoftware(s),r.software.push(s);break;case"asset":this.addAsset(s),r.assets.push(s);break;case"template":try{const a=this.compileAndAddTemplate(s);r.templates.push(a)}catch(a){let c=`Unsatisfied dependencies in ${m(s.fullName)}:
4
4
  `;c+=` - ${a.message}
5
- `,n.push({src:s,err:Error(c)})}break;case"test":break;default:O(s.fullName.type)}}if(o.length===n.length){let s="";for(const i of n)s+=`
6
- ${i.err.message}`;throw new Error(s)}o=n.map(({src:s})=>s)}return r}}const fe="[_a-zA-Z][_a-zA-Z0-9]*",M=(t,e)=>new RegExp(`\\b${t}\\.(?<fnCall>(?<fnName>`+e+')\\s*\\(\\s*"(?<templateName>[^"]+)"\\s*\\))'),Je=t=>M(t,"getTemplateId"),qe=t=>M(t,"getSoftwareInfo"),pe=t=>M(t,"importTemplate"),ue=t=>M(t,"importSoftware"),We=t=>M(t,"importAsset"),_e=/^\s*(\/\/)|(\/\*.*\*\/)/,Ue=/^\s*\/\*/,Be=/\*\//,$e=/\s*:=\s*import\s*\(\s*"(?<moduleName>[^"]+)"\s*\)/,Ve=new RegExp(`\\b(?<importName>${fe}(\\.${fe})*)${$e.source}`),Ze=/(?<pkgName>[^"]+)?:(?<depID>[^"]+)/;class te{constructor(e,r,o,n,s){this.compileMode=e,this.fullName=r,this.src=o,this.srcName=n,this.dependencies=s}}function ve(t,e,r,o){const n=we.readFileSync(e).toString(),{deps:s,normalized:i}=Ke(n,r,o);return new te(t,r,i,e,s.array)}function Ke(t,e,r){const o=ze(),n=t.split(`
7
- `),s=[];let i={isInCommentBlock:!1,tplDepREs:new Map},a=0;for(const c of n){a++;try{const f=Xe(c,i,e.pkg,r);s.push(f.line),i=f.context,f.artifact&&o.add(f.artifact)}catch(f){throw new Error(`[line ${a}]: ${f.message}
5
+ `,n.push({src:s,err:Error(c)})}break;case"test":break;default:x(s.fullName.type)}}if(o.length===n.length){let s="";for(const i of n)s+=`
6
+ ${i.err.message}`;throw new Error(s)}o=n.map(({src:s})=>s)}return r}}const ue="[_a-zA-Z][_a-zA-Z0-9]*",O=(t,e)=>new RegExp(`\\b${t}\\.(?<fnCall>(?<fnName>`+e+')\\s*\\(\\s*"(?<templateName>[^"]+)"\\s*\\))'),We=t=>O(t,"getTemplateId"),_e=t=>O(t,"getSoftwareInfo"),me=t=>O(t,"importTemplate"),ge=t=>O(t,"importSoftware"),Ue=t=>O(t,"importAsset"),Be=/^\s*(\/\/)|(\/\*.*\*\/)/,Ve=/^\s*\/\*/,Ze=/\*\//,Ee=/\s*:=\s*import\s*\(\s*"(?<moduleName>[^"]+)"\s*\)/,Ke=new RegExp(`\\b(?<importName>${ue}(\\.${ue})*)${Ee.source}`),Xe=/(?<pkgName>[^"]+)?:(?<depID>[^"]+)/;class re{constructor(e,r,o,n,s){this.compileMode=e,this.fullName=r,this.src=o,this.srcName=n,this.dependencies=s}}function Ne(t,e,r,o){const n=be.readFileSync(e).toString(),{deps:s,normalized:i}=He(n,r,o);return new re(t,r,i,e,s.array)}function He(t,e,r){const o=Je(),n=t.split(`
7
+ `),s=[];let i={isInCommentBlock:!1,tplDepREs:new Map},a=0;for(const c of n){a++;try{const f=Qe(c,i,e.pkg,r);s.push(f.line),i=f.context,f.artifact&&o.add(f.artifact)}catch(f){throw new Error(`[line ${a}]: ${f.message}
8
8
  ${c}`)}}return{normalized:s.join(`
9
- `),deps:o}}function Xe(t,e,r,o){if(e.isInCommentBlock)return Be.exec(t)&&(e.isInCommentBlock=!1),{line:t,context:e,artifact:void 0};if(_e.exec(t))return{line:t,context:e,artifact:void 0};if(Ue.exec(t))return e.isInCommentBlock=!0,{line:t,context:e,artifact:void 0};const n=$e.exec(t);if(n){const s=He(t);if(s.module==="plapi")return e.tplDepREs.has(s.module)||e.tplDepREs.set(s.module,[["template",Je(s.alias)],["software",qe(s.alias)]]),{line:t,context:e,artifact:void 0};(s.module==="@milaboratory/tengo-sdk:ll"||s.module==="@platforma-sdk/workflow-tengo:ll"||(r==="@milaboratory/tengo-sdk"||r==="@platforma-sdk/workflow-tengo")&&s.module===":ll")&&(e.tplDepREs.has(s.module)||e.tplDepREs.set(s.module,[["template",pe(s.alias)],["software",ue(s.alias)]])),(s.module==="@milaboratory/tengo-sdk:assets"||s.module==="@platforma-sdk/workflow-tengo:assets"||(r==="@milaboratory/tengo-sdk"||r==="@platforma-sdk/workflow-tengo")&&s.module===":assets")&&(e.tplDepREs.has(s.module)||e.tplDepREs.set(s.module,[["template",pe(s.alias)],["software",ue(s.alias)],["asset",We(s.alias)]]));const i=me(s.module,"library",r);return i?(t=t.replace(n[0],` := import("${i.pkg}:${i.id}")`),{line:t,context:e,artifact:i}):{line:t,context:e,artifact:void 0}}if(e.tplDepREs.size>0)for(const[s,i]of e.tplDepREs)for(const[a,c]of i){const f=c.exec(t);if(!f||!f.groups)continue;const{fnCall:u,templateName:b,fnName:$}=f.groups;if(!u||!b||!$)throw Error("failed to parse template import statement");const y=me(b,a,r);if(!y)throw Error(`failed to parse artifact name in ${$} import statement`);return t=t.replace(u,`${$}("${y.pkg}:${y.id}")`),{line:t,context:e,artifact:y}}return{line:t,context:e,artifact:void 0}}function He(t){const e=Ve.exec(t);if(!e||!e.groups)throw Error("failed to parse 'import' statement");const{importName:r,moduleName:o}=e.groups;if(!r||!o)throw Error("failed to parse 'import' statement");return{module:o,alias:r}}function me(t,e,r){const o=Ze.exec(t);if(!o)return;if(!o.groups)throw Error("failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'");const{pkgName:n,depID:s}=o.groups;if(!s)throw Error("failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'");return{type:e,pkg:n??r,id:s}}const P=".plj.gz",J=".lib.tengo",T=".sw.json",ge=".test.tengo",q=".tpl.tengo",W=".lib.tengo",_=".sw.json",Qe=[W,q,_];function N(t="debug"){return G.createLogger({level:t,format:G.format.printf(({level:e,message:r})=>`${e.padStart(6," ")}: ${r}`),transports:[new G.transports.Console({stderrLevels:["error","warn","info","debug"],handleExceptions:!0})]})}function j(){return JSON.parse(p.readFileSync("package.json").toString())}function Ne(t,e){return d.resolve(e,t,"tengo","lib")}function Ee(t,e){return d.resolve(e,t,"tengo","tpl")}function Se(t,e){return d.resolve(e,t,"tengo","software")}function ke(t,e){return d.resolve(e,t,"tengo","asset")}function Ae(t,e,r,o,n=!1){const s=d.resolve(o,"package.json");if(v(s)!=="file"){for(const ne of p.readdirSync(o)){const Fe=v(d.join(o,ne))==="link",ie=d.resolve(o,ne);v(ie)==="dir"&&Ae(t,e,r,ie,Fe)}return}const i=Ne("dist",o),a=Ee("dist",o),c=Se("dist",o),f=ke("dist",o),u=v(i)==="dir",b=v(a)==="dir",$=v(c)==="dir",y=v(f)==="dir";if(!u&&!b&&!$&&!y)return;const F=JSON.parse(p.readFileSync(s).toString());if(F.name!==r.name){if(v(d.resolve(o,"node_modules"))==="dir"&&n)throw new Error(`nested node_modules is a sign of library dependencies version incompatibility in ${o}`);u&&Ye(t,F,"dist",i,e),b&&et(t,F,"dist",a,e),$&&tt(t,F,"dist",c,e),y&&st(t,F,"dist",f,e)}}function Ye(t,e,r,o,n){for(const s of p.readdirSync(o)){const i=d.resolve(o,s);if(!s.endsWith(J))throw new Error(`unexpected file in 'lib' folder: ${i}`);const a={type:"library",pkg:e.name,id:s.slice(0,s.length-J.length),version:e.version},c=ve(r,i,a,!0);if(n.addLib(c),t.debug(`Adding dependency ${m(a)} from ${i}`),c.dependencies.length>0){t.debug("Dependencies:");for(const f of c.dependencies)t.debug(` - ${g(f)}`)}}}function et(t,e,r,o,n){for(const s of p.readdirSync(o)){const i=d.resolve(o,s);if(!s.endsWith(P))throw new Error(`unexpected file in 'tpl' folder: ${i}`);const a={type:"template",pkg:e.name,id:s.slice(0,s.length-P.length),version:e.version},c=new be(r,a,{content:p.readFileSync(i)});n.addTemplate(c),t.debug(`Adding dependency ${m(a)} from ${i}`)}}function tt(t,e,r,o,n){for(const s of p.readdirSync(o)){const i=d.resolve(o,s);if(!s.endsWith(T))throw new Error(`unexpected file in 'software' folder: ${i}`);const a={type:"software",pkg:e.name,id:s.slice(0,s.length-T.length),version:e.version},c=new te(r,a,p.readFileSync(i).toString(),i,[]);t.debug(`Adding dependency ${m(a)} from ${i}`),n.addSoftware(c)}}function st(t,e,r,o,n){for(const s of p.readdirSync(o)){const i=d.resolve(o,s);if(!s.endsWith(T))throw new Error(`unexpected file in 'asset' folder: ${i}`);const a={type:"asset",pkg:e.name,id:s.slice(0,s.length-T.length),version:e.version},c=new te(r,a,p.readFileSync(i).toString(),i,[]);t.debug(`Adding dependency ${m(a)} from ${i}`),n.addAsset(c)}}function R(t,e,r,o,n){const s=[];for(const i of p.readdirSync(d.join(o,n))){const a=d.join(n,i),c=d.join(o,a);if(v(c)==="dir"){const y=R(t,e,r,o,a);s.push(...y);continue}const f=i==="index.lib.tengo"?`${d.basename(n)}.lib.tengo`:a,u=rt(e,f.replaceAll(d.sep,"."));if(!u)continue;const b=d.resolve(o,a);t.debug(`Parsing ${m(u)} from ${b}`);const $=ve(r,b,u,!0);if($.dependencies.length>0){t.debug("Detected dependencies:");for(const y of $.dependencies)t.debug(` - ${g(y)}`)}s.push($)}return s}function se(t,e,r){const o=new Pe(r);return Ae(t,o,e,Le()),o}function rt(t,e){const r={pkg:t.name,version:t.version};return e.endsWith(W)?{...r,id:e.substring(0,e.length-W.length),type:"library"}:e.endsWith(q)?{...r,id:e.substring(0,e.length-q.length),type:"template"}:e.endsWith(_)?{...r,id:e.substring(0,e.length-_.length),type:"software"}:e.endsWith(ge)?{...r,id:e.substring(0,e.length-ge.length),type:"test"}:null}function ot(t,e){const r=j(),o=se(t,r,e),n=R(t,r,e,"src","");if(n.length===0){const i=[];for(const a of Qe)i.push(`*${a}`);t.error(`Nothing to compile. Looked for ${i.join(", ")}`),process.exit(1)}t.info(`Compiling '${e}'...`);const s=o.compileAndAdd(n);return t.debug("Done."),s}function nt(t,e,r){if(e.libs.length>0){const o=Ne(r,".");p.mkdirSync(o,{recursive:!0});for(const n of e.libs){const s=d.resolve(o,n.fullName.id+J);t.info(` - writing ${s}`),p.writeFileSync(s,n.src)}}if(e.templates.length>0){const o=Ee(r,".");p.mkdirSync(o,{recursive:!0});for(const n of e.templates){const s=d.resolve(o,n.fullName.id+P);t.info(` - writing ${s}`),p.writeFileSync(s,n.content)}}if(e.software.length>0){const o=Se(r,".");p.mkdirSync(o,{recursive:!0});for(const n of e.software){const s=d.resolve(o,n.fullName.id+T);t.info(` - writing ${s}`),p.writeFileSync(s,n.src)}}if(e.assets.length>0){const o=ke(r,".");p.mkdirSync(o,{recursive:!0});for(const n of e.software){const s=d.resolve(o,n.fullName.id+T);t.info(` - writing ${s}`),p.writeFileSync(s,n.src)}}}const re={"log-level":h.Flags.string({description:"logging level",default:"info",options:["error","warn","info","debug"]})},it={"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:","})},k=class k extends h.Command{async run(){const{flags:e}=await this.parse(k),r=N(e["log-level"]),o=j(),n=ot(r,"dist");nt(r,n,"dist"),r.info("");let s=`declare type TemplateFromFile = { readonly type: "from-file"; readonly path: string; };
9
+ `),deps:o}}function Qe(t,e,r,o){if(e.isInCommentBlock)return Ze.exec(t)&&(e.isInCommentBlock=!1),{line:t,context:e,artifact:void 0};if(Be.exec(t))return{line:t,context:e,artifact:void 0};if(Ve.exec(t))return e.isInCommentBlock=!0,{line:t,context:e,artifact:void 0};const n=Ee.exec(t);if(n){const s=Ye(t);if(s.module==="plapi")return e.tplDepREs.has(s.module)||e.tplDepREs.set(s.module,[["template",We(s.alias)],["software",_e(s.alias)]]),{line:t,context:e,artifact:void 0};(s.module==="@milaboratory/tengo-sdk:ll"||s.module==="@platforma-sdk/workflow-tengo:ll"||(r==="@milaboratory/tengo-sdk"||r==="@platforma-sdk/workflow-tengo")&&s.module===":ll")&&(e.tplDepREs.has(s.module)||e.tplDepREs.set(s.module,[["template",me(s.alias)],["software",ge(s.alias)]])),(s.module==="@milaboratory/tengo-sdk:assets"||s.module==="@platforma-sdk/workflow-tengo:assets"||(r==="@milaboratory/tengo-sdk"||r==="@platforma-sdk/workflow-tengo")&&s.module===":assets")&&(e.tplDepREs.has(s.module)||e.tplDepREs.set(s.module,[["template",me(s.alias)],["software",ge(s.alias)],["asset",Ue(s.alias)]]));const i=he(s.module,"library",r);return i?(t=t.replace(n[0],` := import("${i.pkg}:${i.id}")`),{line:t,context:e,artifact:i}):{line:t,context:e,artifact:void 0}}if(e.tplDepREs.size>0)for(const[s,i]of e.tplDepREs)for(const[a,c]of i){const f=c.exec(t);if(!f||!f.groups)continue;const{fnCall:u,templateName:b,fnName:$}=f.groups;if(!u||!b||!$)throw Error("failed to parse template import statement");const y=he(b,a,r);if(!y)throw Error(`failed to parse artifact name in ${$} import statement`);return t=t.replace(u,`${$}("${y.pkg}:${y.id}")`),{line:t,context:e,artifact:y}}return{line:t,context:e,artifact:void 0}}function Ye(t){const e=Ke.exec(t);if(!e||!e.groups)throw Error("failed to parse 'import' statement");const{importName:r,moduleName:o}=e.groups;if(!r||!o)throw Error("failed to parse 'import' statement");return{module:o,alias:r}}function he(t,e,r){const o=Xe.exec(t);if(!o)return;if(!o.groups)throw Error("failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'");const{pkgName:n,depID:s}=o.groups;if(!s)throw Error("failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'");return{type:e,pkg:n??r,id:s}}const z=".plj.gz",P=".lib.tengo",J=".sw.json",q=".as.json",we=".test.tengo",W=".tpl.tengo",_=".lib.tengo",U=".sw.json",B=".as.json",et=[_,W,U,B];function E(t="debug"){return I.createLogger({level:t,format:I.format.printf(({level:e,message:r})=>`${e.padStart(6," ")}: ${r}`),transports:[new I.transports.Console({stderrLevels:["error","warn","info","debug"],handleExceptions:!0})]})}function M(){return JSON.parse(p.readFileSync("package.json").toString())}function Se(t,e){return d.resolve(e,t,"tengo","lib")}function ke(t,e){return d.resolve(e,t,"tengo","tpl")}function Ae(t,e){return d.resolve(e,t,"tengo","software")}function Te(t,e){return d.resolve(e,t,"tengo","asset")}function De(t,e,r,o,n=!1){const s=d.resolve(o,"package.json");if(v(s)!=="file"){for(const ae of p.readdirSync(o)){const Oe=v(d.join(o,ae))==="link",le=d.resolve(o,ae);v(le)==="dir"&&De(t,e,r,le,Oe)}return}const i=Se("dist",o),a=ke("dist",o),c=Ae("dist",o),f=Te("dist",o),u=v(i)==="dir",b=v(a)==="dir",$=v(c)==="dir",y=v(f)==="dir";if(!u&&!b&&!$&&!y)return;const D=JSON.parse(p.readFileSync(s).toString());if(D.name!==r.name){if(v(d.resolve(o,"node_modules"))==="dir"&&n)throw new Error(`nested node_modules is a sign of library dependencies version incompatibility in ${o}`);u&&tt(t,D,"dist",i,e),b&&st(t,D,"dist",a,e),$&&rt(t,D,"dist",c,e),y&&ot(t,D,"dist",f,e)}}function tt(t,e,r,o,n){for(const s of p.readdirSync(o)){const i=d.resolve(o,s);if(!s.endsWith(P))throw new Error(`unexpected file in 'lib' folder: ${i}`);const a={type:"library",pkg:e.name,id:s.slice(0,s.length-P.length),version:e.version},c=Ne(r,i,a,!0);if(n.addLib(c),t.debug(`Adding dependency ${m(a)} from ${i}`),c.dependencies.length>0){t.debug("Dependencies:");for(const f of c.dependencies)t.debug(` - ${g(f)}`)}}}function st(t,e,r,o,n){for(const s of p.readdirSync(o)){const i=d.resolve(o,s);if(!s.endsWith(z))throw new Error(`unexpected file in 'tpl' folder: ${i}`);const a={type:"template",pkg:e.name,id:s.slice(0,s.length-z.length),version:e.version},c=new ve(r,a,{content:p.readFileSync(i)});n.addTemplate(c),t.debug(`Adding dependency ${m(a)} from ${i}`)}}function rt(t,e,r,o,n){for(const s of p.readdirSync(o)){const i=d.resolve(o,s);if(!s.endsWith(J))throw new Error(`unexpected file in 'software' folder: ${i}`);const a={type:"software",pkg:e.name,id:s.slice(0,s.length-J.length),version:e.version},c=new re(r,a,p.readFileSync(i).toString(),i,[]);t.debug(`Adding dependency ${m(a)} from ${i}`),n.addSoftware(c)}}function ot(t,e,r,o,n){for(const s of p.readdirSync(o)){const i=d.resolve(o,s);if(!s.endsWith(q))throw new Error(`unexpected file in 'asset' folder: ${i}`);const a={type:"asset",pkg:e.name,id:s.slice(0,s.length-q.length),version:e.version},c=new re(r,a,p.readFileSync(i).toString(),i,[]);t.debug(`Adding dependency ${m(a)} from ${i}`),n.addAsset(c)}}function j(t,e,r,o,n){const s=[];for(const i of p.readdirSync(d.join(o,n))){const a=d.join(n,i),c=d.join(o,a);if(v(c)==="dir"){const y=j(t,e,r,o,a);s.push(...y);continue}const f=i==="index.lib.tengo"?`${d.basename(n)}.lib.tengo`:a,u=nt(e,f.replaceAll(d.sep,"."));if(!u)continue;const b=d.resolve(o,a);t.debug(`Parsing ${m(u)} from ${b}`);const $=Ne(r,b,u,!0);if($.dependencies.length>0){t.debug("Detected dependencies:");for(const y of $.dependencies)t.debug(` - ${g(y)}`)}s.push($)}return s}function oe(t,e,r){const o=new qe(r);return De(t,o,e,Ie()),o}function nt(t,e){const r={pkg:t.name,version:t.version};return e.endsWith(_)?{...r,id:e.substring(0,e.length-_.length),type:"library"}:e.endsWith(W)?{...r,id:e.substring(0,e.length-W.length),type:"template"}:e.endsWith(U)?{...r,id:e.substring(0,e.length-U.length),type:"software"}:e.endsWith(B)?{...r,id:e.substring(0,e.length-B.length),type:"asset"}:e.endsWith(we)?{...r,id:e.substring(0,e.length-we.length),type:"test"}:null}function it(t,e){const r=M(),o=oe(t,r,e),n=j(t,r,e,"src","");if(n.length===0){const i=[];for(const a of et)i.push(`*${a}`);t.error(`Nothing to compile. Looked for ${i.join(", ")}`),process.exit(1)}t.info(`Compiling '${e}'...`);const s=o.compileAndAdd(n);return t.debug("Done."),s}function at(t,e,r){if(e.libs.length>0){const o=Se(r,".");p.mkdirSync(o,{recursive:!0});for(const n of e.libs){const s=d.resolve(o,n.fullName.id+P);t.info(` - writing ${s}`),p.writeFileSync(s,n.src)}}if(e.templates.length>0){const o=ke(r,".");p.mkdirSync(o,{recursive:!0});for(const n of e.templates){const s=d.resolve(o,n.fullName.id+z);t.info(` - writing ${s}`),p.writeFileSync(s,n.content)}}if(e.software.length>0){const o=Ae(r,".");p.mkdirSync(o,{recursive:!0});for(const n of e.software){const s=d.resolve(o,n.fullName.id+J);t.info(` - writing ${s}`),p.writeFileSync(s,n.src)}}if(e.assets.length>0){const o=Te(r,".");p.mkdirSync(o,{recursive:!0});for(const n of e.software){const s=d.resolve(o,n.fullName.id+q);t.info(` - writing ${s}`),p.writeFileSync(s,n.src)}}}const ne={"log-level":h.Flags.string({description:"logging level",default:"info",options:["error","warn","info","debug"]})},lt={"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:","})},k=class k extends h.Command{async run(){const{flags:e}=await this.parse(k),r=E(e["log-level"]),o=M(),n=it(r,"dist");at(r,n,"dist"),r.info("");let s=`declare type TemplateFromFile = { readonly type: "from-file"; readonly path: string; };
10
10
  `;s+=`declare type TplName = ${n.templates.map(u=>'"'+u.fullName.id+'"').join(" | ")};
11
11
  `,s+=`declare const Templates: Record<TplName, TemplateFromFile>;
12
12
  `,s+=`export { Templates };
@@ -19,15 +19,15 @@ export const Templates = {
19
19
  }};
20
20
  `,a+=`
21
21
  };
22
- `,await x.writeFile("dist/index.d.ts",s),o.type==="module"?(await x.writeFile("dist/index.cjs",i),await x.writeFile("dist/index.js",a)):(await x.writeFile("dist/index.js",i),await x.writeFile("dist/index.mjs",a)),at(e),e["generate-tags"]&&lt(r,e),r.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",{...re,...it});let U=k;function at(t){process.env.GENERATE_TAGS!=null&&(t["generate-tags"]=process.env.GENERATE_TAGS=="true"),process.env.TAGS_FILE!=null&&(t["tags-file"]=process.env.TAGS_FILE),process.env.TAGS_ADDITIONAL_ARGS!=null&&(t["tags-additional-args"]=process.env.TAGS_ADDITIONAL_ARGS.split(","))}function lt(t,e){var a;const r=d.resolve(e["tags-file"]),o=d.dirname(r),n=e["tags-additional-args"],s=ct(o);t.info(`Generating tags for tengo autocompletion from "${o}" in "${r}", additional arguments: "${n}".
23
- Found ${s.length} tengo files...`);const i=he.spawnSync("ctags",["-f",r,...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",...s],{env:process.env,stdio:"inherit",cwd:o});if((a=i.error)!=null&&a.message.includes("ENOENT")){console.log(`
22
+ `,await F.writeFile("dist/index.d.ts",s),o.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)),ct(e),e["generate-tags"]&&dt(r,e),r.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",{...ne,...lt});let V=k;function ct(t){process.env.GENERATE_TAGS!=null&&(t["generate-tags"]=process.env.GENERATE_TAGS=="true"),process.env.TAGS_FILE!=null&&(t["tags-file"]=process.env.TAGS_FILE),process.env.TAGS_ADDITIONAL_ARGS!=null&&(t["tags-additional-args"]=process.env.TAGS_ADDITIONAL_ARGS.split(","))}function dt(t,e){var a;const r=d.resolve(e["tags-file"]),o=d.dirname(r),n=e["tags-additional-args"],s=ft(o);t.info(`Generating tags for tengo autocompletion from "${o}" in "${r}", additional arguments: "${n}".
23
+ Found ${s.length} tengo files...`);const i=ye.spawnSync("ctags",["-f",r,...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",...s],{env:process.env,stdio:"inherit",cwd:o});if((a=i.error)!=null&&a.message.includes("ENOENT")){console.log(`
24
24
  pl-tengo can create tags for tengo autocompletion,
25
25
  but the program should be installed
26
26
  with "brew install universal-ctags" on OSX
27
27
  or "sudo apt install universal-ctags" on Ubuntu.
28
28
 
29
29
  For vscode, you should also install ctags extension:
30
- https://marketplace.visualstudio.com/items?itemName=jaydenlin.ctags-support`);return}dt(i,"failed to generate ctags"),t.info("Generation of tags is done.")}function ct(t){const e=p.readdirSync(t,{withFileTypes:!0,recursive:!0}),r=[];return e.forEach(o=>{if(!o.isDirectory()&&o.name.endsWith(".tengo")){const n=d.join(o.parentPath,o.name).replace(t,".");r.push(n)}}),r}function dt(t,e){t.error&&console.log(t.error);const r=e;t.status!==0&&console.log(`WARN: ${r} the build will continue as-is`)}function oe(t,e){const r=j(),o=R(t,r,"dist","src",""),n=se(t,r,"dist");for(const s of n.allLibs())t.debug(`Dumping to pl-tester: ${g(s.fullName)}`),e.write(JSON.stringify(s)+`
30
+ https://marketplace.visualstudio.com/items?itemName=jaydenlin.ctags-support`);return}pt(i,"failed to generate ctags"),t.info("Generation of tags is done.")}function ft(t){const e=p.readdirSync(t,{withFileTypes:!0,recursive:!0}),r=[];return e.forEach(o=>{if(!o.isDirectory()&&o.name.endsWith(".tengo")){const n=d.join(o.parentPath,o.name).replace(t,".");r.push(n)}}),r}function pt(t,e){t.error&&console.log(t.error);const r=e;t.status!==0&&console.log(`WARN: ${r} the build will continue as-is`)}function ie(t,e){const r=M(),o=j(t,r,"dist","src",""),n=oe(t,r,"dist");for(const s of n.allLibs())t.debug(`Dumping to pl-tester: ${g(s.fullName)}`),e.write(JSON.stringify(s)+`
31
31
  `);for(const s of o)s.fullName.type==="library"&&(t.debug(`Dumping to pl-tester: ${g(s.fullName)}`),e.write(JSON.stringify(s)+`
32
32
  `));for(const s of n.allTemplates())t.debug(`Dumping to pl-tester: ${g(s.fullName)}`),e.write(JSON.stringify(s)+`
33
33
  `);for(const s of o)s.fullName.type==="template"&&(t.debug(`Dumping to pl-tester: ${g(s.fullName)} ${s.srcName}`),e.write(JSON.stringify(s)+`
@@ -36,8 +36,8 @@ https://marketplace.visualstudio.com/items?itemName=jaydenlin.ctags-support`);re
36
36
  `));for(const s of n.allAssets())t.debug(`Dumping to pl-tester: ${g(s.fullName)}`),e.write(JSON.stringify(s)+`
37
37
  `);for(const s of o)s.fullName.type==="asset"&&(t.debug(`Dumping to pl-tester: ${g(s.fullName)}`),e.write(JSON.stringify(s)+`
38
38
  `));for(const s of o)s.fullName.type==="test"&&(t.debug(`Dumping to pl-tester: ${g(s.fullName)} ${s.srcName}`),e.write(JSON.stringify(s)+`
39
- `))}function ft(t,e,r){const o=j(),n=R(t,o,"dist","src","");if(!e){for(const i of n)i.fullName.type==="library"&&r.write(JSON.stringify(i)+`
40
- `);return}const s=se(t,o,"dist");for(const i of n)i.fullName.type==="library"&&s.addLib(i);for(const i of s.allLibs())r.write(JSON.stringify(i)+`
41
- `)}function I(t,e,r){const o=j(),n=R(t,o,"dist","src","");for(const s of n)s.fullName.type===r&&e.write(JSON.stringify(s)+`
42
- `)}function pt(t,e){I(t,e,"template")}function ut(t,e){I(t,e,"software")}function mt(t,e){I(t,e,"asset")}function gt(t,e){I(t,e,"test")}function Te(t,...e){const r=he.spawn(t,e,{stdio:["pipe","inherit","inherit"]});return r.stdin.on("error",o=>{o.code}),r}function De(t){return new Promise((e,r)=>{t.on("close",o=>{e(o)}),t.on("error",o=>{r(o)})})}const E=class E extends h.Command{async run(){const{flags:e,argv:r}=await this.parse(E),o=N(e["log-level"]),n=r.length==0?["./src"]:r,s=Te(ye.TengoTesterBinaryPath,"check","--log-level",e["log-level"],"--artifacts","-",...n);try{oe(o,s.stdin)}catch(i){o.error(i)}finally{s.stdin.end();const i=await De(s);process.exit(i)}}};l(E,"description","check tengo sources for language processor an"),l(E,"strict",!1),l(E,"flags",{...re}),l(E,"examples",["<%= config.bin %> <%= command.id %>"]);let B=E;const S=class S extends h.Command{async run(){const{flags:e}=await this.parse(S),r=N(e["log-level"]),o=this.argv.length==0?["./src"]:this.argv,n=Te(ye.TengoTesterBinaryPath,"run","--log-level",e["log-level"],"--artifacts","-",...o);try{oe(r,n.stdin)}catch(s){r.error(s)}finally{n.stdin.end();const s=await De(n);process.exit(s)}}};l(S,"description","run tengo unit tests (.test.tengo)"),l(S,"strict",!1),l(S,"flags",{...re}),l(S,"examples",["<%= config.bin %> <%= command.id %>"]);let V=S;class Z extends h.Command{async run(){const e=N();oe(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 K extends h.Command{async run(){const e=N();mt(e,D.stdout)}}l(K,"description","parse sources in current package and dump all found tests to stdout"),l(K,"examples",["<%= config.bin %> <%= command.id %>"]);const A=class A extends h.Command{async run(){const{flags:e}=await this.parse(A),r=N();ft(r,e.deps,D.stdout)}};l(A,"description","parse sources in current package and dump all found templates to stdout"),l(A,"examples",["<%= config.bin %> <%= command.id %>"]),l(A,"flags",{deps:h.Flags.boolean({name:"deps",description:"add also all libraries found in node_modules"})});let X=A;class H extends h.Command{async run(){const e=N();ut(e,D.stdout)}}l(H,"description","parse sources in current package and dump all found tests to stdout"),l(H,"examples",["<%= config.bin %> <%= command.id %>"]);class Q extends h.Command{async run(){const e=N();pt(e,D.stdout)}}l(Q,"description","parse sources in current package and dump all found templates to stdout"),l(Q,"examples",["<%= config.bin %> <%= command.id %>"]);class Y extends h.Command{async run(){const e=N();gt(e,D.stdout)}}l(Y,"description","parse sources in current package and dump all found tests to stdout"),l(Y,"examples",["<%= config.bin %> <%= command.id %>"]);const ht={build:U,check:B,test:V,"dump:all":Z,"dump:assets":K,"dump:libs":X,"dump:software":H,"dump:templates":Q,"dump:tests":Y};exports.COMMANDS=ht;
39
+ `))}function ut(t,e,r){const o=M(),n=j(t,o,"dist","src","");if(!e){for(const i of n)i.fullName.type==="library"&&r.write(JSON.stringify(i)+`
40
+ `);return}const s=oe(t,o,"dist");for(const i of n)i.fullName.type==="library"&&s.addLib(i);for(const i of s.allLibs())r.write(JSON.stringify(i)+`
41
+ `)}function C(t,e,r){const o=M(),n=j(t,o,"dist","src","");for(const s of n)s.fullName.type===r&&e.write(JSON.stringify(s)+`
42
+ `)}function mt(t,e){C(t,e,"template")}function gt(t,e){C(t,e,"software")}function ht(t,e){C(t,e,"asset")}function wt(t,e){C(t,e,"test")}function Fe(t,...e){const r=ye.spawn(t,e,{stdio:["pipe","inherit","inherit"]});return r.stdin.on("error",o=>{o.code}),r}function xe(t){return new Promise((e,r)=>{t.on("close",o=>{e(o)}),t.on("error",o=>{r(o)})})}const N=class N extends h.Command{async run(){const{flags:e,argv:r}=await this.parse(N),o=E(e["log-level"]),n=r.length==0?["./src"]:r,s=Fe($e.TengoTesterBinaryPath,"check","--log-level",e["log-level"],"--artifacts","-",...n);try{ie(o,s.stdin)}catch(i){o.error(i)}finally{s.stdin.end();const i=await xe(s);process.exit(i)}}};l(N,"description","check tengo sources for language processor an"),l(N,"strict",!1),l(N,"flags",{...ne}),l(N,"examples",["<%= config.bin %> <%= command.id %>"]);let Z=N;const S=class S extends h.Command{async run(){const{flags:e}=await this.parse(S),r=E(e["log-level"]),o=this.argv.length==0?["./src"]:this.argv,n=Fe($e.TengoTesterBinaryPath,"run","--log-level",e["log-level"],"--artifacts","-",...o);try{ie(r,n.stdin)}catch(s){r.error(s)}finally{n.stdin.end();const s=await xe(n);process.exit(s)}}};l(S,"description","run tengo unit tests (.test.tengo)"),l(S,"strict",!1),l(S,"flags",{...ne}),l(S,"examples",["<%= config.bin %> <%= command.id %>"]);let K=S;class X extends h.Command{async run(){const e=E();ie(e,T.stdout)}}l(X,"description","parse sources in current package and dump all found artifacts to stdout"),l(X,"examples",["<%= config.bin %> <%= command.id %>"]);class H extends h.Command{async run(){const e=E();ht(e,T.stdout)}}l(H,"description","parse sources in current package and dump all found tests to stdout"),l(H,"examples",["<%= config.bin %> <%= command.id %>"]);const A=class A extends h.Command{async run(){const{flags:e}=await this.parse(A),r=E();ut(r,e.deps,T.stdout)}};l(A,"description","parse sources in current package and dump all found templates to stdout"),l(A,"examples",["<%= config.bin %> <%= command.id %>"]),l(A,"flags",{deps:h.Flags.boolean({name:"deps",description:"add also all libraries found in node_modules"})});let Q=A;class Y extends h.Command{async run(){const e=E();gt(e,T.stdout)}}l(Y,"description","parse sources in current package and dump all found tests to stdout"),l(Y,"examples",["<%= config.bin %> <%= command.id %>"]);class ee extends h.Command{async run(){const e=E();mt(e,T.stdout)}}l(ee,"description","parse sources in current package and dump all found templates to stdout"),l(ee,"examples",["<%= config.bin %> <%= command.id %>"]);class te extends h.Command{async run(){const e=E();wt(e,T.stdout)}}l(te,"description","parse sources in current package and dump all found tests to stdout"),l(te,"examples",["<%= config.bin %> <%= command.id %>"]);const yt={build:V,check:Z,test:K,"dump:all":X,"dump:assets":H,"dump:libs":Q,"dump:software":Y,"dump:templates":ee,"dump:tests":te};exports.COMMANDS=yt;
43
43
  //# sourceMappingURL=index.js.map