diff options
Diffstat (limited to 'packages/monorepo-scripts/src/utils/utils.ts')
-rw-r--r-- | packages/monorepo-scripts/src/utils/utils.ts | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/packages/monorepo-scripts/src/utils/utils.ts b/packages/monorepo-scripts/src/utils/utils.ts index 8ba59c81d..d9bae3ea9 100644 --- a/packages/monorepo-scripts/src/utils/utils.ts +++ b/packages/monorepo-scripts/src/utils/utils.ts @@ -1,10 +1,11 @@ +import batchPackages = require('@lerna/batch-packages'); import * as fs from 'fs'; import * as _ from 'lodash'; import { exec as execAsync } from 'promisify-child-process'; import semver = require('semver'); import { constants } from '../constants'; -import { GitTagsByPackageName, Package, UpdatedPackage } from '../types'; +import { GitTagsByPackageName, Package, PackageJSON, UpdatedPackage } from '../types'; import { changelogUtils } from './changelog_utils'; @@ -12,6 +13,15 @@ export const utils = { log(...args: any[]): void { console.log(...args); // tslint:disable-line:no-console }, + getTopologicallySortedPackages(rootDir: string): Package[] { + const packages = utils.getPackages(rootDir); + const batchedPackages: PackageJSON[] = _.flatten(batchPackages(_.map(packages, pkg => pkg.packageJson), false)); + const topsortedPackages: Package[] = _.map( + batchedPackages, + (pkg: PackageJSON) => _.find(packages, pkg1 => pkg1.packageJson.name === pkg.name) as Package, + ); + return topsortedPackages; + }, getPackages(rootDir: string): Package[] { const rootPackageJsonString = fs.readFileSync(`${rootDir}/package.json`, 'utf8'); const rootPackageJson = JSON.parse(rootPackageJsonString); |