Skip to content

Commit

Permalink
Examples cleanup (#205)
Browse files Browse the repository at this point in the history
Three main things:

- Move from webpack 5 to webpack 4 (webpack 5 is having some issues with ethers at the moment).
- Add bundler-specific demos (Parcel and Webpack with ts-loader).
- Use latest Connect APIs.
  • Loading branch information
bpierre authored Aug 14, 2020
1 parent efa70f8 commit 13c57df
Show file tree
Hide file tree
Showing 22 changed files with 472 additions and 148 deletions.
2 changes: 2 additions & 0 deletions examples/bundler-parcel/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
.cache/
20 changes: 20 additions & 0 deletions examples/bundler-parcel/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "bundler-parcel",
"private": true,
"version": "0.5.3",
"main": "index.js",
"license": "MIT",
"scripts": {
"start": "parcel src/index.html",
"build": "parcel build src/index.html"
},
"dependencies": {
"@aragon/connect-react": "^0.5.3",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"string.ify": "^1.0.64"
},
"devDependencies": {
"parcel": "^1.12.4"
}
}
11 changes: 11 additions & 0 deletions examples/bundler-parcel/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>bundler-parcel</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
</head>
<body>
Please open the console
</body>
</html>
5 changes: 5 additions & 0 deletions examples/bundler-parcel/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import connect from '@aragon/connect'

connect('a1.aragonid.eth', 'thegraph').then((org) => {
console.log('Organization:', org)
})
27 changes: 27 additions & 0 deletions examples/bundler-webpack-ts-loader/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "bundler-webpack-ts-loader",
"main": "dist/index.js",
"version": "0.5.3",
"private": true,
"sideEffects": false,
"scripts": {
"start": "yarn clean && webpack-dev-server",
"build": "yarn clean && webpack --env production",
"clean": "rm -rf ./dist ./tsconfig.tsbuildinfo"
},
"dependencies": {
"@aragon/connect": "^0.5.3",
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"devDependencies": {
"@types/react": "^16.9.35",
"@types/react-dom": "^16.9.8",
"html-webpack-plugin": "^4.3.0",
"ts-loader": "^7.0.2",
"typescript": "^3.8.3",
"webpack": "^4.44.1",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3"
}
}
11 changes: 11 additions & 0 deletions examples/bundler-webpack-ts-loader/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>bundler-webpack-ts-loader</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
</head>
<body>
Please open the console
</body>
</html>
5 changes: 5 additions & 0 deletions examples/bundler-webpack-ts-loader/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import connect from '@aragon/connect'

connect('a1.aragonid.eth', 'thegraph').then((org) => {
console.log('Organization:', org)
})
10 changes: 10 additions & 0 deletions examples/bundler-webpack-ts-loader/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "src",
"jsx": "react"
},
"include": ["src"],
"exclude": ["dist"]
}
36 changes: 36 additions & 0 deletions examples/bundler-webpack-ts-loader/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
entry: './src/index.tsx',
devtool: 'inline-source-map',
target: 'web',
mode: process.env.NODE_ENV || 'development',
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader',
options: { projectReferences: true },
},
],
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
mainFields: ['main', 'module', 'browser'],
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
},
devServer: {
contentBase: path.join(__dirname, 'dist'),
port: 1234,
},
plugins: [new HtmlWebpackPlugin({ template: './src/index.html' })],
}
6 changes: 3 additions & 3 deletions examples/list-balances-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ const RESET = '\x1b[0m'
const DECIMALS = 18

const env = {
chainId: parseInt(process.env.CHAIN_ID ?? '1', 10),
network: parseInt(process.env.CHAIN_ID ?? '1', 10),
location: process.env.ORGANIZATION ?? 'piedao.aragonid.eth',
}

async function main() {
const org = await connect(env.location, 'thegraph', { chainId: env.chainId })
const org = await connect(env.location, 'thegraph', { network: env.network })
const tokens = await connectTokens(org.app('token-manager'))
const token = await tokens.token()
const holders = await tokens.holders()

printOrganization(org)
printBalances(holders, await token.symbol)
printBalances(holders, token.symbol)
}

function printOrganization(organization: any): void {
Expand Down
2 changes: 1 addition & 1 deletion examples/list-votes-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const env = {

async function main() {
const org = await connect(env.location, 'thegraph', { network: env.network })
const voting = await connectVoting(org.app('tsateiurteiuart'))
const voting = await connectVoting(org.app('voting'))
const votes = await voting.votes()

printOrganization(org)
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal-setup-web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
</head>
<body>
<div id="app"></div>
<script src="dist/index.js"></script>
<script src="index.js"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions examples/minimal-setup-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"main": "index.js",
"license": "MIT",
"scripts": {
"start": "parcel index.js",
"build": "parcel build index.js"
"start": "parcel index.html",
"build": "parcel build index.html"
},
"dependencies": {
"@aragon/connect-react": "^0.5.3",
Expand Down
13 changes: 5 additions & 8 deletions examples/org-viewer-react/package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
{
"name": "org-viewer-react",
"main": "dist/index.js",
"version": "0.5.3",
"private": true,
"sideEffects": false,
"scripts": {
"dev": "yarn clean && webpack-dev-server",
"build": "yarn clean && NODE_ENV=production webpack",
"start": "yarn clean && webpack-dev-server",
"build": "yarn clean && webpack --production",
"build:stats": "yarn clean && webpack --env production --json > webpack-stats.json",
"clean": "rm -rf ./dist ./tsconfig.tsbuildinfo",
"compile": "tsc"
"clean": "rm -rf ./dist ./tsconfig.tsbuildinfo"
},
"dependencies": {
"@aragon/connect-react": "^0.5.3",
"@emotion/core": "^10.0.28",
"@types/react": "^16.9.35",
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"devDependencies": {
"@types/react": "^16.9.35",
"@types/react-dom": "^16.9.8",
"html-webpack-plugin": "^4.3.0",
"ts-loader": "^7.0.2",
"typescript": "^3.8.3",
"webpack": "^5.0.0-beta.15",
"webpack": "^4.44.1",
"webpack-bundle-analyzer": "^3.8.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3"
Expand Down
4 changes: 2 additions & 2 deletions examples/org-viewer-react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export default function App() {
return (
<Connect
location={filterOrgName(orgName)}
connector={['thegraph', { orgSubgraphUrl: env.orgSubgraphUrl }]}
options={{ chainId: env.chainId }}
connector="thegraph"
options={{ network: env.chainId }}
>
<Main>
<OrgInput onChange={openOrg} orgName={orgName} />
Expand Down
3 changes: 0 additions & 3 deletions examples/org-viewer-react/src/environment.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
type EnvType = {
addresses: string[]
chainId: number
orgSubgraphUrl?: string
}

const ENV_NAME = 'mainnet'
Expand All @@ -22,8 +21,6 @@ const ENVIRONMENTS = new Map([
'mainnet_staging',
{
chainId: 1,
orgSubgraphUrl:
'https://api.thegraph.com/subgraphs/name/aragon/aragon-mainnet-staging',
addresses: ['piedao.aragonid.eth'],
},
],
Expand Down
5 changes: 1 addition & 4 deletions examples/org-viewer-react/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ module.exports = {
devtool: 'inline-source-map',
target: 'web',
mode: process.env.NODE_ENV || 'development',
stats: {
preset: process.env.NODE_ENV === 'production' ? 'errors-only' : 'normal',
},
module: {
rules: [
{
Expand All @@ -27,7 +24,7 @@ module.exports = {
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
mainFields: ['module', 'browser', 'main'],
mainFields: ['main', 'module', 'browser'],
},
output: {
filename: 'bundle.js',
Expand Down
6 changes: 3 additions & 3 deletions examples/org-viewer-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"private": true,
"sideEffects": false,
"scripts": {
"dev": "yarn clean && webpack-dev-server",
"start": "yarn clean && webpack-dev-server",
"build": "yarn clean && NODE_ENV=production webpack",
"build:stats": "yarn clean && webpack --env production --json > webpack-stats.json",
"clean": "rm -rf ./dist ./tsconfig.tsbuildinfo",
Expand All @@ -14,16 +14,16 @@
"dependencies": {
"@aragon/connect": "^0.5.3",
"@emotion/core": "^10.0.28",
"@types/react": "^16.9.35",
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"devDependencies": {
"@types/react": "^16.9.35",
"@types/react-dom": "^16.9.8",
"html-webpack-plugin": "^4.3.0",
"ts-loader": "^7.0.2",
"typescript": "^3.8.3",
"webpack": "^5.0.0-beta.15",
"webpack": "^4.44.1",
"webpack-bundle-analyzer": "^3.8.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3"
Expand Down
6 changes: 1 addition & 5 deletions examples/org-viewer-web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ export default function App() {

const [org = null, loading] = useCancellableAsync(
async () =>
connect(
filterOrgName(orgName),
['thegraph', { orgSubgraphUrl: env.orgSubgraphUrl }],
{ chainId: env.chainId }
),
connect(filterOrgName(orgName), 'thegraph', { network: env.chainId }),
[orgName]
)

Expand Down
10 changes: 0 additions & 10 deletions examples/org-viewer-web/src/environment.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
type EnvType = {
addresses: string[]
chainId: number
orgSubgraphUrl?: string
}

const ENV_NAME = 'mainnet'
Expand All @@ -18,15 +17,6 @@ const ENVIRONMENTS = new Map([
],
},
],
[
'mainnet_staging',
{
chainId: 1,
orgSubgraphUrl:
'https://api.thegraph.com/subgraphs/name/aragon/aragon-mainnet-staging',
addresses: ['piedao.aragonid.eth'],
},
],
[
'rinkeby',
{
Expand Down
5 changes: 1 addition & 4 deletions examples/org-viewer-web/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ module.exports = {
devtool: 'inline-source-map',
target: 'web',
mode: process.env.NODE_ENV || 'development',
stats: {
preset: process.env.NODE_ENV === 'production' ? 'errors-only' : 'normal',
},
module: {
rules: [
{
Expand All @@ -27,7 +24,7 @@ module.exports = {
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
mainFields: ['module', 'browser', 'main'],
mainFields: ['main', 'module', 'browser'],
},
output: {
filename: 'bundle.js',
Expand Down
Loading

0 comments on commit 13c57df

Please sign in to comment.