forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpackages.js
40 lines (32 loc) · 1.26 KB
/
packages.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
'use strict';
const fs = require('fs');
const glob = require('glob');
const path = require('path');
const packageRoot = path.join(__dirname, '../packages');
// All the supported packages. Go through the packages directory and create a map of
// name => fullPath.
const packages =
glob.sync(path.join(packageRoot, '**/package.json'))
.filter(p => !p.match(/blueprints/))
.map(pkgPath => path.relative(packageRoot, path.dirname(pkgPath)))
.map(pkgName => {
return { name: pkgName, root: path.join(packageRoot, pkgName) };
})
.reduce((packages, pkg) => {
let pkgJson = JSON.parse(fs.readFileSync(path.join(pkg.root, 'package.json'), 'utf8'));
let name = pkgJson['name'];
packages[name] = {
dist: path.join(__dirname, '../dist', pkg.name),
packageJson: path.join(pkg.root, 'package.json'),
root: pkg.root,
relative: path.relative(path.dirname(__dirname), pkg.root),
main: path.resolve(pkg.root, 'src/index.ts')
};
return packages;
}, {});
module.exports = packages;
// If we run this from the command line, just output the list of modules neatly formatted.
if (require.main === module) {
// eslint-disable-next-line no-console
console.log(JSON.stringify(packages, null, 2));
}