Refactor publish script so that root package.json configs.packagesWithDocs is canonical source of which packages have doc pages

This commit is contained in:
Fabio Berger 2018-08-22 23:13:59 +01:00
parent b7c119b2aa
commit 69b436babe
13 changed files with 41 additions and 57 deletions

View File

@ -34,8 +34,7 @@
"assets": [
"packages/0x.js/_bundles/index.js",
"packages/0x.js/_bundles/index.min.js"
],
"shouldPublishDocs": true
]
}
},
"repository": {

View File

@ -30,8 +30,7 @@
},
"config": {
"postpublish": {
"assets": [],
"shouldPublishDocs": true
"assets": []
}
},
"repository": {

View File

@ -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": {

View File

@ -16,8 +16,7 @@
},
"config": {
"postpublish": {
"assets": [],
"shouldPublishDocs": true
"assets": []
}
},
"license": "Apache-2.0",

View File

@ -23,8 +23,7 @@
"config": {
"postpublish": {
"assets": [],
"shouldPublishDocs": true,
"omitExports": ["schemas"]
"docOmitExports": ["schemas"]
}
},
"repository": {

View File

@ -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> {

View File

@ -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

View File

@ -27,8 +27,7 @@
"config": {
"contracts_v2_beta": "IWallet IValidator Exchange ERC20Proxy ERC20Token DummyERC20Token",
"postpublish": {
"assets": [],
"shouldPublishDocs": true
"assets": []
}
},
"license": "Apache-2.0",

View File

@ -31,8 +31,7 @@
"config": {
"contracts_v2_beta": "AssetProxyOwner ERC20Proxy ERC20Token ERC721Proxy ERC721Token Exchange Forwarder OrderValidator WETH9 ZRXToken",
"postpublish": {
"assets": [],
"shouldPublishDocs": true
"assets": []
}
},
"repository": {

View File

@ -25,8 +25,7 @@
},
"config": {
"postpublish": {
"assets": [],
"shouldPublishDocs": true
"assets": []
}
},
"bin": {

View File

@ -26,8 +26,7 @@
"config": {
"postpublish": {
"assets": [],
"shouldPublishDocs": true,
"omitExports": ["ProfilerSubprovider", "RevertTraceSubprovider"]
"docOmitExports": ["ProfilerSubprovider", "RevertTraceSubprovider"]
}
},
"repository": {

View File

@ -25,8 +25,7 @@
},
"config": {
"postpublish": {
"assets": [],
"shouldPublishDocs": true
"assets": []
}
},
"dependencies": {

View File

@ -22,8 +22,7 @@
},
"config": {
"postpublish": {
"assets": [],
"shouldPublishDocs": true
"assets": []
}
},
"license": "Apache-2.0",