Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to forward command into run-commands using NX CLI?

Given I have entries in angular.json that define various commands using the serverless CLI (as an example)

"serverless-deploy": {
  "builder": "@nrwl/workspace:run-commands",
  "options": {
    "command": "npx serverless deploy",
    "cwd": "apps/my-app"
  }
},
"serverless-remove": {
  "builder": "@nrwl/workspace:run-commands",
  "options": {
    "command": "npx serverless remove",
    "cwd": "apps/my-app"
  }
}

How can I improve this by reducing duplication and combining it into one entry so that I can forward the command in?

E.G something like this:

"sls": {
  "builder": "@nrwl/workspace:run-commands",
  "options": {
    "command": "npx serverless",
    "cwd": "apps/my-app"
  }
}

And then call it with nx run my-app:sls MYCOMMAND (E.G 'deploy' or 'remove')? Unfortunately the above doesn't work but would love to know if this is possible.

like image 600
williamsandonz Avatar asked Apr 29 '26 22:04

williamsandonz


1 Answers

"sls": {
  "builder": "@nrwl/workspace:run-commands",
  "options": {
    "commands": [
      "npx sls {args.cmd}"
    ],
    "cwd": "apps/api",
    "parallel": false
  }
},

nx run api:sls --cmd=deploy
like image 161
williamsandonz Avatar answered May 04 '26 13:05

williamsandonz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!