@platforma-sdk/tengo-builder 1.19.0 → 1.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/compiler/source.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAEhB,WAAW,EACX,cAAc,EACf,MAAM,WAAW,CAAC;AAoEnB,qBAAa,cAAc;IAEvB,qDAAqD;aACrC,WAAW,EAAE,WAAW;IACxC,kDAAkD;aAClC,QAAQ,EAAE,gBAAgB;IAC1C,6BAA6B;aACb,GAAG,EAAE,MAAM;IAC3B,mDAAmD;aACnC,OAAO,EAAE,MAAM;IAC/B,2BAA2B;aACX,YAAY,EAAE,iBAAiB,EAAE;IACjD,0DAA0D;aAC1C,eAAe,EAAE,cAAc,EAAE;;IAXjD,qDAAqD;IACrC,WAAW,EAAE,WAAW;IACxC,kDAAkD;IAClC,QAAQ,EAAE,gBAAgB;IAC1C,6BAA6B;IACb,GAAG,EAAE,MAAM;IAC3B,mDAAmD;IACnC,OAAO,EAAE,MAAM;IAC/B,2BAA2B;IACX,YAAY,EAAE,iBAAiB,EAAE;IACjD,0DAA0D;IAC1C,eAAe,EAAE,cAAc,EAAE;CAEpD;AAED,wBAAgB,eAAe,CAC7B,MAAM,EAAE,OAAO,CAAC,MAAM,EACtB,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,gBAAgB,EAChC,SAAS,EAAE,OAAO,GACjB,cAAc,CAKhB;AAED,wBAAgB,WAAW,CACzB,MAAM,EAAE,OAAO,CAAC,MAAM,EACtB,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,MAAM,EACX,cAAc,EAAE,gBAAgB,EAChC,SAAS,EAAE,OAAO,GACjB,cAAc,CAIhB"}
1
+ {"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/compiler/source.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EAErB,KAAK,WAAW,EAChB,KAAK,cAAc,EAEpB,MAAM,WAAW,CAAC;AAqEnB,qBAAa,cAAc;IAEvB,qDAAqD;aACrC,WAAW,EAAE,WAAW;IACxC,kDAAkD;aAClC,QAAQ,EAAE,gBAAgB;IAC1C,6BAA6B;aACb,GAAG,EAAE,MAAM;IAC3B,mDAAmD;aACnC,OAAO,EAAE,MAAM;IAC/B,2BAA2B;aACX,YAAY,EAAE,iBAAiB,EAAE;IACjD,0DAA0D;aAC1C,eAAe,EAAE,cAAc,EAAE;;IAXjD,qDAAqD;IACrC,WAAW,EAAE,WAAW;IACxC,kDAAkD;IAClC,QAAQ,EAAE,gBAAgB;IAC1C,6BAA6B;IACb,GAAG,EAAE,MAAM;IAC3B,mDAAmD;IACnC,OAAO,EAAE,MAAM;IAC/B,2BAA2B;IACX,YAAY,EAAE,iBAAiB,EAAE;IACjD,0DAA0D;IAC1C,eAAe,EAAE,cAAc,EAAE;CAEpD;AAED,wBAAgB,eAAe,CAC7B,MAAM,EAAE,OAAO,CAAC,MAAM,EACtB,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,gBAAgB,EAChC,SAAS,EAAE,OAAO,GACjB,cAAc,CAKhB;AAED,wBAAgB,WAAW,CACzB,MAAM,EAAE,OAAO,CAAC,MAAM,EACtB,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,MAAM,EACX,cAAc,EAAE,gBAAgB,EAChC,SAAS,EAAE,OAAO,GACjB,cAAc,CAIhB"}
package/dist/index.js CHANGED
@@ -3,10 +3,10 @@
3
3
  `;n.push({src:o,err:Error(a)});continue}switch(o.fullName.type){case"library":this.addLib(o),t.libs.push(o);break;case"software":this.addSoftware(o),t.software.push(o);break;case"asset":this.addAsset(o),t.assets.push(o);break;case"template":try{const a=this.compileAndAddTemplate(o);t.templates.push(a)}catch(a){const c=a;let u=`Unsatisfied dependencies in ${m(o.fullName)}:
4
4
  `;u+=` - ${c.message}
5
5
  `,n.push({src:o,err:Error(u)})}break;case"test":break;default:F(o.fullName.type)}}if(r.length===n.length){let o="";for(const i of n)o+=`
6
- ${i.err.message}`;throw new Error(o)}r=n.map(({src:o})=>o)}return t}}const ue="[_a-zA-Z][_a-zA-Z0-9]*",x=(s,e)=>new RegExp(`\\b${s}\\.(?<fnCall>(?<fnName>`+e+')\\s*\\(\\s*"(?<templateName>[^"]+)"\\s*\\))'),ze=s=>x(s,"getTemplateId"),Be=s=>x(s,"getSoftwareInfo"),me=s=>x(s,"importTemplate"),ge=s=>x(s,"importSoftware"),Ve=s=>x(s,"importAsset"),Ze=/^\s*$/,Ke=/^\/\/tengo:[\w]/,Xe=/^\s*\/\/\s*tengo:\s*./,Ye=/^\s*(\/\/)|(\/\*.*\*\/)/,He=/^\s*\/\*/,Qe=/\*\//,$e=/\s*:=\s*import\s*\(\s*"(?<moduleName>[^"]+)"\s*\)/,et=new RegExp(`\\b(?<importName>${ue}(\\.${ue})*)${$e.source}`),tt=/(?<pkgName>[^"]+)?:(?<depID>[^"]+)/,st=s=>{const e=s.split(" "),t=e[0].split(":");if(t.length!=2)throw new Error("compiler option format is wrong: expect to have option name after 'tengo:' prefix, like 'tengo:MyOption'");return{name:t[1],args:e.slice(1)}};class oe{constructor(e,t,r,n,o,i){this.compileMode=e,this.fullName=t,this.src=r,this.srcName=n,this.dependencies=o,this.compilerOptions=i}}function Ne(s,e,t,r,n){const o=be.readFileSync(t).toString(),{deps:i,normalized:a,opts:c}=ot(s,o,r,n);return new oe(e,r,a,t,i.array,c)}function ot(s,e,t,r){const n=Pe(),o=[],i=e.split(`
7
- `),a=[];let c={isInCommentBlock:!1,canDetectOptions:!0,tplDepREs:new Map,lineNo:0};for(const u of i){c.lineNo++;try{const d=rt(s,u,c,t.pkg,r);a.push(d.line),c=d.context,d.artifact&&n.add(d.artifact),d.option&&o.push(d.option)}catch(d){const y=d;throw new Error(`[line ${c.lineNo}]: ${y.message}
8
- ${u}`)}}return{normalized:a.join(`
9
- `),deps:n,opts:o}}function rt(s,e,t,r,n){if(t.isInCommentBlock)return Qe.exec(e)&&(t.isInCommentBlock=!1),{line:"",context:t,artifact:void 0,option:void 0};if(Ke.exec(e)){if(!t.canDetectOptions)throw s.error(`[line ${t.lineNo}]: compiler option '//tengo:' was detected, but it cannot be applied as compiler options can be set only at the file header, before any code line'`),new Error("tengo compiler options ('//tengo:' comments) can be set only in file header");return{line:e,context:t,artifact:void 0,option:st(e)}}if(Xe.exec(e)&&t.canDetectOptions)return s.warn(`[line ${t.lineNo}]: text simillar to compiler option ('//tengo:...') was detected, but it has wrong format. Leave it as is, if you did not mean to use a line as compiler option. Or format it to '//tengo:<option>' otherwise (no spaces between '//' and 'tengo', no spaces between ':' and option name)`),{line:e,context:t,artifact:void 0,option:void 0};if(Ye.exec(e))return{line:"",context:t,artifact:void 0,option:void 0};if(He.exec(e))return t.isInCommentBlock=!0,{line:"",context:t,artifact:void 0,option:void 0};if(Ze.exec(e))return{line:e,context:t,artifact:void 0,option:void 0};t.canDetectOptions=!1;const o=$e.exec(e);if(o){const i=nt(e);if(i.module==="plapi")return t.tplDepREs.has(i.module)||t.tplDepREs.set(i.module,[["template",ze(i.alias)],["software",Be(i.alias)]]),{line:e,context:t,artifact:void 0,option:void 0};(i.module==="@milaboratory/tengo-sdk:ll"||i.module==="@platforma-sdk/workflow-tengo:ll"||(r==="@milaboratory/tengo-sdk"||r==="@platforma-sdk/workflow-tengo")&&i.module===":ll")&&(t.tplDepREs.has(i.module)||t.tplDepREs.set(i.module,[["template",me(i.alias)],["software",ge(i.alias)]])),(i.module==="@milaboratory/tengo-sdk:assets"||i.module==="@platforma-sdk/workflow-tengo:assets"||(r==="@milaboratory/tengo-sdk"||r==="@platforma-sdk/workflow-tengo")&&i.module===":assets")&&(t.tplDepREs.has(i.module)||t.tplDepREs.set(i.module,[["template",me(i.alias)],["software",ge(i.alias)],["asset",Ve(i.alias)]]));const a=he(i.module,"library",r);return a?(e=e.replace(o[0],` := import("${a.pkg}:${a.id}")`),{line:e,context:t,artifact:a,option:void 0}):{line:e,context:t,artifact:void 0,option:void 0}}if(t.tplDepREs.size>0)for(const[i,a]of t.tplDepREs)for(const[c,u]of a){const d=u.exec(e);if(!d||!d.groups)continue;const{fnCall:y,templateName:E,fnName:b}=d.groups;if(!y||!E||!b)throw Error("failed to parse template import statement");const v=he(E,c,r);if(!v)throw Error(`failed to parse artifact name in ${b} import statement`);return e=e.replace(y,`${b}("${v.pkg}:${v.id}")`),{line:e,context:t,artifact:v,option:void 0}}return{line:e,context:t,artifact:void 0,option:void 0}}function nt(s){const e=et.exec(s);if(!e||!e.groups)throw Error("failed to parse 'import' statement");const{importName:t,moduleName:r}=e.groups;if(!t||!r)throw Error("failed to parse 'import' statement");return{module:r,alias:t}}function he(s,e,t){const r=tt.exec(s);if(!r)return;if(!r.groups)throw Error("failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'");const{pkgName:n,depID:o}=r.groups;if(!o)throw Error("failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'");return{type:e,pkg:n??t,id:o}}const P=".plj.gz",U=".lib.tengo",q=".sw.json",J=".as.json",we=".test.tengo",W=".tpl.tengo",z=".lib.tengo",B=".sw.json",V=".as.json",it=[z,W,B,V];function M(){return JSON.parse(p.readFileSync("package.json").toString())}function Se(s,e){return f.resolve(e,s,"tengo","lib")}function ke(s,e){return f.resolve(e,s,"tengo","tpl")}function Ae(s,e){return f.resolve(e,s,"tengo","software")}function Te(s,e){return f.resolve(e,s,"tengo","asset")}function De(s,e,t,r,n=!1){const o=f.resolve(r,"package.json");if($(o)!=="file"){for(const ae of p.readdirSync(r)){const xe=$(f.join(r,ae))==="link",le=f.resolve(r,ae);$(le)==="dir"&&De(s,e,t,le,xe)}return}const i=Se("dist",r),a=ke("dist",r),c=Ae("dist",r),u=Te("dist",r),d=$(i)==="dir",y=$(a)==="dir",E=$(c)==="dir",b=$(u)==="dir";if(!d&&!y&&!E&&!b)return;const v=JSON.parse(p.readFileSync(o).toString());if(v.name!==t.name){if($(f.resolve(r,"node_modules"))==="dir"&&n)throw new Error(`nested node_modules is a sign of library dependencies version incompatibility in ${r}`);d&&at(s,v,"dist",i,e),y&&lt(s,v,"dist",a,e),E&&ct(s,v,"dist",c,e),b&&dt(s,v,"dist",u,e)}}function at(s,e,t,r,n){for(const o of p.readdirSync(r)){const i=f.resolve(r,o);if(!o.endsWith(U))throw new Error(`unexpected file in 'lib' folder: ${i}`);const a={type:"library",pkg:e.name,id:o.slice(0,o.length-U.length),version:e.version},c=Ne(s,t,i,a,!0);if(n.addLib(c),s.debug(`Adding dependency ${m(a)} from ${i}`),c.dependencies.length>0){s.debug("Dependencies:");for(const u of c.dependencies)s.debug(` - ${g(u)}`)}}}function lt(s,e,t,r,n){for(const o of p.readdirSync(r)){const i=f.resolve(r,o);if(!o.endsWith(P))throw new Error(`unexpected file in 'tpl' folder: ${i}`);const a={type:"template",pkg:e.name,id:o.slice(0,o.length-P.length),version:e.version},c=new Ee(t,a,{content:p.readFileSync(i)});n.addTemplate(c),s.debug(`Adding dependency ${m(a)} from ${i}`)}}function ct(s,e,t,r,n){for(const o of p.readdirSync(r)){const i=f.resolve(r,o);if(!o.endsWith(q))throw new Error(`unexpected file in 'software' folder: ${i}`);const a={type:"software",pkg:e.name,id:o.slice(0,o.length-q.length),version:e.version},c=new oe(t,a,p.readFileSync(i).toString(),i,[],[]);s.debug(`Adding dependency ${m(a)} from ${i}`),n.addSoftware(c)}}function dt(s,e,t,r,n){for(const o of p.readdirSync(r)){const i=f.resolve(r,o);if(!o.endsWith(J))throw new Error(`unexpected file in 'asset' folder: ${i}`);const a={type:"asset",pkg:e.name,id:o.slice(0,o.length-J.length),version:e.version},c=new oe(t,a,p.readFileSync(i).toString(),i,[],[]);s.debug(`Adding dependency ${m(a)} from ${i}`),n.addAsset(c)}}function R(s,e,t,r,n){const o=[];for(const i of p.readdirSync(f.join(r,n))){const a=f.join(n,i),c=f.join(r,a);if($(c)==="dir"){const b=R(s,e,t,r,a);o.push(...b);continue}const u=i==="index.lib.tengo"?`${f.dirname(a)}.lib.tengo`:a,d=ft(e,u.replaceAll(f.sep,"."));if(!d)continue;const y=f.resolve(r,a);s.debug(`Parsing ${m(d)} from ${y}`);const E=Ne(s,t,y,d,!0);if(E.dependencies.length>0){s.debug("Detected dependencies:");for(const b of E.dependencies)s.debug(` - ${g(b)}`)}o.push(E)}return o}function re(s,e,t){const r=new We(t);return De(s,r,e,Ie()),r}function ft(s,e){const t={pkg:s.name,version:s.version};return e.endsWith(z)?{...t,id:e.substring(0,e.length-z.length),type:"library"}:e.endsWith(W)?{...t,id:e.substring(0,e.length-W.length),type:"template"}:e.endsWith(B)?{...t,id:e.substring(0,e.length-B.length),type:"software"}:e.endsWith(V)?{...t,id:e.substring(0,e.length-V.length),type:"asset"}:e.endsWith(we)?{...t,id:e.substring(0,e.length-we.length),type:"test"}:null}function pt(s,e){const t=M(),r=re(s,t,e),n=R(s,t,e,"src","");if(n.length===0){const i=[];for(const a of it)i.push(`*${a}`);s.error(`Nothing to compile. Looked for ${i.join(", ")}`),process.exit(1)}s.info(`Compiling '${e}'...`);const o=r.compileAndAdd(n);return s.debug("Done."),o}function ut(s,e,t){if(e.libs.length>0){const r=Se(t,".");p.mkdirSync(r,{recursive:!0});for(const n of e.libs){const o=f.resolve(r,n.fullName.id+U);s.info(` - writing ${o}`),p.writeFileSync(o,n.src)}}if(e.templates.length>0){const r=ke(t,".");p.mkdirSync(r,{recursive:!0});for(const n of e.templates){const o=f.resolve(r,n.fullName.id+P);s.info(` - writing ${o}`),p.writeFileSync(o,n.content)}}if(e.software.length>0){const r=Ae(t,".");p.mkdirSync(r,{recursive:!0});for(const n of e.software){const o=f.resolve(r,n.fullName.id+q);s.info(` - writing ${o}`),p.writeFileSync(o,n.src)}}if(e.assets.length>0){const r=Te(t,".");p.mkdirSync(r,{recursive:!0});for(const n of e.software){const o=f.resolve(r,n.fullName.id+J);s.info(` - writing ${o}`),p.writeFileSync(o,n.src)}}}const ne={"log-level":h.Flags.string({description:"logging level",default:"info",options:["error","warn","info","debug"]})},mt={"generate-tags":h.Flags.boolean({description:"generate tags, default false",default:!1}),"tags-file":h.Flags.file({description:'where to put ".tags" file, it should be a root of VS Code project',default:"../../.tags"}),"tags-additional-args":h.Flags.string({description:"additional flags for universal-ctags command: e.g. -e for emacs",default:[],multiple:!0,delimiter:","})},A=class A extends h.Command{async run(){const{flags:e}=await this.parse(A),t=N(e["log-level"]),r=M(),n=pt(t,"dist");ut(t,n,"dist"),t.info("");let o=`declare type TemplateFromFile = { readonly type: "from-file"; readonly path: string; };
6
+ ${i.err.message}`;throw new Error(o)}r=n.map(({src:o})=>o)}return t}}const ue="[_a-zA-Z][_a-zA-Z0-9]*",x=(s,e)=>new RegExp(`\\b${s}\\.(?<fnCall>(?<fnName>`+e+')\\s*\\(\\s*"(?<templateName>[^"]+)"\\s*\\))'),ze=s=>x(s,"getTemplateId"),Be=s=>x(s,"getSoftwareInfo"),me=s=>x(s,"importTemplate"),ge=s=>x(s,"importSoftware"),Ve=s=>x(s,"importAsset"),Ze=/^\s*$/,Ke=/^\/\/tengo:[\w]/,Xe=/^\s*\/\/\s*tengo:\s*./,Ye=/\/\*.*?\*\//g,He=/^\s*(\/\/)/,Qe=/^\s*\/\*/,et=/\*\//,$e=/\s*:=\s*import\s*\(\s*"(?<moduleName>[^"]+)"\s*\)/,tt=new RegExp(`\\b(?<importName>${ue}(\\.${ue})*)${$e.source}`),st=/(?<pkgName>[^"]+)?:(?<depID>[^"]+)/,ot=s=>{const e=s.split(" "),t=e[0].split(":");if(t.length!=2)throw new Error("compiler option format is wrong: expect to have option name after 'tengo:' prefix, like 'tengo:MyOption'");return{name:t[1],args:e.slice(1)}};class oe{constructor(e,t,r,n,o,i){this.compileMode=e,this.fullName=t,this.src=r,this.srcName=n,this.dependencies=o,this.compilerOptions=i}}function Ne(s,e,t,r,n){const o=be.readFileSync(t).toString(),{deps:i,normalized:a,opts:c}=rt(s,o,r,n);return new oe(e,r,a,t,i.array,c)}function rt(s,e,t,r){const n=Pe(),o=[],i=e.split(`
7
+ `),a=[];let c={isInCommentBlock:!1,canDetectOptions:!0,tplDepREs:new Map,lineNo:0};for(const u of i){c.lineNo++;try{const d=nt(s,u,c,t.pkg,r);a.push(d.line),c=d.context,d.artifact&&n.add(d.artifact),d.option&&o.push(d.option)}catch(d){const y=d;throw new Error(`[line ${c.lineNo} in ${m(t)}]: ${y.message}
8
+ ${u}`,{cause:y})}}return{normalized:a.join(`
9
+ `),deps:n,opts:o}}function nt(s,e,t,r,n){if(e=e.replaceAll(Ye,""),t.isInCommentBlock)return et.exec(e)&&(t.isInCommentBlock=!1),{line:"",context:t,artifact:void 0,option:void 0};if(Ke.exec(e)){if(!t.canDetectOptions)throw s.error(`[line ${t.lineNo}]: compiler option '//tengo:' was detected, but it cannot be applied as compiler options can be set only at the file header, before any code line'`),new Error("tengo compiler options ('//tengo:' comments) can be set only in file header");return{line:e,context:t,artifact:void 0,option:ot(e)}}if(Xe.exec(e)&&t.canDetectOptions)return s.warn(`[line ${t.lineNo}]: text simillar to compiler option ('//tengo:...') was detected, but it has wrong format. Leave it as is, if you did not mean to use a line as compiler option. Or format it to '//tengo:<option>' otherwise (no spaces between '//' and 'tengo', no spaces between ':' and option name)`),{line:e,context:t,artifact:void 0,option:void 0};if(He.test(e))return{line:"",context:t,artifact:void 0,option:void 0};if(Qe.exec(e))return t.isInCommentBlock=!0,{line:"",context:t,artifact:void 0,option:void 0};if(e.includes("/*"))throw new Error("malformed multiline comment");if(Ze.exec(e))return{line:e,context:t,artifact:void 0,option:void 0};t.canDetectOptions=!1;const o=$e.exec(e);if(o){const i=it(e);if(i.module==="plapi")return t.tplDepREs.has(i.module)||t.tplDepREs.set(i.module,[["template",ze(i.alias)],["software",Be(i.alias)]]),{line:e,context:t,artifact:void 0,option:void 0};(i.module==="@milaboratory/tengo-sdk:ll"||i.module==="@platforma-sdk/workflow-tengo:ll"||(r==="@milaboratory/tengo-sdk"||r==="@platforma-sdk/workflow-tengo")&&i.module===":ll")&&(t.tplDepREs.has(i.module)||t.tplDepREs.set(i.module,[["template",me(i.alias)],["software",ge(i.alias)]])),(i.module==="@milaboratory/tengo-sdk:assets"||i.module==="@platforma-sdk/workflow-tengo:assets"||(r==="@milaboratory/tengo-sdk"||r==="@platforma-sdk/workflow-tengo")&&i.module===":assets")&&(t.tplDepREs.has(i.module)||t.tplDepREs.set(i.module,[["template",me(i.alias)],["software",ge(i.alias)],["asset",Ve(i.alias)]]));const a=he(i.module,"library",r);return a?(e=e.replace(o[0],` := import("${a.pkg}:${a.id}")`),{line:e,context:t,artifact:a,option:void 0}):{line:e,context:t,artifact:void 0,option:void 0}}if(t.tplDepREs.size>0)for(const[i,a]of t.tplDepREs)for(const[c,u]of a){const d=u.exec(e);if(!d||!d.groups)continue;const{fnCall:y,templateName:E,fnName:b}=d.groups;if(!y||!E||!b)throw Error("failed to parse template import statement");const v=he(E,c,r);if(!v)throw Error(`failed to parse artifact name in ${b} import statement`);return e=e.replace(y,`${b}("${v.pkg}:${v.id}")`),{line:e,context:t,artifact:v,option:void 0}}return{line:e,context:t,artifact:void 0,option:void 0}}function it(s){const e=tt.exec(s);if(!e||!e.groups)throw Error("failed to parse 'import' statement");const{importName:t,moduleName:r}=e.groups;if(!t||!r)throw Error("failed to parse 'import' statement");return{module:r,alias:t}}function he(s,e,t){const r=st.exec(s);if(!r)return;if(!r.groups)throw Error("failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'");const{pkgName:n,depID:o}=r.groups;if(!o)throw Error("failed to parse dependency name inside 'import' statement. The dependency name should have format '<package>:<templateName>'");return{type:e,pkg:n??t,id:o}}const P=".plj.gz",U=".lib.tengo",q=".sw.json",J=".as.json",we=".test.tengo",W=".tpl.tengo",z=".lib.tengo",B=".sw.json",V=".as.json",at=[z,W,B,V];function M(){return JSON.parse(p.readFileSync("package.json").toString())}function Se(s,e){return f.resolve(e,s,"tengo","lib")}function ke(s,e){return f.resolve(e,s,"tengo","tpl")}function Ae(s,e){return f.resolve(e,s,"tengo","software")}function Te(s,e){return f.resolve(e,s,"tengo","asset")}function De(s,e,t,r,n=!1){const o=f.resolve(r,"package.json");if($(o)!=="file"){for(const ae of p.readdirSync(r)){const xe=$(f.join(r,ae))==="link",le=f.resolve(r,ae);$(le)==="dir"&&De(s,e,t,le,xe)}return}const i=Se("dist",r),a=ke("dist",r),c=Ae("dist",r),u=Te("dist",r),d=$(i)==="dir",y=$(a)==="dir",E=$(c)==="dir",b=$(u)==="dir";if(!d&&!y&&!E&&!b)return;const v=JSON.parse(p.readFileSync(o).toString());if(v.name!==t.name){if($(f.resolve(r,"node_modules"))==="dir"&&n)throw new Error(`nested node_modules is a sign of library dependencies version incompatibility in ${r}`);d&&lt(s,v,"dist",i,e),y&&ct(s,v,"dist",a,e),E&&dt(s,v,"dist",c,e),b&&ft(s,v,"dist",u,e)}}function lt(s,e,t,r,n){for(const o of p.readdirSync(r)){const i=f.resolve(r,o);if(!o.endsWith(U))throw new Error(`unexpected file in 'lib' folder: ${i}`);const a={type:"library",pkg:e.name,id:o.slice(0,o.length-U.length),version:e.version},c=Ne(s,t,i,a,!0);if(n.addLib(c),s.debug(`Adding dependency ${m(a)} from ${i}`),c.dependencies.length>0){s.debug("Dependencies:");for(const u of c.dependencies)s.debug(` - ${g(u)}`)}}}function ct(s,e,t,r,n){for(const o of p.readdirSync(r)){const i=f.resolve(r,o);if(!o.endsWith(P))throw new Error(`unexpected file in 'tpl' folder: ${i}`);const a={type:"template",pkg:e.name,id:o.slice(0,o.length-P.length),version:e.version},c=new Ee(t,a,{content:p.readFileSync(i)});n.addTemplate(c),s.debug(`Adding dependency ${m(a)} from ${i}`)}}function dt(s,e,t,r,n){for(const o of p.readdirSync(r)){const i=f.resolve(r,o);if(!o.endsWith(q))throw new Error(`unexpected file in 'software' folder: ${i}`);const a={type:"software",pkg:e.name,id:o.slice(0,o.length-q.length),version:e.version},c=new oe(t,a,p.readFileSync(i).toString(),i,[],[]);s.debug(`Adding dependency ${m(a)} from ${i}`),n.addSoftware(c)}}function ft(s,e,t,r,n){for(const o of p.readdirSync(r)){const i=f.resolve(r,o);if(!o.endsWith(J))throw new Error(`unexpected file in 'asset' folder: ${i}`);const a={type:"asset",pkg:e.name,id:o.slice(0,o.length-J.length),version:e.version},c=new oe(t,a,p.readFileSync(i).toString(),i,[],[]);s.debug(`Adding dependency ${m(a)} from ${i}`),n.addAsset(c)}}function R(s,e,t,r,n){const o=[];for(const i of p.readdirSync(f.join(r,n))){const a=f.join(n,i),c=f.join(r,a);if($(c)==="dir"){const b=R(s,e,t,r,a);o.push(...b);continue}const u=i==="index.lib.tengo"?`${f.dirname(a)}.lib.tengo`:a,d=pt(e,u.replaceAll(f.sep,"."));if(!d)continue;const y=f.resolve(r,a);s.debug(`Parsing ${m(d)} from ${y}`);const E=Ne(s,t,y,d,!0);if(E.dependencies.length>0){s.debug("Detected dependencies:");for(const b of E.dependencies)s.debug(` - ${g(b)}`)}o.push(E)}return o}function re(s,e,t){const r=new We(t);return De(s,r,e,Ie()),r}function pt(s,e){const t={pkg:s.name,version:s.version};return e.endsWith(z)?{...t,id:e.substring(0,e.length-z.length),type:"library"}:e.endsWith(W)?{...t,id:e.substring(0,e.length-W.length),type:"template"}:e.endsWith(B)?{...t,id:e.substring(0,e.length-B.length),type:"software"}:e.endsWith(V)?{...t,id:e.substring(0,e.length-V.length),type:"asset"}:e.endsWith(we)?{...t,id:e.substring(0,e.length-we.length),type:"test"}:null}function ut(s,e){const t=M(),r=re(s,t,e),n=R(s,t,e,"src","");if(n.length===0){const i=[];for(const a of at)i.push(`*${a}`);s.error(`Nothing to compile. Looked for ${i.join(", ")}`),process.exit(1)}s.info(`Compiling '${e}'...`);const o=r.compileAndAdd(n);return s.debug("Done."),o}function mt(s,e,t){if(e.libs.length>0){const r=Se(t,".");p.mkdirSync(r,{recursive:!0});for(const n of e.libs){const o=f.resolve(r,n.fullName.id+U);s.info(` - writing ${o}`),p.writeFileSync(o,n.src)}}if(e.templates.length>0){const r=ke(t,".");p.mkdirSync(r,{recursive:!0});for(const n of e.templates){const o=f.resolve(r,n.fullName.id+P);s.info(` - writing ${o}`),p.writeFileSync(o,n.content)}}if(e.software.length>0){const r=Ae(t,".");p.mkdirSync(r,{recursive:!0});for(const n of e.software){const o=f.resolve(r,n.fullName.id+q);s.info(` - writing ${o}`),p.writeFileSync(o,n.src)}}if(e.assets.length>0){const r=Te(t,".");p.mkdirSync(r,{recursive:!0});for(const n of e.software){const o=f.resolve(r,n.fullName.id+J);s.info(` - writing ${o}`),p.writeFileSync(o,n.src)}}}const ne={"log-level":h.Flags.string({description:"logging level",default:"info",options:["error","warn","info","debug"]})},gt={"generate-tags":h.Flags.boolean({description:"generate tags, default false",default:!1}),"tags-file":h.Flags.file({description:'where to put ".tags" file, it should be a root of VS Code project',default:"../../.tags"}),"tags-additional-args":h.Flags.string({description:"additional flags for universal-ctags command: e.g. -e for emacs",default:[],multiple:!0,delimiter:","})},A=class A extends h.Command{async run(){const{flags:e}=await this.parse(A),t=N(e["log-level"]),r=M(),n=ut(t,"dist");mt(t,n,"dist"),t.info("");let o=`declare type TemplateFromFile = { readonly type: "from-file"; readonly path: string; };
10
10
  `;o+=`declare type TplName = ${n.templates.map(d=>'"'+d.fullName.id+'"').join(" | ")};
11
11
  `,o+=`declare const Templates: Record<TplName, TemplateFromFile>;
12
12
  `,o+=`export { Templates };
@@ -19,7 +19,7 @@ export const Templates = {
19
19
  }};
20
20
  `,a+=`
21
21
  };
22
- `,await O.writeFile("dist/index.d.ts",o),r.type==="module"?(await O.writeFile("dist/index.cjs",i),await O.writeFile("dist/index.js",a)):(await O.writeFile("dist/index.js",i),await O.writeFile("dist/index.mjs",a)),gt(e),e["generate-tags"]&&ht(t,e),t.info("Template Pack build done.")}};l(A,"description","build tengo sources into single distributable pack file"),l(A,"examples",["<%= config.bin %> <%= command.id %>"]),l(A,"flags",{...ne,...mt});let Z=A;function gt(s){process.env.GENERATE_TAGS!=null&&(s["generate-tags"]=process.env.GENERATE_TAGS=="true"),process.env.TAGS_FILE!=null&&(s["tags-file"]=process.env.TAGS_FILE),process.env.TAGS_ADDITIONAL_ARGS!=null&&(s["tags-additional-args"]=process.env.TAGS_ADDITIONAL_ARGS.split(","))}function ht(s,e){var a;const t=f.resolve(e["tags-file"]),r=f.dirname(t),n=e["tags-additional-args"],o=wt(r);s.info(`Generating tags for tengo autocompletion from "${r}" in "${t}", additional arguments: "${n.join('" "')}".
22
+ `,await O.writeFile("dist/index.d.ts",o),r.type==="module"?(await O.writeFile("dist/index.cjs",i),await O.writeFile("dist/index.js",a)):(await O.writeFile("dist/index.js",i),await O.writeFile("dist/index.mjs",a)),ht(e),e["generate-tags"]&&wt(t,e),t.info("Template Pack build done.")}};l(A,"description","build tengo sources into single distributable pack file"),l(A,"examples",["<%= config.bin %> <%= command.id %>"]),l(A,"flags",{...ne,...gt});let Z=A;function ht(s){process.env.GENERATE_TAGS!=null&&(s["generate-tags"]=process.env.GENERATE_TAGS=="true"),process.env.TAGS_FILE!=null&&(s["tags-file"]=process.env.TAGS_FILE),process.env.TAGS_ADDITIONAL_ARGS!=null&&(s["tags-additional-args"]=process.env.TAGS_ADDITIONAL_ARGS.split(","))}function wt(s,e){var a;const t=f.resolve(e["tags-file"]),r=f.dirname(t),n=e["tags-additional-args"],o=yt(r);s.info(`Generating tags for tengo autocompletion from "${r}" in "${t}", additional arguments: "${n.join('" "')}".
23
23
  Found ${o.length} tengo files...`);const i=ye.spawnSync("ctags",["-f",t,...n,"--langdef=tengo","--map-tengo=+.tengo","--kinddef-tengo=f,function,function","--regex-tengo=/^\\s*(.*)(:| :=| =) ?func.*/\\1/f/","--kinddef-tengo=c,constant,constant",'--regex-tengo=/^\\s*(.*) := ("|\\{).*/\\1/c/',"-R",...o],{env:process.env,stdio:"inherit",cwd:r});if((a=i.error)!=null&&a.message.includes("ENOENT")){console.log(`
24
24
  pl-tengo can create tags for tengo autocompletion,
25
25
  but the program should be installed
@@ -27,7 +27,7 @@ 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}yt(i,"failed to generate ctags"),s.info("Generation of tags is done.")}function wt(s){const e=p.readdirSync(s,{withFileTypes:!0,recursive:!0}),t=[];return e.forEach(r=>{if(!r.isDirectory()&&r.name.endsWith(".tengo")){const n=f.join(r.parentPath,r.name).replace(s,".");t.push(n)}}),t}function yt(s,e){s.error&&console.log(s.error);const t=e;s.status!==0&&console.log(`WARN: ${t} the build will continue as-is`)}function ie(s,e){const t=M(),r=R(s,t,"dist","src",""),n=re(s,t,"dist");for(const o of n.allLibs())s.debug(`Dumping to pl-tester: ${g(o.fullName)}`),e.write(JSON.stringify(o)+`
30
+ https://marketplace.visualstudio.com/items?itemName=jaydenlin.ctags-support`);return}bt(i,"failed to generate ctags"),s.info("Generation of tags is done.")}function yt(s){const e=p.readdirSync(s,{withFileTypes:!0,recursive:!0}),t=[];return e.forEach(r=>{if(!r.isDirectory()&&r.name.endsWith(".tengo")){const n=f.join(r.parentPath,r.name).replace(s,".");t.push(n)}}),t}function bt(s,e){s.error&&console.log(s.error);const t=e;s.status!==0&&console.log(`WARN: ${t} the build will continue as-is`)}function ie(s,e){const t=M(),r=R(s,t,"dist","src",""),n=re(s,t,"dist");for(const o of n.allLibs())s.debug(`Dumping to pl-tester: ${g(o.fullName)}`),e.write(JSON.stringify(o)+`
31
31
  `);for(const o of r)o.fullName.type==="library"&&(s.debug(`Dumping to pl-tester: ${g(o.fullName)}`),e.write(JSON.stringify(o)+`
32
32
  `));for(const o of n.allTemplates())s.debug(`Dumping to pl-tester: ${g(o.fullName)}`),e.write(JSON.stringify(o)+`
33
33
  `);for(const o of r)o.fullName.type==="template"&&(s.debug(`Dumping to pl-tester: ${g(o.fullName)} ${o.srcName}`),e.write(JSON.stringify(o)+`
@@ -36,8 +36,8 @@ https://marketplace.visualstudio.com/items?itemName=jaydenlin.ctags-support`);re
36
36
  `));for(const o of n.allAssets())s.debug(`Dumping to pl-tester: ${g(o.fullName)}`),e.write(JSON.stringify(o)+`
37
37
  `);for(const o of r)o.fullName.type==="asset"&&(s.debug(`Dumping to pl-tester: ${g(o.fullName)}`),e.write(JSON.stringify(o)+`
38
38
  `));for(const o of r)o.fullName.type==="test"&&(s.debug(`Dumping to pl-tester: ${g(o.fullName)} ${o.srcName}`),e.write(JSON.stringify(o)+`
39
- `))}function bt(s,e,t){const r=M(),n=R(s,r,"dist","src","");if(!e){for(const i of n)i.fullName.type==="library"&&t.write(JSON.stringify(i)+`
39
+ `))}function vt(s,e,t){const r=M(),n=R(s,r,"dist","src","");if(!e){for(const i of n)i.fullName.type==="library"&&t.write(JSON.stringify(i)+`
40
40
  `);return}const o=re(s,r,"dist");for(const i of n)i.fullName.type==="library"&&o.addLib(i);for(const i of o.allLibs())t.write(JSON.stringify(i)+`
41
41
  `)}function I(s,e,t){const r=M(),n=R(s,r,"dist","src","");for(const o of n)o.fullName.type===t&&e.write(JSON.stringify(o)+`
42
- `)}function vt(s,e){I(s,e,"template")}function Et(s,e){I(s,e,"software")}function $t(s,e){I(s,e,"asset")}function Nt(s,e){I(s,e,"test")}function Oe(s,...e){const t=ye.spawn(s,e,{stdio:["pipe","inherit","inherit"]});return t.stdin.on("error",r=>{r.code}),t}function Fe(s){return new Promise((e,t)=>{s.on("close",r=>{e(r)}),s.on("error",r=>{t(r)})})}const S=class S extends h.Command{async run(){const{flags:e,argv:t}=await this.parse(S),r=N(e["log-level"]),n=t.length==0?["./src"]:t,o=Oe(ve.TengoTesterBinaryPath,"check","--log-level",e["log-level"],"--artifacts","-",...n);try{ie(r,o.stdin)}catch(i){r.error(i)}finally{o.stdin.end();const i=await Fe(o);process.exit(i)}}};l(S,"description","check tengo sources for language processor an"),l(S,"strict",!1),l(S,"flags",{...ne}),l(S,"examples",["<%= config.bin %> <%= command.id %>"]);let K=S;const k=class k extends h.Command{async run(){const{flags:e}=await this.parse(k),t=N(e["log-level"]),r=this.argv.length==0?["./src"]:this.argv,n=Oe(ve.TengoTesterBinaryPath,"run","--log-level",e["log-level"],"--artifacts","-",...r);try{ie(t,n.stdin)}catch(o){t.error(o)}finally{n.stdin.end();const o=await Fe(n);process.exit(o)}}};l(k,"description","run tengo unit tests (.test.tengo)"),l(k,"strict",!1),l(k,"flags",{...ne}),l(k,"examples",["<%= config.bin %> <%= command.id %>"]);let X=k;class Y extends h.Command{async run(){const e=N();ie(e,D.stdout)}}l(Y,"description","parse sources in current package and dump all found artifacts to stdout"),l(Y,"examples",["<%= config.bin %> <%= command.id %>"]);class H extends h.Command{async run(){const e=N();$t(e,D.stdout)}}l(H,"description","parse sources in current package and dump all found assets to stdout"),l(H,"examples",["<%= config.bin %> <%= command.id %>"]);const T=class T extends h.Command{async run(){const{flags:e}=await this.parse(T),t=N();bt(t,e.deps,D.stdout)}};l(T,"description","parse sources in current package and dump all found libs to stdout"),l(T,"examples",["<%= config.bin %> <%= command.id %>"]),l(T,"flags",{deps:h.Flags.boolean({name:"deps",description:"add also all libraries found in node_modules"})});let Q=T;class ee extends h.Command{async run(){const e=N();Et(e,D.stdout)}}l(ee,"description","parse sources in current package and dump all found software to stdout"),l(ee,"examples",["<%= config.bin %> <%= command.id %>"]);class te extends h.Command{async run(){const e=N();vt(e,D.stdout)}}l(te,"description","parse sources in current package and dump all found templates to stdout"),l(te,"examples",["<%= config.bin %> <%= command.id %>"]);class se extends h.Command{async run(){const e=N();Nt(e,D.stdout)}}l(se,"description","parse sources in current package and dump all found tests to stdout"),l(se,"examples",["<%= config.bin %> <%= command.id %>"]);const St={build:Z,check:K,test:X,"dump:all":Y,"dump:assets":H,"dump:libs":Q,"dump:software":ee,"dump:templates":te,"dump:tests":se};exports.COMMANDS=St;
42
+ `)}function Et(s,e){I(s,e,"template")}function $t(s,e){I(s,e,"software")}function Nt(s,e){I(s,e,"asset")}function St(s,e){I(s,e,"test")}function Oe(s,...e){const t=ye.spawn(s,e,{stdio:["pipe","inherit","inherit"]});return t.stdin.on("error",r=>{r.code}),t}function Fe(s){return new Promise((e,t)=>{s.on("close",r=>{e(r)}),s.on("error",r=>{t(r)})})}const S=class S extends h.Command{async run(){const{flags:e,argv:t}=await this.parse(S),r=N(e["log-level"]),n=t.length==0?["./src"]:t,o=Oe(ve.TengoTesterBinaryPath,"check","--log-level",e["log-level"],"--artifacts","-",...n);try{ie(r,o.stdin)}catch(i){r.error(i)}finally{o.stdin.end();const i=await Fe(o);process.exit(i)}}};l(S,"description","check tengo sources for language processor an"),l(S,"strict",!1),l(S,"flags",{...ne}),l(S,"examples",["<%= config.bin %> <%= command.id %>"]);let K=S;const k=class k extends h.Command{async run(){const{flags:e}=await this.parse(k),t=N(e["log-level"]),r=this.argv.length==0?["./src"]:this.argv,n=Oe(ve.TengoTesterBinaryPath,"run","--log-level",e["log-level"],"--artifacts","-",...r);try{ie(t,n.stdin)}catch(o){t.error(o)}finally{n.stdin.end();const o=await Fe(n);process.exit(o)}}};l(k,"description","run tengo unit tests (.test.tengo)"),l(k,"strict",!1),l(k,"flags",{...ne}),l(k,"examples",["<%= config.bin %> <%= command.id %>"]);let X=k;class Y extends h.Command{async run(){const e=N();ie(e,D.stdout)}}l(Y,"description","parse sources in current package and dump all found artifacts to stdout"),l(Y,"examples",["<%= config.bin %> <%= command.id %>"]);class H extends h.Command{async run(){const e=N();Nt(e,D.stdout)}}l(H,"description","parse sources in current package and dump all found assets to stdout"),l(H,"examples",["<%= config.bin %> <%= command.id %>"]);const T=class T extends h.Command{async run(){const{flags:e}=await this.parse(T),t=N();vt(t,e.deps,D.stdout)}};l(T,"description","parse sources in current package and dump all found libs to stdout"),l(T,"examples",["<%= config.bin %> <%= command.id %>"]),l(T,"flags",{deps:h.Flags.boolean({name:"deps",description:"add also all libraries found in node_modules"})});let Q=T;class ee extends h.Command{async run(){const e=N();$t(e,D.stdout)}}l(ee,"description","parse sources in current package and dump all found software to stdout"),l(ee,"examples",["<%= config.bin %> <%= command.id %>"]);class te extends h.Command{async run(){const e=N();Et(e,D.stdout)}}l(te,"description","parse sources in current package and dump all found templates to stdout"),l(te,"examples",["<%= config.bin %> <%= command.id %>"]);class se extends h.Command{async run(){const e=N();St(e,D.stdout)}}l(se,"description","parse sources in current package and dump all found tests to stdout"),l(se,"examples",["<%= config.bin %> <%= command.id %>"]);const kt={build:Z,check:K,test:X,"dump:all":Y,"dump:assets":H,"dump:libs":Q,"dump:software":ee,"dump:templates":te,"dump:tests":se};exports.COMMANDS=kt;
43
43
  //# sourceMappingURL=index.js.map