diff options
author | Fabio Berger <me@fabioberger.com> | 2018-04-09 18:11:18 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-04-09 18:11:18 +0800 |
commit | b7e98abc43daa4c625e155327cf8ea5656da2451 (patch) | |
tree | 344597349acac698338c09da117c2583ad277c44 /packages/monorepo-scripts/src | |
parent | 073bf738ddb271b6b4158798baf4cac3cb0608e9 (diff) | |
download | dexon-sol-tools-b7e98abc43daa4c625e155327cf8ea5656da2451.tar dexon-sol-tools-b7e98abc43daa4c625e155327cf8ea5656da2451.tar.gz dexon-sol-tools-b7e98abc43daa4c625e155327cf8ea5656da2451.tar.bz2 dexon-sol-tools-b7e98abc43daa4c625e155327cf8ea5656da2451.tar.lz dexon-sol-tools-b7e98abc43daa4c625e155327cf8ea5656da2451.tar.xz dexon-sol-tools-b7e98abc43daa4c625e155327cf8ea5656da2451.tar.zst dexon-sol-tools-b7e98abc43daa4c625e155327cf8ea5656da2451.zip |
Refactor publish script to have it's main execution body be lean and discrete steps
Diffstat (limited to 'packages/monorepo-scripts/src')
-rw-r--r-- | packages/monorepo-scripts/src/publish.ts | 61 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/types.ts | 4 |
2 files changed, 44 insertions, 21 deletions
diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index adc1de64a..f0fb00acd 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -10,7 +10,7 @@ import semverDiff = require('semver-diff'); import semverSort = require('semver-sort'); import { constants } from './constants'; -import { Changelog, Changes, SemVerIndex, UpdatedPackage } from './types'; +import { Changelog, Changes, PackageToVersionChange, SemVerIndex, UpdatedPackage } from './types'; import { utils } from './utils'; const IS_DRY_RUN = process.env.IS_DRY_RUN === 'true'; @@ -23,6 +23,39 @@ const semverNameToIndex: { [semver: string]: number } = { }; (async () => { + // Fetch public, updated Lerna packages + const updatedPublicLernaPackages = await getUpdatedPublicLernaPackagesAsync(); + + // Update CHANGELOGs + const updatedPublicLernaPackageNames = _.map(updatedPublicLernaPackages, pkg => pkg.package.name); + utils.log(`Will update CHANGELOGs and publish: \n${updatedPublicLernaPackageNames.join('\n')}\n`); + const packageToVersionChange = await updateChangeLogsAsync(updatedPublicLernaPackages); + + // Push changelog changes to Github + if (!IS_DRY_RUN) { + await pushChangelogsToGithubAsync(); + } + + // Call LernaPublish + utils.log('Version updates to apply:'); + _.each(packageToVersionChange, (versionChange: string, packageName: string) => { + utils.log(`${packageName} -> ${versionChange}`); + }); + utils.log(`Calling 'lerna publish'...`); + await lernaPublishAsync(packageToVersionChange); +})().catch(err => { + utils.log(err); + process.exit(1); +}); + +async function pushChangelogsToGithubAsync() { + await execAsync(`git add . --all`, { cwd: constants.monorepoRootPath }); + await execAsync(`git commit -m "Updated CHANGELOGS"`, { cwd: constants.monorepoRootPath }); + await execAsync(`git push`, { cwd: constants.monorepoRootPath }); + utils.log(`Pushed CHANGELOG updates to Github`); +} + +async function getUpdatedPublicLernaPackagesAsync(): Promise<LernaPackage[]> { const updatedPublicPackages = await getPublicLernaUpdatedPackagesAsync(); const updatedPackageNames = _.map(updatedPublicPackages, pkg => pkg.name); @@ -30,10 +63,11 @@ const semverNameToIndex: { [semver: string]: number } = { const updatedPublicLernaPackages = _.filter(allLernaPackages, pkg => { return _.includes(updatedPackageNames, pkg.package.name); }); - const updatedPublicLernaPackageNames = _.map(updatedPublicLernaPackages, pkg => pkg.package.name); - utils.log(`Will update CHANGELOGs and publish: \n${updatedPublicLernaPackageNames.join('\n')}\n`); + return updatedPublicLernaPackages; +} - const packageToVersionChange: { [name: string]: string } = {}; +async function updateChangeLogsAsync(updatedPublicLernaPackages: LernaPackage[]): Promise<PackageToVersionChange> { + const packageToVersionChange: PackageToVersionChange = {}; for (const lernaPackage of updatedPublicLernaPackages) { const packageName = lernaPackage.package.name; const changelogJSONPath = path.join(lernaPackage.location, 'CHANGELOG.json'); @@ -88,23 +122,8 @@ const semverNameToIndex: { [semver: string]: number } = { utils.log(`${packageName}: Updated CHANGELOG.md`); } - if (!IS_DRY_RUN) { - await execAsync(`git add . --all`, { cwd: constants.monorepoRootPath }); - await execAsync(`git commit -m "Updated CHANGELOGS"`, { cwd: constants.monorepoRootPath }); - await execAsync(`git push`, { cwd: constants.monorepoRootPath }); - utils.log(`Pushed CHANGELOG updates to Github`); - } - - utils.log('Version updates to apply:'); - _.each(packageToVersionChange, (versionChange: string, packageName: string) => { - utils.log(`${packageName} -> ${versionChange}`); - }); - utils.log(`Calling 'lerna publish'...`); - await lernaPublishAsync(packageToVersionChange); -})().catch(err => { - utils.log(err); - process.exit(1); -}); + return packageToVersionChange; +} async function lernaPublishAsync(packageToVersionChange: { [name: string]: string }) { // HACK: Lerna publish does not provide a way to specify multiple package versions via diff --git a/packages/monorepo-scripts/src/types.ts b/packages/monorepo-scripts/src/types.ts index 9e6edd186..28d00d710 100644 --- a/packages/monorepo-scripts/src/types.ts +++ b/packages/monorepo-scripts/src/types.ts @@ -21,3 +21,7 @@ export enum SemVerIndex { Minor, Major, } + +export interface PackageToVersionChange { + [name: string]: string; +} |