@platforma-sdk/tengo-builder 1.14.11 → 1.14.12

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,12 +1,13 @@
1
1
  import { Command } from '@oclif/core';
2
+ import { BooleanFlag, OptionFlag, CustomOptions } from '@oclif/core/interfaces';
2
3
  export default class Build extends Command {
3
4
  static description: string;
4
5
  static examples: string[];
5
6
  static flags: {
6
- "generate-tags": import('@oclif/core/interfaces').BooleanFlag<boolean>;
7
- "tags-file": import('@oclif/core/interfaces').OptionFlag<string, import('@oclif/core/interfaces').CustomOptions>;
8
- "tags-additional-args": import('@oclif/core/interfaces').OptionFlag<string[], import('@oclif/core/interfaces').CustomOptions>;
9
- "log-level": import('@oclif/core/interfaces').OptionFlag<string, import('@oclif/core/interfaces').CustomOptions>;
7
+ "generate-tags": BooleanFlag<boolean>;
8
+ "tags-file": OptionFlag<string, CustomOptions>;
9
+ "tags-additional-args": OptionFlag<string[], CustomOptions>;
10
+ "log-level": OptionFlag<string, CustomOptions>;
10
11
  };
11
12
  run(): Promise<void>;
12
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAQtC,MAAM,CAAC,OAAO,OAAO,KAAM,SAAQ,OAAO;IACxC,OAAgB,WAAW,SAA6D;IAExF,OAAgB,QAAQ,WAA2C;IAEnE,OAAgB,KAAK;;;;;MAGnB;IAEW,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAiDlC"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAQtC,MAAM,CAAC,OAAO,OAAO,KAAM,SAAQ,OAAO;IACxC,OAAgB,WAAW,SAA6D;IAExF,OAAgB,QAAQ,WAA2C;IAEnE,OAAgB,KAAK;;;;;MAGnB;IAEW,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAiDlC"}
@@ -1,9 +1,10 @@
1
1
  import { Command } from '@oclif/core';
2
+ import { OptionFlag, CustomOptions } from '@oclif/core/interfaces';
2
3
  export default class Check extends Command {
3
4
  static description: string;
4
5
  static strict: boolean;
5
6
  static flags: {
6
- "log-level": import('@oclif/core/interfaces').OptionFlag<string, import('@oclif/core/interfaces').CustomOptions>;
7
+ "log-level": OptionFlag<string, CustomOptions>;
7
8
  };
8
9
  static examples: string[];
9
10
  run(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/commands/check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAOtC,MAAM,CAAC,OAAO,OAAO,KAAM,SAAQ,OAAO;IACxC,OAAgB,WAAW,SAAmD;IAM9E,MAAM,CAAC,MAAM,UAAS;IAEtB,OAAgB,KAAK;;MAAsB;IAE3C,OAAgB,QAAQ,WAA2C;IAEtD,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAwBlC"}
1
+ {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/commands/check.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAOtC,MAAM,CAAC,OAAO,OAAO,KAAM,SAAQ,OAAO;IACxC,OAAgB,WAAW,SAAmD;IAM9E,MAAM,CAAC,MAAM,UAAS;IAEtB,OAAgB,KAAK;;MAAsB;IAE3C,OAAgB,QAAQ,WAA2C;IAEtD,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAwBlC"}
@@ -1,9 +1,10 @@
1
1
  import { Command } from '@oclif/core';
2
+ import { BooleanFlag } from '@oclif/core/interfaces';
2
3
  export default class DumpLibs extends Command {
3
4
  static description: string;
4
5
  static examples: string[];
5
6
  static flags: {
6
- deps: import('@oclif/core/interfaces').BooleanFlag<boolean>;
7
+ deps: BooleanFlag<boolean>;
7
8
  };
8
9
  run(): Promise<void>;
9
10
  }
@@ -1 +1 @@
1
- {"version":3,"file":"libs.d.ts","sourceRoot":"","sources":["../../../src/commands/dump/libs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,MAAM,aAAa,CAAA;AAK5C,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,OAAO;IAC3C,OAAgB,WAAW,SAA4E;IAEvG,OAAgB,QAAQ,WAEvB;IAED,OAAgB,KAAK;;MAEpB;IAEY,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAMlC"}
1
+ {"version":3,"file":"libs.d.ts","sourceRoot":"","sources":["../../../src/commands/dump/libs.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAS,MAAM,aAAa,CAAA;AAK5C,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,OAAO;IAC3C,OAAgB,WAAW,SAA4E;IAEvG,OAAgB,QAAQ,WAEvB;IAED,OAAgB,KAAK;;MAEpB;IAEY,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAMlC"}
@@ -1,9 +1,19 @@
1
1
  import { default as Build } from './build';
2
2
  import { default as Check } from './check';
3
3
  import { default as Test } from './test';
4
+ import { default as DumpAll } from './dump/all';
5
+ import { default as DumpLibs } from './dump/libs';
6
+ import { default as DumpSoftware } from './dump/software';
7
+ import { default as DumpTemplates } from './dump/templates';
8
+ import { default as DumpTests } from './dump/tests';
4
9
  export declare const COMMANDS: {
5
10
  build: typeof Build;
6
11
  check: typeof Check;
7
12
  test: typeof Test;
13
+ 'dump all': typeof DumpAll;
14
+ 'dump libs': typeof DumpLibs;
15
+ 'dump software': typeof DumpSoftware;
16
+ 'dump templates': typeof DumpTemplates;
17
+ 'dump tests': typeof DumpTests;
8
18
  };
9
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAC;AAC5B,OAAO,KAAK,MAAM,SAAS,CAAC;AAC5B,OAAO,IAAI,MAAM,QAAQ,CAAC;AAG1B,eAAO,MAAM,QAAQ;;;;CAIpB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAC;AAC5B,OAAO,KAAK,MAAM,SAAS,CAAC;AAC5B,OAAO,IAAI,MAAM,QAAQ,CAAC;AAE1B,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,QAAQ,MAAM,aAAa,CAAC;AACnC,OAAO,YAAY,MAAM,iBAAiB,CAAC;AAC3C,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAC7C,OAAO,SAAS,MAAM,cAAc,CAAC;AAGrC,eAAO,MAAM,QAAQ;;;;;;;;;CASpB,CAAC"}
@@ -1,9 +1,10 @@
1
1
  import { Command } from '@oclif/core';
2
+ import { OptionFlag, CustomOptions } from '@oclif/core/interfaces';
2
3
  export default class Test extends Command {
3
4
  static description: string;
4
5
  static strict: boolean;
5
6
  static flags: {
6
- "log-level": import('@oclif/core/interfaces').OptionFlag<string, import('@oclif/core/interfaces').CustomOptions>;
7
+ "log-level": OptionFlag<string, CustomOptions>;
7
8
  };
8
9
  static examples: string[];
9
10
  run(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../src/commands/test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAOtC,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,OAAO;IACvC,OAAgB,WAAW,SAAwC;IAEnE,MAAM,CAAC,MAAM,UAAS;IAEtB,OAAgB,KAAK;;MAAsB;IAE3C,OAAgB,QAAQ,WAA2C;IAEtD,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAwBlC"}
1
+ {"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../src/commands/test.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAOtC,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,OAAO;IACvC,OAAgB,WAAW,SAAwC;IAEnE,MAAM,CAAC,MAAM,UAAS;IAEtB,OAAgB,KAAK;;MAAsB;IAE3C,OAAgB,QAAQ,WAA2C;IAEtD,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAwBlC"}
package/dist/index.js CHANGED
@@ -1,15 +1,15 @@
1
- "use strict";var ye=Object.defineProperty;var be=(t,e,r)=>e in t?ye(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var d=(t,e,r)=>be(t,typeof e!="symbol"?e+"":e,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const re=require("node:child_process"),S=require("@oclif/core"),ve=require("node:path"),oe=require("node:fs"),V=require("node:zlib"),$e=require("canonicalize"),A=require("winston"),Ee=require("node:fs/promises"),se=require("@milaboratories/tengo-tester");function q(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const s=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,s.get?s:{enumerable:!0,get:()=>t[r]})}}return e.default=t,Object.freeze(e)}const c=q(ve),u=q(oe),k=q(Ee);function T(t){throw new Error("Unexpected object: "+t)}function Se(){let t=process.cwd();for(;t;){const e=c.join(t,"node_modules");if(u.existsSync(e))return e;const r=c.resolve(t,"..");if(r===t)break;t=r}throw new Error("Unable to find node_modules directory.")}function v(t){try{const e=u.statSync(t);return e.isDirectory()?"dir":e.isFile()?"file":e.isSymbolicLink()?"link":"unknown"}catch(e){if(e.code=="ENOENT")return"absent";throw e}}function Z(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 K(t,e){return t.type==e.type&&t.pkg==e.pkg&&t.id==e.id}function y(t){return`${t.pkg}:${t.id}`}function F(t){return{name:y(t),version:t.version}}function Ne(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 X(t){return`${t.pkg}:${t.id}:${t.version}`}const ke=new TextDecoder,Te=new TextEncoder;class ne{constructor(e,r,s){d(this,"data");d(this,"content");this.compileMode=e,this.fullName=r;let{data:n,content:o}=s;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");if(n===void 0&&(n=JSON.parse(ke.decode(V.gunzipSync(o))),n.type!=="pl.tengo-template.v2"))throw new Error("malformed template");o===void 0&&(o=V.gzipSync(Te.encode($e(n))));const i=Ne(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: ${X(i)} != ${X(r)}`);this.data=n,this.content=o}toJSON(){return{compileMode:this.compileMode,fullName:this.fullName,data:this.data}}}class M{constructor(e){d(this,"map",new Map);this.nameExtractor=e}add(e,r=!0){const s=Z(this.nameExtractor(e)),n=this.map.get(s);return n&&!r||this.map.set(s,e),n}get(e){return this.map.get(Z(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 De(){return new M(t=>t)}class x{constructor(e){d(this,"dev");d(this,"dist");this.nameExtractor=e,this.dev=new M(e),this.dist=new M(e)}add(e,r,s=!0){switch(e){case"dist":return this.dist.add(r,s);default:T(e)}}get(e,r){switch(e){case"dist":return this.dist.get(r);default:T(e)}}array(e){const r=[];return this.forEach(e,s=>r.push(s)),r}forEach(e,r){this.dist.forEach((s,n)=>r(this.get(e,n)??s,n))}}class Ae{constructor(e){d(this,"libs",new x(e=>e.fullName));d(this,"software",new x(e=>e.fullName));d(this,"templates",new x(e=>e.fullName));this.compileMode=e}populateTemplateDataFromDependencies(e,r,s,n){for(const o of s)switch(o.type){case"library":const i=this.getLibOrError(o),a=n.indexOf(y(o));if(a>=0){let p=`library import recursion detected: ${n.slice(a).join(" -> ")} -> ${y(o)}`;throw new Error(p)}r.libs[y(o)]={...F(i.fullName),src:i.src},this.populateTemplateDataFromDependencies(e,r,i.dependencies,[...n,y(o)]);break;case"software":const l=this.getSoftwareOrError(o);r.software[y(o)]={...F(l.fullName),src:l.src};break;case"template":if(K(e,o))continue;const f=this.getTemplateOrError(o);r.templates[y(o)]=f.data;break;case"test":throw new Error(`dependencies tree error: tests should never be part of template: ${g(o)} is dependency of ${y(e)}`);default:T(o.type)}}compileAndAddTemplate(e){if(e.fullName.type!=="template")throw new Error("unexpected source type");const r={type:"pl.tengo-template.v2",...F(e.fullName),templates:{},libs:{},software:{},src:e.src};this.populateTemplateDataFromDependencies(e.fullName,r,e.dependencies,[]);const s=new ne(e.compileMode,e.fullName,{data:r});return this.addTemplate(s),s}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: ${y(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: ${y(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: ${y(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"test":return;default:T(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:[]};let s=[];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)):s.push(n);for(;s.length>0;){const n=[];for(const o of s){const i=o.dependencies.filter(a=>!this.getArtefact(a)&&!(o.fullName.type==="template"&&K(o.fullName,a)));if(i.length>0){let a=`Unsatisfied dependencies in ${m(o.fullName)}:
1
+ "use strict";var ke=Object.defineProperty;var Te=(t,e,r)=>e in t?ke(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var c=(t,e,r)=>Te(t,typeof e!="symbol"?e+"":e,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const fe=require("node:child_process"),h=require("@oclif/core"),De=require("node:path"),pe=require("node:fs"),re=require("node:zlib"),Fe=require("canonicalize"),j=require("winston"),xe=require("node:fs/promises"),ue=require("@milaboratories/tengo-tester"),O=require("node:process");function H(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=H(De),u=H(pe),x=H(xe);function A(t){throw new Error("Unexpected object: "+t)}function Ae(){let t=process.cwd();for(;t;){const e=d.join(t,"node_modules");if(u.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 N(t){try{const e=u.statSync(t);return e.isDirectory()?"dir":e.isFile()?"file":e.isSymbolicLink()?"link":"unknown"}catch(e){if(e.code=="ENOENT")return"absent";throw e}}function se(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 oe(t,e){return t.type==e.type&&t.pkg==e.pkg&&t.id==e.id}function b(t){return`${t.pkg}:${t.id}`}function R(t){return{name:b(t),version:t.version}}function Oe(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 ne(t){return`${t.pkg}:${t.id}:${t.version}`}const Me=new TextDecoder,je=new TextEncoder;class me{constructor(e,r,o){c(this,"data");c(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(Me.decode(re.gunzipSync(s))),n.type!=="pl.tengo-template.v2"))throw new Error("malformed template");s===void 0&&(s=re.gzipSync(je.encode(Fe(n))));const i=Oe(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: ${ne(i)} != ${ne(r)}`);this.data=n,this.content=s}toJSON(){return{compileMode:this.compileMode,fullName:this.fullName,data:this.data}}}class C{constructor(e){c(this,"map",new Map);this.nameExtractor=e}add(e,r=!0){const o=se(this.nameExtractor(e)),n=this.map.get(o);return n&&!r||this.map.set(o,e),n}get(e){return this.map.get(se(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 Re(){return new C(t=>t)}class L{constructor(e){c(this,"dev");c(this,"dist");this.nameExtractor=e,this.dev=new C(e),this.dist=new C(e)}add(e,r,o=!0){switch(e){case"dist":return this.dist.add(r,o);default:A(e)}}get(e,r){switch(e){case"dist":return this.dist.get(r);default:A(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 Le{constructor(e){c(this,"libs",new L(e=>e.fullName));c(this,"software",new L(e=>e.fullName));c(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(b(s));if(a>=0){let p=`library import recursion detected: ${n.slice(a).join(" -> ")} -> ${b(s)}`;throw new Error(p)}r.libs[b(s)]={...R(i.fullName),src:i.src},this.populateTemplateDataFromDependencies(e,r,i.dependencies,[...n,b(s)]);break;case"software":const l=this.getSoftwareOrError(s);r.software[b(s)]={...R(l.fullName),src:l.src};break;case"template":if(oe(e,s))continue;const f=this.getTemplateOrError(s);r.templates[b(s)]=f.data;break;case"test":throw new Error(`dependencies tree error: tests should never be part of template: ${g(s)} is dependency of ${b(e)}`);default:A(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:{},src:e.src};this.populateTemplateDataFromDependencies(e.fullName,r,e.dependencies,[]);const o=new me(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: ${b(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: ${b(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: ${b(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"test":return;default:A(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:[]};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)):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"&&oe(s.fullName,a)));if(i.length>0){let a=`Unsatisfied dependencies in ${m(s.fullName)}:
2
2
  `;for(const l of i)a+=` - ${g(l)}
3
- `;n.push({src:o,err:Error(a)});continue}switch(o.fullName.type){case"library":this.addLib(o),r.libs.push(o);break;case"software":this.addSoftware(o),r.software.push(o);break;case"template":try{const a=this.compileAndAddTemplate(o);r.templates.push(a)}catch(a){let l=`Unsatisfied dependencies in ${m(o.fullName)}:
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"template":try{const a=this.compileAndAddTemplate(s);r.templates.push(a)}catch(a){let l=`Unsatisfied dependencies in ${m(s.fullName)}:
4
4
  `;l+=` - ${a.message}
5
- `,n.push({src:o,err:Error(l)})}break;case"test":break;default:T(o.fullName.type)}}if(s.length===n.length){let o="";for(const i of n)o+=`
6
- ${i.err.message}`;throw new Error(o)}s=n.map(({src:o})=>o)}return r}}const H="[_a-zA-Z][_a-zA-Z0-9]*",D=(t,e)=>new RegExp(`\\b${t}\\.(?<fnCall>(?<fnName>`+e+')\\s*\\(\\s*"(?<templateName>[^"]+)"\\s*\\))'),Fe=t=>D(t,"getTemplateId"),xe=t=>D(t,"getSoftwareInfo"),Q=t=>D(t,"importTemplate"),Y=t=>D(t,"importSoftware"),Me=/^\s*(\/\/)|(\/\*.*\*\/)/,je=/^\s*\/\*/,Oe=/\*\//,ie=/\s*:=\s*import\s*\(\s*"(?<moduleName>[^"]+)"\s*\)/,Re=new RegExp(`\\b(?<importName>${H}(\\.${H})*)${ie.source}`),Le=/(?<pkgName>[^"]+)?:(?<depID>[^"]+)/;class ae{constructor(e,r,s,n,o){this.compileMode=e,this.fullName=r,this.src=s,this.srcName=n,this.dependencies=o}}function le(t,e,r,s){const n=oe.readFileSync(e).toString(),{deps:o,normalized:i}=Ce(n,r,s);return new ae(t,r,i,e,o.array)}function Ce(t,e,r){const s=De(),n=t.split(`
7
- `),o=[];let i={isInCommentBlock:!1,tplDepREs:new Map},a=0;for(const l of n){a++;try{const f=Ie(l,i,e.pkg,r);o.push(f.line),i=f.context,f.artifact&&s.add(f.artifact)}catch(f){throw new Error(`[line ${a}]: ${f.message}
8
- ${l}`)}}return{normalized:o.join(`
9
- `),deps:s}}function Ie(t,e,r,s){if(e.isInCommentBlock)return Oe.exec(t)&&(e.isInCommentBlock=!1),{line:t,context:e,artifact:void 0};if(Me.exec(t))return{line:t,context:e,artifact:void 0};if(je.exec(t))return e.isInCommentBlock=!0,{line:t,context:e,artifact:void 0};const n=ie.exec(t);if(n){const o=Ge(t);if(o.module==="plapi")return e.tplDepREs.has(o.module)||e.tplDepREs.set(o.module,[["template",Fe(o.alias)],["software",xe(o.alias)]]),{line:t,context:e,artifact:void 0};(o.module==="@milaboratory/tengo-sdk:ll"||o.module==="@platforma-sdk/workflow-tengo:ll"||(r==="@milaboratory/tengo-sdk"||r==="@platforma-sdk/workflow-tengo")&&o.module===":ll")&&(e.tplDepREs.has(o.module)||e.tplDepREs.set(o.module,[["template",Q(o.alias)],["software",Y(o.alias)]])),(o.module==="@milaboratory/tengo-sdk:assets"||o.module==="@platforma-sdk/workflow-tengo:assets"||(r==="@milaboratory/tengo-sdk"||r==="@platforma-sdk/workflow-tengo")&&o.module===":assets")&&(e.tplDepREs.has(o.module)||e.tplDepREs.set(o.module,[["template",Q(o.alias)],["software",Y(o.alias)]]));const i=ee(o.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[o,i]of e.tplDepREs)for(const[a,l]of i){const f=l.exec(t);if(!f||!f.groups)continue;const{fnCall:p,templateName:b,fnName:h}=f.groups;if(!p||!b||!h)throw Error("failed to parse template import statement");const w=ee(b,a,r);if(!w)throw Error(`failed to parse artifact name in ${h} import statement`);return t=t.replace(p,`${h}("${w.pkg}:${w.id}")`),{line:t,context:e,artifact:w}}return{line:t,context:e,artifact:void 0}}function Ge(t){const e=Re.exec(t);if(!e||!e.groups)throw Error("failed to parse 'import' statement");const{importName:r,moduleName:s}=e.groups;if(!r||!s)throw Error("failed to parse 'import' statement");return{module:s,alias:r}}function ee(t,e,r){const s=Le.exec(t);if(!s)return;if(!s.groups)throw Error("failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'");const{pkgName:n,depID:o}=s.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??r,id:o}}const j=".plj.gz",O=".lib.tengo",R=".sw.json",te=".test.tengo",L=".tpl.tengo",C=".lib.tengo",I=".sw.json",ze=[C,L,I];function W(t="debug"){return A.createLogger({level:t,format:A.format.printf(({level:e,message:r})=>`${e.padStart(6," ")}: ${r}`),transports:[new A.transports.Console({stderrLevels:["error","warn","info","debug"],handleExceptions:!0})]})}function _(){return JSON.parse(u.readFileSync("package.json").toString())}function ce(t,e){return c.resolve(e,t,"tengo","lib")}function fe(t,e){return c.resolve(e,t,"tengo","tpl")}function de(t,e){return c.resolve(e,t,"tengo","software")}function pe(t,e,r,s,n=!1){const o=c.resolve(s,"package.json");if(v(o)!=="file"){for(const w of u.readdirSync(s)){const we=v(c.join(s,w))==="link",B=c.resolve(s,w);v(B)==="dir"&&pe(t,e,r,B,we)}return}const i=ce("dist",s),a=fe("dist",s),l=de("dist",s),f=v(i)==="dir",p=v(a)==="dir",b=v(l)==="dir";if(!f&&!p&&!b)return;const h=JSON.parse(u.readFileSync(o).toString());if(h.name!==r.name){if(v(c.resolve(s,"node_modules"))==="dir"&&n)throw new Error(`nested node_modules is a sign of library dependencies version incompatibility in ${s}`);f&&Pe(t,h,"dist",i,e),p&&qe(t,h,"dist",a,e),b&&We(t,h,"dist",l,e)}}function Pe(t,e,r,s,n){for(const o of u.readdirSync(s)){const i=c.resolve(s,o);if(!o.endsWith(O))throw new Error(`unexpected file in 'lib' folder: ${i}`);const a={type:"library",pkg:e.name,id:o.slice(0,o.length-O.length),version:e.version},l=le(r,i,a,!0);if(n.addLib(l),t.debug(`Adding dependency ${m(a)} from ${i}`),l.dependencies.length>0){t.debug("Dependencies:");for(const f of l.dependencies)t.debug(` - ${g(f)}`)}}}function qe(t,e,r,s,n){for(const o of u.readdirSync(s)){const i=c.resolve(s,o);if(!o.endsWith(j))throw new Error(`unexpected file in 'tpl' folder: ${i}`);const a={type:"template",pkg:e.name,id:o.slice(0,o.length-j.length),version:e.version},l=new ne(r,a,{content:u.readFileSync(i)});n.addTemplate(l),t.debug(`Adding dependency ${m(a)} from ${i}`)}}function We(t,e,r,s,n){for(const o of u.readdirSync(s)){const i=c.resolve(s,o);if(!o.endsWith(R))throw new Error(`unexpected file in 'software' folder: ${i}`);const a={type:"software",pkg:e.name,id:o.slice(0,o.length-R.length),version:e.version},l=new ae(r,a,u.readFileSync(i).toString(),i,[]);n.addSoftware(l),t.debug(`Adding dependency ${m(a)} from ${i}`)}}function J(t,e,r,s,n){const o=[];for(const i of u.readdirSync(c.join(s,n))){const a=c.join(n,i),l=c.join(s,a);if(v(l)==="dir"){const w=J(t,e,r,s,a);o.push(...w);continue}const f=i==="index.lib.tengo"?`${c.basename(n)}.lib.tengo`:a,p=_e(e,f.replaceAll(c.sep,"."));if(!p)continue;const b=c.resolve(s,a);t.debug(`Parsing ${m(p)} from ${b}`);const h=le(r,b,p,!0);if(h.dependencies.length>0){t.debug("Detected dependencies:");for(const w of h.dependencies)t.debug(` - ${g(w)}`)}o.push(h)}return o}function ue(t,e,r){const s=new Ae(r);return pe(t,s,e,Se()),s}function _e(t,e){const r={pkg:t.name,version:t.version};return e.endsWith(C)?{...r,id:e.substring(0,e.length-C.length),type:"library"}:e.endsWith(L)?{...r,id:e.substring(0,e.length-L.length),type:"template"}:e.endsWith(I)?{...r,id:e.substring(0,e.length-I.length),type:"software"}:e.endsWith(te)?{...r,id:e.substring(0,e.length-te.length),type:"test"}:null}function Je(t,e){const r=_(),s=ue(t,r,e),n=J(t,r,e,"src","");if(n.length===0){const i=[];for(const a of ze)i.push(`*${a}`);t.error(`Nothing to compile. Looked for ${i.join(", ")}`),process.exit(1)}t.info(`Compiling '${e}'...`);const o=s.compileAndAdd(n);return t.debug("Done."),o}function Ue(t,e,r){if(e.libs.length>0){const s=ce(r,".");u.mkdirSync(s,{recursive:!0});for(const n of e.libs){const o=c.resolve(s,n.fullName.id+O);t.info(` - writing ${o}`),u.writeFileSync(o,n.src)}}if(e.templates.length>0){const s=fe(r,".");u.mkdirSync(s,{recursive:!0});for(const n of e.templates){const o=c.resolve(s,n.fullName.id+j);t.info(` - writing ${o}`),u.writeFileSync(o,n.content)}}if(e.software.length>0){const s=de(r,".");u.mkdirSync(s,{recursive:!0});for(const n of e.software){const o=c.resolve(s,n.fullName.id+R);t.info(` - writing ${o}`),u.writeFileSync(o,n.src)}}}const U={"log-level":S.Flags.string({description:"logging level",default:"info",options:["error","warn","info","debug"]})},Be={"generate-tags":S.Flags.boolean({description:"generate tags, default false",default:!1}),"tags-file":S.Flags.file({description:'where to put ".tags" file, it should be a root of VS Code project',default:"../../.tags"}),"tags-additional-args":S.Flags.string({description:"additional flags for universal-ctags command: e.g. -e for emacs",default:[],multiple:!0,delimiter:","})},N=class N extends S.Command{async run(){const{flags:e}=await this.parse(N),r=W(e["log-level"]),s=_(),n=Je(r,"dist");Ue(r,n,"dist"),r.info("");let o=`declare type TemplateFromFile = { readonly type: "from-file"; readonly path: string; };
10
- `;o+=`declare type TplName = ${n.templates.map(p=>'"'+p.fullName.id+'"').join(" | ")};
11
- `,o+=`declare const Templates: Record<TplName, TemplateFromFile>;
12
- `,o+=`export { Templates };
5
+ `,n.push({src:s,err:Error(l)})}break;case"test":break;default:A(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 ie="[_a-zA-Z][_a-zA-Z0-9]*",M=(t,e)=>new RegExp(`\\b${t}\\.(?<fnCall>(?<fnName>`+e+')\\s*\\(\\s*"(?<templateName>[^"]+)"\\s*\\))'),Ce=t=>M(t,"getTemplateId"),Ie=t=>M(t,"getSoftwareInfo"),ae=t=>M(t,"importTemplate"),ce=t=>M(t,"importSoftware"),Ge=/^\s*(\/\/)|(\/\*.*\*\/)/,ze=/^\s*\/\*/,Je=/\*\//,ge=/\s*:=\s*import\s*\(\s*"(?<moduleName>[^"]+)"\s*\)/,Pe=new RegExp(`\\b(?<importName>${ie}(\\.${ie})*)${ge.source}`),qe=/(?<pkgName>[^"]+)?:(?<depID>[^"]+)/;class he{constructor(e,r,o,n,s){this.compileMode=e,this.fullName=r,this.src=o,this.srcName=n,this.dependencies=s}}function we(t,e,r,o){const n=pe.readFileSync(e).toString(),{deps:s,normalized:i}=We(n,r,o);return new he(t,r,i,e,s.array)}function We(t,e,r){const o=Re(),n=t.split(`
7
+ `),s=[];let i={isInCommentBlock:!1,tplDepREs:new Map},a=0;for(const l of n){a++;try{const f=_e(l,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
+ ${l}`)}}return{normalized:s.join(`
9
+ `),deps:o}}function _e(t,e,r,o){if(e.isInCommentBlock)return Je.exec(t)&&(e.isInCommentBlock=!1),{line:t,context:e,artifact:void 0};if(Ge.exec(t))return{line:t,context:e,artifact:void 0};if(ze.exec(t))return e.isInCommentBlock=!0,{line:t,context:e,artifact:void 0};const n=ge.exec(t);if(n){const s=Ue(t);if(s.module==="plapi")return e.tplDepREs.has(s.module)||e.tplDepREs.set(s.module,[["template",Ce(s.alias)],["software",Ie(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",ae(s.alias)],["software",ce(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",ae(s.alias)],["software",ce(s.alias)]]));const i=le(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,l]of i){const f=l.exec(t);if(!f||!f.groups)continue;const{fnCall:p,templateName:v,fnName:w}=f.groups;if(!p||!v||!w)throw Error("failed to parse template import statement");const y=le(v,a,r);if(!y)throw Error(`failed to parse artifact name in ${w} import statement`);return t=t.replace(p,`${w}("${y.pkg}:${y.id}")`),{line:t,context:e,artifact:y}}return{line:t,context:e,artifact:void 0}}function Ue(t){const e=Pe.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 le(t,e,r){const o=qe.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 I=".plj.gz",G=".lib.tengo",z=".sw.json",de=".test.tengo",J=".tpl.tengo",P=".lib.tengo",q=".sw.json",Be=[P,J,q];function $(t="debug"){return j.createLogger({level:t,format:j.format.printf(({level:e,message:r})=>`${e.padStart(6," ")}: ${r}`),transports:[new j.transports.Console({stderrLevels:["error","warn","info","debug"],handleExceptions:!0})]})}function k(){return JSON.parse(u.readFileSync("package.json").toString())}function ye(t,e){return d.resolve(e,t,"tengo","lib")}function be(t,e){return d.resolve(e,t,"tengo","tpl")}function ve(t,e){return d.resolve(e,t,"tengo","software")}function Ne(t,e,r,o,n=!1){const s=d.resolve(o,"package.json");if(N(s)!=="file"){for(const y of u.readdirSync(o)){const Se=N(d.join(o,y))==="link",te=d.resolve(o,y);N(te)==="dir"&&Ne(t,e,r,te,Se)}return}const i=ye("dist",o),a=be("dist",o),l=ve("dist",o),f=N(i)==="dir",p=N(a)==="dir",v=N(l)==="dir";if(!f&&!p&&!v)return;const w=JSON.parse(u.readFileSync(s).toString());if(w.name!==r.name){if(N(d.resolve(o,"node_modules"))==="dir"&&n)throw new Error(`nested node_modules is a sign of library dependencies version incompatibility in ${o}`);f&&Ve(t,w,"dist",i,e),p&&Ze(t,w,"dist",a,e),v&&Ke(t,w,"dist",l,e)}}function Ve(t,e,r,o,n){for(const s of u.readdirSync(o)){const i=d.resolve(o,s);if(!s.endsWith(G))throw new Error(`unexpected file in 'lib' folder: ${i}`);const a={type:"library",pkg:e.name,id:s.slice(0,s.length-G.length),version:e.version},l=we(r,i,a,!0);if(n.addLib(l),t.debug(`Adding dependency ${m(a)} from ${i}`),l.dependencies.length>0){t.debug("Dependencies:");for(const f of l.dependencies)t.debug(` - ${g(f)}`)}}}function Ze(t,e,r,o,n){for(const s of u.readdirSync(o)){const i=d.resolve(o,s);if(!s.endsWith(I))throw new Error(`unexpected file in 'tpl' folder: ${i}`);const a={type:"template",pkg:e.name,id:s.slice(0,s.length-I.length),version:e.version},l=new me(r,a,{content:u.readFileSync(i)});n.addTemplate(l),t.debug(`Adding dependency ${m(a)} from ${i}`)}}function Ke(t,e,r,o,n){for(const s of u.readdirSync(o)){const i=d.resolve(o,s);if(!s.endsWith(z))throw new Error(`unexpected file in 'software' folder: ${i}`);const a={type:"software",pkg:e.name,id:s.slice(0,s.length-z.length),version:e.version},l=new he(r,a,u.readFileSync(i).toString(),i,[]);n.addSoftware(l),t.debug(`Adding dependency ${m(a)} from ${i}`)}}function T(t,e,r,o,n){const s=[];for(const i of u.readdirSync(d.join(o,n))){const a=d.join(n,i),l=d.join(o,a);if(N(l)==="dir"){const y=T(t,e,r,o,a);s.push(...y);continue}const f=i==="index.lib.tengo"?`${d.basename(n)}.lib.tengo`:a,p=Xe(e,f.replaceAll(d.sep,"."));if(!p)continue;const v=d.resolve(o,a);t.debug(`Parsing ${m(p)} from ${v}`);const w=we(r,v,p,!0);if(w.dependencies.length>0){t.debug("Detected dependencies:");for(const y of w.dependencies)t.debug(` - ${g(y)}`)}s.push(w)}return s}function Q(t,e,r){const o=new Le(r);return Ne(t,o,e,Ae()),o}function Xe(t,e){const r={pkg:t.name,version:t.version};return e.endsWith(P)?{...r,id:e.substring(0,e.length-P.length),type:"library"}:e.endsWith(J)?{...r,id:e.substring(0,e.length-J.length),type:"template"}:e.endsWith(q)?{...r,id:e.substring(0,e.length-q.length),type:"software"}:e.endsWith(de)?{...r,id:e.substring(0,e.length-de.length),type:"test"}:null}function He(t,e){const r=k(),o=Q(t,r,e),n=T(t,r,e,"src","");if(n.length===0){const i=[];for(const a of Be)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 Qe(t,e,r){if(e.libs.length>0){const o=ye(r,".");u.mkdirSync(o,{recursive:!0});for(const n of e.libs){const s=d.resolve(o,n.fullName.id+G);t.info(` - writing ${s}`),u.writeFileSync(s,n.src)}}if(e.templates.length>0){const o=be(r,".");u.mkdirSync(o,{recursive:!0});for(const n of e.templates){const s=d.resolve(o,n.fullName.id+I);t.info(` - writing ${s}`),u.writeFileSync(s,n.content)}}if(e.software.length>0){const o=ve(r,".");u.mkdirSync(o,{recursive:!0});for(const n of e.software){const s=d.resolve(o,n.fullName.id+z);t.info(` - writing ${s}`),u.writeFileSync(s,n.src)}}}const Y={"log-level":h.Flags.string({description:"logging level",default:"info",options:["error","warn","info","debug"]})},Ye={"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:","})},D=class D extends h.Command{async run(){const{flags:e}=await this.parse(D),r=$(e["log-level"]),o=k(),n=He(r,"dist");Qe(r,n,"dist"),r.info("");let s=`declare type TemplateFromFile = { readonly type: "from-file"; readonly path: string; };
10
+ `;s+=`declare type TplName = ${n.templates.map(p=>'"'+p.fullName.id+'"').join(" | ")};
11
+ `,s+=`declare const Templates: Record<TplName, TemplateFromFile>;
12
+ `,s+=`export { Templates };
13
13
  `;let i=`module.exports = { Templates: {
14
14
  `,a=`import { resolve } from 'node:path';
15
15
  export const Templates = {
@@ -19,20 +19,25 @@ export const Templates = {
19
19
  }};
20
20
  `,a+=`
21
21
  };
22
- `,await k.writeFile("dist/index.d.ts",o),s.type==="module"?(await k.writeFile("dist/index.cjs",i),await k.writeFile("dist/index.js",a)):(await k.writeFile("dist/index.js",i),await k.writeFile("dist/index.mjs",a)),Ve(e),e["generate-tags"]&&Ze(r,e),r.info("Template Pack build done.")}};d(N,"description","build tengo sources into single distributable pack file"),d(N,"examples",["<%= config.bin %> <%= command.id %>"]),d(N,"flags",{...U,...Be});let G=N;function Ve(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 Ze(t,e){var a;const r=c.resolve(e["tags-file"]),s=c.dirname(r),n=e["tags-additional-args"],o=Ke(s);t.info(`Generating tags for tengo autocompletion from "${s}" in "${r}", additional arguments: "${n}".
23
- Found ${o.length} tengo files...`);const i=re.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",...o],{env:process.env,stdio:"inherit",cwd:s});if((a=i.error)!=null&&a.message.includes("ENOENT")){console.log(`
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)),et(e),e["generate-tags"]&&tt(r,e),r.info("Template Pack build done.")}};c(D,"description","build tengo sources into single distributable pack file"),c(D,"examples",["<%= config.bin %> <%= command.id %>"]),c(D,"flags",{...Y,...Ye});let W=D;function et(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 tt(t,e){var a;const r=d.resolve(e["tags-file"]),o=d.dirname(r),n=e["tags-additional-args"],s=rt(o);t.info(`Generating tags for tengo autocompletion from "${o}" in "${r}", additional arguments: "${n}".
23
+ Found ${s.length} tengo files...`);const i=fe.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}Xe(i,"failed to generate ctags"),t.info("Generation of tags is done.")}function Ke(t){const e=u.readdirSync(t,{withFileTypes:!0,recursive:!0}),r=[];return e.forEach(s=>{if(!s.isDirectory()&&s.name.endsWith(".tengo")){const n=c.join(s.parentPath,s.name).replace(t,".");r.push(n)}}),r}function Xe(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 me(t,e){const r=_(),s=J(t,r,"dist","src",""),n=ue(t,r,"dist");for(const o of n.allLibs())t.debug(`Dumping to pl-tester: ${g(o.fullName)}`),e.write(JSON.stringify(o)+`
31
- `);for(const o of s)o.fullName.type==="library"&&(t.debug(`Dumping to pl-tester: ${g(o.fullName)}`),e.write(JSON.stringify(o)+`
32
- `));for(const o of n.allTemplates())t.debug(`Dumping to pl-tester: ${g(o.fullName)}`),e.write(JSON.stringify(o)+`
33
- `);for(const o of s)o.fullName.type==="template"&&(t.debug(`Dumping to pl-tester: ${g(o.fullName)} ${o.srcName}`),e.write(JSON.stringify(o)+`
34
- `));for(const o of n.allSoftware())t.debug(`Dumping to pl-tester: ${g(o.fullName)}`),e.write(JSON.stringify(o)+`
35
- `);for(const o of s)o.fullName.type==="software"&&(t.debug(`Dumping to pl-tester: ${g(o.fullName)}`),e.write(JSON.stringify(o)+`
36
- `));for(const o of s)o.fullName.type==="test"&&(t.debug(`Dumping to pl-tester: ${g(o.fullName)} ${o.srcName}`),e.write(JSON.stringify(o)+`
37
- `))}function ge(t,...e){const r=re.spawn(t,e,{stdio:["pipe","inherit","inherit"]});return r.stdin.on("error",s=>{s.code}),r}function he(t){return new Promise((e,r)=>{t.on("close",s=>{e(s)}),t.on("error",s=>{r(s)})})}const $=class $ extends S.Command{async run(){const{flags:e,argv:r}=await this.parse($),s=W(e["log-level"]),n=r.length==0?["./src"]:r,o=ge(se.TengoTesterBinaryPath,"check","--log-level",e["log-level"],"--artifacts","-",...n);try{me(s,o.stdin)}catch(i){s.error(i)}finally{o.stdin.end();const i=await he(o);process.exit(i)}}};d($,"description","check tengo sources for language processor an"),d($,"strict",!1),d($,"flags",{...U}),d($,"examples",["<%= config.bin %> <%= command.id %>"]);let z=$;const E=class E extends S.Command{async run(){const{flags:e}=await this.parse(E),r=W(e["log-level"]),s=this.argv.length==0?["./src"]:this.argv,n=ge(se.TengoTesterBinaryPath,"run","--log-level",e["log-level"],"--artifacts","-",...s);try{me(r,n.stdin)}catch(o){r.error(o)}finally{n.stdin.end();const o=await he(n);process.exit(o)}}};d(E,"description","run tengo unit tests (.test.tengo)"),d(E,"strict",!1),d(E,"flags",{...U}),d(E,"examples",["<%= config.bin %> <%= command.id %>"]);let P=E;const He={build:G,check:z,test:P};exports.COMMANDS=He;
30
+ https://marketplace.visualstudio.com/items?itemName=jaydenlin.ctags-support`);return}st(i,"failed to generate ctags"),t.info("Generation of tags is done.")}function rt(t){const e=u.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 st(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 ee(t,e){const r=k(),o=T(t,r,"dist","src",""),n=Q(t,r,"dist");for(const s of n.allLibs())t.debug(`Dumping to pl-tester: ${g(s.fullName)}`),e.write(JSON.stringify(s)+`
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
+ `));for(const s of n.allTemplates())t.debug(`Dumping to pl-tester: ${g(s.fullName)}`),e.write(JSON.stringify(s)+`
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)+`
34
+ `));for(const s of n.allSoftware())t.debug(`Dumping to pl-tester: ${g(s.fullName)}`),e.write(JSON.stringify(s)+`
35
+ `);for(const s of o)s.fullName.type==="software"&&(t.debug(`Dumping to pl-tester: ${g(s.fullName)}`),e.write(JSON.stringify(s)+`
36
+ `));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)+`
37
+ `))}function ot(t,e,r){const o=k(),n=T(t,o,"dist","src","");if(!e){for(const i of n)i.fullName.type==="library"&&r.write(JSON.stringify(i)+`
38
+ `);return}const s=Q(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)+`
39
+ `)}function nt(t,e){const r=k(),o=T(t,r,"dist","src","");for(const n of o)n.fullName.type==="template"&&e.write(JSON.stringify(n)+`
40
+ `)}function it(t,e){const r=k(),o=T(t,r,"dist","src","");for(const n of o)n.fullName.type==="software"&&e.write(JSON.stringify(n)+`
41
+ `)}function at(t,e){const r=k(),o=T(t,r,"dist","src","");for(const n of o)n.fullName.type==="test"&&e.write(JSON.stringify(n)+`
42
+ `)}function $e(t,...e){const r=fe.spawn(t,e,{stdio:["pipe","inherit","inherit"]});return r.stdin.on("error",o=>{o.code}),r}function Ee(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=$(e["log-level"]),n=r.length==0?["./src"]:r,s=$e(ue.TengoTesterBinaryPath,"check","--log-level",e["log-level"],"--artifacts","-",...n);try{ee(o,s.stdin)}catch(i){o.error(i)}finally{s.stdin.end();const i=await Ee(s);process.exit(i)}}};c(E,"description","check tengo sources for language processor an"),c(E,"strict",!1),c(E,"flags",{...Y}),c(E,"examples",["<%= config.bin %> <%= command.id %>"]);let _=E;const S=class S extends h.Command{async run(){const{flags:e}=await this.parse(S),r=$(e["log-level"]),o=this.argv.length==0?["./src"]:this.argv,n=$e(ue.TengoTesterBinaryPath,"run","--log-level",e["log-level"],"--artifacts","-",...o);try{ee(r,n.stdin)}catch(s){r.error(s)}finally{n.stdin.end();const s=await Ee(n);process.exit(s)}}};c(S,"description","run tengo unit tests (.test.tengo)"),c(S,"strict",!1),c(S,"flags",{...Y}),c(S,"examples",["<%= config.bin %> <%= command.id %>"]);let U=S;class B extends h.Command{async run(){const e=$();ee(e,O.stdout)}}c(B,"description","parse sources in current package and dump all found artifacts to stdout"),c(B,"examples",["<%= config.bin %> <%= command.id %>"]);const F=class F extends h.Command{async run(){const{flags:e}=await this.parse(F),r=$();ot(r,e.deps,O.stdout)}};c(F,"description","parse sources in current package and dump all found templates to stdout"),c(F,"examples",["<%= config.bin %> <%= command.id %>"]),c(F,"flags",{deps:h.Flags.boolean({name:"deps",description:"add also all libraries found in node_modules"})});let V=F;class Z extends h.Command{async run(){const e=$();it(e,O.stdout)}}c(Z,"description","parse sources in current package and dump all found tests to stdout"),c(Z,"examples",["<%= config.bin %> <%= command.id %>"]);class K extends h.Command{async run(){const e=$();nt(e,O.stdout)}}c(K,"description","parse sources in current package and dump all found templates to stdout"),c(K,"examples",["<%= config.bin %> <%= command.id %>"]);class X extends h.Command{async run(){const e=$();at(e,O.stdout)}}c(X,"description","parse sources in current package and dump all found tests to stdout"),c(X,"examples",["<%= config.bin %> <%= command.id %>"]);const ct={build:W,check:_,test:U,"dump all":B,"dump libs":V,"dump software":Z,"dump templates":K,"dump tests":X};exports.COMMANDS=ct;
38
43
  //# sourceMappingURL=index.js.map