代码之家  ›  专栏  ›  技术社区  ›  Hedge

如何仅在MacOS上运行package.json postill脚本

  •  1
  • Hedge  · 技术社区  · 8 年前

    我必须执行这个 postinstall MacOS上的脚本(修复react本机映射中的临时错误):

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

    在Linux或Windows上不需要它,所以我如何只在MacOS上执行它?

    1 回复  |  直到 8 年前
        1
  •  2
  •   Andrew Myers Sanchit Panchwatikar    7 年前

    这个 cross-os 使用package.json,NPM包似乎可以完全满足您的需求,即:

    "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'"
      }
    }
    

    示例仅来自repo;命名显然会反映您的用例等。