diff options
author | Fabio Berger <me@fabioberger.com> | 2018-08-23 06:13:59 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-08-23 06:13:59 +0800 |
commit | 69b436babee4959a0bb6b5c78e3ea26e2a2f9720 (patch) | |
tree | f28e2db2b81654117efe300194544d8d5d5620c1 | |
parent | b7c119b2aaaa2f3579ca4aeef198eca7f38f1216 (diff) | |
download | dexon-0x-contracts-69b436babee4959a0bb6b5c78e3ea26e2a2f9720.tar.gz dexon-0x-contracts-69b436babee4959a0bb6b5c78e3ea26e2a2f9720.tar.zst dexon-0x-contracts-69b436babee4959a0bb6b5c78e3ea26e2a2f9720.zip |
Refactor publish script so that root package.json configs.packagesWithDocs is canonical source of which packages have doc pages
-rw-r--r-- | packages/0x.js/package.json | 3 | ||||
-rw-r--r-- | packages/connect/package.json | 3 | ||||
-rw-r--r-- | packages/contract-wrappers/package.json | 3 | ||||
-rw-r--r-- | packages/ethereum-types/package.json | 3 | ||||
-rw-r--r-- | packages/json-schemas/package.json | 3 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/publish.ts | 53 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/utils/doc_generate_and_upload_utils.ts | 12 | ||||
-rw-r--r-- | packages/order-utils/package.json | 3 | ||||
-rw-r--r-- | packages/order-watcher/package.json | 3 | ||||
-rw-r--r-- | packages/sol-compiler/package.json | 3 | ||||
-rw-r--r-- | packages/sol-cov/package.json | 3 | ||||
-rw-r--r-- | packages/subproviders/package.json | 3 | ||||
-rw-r--r-- | packages/web3-wrapper/package.json | 3 |
13 files changed, 41 insertions, 57 deletions
diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 5911125ed..af1e47cd8 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -34,8 +34,7 @@ "assets": [ "packages/0x.js/_bundles/index.js", "packages/0x.js/_bundles/index.min.js" - ], - "shouldPublishDocs": true + ] } }, "repository": { diff --git a/packages/connect/package.json b/packages/connect/package.json index e627f3aee..5de8dae13 100644 --- a/packages/connect/package.json +++ b/packages/connect/package.json @@ -30,8 +30,7 @@ }, "config": { "postpublish": { - "assets": [], - "shouldPublishDocs": true + "assets": [] } }, "repository": { diff --git a/packages/contract-wrappers/package.json b/packages/contract-wrappers/package.json index c06ef9650..f8477e878 100644 --- a/packages/contract-wrappers/package.json +++ b/packages/contract-wrappers/package.json @@ -32,8 +32,7 @@ "contracts_v2_beta": "AssetProxyOwner Exchange ERC20Proxy ERC20Token ERC721Proxy ERC721Token WETH9 ZRXToken Forwarder OrderValidator", "contracts_v2": "DummyERC20Token DummyERC721Token", "postpublish": { - "assets": [], - "shouldPublishDocs": true + "assets": [] } }, "repository": { diff --git a/packages/ethereum-types/package.json b/packages/ethereum-types/package.json index 8ced7c1b6..73325da4b 100644 --- a/packages/ethereum-types/package.json +++ b/packages/ethereum-types/package.json @@ -16,8 +16,7 @@ }, "config": { "postpublish": { - "assets": [], - "shouldPublishDocs": true + "assets": [] } }, "license": "Apache-2.0", diff --git a/packages/json-schemas/package.json b/packages/json-schemas/package.json index 5ee46d371..3434c9eb1 100644 --- a/packages/json-schemas/package.json +++ b/packages/json-schemas/package.json @@ -23,8 +23,7 @@ "config": { "postpublish": { "assets": [], - "shouldPublishDocs": true, - "omitExports": ["schemas"] + "docOmitExports": ["schemas"] } }, "repository": { diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 7e91b9281..3b5070395 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -1,6 +1,7 @@ #!/usr/bin/env node import * as promisify from 'es6-promisify'; +import * as fs from 'fs'; import * as _ from 'lodash'; import * as moment from 'moment'; import opn = require('opn'); @@ -35,12 +36,13 @@ async function confirmAsync(message: string): Promise<void> { // Fetch public, updated Lerna packages const shouldIncludePrivate = true; const allUpdatedPackages = await utils.getUpdatedPackagesAsync(shouldIncludePrivate); + const packagesWithDocs = getPackagesWithDocs(allUpdatedPackages); if (!configs.IS_LOCAL_PUBLISH) { await confirmAsync( 'THIS IS NOT A TEST PUBLISH! You are about to publish one or more packages to npm. Are you sure you want to continue? (y/n)', ); - await confirmDocPagesRenderAsync(allUpdatedPackages); + await confirmDocPagesRenderAsync(packagesWithDocs); } // Update CHANGELOGs @@ -74,57 +76,60 @@ async function confirmAsync(message: string): Promise<void> { utils.log(`Calling 'lerna publish'...`); await lernaPublishAsync(packageToNextVersion); const isStaging = false; - await generateAndUploadDocJsonsAsync(updatedPublicPackages, isStaging); + await generateAndUploadDocJsonsAsync(packagesWithDocs, isStaging); await publishReleaseNotesAsync(updatedPublicPackages); })().catch(err => { utils.log(err); process.exit(1); }); -async function generateAndUploadDocJsonsAsync(updatedPublicPackages: Package[], isStaging: boolean): Promise<void> { - for (const pkg of updatedPublicPackages) { - const packageName = pkg.packageJson.name; - const nameWithoutPrefix = packageName.replace('@0xproject/', ''); +function getPackagesWithDocs(allUpdatedPackages: Package[]): Package[] { + const rootPackageJsonPath = `${constants.monorepoRootPath}/package.json`; + const rootPackageJson = JSON.parse(fs.readFileSync(rootPackageJsonPath).toString()); + const packagesWithDocPagesStringIfExist = _.get(rootPackageJson, 'configs.packagesWithDocPages', undefined); + if (_.isUndefined(packagesWithDocPagesStringIfExist)) { + return []; // None to generate & publish + } + const packagesWithDocPages = packagesWithDocPagesStringIfExist.split(' '); + const updatedPackagesWithDocPages: Package[] = []; + _.each(allUpdatedPackages, pkg => { + const nameWithoutPrefix = pkg.packageJson.name.replace('@0xproject/', ''); + if (_.includes(packagesWithDocPages, nameWithoutPrefix)) { + updatedPackagesWithDocPages.push(pkg); + } + }); + return updatedPackagesWithDocPages; +} + +async function generateAndUploadDocJsonsAsync(packagesWithDocs: Package[], isStaging: boolean): Promise<void> { + for (const pkg of packagesWithDocs) { + const nameWithoutPrefix = pkg.packageJson.name.replace('@0xproject/', ''); const shouldUploadDocs = true; const docGenerateAndUploadUtils = new DocGenerateAndUploadUtils(nameWithoutPrefix, isStaging, shouldUploadDocs); await docGenerateAndUploadUtils.generateAndUploadDocsAsync(); } } -async function confirmDocPagesRenderAsync(packages: Package[]): Promise<void> { +async function confirmDocPagesRenderAsync(packagesWithDocs: Package[]): Promise<void> { // push docs to staging utils.log("Upload all docJson's to S3 staging..."); const isStaging = true; - await generateAndUploadDocJsonsAsync(packages, isStaging); + await generateAndUploadDocJsonsAsync(packagesWithDocs, isStaging); // 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.packageJson.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.packageJson.name; const nameWithoutPrefix = _.startsWith(name, NPM_NAMESPACE) ? name.split('@0xproject/')[1] : name; - const docSegmentIfExists = 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}`; + const link = `${constants.stagingWebsite}/docs/${nameWithoutPrefix}`; // tslint:disable-next-line:no-floating-promises opn(link); }); - await confirmAsync('Do all the doc pages render properly? (y/n)'); + await confirmAsync('Do all the doc pages render? (y/n)'); } async function pushChangelogsToGithubAsync(): Promise<void> { diff --git a/packages/monorepo-scripts/src/utils/doc_generate_and_upload_utils.ts b/packages/monorepo-scripts/src/utils/doc_generate_and_upload_utils.ts index 1645ba0d6..5fee98b63 100644 --- a/packages/monorepo-scripts/src/utils/doc_generate_and_upload_utils.ts +++ b/packages/monorepo-scripts/src/utils/doc_generate_and_upload_utils.ts @@ -173,22 +173,12 @@ export class DocGenerateAndUploadUtils { throw new Error(`Couldn't find a package.json for ${packageName}`); } this._packageJson = pkg.packageJson; - this._omitExports = _.get(this._packageJson, 'config.postpublish.omitExports', []); + this._omitExports = _.get(this._packageJson, 'config.postpublish.docOmitExports', []); const indexPath = `${this._packagePath}/src/index.ts`; const exportInfo = DocGenerateAndUploadUtils._getExportPathToExportedItems(indexPath, this._omitExports); this._exportPathToExportedItems = exportInfo.exportPathToExportedItems; this._exportPathOrder = exportInfo.exportPathOrder; - - const shouldPublishDocs = !!_.get(this._packageJson, 'config.postpublish.shouldPublishDocs'); - if (!shouldPublishDocs) { - utils.log( - `GENERATE_UPLOAD_DOCS: ${ - this._packageJson.name - } packageJson.config.postpublish.shouldPublishDocs is false. Skipping doc JSON generation.`, - ); - return; - } } public async generateAndUploadDocsAsync(): Promise<void> { // For each dep that is another one of our monorepo packages, we fetch it's index.ts diff --git a/packages/order-utils/package.json b/packages/order-utils/package.json index dc6d8328d..dbccded86 100644 --- a/packages/order-utils/package.json +++ b/packages/order-utils/package.json @@ -27,8 +27,7 @@ "config": { "contracts_v2_beta": "IWallet IValidator Exchange ERC20Proxy ERC20Token DummyERC20Token", "postpublish": { - "assets": [], - "shouldPublishDocs": true + "assets": [] } }, "license": "Apache-2.0", diff --git a/packages/order-watcher/package.json b/packages/order-watcher/package.json index 37a1c20e4..121f3f3f4 100644 --- a/packages/order-watcher/package.json +++ b/packages/order-watcher/package.json @@ -31,8 +31,7 @@ "config": { "contracts_v2_beta": "AssetProxyOwner ERC20Proxy ERC20Token ERC721Proxy ERC721Token Exchange Forwarder OrderValidator WETH9 ZRXToken", "postpublish": { - "assets": [], - "shouldPublishDocs": true + "assets": [] } }, "repository": { diff --git a/packages/sol-compiler/package.json b/packages/sol-compiler/package.json index d5cb2509b..e13a28efa 100644 --- a/packages/sol-compiler/package.json +++ b/packages/sol-compiler/package.json @@ -25,8 +25,7 @@ }, "config": { "postpublish": { - "assets": [], - "shouldPublishDocs": true + "assets": [] } }, "bin": { diff --git a/packages/sol-cov/package.json b/packages/sol-cov/package.json index dfeee4a81..a6c383b6f 100644 --- a/packages/sol-cov/package.json +++ b/packages/sol-cov/package.json @@ -26,8 +26,7 @@ "config": { "postpublish": { "assets": [], - "shouldPublishDocs": true, - "omitExports": ["ProfilerSubprovider", "RevertTraceSubprovider"] + "docOmitExports": ["ProfilerSubprovider", "RevertTraceSubprovider"] } }, "repository": { diff --git a/packages/subproviders/package.json b/packages/subproviders/package.json index 8b8c06c25..38b99c976 100644 --- a/packages/subproviders/package.json +++ b/packages/subproviders/package.json @@ -25,8 +25,7 @@ }, "config": { "postpublish": { - "assets": [], - "shouldPublishDocs": true + "assets": [] } }, "dependencies": { diff --git a/packages/web3-wrapper/package.json b/packages/web3-wrapper/package.json index f7278004d..d584db453 100644 --- a/packages/web3-wrapper/package.json +++ b/packages/web3-wrapper/package.json @@ -22,8 +22,7 @@ }, "config": { "postpublish": { - "assets": [], - "shouldPublishDocs": true + "assets": [] } }, "license": "Apache-2.0", |