【问题标题】:How can I run multiple commands in package.json scripts?如何在 package.json 脚本中运行多个命令?
【发布时间】:2020-05-10 05:18:24
【问题描述】:

我正在使用 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.

【问题讨论】:

  • 你想在里面加入 shell 脚本吗?
  • 我知道您的目标是 Android,但是您在什么环境中运行 npm 脚本?您是否尝试过使用&amp;&amp; 而不是;
  • 我确实尝试过&amp;&amp;,但它在 Windows 上的 Powershell 上不起作用:'(
  • @AlexandreLage - 是的,你是对的,我忘记了我之前在 Powershell 中的created an alias for the which command。你需要运行get-command cmd.exe。但是,它现在不相关,因为您的问题与原始问题有很大不同。

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


【解决方案1】:

您应该使用&amp;&amp; 在任何平台和来自 npm 脚本的任何 shell 上运行多个命令。你会认为它在 powershell 上不起作用,但它确实可以。

[npm] 没有与 && 完全相同的语义(它执行 第二个命令不管第一个是否成功),但它确实 努力将多个命令串在一起。

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

【讨论】:

  • 谢谢。你说的对。我更新了我的问题,因为我意识到问题不是将&amp;&amp; 与 npm 脚本一起使用,而是与 detox 脚本一起使用。投票给你
猜你喜欢
  • 2019-08-15
  • 2020-08-11
  • 2022-08-17
  • 1970-01-01
  • 2018-08-02
  • 2020-07-27
  • 1970-01-01
  • 2019-08-24
  • 1970-01-01
相关资源
最近更新 更多