_Please make sure you have read the submission guidelines before posting an issue_
When running something like nx affected:apps --all or nx affected:apps, I would like to be able to only get the list of apps as output.
The purpose is to be able to write scripts that use the output of nx affected:apps.
Currently, I get the following extra line just before the list of apps:
Note: Nx defaulted to --base=master --head=HEAD
Please provide any relevant information about your setup:
@victornoel you may find it useful to require parseFiles and getAffectedApps from @nrwl/workspace/src/command-line/shared. We use those functions at work for a similar purpose to what you described.
const {
parseFiles,
getAffectedApps
} = require('@nrwl/schematics/src/command-line/shared');
const affectedApps = getAffectedApps(
parseFiles({
base: 'origin/master',
head: 'HEAD'
}).files
);
We're on version 7 of Nx, but I think it'll work the same for version 8.
@victornoel I'm actually thinking about having a --json option to affected commands, so you can pass the result of a command invocation to JSON.parse.
@vsavkin yes, this would work for me. The main objective is to exploit this kind of information in CI scripts and stuffs like that :)
After the update to 8.3 I wrote myself a bash script:
npm run affected:apps -- --base=$BASE --exclude=$EXCLUDES | awk 'NR > 7 { print $2 }' | sed '$d' | tr '\n' ','
Maybe this helps people in their CI/CD Pipelines :)
@vsavkin I just upgraded from 8.0 to 8.4 and now, the output of affected:apps is almost useless (except for doing https://github.com/nrwl/nx/issues/1571#issuecomment-515659813 but it's not working exactly as I would like…). I can hack it away, but it would be great to know if the json output feature you were talking about was still planned to be implemented, and maybe if you know when?
Thanks @BuckyMaler, I went with your solution until then, updated for 8.4:
const {
parseFiles,
getAffectedApps
} = require('@nrwl/workspace/src/command-line/shared');
const affectedApps = getAffectedApps(
parseFiles({
base: process.argv[2] || 'origin/master',
head: 'HEAD'
}).files
);
console.log(affectedApps.join(' '));
Folks, we are working on it. Thank you for your patience.
So what is the solution for v8.8?
This is what I come to:
nx print-affected | jq -r '.dependencyGraph.projects[] | select(.type=="app") | .name'
Unfortunately it is way slower than the script provided by @victornoel and the "getAffectedApps" is gone from the shared lib in v8.8.
@vilbara a new --plain option was added, see doc:
https://github.com/nrwl/nx/blob/master/docs/angular/api-workspace/npmscripts/format-check.md#plain
Folks,
--plain provides the old output with the apps and libs just separated with a space.
So you could do:
nx affected:apps --base=master --plain
And it will print:
app1 app2
We added print-affected to print a lot more information as well. We are working on enhancing print-affected to handle more scenarios.
I'm going to close it.
@vsavkin great, thanks :)
@vsavkin In which version was this fixed ?
Most helpful comment
Folks, we are working on it. Thank you for your patience.