在 windows cmd 中使用 for 循环递归迭代,不包括 node_modules 及其子目录

Iterate recursively using for loop in windows cmd, excluding node_modules and it's subdirectories

亲爱的 Whosebug 用户,我是 Linux 用户,我正在和我的朋友一起开发一个应用程序。 他们正在使用 Windows,问题是在我的 package.json 中,我得到了如下所示的 linter 脚本:

"scripts": {
  "lint": "eslint '.'"
}

以下脚本在 Linux 上工作正常(它递归地检查所有文件,不包括 node_modules 文件夹),但在 Windows 上失败。 我在网上搜索时发现 Windows 用户应该使用的脚本。

"wlint": "for /r %f in (*.js) do eslint %f"

我的伙伴告诉我它在 Windows 上工作正常,除了它通过 node_modules 目录。

问题是:如何修改脚本排除node_modules目录?

以下命令将路径名回显到管道中,查找不包含字符串 \node_modules\ 的行,然后对其运行 eslint。

FOR /R %f IN (*.js) DO (ECHO %~f | (findstr /V /L "\node_modules\" >NUL && eslint "%~f"))

像这样应该可以做你想做的事情。