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 /packages/monorepo-scripts | |
parent | b7c119b2aaaa2f3579ca4aeef198eca7f38f1216 (diff) | |
download | dexon-sol-tools-69b436babee4959a0bb6b5c78e3ea26e2a2f9720.tar dexon-sol-tools-69b436babee4959a0bb6b5c78e3ea26e2a2f9720.tar.gz dexon-sol-tools-69b436babee4959a0bb6b5c78e3ea26e2a2f9720.tar.bz2 dexon-sol-tools-69b436babee4959a0bb6b5c78e3ea26e2a2f9720.tar.lz dexon-sol-tools-69b436babee4959a0bb6b5c78e3ea26e2a2f9720.tar.xz dexon-sol-tools-69b436babee4959a0bb6b5c78e3ea26e2a2f9720.tar.zst dexon-sol-tools-69b436babee4959a0bb6b5c78e3ea26e2a2f9720.zip |
Refactor publish script so that root package.json configs.packagesWithDocs is canonical source of which packages have doc pages
Diffstat (limited to 'packages/monorepo-scripts')
-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 |
2 files changed, 30 insertions, 35 deletions
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 |