forked from angular/components
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapprove-api-golden.js
37 lines (30 loc) · 1.16 KB
/
approve-api-golden.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env node
const shelljs = require('shelljs');
const chalk = require('chalk');
const path = require('path');
const {guessPackageName} = require('./util');
const projectDir = path.join(__dirname, '../');
const bazel = process.env['BAZEL'] || 'pnpm -s bazel';
if (process.argv.length < 3) {
console.error(chalk.red('No package name has been passed in for API golden approval.'));
process.exit(1);
}
// ShellJS should exit if any command fails.
shelljs.set('-e');
shelljs.cd(projectDir);
for (const searchPackageName of process.argv.slice(2)) {
const packageNameGuess = guessPackageName(searchPackageName, path.join(projectDir, 'src'));
if (!packageNameGuess.result) {
console.error(
chalk.red(
`Could not find package for API golden approval called ` +
`${chalk.yellow(searchPackageName)}. Looked in packages:\n` +
`${packageNameGuess.attempts.join('\n')}`,
),
);
process.exit(1);
}
const [packageName, ..._entryPointTail] = packageNameGuess.result.split('/');
const apiGoldenTargetName = `//goldens:${packageName}_api.accept`.replace(/-/g, '_');
shelljs.exec(`${bazel} run ${apiGoldenTargetName}`);
}