UNPKG

@anolilab/prettier-config

Version:
14 lines (12 loc) 2.4 kB
#!/usr/bin/env node var p=Object.defineProperty;var l=(e,r)=>p(e,"name",{value:r,configurable:!0});import{existsSync as a}from"node:fs";import{readFile as g,writeFile as c}from"node:fs/promises";import{join as i}from"node:path";import{exit as s}from"node:process";const m={arrowParens:"always",bracketSpacing:!0,embeddedLanguageFormatting:"auto",endOfLine:"lf",htmlWhitespaceSensitivity:"css",insertPragma:!1,jsxSingleQuote:!1,overrides:[{files:".eslintrc",options:{parser:"json"}},{files:".prettierrc",options:{parser:"json"}},{files:".stylelintrc",options:{parser:"json"}},{files:"package*.json",options:{printWidth:1e3}},{files:"*.yml",options:{singleQuote:!1}},{files:"*.yaml",options:{singleQuote:!1}}],printWidth:160,proseWrap:"preserve",quoteProps:"as-needed",rangeEnd:Number.POSITIVE_INFINITY,rangeStart:0,requirePragma:!1,semi:!0,singleQuote:!1,tabWidth:4,trailingComma:"all",useTabs:!1,vueIndentScriptAndStyle:!1};var u=Object.defineProperty,f=l((e,r)=>u(e,"name",{value:r,configurable:!0}),"a");const t=".prettierrc",d=f(async(e,r)=>{for(const o of[t,`${t}.js`,`${t}.cjs`,`${t}.mjs`,`${t}.json`,`${t}.json5`,`${t}.yaml`,`${t}.yml`,`${t}.toml`,"prettier.config.js","prettier.config.mjs","prettier.config.cjs"])if(a(i(e,o))){console.warn(`⚠️ ${o} already exists; Make sure that it includes the following for @anolilab/prettier-config to work as it should: ${JSON.stringify(m,void 0,4)} `);return}const n=i(e,".prettierrc.js");await c(n,`${r?'import config from "@anolilab/prettier-config";':'var config = require("@anolilab/prettier-config");'} ${r?"export default":"module.exports ="} { ...config, } `,"utf8")},"writePrettierRc"),y=f(async e=>{const r=i(e,".prettierignore");if(a(r)){console.warn("⚠️ .prettierignore already exists");return}await c(r,`${["*.md","*.sh","*.yml","*.svg","*.gif","*.log",".DS_Store","CNAME","AUTHORS","LICENSE","es/","lib/","dist/","coverage/"].join(` `)} `,"utf8")},"writePrettierIgnore");(async()=>{const e=process.cwd(),r=i(e,"package.json");a(r)||(console.error("No package.json found in the current directory. You need to run this command in a directory with a package.json file."),s(1));const n=JSON.parse(await g(r,"utf8"));console.log("Configuring @anolilab/prettier-config",e,` `);try{await d(e,n.type==="module"),await y(e),console.log("Everything went well, have fun!"),s(0)}catch(o){console.error("Something went wrong:",o),s(1)}})();