forked from angular/components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-entry-point-setup.js
59 lines (51 loc) · 1.94 KB
/
check-entry-point-setup.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env node
/**
* Script that detects and validates entry-points. The script walks through all
* source files in the code base and ensures that determined entry-points are
* configured. The list of configured entry-points in Starlark is passed to the
* script through a manifest file (generated by Bazel)
*/
const {join, dirname} = require('path');
const {sync: globSync} = require('glob');
const minimatch = require('minimatch');
const fs = require('fs');
const chalk = require('chalk');
const [entryPointManifest] = process.argv.slice(2);
const entryPoints = JSON.parse(fs.readFileSync(entryPointManifest, 'utf8'));
const packagesDir = join(__dirname, '../src');
/**
* Globs that matches directories which should never be considered
* as entry-points.
*/
const excludeGlobs = [
'cdk/testing/private',
'*/schematics/**',
// The protractor testing entry-point is no longer publicly available,
// but exists in the repository until it can be removed in g3.
'cdk/testing/protractor',
];
/** List of detected entry-points which are not properly configured. */
const nonConfigured = [];
// We require a minimum depth of two. This ensures that we only check entry-points and
// do not check package names (like "cdk"). There is no validation for package names yet.
globSync('*/*/**/public-api.ts', {cwd: packagesDir}).forEach(filePath => {
const entryPointName = dirname(filePath);
if (
!excludeGlobs.some(pattern => minimatch(entryPointName, pattern)) &&
!entryPoints.includes(entryPointName)
) {
nonConfigured.push(entryPointName);
}
});
if (nonConfigured.length) {
console.error(
chalk.red(
'Found entry-points which are not configured. Add the following ' +
'entry-points to the package-specific "config.bzl" file:\n',
),
);
nonConfigured.forEach(e => console.warn(chalk.yellow(` - ${e}`)));
process.exit(1);
} else {
console.log(chalk.green('All detected entry-points are configured properly.'));
}