繁体   English   中英

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

[英]How can I run multiple commands in package.json scripts?

我正在使用detox对我的 react-native 应用程序进行端到端测试。 当我尝试运行yarn detox build -c android.emu.release时,它不能很好地运行脚本cd android; ./gradlew assembleRelease app:assembleAndroidTest -DtestBuildType=release; cd - cd android; ./gradlew assembleRelease app:assembleAndroidTest -DtestBuildType=release; cd - 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] 对于 && 没有完全相同的语义(无论第一个命令是否成功,它都会执行第二个命令),但它确实可以将多个命令串在一行上。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM