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"`
|
`npm run affected -- --target extract-i18n --files="libs/${mylib}/src/index.ts"`
|
||||||
);
|
);
|
||||||
expect(i18n).toContain(`Running extract-i18n for ${myapp}`);
|
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);
|
}, 1000000);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -14,7 +14,8 @@ import {
|
|||||||
getProjectNames,
|
getProjectNames,
|
||||||
parseFiles,
|
parseFiles,
|
||||||
getAllProjectNamesWithTarget,
|
getAllProjectNamesWithTarget,
|
||||||
getAffectedProjectsWithTarget
|
getAffectedProjectsWithTarget,
|
||||||
|
readAngularJson
|
||||||
} from './shared';
|
} from './shared';
|
||||||
import { generateGraph } from './dep-graph';
|
import { generateGraph } from './dep-graph';
|
||||||
import { GlobalNxArgs } from './nx';
|
import { GlobalNxArgs } from './nx';
|
||||||
@ -155,6 +156,11 @@ async function runCommand(
|
|||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
console.log(`With flags: ${args.join(' ')}`);
|
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) {
|
if (parsedArgs.parallel) {
|
||||||
// Make sure the `package.json` has the `ng: "ng"` command needed by `npm-run-all`
|
// Make sure the `package.json` has the `ng: "ng"` command needed by `npm-run-all`
|
||||||
const packageJson = JSON.parse(
|
const packageJson = JSON.parse(
|
||||||
@ -170,8 +176,16 @@ async function runCommand(
|
|||||||
await runAll(
|
await runAll(
|
||||||
projects.map(app => {
|
projects.map(app => {
|
||||||
return ngCommands.includes(command)
|
return ngCommands.includes(command)
|
||||||
? `ng -- ${command} --project=${app} ${args.join(' ')} `
|
? `ng -- ${command} --project=${app} ${transformArgs(
|
||||||
: `ng -- run ${app}:${command} ${args.join(' ')} `;
|
args,
|
||||||
|
app,
|
||||||
|
projectMetadata.get(app)
|
||||||
|
).join(' ')} `
|
||||||
|
: `ng -- run ${app}:${command} ${transformArgs(
|
||||||
|
args,
|
||||||
|
app,
|
||||||
|
projectMetadata.get(app)
|
||||||
|
).join(' ')} `;
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
parallel: parsedArgs.parallel,
|
parallel: parsedArgs.parallel,
|
||||||
@ -209,8 +223,16 @@ async function runCommand(
|
|||||||
projects.forEach(project => {
|
projects.forEach(project => {
|
||||||
console.log(`${iterationMessage} ${project}`);
|
console.log(`${iterationMessage} ${project}`);
|
||||||
const task = ngCommands.includes(command)
|
const task = ngCommands.includes(command)
|
||||||
? `node ${ngPath()} ${command} --project=${project} ${args.join(' ')} `
|
? `node ${ngPath()} ${command} --project=${project} ${transformArgs(
|
||||||
: `node ${ngPath()} run ${project}:${command} ${args.join(' ')} `;
|
args,
|
||||||
|
project,
|
||||||
|
projectMetadata.get(project)
|
||||||
|
).join(' ')} `
|
||||||
|
: `node ${ngPath()} run ${project}:${command} ${transformArgs(
|
||||||
|
args,
|
||||||
|
project,
|
||||||
|
projectMetadata.get(project)
|
||||||
|
).join(' ')} `;
|
||||||
try {
|
try {
|
||||||
execSync(task, {
|
execSync(task, {
|
||||||
stdio: [0, 1, 2]
|
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[] {
|
function filterNxSpecificArgs(parsedArgs: YargsAffectedOptions): string[] {
|
||||||
const filteredArgs = { ...parsedArgs };
|
const filteredArgs = { ...parsedArgs };
|
||||||
// Delete Nx arguments from parsed Args
|
// Delete Nx arguments from parsed Args
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user