|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google Inc. All Rights Reserved. |
| 4 | + * |
| 5 | + * Use of this source code is governed by an MIT-style license that can be |
| 6 | + * found in the LICENSE file at https://angular.io/license |
| 7 | + */ |
| 8 | +'use strict'; |
| 9 | + |
| 10 | +import * as fs from 'fs'; |
| 11 | +import * as glob from 'glob'; |
| 12 | +import * as path from 'path'; |
| 13 | + |
| 14 | +const packageRoot = path.join(__dirname, '../packages'); |
| 15 | +const distRoot = path.join(__dirname, '../dist'); |
| 16 | + |
| 17 | + |
| 18 | +export interface PackageInfo { |
| 19 | + name: string; |
| 20 | + root: string; |
| 21 | + bin: { [name: string]: string}; |
| 22 | + relative: string; |
| 23 | + main: string; |
| 24 | + dist: string; |
| 25 | + tsConfig?: string; |
| 26 | + packageJson: string; |
| 27 | + dependencies: string[]; |
| 28 | +} |
| 29 | +export type PackageMap = { [name: string]: PackageInfo }; |
| 30 | + |
| 31 | + |
| 32 | +const packageJsonPaths = |
| 33 | + glob.sync(path.join(packageRoot, '**/package.json')) |
| 34 | + // Removing all files from templates. |
| 35 | + .filter(p => !p.match(/\/angular.*files\//)); |
| 36 | + |
| 37 | + |
| 38 | +// All the supported packages. Go through the packages directory and create a _map of |
| 39 | +// name => fullPath. |
| 40 | +export const packages: PackageMap = |
| 41 | + packageJsonPaths |
| 42 | + .map(pkgPath => [pkgPath, path.relative(packageRoot, path.dirname(pkgPath))]) |
| 43 | + .map(([pkgPath, pkgName]) => { |
| 44 | + return { name: pkgName, root: path.dirname(pkgPath) }; |
| 45 | + }) |
| 46 | + .reduce((packages: PackageMap, pkg) => { |
| 47 | + const pkgRoot = pkg.root; |
| 48 | + let pkgJson = require(path.join(pkgRoot, 'package.json')); |
| 49 | + let name = pkgJson['name']; |
| 50 | + let bin: {[name: string]: string} = {}; |
| 51 | + Object.keys(pkgJson['bin'] || {}).forEach(binName => { |
| 52 | + bin[binName] = path.resolve(pkg.root, pkgJson['bin'][binName]); |
| 53 | + }); |
| 54 | + |
| 55 | + let tsConfig: string | undefined = path.resolve(pkgRoot, 'tsconfig.json'); |
| 56 | + if (!fs.existsSync(tsConfig)) { |
| 57 | + tsConfig = undefined; |
| 58 | + } |
| 59 | + |
| 60 | + packages[name] = { |
| 61 | + dist: path.join(distRoot, name), |
| 62 | + packageJson: path.join(pkgRoot, 'package.json'), |
| 63 | + root: pkgRoot, |
| 64 | + relative: path.relative(path.dirname(__dirname), pkgRoot), |
| 65 | + main: path.resolve(pkgRoot, 'src/index.ts'), |
| 66 | + bin, |
| 67 | + tsConfig, |
| 68 | + name, |
| 69 | + dependencies: [] |
| 70 | + }; |
| 71 | + return packages; |
| 72 | + }, {}); |
| 73 | + |
| 74 | + |
| 75 | +// Update with dependencies. |
| 76 | +for (const pkgName of Object.keys(packages)) { |
| 77 | + const pkg = packages[pkgName]; |
| 78 | + const pkgJson = require(path.join(pkg.root, 'package.json')); |
| 79 | + pkg.dependencies = Object.keys(packages).filter(name => { |
| 80 | + return name in (pkgJson.dependencies || {}) |
| 81 | + || name in (pkgJson.devDependencies || {}) |
| 82 | + || name in (pkgJson.peerDependencies || {}); |
| 83 | + }); |
| 84 | +} |
0 commit comments