脚本宝典收集整理的这篇文章主要介绍了命令行CLI一键生成各种烦人的lint配置实例,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
写一个前端工程,要配置特别多的配置文件,大量的配置文件让我们很烦心,占用了大量写代码的时间。
就像上图,看着就头大。
每次要启动一个新的项目,都要从头配一遍。有人可能把这些文件当做模板保存下来,有需要的时候再复制粘贴。可是各个项目还是不尽相同,还是需要手动改动。
于是我决定写一个命令行工具来解决这件事。
这个工具叫做 create-lint-config
,一个一键创建所有的 lint 配置的 CLI 命令行工具。前端工程中特别多的配置文件例如 Eslint、PRettier 等让我们心烦意乱。我们的目标是快速而轻松地生成这些配置!
在你的项目根目录执行以下命令:
# 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) })
--template
标志来选择模板,创建更多的配置文件模板,包括 ts、vue、react、node 等等以上就是命令行CLI一键生成各种烦人的lint配置实例的详细内容,更多关于命令行CLI一键生成lint配置的资料请关注脚本宝典其它相关文章!
以上是脚本宝典为你收集整理的命令行CLI一键生成各种烦人的lint配置实例全部内容,希望文章能够帮你解决命令行CLI一键生成各种烦人的lint配置实例所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。