aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-03-16 23:56:53 +0800
committerFabio Berger <me@fabioberger.com>2018-03-16 23:56:53 +0800
commitd7bf003d511321ec6cb8814cb1549c46b4efba86 (patch)
treede5f31ad85677a910f88aec9d53a1bc45d85195c /packages
parent5a827eb3d4aefc65f808865f2634108b62406278 (diff)
downloaddexon-sol-tools-d7bf003d511321ec6cb8814cb1549c46b4efba86.tar
dexon-sol-tools-d7bf003d511321ec6cb8814cb1549c46b4efba86.tar.gz
dexon-sol-tools-d7bf003d511321ec6cb8814cb1549c46b4efba86.tar.bz2
dexon-sol-tools-d7bf003d511321ec6cb8814cb1549c46b4efba86.tar.lz
dexon-sol-tools-d7bf003d511321ec6cb8814cb1549c46b4efba86.tar.xz
dexon-sol-tools-d7bf003d511321ec6cb8814cb1549c46b4efba86.tar.zst
dexon-sol-tools-d7bf003d511321ec6cb8814cb1549c46b4efba86.zip
Refactor all docJSON's to reside within the same S3 bucket under different folders
Diffstat (limited to 'packages')
-rw-r--r--packages/0x.js/package.json4
-rw-r--r--packages/connect/package.json4
-rw-r--r--packages/deployer/package.json4
-rw-r--r--packages/web3-wrapper/package.json4
-rw-r--r--packages/website/ts/pages/documentation/doc_page.tsx28
-rw-r--r--packages/website/ts/types.ts2
-rw-r--r--packages/website/ts/utils/constants.ts3
-rw-r--r--packages/website/ts/utils/doc_utils.ts60
8 files changed, 72 insertions, 37 deletions
diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json
index 0cb01d352..4bc0cc193 100644
--- a/packages/0x.js/package.json
+++ b/packages/0x.js/package.json
@@ -36,8 +36,8 @@
"assets": ["_bundles/index.js", "_bundles/index.min.js"],
"docPublishConfigs": {
"extraFileIncludes": ["../types/src/index.ts"],
- "s3BucketPath": "s3://0xjs-docs-jsons/",
- "s3StagingBucketPath": "s3://staging-0xjs-docs-jsons/"
+ "s3BucketPath": "s3://doc-jsons/0xjs/",
+ "s3StagingBucketPath": "s3://staging-doc-jsons/0xjs/"
}
}
},
diff --git a/packages/connect/package.json b/packages/connect/package.json
index e0478b42a..b1b033621 100644
--- a/packages/connect/package.json
+++ b/packages/connect/package.json
@@ -29,8 +29,8 @@
"postpublish": {
"assets": ["_bundles/index.js", "_bundles/index.min.js"],
"docPublishConfigs": {
- "s3BucketPath": "s3://connect-docs-jsons/",
- "s3StagingBucketPath": "s3://staging-connect-docs-jsons/"
+ "s3BucketPath": "s3://doc-jsons/connect/",
+ "s3StagingBucketPath": "s3://staging-doc-jsons/connect/"
}
}
},
diff --git a/packages/deployer/package.json b/packages/deployer/package.json
index 64852e89d..346b967e2 100644
--- a/packages/deployer/package.json
+++ b/packages/deployer/package.json
@@ -23,8 +23,8 @@
"assets": [],
"docPublishConfigs": {
"extraFileIncludes": ["../types/src/index.ts"],
- "s3BucketPath": "s3://depoyer-docs-jsons/",
- "s3StagingBucketPath": "s3://staging-depoyer-docs-jsons/"
+ "s3BucketPath": "s3://doc-jsons/deployer/",
+ "s3StagingBucketPath": "s3://staging-doc-jsons/deployer/"
}
}
},
diff --git a/packages/web3-wrapper/package.json b/packages/web3-wrapper/package.json
index ae7ba8b26..9b41f1de6 100644
--- a/packages/web3-wrapper/package.json
+++ b/packages/web3-wrapper/package.json
@@ -16,8 +16,8 @@
"postpublish": {
"docPublishConfigs": {
"extraFileIncludes": ["../types/src/index.ts"],
- "s3BucketPath": "s3://web3-wrapper-docs-json/",
- "s3StagingBucketPath": "s3://staging-web3-wrapper-docs-json/"
+ "s3BucketPath": "s3://doc-jsons/web3-wrapper/",
+ "s3StagingBucketPath": "s3://staging-doc-jsons/web3-wrapper/"
}
}
},
diff --git a/packages/website/ts/pages/documentation/doc_page.tsx b/packages/website/ts/pages/documentation/doc_page.tsx
index ecae7147d..5f09ec9ef 100644
--- a/packages/website/ts/pages/documentation/doc_page.tsx
+++ b/packages/website/ts/pages/documentation/doc_page.tsx
@@ -17,13 +17,13 @@ import { utils } from 'ts/utils/utils';
const ZERO_EX_JS_VERSION_MISSING_TOPLEVEL_PATH = '0.32.4';
-const isDevelopment = configs.ENVIRONMENT === Environments.DEVELOPMENT;
-const docIdToS3BucketName: { [id: string]: string } = {
- [DocPackages.ZeroExJs]: isDevelopment ? 'staging-0xjs-docs-jsons' : '0xjs-docs-jsons',
- [DocPackages.SmartContracts]: 'smart-contracts-docs-json',
- [DocPackages.Connect]: isDevelopment ? 'staging-connect-docs-jsons' : 'connect-docs-jsons',
- [DocPackages.Web3Wrapper]: isDevelopment ? 'staging-web3-wrapper-docs-json' : 'web3-wrapper-docs-json',
- [DocPackages.Deployer]: isDevelopment ? 'staging-depoyer-docs-jsons' : 'depoyer-docs-jsons',
+const isDevelopment = configs.ENVIRONMENT !== Environments.DEVELOPMENT;
+const docIdToS3FolderName: { [id: string]: string } = {
+ [DocPackages.ZeroExJs]: '0xjs',
+ [DocPackages.SmartContracts]: 'smart-contracts',
+ [DocPackages.Connect]: 'connect',
+ [DocPackages.Web3Wrapper]: 'web3-wrapper',
+ [DocPackages.Deployer]: 'deployer',
};
const docIdToSubpackageName: { [id: string]: string } = {
@@ -101,25 +101,25 @@ export class DocPage extends React.Component<DocPageProps, DocPageState> {
);
}
private async _fetchJSONDocsFireAndForgetAsync(preferredVersionIfExists?: string): Promise<void> {
- const s3BucketName = docIdToS3BucketName[this.props.docsInfo.id];
- const docsJsonRoot = `${constants.S3_BUCKET_ROOT}/${s3BucketName}`;
- const versionToFileName = await docUtils.getVersionToFileNameAsync(docsJsonRoot);
- const versions = _.keys(versionToFileName);
+ const folderName = docIdToS3FolderName[this.props.docsInfo.id];
+ const docBucketRoot = isDevelopment ? constants.S3_STAGING_DOC_BUCKET_ROOT : constants.S3_DOC_BUCKET_ROOT;
+ const versionToFilePath = await docUtils.getVersionToFilePathAsync(docBucketRoot, folderName);
+ const versions = _.keys(versionToFilePath);
this.props.dispatcher.updateAvailableDocVersions(versions);
const sortedVersions = semverSort.desc(versions);
const latestVersion = sortedVersions[0];
let versionToFetch = latestVersion;
if (!_.isUndefined(preferredVersionIfExists)) {
- const preferredVersionFileNameIfExists = versionToFileName[preferredVersionIfExists];
+ const preferredVersionFileNameIfExists = versionToFilePath[preferredVersionIfExists];
if (!_.isUndefined(preferredVersionFileNameIfExists)) {
versionToFetch = preferredVersionIfExists;
}
}
this.props.dispatcher.updateCurrentDocsVersion(versionToFetch);
- const versionFileNameToFetch = versionToFileName[versionToFetch];
- const versionDocObj = await docUtils.getJSONDocFileAsync(versionFileNameToFetch, docsJsonRoot);
+ const versionFilePathToFetch = versionToFilePath[versionToFetch];
+ const versionDocObj = await docUtils.getJSONDocFileAsync(versionFilePathToFetch, docBucketRoot);
const docAgnosticFormat = this.props.docsInfo.convertToDocAgnosticFormat(versionDocObj);
if (!this._isUnmounted) {
diff --git a/packages/website/ts/types.ts b/packages/website/ts/types.ts
index 33a5f8229..4a3426b56 100644
--- a/packages/website/ts/types.ts
+++ b/packages/website/ts/types.ts
@@ -336,7 +336,7 @@ export enum TokenVisibility {
TRACKED = 'TRACKED',
}
-export interface VersionToFileName {
+export interface VersionToFilePath {
[version: string]: string;
}
diff --git a/packages/website/ts/utils/constants.ts b/packages/website/ts/utils/constants.ts
index f63e8617e..42a2f44d0 100644
--- a/packages/website/ts/utils/constants.ts
+++ b/packages/website/ts/utils/constants.ts
@@ -29,7 +29,8 @@ export const constants = {
PROVIDER_NAME_GENERIC: 'Injected Web3',
PROVIDER_NAME_PUBLIC: '0x Public',
ROLLBAR_ACCESS_TOKEN: 'a6619002b51c4464928201e6ea94de65',
- S3_BUCKET_ROOT: 'https://s3.amazonaws.com',
+ S3_DOC_BUCKET_ROOT: 'https://s3.amazonaws.com/doc-jsons',
+ S3_STAGING_DOC_BUCKET_ROOT: 'https://s3.amazonaws.com/staging-doc-jsons',
SUCCESS_STATUS: 200,
UNAVAILABLE_STATUS: 503,
TAKER_FEE: new BigNumber(0),
diff --git a/packages/website/ts/utils/doc_utils.ts b/packages/website/ts/utils/doc_utils.ts
index 6b3f5f378..2a599bcbe 100644
--- a/packages/website/ts/utils/doc_utils.ts
+++ b/packages/website/ts/utils/doc_utils.ts
@@ -2,21 +2,21 @@ import { DoxityDocObj, TypeDocNode } from '@0xproject/react-docs';
import { logUtils } from '@0xproject/utils';
import findVersions = require('find-versions');
import * as _ from 'lodash';
-import { S3FileObject, VersionToFileName } from 'ts/types';
+import { S3FileObject, VersionToFilePath } from 'ts/types';
import { utils } from 'ts/utils/utils';
import convert = require('xml-js');
export const docUtils = {
- async getVersionToFileNameAsync(s3DocJsonRoot: string): Promise<VersionToFileName> {
- const versionFileNames = await this.getVersionFileNamesAsync(s3DocJsonRoot);
- const versionToFileName: VersionToFileName = {};
- _.each(versionFileNames, fileName => {
- const [version] = findVersions(fileName);
- versionToFileName[version] = fileName;
+ async getVersionToFilePathAsync(s3DocJsonRoot: string, folderName: string): Promise<VersionToFilePath> {
+ const versionFilePaths = await this.getVersionFileNamesAsync(s3DocJsonRoot, folderName);
+ const versionToFilePath: VersionToFilePath = {};
+ _.each(versionFilePaths, filePath => {
+ const [version] = findVersions(filePath);
+ versionToFilePath[version] = filePath;
});
- return versionToFileName;
+ return versionToFilePath;
},
- async getVersionFileNamesAsync(s3DocJsonRoot: string): Promise<string[]> {
+ async getVersionFileNamesAsync(s3DocJsonRoot: string, folderName: string): Promise<string[]> {
const response = await fetch(s3DocJsonRoot);
if (response.status !== 200) {
// TODO: Show the user an error message when the docs fail to load
@@ -33,13 +33,47 @@ export const docUtils = {
? (responseObj.ListBucketResult.Contents as S3FileObject[])
: [responseObj.ListBucketResult.Contents];
- const versionFileNames = _.map(fileObjs, fileObj => {
+ /*
+ * S3 simply pre-fixes files in "folders" with the folder name. Thus, since we
+ * store docJSONs for multiple packages in a single S3 bucket, we must filter out
+ * the versionFileNames for a given folder here (ignoring folder entries)
+ *
+ * Example S3 response:
+ * <ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
+ * <Name>staging-doc-jsons</Name>
+ * <Prefix/>
+ * <Marker/>
+ * <MaxKeys>1000</MaxKeys>
+ * <IsTruncated>false</IsTruncated>
+ * <Contents>
+ * <Key>0xjs/</Key>
+ * <LastModified>2018-03-16T13:17:46.000Z</LastModified>
+ * <ETag>"d41d8cd98f00b204e9800998ecf8427e"</ETag>
+ * <Size>0</Size>
+ * <StorageClass>STANDARD</StorageClass>
+ * </Contents>
+ * <Contents>
+ * <Key>0xjs/v0.1.0.json</Key>
+ * <LastModified>2018-03-16T13:18:23.000Z</LastModified>
+ * <ETag>"b4f7f74913aab4a5ad1e6a58fcb3b274"</ETag>
+ * <Size>1039050</Size>
+ * <StorageClass>STANDARD</StorageClass>
+ * </Contents>
+ */
+ const relevantObjs = _.filter(fileObjs, fileObj => {
+ const key = fileObj.Key._text;
+ const isInFolderOfInterest = _.includes(key, folderName);
+ const isFileEntry = !_.endsWith(key, '/');
+ return isInFolderOfInterest && isFileEntry;
+ });
+
+ const versionFilePaths = _.map(relevantObjs, fileObj => {
return fileObj.Key._text;
});
- return versionFileNames;
+ return versionFilePaths;
},
- async getJSONDocFileAsync(fileName: string, s3DocJsonRoot: string): Promise<TypeDocNode | DoxityDocObj> {
- const endpoint = `${s3DocJsonRoot}/${fileName}`;
+ async getJSONDocFileAsync(filePath: string, s3DocJsonRoot: string): Promise<TypeDocNode | DoxityDocObj> {
+ const endpoint = `${s3DocJsonRoot}/${filePath}`;
const response = await fetch(endpoint);
if (response.status !== 200) {
// TODO: Show the user an error message when the docs fail to load