选择带有递归glob for babel命令的文件

时间:2018-03-02 16:37:12

标签: node.js unix babel

给出以下文件夹结构:

.
└── 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

我想知道它可以采用递归的全局。

1 个答案:

答案 0 :(得分:0)

您可以使用以下命令处理当前目录(和子目录)中的所有babel . --only index.js -d /output/directory 个文件:

/output/directory

这将复制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"' {} \; 中当前目录的子文件夹结构,并将编译好的文件放在那里。

此外,可以将处理委托给bash并独立执行每个文件上的babel:

{
  "query": "i want to buy apples",
  "topScoringIntent": {
    "intent": "Buy",
    "score": 0.999846
  },
  "intents": [
    {
      "intent": "Buy",
      "score": 0.999846
    },
    {
      "intent": "None",
      "score": 0.2572831
    },
    {
      "intent": "sell",
      "score": 2.32163586e-7
    },
    {
      "intent": "prank",
      "score": 2.32163146e-7
    }
  ],
  "entities": [
    {
      "entity": "apples",
      "type": "Fruit",
      "startIndex": 14,
      "endIndex": 19,
      "resolution": {
        "values": [
          "apple"
        ]
      }
    }
  ]
}