Refactor publish script so that root package.json configs.packagesWithDocs is canonical source of which packages have doc pages
This commit is contained in:
parent
b7c119b2aa
commit
69b436babe
@ -34,8 +34,7 @@
|
|||||||
"assets": [
|
"assets": [
|
||||||
"packages/0x.js/_bundles/index.js",
|
"packages/0x.js/_bundles/index.js",
|
||||||
"packages/0x.js/_bundles/index.min.js"
|
"packages/0x.js/_bundles/index.min.js"
|
||||||
],
|
]
|
||||||
"shouldPublishDocs": true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -30,8 +30,7 @@
|
|||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"postpublish": {
|
"postpublish": {
|
||||||
"assets": [],
|
"assets": []
|
||||||
"shouldPublishDocs": true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -32,8 +32,7 @@
|
|||||||
"contracts_v2_beta": "AssetProxyOwner Exchange ERC20Proxy ERC20Token ERC721Proxy ERC721Token WETH9 ZRXToken Forwarder OrderValidator",
|
"contracts_v2_beta": "AssetProxyOwner Exchange ERC20Proxy ERC20Token ERC721Proxy ERC721Token WETH9 ZRXToken Forwarder OrderValidator",
|
||||||
"contracts_v2": "DummyERC20Token DummyERC721Token",
|
"contracts_v2": "DummyERC20Token DummyERC721Token",
|
||||||
"postpublish": {
|
"postpublish": {
|
||||||
"assets": [],
|
"assets": []
|
||||||
"shouldPublishDocs": true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -16,8 +16,7 @@
|
|||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"postpublish": {
|
"postpublish": {
|
||||||
"assets": [],
|
"assets": []
|
||||||
"shouldPublishDocs": true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
|
@ -23,8 +23,7 @@
|
|||||||
"config": {
|
"config": {
|
||||||
"postpublish": {
|
"postpublish": {
|
||||||
"assets": [],
|
"assets": [],
|
||||||
"shouldPublishDocs": true,
|
"docOmitExports": ["schemas"]
|
||||||
"omitExports": ["schemas"]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
import * as promisify from 'es6-promisify';
|
import * as promisify from 'es6-promisify';
|
||||||
|
import * as fs from 'fs';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
import opn = require('opn');
|
import opn = require('opn');
|
||||||
@ -35,12 +36,13 @@ async function confirmAsync(message: string): Promise<void> {
|
|||||||
// Fetch public, updated Lerna packages
|
// Fetch public, updated Lerna packages
|
||||||
const shouldIncludePrivate = true;
|
const shouldIncludePrivate = true;
|
||||||
const allUpdatedPackages = await utils.getUpdatedPackagesAsync(shouldIncludePrivate);
|
const allUpdatedPackages = await utils.getUpdatedPackagesAsync(shouldIncludePrivate);
|
||||||
|
const packagesWithDocs = getPackagesWithDocs(allUpdatedPackages);
|
||||||
|
|
||||||
if (!configs.IS_LOCAL_PUBLISH) {
|
if (!configs.IS_LOCAL_PUBLISH) {
|
||||||
await confirmAsync(
|
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)',
|
'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
|
// Update CHANGELOGs
|
||||||
@ -74,57 +76,60 @@ async function confirmAsync(message: string): Promise<void> {
|
|||||||
utils.log(`Calling 'lerna publish'...`);
|
utils.log(`Calling 'lerna publish'...`);
|
||||||
await lernaPublishAsync(packageToNextVersion);
|
await lernaPublishAsync(packageToNextVersion);
|
||||||
const isStaging = false;
|
const isStaging = false;
|
||||||
await generateAndUploadDocJsonsAsync(updatedPublicPackages, isStaging);
|
await generateAndUploadDocJsonsAsync(packagesWithDocs, isStaging);
|
||||||
await publishReleaseNotesAsync(updatedPublicPackages);
|
await publishReleaseNotesAsync(updatedPublicPackages);
|
||||||
})().catch(err => {
|
})().catch(err => {
|
||||||
utils.log(err);
|
utils.log(err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
async function generateAndUploadDocJsonsAsync(updatedPublicPackages: Package[], isStaging: boolean): Promise<void> {
|
function getPackagesWithDocs(allUpdatedPackages: Package[]): Package[] {
|
||||||
for (const pkg of updatedPublicPackages) {
|
const rootPackageJsonPath = `${constants.monorepoRootPath}/package.json`;
|
||||||
const packageName = pkg.packageJson.name;
|
const rootPackageJson = JSON.parse(fs.readFileSync(rootPackageJsonPath).toString());
|
||||||
const nameWithoutPrefix = packageName.replace('@0xproject/', '');
|
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 shouldUploadDocs = true;
|
||||||
const docGenerateAndUploadUtils = new DocGenerateAndUploadUtils(nameWithoutPrefix, isStaging, shouldUploadDocs);
|
const docGenerateAndUploadUtils = new DocGenerateAndUploadUtils(nameWithoutPrefix, isStaging, shouldUploadDocs);
|
||||||
await docGenerateAndUploadUtils.generateAndUploadDocsAsync();
|
await docGenerateAndUploadUtils.generateAndUploadDocsAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function confirmDocPagesRenderAsync(packages: Package[]): Promise<void> {
|
async function confirmDocPagesRenderAsync(packagesWithDocs: Package[]): Promise<void> {
|
||||||
// push docs to staging
|
// push docs to staging
|
||||||
utils.log("Upload all docJson's to S3 staging...");
|
utils.log("Upload all docJson's to S3 staging...");
|
||||||
const isStaging = true;
|
const isStaging = true;
|
||||||
await generateAndUploadDocJsonsAsync(packages, isStaging);
|
await generateAndUploadDocJsonsAsync(packagesWithDocs, isStaging);
|
||||||
|
|
||||||
// deploy website to staging
|
// deploy website to staging
|
||||||
utils.log('Deploy website to staging...');
|
utils.log('Deploy website to staging...');
|
||||||
const pathToWebsite = `${constants.monorepoRootPath}/packages/website`;
|
const pathToWebsite = `${constants.monorepoRootPath}/packages/website`;
|
||||||
await execAsync(`yarn deploy_staging`, { cwd: pathToWebsite });
|
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 => {
|
_.each(packagesWithDocs, pkg => {
|
||||||
const name = pkg.packageJson.name;
|
const name = pkg.packageJson.name;
|
||||||
const nameWithoutPrefix = _.startsWith(name, NPM_NAMESPACE) ? name.split('@0xproject/')[1] : name;
|
const nameWithoutPrefix = _.startsWith(name, NPM_NAMESPACE) ? name.split('@0xproject/')[1] : name;
|
||||||
const docSegmentIfExists = nameWithoutPrefix;
|
const link = `${constants.stagingWebsite}/docs/${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
|
// tslint:disable-next-line:no-floating-promises
|
||||||
opn(link);
|
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> {
|
async function pushChangelogsToGithubAsync(): Promise<void> {
|
||||||
|
@ -173,22 +173,12 @@ export class DocGenerateAndUploadUtils {
|
|||||||
throw new Error(`Couldn't find a package.json for ${packageName}`);
|
throw new Error(`Couldn't find a package.json for ${packageName}`);
|
||||||
}
|
}
|
||||||
this._packageJson = pkg.packageJson;
|
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 indexPath = `${this._packagePath}/src/index.ts`;
|
||||||
const exportInfo = DocGenerateAndUploadUtils._getExportPathToExportedItems(indexPath, this._omitExports);
|
const exportInfo = DocGenerateAndUploadUtils._getExportPathToExportedItems(indexPath, this._omitExports);
|
||||||
this._exportPathToExportedItems = exportInfo.exportPathToExportedItems;
|
this._exportPathToExportedItems = exportInfo.exportPathToExportedItems;
|
||||||
this._exportPathOrder = exportInfo.exportPathOrder;
|
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> {
|
public async generateAndUploadDocsAsync(): Promise<void> {
|
||||||
// For each dep that is another one of our monorepo packages, we fetch it's index.ts
|
// For each dep that is another one of our monorepo packages, we fetch it's index.ts
|
||||||
|
@ -27,8 +27,7 @@
|
|||||||
"config": {
|
"config": {
|
||||||
"contracts_v2_beta": "IWallet IValidator Exchange ERC20Proxy ERC20Token DummyERC20Token",
|
"contracts_v2_beta": "IWallet IValidator Exchange ERC20Proxy ERC20Token DummyERC20Token",
|
||||||
"postpublish": {
|
"postpublish": {
|
||||||
"assets": [],
|
"assets": []
|
||||||
"shouldPublishDocs": true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
|
@ -31,8 +31,7 @@
|
|||||||
"config": {
|
"config": {
|
||||||
"contracts_v2_beta": "AssetProxyOwner ERC20Proxy ERC20Token ERC721Proxy ERC721Token Exchange Forwarder OrderValidator WETH9 ZRXToken",
|
"contracts_v2_beta": "AssetProxyOwner ERC20Proxy ERC20Token ERC721Proxy ERC721Token Exchange Forwarder OrderValidator WETH9 ZRXToken",
|
||||||
"postpublish": {
|
"postpublish": {
|
||||||
"assets": [],
|
"assets": []
|
||||||
"shouldPublishDocs": true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -25,8 +25,7 @@
|
|||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"postpublish": {
|
"postpublish": {
|
||||||
"assets": [],
|
"assets": []
|
||||||
"shouldPublishDocs": true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
|
@ -26,8 +26,7 @@
|
|||||||
"config": {
|
"config": {
|
||||||
"postpublish": {
|
"postpublish": {
|
||||||
"assets": [],
|
"assets": [],
|
||||||
"shouldPublishDocs": true,
|
"docOmitExports": ["ProfilerSubprovider", "RevertTraceSubprovider"]
|
||||||
"omitExports": ["ProfilerSubprovider", "RevertTraceSubprovider"]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -25,8 +25,7 @@
|
|||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"postpublish": {
|
"postpublish": {
|
||||||
"assets": [],
|
"assets": []
|
||||||
"shouldPublishDocs": true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -22,8 +22,7 @@
|
|||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"postpublish": {
|
"postpublish": {
|
||||||
"assets": [],
|
"assets": []
|
||||||
"shouldPublishDocs": true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user