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

时间:2020-01-23 21:00:46

标签: javascript android powershell react-native package.json

我正在使用detox进行我的本机应用程序的端到端测试。当我尝试运行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.

1 个答案:

答案 0 :(得分:1)

您应该使用&&在npm脚本的任何平台和任何shell上运行多个命令。您可能希望它无法在Powershell上运行,但实际上可以。

[npm]的&&语义不完全相同(它执行 第二个命令,无论第一个命令是否成功),但它确实 可以将一行中的多个命令串在一起。

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

相关问题