/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@timeax/valet@1.0.30/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
#!/usr/bin/env node
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const child_process_1=require("child_process"),commander_1=require("commander"),program=new commander_1.Command,utilities_1=require("@timeax/utilities"),sass_to_lightening_1=require("./sass-to-lightening"),csr_1=__importDefault(require("./csr"));function restartServer(){(0,child_process_1.exec)('httpd -k restart -n "Apache2.4"',(e=>{if(e)return console.log(e.message);console.log("Apache restarted")}))}const attrs={domain:"",path:""},manager={get _hosts(){let e=process.env.HOSTS||"C:/Windows/System32/drivers/etc/hosts";const t=process.env.HOSTS?null:process.env.DRIVE;return t&&(e=t+e.substring(1)),e},get _vhosts(){let e=process.env.VP||"D:/xampp/apache/conf/extra/httpd-vhosts.conf";const t=process.env.VP?null:process.env.VD;return t&&(e=t+e.substring(1)),e},get hosts(){return utilities_1.Fs.content(this._hosts)||""},get vhosts(){return utilities_1.Fs.content(this._vhosts)||""},set hosts(e){utilities_1.Fs.writeSync(this._hosts,e)},set vhosts(e){utilities_1.Fs.writeSync(this._vhosts,e)}};function write(){writeVHost(),addHost(),console.log("Created successfully")}function createId(){let e=`## domain: ${attrs.domain}----`;return{start:e,end:e+"####"}}function writeVHost(){let e=manager.vhosts;const{start:t}=createId();console.log(e),e?.includes(t)?console.log("Virtual host already exists"):(e+=append(createVirtualHost()),manager.vhosts=e,console.log(e))}function addHost(){let e=manager.hosts;const t=createId();e?.includes(t.start)?console.log("Virtual host already exists"):(e+=append(`127.0.0.1    ${attrs.domain}`),manager.hosts=e,console.log("Written to path: "+manager._hosts),console.log("Content: "+e))}function createVirtualHost(){return`<VirtualHost ${attrs.domain}>\n    DocumentRoot "${attrs.path}"\n    ServerName ${attrs.domain}\n    ServerAlias *.${attrs.domain}\n\n    <Directory "${attrs.path}">\n        Require local\n    </Directory>\n</VirtualHost>`}function append(e){const t=createId();return`\n\n${t.start}\n${e}\n${t.end}`}function deleteHost(){let{start:e,end:t}=createId();[manager._hosts,manager._vhosts].forEach((o=>{let n=utilities_1.Fs.content(o);const s=new RegExp(e),a=new RegExp(t);console.log(s.exec(n),e);const[r,i]=[s.exec(n).index,a.exec(n).index];r>-1&&i>r&&(console.log("Deleted content: "+n.slice(r,i+t.length)),n=n.replace(n.slice(r,i+t.length),""),utilities_1.Fs.writeSync(o,n))}))}function createDomain(e,t){return t||(e.match(/^(?:https?:\/\/)?(?:[^.]+\.)?example\.com(\/.*)?$/)?e:e+".test")}function set(e,t){attrs.domain=e,attrs.path=t}function install(e){let t=e.path||process.cwd();set(createDomain(utilities_1.Fs.dirname(t),e.domain),t),write(),restartServer()}function update(e){let t=e.path||process.cwd();set(createDomain(utilities_1.Fs.dirname(t),e.domain),t);let{start:o,end:n}=createId();const s=manager.hosts,a=manager.vhosts;[{path:manager._hosts,content:s,name:"hosts"},{path:manager._vhosts,content:a,name:"vhosts"}].forEach((({content:t,path:s,name:a})=>{if(t.includes(o)){const[e,s]=[t.indexOf(o),t.indexOf(n)+n.length],r=t.slice(e,s);manager[a]=t.replace(r,append("vhosts"===a?createVirtualHost():`127.0.0.1    ${attrs.domain}`))}else install(e)})),restartServer()}function del(e){if(e){let t=e.path||process.cwd(),o=createDomain(utilities_1.Fs.name(t),e.domain.join(" "));attrs.domain=o,attrs.path=t,deleteHost(),restartServer(),console.log("deleted sucessfully")}}function parse(e){return e.map((e=>parseInt(e.trim()))).filter((e=>"number"==typeof e))}function getNumbers(e){return(e=e.trim()).includes(",")?parse(e.split(",")):parse([e])}async function listDomains(e){const{default:{prompt:t}}=await import("inquirer");let o=[],n=[];e.remove&&e.remove.forEach((e=>o.push(...getNumbers(e)))),e.format&&e.format.forEach((e=>n.push(...getNumbers(e))));let s=getTable();if(s){if(n.length>0)for(let e of n){e<0&&(e=s.length+e);const o=s[e];if(!o)continue;if((await t([{name:"modify",message:`Are you sure you want to modify ${o.Name} in ${o.Directory}`,type:"confirm"}])).modify){modify(await t([{name:"domain",message:"Enter Domain name",type:"input",default:o.Name},{name:"alias",message:"Enter Server Alias",type:"input",default:o.ServerAlias},{name:"path",message:"Root Directory (relative paths are valid)",type:"input",default:o.Directory},{name:"dns",message:"Enter new DNS",type:"input",default:o.DNS},{name:"port",message:"Enter Port",type:"input",default:o.Port}])),s=getTable()}}if(o.length>0){for(let e of o){e<0&&(e=s.length+e);const o=s[e];if(!o)continue;(await t([{name:"delete",message:`Are you sure you want to delete ${o.Name} in ${o.Directory}`,type:"confirm"}])).delete&&del({domain:[o.Name],path:o.Directory})}s=getTable()}console.log("\n\nList Of Installed Domains"),console.table(s)}else console.log("No records found");console.log(`\nSee hosts file at -> ${manager._hosts}`),console.log(`\nSee vhosts file at -> ${manager._vhosts}`)}function extract(e,t,o){let n=t.match(/<VirtualHost\s+?[^\>]*>/gm)?.[0];n&&(n=n.replace(/<VirtualHost\s+?/gm,"").replace(">",""));let s=t.match(/ServerAlias\s+[^\n]*/gm)?.[0];s&&(s=s.replace(/ServerAlias\s+?/,"")?.trim());let a=t.match(/DocumentRoot\s+[^\n]*/gm)?.[0];a&&(a=a.replace(/DocumentRoot\s+?[^"]*"/gm,"").replace('"',"").trim());let r=e.replace(new RegExp(`\\s+?${o}[^\n]*`),"")?.trim();return{alias:s,directory:a,serverPort:n,dns:r}}function modify(e){}function getTable(){let{hosts:e,vhosts:t}=manager,o=t.match(/\#\#\s+?domain:\s+?[^\n]*---(-(?!\#))/gm),n={};if(Array.isArray(o))return o.forEach((o=>{const s=o.match(/(?<=(\#\#\sdomain:))\s([^\n]*(?=(----)))/gm)?.[0]?.trim();if(s){attrs.domain=s;const{start:o,end:a}=createId(),r=t.slice(t.indexOf(o),t.indexOf(a)+a.length),{alias:i,directory:l,serverPort:c,dns:m}=extract(e.indexOf(o)>-1?e.slice(e.indexOf(o)+o.length,e.indexOf(a)):"",r,s);n[s]={alias:i,directory:l,serverPort:c,dns:m}}})),Object.keys(n).map((e=>({Name:e,ServerAlias:n[e].alias,Directory:n[e].directory,DNS:n[e].dns,Port:n[e].serverPort,Url:`http://${e}/`})))}(async()=>{const{default:e}=await import("chalk");function t(){return e.gray(`[${(new Date).toISOString()}]`)}const o=console.log,n=console.error,s=console.warn,a=console.info;console.log=(...n)=>o(t(),e.white(...n)),console.error=(...o)=>n(t(),e.red("ERROR:"),e.red(...o)),console.warn=(...o)=>s(t(),e.yellow("WARNING:"),e.yellow(...o)),console.info=(...o)=>a(t(),e.blue("INFO:"),e.blue(...o)),program.name("web").version("0.0.2").description("Web Development Utility CMD Interface"),(0,sass_to_lightening_1.createSassCompilerCommand)(program),program.command("list").description("Get a full list of a installed domains").option("-f, --format <id...>").option("-rm, --remove <id...>").action(listDomains),program.command("l").description("Get a full list of a installed domains").option("-f, --format <id...>").option("-rm, --remove <id...>").action(listDomains),program.command("install").description("Install a local domain on your system").option("-d, --domain <domainName>").option("-p, --path <filepath>").action(install),program.command("update").description("update a local domain on your system").option("-d, --domain <domainName>").option("-p, --path <filepath>").action(update),program.command("i").description("Install a local domain on your system").option("-d, --domain <domainName>").option("-p, --path <filepath>").action(install),program.command("del").description("Deletes virtual host").option("-d, --domain <domain...>","-p, --path <path>").action(del),(0,csr_1.default)(program),program.parse(process.argv)})();
//# sourceMappingURL=/sm/281e3e40de03f0790cc8e0b9dcfb7d6e1a17a59fbd1ec5187203de65b1dc7392.map