怎么用命令行CLI一键生成各种烦人的lint配置
导读:本文共1808.5字符,通常情况下阅读需要6分钟。同时您也可以点击右侧朗读,来听本文内容。按键盘←(左) →(右) 方向键可以翻页。
摘要: create-lint-config这个工具叫做 create-lint-config,一个一键创建所有的 lint 配置的 CLI 命令行工具。前端工程中特别多的配置文件例如 Eslint、Prettier 等让我们心烦意乱。我们的目标是快速而轻松地生成这些配置!使用在你的项目根目录执行以下命令:#npmnpmcreatelint-config@latest... ...
目录
(为您整理了一些要点),点击可以直达。create-lint-config
这个工具叫做 create-lint-config
,一个一键创建所有的 lint 配置的 CLI 命令行工具。前端工程中特别多的配置文件例如 Eslint、Prettier 等让我们心烦意乱。我们的目标是快速而轻松地生成这些配置!
使用
在你的项目根目录执行以下命令:
#npmnpmcreatelint-config@latest#yarnyarncreatelint-config#pnpmpnpmcreatelint-config@latest
执行结果如下:
这个命令,一次执行,创建了 Eslint、StyleLint、prettier、commitlint、husy、lint-staged 等所有配置文件。
现有功能
生成 Eslint 配置。
生成 prettier 配置。
生成 stylelint 配置。
生成 husky 配置。
生成 commitlint 配置。
自动安装依赖。
期待更多。
源码解读
#!/usr/bin/envnodeasyncfunctioninstall({pkgManager,cwd,_arguments}:{pkgManager:string;cwd:string;arguments:array}){}asyncfunctioninit(){//拷贝配置文件基础模板,包括Eslint、StyleLint、prettier、commitlint、husy、lint-stagedawaitspinner({start:`Basetemplatecopying...`,end:'Templatecopied',while:()=>{try{copy('base')}catch(e){error('error',e)process.exit(1)}},})//安装huskyawaitspinner({start:`Huskyinstalling...`,end:'Huskyinstalled',while:()=>install({cwd:process.cwd(),pkgManager:'npx',_arguments:['husky','install'],}).catch((e)=>{error('error',e)process.exit(1)}),})//husky写入commit-msg校验指令,使用commitlintawaitspinner({start:`Addingcommit-msglint...`,end:'Commit-msglintadded',while:()=>install({cwd:process.cwd(),pkgManager:'npx',_arguments:['husky','add','.husky/commit-msg','npx--no-installcommitlint--edit""'],}).catch((e)=>{error('error',e)process.exit(1)}),})//husky写入pre-commit校验指令,使用lint-staged执行elint等awaitspinner({start:`Addinglint-staged...`,end:'Lint-stagedadded',while:()=>install({cwd:process.cwd(),pkgManager:'npx',_arguments:['husky','add','.husky/pre-commit','npxlint-staged'],}).catch((e)=>{error('error',e)process.exit(1)}),})//安装依赖awaitspinner({start:`Dependenciesinstallingwithnpm...`,end:'Dependenciesinstalled',while:()=>install({cwd:process.cwd(),pkgManager:'npm',_arguments:['install'],}).catch((e)=>{error('error',e)process.exit(1)}),})}init().catch((e)=>{console.error(e)})
TODO
支持通过
--template
标志来选择模板,创建更多的配置文件模板,包括 ts、vue、react、node 等等支持更灵活的交互式选项。现在只能一键生成默认的模板,有些配置可能是一些人不需要的,后续计划可以更灵活。
</div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
怎么用命令行CLI一键生成各种烦人的lint配置的详细内容,希望对您有所帮助,信息来源于网络。