diff options
author | Fabio Berger <me@fabioberger.com> | 2018-04-24 09:34:40 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-24 09:34:40 +0800 |
commit | 04c07d9006ad1a66044e6d32009d23d552a5b099 (patch) | |
tree | 223eb7dff2b0be899870c4c11698d044db8d31ac /packages/monorepo-scripts/src/utils.ts | |
parent | d08bfbf7054d0d98680daab3d1fdc0ac878dcc16 (diff) | |
parent | a3cc5c1dd7e88aea50859560f7d751435cb577bd (diff) | |
download | dexon-0x-contracts-04c07d9006ad1a66044e6d32009d23d552a5b099.tar dexon-0x-contracts-04c07d9006ad1a66044e6d32009d23d552a5b099.tar.gz dexon-0x-contracts-04c07d9006ad1a66044e6d32009d23d552a5b099.tar.bz2 dexon-0x-contracts-04c07d9006ad1a66044e6d32009d23d552a5b099.tar.lz dexon-0x-contracts-04c07d9006ad1a66044e6d32009d23d552a5b099.tar.xz dexon-0x-contracts-04c07d9006ad1a66044e6d32009d23d552a5b099.tar.zst dexon-0x-contracts-04c07d9006ad1a66044e6d32009d23d552a5b099.zip |
Merge pull request #541 from 0xProject/improveMonorepoScripts
Improve Monorepo-scripts
Diffstat (limited to 'packages/monorepo-scripts/src/utils.ts')
-rw-r--r-- | packages/monorepo-scripts/src/utils.ts | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/packages/monorepo-scripts/src/utils.ts b/packages/monorepo-scripts/src/utils.ts index 9aa37e272..4412f753a 100644 --- a/packages/monorepo-scripts/src/utils.ts +++ b/packages/monorepo-scripts/src/utils.ts @@ -1,6 +1,11 @@ +import * as fs from 'fs'; +import lernaGetPackages = require('lerna-get-packages'); import * as _ from 'lodash'; import { exec as execAsync, spawn } from 'promisify-child-process'; +import { constants } from './constants'; +import { UpdatedPackage } from './types'; + export const utils = { log(...args: any[]): void { console.log(...args); // tslint:disable-line:no-console @@ -17,4 +22,43 @@ export const utils = { cwd, }); }, + async getUpdatedLernaPackagesAsync(shouldIncludePrivate: boolean): Promise<LernaPackage[]> { + const updatedPublicPackages = await this.getLernaUpdatedPackagesAsync(shouldIncludePrivate); + const updatedPackageNames = _.map(updatedPublicPackages, pkg => pkg.name); + + const allLernaPackages = lernaGetPackages(constants.monorepoRootPath); + const updatedPublicLernaPackages = _.filter(allLernaPackages, pkg => { + return _.includes(updatedPackageNames, pkg.package.name); + }); + return updatedPublicLernaPackages; + }, + async getLernaUpdatedPackagesAsync(shouldIncludePrivate: boolean): Promise<UpdatedPackage[]> { + const result = await execAsync(`${constants.lernaExecutable} updated --json`, { + cwd: constants.monorepoRootPath, + }); + const updatedPackages = JSON.parse(result.stdout); + if (!shouldIncludePrivate) { + const updatedPublicPackages = _.filter(updatedPackages, updatedPackage => !updatedPackage.private); + return updatedPublicPackages; + } + return updatedPackages; + }, + getChangelogJSONIfExists(changelogPath: string) { + try { + const changelogJSON = fs.readFileSync(changelogPath, 'utf-8'); + return changelogJSON; + } catch (err) { + return undefined; + } + }, + getChangelogJSONOrCreateIfMissing(changelogPath: string): string { + const changelogIfExists = this.getChangelogJSONIfExists(changelogPath); + if (_.isUndefined(changelogIfExists)) { + // If none exists, create new, empty one. + const emptyChangelogJSON = JSON.stringify([]); + fs.writeFileSync(changelogPath, emptyChangelogJSON); + return emptyChangelogJSON; + } + return changelogIfExists; + }, }; |