svhost 1.0.16 → 1.0.17

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,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var ie=Object.create;var Q=Object.defineProperty;var ne=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var le=Object.getPrototypeOf,ce=Object.prototype.hasOwnProperty;var he=(i,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of ae(e))!ce.call(i,s)&&s!==r&&Q(i,s,{get:()=>e[s],enumerable:!(t=ne(e,s))||t.enumerable});return i};var L=(i,e,r)=>(r=i!=null?ie(le(i)):{},he(e||!i||!i.__esModule?Q(r,"default",{value:i,enumerable:!0}):r,i));var E=L(require("path"));var A=L(require("fs-extra")),X=require("fs/promises"),y=L(require("path"));async function W(i){try{return await A.default.exists(i)}catch{return!1}}async function I(i){try{return(await A.default.stat(i)).isFile()}catch{return!1}}async function C(i){try{return(await A.default.stat(i)).isDirectory()}catch{return!1}}async function G(i,e){let{recursive:r=!1,filesOnly:t=!1,dirsOnly:s=!1,returnType:o="absolute",forwardSlashes:n=!1,ignorefile:l,quiet:a=!0,includeIgnorefile:h=!1}=e||{};return new Promise(async(c,d)=>{function p(m){return n?m.replace(/\\/g,"/"):m}a||console.log(`Reading directory: ${i}`,{recursive:r,filesOnly:t,dirsOnly:s,returnType:o,forwardSlashes:n,quiet:a,includeIgnorefile:h,ignorefile:l});try{if(!await W(i))return d(new Error(`Directory does not exist: ${i}`));if(!await C(i))return d(new Error(`Path is not a directory: ${i}`));let u=(await(0,X.readdir)(i,{withFileTypes:!0,recursive:r})).filter(f=>!h&&f.name===".ignore"&&y.default.resolve(i)===y.default.resolve(f.parentPath)?!1:t?f.isFile():s?f.isDirectory():!0);if(l?.data||l?.path||await W(y.default.join(i,".ignore"))){a||console.log(`Applying ignore rules from: ${l?.path||"provided data"}`);let f="";if(l?.data)f=l.data;else if(l?.path)try{f=await A.default.readFile(l.path,"utf8")}catch(g){a||console.warn(`Warning: Could not read ignorefile at ${l.path}: ${g.message}`)}else try{f=await A.default.readFile(y.default.join(i,".ignore"),"utf8")}catch(g){a||console.warn(`Warning: Could not read ignorefile at ${y.default.join(i,".ignore")}: ${g.message}`)}if(f){a||(console.log(`All .ignore data:
3
- ------------------------`),console.log(f),console.log("------------------------"));let g="",x="",K=v=>v?.replace(/(([ \t]*)#.*$)/gm,"")?.replace(/^([ \t])*|([ \t])*$/gm,"")?.split(/\r?\n/)?.filter(P=>P.length),oe=v=>v.match(/RegExp[ \s]*\([ \s]*['"`](?<regex>.*)['"`][ \s]*,[ \s]*['"`](?<flags>.*)['"`][ \s]*\)|RegExp[ \s]*\([ \s]*['"`](?<regex>.*)['"`][ \s]*\)/m),Y=(v,z,P)=>v.filter(J=>{let $=p(y.default.relative(i,y.default.resolve(J.parentPath,J.name)));for(let Z of z){let q=oe(Z);if($){if(q){let M=q?.groups?.regex||"",U=q?.groups?.flags||"m";if($?.match(new RegExp(M,U)))return P?(a||console.log(`Included path "${$}" via Regex("${M}","${U}") Match pattern.`),!0):(a||console.log(`Ignored path "${$}" via Regex("${M}","${U}") Match pattern.`),!1)}if($?.match(new RegExp(`^${Z}$`,"gm")))return P?(a||console.log(`Included path "${$}" via Match pattern.`),!0):(a||console.log(`Ignored path "${$}" via Match pattern.`),!1)}}return!P});if(f.match(/^[ \t]*#?[ \t]*EXCLUDE EXCLUDE EXCLUDE[ \t]*$/gm)&&(f.match(/^[ \t]*#[ \t]*EXCLUDE EXCLUDE EXCLUDE[ \t]*$/gm)?g=f.replace(/^[ \t]*#[ \t]*EXCLUDE EXCLUDE EXCLUDE[ \t]*.*/gms,""):x=f.replace(/.*[ \t]*EXCLUDE EXCLUDE EXCLUDE[ \t]*$/gms,"")),a||(console.log(`Include data:
2
+ "use strict";var ie=Object.create;var Q=Object.defineProperty;var ne=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var le=Object.getPrototypeOf,ce=Object.prototype.hasOwnProperty;var he=(i,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of ae(e))!ce.call(i,s)&&s!==r&&Q(i,s,{get:()=>e[s],enumerable:!(t=ne(e,s))||t.enumerable});return i};var L=(i,e,r)=>(r=i!=null?ie(le(i)):{},he(e||!i||!i.__esModule?Q(r,"default",{value:i,enumerable:!0}):r,i));var E=L(require("path"));var A=L(require("fs-extra")),X=require("fs/promises"),y=L(require("path"));async function W(i){try{return await A.default.exists(i)}catch{return!1}}async function I(i){try{return(await A.default.stat(i)).isFile()}catch{return!1}}async function C(i){try{return(await A.default.stat(i)).isDirectory()}catch{return!1}}async function G(i,e){let{recursive:r=!1,filesOnly:t=!1,dirsOnly:s=!1,returnType:o="absolute",forwardSlashes:a=!1,ignorefile:l,quiet:n=!0,includeIgnorefile:h=!1}=e||{};return new Promise(async(c,d)=>{function p(m){return a?m.replace(/\\/g,"/"):m}n||console.log(`Reading directory: ${i}`,{recursive:r,filesOnly:t,dirsOnly:s,returnType:o,forwardSlashes:a,quiet:n,includeIgnorefile:h,ignorefile:l});try{if(!await W(i))return d(new Error(`Directory does not exist: ${i}`));if(!await C(i))return d(new Error(`Path is not a directory: ${i}`));let u=(await(0,X.readdir)(i,{withFileTypes:!0,recursive:r})).filter(f=>!h&&f.name===".ignore"&&y.default.resolve(i)===y.default.resolve(f.parentPath)?!1:t?f.isFile():s?f.isDirectory():!0);if(l?.data||l?.path||await W(y.default.join(i,".ignore"))){n||console.log(`Applying ignore rules from: ${l?.path||"provided data"}`);let f="";if(l?.data)f=l.data;else if(l?.path)try{f=await A.default.readFile(l.path,"utf8")}catch(g){n||console.warn(`Warning: Could not read ignorefile at ${l.path}: ${g.message}`)}else try{f=await A.default.readFile(y.default.join(i,".ignore"),"utf8")}catch(g){n||console.warn(`Warning: Could not read ignorefile at ${y.default.join(i,".ignore")}: ${g.message}`)}if(f){n||(console.log(`All .ignore data:
3
+ ------------------------`),console.log(f),console.log("------------------------"));let g="",x="",K=v=>v?.replace(/(([ \t]*)#.*$)/gm,"")?.replace(/^([ \t])*|([ \t])*$/gm,"")?.split(/\r?\n/)?.filter(P=>P.length),oe=v=>v.match(/RegExp[ \s]*\([ \s]*['"`](?<regex>.*)['"`][ \s]*,[ \s]*['"`](?<flags>.*)['"`][ \s]*\)|RegExp[ \s]*\([ \s]*['"`](?<regex>.*)['"`][ \s]*\)/m),Y=(v,z,P)=>v.filter(J=>{let $=p(y.default.relative(i,y.default.resolve(J.parentPath,J.name)));for(let Z of z){let q=oe(Z);if($){if(q){let M=q?.groups?.regex||"",U=q?.groups?.flags||"m";if($?.match(new RegExp(M,U)))return P?(n||console.log(`Included path "${$}" via Regex("${M}","${U}") Match pattern.`),!0):(n||console.log(`Ignored path "${$}" via Regex("${M}","${U}") Match pattern.`),!1)}if($?.match(new RegExp(`^${Z}$`,"gm")))return P?(n||console.log(`Included path "${$}" via Match pattern.`),!0):(n||console.log(`Ignored path "${$}" via Match pattern.`),!1)}}return!P});if(f.match(/^[ \t]*#?[ \t]*EXCLUDE EXCLUDE EXCLUDE[ \t]*$/gm)&&(f.match(/^[ \t]*#[ \t]*EXCLUDE EXCLUDE EXCLUDE[ \t]*$/gm)?g=f.replace(/^[ \t]*#[ \t]*EXCLUDE EXCLUDE EXCLUDE[ \t]*.*/gms,""):x=f.replace(/.*[ \t]*EXCLUDE EXCLUDE EXCLUDE[ \t]*$/gms,"")),n||(console.log(`Include data:
4
4
  ------------------------`),console.log(x),console.log("------------------------"),console.log(`Exclude data - EXCLUDE EXCLUDE EXCLUDE:
5
- ------------------------`),console.log(g),console.log("------------------------")),console.log("Applying exclude and include rules from .ignore file"),console.log("Initial file count before applying ignore rules:",u.length),g){let v=K(g);a||console.log("Exclude lines:",v),u=Y(u,v,!1)}if(x){let v=K(x);a||console.log("Include lines:",v),u=Y(u,v,!0)}console.log("Final file count after applying ignore rules:",u.length)}}let _=y.default.resolve(i);switch(o){case"absolute":{let f=u.map(g=>{let x=y.default.join(g.parentPath,g.name);return p(x)});return c(f)}case"relative":{let f=u.map(g=>{let x=y.default.join(g.parentPath,g.name);return p(y.default.relative(_,x))});return c(f)}case"dirent":return c(u);case"all":{let f=u.map(g=>{let x=y.default.join(g.parentPath,g.name);return{name:g.name,absolutePath:p(x),relativePath:p(y.default.relative(_,x)),isFile:g.isFile(),isDirectory:g.isDirectory()}});return c(f)}default:return d(new Error(`Invalid returnType option: ${o}`))}}catch(m){d(m)}})}(async(i=!1)=>{let e=`
5
+ ------------------------`),console.log(g),console.log("------------------------")),console.log("Applying exclude and include rules from .ignore file"),console.log("Initial file count before applying ignore rules:",u.length),g){let v=K(g);n||console.log("Exclude lines:",v),u=Y(u,v,!1)}if(x){let v=K(x);n||console.log("Include lines:",v),u=Y(u,v,!0)}console.log("Final file count after applying ignore rules:",u.length)}}let _=y.default.resolve(i);switch(o){case"absolute":{let f=u.map(g=>{let x=y.default.join(g.parentPath,g.name);return p(x)});return c(f)}case"relative":{let f=u.map(g=>{let x=y.default.join(g.parentPath,g.name);return p(y.default.relative(_,x))});return c(f)}case"dirent":return c(u);case"all":{let f=u.map(g=>{let x=y.default.join(g.parentPath,g.name);return{name:g.name,absolutePath:p(x),relativePath:p(y.default.relative(_,x)),isFile:g.isFile(),isDirectory:g.isDirectory()}});return c(f)}default:return d(new Error(`Invalid returnType option: ${o}`))}}catch(m){d(m)}})}(async(i=!1)=>{let e=`
6
6
  # Ignore files and directories
7
7
 
8
8
  dir1
@@ -11,14 +11,14 @@ EXCLUDE EXCLUDE EXCLUDE
11
11
  react-app.yml
12
12
  RegExp("node-app.yml$")
13
13
 
14
- `;if(i){let t=y.default.resolve("src/classes/svhost-nginx/sample/data"),s=await G(t,{recursive:!0,returnType:"relative",forwardSlashes:!0,filesOnly:!1,quiet:!1,ignorefile:{data:e}});console.log("Directory contents:",s)}})(!1);var k=class{constructor(e){this.svhostNginx=e}};function ee(i){let e=i?.date||new Date;switch(i?.format||"standard"){case"email":{let t={timeZone:"Asia/Kolkata",year:"numeric",month:"short",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1,timeZoneName:"longOffset"};return new Intl.DateTimeFormat("en-IN",t).format(e)}case"standard":{let t=e.getFullYear(),s=String(e.getMonth()+1).padStart(2,"0"),o=String(e.getDate()).padStart(2,"0"),n=String(e.getHours()).padStart(2,"0"),l=String(e.getMinutes()).padStart(2,"0"),a=String(e.getSeconds()).padStart(2,"0");return`${t}-${s}-${o} ${n}:${l}:${a}`}}}var w=require("fs/promises");var te=require("js-yaml"),H=require("fs/promises"),re=require("path"),F=class{constructor(){}async _readFile(e){if(!e||typeof e!="string")throw new TypeError("Path must be a non-empty string");let r=(0,re.resolve)(e);if(!(await(0,H.stat)(r)).isFile())throw new Error(`Not a readable file: ${r}`);try{return await(0,H.readFile)(r,{encoding:"utf8"})}catch(s){let o=s;throw o.code==="EACCES"||o.code==="EPERM"?new Error(`No read permission for file: ${r}`,{cause:o}):new Error(`Error reading file: ${r}`,{cause:o})}}_resolveVars(e,r){return JSON.parse(JSON.stringify(e),(t,s)=>typeof s=="string"?s.replace(/\$\{(\w+)\}/g,(o,n)=>String(r[n])):s)}async read(e){let r=await this._readFile(e),t=(0,te.load)(r);return this._resolveVars(t,t?.vars)}};var V=class{};function R(i,e={}){let{notAllowed:r=[void 0,null,"",0],message:t=s=>`"${s}" is required.`}=e;if(typeof i=="object"&&Object.keys(i).length){Object.entries(i).forEach(([s,o])=>{if(r.includes(o))throw new Error(t(s));if(e.noEmptyArray&&Array.isArray(o)&&o.length===0)throw new Error(`${s} cannot be an empty array.`);if(e.noEmptyObject&&o instanceof Object&&Object.keys(o).length===0)throw new Error(`${s} cannot be an empty object.`)});return}throw new Error('Invalid arg passed to "validateRequired"')}function b(i,e={}){let{tab:r=1,joinArray:t=!1,tabSize:s=4}=e;if(typeof i=="string")return b([i],e);if(Array.isArray(i)){let o=" ".repeat(r*s),n=i.map(l=>`${o}${l}`);return t?n.join(`
15
- `):n}else throw new Error("Argument passed to indent method should be string or string[].")}var D=class{constructor(e){this.order=10;this.items=[];R({location:e}),this.location=e}setItem(e=""){Array.isArray(e)?this.items.push(...e):this.items.push(e)}setOrder(e){this.order=e}getData(e){let{joinArray:r=!1}=e||{},t=[];return t.push(`location ${this.location} {`),t.push(...b(this.items)),t.push("}"),r?t.join(`
16
- `):t}};var S=class{constructor(e){let{host:r="localhost",port:t,location:s="/",hostUri:o="/",headers:n=new Map,resetHeader:l=!1}=e;if(R({port:t},{message:a=>`"${a}" is required in ReverseProxy constructor.`}),this.host=r,this.port=t,this.location=s,this.hostUri=o,this.resetHeader=l,!(n instanceof Map))throw new Error('"headers" must be a Map');this.headers=new Map,this.headerArgs=n,this.setDefaultHeaders()}setHost(e){this.host=e}setPort(e){this.port=e}setResetHeader(e){this.resetHeader=e,this.setDefaultHeaders()}setHeader(e,r){this.headers.set(e,r)}deleteHeader(e){this.headers.delete(e)}getHeader(e){return this.headers.get(e)}getHeaders(){return new Map(this.headers)}getHeadersList(){let e=[];for(let[r,t]of this.headers.entries())e.push(`${r} ${t};`);return e}setDefaultHeaders(e){let r=e?.reset||!1;this.headers.clear();let t=new Map;t.set("proxy_pass",`http://${this.host}:${this.port}${this.hostUri}`),r||(this.resetHeader||(t.set("proxy_set_header Host","$host"),t.set("proxy_set_header X-Real-IP","$remote_addr"),t.set("proxy_set_header X-Forwarded-Host","$http_host"),t.set("proxy_set_header X-Forwarded-Proto","$scheme"),t.set("proxy_set_header X-Forwarded-For","$proxy_add_x_forwarded_for"),t.set("proxy_cache_bypass","$http_upgrade"),t.set("proxy_http_version","1.1"),t.set("proxy_set_header Upgrade","$http_upgrade"),t.set("proxy_set_header Connection","upgrade")),this.headers=new Map([...t,...this.headerArgs]))}getData(e={}){let{joinArray:r=!1}=e,t=this.getHeadersList(),s=new D(this.location);return s.setItem(t),s.getData({joinArray:r})}};var N=class{constructor(){this.serverItems=[];this.sslItems=[];this.locationBlocks=[];this.redirectItems=[]}addServerItem(e){Array.isArray(e)?this.serverItems.push(...e):this.serverItems.push(e)}addSslItem(e){Array.isArray(e)?this.sslItems.push(...e):this.sslItems.push(e)}addLocationBlock(e=null){e&&e instanceof D&&this.locationBlocks.push(e)}addRedirectItem(e){Array.isArray(e)?this.redirectItems.push(...e):this.redirectItems.push(e)}getData(e={}){let{joinArray:r=!1}=e,t=[];if(t.push("server {"),t.push(...b(this.serverItems)),this.sslItems?.length&&(t.push(`
14
+ `;if(i){let t=y.default.resolve("src/classes/svhost-nginx/sample/data"),s=await G(t,{recursive:!0,returnType:"relative",forwardSlashes:!0,filesOnly:!1,quiet:!1,ignorefile:{data:e}});console.log("Directory contents:",s)}})(!1);var k=class{constructor(e){this.svhostNginx=e}};function ee(i){let e=i?.date||new Date;switch(i?.format||"standard"){case"email":{let t={timeZone:"Asia/Kolkata",year:"numeric",month:"short",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1,timeZoneName:"longOffset"};return new Intl.DateTimeFormat("en-IN",t).format(e)}case"standard":{let t=e.getFullYear(),s=String(e.getMonth()+1).padStart(2,"0"),o=String(e.getDate()).padStart(2,"0"),a=String(e.getHours()).padStart(2,"0"),l=String(e.getMinutes()).padStart(2,"0"),n=String(e.getSeconds()).padStart(2,"0");return`${t}-${s}-${o} ${a}:${l}:${n}`}}}var w=require("fs/promises");var te=require("js-yaml"),H=require("fs/promises"),re=require("path"),F=class{constructor(){}async _readFile(e){if(!e||typeof e!="string")throw new TypeError("Path must be a non-empty string");let r=(0,re.resolve)(e);if(!(await(0,H.stat)(r)).isFile())throw new Error(`Not a readable file: ${r}`);try{return await(0,H.readFile)(r,{encoding:"utf8"})}catch(s){let o=s;throw o.code==="EACCES"||o.code==="EPERM"?new Error(`No read permission for file: ${r}`,{cause:o}):new Error(`Error reading file: ${r}`,{cause:o})}}_resolveVars(e,r){return JSON.parse(JSON.stringify(e),(t,s)=>typeof s=="string"?s.replace(/\$\{(\w+)\}/g,(o,a)=>String(r[a])):s)}async read(e){let r=await this._readFile(e),t=(0,te.load)(r);return this._resolveVars(t,t?.vars)}};var V=class{};function R(i,e={}){let{notAllowed:r=[void 0,null,"",0],message:t=s=>`"${s}" is required.`}=e;if(typeof i=="object"&&Object.keys(i).length){Object.entries(i).forEach(([s,o])=>{if(r.includes(o))throw new Error(t(s));if(e.noEmptyArray&&Array.isArray(o)&&o.length===0)throw new Error(`${s} cannot be an empty array.`);if(e.noEmptyObject&&o instanceof Object&&Object.keys(o).length===0)throw new Error(`${s} cannot be an empty object.`)});return}throw new Error('Invalid arg passed to "validateRequired"')}function b(i,e={}){let{tab:r=1,joinArray:t=!1,tabSize:s=4}=e;if(typeof i=="string")return b([i],e);if(Array.isArray(i)){let o=" ".repeat(r*s),a=i.map(l=>`${o}${l}`);return t?a.join(`
15
+ `):a}else throw new Error("Argument passed to indent method should be string or string[].")}var D=class{constructor(e){this.order=10;this.items=[];R({location:e}),this.location=e}setItem(e=""){Array.isArray(e)?this.items.push(...e):this.items.push(e)}setOrder(e){this.order=e}getData(e){let{joinArray:r=!1}=e||{},t=[];return t.push(`location ${this.location} {`),t.push(...b(this.items)),t.push("}"),r?t.join(`
16
+ `):t}};var S=class{constructor(e){let{host:r="localhost",port:t,location:s="/",hostUri:o="/",headers:a=new Map,resetHeader:l=!1}=e;if(R({port:t},{message:n=>`"${n}" is required in ReverseProxy constructor.`}),this.host=r,this.port=t,this.location=s,this.hostUri=o,this.resetHeader=l,!(a instanceof Map))throw new Error('"headers" must be a Map');this.headers=new Map,this.headerArgs=a,this.setDefaultHeaders()}setHost(e){this.host=e}setPort(e){this.port=e}setResetHeader(e){this.resetHeader=e,this.setDefaultHeaders()}setHeader(e,r){this.headers.set(e,r)}deleteHeader(e){this.headers.delete(e)}getHeader(e){return this.headers.get(e)}getHeaders(){return new Map(this.headers)}getHeadersList(){let e=[];for(let[r,t]of this.headers.entries())e.push(`${r} ${t};`);return e}setDefaultHeaders(e){let r=e?.reset||!1;this.headers.clear();let t=new Map;t.set("proxy_pass",`http://${this.host}:${this.port}${this.hostUri}`),r||(this.resetHeader||(t.set("proxy_set_header Host","$host"),t.set("proxy_set_header X-Real-IP","$remote_addr"),t.set("proxy_set_header X-Forwarded-Host","$http_host"),t.set("proxy_set_header X-Forwarded-Proto","$scheme"),t.set("proxy_set_header X-Forwarded-For","$proxy_add_x_forwarded_for"),t.set("proxy_cache_bypass","$http_upgrade"),t.set("proxy_http_version","1.1"),t.set("proxy_set_header Upgrade","$http_upgrade"),t.set("proxy_set_header Connection","upgrade")),this.headers=new Map([...t,...this.headerArgs]))}getData(e={}){let{joinArray:r=!1}=e,t=this.getHeadersList(),s=new D(this.location);return s.setItem(t),s.getData({joinArray:r})}};var N=class{constructor(){this.serverItems=[];this.sslItems=[];this.locationBlocks=[];this.redirectItems=[]}addServerItem(e){Array.isArray(e)?this.serverItems.push(...e):this.serverItems.push(e)}addSslItem(e){Array.isArray(e)?this.sslItems.push(...e):this.sslItems.push(e)}addLocationBlock(e=null){e&&e instanceof D&&this.locationBlocks.push(e)}addRedirectItem(e){Array.isArray(e)?this.redirectItems.push(...e):this.redirectItems.push(e)}getData(e={}){let{joinArray:r=!1}=e,t=[];if(t.push("server {"),t.push(...b(this.serverItems)),this.sslItems?.length&&(t.push(`
17
17
  `),this.sslItems.forEach(s=>{t.push(b(s))})),this.redirectItems?.length)t.push(`
18
- `),this.redirectItems.forEach(s=>{t.push(b(s))});else if(this.locationBlocks?.length){let s=this.locationBlocks.toSorted((o,n)=>o.order-n.order);t.push(""),s.forEach(o=>{t.push(""),t.push(...b(o.getData()))})}return t.push("}"),r?t.join(`
19
- `):t}};var T=class{constructor(e){let{id:r,domainName:t="",tld:s="com",serverNames:o=[],redirectToFirstServer:n=!0,appType:l="reverseProxy",reverseProxies:a=new Map,ssl:h=!1,sslCertificateName:c,redirectToHttps:d=!1,rootDirectory:p="/var/www/html",http_port:m=80,https_port:u="443 ssl",meta:_}=e||{};if(R({id:r,domainName:t,tld:s,serverNames:o,rootDirectory:p,appType:l,http_port:m,https_port:u},{noEmptyArray:!0,noEmptyObject:!0}),this.reverseProxies=a,!Array.isArray(o)||o.length===0)throw new Error('"serverNames" must be a non-empty array of server-names');this.id=r,this.domainName=t,this.tld=s,this.serverNames=o,this.redirectToFirstServer=n,this.appType=l,this.ssl=h,this.sslCertificateName=c??`${t}.${s}`,this.redirectToHttps=d,this.rootDirectory=p,this.http_port=m,this.https_port=u,this.meta=_??{},this.meta.group=this.meta?.group??"default"}setReverseProxy(e){if(e instanceof S&&e?.location){if(this.reverseProxies)this.reverseProxies.set(e?.location,e);else{let r=`Error: Server ID: ${this.id} - reverseProxies Map is not initialized.`;throw console.error(r),new Error(r)}return}console.warn("Error: Server ID: ${this.id} - Invalid reverseProxy passed",JSON.stringify(e))}getLocationBlocks(){let e=[];if(this.reverseProxies?.size&&this.reverseProxies instanceof Map)this.reverseProxies?.forEach(r=>{let t=new D(r.location);t.setItem(r.getHeadersList()),e.push(t)});else{let r=new D("/");r.setItem("try_files $uri $uri/ =404;"),e.push(r)}return e}createServerBlock(e={}){let{joinArray:r=!1,serverDirectives:t=[],addSslCertificates:s=!1,redirects:o=[],locationBlocks:n=[]}=e,l=new N;if(t?.length&&t.forEach(a=>{l.addServerItem(a)}),s){let a=[];if(this.ssl===void 0)throw new Error(`Please provide/set valid value for "this.ssl" in 'Vhost' constructor, if you want to redirect to HTTPS`);if(this.ssl===!0)l.addSslItem([`ssl_certificate /etc/letsencrypt/live/${this.sslCertificateName}/fullchain.pem;`,`ssl_certificate_key /etc/letsencrypt/live/${this.sslCertificateName}/privkey.pem;`,...a]);else if(this.ssl!==!1)if(typeof this.ssl=="object")l.addSslItem([`ssl_certificate ${this.ssl?.crt};`,`ssl_certificate_key ${this.ssl?.key};`,...a]);else throw new Error("Something Went Wrong in SSL Directives.")}if(o?.length)l.addRedirectItem(o);else{let h=[...this.getLocationBlocks(),...n].sort((c,d)=>c?.order-d?.order);h?.length&&h.forEach(c=>{l.addLocationBlock(c)})}return l.getData({joinArray:r})}getIndexDirective(){let e="index index.html index.htm";switch(this.appType){case"reverseProxy":return`${e};`;case"html":return`${e};`;case"react":return`${e};`;case"node":return`${e};`;case"react-node":return`${e};`;case"php":return`index.php ${e};`;case"python":return`index.py ${e};`;default:return`${e}; # Default`}}getServerDirectives(e={}){let{serverNames:r,redirect:t=!1,port:s=this.http_port}=e,o=[`listen ${s};`,`listen [::]:${s};`,"",`server_name ${r?.join(" ")};`];return t||o.push("",this.getIndexDirective(),`root ${this.rootDirectory};`),o}_generateFullServerBlock(e){let{redirectHttps:r=!1,redirectWWW:t=!1,port:s,onlyFirstServerName:o=!1}=e||{},n=[];if(r||t){let h=r||s===this.https_port?"s":"",c=t?this.serverNames?.[0]:"$host";n.push(`return 301 http${h}://${c}$request_uri;`)}let l=t?this.serverNames?.slice(1):this.serverNames;return this.createServerBlock({serverDirectives:this.getServerDirectives({serverNames:o?[l?.[0]]:l,port:s,redirect:r||t}),addSslCertificates:!!(this.ssl&&s===this.https_port),redirects:n?.length?n:void 0})}getData(e){let{joinArray:r=!1}=e??{},t=[],s=this.serverNames,o=this.redirectToFirstServer&&this.serverNames?.length>1?this.serverNames?.[0]:"",n=this.redirectToHttps;return n?o?(t.push(this._generateFullServerBlock({port:this.http_port,redirectHttps:!0,redirectWWW:!0})),t.push(this._generateFullServerBlock({port:this.https_port,redirectHttps:!0,redirectWWW:!0})),t.push(this._generateFullServerBlock({port:this.http_port,redirectHttps:!0,redirectWWW:!1,onlyFirstServerName:!0})),t.push(this._generateFullServerBlock({port:this.https_port,redirectHttps:!1,redirectWWW:!1,onlyFirstServerName:!0}))):(t.push(this._generateFullServerBlock({port:this.http_port,redirectHttps:!0,redirectWWW:!1})),t.push(this._generateFullServerBlock({port:this.https_port,redirectHttps:!1,redirectWWW:!1}))):o?(t.push(this._generateFullServerBlock({port:this.http_port,redirectHttps:!1,redirectWWW:!0})),t.push(this._generateFullServerBlock({port:this.https_port,redirectHttps:!1,redirectWWW:!0})),t.push(this._generateFullServerBlock({port:this.http_port,redirectHttps:!1,redirectWWW:!1,onlyFirstServerName:!0})),t.push(this._generateFullServerBlock({port:this.https_port,redirectHttps:!1,redirectWWW:!1,onlyFirstServerName:!0}))):(console.log(22222222222222,{redirectToHttps:n,redirectToFirtServerName:o,serverNames:s}),t.push(this._generateFullServerBlock({port:this.http_port,redirectHttps:!1,redirectWWW:!1})),this.ssl&&t.push(this._generateFullServerBlock({port:this.https_port,redirectHttps:!1,redirectWWW:!1}))),((a={})=>{let{joinArray:h=!1}=a,c=[];return t?.map((d,p)=>{c.push(...d),p+1<t?.length&&c.push("")}),h?c?.join(`
20
- `):c})({joinArray:r})}};var O=class{constructor(e){this.helper=new k(this)}async yamlToVhostInstances(e,r){let{quiet:t=!1}=r||{};try{let o=await new F().read(e),n=o?.vhosts||[],l=o?.meta||{};t||(console.log(`YAML Config Data : -------- Total VHosts in file "${e}":`,n.length),console.log("VHosts Default Meta:",{defaultMeta:l}));for(let h of n)t||(console.log("VHost Data:",h),console.log("VHost reverseProxies:",h?.reverseProxies));let a=[];return n.forEach(h=>{let c=structuredClone(h);c.meta={...l,...c.meta??{}},delete c.reverseProxies,console.log(222,c);let d=new T(c);a.push(d),t||(console.log("Processing VHost:",d.id),console.log("vhostData?.reverseProxies:",h?.reverseProxies)),[...h?.reverseProxies??[]].forEach(p=>{let[[m,u]]=Object.entries(p??{});t||console.log("Reverse Proxy Data:",{pathKey:m,proxyConfig:u}),u.location=m;let _=new S(u);d.setReverseProxy(_)})}),t||console.log(`Loaded (${a.length}) vhost(s) from YAML file: "${e}"`),a}catch(s){throw new Error(`Error reading YAML file "${e}": ${s?.message}`,{cause:s})}}async getVhostInstanceArray(e,r){let{quiet:t=!1}=r||{};try{return I(e)?await this.yamlToVhostInstances(e,{quiet:t}):(t||console.warn(`The path "${e}" is not a valid file.`),null)}catch(s){throw console.error("-----------------------------------"),console.error(`Error Message: ${s?.message}`),console.error("----------------- Complete Error ------------------"),console.error(s),console.error("-----------------------------------"),new Error(`YAML File Error, while importing "${e}": ${s?.message}`)}}async getVhostInstances(e,r){let{quiet:t=!1}=r||{};try{let s=await G(e,{recursive:!0,filesOnly:!0,returnType:"relative",forwardSlashes:!0,quiet:t});t||(console.log(4444,{quiet:t},{files:s}),console.log(s));let o=[];for(let n of s)if(n.endsWith(".yml")||n.endsWith(".yaml")){let l=E.default.resolve(e,n),a=await this.getVhostInstanceArray(l,{quiet:t});a?.length&&o.push(...a)}return o}catch(s){throw new Error(`Error in "getVhostInstances()" from directory "${e}": Error:"${s.message}"`,{cause:s})}}async ensureDir(e,r){let{quiet:t=!1,directoryName:s="Output"}=r||{};if(!await C(e))if(await C(E.default.dirname(e)))t||console.log(`## ${s} directory does not exist. Creating directory: "${e}"`),await(0,w.mkdir)(e,{recursive:!0});else throw new Error(`## ${s} directory does not exist: ${e}`)}getVhostConfigFileData(e,r){let{joinArray:t=!1}=r||{},s=e.getData()??[],o=e.reverseProxies?.size?[...e.reverseProxies].map(([l,a])=>`${l} => ${a?.host}:${a?.port}${a?.hostUri}`).join(", "):"",n=[`# Created at: ${ee()}`,`# ID: ${e.id}`,`# HOST (s): ${o}`,`# GROUP: ${e?.meta?.group}`,"###################################",`
18
+ `),this.redirectItems.forEach(s=>{t.push(b(s))});else if(this.locationBlocks?.length){let s=this.locationBlocks.toSorted((o,a)=>o.order-a.order);t.push(""),s.forEach(o=>{t.push(""),t.push(...b(o.getData()))})}return t.push("}"),r?t.join(`
19
+ `):t}};var T=class{constructor(e){let{id:r,domainName:t="",tld:s="com",serverNames:o=[],redirectToFirstServer:a=!0,appType:l="reverseProxy",reverseProxies:n=new Map,ssl:h=!1,sslCertificateName:c,redirectToHttps:d=!1,rootDirectory:p="/var/www/html",http_port:m=80,https_port:u="443 ssl",meta:_}=e||{};if(R({id:r,domainName:t,tld:s,serverNames:o,rootDirectory:p,appType:l,http_port:m,https_port:u},{noEmptyArray:!0,noEmptyObject:!0}),this.reverseProxies=n,!Array.isArray(o)||o.length===0)throw new Error('"serverNames" must be a non-empty array of server-names');this.id=r,this.domainName=t,this.tld=s,this.serverNames=o,this.redirectToFirstServer=a,this.appType=l,this.ssl=h,this.sslCertificateName=c??`${t}.${s}`,this.redirectToHttps=d,this.rootDirectory=p,this.http_port=m,this.https_port=u,this.meta=_??{},this.meta.group=this.meta?.group??"default"}setReverseProxy(e){if(e instanceof S&&e?.location){if(this.reverseProxies)this.reverseProxies.set(e?.location,e);else{let r=`Error: Server ID: ${this.id} - reverseProxies Map is not initialized.`;throw console.error(r),new Error(r)}return}console.warn("Error: Server ID: ${this.id} - Invalid reverseProxy passed",JSON.stringify(e))}getLocationBlocks(){let e=[];if(this.reverseProxies?.size&&this.reverseProxies instanceof Map)this.reverseProxies?.forEach(r=>{let t=new D(r.location);t.setItem(r.getHeadersList()),e.push(t)});else{let r=new D("/");r.setItem("try_files $uri $uri/ =404;"),e.push(r)}return e}createServerBlock(e={}){let{joinArray:r=!1,serverDirectives:t=[],addSslCertificates:s=!1,redirects:o=[],locationBlocks:a=[]}=e,l=new N;if(t?.length&&t.forEach(n=>{l.addServerItem(n)}),s){let n=[];if(this.ssl===void 0)throw new Error(`Please provide/set valid value for "this.ssl" in 'Vhost' constructor, if you want to redirect to HTTPS`);if(this.ssl===!0)l.addSslItem([`ssl_certificate /etc/letsencrypt/live/${this.sslCertificateName}/fullchain.pem;`,`ssl_certificate_key /etc/letsencrypt/live/${this.sslCertificateName}/privkey.pem;`,...n]);else if(this.ssl!==!1)if(typeof this.ssl=="object")l.addSslItem([`ssl_certificate ${this.ssl?.crt};`,`ssl_certificate_key ${this.ssl?.key};`,...n]);else throw new Error("Something Went Wrong in SSL Directives.")}if(o?.length)l.addRedirectItem(o);else{let h=[...this.getLocationBlocks(),...a].sort((c,d)=>c?.order-d?.order);h?.length&&h.forEach(c=>{l.addLocationBlock(c)})}return l.getData({joinArray:r})}getIndexDirective(){let e="index index.html index.htm";switch(this.appType){case"reverseProxy":return`${e};`;case"html":return`${e};`;case"react":return`${e};`;case"node":return`${e};`;case"react-node":return`${e};`;case"php":return`index.php ${e};`;case"python":return`index.py ${e};`;default:return`${e}; # Default`}}getServerDirectives(e={}){let{serverNames:r,redirect:t=!1,port:s=this.http_port}=e,o=[`listen ${s};`,`listen [::]:${s};`,"",`server_name ${r?.join(" ")};`];return t||o.push("",this.getIndexDirective(),`root ${this.rootDirectory};`),o}_generateFullServerBlock(e){let{redirectHttps:r=!1,redirectWWW:t=!1,port:s,onlyFirstServerName:o=!1}=e||{},a=[];if(r||t){let h=r||s===this.https_port?"s":"",c=t?this.serverNames?.[0]:"$host";a.push(`return 301 http${h}://${c}$request_uri;`)}let l=t?this.serverNames?.slice(1):this.serverNames;return this.createServerBlock({serverDirectives:this.getServerDirectives({serverNames:o?[l?.[0]]:l,port:s,redirect:r||t}),addSslCertificates:!!(this.ssl&&s===this.https_port),redirects:a?.length?a:void 0})}getData(e){let{joinArray:r=!1}=e??{},t=[],s=this.serverNames,o=this.redirectToFirstServer&&this.serverNames?.length>1?this.serverNames?.[0]:"";return this.redirectToHttps?o?(t.push(this._generateFullServerBlock({port:this.http_port,redirectHttps:!0,redirectWWW:!0})),t.push(this._generateFullServerBlock({port:this.https_port,redirectHttps:!0,redirectWWW:!0})),t.push(this._generateFullServerBlock({port:this.http_port,redirectHttps:!0,redirectWWW:!1,onlyFirstServerName:!0})),t.push(this._generateFullServerBlock({port:this.https_port,redirectHttps:!1,redirectWWW:!1,onlyFirstServerName:!0}))):(t.push(this._generateFullServerBlock({port:this.http_port,redirectHttps:!0,redirectWWW:!1})),t.push(this._generateFullServerBlock({port:this.https_port,redirectHttps:!1,redirectWWW:!1}))):o?(t.push(this._generateFullServerBlock({port:this.http_port,redirectHttps:!1,redirectWWW:!0})),t.push(this._generateFullServerBlock({port:this.https_port,redirectHttps:!1,redirectWWW:!0})),t.push(this._generateFullServerBlock({port:this.http_port,redirectHttps:!1,redirectWWW:!1,onlyFirstServerName:!0})),t.push(this._generateFullServerBlock({port:this.https_port,redirectHttps:!1,redirectWWW:!1,onlyFirstServerName:!0}))):(t.push(this._generateFullServerBlock({port:this.http_port,redirectHttps:!1,redirectWWW:!1})),this.ssl&&t.push(this._generateFullServerBlock({port:this.https_port,redirectHttps:!1,redirectWWW:!1}))),((n={})=>{let{joinArray:h=!1}=n,c=[];return t?.map((d,p)=>{c.push(...d),p+1<t?.length&&c.push("")}),h?c?.join(`
20
+ `):c})({joinArray:r})}};var O=class{constructor(e){this.helper=new k(this)}async yamlToVhostInstances(e,r){let{quiet:t=!1}=r||{};try{let o=await new F().read(e),a=o?.vhosts||[],l=o?.meta||{};t||(console.log(`YAML Config Data : -------- Total VHosts in file "${e}":`,a.length),console.log("VHosts Default Meta:",{defaultMeta:l}));for(let h of a)t||(console.log("VHost Data:",h),console.log("VHost reverseProxies:",h?.reverseProxies));let n=[];return a.forEach(h=>{let c=structuredClone(h);c.meta={...l,...c.meta??{}},delete c.reverseProxies,t||console.log("New VHost Data (without reverseProxies):",c);let d=new T(c);n.push(d),t||(console.log("Processing VHost:",d.id),console.log("vhostData?.reverseProxies:",h?.reverseProxies)),[...h?.reverseProxies??[]].forEach(p=>{let[[m,u]]=Object.entries(p??{});t||console.log("Reverse Proxy Data:",{pathKey:m,proxyConfig:u}),u.location=m;let _=new S(u);d.setReverseProxy(_)})}),t||console.log(`Loaded (${n.length}) vhost(s) from YAML file: "${e}"`),n}catch(s){throw new Error(`Error reading YAML file "${e}": ${s?.message}`,{cause:s})}}async getVhostInstanceArray(e,r){let{quiet:t=!1}=r||{};try{return I(e)?await this.yamlToVhostInstances(e,{quiet:t}):(t||console.warn(`The path "${e}" is not a valid file.`),null)}catch(s){throw console.error("-----------------------------------"),console.error(`Error Message: ${s?.message}`),console.error("----------------- Complete Error ------------------"),console.error(s),console.error("-----------------------------------"),new Error(`YAML File Error, while importing "${e}": ${s?.message}`)}}async getVhostInstances(e,r){let{quiet:t=!1}=r||{};try{let s=await G(e,{recursive:!0,filesOnly:!0,returnType:"relative",forwardSlashes:!0,quiet:t});t||(console.log(4444,{quiet:t},{files:s}),console.log(s));let o=[];for(let a of s)if(a.endsWith(".yml")||a.endsWith(".yaml")){let l=E.default.resolve(e,a),n=await this.getVhostInstanceArray(l,{quiet:t});n?.length&&o.push(...n)}return o}catch(s){throw new Error(`Error in "getVhostInstances()" from directory "${e}": Error:"${s.message}"`,{cause:s})}}async ensureDir(e,r){let{quiet:t=!1,directoryName:s="Output"}=r||{};if(!await C(e))if(await C(E.default.dirname(e)))t||console.log(`## ${s} directory does not exist. Creating directory: "${e}"`),await(0,w.mkdir)(e,{recursive:!0});else throw new Error(`## ${s} directory does not exist: ${e}`)}getVhostConfigFileData(e,r){let{joinArray:t=!1}=r||{},s=e.getData()??[],o=e.reverseProxies?.size?[...e.reverseProxies].map(([l,n])=>`${l} => ${n?.host}:${n?.port}${n?.hostUri}`).join(", "):"",a=[`# Created at: ${ee()}`,`# ID: ${e.id}`,`# HOST (s): ${o}`,`# GROUP: ${e?.meta?.group}`,"###################################",`
21
21
 
22
- `,...s];return t?n.join(`
23
- `):n}async generateVhostConfig(e){let{vhosts:r,destDir:t,quiet:s=!1}=e;await this.ensureDir(t,{quiet:s,directoryName:"Destination"});for(let o of r){let n=this.getVhostConfigFileData(o,{joinArray:!0}),l=o?.meta?.confFileName??`${o?.meta?.group}--${o.id}.conf`,a=E.default.resolve(t,l);console.log(`Generating vhost config file: "${a}" ...`,n);try{await(0,w.writeFile)(a,n)}catch(h){throw new Error(`Error writing vhost config file "${a}": ${h?.message}`,{cause:h})}}}async generate(e){let{file:r,srcDir:t,outputDir:s,quiet:o=!1,cleanDir:n=!1,createEmptyFile:l=!1,nginxConfFile:a,subConfdDir:h=!0}=e;try{if(!r&&!t)throw new Error('Either "file" or "srcDir" must be provided.');if(r&&!await I(r))throw new Error(`The specified file does not exist: ${r}`);if(t&&!await C(t))throw new Error(`The specified source directory does not exist: ${t}`);await this.ensureDir(s,{quiet:o,directoryName:"output"}),h&&await this.ensureDir(E.default.resolve(s,"conf.d"),{quiet:o,directoryName:"output/conf.d"});let c=[];if(o||console.log(1111,{file:r,srcDir:t}),r){let p=await this.getVhostInstanceArray(r,{quiet:o});p?.length&&c.push(...p)}if(t){let p=await this.getVhostInstances(t,{quiet:o});o||(console.log({"vhostInstances Count":p.length}),console.log(3333,p)),c.push(...p)}if(n){let p=(await(0,w.readdir)(s)).map(m=>E.default.resolve(s,m));await Promise.all(p.map(m=>(0,w.rm)(m,{recursive:!0,force:!0})))}if(l&&await(0,w.writeFile)(E.default.resolve(s,".empty"),""),a){let p=E.default.resolve(a);await W(p)&&await(0,w.copyFile)(p,E.default.resolve(s,"nginx.conf"))}let d=h?E.default.resolve(s,"conf.d"):s;o||(console.log(`Total vhosts to generate: ${c.length} . Output Directory: "${s}"`),console.log({subConfdDir:h}),console.log(`conf.d Directory: "${d}"`)),await this.generateVhostConfig({vhosts:c,destDir:d,quiet:o}),o||console.log(`Generated (${c.length}) vhost configuration file(s) in "${s}".`)}catch(c){throw new Error(`Error in generate method: "${c.message}"`,{cause:c})}}};var se=require("commander");var B=L(require("path"));var j=class extends V{constructor(){super();this.quiet=!0}setupCommand(){let r=new se.Command;return r.name("svhost-nginx").description("Nginx - Simple Virtual Host").version("1.0.0"),r.description("Generate Nginx configuration for a virtual host").option("-f, --src-file <srcFile>","Source file for configuration").option("--src-dir <srcDir>","Source directory for configuration").requiredOption("-d, --dest-dir <destDir>","Destination directory for configuration").action(this.actionDefault.bind(this)),r.parseAsync(process.argv)}async run(r){let{quiet:t=!0}=r||{};this.quiet=t,await this.setupCommand()}async actionDefault(r,t,s){let{srcFile:o,srcDir:n,destDir:l}=r;if(this.quiet||console.log("Commander:",{name:r,command:s}),o&&n)throw new Error("Please provide either --src-file or --src-dir, not both.");if(!o&&!n)throw new Error("Please provide either --src-file or --src-dir.");let a=B.default.resolve(o||""),h=B.default.resolve(n||""),c=B.default.resolve(l);if(this.quiet||console.table({"Source File":a,"Source Directory":h,"Destination Directory":c}),o&&!await I(o))throw new Error(`Source file does not exist: "${o}"`);if(n&&!await C(n))throw new Error(`Source directory does not exist: "${n}"`);console.log("Generating Nginx configuration ...");let d=new O;o?await d.generate({file:a,outputDir:c,quiet:this.quiet,cleanDir:!0}):n&&await d.generate({srcDir:h,outputDir:c,quiet:this.quiet,cleanDir:!0}),this.quiet||(console.log("option1 action executed"),console.log("Name:",r,typeof r))}};var pe=new j;pe.run().then(()=>{process.exit(0)}).catch(i=>{console.error("Error executing CLI:",i),process.exit(1)});
22
+ `,...s];return t?a.join(`
23
+ `):a}async generateVhostConfig(e){let{vhosts:r,destDir:t,quiet:s=!1}=e;await this.ensureDir(t,{quiet:s,directoryName:"Destination"});for(let o of r){let a=this.getVhostConfigFileData(o,{joinArray:!0}),l=o?.meta?.confFileName??`${o?.meta?.group}--${o.id}.conf`,n=E.default.resolve(t,l);s||console.log(`Generating vhost config file: "${n}" ...`,a);try{await(0,w.writeFile)(n,a)}catch(h){throw new Error(`Error writing vhost config file "${n}": ${h?.message}`,{cause:h})}}}async generate(e){let{file:r,srcDir:t,outputDir:s,quiet:o=!1,cleanDir:a=!1,createEmptyFile:l=!1,nginxConfFile:n,subConfdDir:h=!0}=e;try{if(!r&&!t)throw new Error('Either "file" or "srcDir" must be provided.');if(r&&!await I(r))throw new Error(`The specified file does not exist: ${r}`);if(t&&!await C(t))throw new Error(`The specified source directory does not exist: ${t}`);await this.ensureDir(s,{quiet:o,directoryName:"output"}),h&&await this.ensureDir(E.default.resolve(s,"conf.d"),{quiet:o,directoryName:"output/conf.d"});let c=[];if(o||console.log(1111,{file:r,srcDir:t}),r){let p=await this.getVhostInstanceArray(r,{quiet:o});p?.length&&c.push(...p)}if(t){let p=await this.getVhostInstances(t,{quiet:o});o||(console.log({"vhostInstances Count":p.length}),console.log(3333,p)),c.push(...p)}if(a){let p=(await(0,w.readdir)(s)).map(m=>E.default.resolve(s,m));await Promise.all(p.map(m=>(0,w.rm)(m,{recursive:!0,force:!0})))}if(l&&await(0,w.writeFile)(E.default.resolve(s,".empty"),""),n){let p=E.default.resolve(n);await W(p)&&await(0,w.copyFile)(p,E.default.resolve(s,"nginx.conf"))}let d=h?E.default.resolve(s,"conf.d"):s;o||(console.log(`Total vhosts to generate: ${c.length} . Output Directory: "${s}"`),console.log({subConfdDir:h}),console.log(`conf.d Directory: "${d}"`)),await this.generateVhostConfig({vhosts:c,destDir:d,quiet:o}),o||console.log(`Generated (${c.length}) vhost configuration file(s) in "${s}".`)}catch(c){throw new Error(`Error in generate method: "${c.message}"`,{cause:c})}}};var se=require("commander");var B=L(require("path"));var j=class extends V{constructor(){super();this.quiet=!0}setupCommand(){let r=new se.Command;return r.name("svhost-nginx").description("Nginx - Simple Virtual Host").version("1.0.0"),r.description("Generate Nginx configuration for a virtual host").option("-f, --src-file <srcFile>","Source file for configuration").option("--src-dir <srcDir>","Source directory for configuration").requiredOption("-d, --dest-dir <destDir>","Destination directory for configuration").action(this.actionDefault.bind(this)),r.parseAsync(process.argv)}async run(r){let{quiet:t=!0}=r||{};this.quiet=t,await this.setupCommand()}async actionDefault(r,t,s){let{srcFile:o,srcDir:a,destDir:l}=r;if(this.quiet||console.log("Commander:",{name:r,command:s}),o&&a)throw new Error("Please provide either --src-file or --src-dir, not both.");if(!o&&!a)throw new Error("Please provide either --src-file or --src-dir.");let n=B.default.resolve(o||""),h=B.default.resolve(a||""),c=B.default.resolve(l);if(this.quiet||console.table({"Source File":n,"Source Directory":h,"Destination Directory":c}),o&&!await I(o))throw new Error(`Source file does not exist: "${o}"`);if(a&&!await C(a))throw new Error(`Source directory does not exist: "${a}"`);console.log("Generating Nginx configuration ...");let d=new O;o?await d.generate({file:n,outputDir:c,quiet:this.quiet,cleanDir:!0}):a&&await d.generate({srcDir:h,outputDir:c,quiet:this.quiet,cleanDir:!0}),this.quiet||(console.log("option1 action executed"),console.log("Name:",r,typeof r))}};var pe=new j;pe.run().then(()=>{process.exit(0)}).catch(i=>{console.error("Error executing CLI:",i),process.exit(1)});
24
24
  //# sourceMappingURL=svhost-nginx.js.map