aboutsummaryrefslogtreecommitdiffstats
path: root/packages/monorepo-scripts/src/utils.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-04-19 10:40:22 +0800
committerFabio Berger <me@fabioberger.com>2018-04-19 10:40:22 +0800
commit7dd3b2d38b4e4ee2f1daa24c90f503b2e7ad0422 (patch)
treea768031f546dea84718455ac2465c4edcde5096d /packages/monorepo-scripts/src/utils.ts
parent62fcb51e1a9893b8d18536eefc9497d6c1f36c39 (diff)
downloaddexon-sol-tools-7dd3b2d38b4e4ee2f1daa24c90f503b2e7ad0422.tar
dexon-sol-tools-7dd3b2d38b4e4ee2f1daa24c90f503b2e7ad0422.tar.gz
dexon-sol-tools-7dd3b2d38b4e4ee2f1daa24c90f503b2e7ad0422.tar.bz2
dexon-sol-tools-7dd3b2d38b4e4ee2f1daa24c90f503b2e7ad0422.tar.lz
dexon-sol-tools-7dd3b2d38b4e4ee2f1daa24c90f503b2e7ad0422.tar.xz
dexon-sol-tools-7dd3b2d38b4e4ee2f1daa24c90f503b2e7ad0422.tar.zst
dexon-sol-tools-7dd3b2d38b4e4ee2f1daa24c90f503b2e7ad0422.zip
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.ts45
1 files changed, 45 insertions, 0 deletions
diff --git a/packages/monorepo-scripts/src/utils.ts b/packages/monorepo-scripts/src/utils.ts
index 9aa37e272..3a16bf91d 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,44 @@ 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) {
+ let changelogJSON: string;
+ try {
+ 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([], null, 4);
+ fs.writeFileSync(changelogPath, emptyChangelogJSON);
+ return emptyChangelogJSON;
+ }
+ return changelogIfExists;
+ },
};