From d1e33a3dff3f62b7c84fd5b5d1307572853beeee Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 24 Jul 2018 16:07:11 +0200 Subject: Add utils.getTopologicallySortedPackages --- packages/monorepo-scripts/src/utils/utils.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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); -- cgit v1.2.3