@in-ch/setup
Version:
A tool for quick setup and configuration of essential project files.
106 lines (88 loc) • 24.3 kB
JavaScript
;var io=Object.create;var le=Object.defineProperty;var ro=Object.getOwnPropertyDescriptor;var so=Object.getOwnPropertyNames;var ao=Object.getPrototypeOf,co=Object.prototype.hasOwnProperty;var lo=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of so(t))!co.call(e,a)&&a!==o&&le(e,a,{get:()=>t[a],enumerable:!(n=ro(t,a))||n.enumerable});return e};var s=(e,t,o)=>(o=e!=null?io(ao(e)):{},lo(t||!e||!e.__esModule?le(o,"default",{value:e,enumerable:!0}):o,e));var Kt=require("commander");var dt=require("commander");var Pe=require("commander"),Ie=require("fs");var D=require("child_process");var C={NPM:"npm",PNPM:"pnpm",YARN:"yarn"},L={NPM:"npm",PNPM:"pnpm",YARN:"yarn"},O={NPM:"npm install",PNPM:"pnpm add",YARN:"yarn add"},me=[{name:C.NPM,value:L.NPM},{name:C.PNPM,value:L.PNPM},{name:C.YARN,value:L.YARN},{name:"cancel",value:"cancel"}],l=[{name:C.NPM,value:O.NPM},{name:C.PNPM,value:O.PNPM},{name:C.YARN,value:O.YARN},{name:"cancel",value:"cancel"}];var pe=s(require("fs"),1),mo=()=>{let e=pe.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"},m=mo;var de=s(require("path"),1),fe=require("@inquirer/prompts"),ge=async()=>{console.log(`
Installing husky dependencies...
`);try{let e="husky -D",t=m();if(t==="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.
`),t==="default")){let n=await(0,fe.select)({message:`Which package manager would you like to use for installation?
`,choices:l});if(n==="cancel")return;t=n}let o=`${t} ${e}`;(0,D.execSync)(`${o} -D`,{stdio:"inherit"})}catch{console.error("\u{1F972} \u{1F972} \u{1F972} Failed to install dependencies..."),process.exit(1)}},ue=async()=>{(0,D.execSync)("npx husky init",{stdio:"inherit"})},he=async()=>{let e=de.default.resolve(process.cwd(),"package.json"),t=await import("fs-extra");try{await t.access(e)}catch{console.error("Could not find the package.json file.");return}try{let o=await t.readFile(e,"utf-8"),n=JSON.parse(o);n.scripts||(n.scripts={}),n.scripts.test='echo "Error: no test specified" && exit 1',await t.writeFile(e,JSON.stringify(n,null,2),"utf-8"),console.log("package.json file updated successfully.")}catch(o){console.error("An error occurred while reading or modifying the package.json file:",o)}};var R=require("child_process");var ye=require("child_process"),Ce=require("commander");var ke=require("@inquirer/prompts"),xe=new Ce.Command().command("pm").description("Initialize package manager").action(async()=>w()),w=async()=>{try{let e=await(0,ke.select)({message:`Which package manager would you like to use?
`,choices:me});if(e==="cancel")return;(0,ye.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 Se=require("@inquirer/prompts");var we=require("child_process");function h(e){return new Promise((t,o)=>{(0,we.exec)(`npm show ${e} version`,(n,a,c)=>{if(n){o(`Error fetching latest version: ${n.message}`);return}if(c){o(`Error: ${c}`);return}t(a.trim())})})}var ve=require("child_process"),G=s(require("fs-extra"),1),be=s(require("path"),1);function k(e="@in-ch/setup"){try{let t=(0,ve.execSync)("npm root -g",{encoding:"utf-8"}).trim(),o=be.default.join(t,e,"package.json");if(G.default.existsSync(o))return JSON.parse(G.default.readFileSync(o,"utf-8"));throw new Error("package.json not found")}catch(t){return console.error("Error fetching global package.json:",t),null}}function U(){try{(0,R.execSync)("npm --version",{stdio:"ignore"})}catch{w()}}async function r(){U();let e=await h("@in-ch/setup"),t=await k().version;t!==e&&await(0,Se.confirm)({message:`The latest version is ${e}, but the current version is ${t}. An update is needed. Would you like to update?`})&&((0,R.execSync)("npm install @in-ch/setup@latest -g",{stdio:"inherit"}),console.log("Update completed successfully."))}var Me=require("@inquirer/prompts"),Ee=new Pe.Command().command("husky").description("Setup husky").action(async()=>v()),v=async()=>{if(await r(),[".husky"].filter(o=>(0,Ie.existsSync)(o)).length>0&&!await(0,Me.confirm)({message:"Husky settings are already configured. Do you still want to proceed with the setup?"})){console.log("canceled!");return}await ge(),await ue(),await he()};var ft=require("fs");var ct=require("child_process");var Oe=require("commander");var De=require("fs");var b=require("child_process");var Y=s(require("fs"),1);var Ae=require("child_process"),Te=s(require("path"),1);function V(e){try{let t=(0,Ae.execSync)("npm root -g",{encoding:"utf8"}).trim();return Te.default.resolve(t,e)}catch(t){return console.error("Error resolving global package path:",t),null}}var _=s(require("path"),1);function d(e){if(!e)throw new Error("File name is required");if(process.env.NODE_ENV==="development")return _.default.resolve(process.cwd(),"const/config",e)+B[e];{let o=V("@in-ch/setup");if(!o)throw new Error("Could not resolve global path for @in-ch/setup");return _.default.resolve(o,"const/config",e)+B[e]}}var je=s(require("path"),1),S=require("@inquirer/prompts"),Fe=async()=>{console.log(`
Installing eslint dependencies...
`);try{let e="eslint @types/eslint eslint-plugin-jsdoc eslint-plugin-no-for-of-array eslint-plugin-vue @eslint/js typescript-eslint globals",t=m();if(t==="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.
`),t==="default")){let n=await(0,S.select)({message:`Which package manager would you like to use for installation?
`,choices:l});if(n==="cancel")return;t=n}let o=`${t} ${e}`;(0,b.execSync)(`${o} -D`,{stdio:"inherit"})}catch{console.error("\u{1F972} \u{1F972} \u{1F972} Failed to install dependencies..."),process.exit(1)}},Ne=async()=>{console.log(`
Installing eslint dependencies...
`);try{let e="eslint eslint-config-airbnb-base eslint-plugin-import @typescript-eslint/parser @typescript-eslint/eslint-plugin",t=m();if(t==="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.
`),t==="default")){let n=await(0,S.select)({message:`Which package manager would you like to use for installation?
`,choices:l});if(n==="cancel")return;t=n}let o=`${t} ${e}`;(0,b.execSync)(`${o} -D`,{stdio:"inherit"})}catch{console.error("\u{1F972} \u{1F972} \u{1F972} Failed to install dependencies..."),process.exit(1)}},$e=async()=>{console.log(`
Installing eslint dependencies...
`);try{let e="eslint eslint-config-google",t=m();if(t==="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.
`),t==="default")){let n=await(0,S.select)({message:`Which package manager would you like to use for installation?
`,choices:l});if(n==="cancel")return;t=n}let o=`${t} ${e}`;(0,b.execSync)(`${o} -D`,{stdio:"inherit"})}catch{console.error("\u{1F972} \u{1F972} \u{1F972} Failed to install dependencies..."),process.exit(1)}},Le=async()=>{console.log(`
Installing eslint dependencies...
`);try{let e="eslint eslint-config-xo",t=m();if(t==="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.
`),t==="default")){let n=await(0,S.select)({message:`Which package manager would you like to use for installation?
`,choices:l});if(n==="cancel")return;t=n}let o=`${t} ${e}`;(0,b.execSync)(`${o} -D`,{stdio:"inherit"})}catch{console.error("\u{1F972} \u{1F972} \u{1F972} Failed to install dependencies..."),process.exit(1)}},P=e=>{let t=process.cwd(),o=Y.default.readFileSync(d(e),"utf-8");try{Y.default.writeFileSync(je.default.join(t,"eslint.config.mjs"),o,"utf-8"),console.log(`
\u{1F389} Successfully created the ESLint configuration file.`)}catch(n){console.error(`\u{1F972} \u{1F972} \u{1F972} Failed to setup eslint... to
`,n),process.exit(1)}};var A=require("@inquirer/prompts"),Ge=new Oe.Command().command("eslint").description("Setup eslint file").action(async()=>W()),W=async()=>{if(await r(),[".eslintrc.js",".eslintrc.json",".eslintrc.yaml",".eslintrc.yml",".eslintrc.config.mjs",".eslintrc"].filter(n=>(0,De.existsSync)(n)).length>0&&!await(0,A.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,A.select)({message:"Choose an ESLint configuration type:",choices:H});o===E.airbnb?(console.log("Setting up Airbnb ESLint configuration..."),Ne(),P(i.AIRBNB)):o===E.google?(console.log("Setting up Google ESLint configuration..."),$e(),P(i.GOOGLE)):o===E.xo?(console.log("Setting up XO ESLint configuration..."),Le(),P(i.XO)):(console.log("Setting up Import Sort ESLint configuration..."),Fe(),P(i.ESLINT))};var _e=require("commander"),Be=require("fs");var T=require("child_process");var J=s(require("fs"),1);var Re=s(require("path"),1),Ue=async()=>{(0,T.execSync)("git init",{stdio:"inherit"})},Ve=()=>{let e=process.cwd(),t=J.default.readFileSync(d(i.GITMESSAGE),"utf-8");try{J.default.writeFileSync(Re.default.join(e,".gitmessage"),t,"utf-8"),(0,T.execSync)("git config commit.template .gitmessage"),(0,T.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(o){console.error(`\u{1F972} \u{1F972} \u{1F972} Failed to setup git message... to
`,o),process.exit(1)}};var Ye=require("@inquirer/prompts"),We=new _e.Command().command("gitmessage").description("Setup git message file").action(async()=>z()),z=async()=>{if(await r(),!(0,Be.existsSync)(".git")){if(!await(0,Ye.confirm)({message:"Git is not initialized. Would you like to initialize it?"})){console.log("canceled!");return}await Ue()}Ve()};var Xe=require("commander"),qe=require("fs");var He=require("child_process");var j=s(require("fs"),1);var K=s(require("path"),1),Je=require("@inquirer/prompts"),ze=async()=>{console.log(`
Installing prettier dependencies...
`);try{let e="prettier prettier-plugin-sort-re-exports @trivago/prettier-plugin-sort-imports",t=m();if(t==="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.
`),t==="default")){let n=await(0,Je.select)({message:`Which package manager would you like to use for installation?
`,choices:l});if(n==="cancel")return;t=n}let o=`${t} ${e}`;(0,He.execSync)(`${o} -D`,{stdio:"inherit"})}catch(e){console.error(`\u{1F972} Fail to install prettier dependencies.... to
`+e),process.exit(1)}},Ke=()=>{let e=process.cwd(),t=j.default.readFileSync(d(i.PRETTIER),"utf-8"),o=`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{j.default.writeFileSync(K.default.join(e,".prettierrc.cjs"),t,"utf-8"),j.default.writeFileSync(K.default.join(e,".prettierignore"),o,"utf-8"),console.log("\u{1F389} Prettier configuration file has been created.")}catch(n){console.error(`\u{1F972} Failed to setup prettier... to
`,n),process.exit(1)}};var Qe=require("@inquirer/prompts"),Ze=new Xe.Command().command("prettier").description("Setup prettier file").action(async()=>X()),X=async()=>{if(await r(),[".prettierrc",".prettierrc.json",".prettierrc.yml",".prettierrc.yaml",".prettierrc.js",".prettierrc.cjs","prettier.config.js","prettier.config.cjs"].filter(o=>(0,qe.existsSync)(o)).length>0&&!await(0,Qe.confirm)({message:"At least one Prettier file exists. Do you still want to proceed with the setup?"})){console.log("canceled!");return}ze(),Ke()};var nt=require("commander"),it=require("fs");var q=require("child_process");var et=require("@inquirer/prompts"),tt=async()=>{console.log(`
Installing typescript dependencies...
`);try{let e="typescript @types/node @types/react",t=m();if(t==="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.
`),t==="default")){let n=await(0,et.select)({message:`Which package manager would you like to use for installation?
`,choices:l});if(n==="cancel")return;t=n}let o=`${t} ${e}`;(0,q.execSync)(`${o} -D`,{stdio:"inherit"})}catch{console.error("\u{1F972} \u{1F972} \u{1F972} Failed to install dependencies..."),process.exit(1)}},ot=()=>{console.log("Configure Typescript"),(0,q.execSync)("npx tsc --init")};var rt=new nt.Command().command("typescript").description("Setup typescript file").action(async()=>Q()),Q=async()=>{if(await r(),[".tsconfig.json"].filter(o=>(0,it.existsSync)(o)).length>0){console.error("At least one Typescript file exists.");return}tt(),ot()};var i={ESLINT:"eslint",PRETTIER:"prettier",TYPESCRIPT:"typescript",GITMESSAGE:"gitmessage",HUSKY:"husky",COMMIT_LINT:"commitlint",LINT_STAGE:"lintstage",AIRBNB:"airbnb",GOOGLE:"google",XO:"xo"},po=Object.entries(i).filter(([e])=>![i.AIRBNB,i.GOOGLE,i.XO].includes(e)).map(([e,t])=>({name:e,value:t})),st=po.map(e=>e.value),Z={[i.ESLINT]:()=>W(),[i.PRETTIER]:()=>X(),[i.TYPESCRIPT]:()=>Q(),[i.GITMESSAGE]:()=>z(),[i.HUSKY]:()=>v(),[i.COMMIT_LINT]:()=>ee()},B={[i.ESLINT]:".js",[i.PRETTIER]:".js",[i.TYPESCRIPT]:".json",[i.GITMESSAGE]:".txt",[i.COMMIT_LINT]:".json",[i.LINT_STAGE]:".json",[i.AIRBNB]:".js",[i.GOOGLE]:".js",[i.XO]:".js"},at=[{name:i.ESLINT,value:i.ESLINT},{name:i.PRETTIER,value:i.PRETTIER},{name:i.TYPESCRIPT,value:i.TYPESCRIPT},{name:i.GITMESSAGE,value:i.GITMESSAGE},{name:i.HUSKY,value:i.HUSKY},{name:i.COMMIT_LINT,value:i.COMMIT_LINT}],H=[{name:"Import Sort",value:"import-sort"},{name:"Airbnb",value:"airbnb"},{name:"Google",value:"google"},{name:"XO",value:"xo"}],E=H.reduce((e,t)=>(e[t.value]=t.value,e),{});var I=s(require("fs"),1);var te=s(require("path"),1),lt=require("@inquirer/prompts"),mt=async()=>{console.log(`
Installing eslint dependencies...
`);try{let e=["@commitlint/config-conventional","@commitlint/cli","lint-staged"],t=m();if(t==="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.
`),t==="default")){let n=await(0,lt.select)({message:`Which package manager would you like to use for installation?
`,choices:l});if(n==="cancel")return;t=n}let o=`${t} ${e.join(" ")}`;(0,ct.execSync)(`${o} -D`,{stdio:"inherit"})}catch{console.error("\u{1F972} \u{1F972} \u{1F972} Failed to install commitlint's dependencies..."),process.exit(1)}},pt=()=>{let e=process.cwd(),t=I.default.readFileSync(d(i.COMMIT_LINT),"utf-8"),o=I.default.readFileSync(d(i.LINT_STAGE),"utf-8");try{I.default.writeFileSync(te.default.join(e,".commitlintrc.json"),t,"utf-8"),I.default.writeFileSync(te.default.join(e,".lintstagedrc.json"),o,"utf-8"),console.log(`
\u{1F389} Successfully created the Commitlint configuration file.`)}catch(n){console.error(`\u{1F972} \u{1F972} \u{1F972} Failed to setup commit lint... to
`,n),process.exit(1)}};var gt=require("@inquirer/prompts"),ut=new dt.Command().command("commitlint").description("Setup commit lint").action(async()=>ee()),ee=async()=>{if(await r(),!(0,ft.existsSync)(".husky")){if(!await(0,gt.confirm)({message:"Husky is not initialized. Would you like to initialize it?"})){console.log("canceled!");return}await v()}mt(),pt()};var kt=require("child_process"),xt=require("commander");var yt=require("child_process"),Ct=s(require("os"),1),ht=e=>{try{return(0,yt.execSync)(`which ${e}`,{stdio:"ignore"}),!0}catch{return!1}};function oe(e){let t=Ct.default.platform(),o;if(t==="win32")o=`start "" "notepad" "${e}"`;else if(t==="darwin")ht("code")?o=`open -a "Visual Studio Code" "${e}"`:o=`open -a "TextEdit" "${e}"`;else if(t==="linux")ht("code")?o=`code "${e}"`:o=`xdg-open "${e}"`;else return console.error("Unsupported platform"),"";return o}var wt=require("@inquirer/prompts"),vt=new xt.Command().command("edit").description("edit config file").action(async()=>{await r();let e=await(0,wt.select)({message:"What do you want to edit config file.",choices:at}),t=d(e),o=oe(t);(0,kt.exec)(o,n=>{n?console.error("Failed to open file or folder:",n):console.log(`Opened: ${t}`)})});var bt=require("commander");var St=require("@inquirer/prompts"),Pt=new bt.Command().command("init").description("Easy Setup various configs").action(async()=>{await r();let e=await(0,St.checkbox)({message:`Which files do you want to install?
`,choices:st});for(let t of e)Z[t]!==void 0&&await Z[t]()});var It=require("commander");var Mt=new It.Command().command("latest").description("Check latest version of @in-ch/cli package").action(()=>fo()),fo=async()=>{await r();let e=await h("@in-ch/setup");console.log(`The latest version of @in-ch/setup is v${e}`)};var Tt=require("commander");var F=require("child_process"),N=require("@inquirer/prompts"),Et=async()=>{console.log(`
Checking Lighthouse dependencies...
`);try{let e=(0,F.execSync)("lighthouse --version",{encoding:"utf-8"});console.log("Lighouse version: ",e.trim()+`
`)}catch{await(0,N.confirm)({message:"Lighthouse is not installed. Would you like to install it?"})&&(0,F.execSync)("npm i lighthouse -g",{stdio:"inherit"})}},At=async(e=!1)=>{let t=await(0,N.input)({message:"Enter the web address:",default:"http://localhost:3000"}),o=!1;try{let n=new URL(t);o=n.protocol==="http:"||n.protocol==="https:"}catch{o=!1}if(!o){console.error("Invalid web address. Please enter a valid URL.");return}(0,F.execSync)(`lighthouse ${t} ${e?'--chrome-flags="--headless"':" --output=html --view"} `,{stdio:"inherit"})};var jt=new Tt.Command().command("lg").description("Run a Lighthouse test").option("--headless","Run Lighthouse in headless mode").action(async e=>go(e.headless)),go=async(e=!1)=>{await r(),await Et(),await At(e)};var Nt=require("commander"),$t=s(require("fs"),1);var uo={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=uo;function ne(e){if(e.length===0||e[0]===void 0)return{column:[],rows:[]};let t=Object.keys(e.reduce((n,a)=>({...n,...a}),{})),o=e.map(n=>t.map(a=>n[a]||""));return{column:t,rows:o}}function ie({data:e,textColor:t=g.default,headerColor:o=g.default,borderColor:n=g.default}){let{rows:a,column:c}=ne(e),u=g[n??"default"],$=g[o??"default"],Xt=g[t??"default"],x=c.map(p=>p.length+2).map((p,f)=>a.reduce((oo,no)=>Math.max(no[f].length+2,oo),p)),qt=(p,f)=>`${Xt}${p.padEnd(x[f])}`,Qt=(p,f)=>`${$}${p.padEnd(x[f])}`,Zt=()=>`${u}\u250C${c.map((p,f)=>"".padEnd(x[f]+1,"\u2500")).join("\u252C")}\u2510`,eo=()=>`${u}\u251C${c.map((p,f)=>"".padEnd(x[f]+1,"\u2500")).join("\u253C")}\u2524`,to=()=>`${u}\u2514${c.map((p,f)=>"".padEnd(x[f]+1,"\u2500")).join("\u2534")}\u2518`,y="";return y+=Zt()+`
`,y+=`${u}\u2502 ${c.map(Qt).join(`${u}\u2502 `)}${u}\u2502
`,y+=eo()+`
`,a.forEach(p=>{y+=`${u}\u2502 ${p.map(qt).join(`${u}\u2502 `)}\u2502
`}),y+=`${to()}${g.default}
`,y}var Lt=require("url"),Ft={},Ot=new Nt.Command().command("list").description("list all commands").action(async()=>{await r();let t=typeof Ft<"u"?(0,Lt.fileURLToPath)(Ft.url):__filename,o=$t.default.readFileSync(t,"utf-8"),n=/command\("(.+?)"\)\.description\("(.+?)"\)/g,a,c=[];for(;(a=n.exec(o))!==null;){let u=a[1],$=a[2];c.push({command:u,description:$})}console.log(`${g.orange}@in-ch/setup${g.white}'s commands
${ie({data:c,borderColor:"lightBlack",textColor:"default",headerColor:"orange"})}
`)});var Dt=require("child_process"),Gt=require("commander");var Rt=new Gt.Command().command("update").description("Update package version").action(async()=>ho()),ho=async()=>{await U();let e=await h("@in-ch/setup");await k().version!==e?(0,Dt.execSync)("npm install @in-ch/setup@latest -g",{stdio:"inherit"}):console.log("@in-ch/setup package is already up to date.")};var Yt=require("commander");var ae=s(require("fs"),1),Bt=s(require("os"),1),M=s(require("path"),1);var Ut=require("child_process");async function re(e){try{let t=(0,Ut.execSync)("code --list-extensions",{stdio:"pipe"}).toString();return t?t.split(`
`).map(n=>n.trim()).includes(e):(console.error("No extensions found or error executing the command."),!1)}catch(t){t instanceof Error?console.error(t.message):console.error("An unknown error occurred")}}var Vt=require("child_process");async function se(e){try{await(0,Vt.execSync)(`code --install-extension ${e}`)}catch(t){t instanceof Error?console.error(t.message):console.error("An unknown error occurred")}}var _t=(()=>{let e=Bt.default.platform();return e==="win32"?M.default.join(process.env.APPDATA||M.default.join(process.env.HOME,"AppData","Roaming"),"Code","User","settings.json"):e==="darwin"?M.default.join(process.env.HOME,"Library","Application Support","Code","User","settings.json"):M.default.join(process.env.HOME,".config","Code","User","settings.json")})(),yo={"[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 ce(){ae.default.readFile(_t,"utf8",async(e,t)=>{if(e&&e.code!=="ENOENT"){console.error("Error reading VSCode settings.json:",e);return}await re("esbenp.prettier-vscode")||await se("esbenp.prettier-vscode");let n={};if(t)try{n=JSON.parse(t)}catch(c){console.error("Error parsing settings.json:",c);return}let a={...n,...yo};ae.default.writeFile(_t,JSON.stringify(a,null,2),"utf8",c=>{c?console.error("Error writing to settings.json:",c):console.log("VSCode settings.json updated successfully!")})})}var Wt=new Yt.Command().command("autoPrefix").description("Update VSCode Auto Prefix Settings").action(async()=>{await r(),ce()});var Ht=s(require("fs-extra"),1),Jt=s(require("path"),1);function zt(){let e=Jt.default.join("package.json");Ht.default.existsSync(e)||w()}process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function Co(){await zt();let e=await k(),t=new Kt.Command().name("@in-ch/setup").description("Quick config: Download and apply settings in seconds.").version(`@in-ch/setup v${e.version||"1.0.0"}`,"-v, --version","display the version number");t.addCommand(Ot),t.addCommand(Pt),t.addCommand(Ge),t.addCommand(Ze),t.addCommand(vt),t.addCommand(rt),t.addCommand(We),t.addCommand(Ee),t.addCommand(ut),t.addCommand(xe),t.addCommand(jt),t.addCommand(Wt),t.addCommand(Mt),t.addCommand(Rt),t.parse()}Co();
//# sourceMappingURL=index.cjs.map