({
command,
args,
cwd,
}: utils.ProcessConfig)
| 117 | let yarnVersion: string; |
| 118 | |
| 119 | async function simulateCodePushUpExecution({ |
| 120 | command, |
| 121 | args, |
| 122 | cwd, |
| 123 | }: utils.ProcessConfig): Promise<utils.ProcessResult> { |
| 124 | const nxMatch = command.match(/nx run (\w+):code-pushup/); |
| 125 | const outputDir = nxMatch |
| 126 | ? path.join(workDir, `packages/${nxMatch[1]}/.code-pushup`) |
| 127 | : path.join(cwd as string, '.code-pushup'); |
| 128 | await mkdir(outputDir, { recursive: true }); |
| 129 | let stdout = ''; |
| 130 | |
| 131 | const isBulkCommand = /workspaces|concurrency|parallel/.test(command); |
| 132 | const projectOutputDirs = ['cli', 'core', 'utils'].map(project => |
| 133 | path.join(workDir, `packages/${project}/.code-pushup`), |
| 134 | ); |
| 135 | |
| 136 | switch (args![0]) { |
| 137 | case 'compare': |
| 138 | const diffs = fixturePaths.diffs.project; |
| 139 | if (isBulkCommand) { |
| 140 | await Promise.all( |
| 141 | projectOutputDirs.map(async dir => { |
| 142 | await mkdir(dir, { recursive: true }); |
| 143 | await copyFile(diffs.json, path.join(dir, 'report-diff.json')); |
| 144 | await copyFile(diffs.md, path.join(dir, 'report-diff.md')); |
| 145 | }), |
| 146 | ); |
| 147 | } else { |
| 148 | await copyFile(diffs.json, path.join(outputDir, 'report-diff.json')); |
| 149 | await copyFile(diffs.md, path.join(outputDir, 'report-diff.md')); |
| 150 | } |
| 151 | break; |
| 152 | |
| 153 | case 'print-config': |
| 154 | let content = await readFile( |
| 155 | includeUploadConfig |
| 156 | ? fixturePaths.config.portal |
| 157 | : fixturePaths.config.base, |
| 158 | 'utf8', |
| 159 | ); |
| 160 | if (nxMatch) { |
| 161 | // simulate effect of custom persist.outputDir per Nx project |
| 162 | const config = JSON.parse(content) as CoreConfig; |
| 163 | // eslint-disable-next-line functional/immutable-data |
| 164 | config.persist!.outputDir = outputDir; |
| 165 | content = JSON.stringify(config, null, 2); |
| 166 | } |
| 167 | const outputFile = args |
| 168 | ?.find(arg => arg.startsWith('--output=')) |
| 169 | ?.split('=')[1]; |
| 170 | if (outputFile) { |
| 171 | const outputPath = path.resolve(cwd as string, outputFile); |
| 172 | await mkdir(path.dirname(outputPath), { recursive: true }); |
| 173 | await writeFile(outputPath, content); |
| 174 | } else { |
| 175 | stdout = content; |
| 176 | } |
no test coverage detected