给定以下文件夹结构:
.
└── dogs
├── index.js
└── cats
├── index.js
└── racoons
├── index.js
└── walrus
└── index.js
我想运行babel-cli命令babel
并生成对应于每个index.js
的文件作为index.build.js
。
babel命令接收文件或文件夹:
babel index.js --out-file index.build.js
我想知道它可以采取递归glob。
您可以使用以下命令处理当前目录(和子目录)中的所有index.js
文件:
babel . --only index.js -d /output/directory
这将复制/output/directory
中当前目录的子文件夹结构,并将编译后的文件放在那里。
此外,可以将处理委托给bash并在每个文件上独立执行babel:
function processFile(){
local fPath=$1
local fDir=$(dirname $fPath)
local fName=$(basename $fPath)
pushd "$fDir"
babel "$fName" -o "${fName%.js}.build.js"
popd
}
export -f processFile
find . -type f -name "index.js" -exec bash -c 'processFile "$0"' {} \;