diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-04-27 08:11:01 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-04-27 08:11:01 +0800 |
commit | dc19690863187a797f34a95ea824c2de9a9fabae (patch) | |
tree | 40593d3c331193fb8a0c7ceadf7fc8ae4e4c218f /packages/monorepo-scripts/src/utils.ts | |
parent | 9b535e3cec4073205c1343306829bcdec3168002 (diff) | |
parent | 47604384d4042c3c61f29a635491f8165236e763 (diff) | |
download | dexon-sol-tools-dc19690863187a797f34a95ea824c2de9a9fabae.tar dexon-sol-tools-dc19690863187a797f34a95ea824c2de9a9fabae.tar.gz dexon-sol-tools-dc19690863187a797f34a95ea824c2de9a9fabae.tar.bz2 dexon-sol-tools-dc19690863187a797f34a95ea824c2de9a9fabae.tar.lz dexon-sol-tools-dc19690863187a797f34a95ea824c2de9a9fabae.tar.xz dexon-sol-tools-dc19690863187a797f34a95ea824c2de9a9fabae.tar.zst dexon-sol-tools-dc19690863187a797f34a95ea824c2de9a9fabae.zip |
Merge branch 'development' into feature/website/crypto-compare-prices
* development:
Fix react type versions to avoid minor version bumps with breaking changes
Update Web3 Provider Engine to 14.0.4
Remove auto-assignment of everyone to PR's
Check for Yarn instead of npm
Add hack comment about the use of sudo
Fix lazy load component name
Rename Portal and PortalMenu components to LegacyPortal and LegacyPortalMenu
Remove unnecessary additional params
Remove outside declaration
Capitalize yarn
Use path for platform independence
Consolidate github personal access token env to one place: constants.ts
Use methods moved to utils since now shared by multiple scripts
Add comment
Improve comments
Add checks for the required local setup before running the publish script
Add descriptions for all commands in monorepo-scripts
Add removeGitTags script that can be run after a failed Lerna publish
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; + }, }; |