@in-ch/setup
Version:
A tool for quick setup and configuration of essential project files.
90 lines (78 loc) • 27 kB
JavaScript
import{Command as Dt}from"commander";import N from"fs";import O from"path";function R(e=process.cwd()){let o=O.join(e,"package.json"),t=O.join(e,"yarn.lock"),n=O.join(e,"pnpm-lock.yaml");return N.existsSync(o)||N.existsSync(t)||N.existsSync(n)}import{execSync as fo}from"child_process";import ae from"fs-extra";import go from"path";var po={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."},$=po;function l(e,o){e instanceof Error&&(console.error(`\u{1F972} \u{1F972} \u{1F972} ${o}`),$[e.code]?console.error(`Reason: ${$[e.code]}`):console.error(`Reason: ${e.message}`),process.exit(1))}function x(e="@in-ch/setup"){try{let o=fo("npm root -g",{encoding:"utf-8"}).trim(),t=go.join(o,e,"package.json");if(ae.existsSync(t))return JSON.parse(ae.readFileSync(t,"utf-8"));throw new Error("package.json not found")}catch(o){return l(o,"Failed to get package info"),null}}import{exec as uo}from"child_process";import{Command as ho}from"commander";import{promisify as yo}from"util";var S=yo(uo),ce=new ho().command("adb-remote").description("Connect to ADB device wirelessly").action(async()=>{try{console.log("Checking connected ADB devices...");let{stdout:e}=await S("adb devices"),o=e.split(`
`).filter(c=>c.includes(" device")).map(c=>c.split(" ")[0]).filter(c=>c?.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(c=>{console.log(` ${c}`)}),console.log(`
Getting device IP address...`);let{stdout:t}=await S("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 S("adb tcpip 5555"),console.log("TCP/IP mode enabled on port 5555"),console.log(`
Connecting wirelessly...`),await S(`adb connect ${i}:5555`),console.log(`Successfully connected to ${i}:5555`),console.log(`
Verifying wireless connection...`);let{stdout:a}=await S("adb devices");console.log("Current ADB devices:"),console.log(a),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."))}});import{Command as nt}from"commander";import{existsSync as rt}from"fs";import{execSync as ot}from"child_process";import T from"fs";import b from"fs";import I from"path";function Co(e=process.cwd()){let o=I.join(e,"package.json");if(!b.existsSync(o))return!1;if(JSON.parse(b.readFileSync(o,"utf-8")).workspaces)return!0;let n=I.join(e,"pnpm-workspace.yaml");if(b.existsSync(n))return!0;let i=I.join(e,"lerna.json");if(b.existsSync(i))return!0;let a=I.join(e,"bunfig.toml");return!!b.existsSync(a)}var g=Co;import ko from"fs";var xo=()=>{let e=ko.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 u=xo;import{execSync as wo}from"child_process";import vo from"path";function L(e){try{let o=wo("npm root -g",{encoding:"utf8"}).trim();return vo.resolve(o,e)}catch(o){return console.error("Error resolving global package path:",o),null}}import Le from"path";import{Command as Oo}from"commander";var M={IMPORT_SORT:"import-sort",AIRBNB:"airbnb",GOOGLE:"google",XO:"xo"},pn=[{name:"Import Sort",value:M.IMPORT_SORT},{name:"Airbnb",value:M.AIRBNB},{name:"Google",value:M.GOOGLE},{name:"XO",value:M.XO}];var le=[".eslintrc.js",".eslintrc.json",".eslintrc.yaml",".eslintrc.yml",".eslintrc.config.mjs",".eslintrc"];import E from"fs";import So from"path";var me=e=>E.existsSync(e),bo=e=>E.existsSync(e)&&E.statSync(e).isDirectory();var pe=(e,o,t="utf-8")=>{try{let n=So.dirname(e);return bo(n)||E.mkdirSync(n,{recursive:!0}),E.writeFileSync(e,o,t),!0}catch(n){return console.error(`Failed to write file: ${e}`,n),!1}};import{execSync as Eo}from"child_process";var w={NPM:"npm",PNPM:"pnpm",YARN:"yarn"},D={NPM:"npm",PNPM:"pnpm",YARN:"yarn"},G={NPM:"npm install",PNPM:"pnpm add",YARN:"yarn add"},de=[{name:w.NPM,value:D.NPM},{name:w.PNPM,value:D.PNPM},{name:w.YARN,value:D.YARN},{name:"cancel",value:"cancel"}],h=[{name:w.NPM,value:G.NPM},{name:w.PNPM,value:G.PNPM},{name:w.YARN,value:G.YARN},{name:"cancel",value:"cancel"}];import{select as Po}from"@inquirer/prompts";var Io=async e=>{let{dependencies:o,isDev:t=!0,workspace:n=!1}=e;console.log(`
Installing dependencies...
`);try{let i=u();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 y=await Po({message:`Which package manager would you like to use for installation?
`,choices:h});if(y==="cancel")return;i=y}let a=`${i} ${o}`,c=[t?"-D":"",n&&g()?"-w":""].filter(Boolean).join(" ");Eo(`${a} ${c}`,{stdio:"inherit"})}catch(i){throw console.error("\u{1F972} \u{1F972} \u{1F972} Failed to install dependencies..."),i}},fe=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 Io({dependencies:t,isDev:!0,workspace:!0})};var Mo=e=>{let o=process.cwd(),t=p(e);if(!t)return console.error("\u274C Failed to read ESLint configuration template"),!1;let n=`${o}/eslint.config.mjs`;return pe(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 fe(e),Mo(o)}catch(t){return console.error("Failed to setup ESLint configuration:",t),!1}};import{execSync as he}from"child_process";import{exec as To}from"child_process";function C(e){return new Promise((o,t)=>{To(`npm show ${e} version`,(n,i,a)=>{if(n){t(`Error fetching latest version: ${n.message}`);return}if(a){t(`Error: ${a}`);return}o(i.trim())})})}import{execSync as Ao}from"child_process";import{Command as jo}from"commander";import{select as Fo}from"@inquirer/prompts";var ue=new jo().command("pkgmng").alias("pm").description("Initialize package manager").action(async()=>_()),_=async()=>{try{let e=await Fo({message:`Which package manager would you like to use?
`,choices:de});if(e==="cancel")return;Ao(`${e} init`,{stdio:"inherit"})}catch(e){console.error(`\u{1F972} \u{1F972} \u{1F972} Failed to init package manager... to
`,e),process.exit(1)}};import{confirm as No}from"@inquirer/prompts";function B(){try{he("npm --version")}catch{_()}}async function s(){B();let e=await C("@in-ch/setup"),o=await x().version;o!==e&&await No({message:`The latest version is ${e}, but the current version is ${o}. An update is needed. Would you like to update?`})&&(he("npm install @in-ch/setup@latest -g",{stdio:"inherit"}),console.log("Update completed successfully."))}import{confirm as Ro,select as $o}from"@inquirer/prompts";var ye=new Oo().command("eslint").alias("es").description("Setup eslint file").action(async()=>U()),U=async()=>{if(await s(),le.filter(a=>me(a)).length>0&&!await Ro({message:"At least one ESLint file exists. Do you still want to proceed with the setup?"})){console.log("canceled!");return}let o=await $o({message:"Choose an ESLint configuration type:",choices:V}),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))};import{Command as Do}from"commander";import{existsSync as Go}from"fs";import{execSync as H}from"child_process";import Ce from"fs";import Lo from"path";var ke=async()=>{H("git init",{stdio:"inherit"})},xe=()=>{let e=process.cwd(),o=Ce.readFileSync(p(r.GITMESSAGE),"utf-8");try{Ce.writeFileSync(Lo.join(e,".gitmessage"),o,"utf-8"),H("git config commit.template .gitmessage"),H("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){l(t,"Failed to create git message configuration file")}};import{confirm as _o}from"@inquirer/prompts";var we=new Do().command("gitmessage").alias("gm").description("Setup git message file").action(async()=>Y()),Y=async()=>{if(await s(),!Go(".git")){if(!await _o({message:"Git is not initialized. Would you like to initialize it?"})){console.log("canceled!");return}await ke()}xe()};import{Command as Vo}from"commander";import{existsSync as Ho}from"fs";import{execSync as ve}from"child_process";import Bo from"path";import{select as Uo}from"@inquirer/prompts";var Se=async()=>{console.log(`
Installing husky dependencies...
`);try{let e="husky -D",o=u();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 Uo({message:`Which package manager would you like to use for installation?
`,choices:h});if(n==="cancel")return;o=n}let t=`${o} ${e}`;ve(`${t} -D ${g()?"-w":""}`,{stdio:"inherit"})}catch{console.error("\u{1F972} \u{1F972} \u{1F972} Failed to install dependencies..."),process.exit(1)}},be=async()=>{ve("npx husky init",{stdio:"inherit"})},Ee=async()=>{let e=Bo.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){l(t,"Failed to update package.json file")}};import{confirm as Yo}from"@inquirer/prompts";var Pe=new Vo().command("husky").alias("hk").description("Setup husky").action(async()=>P()),P=async()=>{if(await s(),[".husky"].filter(t=>Ho(t)).length>0&&!await Yo({message:"Husky settings are already configured. Do you still want to proceed with the setup?"})){console.log("canceled!");return}await Se(),await be(),await Ee()};import{Command as zo}from"commander";import{existsSync as Ko}from"fs";import{execSync as Wo}from"child_process";import W from"fs";import Ie from"path";import{select as Jo}from"@inquirer/prompts";var Me=async()=>{console.log(`
Installing prettier dependencies...
`);try{let e="prettier prettier-plugin-sort-re-exports @trivago/prettier-plugin-sort-imports",o=u();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 Jo({message:`Which package manager would you like to use for installation?
`,choices:h});if(n==="cancel")return;o=n}let t=`${o} ${e}`;Wo(`${t} -D ${g()?"-w":""}`,{stdio:"inherit"})}catch(e){console.error(`\u{1F972} Fail to install prettier dependencies.... to
`+e),process.exit(1)}},Te=()=>{let e=process.cwd(),o=W.readFileSync(p(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{W.writeFileSync(Ie.join(e,".prettierrc.cjs"),o,"utf-8"),W.writeFileSync(Ie.join(e,".prettierignore"),t,"utf-8"),console.log("\u{1F389} Prettier configuration file has been created.")}catch(n){l(n,"Failed to create prettier file}")}};import{confirm as Xo}from"@inquirer/prompts";var Ae=new zo().command("prettier").alias("pt").description("Setup prettier file").action(async()=>J()),J=async()=>{if(await s(),[".prettierrc",".prettierrc.json",".prettierrc.yml",".prettierrc.yaml",".prettierrc.js",".prettierrc.cjs","prettier.config.js","prettier.config.cjs"].filter(t=>Ko(t)).length>0&&!await Xo({message:"At least one Prettier file exists. Do you still want to proceed with the setup?"})){console.log("canceled!");return}Me(),Te()};import{Command as Qo}from"commander";import{existsSync as Zo}from"fs";import{execSync as je}from"child_process";import{select as qo}from"@inquirer/prompts";var Fe=async()=>{console.log(`
Installing typescript dependencies...
`);try{let e="typescript @types/node @types/react",o=u();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 qo({message:`Which package manager would you like to use for installation?
`,choices:h});if(n==="cancel")return;o=n}let t=`${o} ${e}`;je(`${t} -D ${g()?"-w":""}`,{stdio:"inherit"})}catch{console.error("\u{1F972} \u{1F972} \u{1F972} Failed to install dependencies..."),process.exit(1)}},Ne=()=>{try{console.log("Configure Typescript"),je("npx tsc --init")}catch(e){l(e,"Failed to create typescript.config.json file")}};var Oe=new Qo().command("typescript").alias("ts").description("Setup typescript file").action(async()=>z()),z=async()=>{if(await s(),[".tsconfig.json"].filter(t=>Zo(t)).length>0){console.error("At least one Typescript file exists.");return}Fe(),Ne()};var r={ESLINT:"eslint",PRETTIER:"prettier",TYPESCRIPT:"typescript",GITMESSAGE:"gitmessage",HUSKY:"husky",COMMIT_LINT:"commitlint",LINT_STAGE:"lintstage",AIRBNB:"airbnb",GOOGLE:"google",XO:"xo"},et=Object.entries(r).filter(([e])=>![r.AIRBNB,r.GOOGLE,r.XO].includes(e.toLowerCase())).map(([e,o])=>({name:e,value:o})),Re=et.map(e=>e.value),K={[r.ESLINT]:()=>U(),[r.PRETTIER]:()=>J(),[r.TYPESCRIPT]:()=>z(),[r.GITMESSAGE]:()=>Y(),[r.HUSKY]:()=>P(),[r.COMMIT_LINT]:()=>q()},X={[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"},$e=[{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}],V=[{name:"Import Sort",value:"import-sort"},{name:"Airbnb",value:"airbnb"},{name:"Google",value:"google"},{name:"XO",value:"xo"}],ti=V.reduce((e,o)=>(e[o.value]=o.value,e),{});function p(e){if(!e)throw new Error("File name is required");if(process.env.NODE_ENV==="development")return Le.resolve(process.cwd(),"const/config",e)+X[e];{let t=L("@in-ch/setup");if(!t)throw new Error("Could not resolve global path for @in-ch/setup");return Le.resolve(t,"const/config",e)+X[e]}}import De from"path";import{select as tt}from"@inquirer/prompts";var Ge=async()=>{console.log(`
Installing eslint dependencies...
`);try{let e=["@commitlint/config-conventional","@commitlint/cli","lint-staged"],o=u();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 tt({message:`Which package manager would you like to use for installation?
`,choices:h});if(n==="cancel")return;o=n}let t=`${o} ${e.join(" ")}`;ot(`${t} -D ${g()?"-w":""}`,{stdio:"inherit"})}catch{console.error("\u{1F972} \u{1F972} \u{1F972} Failed to install commitlint's dependencies..."),process.exit(1)}},_e=()=>{let e=process.cwd(),o=T.readFileSync(p(r.COMMIT_LINT),"utf-8"),t=T.readFileSync(p(r.LINT_STAGE),"utf-8");try{T.writeFileSync(De.join(e,".commitlintrc.json"),o,"utf-8"),T.writeFileSync(De.join(e,".lintstagedrc.json"),t,"utf-8"),console.log(`
\u{1F389} Successfully created the Commitlint configuration file.`)}catch(n){l(n,"Failed to create commitlint.config.json file")}};import{confirm as it}from"@inquirer/prompts";var Be=new nt().command("commitlint").alias("cl").description("Setup commit lint").action(async()=>q()),q=async()=>{if(await s(),!rt(".husky")){if(!await it({message:"Husky is not initialized. Would you like to initialize it?"})){console.log("canceled!");return}await P()}Ge(),_e()};import{Command as ct}from"commander";import st from"fs";function Q(){return st.existsSync(".vscode")?!0:(console.log("\u{1F972} .vscode directory not found"),!1)}import*as A from"fs-extra";import{confirm as at}from"@inquirer/prompts";async function Z(e){let o=".cursor/rules";if(!await A.pathExists(o))if(await at({message:`Directory ${e} does not exist. Create it?`,default:!0}))await A.ensureDir(o),console.log(`\u2705 Created directory: ${o}`);else return!1;return!0}var Ue=new ct().name("cursor-rule").alias("cr").description("Setup Cursor AI rules configuration").action(async()=>{if(console.log(`\u{1F3AF} Setting up Cursor AI rules...
`),!Q()){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 Z(".cursor/rules")){console.log(`\u{1F972} Cursor folder not created
`);return}});import{exec as pt}from"child_process";import{Command as dt}from"commander";import{execSync as lt}from"child_process";import mt from"os";var Ve=e=>{try{return lt(`which ${e}`,{stdio:"ignore"}),!0}catch{return!1}};function ee(e){let o=mt.platform(),t;if(o==="win32")t=`start "" "notepad" "${e}"`;else if(o==="darwin")Ve("code")?t=`open -a "Visual Studio Code" "${e}"`:t=`open -a "TextEdit" "${e}"`;else if(o==="linux")Ve("code")?t=`code "${e}"`:t=`xdg-open "${e}"`;else return console.error("Unsupported platform"),"";return t}import{select as ft}from"@inquirer/prompts";var He=new dt().command("edit").description("edit config file").action(async()=>{await s();let e=await ft({message:"What do you want to edit config file.",choices:$e}),o=p(e),t=ee(o);pt(t,n=>{n?console.error("Failed to open file or folder:",n):console.log(`Opened: ${o}`)})});import{Command as gt}from"commander";import Ye,{existsSync as ut}from"fs";import ht from"path";import{confirm as yt,input as We}from"@inquirer/prompts";var Je=new gt().command("env").description("create .env file").action(async()=>{if(await s(),[".env"].filter(t=>ut(t)).length>0)console.log("At least one env file exists.");else try{let t=process.cwd(),n=ht.join(t,".env");Ye.writeFileSync(n,"","utf-8"),console.log("Created .env file successfully");let i=async()=>{if(await yt({message:"Would you like to add a key to the .env file?"})){let c=await We({message:"Enter the key:",default:""}),y=await We({message:"Enter the value:",default:""}),F=`${c}=${y}
`;Ye.appendFileSync(n,F,"utf-8"),console.log(`Added ${c}=${y} to .env`),i()}else console.log("Finished adding key-value pairs.")};i()}catch{console.error("\u{1F972} Failed to create env file")}});import{Command as Ct}from"commander";import{checkbox as kt}from"@inquirer/prompts";var ze=new Ct().command("init").description("Easy Setup various configs").action(async()=>{await s();let e=await kt({message:`Which files do you want to install?
`,choices:Re});for(let o of e)K[o]!==void 0&&await K[o]()});import{Command as xt}from"commander";var Ke=new xt().command("latest").description("Check latest version of @in-ch/cli package").action(()=>wt()),wt=async()=>{await s();let e=await C("@in-ch/setup");console.log(`The latest version of @in-ch/setup is v${e}`)};import{Command as bt}from"commander";import{execSync as oe}from"child_process";import{confirm as vt,input as St}from"@inquirer/prompts";var Xe=async()=>{console.log(`
Checking Lighthouse dependencies...
`);try{let e=oe("lighthouse --version",{encoding:"utf-8"});console.log("Lighouse version: ",e.trim()+`
`)}catch{await vt({message:"Lighthouse is not installed. Would you like to install it?"})&&oe("npm i lighthouse -g",{stdio:"inherit"})}},qe=async(e=!1)=>{let o=await St({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}oe(`lighthouse ${o} ${e?'--chrome-flags="--headless"':" --output=html --view"} `,{stdio:"inherit"})};var Qe=new bt().command("lighthouse").alias("lg").description("Run a Lighthouse test").option("--headless","Run Lighthouse in headless mode").action(async e=>Et(e.headless)),Et=async(e=!1)=>{await s(),await Xe(),await qe(e)};import{Command as It}from"commander";import Mt from"fs";var Pt={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"},f=Pt;function te(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 ne({data:e,textColor:o=f.default,headerColor:t=f.default,borderColor:n=f.default}){let{rows:i,column:a}=te(e),c=f[n??"default"],y=f[t??"default"],F=f[o??"default"],v=a.map(m=>m.length+2).map((m,d)=>i.reduce((lo,mo)=>Math.max(mo[d].length+2,lo),m)),ro=(m,d)=>`${F}${m.padEnd(v[d])}`,io=(m,d)=>`${y}${m.padEnd(v[d])}`,so=()=>`${c}\u250C${a.map((m,d)=>"".padEnd(v[d]+1,"\u2500")).join("\u252C")}\u2510`,ao=()=>`${c}\u251C${a.map((m,d)=>"".padEnd(v[d]+1,"\u2500")).join("\u253C")}\u2524`,co=()=>`${c}\u2514${a.map((m,d)=>"".padEnd(v[d]+1,"\u2500")).join("\u2534")}\u2518`,k="";return k+=so()+`
`,k+=`${c}\u2502 ${a.map(io).join(`${c}\u2502 `)}${c}\u2502
`,k+=ao()+`
`,i.forEach(m=>{k+=`${c}\u2502 ${m.map(ro).join(`${c}\u2502 `)}\u2502
`}),k+=`${co()}${f.default}
`,k}import{fileURLToPath as Tt}from"url";var Ze=new It().command("list").description("list all commands").action(async()=>{await s();let o=typeof import.meta<"u"?Tt(import.meta.url):__filename,t=Mt.readFileSync(o,"utf-8"),n=/command\("(.+?)"\)\.description\("(.+?)"\)/g,i,a=[];for(;(i=n.exec(t))!==null;){let c=i[1].split('"')[0],y=i[2];a.push({command:c,description:y})}console.log(`${f.orange}@in-ch/setup${f.white}'s commands
${ne({data:a,borderColor:"lightBlack",textColor:"default",headerColor:"orange"})}
`)});import{execSync as At}from"child_process";import{Command as jt}from"commander";var eo=new jt().command("update").description("Update package version").action(async()=>Ft()),Ft=async()=>{await B();let e=await C("@in-ch/setup");await x().version!==e?At("npm install @in-ch/setup@latest -g",{stdio:"inherit"}):console.log("@in-ch/setup package is already up to date.")};import{Command as Lt}from"commander";import oo from"fs";import{execSync as Nt}from"child_process";async function re(e){try{let o=Nt("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")}}import{execSync as Ot}from"child_process";async function ie(e){try{await Ot(`code --install-extension ${e}`)}catch(o){o instanceof Error?console.error(o.message):console.error("An unknown error occurred")}}import Rt from"os";import j from"path";var to=(()=>{let e=Rt.platform();return e==="win32"?j.join(process.env.APPDATA||j.join(process.env.HOME,"AppData","Roaming"),"Code","User","settings.json"):e==="darwin"?j.join(process.env.HOME,"Library","Application Support","Code","User","settings.json"):j.join(process.env.HOME,".config","Code","User","settings.json")})(),$t={"[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 se(){try{oo.readFile(to,"utf8",async(e,o)=>{if(e&&e.code!=="ENOENT"){console.error("Error reading VSCode settings.json:",e);return}await re("esbenp.prettier-vscode")||await ie("esbenp.prettier-vscode");let n={};if(o)try{n=JSON.parse(o)}catch(a){console.error("Error parsing settings.json:",a);return}let i={...n,...$t};oo.writeFile(to,JSON.stringify(i,null,2),"utf8",a=>{a?console.error("Error writing to settings.json:",a):console.log("VSCode settings.json updated successfully!")})})}catch(e){l(e,"Failed to update vscode settings.json file")}}var no=new Lt().command("autoPrefix").alias("apf").description("Update VSCode Auto Prefix Settings").action(async()=>{await s(),se()});process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function Gt(){if(await R()){let o=await x(),t=new Dt().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(Ze),t.addCommand(ze),t.addCommand(ye),t.addCommand(Ae),t.addCommand(He),t.addCommand(Oe),t.addCommand(we),t.addCommand(Pe),t.addCommand(Be),t.addCommand(ue),t.addCommand(Qe),t.addCommand(no),t.addCommand(Ke),t.addCommand(eo),t.addCommand(Je),t.addCommand(Ue),t.addCommand(ce),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.')}Gt();
//# sourceMappingURL=index.js.map