mirror of
https://github.com/tiktok/sparo.git
synced 2025-02-17 00:21:14 -05:00
t
This commit is contained in:
parent
fe38729166
commit
938ea09301
1 changed files with 67 additions and 17 deletions
|
@ -1,5 +1,4 @@
|
||||||
import childProcess from 'child_process';
|
import { JsonFile, Sort, Async, Executable } from '@rushstack/node-core-library';
|
||||||
import { JsonFile, Sort } from '@rushstack/node-core-library';
|
|
||||||
import { inject } from 'inversify';
|
import { inject } from 'inversify';
|
||||||
import { SparoProfileService } from '../../services/SparoProfileService';
|
import { SparoProfileService } from '../../services/SparoProfileService';
|
||||||
import { ICommand } from './base';
|
import { ICommand } from './base';
|
||||||
|
@ -7,6 +6,7 @@ import { Command } from '../../decorator';
|
||||||
import { GitService } from '../../services/GitService';
|
import { GitService } from '../../services/GitService';
|
||||||
import { GitSparseCheckoutService } from '../../services/GitSparseCheckoutService';
|
import { GitSparseCheckoutService } from '../../services/GitSparseCheckoutService';
|
||||||
|
|
||||||
|
import type { ChildProcess } from 'child_process';
|
||||||
import type { Argv, ArgumentsCamelCase } from 'yargs';
|
import type { Argv, ArgumentsCamelCase } from 'yargs';
|
||||||
import type { TerminalService } from '../../services/TerminalService';
|
import type { TerminalService } from '../../services/TerminalService';
|
||||||
import type { SparoProfile } from '../../logic/SparoProfile';
|
import type { SparoProfile } from '../../logic/SparoProfile';
|
||||||
|
@ -98,16 +98,56 @@ export class ListProfilesCommand implements ICommand<IListProfilesCommandOptions
|
||||||
Sort.sortMapKeys(sparoProfiles);
|
Sort.sortMapKeys(sparoProfiles);
|
||||||
terminalService.terminal.writeLine(Array.from(sparoProfiles.keys()).join('\n'));
|
terminalService.terminal.writeLine(Array.from(sparoProfiles.keys()).join('\n'));
|
||||||
} else {
|
} else {
|
||||||
|
terminalService.terminal.writeLine(`Query profiles for project ${project}...`);
|
||||||
|
|
||||||
|
Executable.spawnSync('rush', ['list', '--help']);
|
||||||
|
|
||||||
// Query all profiles that contain the specified project
|
// Query all profiles that contain the specified project
|
||||||
const profileProjects: Map<string, string[]> = new Map<string, string[]>();
|
const profileProjects: Map<string, string[]> = new Map<string, string[]>();
|
||||||
for (const [profileName, sparoProfile] of sparoProfiles) {
|
await Async.forEachAsync(
|
||||||
|
sparoProfiles.entries(),
|
||||||
|
async ([profileName, sparoProfile]) => {
|
||||||
const { toSelectors, fromSelectors } = sparoProfile.rushSelectors;
|
const { toSelectors, fromSelectors } = sparoProfile.rushSelectors;
|
||||||
const rushListCmd: string = `rush list --json ${Array.from(toSelectors)
|
const rushListArgs: string[] = ['list', '--json'];
|
||||||
.map((x) => `--to ${x}`)
|
for (const selector of toSelectors) {
|
||||||
.join(' ')} ${Array.from(fromSelectors)
|
rushListArgs.push('--to');
|
||||||
.map((x) => `--from ${x}`)
|
rushListArgs.push(selector);
|
||||||
.join(' ')} `;
|
}
|
||||||
const res: { projects: IProject[] } = JSON.parse(childProcess.execSync(rushListCmd).toString());
|
for (const selector of fromSelectors) {
|
||||||
|
rushListArgs.push('--from');
|
||||||
|
rushListArgs.push(selector);
|
||||||
|
}
|
||||||
|
const childProcess: ChildProcess = Executable.spawn('testrush', rushListArgs, {
|
||||||
|
stdio: ['ignore', 'pipe', 'pipe']
|
||||||
|
});
|
||||||
|
childProcess.stdout!.setEncoding('utf8');
|
||||||
|
childProcess.stderr!.setEncoding('utf8');
|
||||||
|
|
||||||
|
const rushListResultJsonString: string = await new Promise((resolve, reject) => {
|
||||||
|
let stdoutString: string = '';
|
||||||
|
let errorMessage: string = '';
|
||||||
|
|
||||||
|
childProcess.stdout!.on('data', (chunk: Buffer) => {
|
||||||
|
stdoutString += chunk.toString();
|
||||||
|
});
|
||||||
|
childProcess.stderr!.on('data', (chunk: Buffer) => {
|
||||||
|
errorMessage += chunk.toString();
|
||||||
|
});
|
||||||
|
childProcess.on('close', (exitCode: number | null, signal: NodeJS.Signals | null) => {
|
||||||
|
if (exitCode) {
|
||||||
|
reject(
|
||||||
|
new Error(
|
||||||
|
`rush exited with error code ${exitCode}${errorMessage ? `: ${errorMessage}` : ''}`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else if (signal) {
|
||||||
|
reject(new Error(`rush terminated by signal ${signal}`));
|
||||||
|
}
|
||||||
|
resolve(stdoutString);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
const res: { projects: IProject[] } = JSON.parse(rushListResultJsonString.trim());
|
||||||
for (const project of res.projects) {
|
for (const project of res.projects) {
|
||||||
if (profileProjects.has(project.name)) {
|
if (profileProjects.has(project.name)) {
|
||||||
const profiles: string[] | undefined = profileProjects.get(project.name);
|
const profiles: string[] | undefined = profileProjects.get(project.name);
|
||||||
|
@ -116,7 +156,17 @@ export class ListProfilesCommand implements ICommand<IListProfilesCommandOptions
|
||||||
profileProjects.set(project.name, [profileName]);
|
profileProjects.set(project.name, [profileName]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('====', profileName, rushListArgs.join(' '));
|
||||||
|
console.warn(rushListResultJsonString.split('\n').slice(0, 10).join('\n'));
|
||||||
|
console.warn('======');
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
concurrency: 3
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const profilesContainProject: string[] | undefined = profileProjects.get(project);
|
const profilesContainProject: string[] | undefined = profileProjects.get(project);
|
||||||
if (profilesContainProject) {
|
if (profilesContainProject) {
|
||||||
|
|
Loading…
Reference in a new issue