javascript - 如何在 package.json 脚本中运行多个命令?

标签 javascript android powershell react-native package.json

我正在使用detox用于端到端测试我的 react native 应用程序。当我尝试运行yarn detox build -c android.emu.release时它不能很好地运行脚本 cd android ; ./gradlew assembleRelease app:assembleAndroidTest -DtestBuildType=release ; cd - 。该脚本由 detox init 自动生成.

这是我的package.json文件:

{
  "detox": {
    /*...*/
    "android.emu.release": {
        "binaryPath": "android/app/build/outputs/apk/release/app-release.apk",
        "build": "cd android  ./gradlew assembleRelease app:assembleAndroidTest -DtestBuildType=release ; cd -", //<<<<<<<<<<<
        "type": "android.emulator",
        "device": {
          "avdName": "NexusOneAPI29"
        }
      }
    /*...*/
  },
  /*...*/
}

我正在努力奔跑yarn detox build -c android.emu.release例如。如果

我需要使用哪个符号/字符来连接命令而不是 ;正在排毒?

我认为主要错误是:The system cannot find the path specified.从下面提取。

$ yarn detox-build                                                  
yarn run v1.21.1
detox[7600] INFO:  [build.js] cd android ; gradlew assembleRelease app:assembleAndroidTest -DtestBuildType=release ; cd -
The system cannot find the path specified.
detox[7600] ERROR: [cli.js] Error: Command failed: cd android ; gradlew assembleRelease app:assembleAndroidTest -DtestBuildType=releas
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

最佳答案

您应该使用 && 从 npm 脚本在任何平台和任何 shell 上运行多个命令。您可能认为它在 powershell 上不起作用,但实际上它确实有效。

[npm] doesn't have the exact same semantics for && (it executes the second command regardless of the success of the first), but it does work to string together multiple commands on a line.

https://github.com/npm/npm/issues/4040#issuecomment-209034612

关于javascript - 如何在 package.json 脚本中运行多个命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59886960/

相关文章:

javascript - 从 JS 调用 IE Js 调试器

java - 选中复选框时如何删除列表项?

powershell - 使用DisplayNames从文本文件获取SamAccountName

batch-file - 设置服务器列表的PW永不过期

javascript - 如何在 firebase set() 中返回 promise

javascript - HTML/CSS/JS 画线

android - 使用 Intent 获取蓝牙设置连接和配对屏幕?

android - 'drawable' 文件夹和 'drawable-hdpi-ldpi-mdpi-xhdpi' 文件夹有什么区别?

powershell - 如何使用PowerShell按日期对文件进行分组?

javascript - Heatmap dc.js - 手动提供颜色范围