feat(nx): add ability to use interpolated arguments in affected
This commit is contained in:
parent
801cac90d4
commit
09a3ee66ea
@ -197,5 +197,10 @@ describe('Affected', () => {
|
||||
`npm run affected -- --target extract-i18n --files="libs/${mylib}/src/index.ts"`
|
||||
);
|
||||
expect(i18n).toContain(`Running extract-i18n for ${myapp}`);
|
||||
|
||||
const interpolatedTests = runCommand(
|
||||
`npm run affected -- --target test --files="libs/${mylib}/src/index.ts" -- --jest-config {project.root}jest.config.js`
|
||||
);
|
||||
expect(interpolatedTests).toContain(`Running test for ${mylib}`);
|
||||
}, 1000000);
|
||||
});
|
||||
|
||||
@ -14,7 +14,8 @@ import {
|
||||
getProjectNames,
|
||||
parseFiles,
|
||||
getAllProjectNamesWithTarget,
|
||||
getAffectedProjectsWithTarget
|
||||
getAffectedProjectsWithTarget,
|
||||
readAngularJson
|
||||
} from './shared';
|
||||
import { generateGraph } from './dep-graph';
|
||||
import { GlobalNxArgs } from './nx';
|
||||
@ -155,6 +156,11 @@ async function runCommand(
|
||||
if (args.length > 0) {
|
||||
console.log(`With flags: ${args.join(' ')}`);
|
||||
}
|
||||
const angularJson = readAngularJson();
|
||||
const projectMetadata = new Map<string, any>();
|
||||
projects.forEach(project => {
|
||||
projectMetadata.set(project, angularJson.projects[project]);
|
||||
});
|
||||
if (parsedArgs.parallel) {
|
||||
// Make sure the `package.json` has the `ng: "ng"` command needed by `npm-run-all`
|
||||
const packageJson = JSON.parse(
|
||||
@ -170,8 +176,16 @@ async function runCommand(
|
||||
await runAll(
|
||||
projects.map(app => {
|
||||
return ngCommands.includes(command)
|
||||
? `ng -- ${command} --project=${app} ${args.join(' ')} `
|
||||
: `ng -- run ${app}:${command} ${args.join(' ')} `;
|
||||
? `ng -- ${command} --project=${app} ${transformArgs(
|
||||
args,
|
||||
app,
|
||||
projectMetadata.get(app)
|
||||
).join(' ')} `
|
||||
: `ng -- run ${app}:${command} ${transformArgs(
|
||||
args,
|
||||
app,
|
||||
projectMetadata.get(app)
|
||||
).join(' ')} `;
|
||||
}),
|
||||
{
|
||||
parallel: parsedArgs.parallel,
|
||||
@ -209,8 +223,16 @@ async function runCommand(
|
||||
projects.forEach(project => {
|
||||
console.log(`${iterationMessage} ${project}`);
|
||||
const task = ngCommands.includes(command)
|
||||
? `node ${ngPath()} ${command} --project=${project} ${args.join(' ')} `
|
||||
: `node ${ngPath()} run ${project}:${command} ${args.join(' ')} `;
|
||||
? `node ${ngPath()} ${command} --project=${project} ${transformArgs(
|
||||
args,
|
||||
project,
|
||||
projectMetadata.get(project)
|
||||
).join(' ')} `
|
||||
: `node ${ngPath()} run ${project}:${command} ${transformArgs(
|
||||
args,
|
||||
project,
|
||||
projectMetadata.get(project)
|
||||
).join(' ')} `;
|
||||
try {
|
||||
execSync(task, {
|
||||
stdio: [0, 1, 2]
|
||||
@ -235,6 +257,26 @@ async function runCommand(
|
||||
}
|
||||
}
|
||||
|
||||
function transformArgs(
|
||||
args: string[],
|
||||
projectName: string,
|
||||
projectMetadata: any
|
||||
) {
|
||||
return args.map(arg => {
|
||||
const regex = /{project\.([^}]+)}/g;
|
||||
arg.replace(regex, (_, group: string) => {
|
||||
if (group.includes('.')) {
|
||||
throw new Error('Only top-level properties can be interpolated');
|
||||
}
|
||||
|
||||
if (group === 'name') {
|
||||
return projectName;
|
||||
}
|
||||
return projectMetadata[group];
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function filterNxSpecificArgs(parsedArgs: YargsAffectedOptions): string[] {
|
||||
const filteredArgs = { ...parsedArgs };
|
||||
// Delete Nx arguments from parsed Args
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user