UNPKG

@anolilab/stylelint-config

Version:

Stylelint shareable config for the Anolilab stylesheet guide.

19 lines (16 loc) 1.39 kB
#!/usr/bin/env node import{existsSync as a}from"node:fs";import{readFile as f,writeFile as r}from"node:fs/promises";import{join as e}from"node:path";import{exit as s}from"node:process";const t=".stylelintrc",y=async(o,n)=>{const l=[t,`${t}.js`,`${t}.cjs`,`${t}.json`,`${t}.yaml`,`${t}.yml`,"stylelint.config.js","stylelint.config.cjs"];for(const c of l)if(a(e(o,c))){console.warn('⚠️ .stylelintrc.js already exists; Make sure that it includes the following for @anolilab/stylelint-config to work as it should: { "extends": ["@anolilab/stylelint-config"] }.');return}const i=e(o,".stylelintrc.js");await r(i,`${n?"export default":"module.exports ="} { "extends": [ "@anolilab/stylelint-config", ] }; `,"utf8")},g=async o=>{const n=e(o,".stylelintignore");a(n)||await r(n,`package.json package-lock.json yarn.lock pnpm-lock.yaml build/** node_modules/** .next/** dist/** `,"utf8")};(async()=>{const o=process.cwd(),n=e(o,"package.json");a(n)||(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 l=JSON.parse(await f(n,"utf8"));console.log("Configuring @anolilab/stylelint-config",o,` `);try{await y(o,l.type==="module"),await g(o),console.log("😎 Everything went well, have fun!"),s(0)}catch(i){console.log("😬 something went wrong:"),console.error(i),s(1)}})();