UNPKG

@in-ch/setup

Version:

A tool for quick setup and configuration of essential project files.

90 lines (78 loc) 28.1 kB
#!/usr/bin/env node "use strict";var Pt=Object.create;var we=Object.defineProperty;var It=Object.getOwnPropertyDescriptor;var Mt=Object.getOwnPropertyNames;var Tt=Object.getPrototypeOf,At=Object.prototype.hasOwnProperty;var jt=(e,o,t,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of Mt(o))!At.call(e,i)&&i!==t&&we(e,i,{get:()=>o[i],enumerable:!(n=It(o,i))||n.enumerable});return e};var s=(e,o,t)=>(t=e!=null?Pt(Tt(e)):{},jt(o||!e||!e.__esModule?we(t,"default",{value:e,enumerable:!0}):t,e));var Ct=require("commander");var N=s(require("fs"),1),O=s(require("path"),1);function V(e=process.cwd()){let o=O.default.join(e,"package.json"),t=O.default.join(e,"yarn.lock"),n=O.default.join(e,"pnpm-lock.yaml");return N.default.existsSync(o)||N.default.existsSync(t)||N.default.existsSync(n)}var ve=require("child_process"),Y=s(require("fs-extra"),1),Se=s(require("path"),1);var Ft={EACCES:"Permission denied. Try running the command with administrator privileges.",ENOENT:"Directory not found. Ensure you are in the correct project directory.",ENOSPC:"No space left on device. The disk is full. Free up some disk space and try again.",UNKNOWN:"An unexpected file system error occurred."},H=Ft;function m(e,o){e instanceof Error&&(console.error(`\u{1F972} \u{1F972} \u{1F972} ${o}`),H[e.code]?console.error(`Reason: ${H[e.code]}`):console.error(`Reason: ${e.message}`),process.exit(1))}function w(e="@in-ch/setup"){try{let o=(0,ve.execSync)("npm root -g",{encoding:"utf-8"}).trim(),t=Se.default.join(o,e,"package.json");if(Y.default.existsSync(t))return JSON.parse(Y.default.readFileSync(t,"utf-8"));throw new Error("package.json not found")}catch(o){return m(o,"Failed to get package info"),null}}var be=require("child_process"),Ee=require("commander"),Pe=require("util"),P=(0,Pe.promisify)(be.exec),Ie=new Ee.Command().command("adb-remote").description("Connect to ADB device wirelessly").action(async()=>{try{console.log("Checking connected ADB devices...");let{stdout:e}=await P("adb devices"),o=e.split(` `).filter(l=>l.includes(" device")).map(l=>l.split(" ")[0]).filter(l=>l?.trim()!=="");if(o.length===0){console.log(`No ADB devices connected. Please connect a device via USB first.`);return}console.log(`Found ${o.length} connected device(s):`),o.forEach(l=>{console.log(` ${l}`)}),console.log(` Getting device IP address...`);let{stdout:t}=await P("adb shell ip addr show wlan0"),n=t.match(/inet (\d+\.\d+\.\d+\.\d+)/);if(!n){console.log("Could not find IP address for wlan0 interface.");return}let i=n[1];console.log(`Device IP address: ${i}`),console.log(` Enabling TCP/IP mode on port 5555...`),await P("adb tcpip 5555"),console.log("TCP/IP mode enabled on port 5555"),console.log(` Connecting wirelessly...`),await P(`adb connect ${i}:5555`),console.log(`Successfully connected to ${i}:5555`),console.log(` Verifying wireless connection...`);let{stdout:c}=await P("adb devices");console.log("Current ADB devices:"),console.log(c),console.log(` ADB remote connection established successfully!`),console.log("You can now disconnect the USB cable and use ADB wirelessly.")}catch(e){console.error(`Error: ${e instanceof Error?e.message:"Unknown error occurred"}`),e instanceof Error&&e.message.includes("adb: command not found")&&(console.log("Make sure ADB is installed and added to your PATH."),console.log("You can install it via Android SDK Platform Tools."))}});var jo=require("commander"),Fo=require("fs");var Io=require("child_process"),T=s(require("fs"),1);var v=s(require("fs"),1),I=s(require("path"),1);function Nt(e=process.cwd()){let o=I.default.join(e,"package.json");if(!v.default.existsSync(o))return!1;if(JSON.parse(v.default.readFileSync(o,"utf-8")).workspaces)return!0;let n=I.default.join(e,"pnpm-workspace.yaml");if(v.default.existsSync(n))return!0;let i=I.default.join(e,"lerna.json");if(v.default.existsSync(i))return!0;let c=I.default.join(e,"bunfig.toml");return!!v.default.existsSync(c)}var u=Nt;var Me=s(require("fs"),1),Ot=()=>{let e=Me.default.readdirSync(process.cwd());return e.includes("yarn.lock")?"yarn add":e.includes("pnpm-lock.yaml")?"pnpm add":e.includes("package-lock.json")?"npm install":"default"};var h=Ot;var Te=require("child_process"),Ae=s(require("path"),1);function W(e){try{let o=(0,Te.execSync)("npm root -g",{encoding:"utf8"}).trim();return Ae.default.resolve(o,e)}catch(o){return console.error("Error resolving global package path:",o),null}}var me=s(require("path"),1);var We=require("commander");var R={IMPORT_SORT:"import-sort",AIRBNB:"airbnb",GOOGLE:"google",XO:"xo"},nn=[{name:"Import Sort",value:R.IMPORT_SORT},{name:"Airbnb",value:R.AIRBNB},{name:"Google",value:R.GOOGLE},{name:"XO",value:R.XO}];var je=[".eslintrc.js",".eslintrc.json",".eslintrc.yaml",".eslintrc.yml",".eslintrc.config.mjs",".eslintrc"];var S=s(require("fs"),1),Fe=s(require("path"),1),Ne=e=>S.default.existsSync(e),Rt=e=>S.default.existsSync(e)&&S.default.statSync(e).isDirectory();var Oe=(e,o,t="utf-8")=>{try{let n=Fe.default.dirname(e);return Rt(n)||S.default.mkdirSync(n,{recursive:!0}),S.default.writeFileSync(e,o,t),!0}catch(n){return console.error(`Failed to write file: ${e}`,n),!1}};var $e=require("child_process");var b={NPM:"npm",PNPM:"pnpm",YARN:"yarn"},J={NPM:"npm",PNPM:"pnpm",YARN:"yarn"},z={NPM:"npm install",PNPM:"pnpm add",YARN:"yarn add"},Re=[{name:b.NPM,value:J.NPM},{name:b.PNPM,value:J.PNPM},{name:b.YARN,value:J.YARN},{name:"cancel",value:"cancel"}],y=[{name:b.NPM,value:z.NPM},{name:b.PNPM,value:z.PNPM},{name:b.YARN,value:z.YARN},{name:"cancel",value:"cancel"}];var Le=require("@inquirer/prompts"),$t=async e=>{let{dependencies:o,isDev:t=!0,workspace:n=!1}=e;console.log(` Installing dependencies... `);try{let i=h();if(i==="default"){console.log(`The package manager could not be detected. 1. If this is not the project root, please run the command from the root directory. 2. If you have not installed the packages beforehand, please install them first and then try again. `);let C=await(0,Le.select)({message:`Which package manager would you like to use for installation? `,choices:y});if(C==="cancel")return;i=C}let c=`${i} ${o}`,l=[t?"-D":"",n&&u()?"-w":""].filter(Boolean).join(" ");(0,$e.execSync)(`${c} ${l}`,{stdio:"inherit"})}catch(i){throw console.error("\u{1F972} \u{1F972} \u{1F972} Failed to install dependencies..."),i}},De=async e=>{let o={"import-sort":"eslint @types/eslint eslint-plugin-jsdoc eslint-plugin-no-for-of-array eslint-plugin-vue @eslint/js typescript-eslint globals",airbnb:"eslint eslint-config-airbnb-base eslint-plugin-import @typescript-eslint/parser @typescript-eslint/eslint-plugin",google:"eslint eslint-config-google",xo:"eslint eslint-config-xo"},t=o[e]||o["import-sort"];await $t({dependencies:t,isDev:!0,workspace:!0})};var Lt=e=>{let o=process.cwd(),t=d(e);if(!t)return console.error("\u274C Failed to read ESLint configuration template"),!1;let n=`${o}/eslint.config.mjs`;return Oe(n,t)?(console.log(` \u{1F389} Successfully created the ESLint configuration file.`),!0):(console.error("\u{1F972} \u{1F972} \u{1F972} Failed to setup eslint..."),!1)},Ge=async(e,o)=>{try{return await De(e),Lt(o)}catch(t){return console.error("Failed to setup ESLint configuration:",t),!1}};var X=require("child_process");var _e=require("child_process");function k(e){return new Promise((o,t)=>{(0,_e.exec)(`npm show ${e} version`,(n,i,c)=>{if(n){t(`Error fetching latest version: ${n.message}`);return}if(c){t(`Error: ${c}`);return}o(i.trim())})})}var Be=require("child_process"),Ue=require("commander");var Ve=require("@inquirer/prompts"),He=new Ue.Command().command("pkgmng").alias("pm").description("Initialize package manager").action(async()=>K()),K=async()=>{try{let e=await(0,Ve.select)({message:`Which package manager would you like to use? `,choices:Re});if(e==="cancel")return;(0,Be.execSync)(`${e} init`,{stdio:"inherit"})}catch(e){console.error(`\u{1F972} \u{1F972} \u{1F972} Failed to init package manager... to `,e),process.exit(1)}};var Ye=require("@inquirer/prompts");function q(){try{(0,X.execSync)("npm --version")}catch{K()}}async function a(){q();let e=await k("@in-ch/setup"),o=await w().version;o!==e&&await(0,Ye.confirm)({message:`The latest version is ${e}, but the current version is ${o}. An update is needed. Would you like to update?`})&&((0,X.execSync)("npm install @in-ch/setup@latest -g",{stdio:"inherit"}),console.log("Update completed successfully."))}var $=require("@inquirer/prompts");var Je=new We.Command().command("eslint").alias("es").description("Setup eslint file").action(async()=>Q()),Q=async()=>{if(await a(),je.filter(c=>Ne(c)).length>0&&!await(0,$.confirm)({message:"At least one ESLint file exists. Do you still want to proceed with the setup?"})){console.log("canceled!");return}let o=await(0,$.select)({message:"Choose an ESLint configuration type:",choices:Z}),n={airbnb:{type:"airbnb",command:r.AIRBNB},google:{type:"google",command:r.GOOGLE},xo:{type:"xo",command:r.XO}}[o]||{type:"import-sort",command:r.ESLINT};console.log(`Setting up ${n.type} ESLint configuration...`),await Ge(n.type,n.command)||(console.error("\u274C Failed to setup ESLint configuration"),process.exit(1))};var qe=require("commander"),Qe=require("fs");var L=require("child_process"),ee=s(require("fs"),1);var ze=s(require("path"),1);var Ke=async()=>{(0,L.execSync)("git init",{stdio:"inherit"})},Xe=()=>{let e=process.cwd(),o=ee.default.readFileSync(d(r.GITMESSAGE),"utf-8");try{ee.default.writeFileSync(ze.default.join(e,".gitmessage"),o,"utf-8"),(0,L.execSync)("git config commit.template .gitmessage"),(0,L.execSync)("git config init.defaultBranch main"),console.log("\u{1F389} Successfully created the git message configuration file. \u{1F389}"),console.log("You can now write commits following the template using the commit button in your IDE tool or the `git commit` command in the terminal.")}catch(t){m(t,"Failed to create git message configuration file")}};var Ze=require("@inquirer/prompts"),eo=new qe.Command().command("gitmessage").alias("gm").description("Setup git message file").action(async()=>oe()),oe=async()=>{if(await a(),!(0,Qe.existsSync)(".git")){if(!await(0,Ze.confirm)({message:"Git is not initialized. Would you like to initialize it?"})){console.log("canceled!");return}await Ke()}Xe()};var so=require("commander"),ao=require("fs");var te=require("child_process");var oo=s(require("path"),1);var to=require("@inquirer/prompts"),no=async()=>{console.log(` Installing husky dependencies... `);try{let e="husky -D",o=h();if(o==="default"&&(console.log(`The package manager could not be detected. 1. If this is not the project root, please run the command from the root directory. 2. If you have not installed the packages beforehand, please install them first and then try again. `),o==="default")){let n=await(0,to.select)({message:`Which package manager would you like to use for installation? `,choices:y});if(n==="cancel")return;o=n}let t=`${o} ${e}`;(0,te.execSync)(`${t} -D ${u()?"-w":""}`,{stdio:"inherit"})}catch{console.error("\u{1F972} \u{1F972} \u{1F972} Failed to install dependencies..."),process.exit(1)}},ro=async()=>{(0,te.execSync)("npx husky init",{stdio:"inherit"})},io=async()=>{let e=oo.default.resolve(process.cwd(),"package.json"),o=await import("fs-extra");try{await o.access(e)}catch{console.error("Could not find the package.json file.");return}try{let t=await o.readFile(e,"utf-8"),n=JSON.parse(t);n.scripts||(n.scripts={}),n.scripts.test='echo "Error: no test specified" && exit 1',await o.writeFile(e,JSON.stringify(n,null,2),"utf-8"),console.log("package.json file updated successfully.")}catch(t){m(t,"Failed to update package.json file")}};var co=require("@inquirer/prompts"),lo=new so.Command().command("husky").alias("hk").description("Setup husky").action(async()=>M()),M=async()=>{if(await a(),[".husky"].filter(t=>(0,ao.existsSync)(t)).length>0&&!await(0,co.confirm)({message:"Husky settings are already configured. Do you still want to proceed with the setup?"})){console.log("canceled!");return}await no(),await ro(),await io()};var uo=require("commander"),ho=require("fs");var mo=require("child_process"),D=s(require("fs"),1);var ne=s(require("path"),1);var po=require("@inquirer/prompts"),fo=async()=>{console.log(` Installing prettier dependencies... `);try{let e="prettier prettier-plugin-sort-re-exports @trivago/prettier-plugin-sort-imports",o=h();if(o==="default"&&(console.log(`The package manager could not be detected. 1. If this is not the project root, please run the command from the root directory. 2. If you have not installed the packages beforehand, please install them first and then try again. `),o==="default")){let n=await(0,po.select)({message:`Which package manager would you like to use for installation? `,choices:y});if(n==="cancel")return;o=n}let t=`${o} ${e}`;(0,mo.execSync)(`${t} -D ${u()?"-w":""}`,{stdio:"inherit"})}catch(e){console.error(`\u{1F972} Fail to install prettier dependencies.... to `+e),process.exit(1)}},go=()=>{let e=process.cwd(),o=D.default.readFileSync(d(r.PRETTIER),"utf-8"),t=`node_modules/ dist/ build/ coverage/ *.min.js *.bundle.js *.config.js *.cjs logs/ *.log .vscode/ .DS_Store .env .env.* package-lock.json yarn.lock pnpm-lock.yaml`;try{D.default.writeFileSync(ne.default.join(e,".prettierrc.cjs"),o,"utf-8"),D.default.writeFileSync(ne.default.join(e,".prettierignore"),t,"utf-8"),console.log("\u{1F389} Prettier configuration file has been created.")}catch(n){m(n,"Failed to create prettier file}")}};var yo=require("@inquirer/prompts"),Co=new uo.Command().command("prettier").alias("pt").description("Setup prettier file").action(async()=>re()),re=async()=>{if(await a(),[".prettierrc",".prettierrc.json",".prettierrc.yml",".prettierrc.yaml",".prettierrc.js",".prettierrc.cjs","prettier.config.js","prettier.config.cjs"].filter(t=>(0,ho.existsSync)(t)).length>0&&!await(0,yo.confirm)({message:"At least one Prettier file exists. Do you still want to proceed with the setup?"})){console.log("canceled!");return}fo(),go()};var vo=require("commander"),So=require("fs");var ie=require("child_process");var ko=require("@inquirer/prompts"),xo=async()=>{console.log(` Installing typescript dependencies... `);try{let e="typescript @types/node @types/react",o=h();if(o==="default"&&(console.log(`The package manager could not be detected. 1. If this is not the project root, please run the command from the root directory. 2. If you have not installed the packages beforehand, please install them first and then try again. `),o==="default")){let n=await(0,ko.select)({message:`Which package manager would you like to use for installation? `,choices:y});if(n==="cancel")return;o=n}let t=`${o} ${e}`;(0,ie.execSync)(`${t} -D ${u()?"-w":""}`,{stdio:"inherit"})}catch{console.error("\u{1F972} \u{1F972} \u{1F972} Failed to install dependencies..."),process.exit(1)}},wo=()=>{try{console.log("Configure Typescript"),(0,ie.execSync)("npx tsc --init")}catch(e){m(e,"Failed to create typescript.config.json file")}};var bo=new vo.Command().command("typescript").alias("ts").description("Setup typescript file").action(async()=>se()),se=async()=>{if(await a(),[".tsconfig.json"].filter(t=>(0,So.existsSync)(t)).length>0){console.error("At least one Typescript file exists.");return}xo(),wo()};var r={ESLINT:"eslint",PRETTIER:"prettier",TYPESCRIPT:"typescript",GITMESSAGE:"gitmessage",HUSKY:"husky",COMMIT_LINT:"commitlint",LINT_STAGE:"lintstage",AIRBNB:"airbnb",GOOGLE:"google",XO:"xo"},Dt=Object.entries(r).filter(([e])=>![r.AIRBNB,r.GOOGLE,r.XO].includes(e.toLowerCase())).map(([e,o])=>({name:e,value:o})),Eo=Dt.map(e=>e.value),ae={[r.ESLINT]:()=>Q(),[r.PRETTIER]:()=>re(),[r.TYPESCRIPT]:()=>se(),[r.GITMESSAGE]:()=>oe(),[r.HUSKY]:()=>M(),[r.COMMIT_LINT]:()=>le()},ce={[r.ESLINT]:".js",[r.PRETTIER]:".js",[r.TYPESCRIPT]:".json",[r.GITMESSAGE]:".txt",[r.COMMIT_LINT]:".json",[r.LINT_STAGE]:".json",[r.AIRBNB]:".js",[r.GOOGLE]:".js",[r.XO]:".js"},Po=[{name:r.ESLINT,value:r.ESLINT},{name:r.PRETTIER,value:r.PRETTIER},{name:r.TYPESCRIPT,value:r.TYPESCRIPT},{name:r.GITMESSAGE,value:r.GITMESSAGE},{name:r.HUSKY,value:r.HUSKY},{name:r.COMMIT_LINT,value:r.COMMIT_LINT}],Z=[{name:"Import Sort",value:"import-sort"},{name:"Airbnb",value:"airbnb"},{name:"Google",value:"google"},{name:"XO",value:"xo"}],gr=Z.reduce((e,o)=>(e[o.value]=o.value,e),{});function d(e){if(!e)throw new Error("File name is required");if(process.env.NODE_ENV==="development")return me.default.resolve(process.cwd(),"const/config",e)+ce[e];{let t=W("@in-ch/setup");if(!t)throw new Error("Could not resolve global path for @in-ch/setup");return me.default.resolve(t,"const/config",e)+ce[e]}}var pe=s(require("path"),1);var Mo=require("@inquirer/prompts"),To=async()=>{console.log(` Installing eslint dependencies... `);try{let e=["@commitlint/config-conventional","@commitlint/cli","lint-staged"],o=h();if(o==="default"&&(console.log(`The package manager could not be detected. 1. If this is not the project root, please run the command from the root directory. 2. If you have not installed the packages beforehand, please install them first and then try again. `),o==="default")){let n=await(0,Mo.select)({message:`Which package manager would you like to use for installation? `,choices:y});if(n==="cancel")return;o=n}let t=`${o} ${e.join(" ")}`;(0,Io.execSync)(`${t} -D ${u()?"-w":""}`,{stdio:"inherit"})}catch{console.error("\u{1F972} \u{1F972} \u{1F972} Failed to install commitlint's dependencies..."),process.exit(1)}},Ao=()=>{let e=process.cwd(),o=T.default.readFileSync(d(r.COMMIT_LINT),"utf-8"),t=T.default.readFileSync(d(r.LINT_STAGE),"utf-8");try{T.default.writeFileSync(pe.default.join(e,".commitlintrc.json"),o,"utf-8"),T.default.writeFileSync(pe.default.join(e,".lintstagedrc.json"),t,"utf-8"),console.log(` \u{1F389} Successfully created the Commitlint configuration file.`)}catch(n){m(n,"Failed to create commitlint.config.json file")}};var No=require("@inquirer/prompts"),Oo=new jo.Command().command("commitlint").alias("cl").description("Setup commit lint").action(async()=>le()),le=async()=>{if(await a(),!(0,Fo.existsSync)(".husky")){if(!await(0,No.confirm)({message:"Husky is not initialized. Would you like to initialize it?"})){console.log("canceled!");return}await M()}To(),Ao()};var Lo=require("commander");var Ro=s(require("fs"),1);function de(){return Ro.default.existsSync(".vscode")?!0:(console.log("\u{1F972} .vscode directory not found"),!1)}var G=s(require("fs-extra"),1),$o=require("@inquirer/prompts");async function fe(e){let o=".cursor/rules";if(!await G.pathExists(o))if(await(0,$o.confirm)({message:`Directory ${e} does not exist. Create it?`,default:!0}))await G.ensureDir(o),console.log(`\u2705 Created directory: ${o}`);else return!1;return!0}var Do=new Lo.Command().name("cursor-rule").alias("cr").description("Setup Cursor AI rules configuration").action(async()=>{if(console.log(`\u{1F3AF} Setting up Cursor AI rules... `),!de()){console.log(`\u{1F972} .vscode directory not found `),console.log(`Is this a cursor project? `),console.log("Please run `ics cursor-rule` in a cursor project\n");return}if(!await fe(".cursor/rules")){console.log(`\u{1F972} Cursor folder not created `);return}});var Uo=require("child_process"),Vo=require("commander");var _o=require("child_process"),Bo=s(require("os"),1),Go=e=>{try{return(0,_o.execSync)(`which ${e}`,{stdio:"ignore"}),!0}catch{return!1}};function ge(e){let o=Bo.default.platform(),t;if(o==="win32")t=`start "" "notepad" "${e}"`;else if(o==="darwin")Go("code")?t=`open -a "Visual Studio Code" "${e}"`:t=`open -a "TextEdit" "${e}"`;else if(o==="linux")Go("code")?t=`code "${e}"`:t=`xdg-open "${e}"`;else return console.error("Unsupported platform"),"";return t}var Ho=require("@inquirer/prompts"),Yo=new Vo.Command().command("edit").description("edit config file").action(async()=>{await a();let e=await(0,Ho.select)({message:"What do you want to edit config file.",choices:Po}),o=d(e),t=ge(o);(0,Uo.exec)(t,n=>{n?console.error("Failed to open file or folder:",n):console.log(`Opened: ${o}`)})});var Wo=require("commander"),A=s(require("fs"),1);var Jo=s(require("path"),1),j=require("@inquirer/prompts"),zo=new Wo.Command().command("env").description("create .env file").action(async()=>{if(await a(),[".env"].filter(t=>(0,A.existsSync)(t)).length>0)console.log("At least one env file exists.");else try{let t=process.cwd(),n=Jo.default.join(t,".env");A.default.writeFileSync(n,"","utf-8"),console.log("Created .env file successfully");let i=async()=>{if(await(0,j.confirm)({message:"Would you like to add a key to the .env file?"})){let l=await(0,j.input)({message:"Enter the key:",default:""}),C=await(0,j.input)({message:"Enter the value:",default:""}),U=`${l}=${C} `;A.default.appendFileSync(n,U,"utf-8"),console.log(`Added ${l}=${C} to .env`),i()}else console.log("Finished adding key-value pairs.")};i()}catch{console.error("\u{1F972} Failed to create env file")}});var Ko=require("commander");var Xo=require("@inquirer/prompts"),qo=new Ko.Command().command("init").description("Easy Setup various configs").action(async()=>{await a();let e=await(0,Xo.checkbox)({message:`Which files do you want to install? `,choices:Eo});for(let o of e)ae[o]!==void 0&&await ae[o]()});var Qo=require("commander");var Zo=new Qo.Command().command("latest").description("Check latest version of @in-ch/cli package").action(()=>Gt()),Gt=async()=>{await a();let e=await k("@in-ch/setup");console.log(`The latest version of @in-ch/setup is v${e}`)};var tt=require("commander");var _=require("child_process"),B=require("@inquirer/prompts"),et=async()=>{console.log(` Checking Lighthouse dependencies... `);try{let e=(0,_.execSync)("lighthouse --version",{encoding:"utf-8"});console.log("Lighouse version: ",e.trim()+` `)}catch{await(0,B.confirm)({message:"Lighthouse is not installed. Would you like to install it?"})&&(0,_.execSync)("npm i lighthouse -g",{stdio:"inherit"})}},ot=async(e=!1)=>{let o=await(0,B.input)({message:"Enter the web address:",default:"http://localhost:3000"}),t=!1;try{let n=new URL(o);t=n.protocol==="http:"||n.protocol==="https:"}catch{t=!1}if(!t){console.error("Invalid web address. Please enter a valid URL.");return}(0,_.execSync)(`lighthouse ${o} ${e?'--chrome-flags="--headless"':" --output=html --view"} `,{stdio:"inherit"})};var nt=new tt.Command().command("lighthouse").alias("lg").description("Run a Lighthouse test").option("--headless","Run Lighthouse in headless mode").action(async e=>_t(e.headless)),_t=async(e=!1)=>{await a(),await et(),await ot(e)};var it=require("commander"),st=s(require("fs"),1);var Bt={black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",orange:"\x1B[38;5;214m",white:"\x1B[37m",lightBlack:"\x1B[90m",lightRed:"\x1B[91m",lightGreen:"\x1B[92m",lightYellow:"\x1B[93m",lightBlue:"\x1B[94m",lightMagenta:"\x1B[95m",lightCyan:"\x1B[96m",lightWhite:"\x1B[97m",bgBlack:"\x1B[40m",bgRed:"\x1B[41m",bgGreen:"\x1B[42m",bgYellow:"\x1B[43m",bgBlue:"\x1B[44m",bgMagenta:"\x1B[45m",bgCyan:"\x1B[46m",bgWhite:"\x1B[47m",bgLightBlack:"\x1B[100m",bgLightRed:"\x1B[101m",bgLightGreen:"\x1B[102m",bgLightYellow:"\x1B[103m",bgLightBlue:"\x1B[104m",bgLightMagenta:"\x1B[105m",bgLightCyan:"\x1B[106m",bgLightWhite:"\x1B[107m",default:"\x1B[0m"},g=Bt;function ue(e){if(e.length===0||e[0]===void 0)return{column:[],rows:[]};let o=Object.keys(e.reduce((n,i)=>({...n,...i}),{})),t=e.map(n=>o.map(i=>n[i]||""));return{column:o,rows:t}}function he({data:e,textColor:o=g.default,headerColor:t=g.default,borderColor:n=g.default}){let{rows:i,column:c}=ue(e),l=g[n??"default"],C=g[t??"default"],U=g[o??"default"],E=c.map(p=>p.length+2).map((p,f)=>i.reduce((bt,Et)=>Math.max(Et[f].length+2,bt),p)),kt=(p,f)=>`${U}${p.padEnd(E[f])}`,xt=(p,f)=>`${C}${p.padEnd(E[f])}`,wt=()=>`${l}\u250C${c.map((p,f)=>"".padEnd(E[f]+1,"\u2500")).join("\u252C")}\u2510`,vt=()=>`${l}\u251C${c.map((p,f)=>"".padEnd(E[f]+1,"\u2500")).join("\u253C")}\u2524`,St=()=>`${l}\u2514${c.map((p,f)=>"".padEnd(E[f]+1,"\u2500")).join("\u2534")}\u2518`,x="";return x+=wt()+` `,x+=`${l}\u2502 ${c.map(xt).join(`${l}\u2502 `)}${l}\u2502 `,x+=vt()+` `,i.forEach(p=>{x+=`${l}\u2502 ${p.map(kt).join(`${l}\u2502 `)}\u2502 `}),x+=`${St()}${g.default} `,x}var at=require("url"),rt={},ct=new it.Command().command("list").description("list all commands").action(async()=>{await a();let o=typeof rt<"u"?(0,at.fileURLToPath)(rt.url):__filename,t=st.default.readFileSync(o,"utf-8"),n=/command\("(.+?)"\)\.description\("(.+?)"\)/g,i,c=[];for(;(i=n.exec(t))!==null;){let l=i[1].split('"')[0],C=i[2];c.push({command:l,description:C})}console.log(`${g.orange}@in-ch/setup${g.white}'s commands ${he({data:c,borderColor:"lightBlack",textColor:"default",headerColor:"orange"})} `)});var lt=require("child_process"),mt=require("commander");var pt=new mt.Command().command("update").description("Update package version").action(async()=>Ut()),Ut=async()=>{await q();let e=await k("@in-ch/setup");await w().version!==e?(0,lt.execSync)("npm install @in-ch/setup@latest -g",{stdio:"inherit"}):console.log("@in-ch/setup package is already up to date.")};var ht=require("commander");var ke=s(require("fs"),1);var dt=require("child_process");async function ye(e){try{let o=(0,dt.execSync)("code --list-extensions",{stdio:"pipe"}).toString();return o?o.split(` `).map(n=>n.trim()).includes(e):(console.error("No extensions found or error executing the command."),!1)}catch(o){o instanceof Error?console.error(o.message):console.error("An unknown error occurred")}}var ft=require("child_process");async function Ce(e){try{await(0,ft.execSync)(`code --install-extension ${e}`)}catch(o){o instanceof Error?console.error(o.message):console.error("An unknown error occurred")}}var ut=s(require("os"),1),F=s(require("path"),1);var gt=(()=>{let e=ut.default.platform();return e==="win32"?F.default.join(process.env.APPDATA||F.default.join(process.env.HOME,"AppData","Roaming"),"Code","User","settings.json"):e==="darwin"?F.default.join(process.env.HOME,"Library","Application Support","Code","User","settings.json"):F.default.join(process.env.HOME,".config","Code","User","settings.json")})(),Vt={"[javascript]":{"editor.defaultFormatter":"esbenp.prettier-vscode","editor.formatOnSave":!0},"[typescript]":{"editor.defaultFormatter":"esbenp.prettier-vscode","editor.formatOnSave":!0},"[javascriptreact]":{"editor.defaultFormatter":"esbenp.prettier-vscode","editor.formatOnSave":!0},"[typescriptreact]":{"editor.defaultFormatter":"esbenp.prettier-vscode","editor.formatOnSave":!0}};function xe(){try{ke.default.readFile(gt,"utf8",async(e,o)=>{if(e&&e.code!=="ENOENT"){console.error("Error reading VSCode settings.json:",e);return}await ye("esbenp.prettier-vscode")||await Ce("esbenp.prettier-vscode");let n={};if(o)try{n=JSON.parse(o)}catch(c){console.error("Error parsing settings.json:",c);return}let i={...n,...Vt};ke.default.writeFile(gt,JSON.stringify(i,null,2),"utf8",c=>{c?console.error("Error writing to settings.json:",c):console.log("VSCode settings.json updated successfully!")})})}catch(e){m(e,"Failed to update vscode settings.json file")}}var yt=new ht.Command().command("autoPrefix").alias("apf").description("Update VSCode Auto Prefix Settings").action(async()=>{await a(),xe()});process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function Ht(){if(await V()){let o=await w(),t=new Ct.Command().name("@in-ch/setup").description("Quick config: Download and apply settings in seconds.").version(`@in-ch/setup v${o.version||"1.0.0"}`,"-v, --version","display the version number");t.addCommand(ct),t.addCommand(qo),t.addCommand(Je),t.addCommand(Co),t.addCommand(Yo),t.addCommand(bo),t.addCommand(eo),t.addCommand(lo),t.addCommand(Oo),t.addCommand(He),t.addCommand(nt),t.addCommand(yt),t.addCommand(Zo),t.addCommand(pt),t.addCommand(zo),t.addCommand(Do),t.addCommand(Ie),t.parse()}else console.log("\u274C No package manager initialized in this directory."),console.log('\u{1F449} Run "npm init", "yarn init", or "pnpm init" to set up a project.')}Ht(); //# sourceMappingURL=index.cjs.map