diff options
author | Fabio Berger <me@fabioberger.com> | 2018-04-11 18:00:30 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-04-11 18:00:30 +0800 |
commit | 29dc22e208080fa8ff0871b98b530a2deb251a73 (patch) | |
tree | db372a34e85ac8caf4a3f3ed9d7591452df9cb1a /packages/monorepo-scripts | |
parent | 6f72fed8b5b37fac5096413b363b533e0a29f7b5 (diff) | |
parent | c44f9e56ada898ffd0d0e57aa228006977fb238c (diff) | |
download | dexon-sol-tools-29dc22e208080fa8ff0871b98b530a2deb251a73.tar dexon-sol-tools-29dc22e208080fa8ff0871b98b530a2deb251a73.tar.gz dexon-sol-tools-29dc22e208080fa8ff0871b98b530a2deb251a73.tar.bz2 dexon-sol-tools-29dc22e208080fa8ff0871b98b530a2deb251a73.tar.lz dexon-sol-tools-29dc22e208080fa8ff0871b98b530a2deb251a73.tar.xz dexon-sol-tools-29dc22e208080fa8ff0871b98b530a2deb251a73.tar.zst dexon-sol-tools-29dc22e208080fa8ff0871b98b530a2deb251a73.zip |
Merge branch 'development' into removeMigrateStep
* development:
Fix lint error
Fix documentation links in some READMEs
Fix relative link
Add step to publishing that upload staging doc jsons, deploys staging website, opens every docs page and asks the dev to confirm that each one renders properly before publishing
Fix web3Wrapper build command
Add top-level `yarn lerna:stage_docs` to upload docJsons to the staging S3 bucket for all packages with a docs page
Added a detailed description of `renameOverloadedMethods` (special thanks to @fabioberger). Updated Javascript styles in the Abi-Gen and Utils packages, around support for function overloading.
Updated deployer to accept a list of contract directories as input. Contract directories are namespaced to a void clashes. Also in this commit is a fix for overloading contract functions.
Refactor publish script to have it's main execution body be lean and discrete steps
# Conflicts:
# packages/contracts/package.json
# packages/deployer/package.json
Diffstat (limited to 'packages/monorepo-scripts')
-rw-r--r-- | packages/monorepo-scripts/package.json | 3 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/constants.ts | 1 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/globals.d.ts | 6 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/publish.ts | 120 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/types.ts | 4 |
5 files changed, 113 insertions, 21 deletions
diff --git a/packages/monorepo-scripts/package.json b/packages/monorepo-scripts/package.json index b113b4b39..5c0e5a411 100644 --- a/packages/monorepo-scripts/package.json +++ b/packages/monorepo-scripts/package.json @@ -29,6 +29,7 @@ "@0xproject/tslint-config": "0.4.13", "@types/glob": "^5.0.33", "@types/node": "^8.0.53", + "@types/opn": "^5.1.0", "@types/rimraf": "^2.0.2", "depcheck": "^0.6.9", "lerna-get-packages": "^1.0.0", @@ -45,7 +46,9 @@ "glob": "^7.1.2", "lodash": "^4.17.4", "moment": "2.21.0", + "opn": "^5.3.0", "promisify-child-process": "^1.0.5", + "prompt": "^1.0.0", "publish-release": "0xproject/publish-release", "rimraf": "^2.6.2", "semver-diff": "^2.1.0", diff --git a/packages/monorepo-scripts/src/constants.ts b/packages/monorepo-scripts/src/constants.ts index 74387a159..081a49332 100644 --- a/packages/monorepo-scripts/src/constants.ts +++ b/packages/monorepo-scripts/src/constants.ts @@ -2,4 +2,5 @@ import * as path from 'path'; export const constants = { monorepoRootPath: path.join(__dirname, '../../..'), + stagingWebsite: 'http://staging-0xproject.s3-website-us-east-1.amazonaws.com', }; diff --git a/packages/monorepo-scripts/src/globals.d.ts b/packages/monorepo-scripts/src/globals.d.ts index c5898d0f5..1693a6dbb 100644 --- a/packages/monorepo-scripts/src/globals.d.ts +++ b/packages/monorepo-scripts/src/globals.d.ts @@ -3,6 +3,11 @@ declare module 'publish-release'; declare module 'es6-promisify'; declare module 'semver-diff'; +declare module 'prompt' { + const start: () => void; + const get: (promptMessages: string[], callback: (err: Error, result: string) => void) => void; +} + // semver-sort declarations declare module 'semver-sort' { const desc: (versions: string[]) => string[]; @@ -15,6 +20,7 @@ declare interface LernaPackage { version: string; name: string; main?: string; + scripts?: { [command: string]: string }; config?: { additionalTsTypings?: string[]; }; diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index adc1de64a..21c8b72c9 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -1,18 +1,23 @@ #!/usr/bin/env node +import * as promisify from 'es6-promisify'; import * as fs from 'fs'; import lernaGetPackages = require('lerna-get-packages'); import * as _ from 'lodash'; import * as moment from 'moment'; +import opn = require('opn'); import * as path from 'path'; import { exec as execAsync, spawn } from 'promisify-child-process'; +import * as prompt from 'prompt'; 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 DOC_GEN_COMMAND = 'docs:json'; +const NPM_NAMESPACE = '@0xproject/'; const IS_DRY_RUN = process.env.IS_DRY_RUN === 'true'; const TODAYS_TIMESTAMP = moment().unix(); const LERNA_EXECUTABLE = './node_modules/lerna/bin/lerna.js'; @@ -21,8 +26,95 @@ const semverNameToIndex: { [semver: string]: number } = { minor: SemVerIndex.Minor, major: SemVerIndex.Major, }; +const packageNameToWebsitePath: { [name: string]: string } = { + '0x.js': '0xjs', + 'web3-wrapper': 'web3_wrapper', + contracts: 'contracts', + connect: 'connect', + 'json-schemas': 'json-schemas', + deployer: 'deployer', + 'sol-cov': 'sol-cov', + subproviders: 'subproviders', +}; (async () => { + // Fetch public, updated Lerna packages + const updatedPublicLernaPackages = await getUpdatedPublicLernaPackagesAsync(); + + await confirmDocPagesRenderAsync(updatedPublicLernaPackages); + + // 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 confirmDocPagesRenderAsync(packages: LernaPackage[]) { + // push docs to staging + utils.log("Upload all docJson's to S3 staging..."); + await execAsync(`yarn lerna:stage_docs`, { cwd: constants.monorepoRootPath }); + + // deploy website to staging + utils.log('Deploy website to staging...'); + const pathToWebsite = `${constants.monorepoRootPath}/packages/website`; + await execAsync(`yarn deploy_staging`, { cwd: pathToWebsite }); + + const packagesWithDocs = _.filter(packages, pkg => { + const scriptsIfExists = pkg.package.scripts; + if (_.isUndefined(scriptsIfExists)) { + throw new Error('Found a public package without any scripts in package.json'); + } + return !_.isUndefined(scriptsIfExists[DOC_GEN_COMMAND]); + }); + _.each(packagesWithDocs, pkg => { + const name = pkg.package.name; + const nameWithoutPrefix = _.startsWith(name, NPM_NAMESPACE) ? name.split('@0xproject/')[1] : name; + const docSegmentIfExists = packageNameToWebsitePath[nameWithoutPrefix]; + if (_.isUndefined(docSegmentIfExists)) { + throw new Error( + `Found package '${name}' with doc commands but no corresponding docSegment in monorepo_scripts +package.ts. Please add an entry for it and try again.`, + ); + } + const link = `${constants.stagingWebsite}/docs/${docSegmentIfExists}`; + // tslint:disable-next-line:no-floating-promises + opn(link); + }); + + prompt.start(); + const message = 'Do all the doc pages render properly? (yn)'; + const result = await promisify(prompt.get)([message]); + const didConfirm = result[message] === 'y'; + if (!didConfirm) { + utils.log('Publish process aborted.'); + process.exit(0); + } +} + +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 +122,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 +181,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; +} |