From f9ad97b978ae4017adca032168ae7963c94e4157 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 15 Mar 2018 19:23:21 +0100 Subject: Add Deployer docs to website --- packages/contracts/package.json | 1 + packages/deployer/package.json | 15 ++- .../deployer/src/monorepo_scripts/stagedocs.ts | 8 ++ packages/website/md/docs/deployer/installation.md | 18 ++++ packages/website/md/docs/deployer/introduction.md | 17 ++++ packages/website/md/docs/deployer/usage.md | 52 +++++++++++ packages/website/translations/chinese.json | 1 + packages/website/translations/english.json | 1 + packages/website/translations/korean.json | 1 + packages/website/translations/russian.json | 1 + packages/website/translations/spanish.json | 1 + packages/website/ts/components/sidebar_header.tsx | 1 + packages/website/ts/components/top_bar/top_bar.tsx | 19 ++++ .../ts/containers/deployer_documentation.ts | 103 +++++++++++++++++++++ packages/website/ts/index.tsx | 4 + .../website/ts/pages/documentation/doc_page.tsx | 2 + packages/website/ts/types.ts | 3 + 17 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 packages/deployer/src/monorepo_scripts/stagedocs.ts create mode 100644 packages/website/md/docs/deployer/installation.md create mode 100644 packages/website/md/docs/deployer/introduction.md create mode 100644 packages/website/md/docs/deployer/usage.md create mode 100644 packages/website/ts/containers/deployer_documentation.ts (limited to 'packages') diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 05d305942..b16ec3fd0 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -59,6 +59,7 @@ "ethers-typescript-typings": "^0.0.2", "mocha": "^4.0.1", "npm-run-all": "^4.1.2", + "prettier": "^1.11.1", "shx": "^0.2.2", "solc": "^0.4.18", "tslint": "5.8.0", diff --git a/packages/deployer/package.json b/packages/deployer/package.json index 4bc739841..d99f6a44a 100644 --- a/packages/deployer/package.json +++ b/packages/deployer/package.json @@ -12,7 +12,19 @@ "clean": "shx rm -rf lib scripts", "migrate": "npm run build; node lib/src/cli.js migrate", "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'", - "test:circleci": "yarn test" + "test:circleci": "yarn test", + "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_FILES", + "upload_docs_json": "aws s3 cp generated_docs/index.json $S3_URL --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type application/json" + }, + "config": { + "postpublish": { + "assets": [], + "docPublishConfigs": { + "extraFileIncludes": ["../types/src/index.ts"], + "s3BucketPath": "s3://depoyer-docs-jsons/", + "s3StagingBucketPath": "s3://staging-depoyer-docs-jsons/" + } + } }, "bin": { "0x-deployer": "lib/src/cli.js" @@ -38,6 +50,7 @@ "shx": "^0.2.2", "tslint": "5.8.0", "types-bn": "^0.0.1", + "typedoc": "0xProject/typedoc", "typescript": "2.7.1", "web3-typescript-typings": "^0.10.0" }, diff --git a/packages/deployer/src/monorepo_scripts/stagedocs.ts b/packages/deployer/src/monorepo_scripts/stagedocs.ts new file mode 100644 index 000000000..e732ac8eb --- /dev/null +++ b/packages/deployer/src/monorepo_scripts/stagedocs.ts @@ -0,0 +1,8 @@ +import { postpublishUtils } from '@0xproject/monorepo-scripts'; + +import * as packageJSON from '../package.json'; +import * as tsConfigJSON from '../tsconfig.json'; + +const cwd = `${__dirname}/..`; +// tslint:disable-next-line:no-floating-promises +postpublishUtils.publishDocsToStagingAsync(packageJSON, tsConfigJSON, cwd); diff --git a/packages/website/md/docs/deployer/installation.md b/packages/website/md/docs/deployer/installation.md new file mode 100644 index 000000000..9f3838054 --- /dev/null +++ b/packages/website/md/docs/deployer/installation.md @@ -0,0 +1,18 @@ +**Install** + +```bash +npm install @0xproject/deployer --save +``` + +**Import** + +```javascript +import { Deployer, Compiler } from '@0xproject/deployer'; +``` + +or + +```javascript +var Deployer = require('@0xproject/deployer').Deployer; +var Compiler = require('@0xproject/deployer').Compiler; +``` diff --git a/packages/website/md/docs/deployer/introduction.md b/packages/website/md/docs/deployer/introduction.md new file mode 100644 index 000000000..ba9d3735a --- /dev/null +++ b/packages/website/md/docs/deployer/introduction.md @@ -0,0 +1,17 @@ +Welcome to the [Deployer](https://github.com/0xProject/0x-monorepo/tree/development/packages/deployer) documentation! Deployer is a tool for compiling and deploying Solidity smart contracts with ease. + +It serves a similar purpose to the [Truffle framework](http://truffleframework.com/), but for intermediate to advanced Solidity developers that require greater configurability and reliability. + +Deployer has the following advantages over Truffle: + +* Deploy each smart contract with a specific version of Solidity +* Improved artifact files: + * Properly segregated artifacts to support storing different versions of smart contract deployed on different networks. + * Storage of contructor args and contract source code +* An easy to maintain codebase: TypeScript + Single package +* Allows you to specify the deployer address +* Migrations that work with `async/await` +* Migrations that can be written synchronously in order to guarentee deterministic contract addresses +* No race conditions when running migrations. + +Deployer can be used as a command-line tool or as an imported module. diff --git a/packages/website/md/docs/deployer/usage.md b/packages/website/md/docs/deployer/usage.md new file mode 100644 index 000000000..027389eac --- /dev/null +++ b/packages/website/md/docs/deployer/usage.md @@ -0,0 +1,52 @@ +### CLI Usage + +```bash +node ./node_modules/@0xproject/deployer/lib/cli.js --help +cli.js [command] + +Commands: + cli.js compile compile contracts + cli.js deploy deploy a single contract with provided arguments + +Options: + --version Show version number [boolean] + --contracts-dir path of contracts directory to compile + [string] [default: "/Users/leonidlogvinov/Dev/0x/contracts"] + --network-id mainnet=1, kovan=42, testrpc=50 [number] [default: 50] + --should-optimize enable optimizer [boolean] [default: false] + --artifacts-dir path to write contracts artifacts to + [string] [default: "/Users/leonidlogvinov/Dev/0x/build/artifacts/"] + --jsonrpc-port port connected to JSON RPC [number] [default: 8545] + --gas-price gasPrice to be used for transactions + [string] [default: "2000000000"] + --account account to use for deploying contracts [string] + --help Show help [boolean] +``` + +### API Usage + +#### Migrations + +You might want to write a migration scripts (similar to `truffle migrate`), that deploys multiple contracts and configures them. Below you'll find a simple example of such a script to help you get started. + +```typescript +import { Deployer } from '@0xproject/deployer'; +import * as path from 'path'; + +const deployerOpts = { + artifactsDir: path.resolve('src', 'artifacts'), + jsonrpcUrl: 'http://localhost:8545', + networkId: 50, + defaults: { + gas: 1000000, + }, +}; + +const deployer = new Deployer(deployerOpts); + +(async () => { + const etherToken = await deployer.deployAndSaveAsync('WETH9'); +})().catch(console.log); +``` + +A more sophisticated example can be found [here](https://github.com/0xProject/0x-monorepo/tree/development/packages/contracts/migrations) diff --git a/packages/website/translations/chinese.json b/packages/website/translations/chinese.json index 9485de68c..f230754ec 100644 --- a/packages/website/translations/chinese.json +++ b/packages/website/translations/chinese.json @@ -56,6 +56,7 @@ "ABOUT": "关于我们", "CAREERS": "人才招聘", "CONTACT": "联系方式", + "DEPLOYER": "Deployer", "BLOG": "博客", "FORUM": "论坛", "CONNECT": "0x 连接", diff --git a/packages/website/translations/english.json b/packages/website/translations/english.json index 2fbd17623..13d2c1842 100644 --- a/packages/website/translations/english.json +++ b/packages/website/translations/english.json @@ -57,6 +57,7 @@ "ABOUT": "about", "CAREERS": "careers", "CONTACT": "contact", + "DEPLOYER": "Deployer", "BLOG": "blog", "FORUM": "forum", "CONNECT": "0x Connect", diff --git a/packages/website/translations/korean.json b/packages/website/translations/korean.json index d63b200d7..2d32e5c81 100644 --- a/packages/website/translations/korean.json +++ b/packages/website/translations/korean.json @@ -56,6 +56,7 @@ "ABOUT": "기업 정보", "CAREERS": "채용", "CONTACT": "문의", + "DEPLOYER": "Deployer", "BLOG": "블로그", "FORUM": "포럼", "CONNECT": "0x Connect", diff --git a/packages/website/translations/russian.json b/packages/website/translations/russian.json index e660a43fc..9991bb4bc 100644 --- a/packages/website/translations/russian.json +++ b/packages/website/translations/russian.json @@ -56,6 +56,7 @@ "ABOUT": "Kоманда", "CAREERS": "Карьера", "CONTACT": "Связаться с нами", + "DEPLOYER": "Deployer", "BLOG": "Блог", "FORUM": "Форум", "CONNECT": "0x Connect", diff --git a/packages/website/translations/spanish.json b/packages/website/translations/spanish.json index 40f321e30..121115260 100644 --- a/packages/website/translations/spanish.json +++ b/packages/website/translations/spanish.json @@ -57,6 +57,7 @@ "ABOUT": "equipo", "CAREERS": "empleo", "CONTACT": "contacto", + "DEPLOYER": "Deployer", "BLOG": "blog", "FORUM": "foro", "CONNECT": "0x Connect", diff --git a/packages/website/ts/components/sidebar_header.tsx b/packages/website/ts/components/sidebar_header.tsx index 24bd30207..33c5ac857 100644 --- a/packages/website/ts/components/sidebar_header.tsx +++ b/packages/website/ts/components/sidebar_header.tsx @@ -7,6 +7,7 @@ const SHOW_DURATION_MS = 4000; const titleToIcon: { [title: string]: string } = { '0x.js': 'zeroExJs.png', Web3Wrapper: 'zeroExJs.png', + Deployer: 'zeroExJs.png', '0x Connect': 'connect.png', '0x Smart Contracts': 'contracts.png', Wiki: 'wiki.png', diff --git a/packages/website/ts/components/top_bar/top_bar.tsx b/packages/website/ts/components/top_bar/top_bar.tsx index ec8a69a9b..9cde5bf3f 100644 --- a/packages/website/ts/components/top_bar/top_bar.tsx +++ b/packages/website/ts/components/top_bar/top_bar.tsx @@ -145,6 +145,12 @@ export class TopBar extends React.Component { primaryText={this.props.translate.get(Key.Web3Wrapper, Deco.CapWords)} /> , + + + , ]; const bottomBorderStyle = this._shouldDisplayBottomBar() ? styles.bottomBar : {}; const fullWidthClasses = isFullWidthPage ? 'pr4' : ''; @@ -291,6 +297,14 @@ export class TopBar extends React.Component { )} + {!this._isViewingDeployerDocs() && ( + + + {this.props.translate.get(Key.Deployer, Deco.Cap)}{' '} + {this.props.translate.get(Key.Docs, Deco.Cap)} + + + )} {!this._isViewingPortal() && ( @@ -321,6 +335,7 @@ export class TopBar extends React.Component { (!this._isViewing0xjsDocs() && !this._isViewingSmartContractsDocs() && !this._isViewingWeb3WrapperDocs() && + !this._isViewingDeployerDocs() && !this._isViewingConnectDocs()) || _.isUndefined(this.props.menu) ) { @@ -412,6 +427,9 @@ export class TopBar extends React.Component { private _isViewingWeb3WrapperDocs() { return _.includes(this.props.location.pathname, WebsitePaths.Web3Wrapper); } + private _isViewingDeployerDocs() { + return _.includes(this.props.location.pathname, WebsitePaths.Deployer); + } private _isViewingWiki() { return _.includes(this.props.location.pathname, WebsitePaths.Wiki); } @@ -422,6 +440,7 @@ export class TopBar extends React.Component { this._isViewingFAQ() || this._isViewingSmartContractsDocs() || this._isViewingWeb3WrapperDocs() || + this._isViewingDeployerDocs() || this._isViewingConnectDocs() ); } diff --git a/packages/website/ts/containers/deployer_documentation.ts b/packages/website/ts/containers/deployer_documentation.ts new file mode 100644 index 000000000..13187f9eb --- /dev/null +++ b/packages/website/ts/containers/deployer_documentation.ts @@ -0,0 +1,103 @@ +import { constants as docConstants, DocsInfo, DocsInfoConfig, SupportedDocJson } from '@0xproject/react-docs'; +import * as _ from 'lodash'; +import * as React from 'react'; +import { connect } from 'react-redux'; +import { Dispatch } from 'redux'; +import { DocPage as DocPageComponent, DocPageProps } from 'ts/pages/documentation/doc_page'; +import { Dispatcher } from 'ts/redux/dispatcher'; +import { State } from 'ts/redux/reducer'; +import { DocPackages, Environments, WebsitePaths } from 'ts/types'; +import { configs } from 'ts/utils/configs'; +import { constants } from 'ts/utils/constants'; +import { Translate } from 'ts/utils/translate'; + +/* tslint:disable:no-var-requires */ +const IntroMarkdown = require('md/docs/deployer/introduction'); +const InstallationMarkdown = require('md/docs/deployer/installation'); +const UsageMarkdown = require('md/docs/deployer/usage'); +/* tslint:enable:no-var-requires */ + +const docSections = { + introduction: 'introduction', + installation: 'installation', + usage: 'usage', + compiler: 'compiler', + deployer: 'deployer', + types: docConstants.TYPES_SECTION_NAME, +}; + +const docsInfoConfig: DocsInfoConfig = { + id: DocPackages.Deployer, + type: SupportedDocJson.TypeDoc, + displayName: 'Deployer', + packageUrl: 'https://github.com/0xProject/0x-monorepo', + menu: { + introduction: [docSections.introduction], + install: [docSections.installation], + usage: [docSections.usage], + compiler: [docSections.compiler], + deployer: [docSections.deployer], + types: [docSections.types], + }, + sectionNameToMarkdown: { + [docSections.introduction]: IntroMarkdown, + [docSections.installation]: InstallationMarkdown, + [docSections.usage]: UsageMarkdown, + }, + sectionNameToModulePath: { + [docSections.compiler]: ['"deployer/src/compiler"'], + [docSections.deployer]: ['"deployer/src/deployer"'], + [docSections.types]: ['"deployer/src/utils/types"', '"types/src/index"'], + }, + menuSubsectionToVersionWhenIntroduced: {}, + sections: docSections, + visibleConstructors: [docSections.compiler, docSections.deployer], + typeConfigs: { + // Note: This needs to be kept in sync with the types exported in index.ts. Unfortunately there is + // currently no way to extract the re-exported types from index.ts via TypeDoc :( + publicTypes: [ + 'CompilerOptions', + 'DeployerOptions', + 'BaseDeployerOptions', + 'UrlDeployerOptions', + 'ProviderDeployerOptions', + 'TxData', + ], + typeNameToExternalLink: { + Web3: 'https://github.com/ethereum/wiki/wiki/JavaScript-API', + BigNumber: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L127', + ContractInstance: + 'https://github.com/0xProject/0x-monorepo/blob/development/packages/web3-typescript-typings/index.d.ts#L101', + }, + typeNameToPrefix: { + ContractInstance: 'Web3', + }, + }, +}; +const docsInfo = new DocsInfo(docsInfoConfig); + +interface ConnectedState { + docsVersion: string; + availableDocVersions: string[]; + docsInfo: DocsInfo; + translate: Translate; +} + +interface ConnectedDispatch { + dispatcher: Dispatcher; +} + +const mapStateToProps = (state: State, ownProps: DocPageProps): ConnectedState => ({ + docsVersion: state.docsVersion, + availableDocVersions: state.availableDocVersions, + translate: state.translate, + docsInfo, +}); + +const mapDispatchToProps = (dispatch: Dispatch): ConnectedDispatch => ({ + dispatcher: new Dispatcher(dispatch), +}); + +export const Documentation: React.ComponentClass = connect(mapStateToProps, mapDispatchToProps)( + DocPageComponent, +); diff --git a/packages/website/ts/index.tsx b/packages/website/ts/index.tsx index 7f037934b..cc09f2df3 100644 --- a/packages/website/ts/index.tsx +++ b/packages/website/ts/index.tsx @@ -48,6 +48,9 @@ const LazyConnectDocumentation = createLazyComponent('Documentation', async () = const LazyWeb3WrapperDocumentation = createLazyComponent('Documentation', async () => System.import(/* webpackChunkName: "connectDocs" */ 'ts/containers/web3_wrapper_documentation'), ); +const LazyDeployerDocumentation = createLazyComponent('Documentation', async () => + System.import(/* webpackChunkName: "connectDocs" */ 'ts/containers/deployer_documentation'), +); analytics.init(); // tslint:disable-next-line:no-floating-promises @@ -68,6 +71,7 @@ render( +