From 7dd3b2d38b4e4ee2f1daa24c90f503b2e7ad0422 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 19 Apr 2018 11:40:22 +0900 Subject: Add removeGitTags script that can be run after a failed Lerna publish --- packages/monorepo-scripts/src/utils.ts | 45 ++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'packages/monorepo-scripts/src/utils.ts') 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 { + 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 { + 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; + }, }; -- cgit v1.2.3 From b6fb8dbb528a28cfc3d9395262fa39e3eecca2d5 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 20 Apr 2018 10:03:53 +0900 Subject: Remove outside declaration --- packages/monorepo-scripts/src/utils.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'packages/monorepo-scripts/src/utils.ts') diff --git a/packages/monorepo-scripts/src/utils.ts b/packages/monorepo-scripts/src/utils.ts index 3a16bf91d..b1bb78ab2 100644 --- a/packages/monorepo-scripts/src/utils.ts +++ b/packages/monorepo-scripts/src/utils.ts @@ -44,9 +44,8 @@ export const utils = { return updatedPackages; }, getChangelogJSONIfExists(changelogPath: string) { - let changelogJSON: string; try { - changelogJSON = fs.readFileSync(changelogPath, 'utf-8'); + const changelogJSON = fs.readFileSync(changelogPath, 'utf-8'); return changelogJSON; } catch (err) { return undefined; -- cgit v1.2.3 From 1f82c7eadfe9e9cddb56b40562a2f0f69cc7dfd9 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 20 Apr 2018 10:04:22 +0900 Subject: Remove unnecessary additional params --- packages/monorepo-scripts/src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/monorepo-scripts/src/utils.ts') diff --git a/packages/monorepo-scripts/src/utils.ts b/packages/monorepo-scripts/src/utils.ts index b1bb78ab2..4412f753a 100644 --- a/packages/monorepo-scripts/src/utils.ts +++ b/packages/monorepo-scripts/src/utils.ts @@ -55,7 +55,7 @@ export const utils = { const changelogIfExists = this.getChangelogJSONIfExists(changelogPath); if (_.isUndefined(changelogIfExists)) { // If none exists, create new, empty one. - const emptyChangelogJSON = JSON.stringify([], null, 4); + const emptyChangelogJSON = JSON.stringify([]); fs.writeFileSync(changelogPath, emptyChangelogJSON); return emptyChangelogJSON; } -- cgit v1.2.3