如何通过CLI方便生成的Eslint、Prettier等配置文件
Admin 2023-04-03 群英技术资讯 809 次浏览
写一个前端工程,要配置特别多的配置文件,大量的配置文件让我们很烦心,占用了大量写代码的时间。
就像上图,看着就头大。
每次要启动一个新的项目,都要从头配一遍。有人可能把这些文件当做模板保存下来,有需要的时候再复制粘贴。可是各个项目还是不尽相同,还是需要手动改动。
于是我决定写一个命令行工具来解决这件事。
这个工具叫做 create-lint-config
,一个一键创建所有的 lint 配置的 CLI 命令行工具。前端工程中特别多的配置文件例如 Eslint、Prettier 等让我们心烦意乱。我们的目标是快速而轻松地生成这些配置!
github 地址
npm 地址
在你的项目根目录执行以下命令:
# npm npm create lint-config@latest # yarn yarn create lint-config # pnpm pnpm create lint-config@latest
执行结果如下:
这个命令,一次执行,创建了 Eslint、StyleLint、prettier、commitlint、husy、lint-staged 等所有配置文件。
#!/usr/bin/env node async function install({ pkgManager, cwd, _arguments }: { pkgManager: string; cwd: string; arguments: array }) {} async function init() { // 拷贝配置文件基础模板,包括 Eslint、StyleLint、prettier、commitlint、husy、lint-staged await spinner({ start: `Base template copying...`, end: 'Template copied', while: () => { try { copy('base') } catch (e) { error('error', e) process.exit(1) } }, }) // 安装 husky await spinner({ start: `Husky installing...`, end: 'Husky installed', while: () => install({ cwd: process.cwd(), pkgManager: 'npx', _arguments: ['husky', 'install'], }).catch((e) => { error('error', e) process.exit(1) }), }) // husky 写入 commit-msg 校验指令,使用 commitlint await spinner({ start: `Adding commit-msg lint...`, end: 'Commit-msg lint added', while: () => install({ cwd: process.cwd(), pkgManager: 'npx', _arguments: ['husky', 'add', '.husky/commit-msg', 'npx --no-install commitlint --edit ""'], }).catch((e) => { error('error', e) process.exit(1) }), }) // husky 写入 pre-commit校验指令,使用 lint-staged 执行 elint 等 await spinner({ start: `Adding lint-staged...`, end: 'Lint-staged added', while: () => install({ cwd: process.cwd(), pkgManager: 'npx', _arguments: ['husky', 'add', '.husky/pre-commit', 'npx lint-staged'], }).catch((e) => { error('error', e) process.exit(1) }), }) // 安装依赖 await spinner({ start: `Dependencies installing with npm...`, end: 'Dependencies installed', while: () => install({ cwd: process.cwd(), pkgManager: 'npm', _arguments: ['install'], }).catch((e) => { error('error', e) process.exit(1) }), }) } init().catch((e) => { console.error(e) })
更多源码请移步 GitHub 查看
--template
标志来选择模板,创建更多的配置文件模板,包括 ts、vue、react、node 等等这个包还在起步阶段,我希望有需求的同学可以来参与贡献。
github 地址
npm 地址
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
//文件处理类varfs=require('fs');varpath=require('path');varutil=require('util');varFile={in:function(content,flag){this.writeToFile("app.log",content,flag);},on:
最近项目中使用了minio作为静态资源管理服务,所以简单写一下如何通过minio来上传图片,下面这篇文章主要给大家介绍了关于Vue中通过minio上传文件的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下
VueUse 是一个基于 Composition API 的实用函数集合。本文就详细的介绍了VueUse的具体用法,具有一定的参考价值,感兴趣的可以了解一下
vue同级组件之间如何实现传值?我们知道Vue组件之间是有联系的,那么就免不了数组传值,因此这篇文章就给大家来介绍一下vue同级组件之间传值的方法,感兴趣的朋友就往下看吧。
这篇文章给大家分享的是jQuery如何设置元素只读的方法。小编觉得挺实用的,对新手学习jQuery的使用有一定的帮助,因此分享给大家做个参考,文中示例代码介绍的很详细,感兴趣的朋友接下来一起跟随小编看看吧。
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008