怎么用命令行CLI一键生成各种烦人的lint配置(cli,lint,开发技术)

时间:2024-04-29 08:42:05 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

create-lint-config

这个工具叫做 create-lint-config,一个一键创建所有的 lint 配置的 CLI 命令行工具。前端工程中特别多的配置文件例如 Eslint、Prettier 等让我们心烦意乱。我们的目标是快速而轻松地生成这些配置!

使用

在你的项目根目录执行以下命令:

#npmnpmcreatelint-config@latest#yarnyarncreatelint-config#pnpmpnpmcreatelint-config@latest

执行结果如下:

怎么用命令行CLI一键生成各种烦人的lint配置

这个命令,一次执行,创建了 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配置的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:js如何获取异步函数数据下一篇:

5 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18