如何仅在macOS上运行package.json postinstall脚本

时间:2018-05-29 13:00:33

标签: node.js macos npm package.json

我必须在MacOS上执行此postinstall脚本(以修复react-native-maps中的临时错误):

"scripts": {
  "postinstall": "sed -i '' '/Google.*\\.[h|m]/d' node_modules/react-native-maps/lib/ios/AirMaps.xcodeproj/project.pbxproj"
}

在Linux或Windows上不需要它,所以如何才能在macOS上执行它?

1 个答案:

答案 0 :(得分:1)

cross-os npm包似乎完全按照你想要的方式使用package.json,即:

"scripts": {
  "foo": "cross-os bar",
  "bar": {
    "darwin": "echo 'i will only run on Mac'",
    "win32": "echo 'i will only run on Windows'",
    "linux": "echo 'i will only run on Linux'"
  }
}

所以在你的情况下如下:

"scripts": {
  "postinstall": "cross-os bar"
}
"cross-os": {
  "bar": {
    "darwin": "echo 'i will only run on Mac'",
    "win32": "echo 'i will only run on Windows'",
    "linux": "echo 'i will only run on Linux'"
  }
}

例子来自回购;命名显然会反映您的用例等。