aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-08-03 03:08:21 +0800
committerFabio Berger <me@fabioberger.com>2018-08-03 03:08:21 +0800
commitfaa980ffc3bde48e4aaca665c8be83ea4c44b106 (patch)
tree5ffa27a10826d7e29711ca5eea2366ee22039ac9 /packages
parent9a3b630b1989abbe1d6784f121fd0a60169e3012 (diff)
downloaddexon-sol-tools-faa980ffc3bde48e4aaca665c8be83ea4c44b106.tar
dexon-sol-tools-faa980ffc3bde48e4aaca665c8be83ea4c44b106.tar.gz
dexon-sol-tools-faa980ffc3bde48e4aaca665c8be83ea4c44b106.tar.bz2
dexon-sol-tools-faa980ffc3bde48e4aaca665c8be83ea4c44b106.tar.lz
dexon-sol-tools-faa980ffc3bde48e4aaca665c8be83ea4c44b106.tar.xz
dexon-sol-tools-faa980ffc3bde48e4aaca665c8be83ea4c44b106.tar.zst
dexon-sol-tools-faa980ffc3bde48e4aaca665c8be83ea4c44b106.zip
Add ability to omit rendering specific exports and also support direct exports from index.ts
Diffstat (limited to 'packages')
-rw-r--r--packages/json-schemas/package.json3
-rw-r--r--packages/monorepo-scripts/src/utils/publish_utils.ts52
2 files changed, 41 insertions, 14 deletions
diff --git a/packages/json-schemas/package.json b/packages/json-schemas/package.json
index 72db8c649..c421290ec 100644
--- a/packages/json-schemas/package.json
+++ b/packages/json-schemas/package.json
@@ -23,7 +23,8 @@
"config": {
"postpublish": {
"assets": [],
- "shouldPublishDocs": true
+ "shouldPublishDocs": true,
+ "omitExports": ["schemas"]
}
},
"repository": {
diff --git a/packages/monorepo-scripts/src/utils/publish_utils.ts b/packages/monorepo-scripts/src/utils/publish_utils.ts
index 974fb4d0d..2cf67946b 100644
--- a/packages/monorepo-scripts/src/utils/publish_utils.ts
+++ b/packages/monorepo-scripts/src/utils/publish_utils.ts
@@ -119,10 +119,6 @@ function getReleaseNotesForPackage(packageName: string, version: string): string
}
export async function generateAndUploadDocsAsync(packageName: string, isStaging: boolean): Promise<void> {
- const pathToPackage = `${constants.monorepoRootPath}/packages/${packageName}`;
- const indexPath = `${pathToPackage}/src/index.ts`;
- const { exportPathToExportedItems, exportPathOrder } = getExportPathToExportedItems(indexPath);
-
const monorepoPackages = utils.getPackages(constants.monorepoRootPath);
const pkg = _.find(monorepoPackages, monorepoPackage => {
return _.includes(monorepoPackage.packageJson.name, packageName);
@@ -132,6 +128,12 @@ export async function generateAndUploadDocsAsync(packageName: string, isStaging:
}
const packageJson = pkg.packageJson;
+ const omitExports = _.get(packageJson, 'config.postpublish.omitExports', []);
+
+ const pathToPackage = `${constants.monorepoRootPath}/packages/${packageName}`;
+ const indexPath = `${pathToPackage}/src/index.ts`;
+ const { exportPathToExportedItems, exportPathOrder } = getExportPathToExportedItems(indexPath, omitExports);
+
const shouldPublishDocs = !!_.get(packageJson, 'config.postpublish.shouldPublishDocs');
if (!shouldPublishDocs) {
utils.log(
@@ -308,35 +310,59 @@ function findExportPathGivenTypedocName(
return matchingExportPath;
}
-function getExportPathToExportedItems(filePath: string): ExportInfo {
+function getExportPathToExportedItems(filePath: string, omitExports?: string[]): ExportInfo {
const sourceFile = ts.createSourceFile(
'indexFile',
readFileSync(filePath).toString(),
ts.ScriptTarget.ES2017,
/*setParentNodes */ true,
);
- const exportInfo = _getExportPathToExportedItems(sourceFile);
+ const exportInfo = _getExportPathToExportedItems(sourceFile, omitExports);
return exportInfo;
}
-function _getExportPathToExportedItems(sf: ts.SourceFile): ExportInfo {
+function _getExportPathToExportedItems(sf: ts.SourceFile, omitExports?: string[]): ExportInfo {
const exportPathToExportedItems: ExportPathToExportedItems = {};
const exportPathOrder: string[] = [];
+ const exportsToOmit = _.isUndefined(omitExports) ? [] : omitExports;
+ console.log('exportsToOmit', exportsToOmit);
processNode(sf);
function processNode(node: ts.Node): void {
switch (node.kind) {
- case ts.SyntaxKind.ExportDeclaration:
+ case ts.SyntaxKind.ExportDeclaration: {
const exportClause = (node as any).exportClause;
- const pkgName = exportClause.parent.moduleSpecifier.text;
- exportPathOrder.push(pkgName);
+ const exportPath = exportClause.parent.moduleSpecifier.text;
_.each(exportClause.elements, element => {
- exportPathToExportedItems[pkgName] = _.isUndefined(exportPathToExportedItems[pkgName])
- ? [element.name.escapedText]
- : [...exportPathToExportedItems[pkgName], element.name.escapedText];
+ const exportItem = element.name.escapedText;
+ if (!_.includes(exportsToOmit, exportItem)) {
+ exportPathToExportedItems[exportPath] = _.isUndefined(exportPathToExportedItems[exportPath])
+ ? [exportItem]
+ : [...exportPathToExportedItems[exportPath], exportItem];
+ }
});
+ if (!_.isUndefined(exportPathToExportedItems[exportPath])) {
+ exportPathOrder.push(exportPath);
+ }
break;
+ }
+ case ts.SyntaxKind.ExportKeyword: {
+ const foundNode: any = node;
+ const exportPath = './index';
+ if (foundNode.parent && foundNode.parent.name) {
+ const exportItem = foundNode.parent.name.escapedText;
+ if (!_.includes(exportsToOmit, exportItem)) {
+ exportPathToExportedItems[exportPath] = _.isUndefined(exportPathToExportedItems[exportPath])
+ ? [exportItem]
+ : [...exportPathToExportedItems[exportPath], exportItem];
+ }
+ }
+ if (!_.includes(exportPathOrder, exportPath) && !_.isUndefined(exportPathToExportedItems[exportPath])) {
+ exportPathOrder.push(exportPath);
+ }
+ break;
+ }
default:
// noop
break;