Feat/675: Git info (#683)
* feat: add network-switcher lib * feat: add env variables for some deployed app urls * feat: add network processing to environment hoook * refactor: network handling * refactor: remove dialog from provider and add env setter * feat: add network switcher dialog to the trading app * refactor: add network redirect to dialog connect callback * fix: lint * feat: add network configuration files to static app * feat: update environments to use config file instead of static node url * refactor: split out network switcher utils * refactor: split up environment hook * fix: jsonify env variable for possible networks * fix: add formatter file * feat: add network loader component * feat: add network loader to the trading app * fix: assign correct global state to network swicther * feat: add status modal * feat: add network-switcher lib * feat: add env variables for some deployed app urls * feat: add network processing to environment hoook * refactor: network handling * refactor: remove dialog from provider and add env setter * feat: add network switcher dialog to the trading app * refactor: add network redirect to dialog connect callback * fix: lint * fix: jsonify env variable for possible networks * fix: add formatter file * fix: assign correct global state to network swicther * fix: failing tests from UI changes * feat: add environment validation * feat: add runtime validation for network configs * fix: readd node urls to envs to avoid breaking the apps for now * chore: rename network swicther lib to environmnet * fix: lint * feat: add tests for config hook * feat: add environment hook tests * fix: lint * fix: lint * feat: add environment hook tests * feat: add storage tests * fix: formet * feat: improve loading states * fix: format * fix: use router instead of window location * fix: rearrange network loader props and components * fix: remove FC type * fix: env validation * fix: untangle returns in network loader * fix: add teardown for env and localstorage * fix: add custom to env networks * fix: lint * fix: format * fix: lint * fix: remove env provider from simple trading app * fix: remove failing promise hacks * fix: some leftover format files * fix: remove network switcher from tsconf * fix: move Networks to libs/environment * fix: add defaults for ether env vars * feat: add tests for default ether env vars * fix: remove chain id env var from web3 container * fix: remove chain id from the environment * fix: format * fix: lint token * fix: lint env * fix: add comment to callout hack * fix: lint token again * fix: remove skip * fix: move addresses to token app * fix: improve schema validation errors and fix token app * fix: lint * fix: format * fix: format * fix: add network loaders to apps * fix: format * fix: remove logs * fix: cypress process errors * fix: change network loader hierarchy in token * fix: remove stray console.log * fix: revert test changes in simple trading app * fix: prefix env vars with NX Co-authored-by: Dexter Edwards <dexter.edwards93@gmail.com> * fix: improve schema validation errors and fix token app * fix: format * fix: disable lint rules for catch block any types * fix: format again * fix: remove redundant process.platform injections * fix: format * feat: add explorer footer * fix: format * feat: add custom executor for next * feat: adjust footer links and add custom executors * fix: lint and format * fix: format again * fix: add explicit github feedback url * fix: create footer lib * feat: add footer to token app * fix: add compiled file to ignore * fix: make lozenge styling more flexible when no variant specified * fix: remove schema duplication for third party executors * fix: add missing intent variant for the lozenge * fix: move commit hash in footer down two positions * fix: revert breaking schema removals * fix: format * chore: rename footer to network-info * fix: format Co-authored-by: Joe <joe@vega.xyz> Co-authored-by: Matthew Russell <mattrussell36@gmail.com> Co-authored-by: Dexter Edwards <dexter.edwards93@gmail.com>
This commit is contained in:
parent
de04a5b527
commit
836c232a1c
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,6 +5,7 @@
|
||||
/tmp
|
||||
/out-tsc
|
||||
/tools/executors/**/*.js
|
||||
/tools/utils/*.js
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
|
@ -13,6 +13,7 @@ NX_VEGA_ENV=TESTNET
|
||||
NX_VEGA_REST=https://lb.testnet.vega.xyz/datanode/rest
|
||||
NX_VEGA_NETWORKS='{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}'
|
||||
CYPRESS_VEGA_TENDERMINT_URL=https://lb.testnet.vega.xyz/tm
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
|
||||
# App flags
|
||||
NX_EXPLORER_ASSETS=1
|
||||
|
@ -6,6 +6,7 @@ NX_VEGA_URL=http://localhost:3028/query
|
||||
NX_VEGA_NETWORKS='{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}'
|
||||
NX_VEGA_ENV=CUSTOM
|
||||
NX_VEGA_REST=http://localhost:3029
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
|
||||
# App flags
|
||||
NX_EXPLORER_ASSETS=1
|
||||
|
@ -7,3 +7,4 @@ NX_VEGA_URL=https://n04.d.vega.xyz/query
|
||||
NX_VEGA_NETWORKS='{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}'
|
||||
NX_VEGA_ENV=DEVNET
|
||||
NX_VEGA_REST=https://n04.d.vega.xyz/datanode/rest
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
|
@ -7,3 +7,4 @@ NX_VEGA_URL=https://api.token.vega.xyz/query
|
||||
NX_VEGA_NETWORKS='{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}'
|
||||
NX_VEGA_ENV=MAINNET
|
||||
NX_VEGA_REST=https://api.token.vega.xyz/
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
|
@ -7,3 +7,4 @@ NX_VEGA_URL=https://n03.s.vega.xyz/query
|
||||
NX_VEGA_NETWORKS='{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}'
|
||||
NX_VEGA_ENV=STAGNET
|
||||
NX_VEGA_REST=https://n03.s.vega.xyz/datanode/rest
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
|
@ -7,3 +7,4 @@ NX_VEGA_URL=https://n03.stagnet2.vega.xyz/query
|
||||
NX_VEGA_NETWORKS='{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}'
|
||||
NX_VEGA_ENV=STAGNET2
|
||||
NX_VEGA_REST=https://n01.stagnet2.vega.xyz/datanode/rest
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
|
@ -7,3 +7,4 @@ NX_VEGA_URL=https://lb.testnet.vega.xyz/query
|
||||
NX_VEGA_NETWORKS='{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}'
|
||||
NX_VEGA_ENV=TESTNET
|
||||
NX_VEGA_REST=https://lb.testnet.vega.xyz/datanode/rest
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
|
@ -5,3 +5,4 @@ NX_TENDERMINT_WEBSOCKET_URL=wss://localhost:26607/websocket
|
||||
NX_VEGA_URL=http://localhost:3003/query
|
||||
NX_VEGA_ENV=CUSTOM
|
||||
NX_VEGA_REST=http://localhost:3029/rest
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
|
@ -4,7 +4,7 @@
|
||||
"projectType": "application",
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "@nrwl/web:webpack",
|
||||
"executor": "./tools/executors/webpack:build",
|
||||
"outputs": ["{options.outputPath}"],
|
||||
"defaultConfiguration": "production",
|
||||
"options": {
|
||||
@ -38,7 +38,7 @@
|
||||
}
|
||||
},
|
||||
"serve": {
|
||||
"executor": "./tools/executors/serve:serve",
|
||||
"executor": "./tools/executors/webpack:serve",
|
||||
"options": {
|
||||
"port": 3000,
|
||||
"buildTarget": "explorer:build",
|
||||
|
@ -2,6 +2,7 @@ import { useState, useEffect } from 'react';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import { ThemeContext, useThemeSwitcher } from '@vegaprotocol/react-helpers';
|
||||
import { EnvironmentProvider, NetworkLoader } from '@vegaprotocol/environment';
|
||||
import { NetworkInfo } from '@vegaprotocol/network-info';
|
||||
import { createClient } from './lib/apollo-client';
|
||||
import { Nav } from './components/nav';
|
||||
import { Header } from './components/header';
|
||||
@ -36,6 +37,9 @@ function App() {
|
||||
/>
|
||||
<Nav menuOpen={menuOpen} />
|
||||
<Main />
|
||||
<footer className="grid grid-rows-2 grid-cols-[1fr_auto] md:flex md:col-span-2 p-16 gap-12 border-t-1">
|
||||
<NetworkInfo />
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
</NetworkLoader>
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Lozenge } from '@vegaprotocol/ui-toolkit';
|
||||
import { Lozenge, Intent } from '@vegaprotocol/ui-toolkit';
|
||||
|
||||
interface TxOrderTypeProps {
|
||||
orderType: string;
|
||||
@ -36,7 +36,7 @@ const displayString: StringMap = {
|
||||
|
||||
export const TxOrderType = ({ orderType, className }: TxOrderTypeProps) => {
|
||||
return (
|
||||
<Lozenge data-testid="tx-type" className={className}>
|
||||
<Lozenge data-testid="tx-type" variant={Intent.None} className={className}>
|
||||
{displayString[orderType] || orderType}
|
||||
</Lozenge>
|
||||
);
|
||||
|
@ -1,5 +1,13 @@
|
||||
const { execSync } = require('child_process');
|
||||
const webpack = require('webpack');
|
||||
const SentryPlugin = require('@sentry/webpack-plugin');
|
||||
|
||||
const gitCommitHash = execSync('git rev-parse HEAD').toString();
|
||||
const gitOriginUrl = execSync('git remote get-url origin')
|
||||
.toString()
|
||||
.replace('ssh://git@github.com', 'https://github.com')
|
||||
.replace('.git', '');
|
||||
|
||||
module.exports = (config, context) => {
|
||||
const additionalPlugins = process.env.SENTRY_AUTH_TOKEN
|
||||
? [
|
||||
@ -9,8 +17,16 @@ module.exports = (config, context) => {
|
||||
}),
|
||||
]
|
||||
: [];
|
||||
|
||||
return {
|
||||
...config,
|
||||
plugins: [...additionalPlugins, ...config.plugins],
|
||||
plugins: [
|
||||
...additionalPlugins,
|
||||
...config.plugins,
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.GIT_COMMIT_HASH': JSON.stringify(gitCommitHash),
|
||||
'process.env.GIT_ORIGIN_URL': JSON.stringify(gitOriginUrl),
|
||||
}),
|
||||
],
|
||||
};
|
||||
};
|
||||
|
@ -4,7 +4,7 @@
|
||||
"projectType": "application",
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "@nrwl/web:webpack",
|
||||
"executor": "./tools/executors/webpack:build",
|
||||
"outputs": ["{options.outputPath}"],
|
||||
"defaultConfiguration": "production",
|
||||
"options": {
|
||||
@ -41,7 +41,7 @@
|
||||
}
|
||||
},
|
||||
"serve": {
|
||||
"executor": "./tools/executors/serve:serve",
|
||||
"executor": "./tools/executors/webpack:serve",
|
||||
"options": {
|
||||
"buildTarget": "simple-trading-app:build",
|
||||
"hmr": true,
|
||||
|
@ -5,7 +5,7 @@
|
||||
"tags": [],
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "@nrwl/web:webpack",
|
||||
"executor": "./tools/executors/webpack:build",
|
||||
"outputs": ["{options.outputPath}"],
|
||||
"defaultConfiguration": "production",
|
||||
"options": {
|
||||
@ -36,7 +36,7 @@
|
||||
}
|
||||
},
|
||||
"serve": {
|
||||
"executor": "./tools/executors/serve:serve",
|
||||
"executor": "./tools/executors/webpack:serve",
|
||||
"options": {
|
||||
"buildTarget": "static:build"
|
||||
},
|
||||
|
@ -4,7 +4,7 @@
|
||||
"projectType": "application",
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "@nrwl/web:webpack",
|
||||
"executor": "./tools/executors/webpack:build",
|
||||
"outputs": ["{options.outputPath}"],
|
||||
"defaultConfiguration": "production",
|
||||
"options": {
|
||||
@ -37,7 +37,7 @@
|
||||
}
|
||||
},
|
||||
"serve": {
|
||||
"executor": "./tools/executors/serve:serve",
|
||||
"executor": "./tools/executors/webpack:serve",
|
||||
"options": {
|
||||
"port": 3010,
|
||||
"buildTarget": "stats:build",
|
||||
|
@ -7,6 +7,7 @@ NX_ETHERSCAN_URL=https://ropsten.etherscan.io
|
||||
NX_FAIRGROUND=false
|
||||
NX_IS_NEW_BRIDGE_CONTRACT=true
|
||||
NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET":"https://dev.token.vega.xyz","STAGNET2":"staging2.token.vega.xyz","TESTNET":"token.fairground.wtf","MAINNET":"token.vega.xyz"}'
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
|
||||
#Test configuration variables
|
||||
CYPRESS_FAIRGROUND=false
|
||||
|
@ -5,6 +5,7 @@ NX_ETHERSCAN_URL=https://ropsten.etherscan.io
|
||||
NX_FAIRGROUND=false
|
||||
NX_IS_NEW_BRIDGE_CONTRACT=true
|
||||
NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET":"https://dev.token.vega.xyz","STAGNET2":"staging2.token.vega.xyz","TESTNET":"token.fairground.wtf","MAINNET":"token.vega.xyz"}'
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
|
||||
NX_VEGA_URL=http://localhost:3028/query
|
||||
NX_VEGA_REST=http://localhost:3029
|
||||
|
@ -5,3 +5,4 @@ NX_VEGA_URL=https://n04.d.vega.xyz/query
|
||||
NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET":"https://dev.token.vega.xyz","STAGNET2":"staging2.token.vega.xyz","TESTNET":"token.fairground.wtf","MAINNET":"token.vega.xyz"}'
|
||||
NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
|
||||
NX_ETHERSCAN_URL=https://ropsten.etherscan.io
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
|
@ -5,3 +5,4 @@ NX_VEGA_URL=https://api.token.vega.xyz/query
|
||||
NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET":"https://dev.token.vega.xyz","STAGNET2":"staging2.token.vega.xyz","TESTNET":"token.fairground.wtf","MAINNET":"token.vega.xyz"}'
|
||||
NX_ETHEREUM_PROVIDER_URL=https://mainnet.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
|
||||
NX_ETHERSCAN_URL=https://etherscan.io
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
|
@ -5,3 +5,4 @@ NX_VEGA_URL=https://n03.s.vega.xyz/query
|
||||
NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET":"https://dev.token.vega.xyz","STAGNET2":"staging2.token.vega.xyz","TESTNET":"token.fairground.wtf","MAINNET":"token.vega.xyz"}'
|
||||
NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
|
||||
NX_ETHERSCAN_URL=https://ropsten.etherscan.io
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
|
@ -5,3 +5,4 @@ NX_VEGA_URL=https://n03.stagnet2.vega.xyz/query
|
||||
NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET":"https://dev.token.vega.xyz","STAGNET2":"staging2.token.vega.xyz","TESTNET":"token.fairground.wtf","MAINNET":"token.vega.xyz"}'
|
||||
NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
|
||||
NX_ETHERSCAN_URL=https://ropsten.etherscan.io
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
|
@ -5,3 +5,4 @@ NX_VEGA_URL=https://lb.testnet.vega.xyz/query
|
||||
NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET":"https://dev.token.vega.xyz","STAGNET2":"staging2.token.vega.xyz","TESTNET":"token.fairground.wtf","MAINNET":"token.vega.xyz"}'
|
||||
NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
|
||||
NX_ETHERSCAN_URL=https://ropsten.etherscan.io
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
|
@ -4,7 +4,7 @@
|
||||
"projectType": "application",
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "@nrwl/web:webpack",
|
||||
"executor": "./tools/executors/webpack:build",
|
||||
"outputs": ["{options.outputPath}"],
|
||||
"defaultConfiguration": "production",
|
||||
"options": {
|
||||
@ -38,7 +38,7 @@
|
||||
}
|
||||
},
|
||||
"serve": {
|
||||
"executor": "./tools/executors/serve:serve",
|
||||
"executor": "./tools/executors/webpack:serve",
|
||||
"options": {
|
||||
"port": 4210,
|
||||
"buildTarget": "token:build",
|
||||
|
@ -4,7 +4,7 @@ import React, { useMemo } from 'react';
|
||||
import { BrowserRouter as Router } from 'react-router-dom';
|
||||
import { AppLoader } from './app-loader';
|
||||
import { AppBanner } from './components/app-banner';
|
||||
import { AppFooter } from './components/app-footer';
|
||||
import { NetworkInfo } from '@vegaprotocol/network-info';
|
||||
import { BalanceManager } from './components/balance-manager';
|
||||
import { EthWallet } from './components/eth-wallet';
|
||||
import { TemplateSidebar } from './components/page-templates/template-sidebar';
|
||||
@ -54,7 +54,9 @@ const AppContainer = () => {
|
||||
<TemplateSidebar sidebar={sideBar}>
|
||||
<AppRouter />
|
||||
</TemplateSidebar>
|
||||
<AppFooter />
|
||||
<footer className="grid grid-rows-2 grid-cols-[1fr_auto] md:flex md:col-span-2 p-16 gap-12 border-t-1">
|
||||
<NetworkInfo />
|
||||
</footer>
|
||||
</div>
|
||||
<VegaWalletDialogs />
|
||||
<TransactionModal />
|
||||
|
@ -1,28 +0,0 @@
|
||||
import { Link } from '@vegaprotocol/ui-toolkit';
|
||||
import { Trans } from 'react-i18next';
|
||||
|
||||
import { Links } from '../../config';
|
||||
import { ENV } from '../../config/env';
|
||||
|
||||
export const AppFooter = () => {
|
||||
return (
|
||||
<footer className="p-12 text-ui">
|
||||
<p>Version: {ENV.commit || 'development'}</p>
|
||||
<p>
|
||||
<Trans
|
||||
i18nKey="footerLinksText"
|
||||
components={{
|
||||
/* eslint-disable */
|
||||
feedbackLink: (
|
||||
<Link className="text-white underline" href={Links.FEEDBACK} />
|
||||
),
|
||||
githubLink: (
|
||||
<Link className="text-white underline" href={Links.GITHUB} />
|
||||
),
|
||||
/* eslint-enable */
|
||||
}}
|
||||
/>
|
||||
</p>
|
||||
</footer>
|
||||
);
|
||||
};
|
@ -1 +0,0 @@
|
||||
export * from './app-footer';
|
@ -49,7 +49,10 @@ export const AmountInput = ({
|
||||
min={0}
|
||||
step="any"
|
||||
appendElement={
|
||||
<Lozenge className="text-[10px] relative top-[-2px]">
|
||||
<Lozenge
|
||||
variant={Intent.None}
|
||||
className="text-[10px] relative top-[-2px]"
|
||||
>
|
||||
{currency}
|
||||
</Lozenge>
|
||||
}
|
||||
|
@ -24,6 +24,12 @@ Example configurations are provided here:
|
||||
- [Stagnet1](./.env.stagnet1)
|
||||
- [Stagnet2](./.env.stagnet2)
|
||||
|
||||
For convenience, you can boot the app injecting one of the configurations above by running:
|
||||
|
||||
```bash
|
||||
yarn nx run token:serve --env={env} # e.g. stagnet1
|
||||
```
|
||||
|
||||
There are a few different configuration options offered for this app:
|
||||
|
||||
The network configuration for the app
|
||||
|
@ -41,6 +41,14 @@ const networkParamsQueryMock: MockedResponse<NetworkParamsQuery> = {
|
||||
},
|
||||
};
|
||||
|
||||
const mockEnvironment = {
|
||||
VEGA_ENV: 'TESTNET',
|
||||
VEGA_NETWORKS: JSON.stringify({}),
|
||||
GIT_BRANCH: 'test',
|
||||
GIT_COMMIT_HASH: 'abcdef',
|
||||
GIT_ORIGIN_URL: 'https://github.com/test/repo',
|
||||
};
|
||||
|
||||
jest.mock('@web3-react/core', () => {
|
||||
const original = jest.requireActual('@web3-react/core');
|
||||
return {
|
||||
@ -51,7 +59,7 @@ jest.mock('@web3-react/core', () => {
|
||||
|
||||
function setup(mock = networkParamsQueryMock) {
|
||||
return render(
|
||||
<EnvironmentProvider>
|
||||
<EnvironmentProvider definitions={mockEnvironment}>
|
||||
<MockedProvider mocks={[mock]}>
|
||||
<Web3Container>
|
||||
<div>
|
||||
|
@ -4,7 +4,7 @@
|
||||
"projectType": "application",
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "@nrwl/next:build",
|
||||
"executor": "./tools/executors/next:build",
|
||||
"outputs": ["{options.outputPath}"],
|
||||
"defaultConfiguration": "production",
|
||||
"options": {
|
||||
@ -19,7 +19,7 @@
|
||||
}
|
||||
},
|
||||
"serve": {
|
||||
"executor": "@nrwl/next:server",
|
||||
"executor": "./tools/executors/next:serve",
|
||||
"options": {
|
||||
"buildTarget": "trading:build",
|
||||
"dev": true
|
||||
|
@ -40,6 +40,10 @@ const mockEnvironmentState: EnvironmentState = {
|
||||
},
|
||||
ETHEREUM_PROVIDER_URL: 'https://ether.provider',
|
||||
ETHERSCAN_URL: 'https://etherscan.url',
|
||||
GIT_BRANCH: 'test',
|
||||
GIT_ORIGIN_URL: 'https://github.com/test/repo',
|
||||
GIT_COMMIT_HASH: 'abcde01234',
|
||||
GITHUB_FEEDBACK_URL: 'https://github.com/test/feedback',
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
@ -59,6 +63,11 @@ beforeEach(() => {
|
||||
process.env['NX_VEGA_NETWORKS'] = JSON.stringify(
|
||||
mockEnvironmentState.VEGA_NETWORKS
|
||||
);
|
||||
process.env['NX_GIT_BRANCH'] = mockEnvironmentState.GIT_BRANCH;
|
||||
process.env['NX_GIT_ORIGIN_URL'] = mockEnvironmentState.GIT_ORIGIN_URL;
|
||||
process.env['NX_GIT_COMMIT_HASH'] = mockEnvironmentState.GIT_COMMIT_HASH;
|
||||
process.env['NX_GITHUB_FEEDBACK_URL'] =
|
||||
mockEnvironmentState.GITHUB_FEEDBACK_URL;
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
|
@ -58,6 +58,14 @@ const getBundledEnvironmentValue = (key: EnvKey) => {
|
||||
return process.env['NX_ETHERSCAN_URL'];
|
||||
case 'VEGA_NETWORKS':
|
||||
return process.env['NX_VEGA_NETWORKS'];
|
||||
case 'GIT_BRANCH':
|
||||
return process.env['NX_GIT_BRANCH'];
|
||||
case 'GIT_COMMIT_HASH':
|
||||
return process.env['NX_GIT_COMMIT_HASH'];
|
||||
case 'GIT_ORIGIN_URL':
|
||||
return process.env['NX_GIT_ORIGIN_URL'];
|
||||
case 'GITHUB_FEEDBACK_URL':
|
||||
return process.env['NX_GITHUB_FEEDBACK_URL'];
|
||||
case 'VEGA_EXPLORER_URL':
|
||||
return process.env['NX_VEGA_EXPLORER_URL'];
|
||||
}
|
||||
|
@ -23,6 +23,10 @@ const schemaObject = {
|
||||
ETHERSCAN_URL: z.string().url({
|
||||
message: 'The NX_ETHERSCAN_URL environment variable must be a valid url',
|
||||
}),
|
||||
GIT_BRANCH: z.string(),
|
||||
GIT_COMMIT_HASH: z.string(),
|
||||
GIT_ORIGIN_URL: z.string(),
|
||||
GITHUB_FEEDBACK_URL: z.optional(z.string()),
|
||||
VEGA_ENV: z.nativeEnum(Networks),
|
||||
VEGA_NETWORKS: z
|
||||
.object(
|
||||
|
12
libs/network-info/.babelrc
Normal file
12
libs/network-info/.babelrc
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"presets": [
|
||||
[
|
||||
"@nrwl/react/babel",
|
||||
{
|
||||
"runtime": "automatic",
|
||||
"useBuiltIns": "usage"
|
||||
}
|
||||
]
|
||||
],
|
||||
"plugins": []
|
||||
}
|
18
libs/network-info/.eslintrc.json
Normal file
18
libs/network-info/.eslintrc.json
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"extends": ["plugin:@nrwl/nx/react", "../../.eslintrc.json"],
|
||||
"ignorePatterns": ["!**/*"],
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
|
||||
"rules": {}
|
||||
},
|
||||
{
|
||||
"files": ["*.ts", "*.tsx"],
|
||||
"rules": {}
|
||||
},
|
||||
{
|
||||
"files": ["*.js", "*.jsx"],
|
||||
"rules": {}
|
||||
}
|
||||
]
|
||||
}
|
21
libs/network-info/README.md
Normal file
21
libs/network-info/README.md
Normal file
@ -0,0 +1,21 @@
|
||||
# network-info
|
||||
|
||||
This library was generated with [Nx](https://nx.dev).
|
||||
|
||||
## Prerequisites
|
||||
|
||||
The environment variables needed to be present for any app consuming this library.
|
||||
|
||||
`NX_VEGA_URL` OR `NX_VEGA_CONFIG_URL` - either the network configuration url or a url to a node to directly connect to
|
||||
|
||||
`NX_VEGA_NETWORKS` - JSON object with key-value pairs for environments and their deployed URLs
|
||||
|
||||
`NX_GITHUB_FEEDBACK_URL` - the repository's feedback URL to point to
|
||||
|
||||
`NX_ETHEREUM_PROVIDER_URL` - the Ethereum provider url
|
||||
|
||||
For examples, see Block Explorer's .env files [here](../../apps/explorer)
|
||||
|
||||
## Running unit tests
|
||||
|
||||
Run `nx test network-info` to execute the unit tests via [Jest](https://jestjs.io).
|
9
libs/network-info/jest.config.js
Normal file
9
libs/network-info/jest.config.js
Normal file
@ -0,0 +1,9 @@
|
||||
module.exports = {
|
||||
displayName: 'network-info',
|
||||
preset: '../../jest.preset.js',
|
||||
transform: {
|
||||
'^.+\\.[tj]sx?$': 'babel-jest',
|
||||
},
|
||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
|
||||
coverageDirectory: '../../coverage/libs/network-info',
|
||||
};
|
4
libs/network-info/package.json
Normal file
4
libs/network-info/package.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "@vegaprotocol/network-info",
|
||||
"version": "0.0.1"
|
||||
}
|
43
libs/network-info/project.json
Normal file
43
libs/network-info/project.json
Normal file
@ -0,0 +1,43 @@
|
||||
{
|
||||
"root": "libs/network-info",
|
||||
"sourceRoot": "libs/network-info/src",
|
||||
"projectType": "library",
|
||||
"tags": [],
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "@nrwl/web:rollup",
|
||||
"outputs": ["{options.outputPath}"],
|
||||
"options": {
|
||||
"outputPath": "dist/libs/network-info",
|
||||
"tsConfig": "libs/network-info/tsconfig.lib.json",
|
||||
"project": "libs/network-info/package.json",
|
||||
"entryFile": "libs/network-info/src/index.ts",
|
||||
"external": ["react/jsx-runtime"],
|
||||
"rollupConfig": "@nrwl/react/plugins/bundle-rollup",
|
||||
"compiler": "babel",
|
||||
"assets": [
|
||||
{
|
||||
"glob": "libs/network-info/README.md",
|
||||
"input": ".",
|
||||
"output": "."
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"executor": "@nrwl/linter:eslint",
|
||||
"outputs": ["{options.outputFile}"],
|
||||
"options": {
|
||||
"lintFilePatterns": ["libs/network-info/**/*.{ts,tsx,js,jsx}"]
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
"executor": "@nrwl/jest:jest",
|
||||
"outputs": ["coverage/libs/network-info"],
|
||||
"options": {
|
||||
"jestConfig": "libs/network-info/jest.config.js",
|
||||
"passWithNoTests": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
1
libs/network-info/src/index.ts
Normal file
1
libs/network-info/src/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './network-info';
|
87
libs/network-info/src/network-info.tsx
Normal file
87
libs/network-info/src/network-info.tsx
Normal file
@ -0,0 +1,87 @@
|
||||
import { useState } from 'react';
|
||||
import { t } from '@vegaprotocol/react-helpers';
|
||||
import { Link, Lozenge } from '@vegaprotocol/ui-toolkit';
|
||||
import {
|
||||
useEnvironment,
|
||||
NetworkSwitcherDialog,
|
||||
} from '@vegaprotocol/environment';
|
||||
|
||||
const getFeedbackLinks = (gitOriginUrl?: string) =>
|
||||
[
|
||||
{
|
||||
name: 'Github',
|
||||
url: gitOriginUrl,
|
||||
},
|
||||
].filter((link) => !!link.url);
|
||||
|
||||
export const NetworkInfo = () => {
|
||||
const [isNetworkConfigOpen, setNetworkConfigOpen] = useState(false);
|
||||
const {
|
||||
VEGA_URL,
|
||||
VEGA_NETWORKS,
|
||||
GIT_COMMIT_HASH,
|
||||
GIT_ORIGIN_URL,
|
||||
GITHUB_FEEDBACK_URL,
|
||||
ETHEREUM_PROVIDER_URL,
|
||||
} = useEnvironment();
|
||||
const feedbackLinks = getFeedbackLinks(GITHUB_FEEDBACK_URL);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
<p className="mb-16">
|
||||
{t('Reading network data from')}{' '}
|
||||
<Lozenge className="text-black dark:text-white bg-white-60 dark:bg-black-60">
|
||||
{VEGA_URL}
|
||||
</Lozenge>
|
||||
. <Link onClick={() => setNetworkConfigOpen(true)}>{t('Edit')}</Link>
|
||||
</p>
|
||||
<p className="mb-[1rem]">
|
||||
{t('Reading Ethereum data from')}{' '}
|
||||
<Lozenge className="text-black dark:text-white bg-white-60 dark:bg-black-60">
|
||||
{ETHEREUM_PROVIDER_URL}
|
||||
</Lozenge>
|
||||
.{' '}
|
||||
</p>
|
||||
{GIT_COMMIT_HASH && GIT_ORIGIN_URL && (
|
||||
<p className="mb-[1rem]">
|
||||
{t('Version/commit hash')}:{' '}
|
||||
<Link
|
||||
href={`${GIT_ORIGIN_URL}/commit/${GIT_COMMIT_HASH}`}
|
||||
target="_blank"
|
||||
>
|
||||
{GIT_COMMIT_HASH}
|
||||
</Link>
|
||||
</p>
|
||||
)}
|
||||
{feedbackLinks.length > 0 && (
|
||||
<p className="mb-16">
|
||||
{t('Known issues and feedback on')}{' '}
|
||||
{feedbackLinks.map(({ name, url }, index) => (
|
||||
<>
|
||||
<Link key={index} href={url}>
|
||||
{name}
|
||||
</Link>
|
||||
{feedbackLinks.length > 1 &&
|
||||
index < feedbackLinks.length - 2 &&
|
||||
','}
|
||||
{feedbackLinks.length > 1 &&
|
||||
index === feedbackLinks.length - 1 &&
|
||||
`, ${t('and')} `}
|
||||
</>
|
||||
))}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<NetworkSwitcherDialog
|
||||
dialogOpen={isNetworkConfigOpen}
|
||||
setDialogOpen={setNetworkConfigOpen}
|
||||
onConnect={({ network }) => {
|
||||
if (VEGA_NETWORKS[network]) {
|
||||
window.location.href = VEGA_NETWORKS[network] as string;
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
25
libs/network-info/tsconfig.json
Normal file
25
libs/network-info/tsconfig.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"allowJs": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"noImplicitOverride": true,
|
||||
"noPropertyAccessFromIndexSignature": false,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"files": [],
|
||||
"include": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.lib.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.spec.json"
|
||||
}
|
||||
]
|
||||
}
|
22
libs/network-info/tsconfig.lib.json
Normal file
22
libs/network-info/tsconfig.lib.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../dist/out-tsc",
|
||||
"types": ["node"]
|
||||
},
|
||||
"files": [
|
||||
"../../node_modules/@nrwl/react/typings/cssmodule.d.ts",
|
||||
"../../node_modules/@nrwl/react/typings/image.d.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"**/*.spec.ts",
|
||||
"**/*.test.ts",
|
||||
"**/*.spec.tsx",
|
||||
"**/*.test.tsx",
|
||||
"**/*.spec.js",
|
||||
"**/*.test.js",
|
||||
"**/*.spec.jsx",
|
||||
"**/*.test.jsx"
|
||||
],
|
||||
"include": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"]
|
||||
}
|
19
libs/network-info/tsconfig.spec.json
Normal file
19
libs/network-info/tsconfig.spec.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../dist/out-tsc",
|
||||
"module": "commonjs",
|
||||
"types": ["jest", "node"]
|
||||
},
|
||||
"include": [
|
||||
"**/*.test.ts",
|
||||
"**/*.spec.ts",
|
||||
"**/*.test.tsx",
|
||||
"**/*.spec.tsx",
|
||||
"**/*.test.js",
|
||||
"**/*.spec.js",
|
||||
"**/*.test.jsx",
|
||||
"**/*.spec.jsx",
|
||||
"**/*.d.ts"
|
||||
]
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
{
|
||||
"name": "@vegaprotocol/smart-contracts",
|
||||
"version": "0.0.1",
|
||||
"type": "commonjs"
|
||||
"version": "0.0.1"
|
||||
}
|
||||
|
@ -11,6 +11,11 @@ const Template: Story = (args) => <Lozenge {...args}>lozenge</Lozenge>;
|
||||
|
||||
export const Default = Template.bind({});
|
||||
|
||||
export const None = Template.bind({});
|
||||
None.args = {
|
||||
variant: Intent.None,
|
||||
};
|
||||
|
||||
export const Primary = Template.bind({});
|
||||
Primary.args = {
|
||||
variant: Intent.Primary,
|
||||
|
@ -1,7 +1,7 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { getIntentTextAndBackground } from '../../utils/intent';
|
||||
import { Intent } from '../../utils/intent';
|
||||
import type { Intent } from '../../utils/intent';
|
||||
|
||||
interface LozengeProps {
|
||||
children: ReactNode;
|
||||
@ -10,7 +10,7 @@ interface LozengeProps {
|
||||
}
|
||||
|
||||
const getLozengeClasses = (
|
||||
variant: LozengeProps['variant'],
|
||||
variant?: LozengeProps['variant'],
|
||||
className?: string
|
||||
) => {
|
||||
return classNames(
|
||||
@ -20,11 +20,7 @@ const getLozengeClasses = (
|
||||
);
|
||||
};
|
||||
|
||||
export const Lozenge = ({
|
||||
children,
|
||||
variant = Intent.None,
|
||||
className,
|
||||
}: LozengeProps) => {
|
||||
export const Lozenge = ({ children, variant, className }: LozengeProps) => {
|
||||
return (
|
||||
<span className={getLozengeClasses(variant, className)}>{children}</span>
|
||||
);
|
||||
|
@ -28,7 +28,7 @@ export const getIntentBorder = (intent = Intent.None) => {
|
||||
};
|
||||
};
|
||||
|
||||
export const getIntentTextAndBackground = (intent = Intent.None) => {
|
||||
export const getIntentTextAndBackground = (intent?: Intent) => {
|
||||
return {
|
||||
'bg-black text-white dark:bg-white dark:text-black': intent === Intent.None,
|
||||
'bg-vega-pink text-black dark:bg-vega-yellow dark:text-black-normal':
|
||||
|
18
tools/executors/next/build/impl.ts
Normal file
18
tools/executors/next/build/impl.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import type { ExecutorContext } from '@nrwl/devkit';
|
||||
import setup from '../../../utils/setup-environment';
|
||||
import nextBuildExecutor from '@nrwl/next/src/executors/build/build.impl';
|
||||
import { NextBuildBuilderOptions } from '@nrwl/next/src/utils/types';
|
||||
|
||||
type Schema = NextBuildBuilderOptions & {
|
||||
env?: string;
|
||||
};
|
||||
|
||||
export default async function build(
|
||||
options: Schema,
|
||||
context: ExecutorContext
|
||||
): Promise<ReturnType<typeof nextBuildExecutor>> {
|
||||
const { env, ...nextOptions } = options;
|
||||
await setup(env, context, 'tools/executors/next/build');
|
||||
|
||||
return await nextBuildExecutor(nextOptions, context);
|
||||
}
|
50
tools/executors/next/build/schema.json
Normal file
50
tools/executors/next/build/schema.json
Normal file
@ -0,0 +1,50 @@
|
||||
{
|
||||
"cli": "nx",
|
||||
"id": "build",
|
||||
"description": "Serves an app using @nrwl/next:build",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"env": {
|
||||
"type": "string",
|
||||
"description": "Target environment to run the application in. This assumes an .env file present in the project's root in the following format: .env.{envName}"
|
||||
},
|
||||
"root": {
|
||||
"description": "The source root",
|
||||
"type": "string"
|
||||
},
|
||||
"outputPath": {
|
||||
"type": "string",
|
||||
"description": "The output path of the generated files."
|
||||
},
|
||||
"fileReplacements": {
|
||||
"description": "Replace files with other files in the build.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"replace": {
|
||||
"type": "string",
|
||||
"description": "The file to be replaced."
|
||||
},
|
||||
"with": {
|
||||
"type": "string",
|
||||
"description": "The file to replace with."
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["replace", "with"]
|
||||
},
|
||||
"default": []
|
||||
},
|
||||
"nextConfig": {
|
||||
"description": "Path (relative to workspace root) to a function which takes phase, config, and builder options, and returns the resulting config. This is an advanced option and should not be used with a normal Next.js config file (i.e. `next.config.js`).",
|
||||
"type": "string"
|
||||
},
|
||||
"buildLibsFromSource": {
|
||||
"type": "boolean",
|
||||
"description": "Read buildable libraries from source instead of building them separately.",
|
||||
"default": true
|
||||
}
|
||||
},
|
||||
"required": ["root", "outputPath"]
|
||||
}
|
14
tools/executors/next/executor.json
Normal file
14
tools/executors/next/executor.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"executors": {
|
||||
"serve": {
|
||||
"implementation": "./serve/impl",
|
||||
"schema": "./serve/schema.json",
|
||||
"description": "Starts a next server with an optional explicit environment."
|
||||
},
|
||||
"build": {
|
||||
"implementation": "./build/impl",
|
||||
"schema": "./build/schema.json",
|
||||
"description": "Starts a next server with an optional explicit environment."
|
||||
}
|
||||
}
|
||||
}
|
18
tools/executors/next/serve/impl.ts
Normal file
18
tools/executors/next/serve/impl.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import type { ExecutorContext } from '@nrwl/devkit';
|
||||
import setup from '../../../utils/setup-environment';
|
||||
import nextServerExecutor from '@nrwl/next/src/executors/server/server.impl';
|
||||
import { NextServeBuilderOptions } from '@nrwl/next/src/utils/types';
|
||||
|
||||
type Schema = NextServeBuilderOptions & {
|
||||
env?: string;
|
||||
};
|
||||
|
||||
export default async function* serve(
|
||||
options: Schema,
|
||||
context: ExecutorContext
|
||||
): ReturnType<typeof nextServerExecutor> {
|
||||
const { env, ...nextOptions } = options;
|
||||
await setup(env, context, 'tools/executors/next/serve');
|
||||
|
||||
return yield* nextServerExecutor(nextOptions, context);
|
||||
}
|
54
tools/executors/next/serve/schema.json
Normal file
54
tools/executors/next/serve/schema.json
Normal file
@ -0,0 +1,54 @@
|
||||
{
|
||||
"cli": "nx",
|
||||
"id": "serve",
|
||||
"description": "Serves an app using @nrwl/next:server",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"env": {
|
||||
"type": "string",
|
||||
"description": "Target environment to run the application in. This assumes an .env file present in the project's root in the following format: .env.{envName}"
|
||||
},
|
||||
"dev": {
|
||||
"type": "boolean",
|
||||
"description": "Serve the application in the dev mode.",
|
||||
"default": true
|
||||
},
|
||||
"buildTarget": {
|
||||
"type": "string",
|
||||
"description": "Target which builds the application."
|
||||
},
|
||||
"port": {
|
||||
"type": "number",
|
||||
"description": "Port to listen on.",
|
||||
"default": 4200
|
||||
},
|
||||
"staticMarkup": {
|
||||
"type": "boolean",
|
||||
"description": "Static markup.",
|
||||
"default": false
|
||||
},
|
||||
"quiet": {
|
||||
"type": "boolean",
|
||||
"description": "Hide error messages containing server information.",
|
||||
"default": false
|
||||
},
|
||||
"customServerPath": {
|
||||
"type": "string",
|
||||
"description": "Use a custom server script."
|
||||
},
|
||||
"hostname": {
|
||||
"type": "string",
|
||||
"description": "Hostname on which the application is served."
|
||||
},
|
||||
"proxyConfig": {
|
||||
"type": "string",
|
||||
"description": "Path to the proxy configuration file."
|
||||
},
|
||||
"buildLibsFromSource": {
|
||||
"type": "boolean",
|
||||
"description": "Read buildable libraries from source instead of building them separately.",
|
||||
"default": true
|
||||
}
|
||||
},
|
||||
"required": ["buildTarget"]
|
||||
}
|
@ -8,6 +8,6 @@
|
||||
"sourceMap": false,
|
||||
"inlineSourceMap": true
|
||||
},
|
||||
"include": ["impl.ts"],
|
||||
"include": ["build/impl.ts", "serve/impl.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
{
|
||||
"executors": {
|
||||
"serve": {
|
||||
"implementation": "./impl",
|
||||
"schema": "./schema.json",
|
||||
"description": "Starts a dev-server with an optional explicit environment."
|
||||
}
|
||||
}
|
||||
}
|
19
tools/executors/webpack/build/impl.ts
Normal file
19
tools/executors/webpack/build/impl.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import type { ExecutorContext } from '@nrwl/devkit';
|
||||
import setup from '../../../utils/setup-environment';
|
||||
import webpackBuildExecutor, {
|
||||
WebWebpackExecutorOptions,
|
||||
} from '@nrwl/web/src/executors/webpack/webpack.impl';
|
||||
|
||||
type Schema = WebWebpackExecutorOptions & {
|
||||
env?: string;
|
||||
};
|
||||
|
||||
export default async function* build(
|
||||
options: Schema,
|
||||
context: ExecutorContext
|
||||
): ReturnType<typeof webpackBuildExecutor> {
|
||||
const { env, ...buildOptions } = options;
|
||||
await setup(env, context, 'tools/executors/webpack/build');
|
||||
|
||||
return yield* webpackBuildExecutor(buildOptions, context);
|
||||
}
|
359
tools/executors/webpack/build/schema.json
Normal file
359
tools/executors/webpack/build/schema.json
Normal file
@ -0,0 +1,359 @@
|
||||
{
|
||||
"cli": "nx",
|
||||
"id": "build",
|
||||
"description": "Serves an app using @nrwl/web:webpack",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"env": {
|
||||
"type": "string",
|
||||
"description": "Target environment to run the application in. This assumes an .env file present in the project's root in the following format: .env.{envName}"
|
||||
},
|
||||
"crossOrigin": {
|
||||
"type": "string",
|
||||
"description": "The `crossorigin` attribute to use for generated javascript script tags. One of 'none' | 'anonymous' | 'use-credentials'."
|
||||
},
|
||||
"main": {
|
||||
"type": "string",
|
||||
"description": "The name of the main entry-point file."
|
||||
},
|
||||
"tsConfig": {
|
||||
"type": "string",
|
||||
"description": "The name of the Typescript configuration file."
|
||||
},
|
||||
"compiler": {
|
||||
"type": "string",
|
||||
"description": "The compiler to use.",
|
||||
"enum": ["babel", "swc"],
|
||||
"default": "babel"
|
||||
},
|
||||
"outputPath": {
|
||||
"type": "string",
|
||||
"description": "The output path of the generated files."
|
||||
},
|
||||
"deleteOutputPath": {
|
||||
"type": "boolean",
|
||||
"description": "Delete the output path before building.",
|
||||
"default": true
|
||||
},
|
||||
"watch": {
|
||||
"type": "boolean",
|
||||
"description": "Enable re-building when files change.",
|
||||
"default": false
|
||||
},
|
||||
"baseHref": {
|
||||
"type": "string",
|
||||
"description": "Base url for the application being built."
|
||||
},
|
||||
"deployUrl": {
|
||||
"type": "string",
|
||||
"description": "URL where the application will be deployed."
|
||||
},
|
||||
"vendorChunk": {
|
||||
"type": "boolean",
|
||||
"description": "Use a separate bundle containing only vendor libraries.",
|
||||
"default": true
|
||||
},
|
||||
"commonChunk": {
|
||||
"type": "boolean",
|
||||
"description": "Use a separate bundle containing code used across multiple bundles.",
|
||||
"default": true
|
||||
},
|
||||
"runtimeChunk": {
|
||||
"type": "boolean",
|
||||
"description": "Use a separate bundle containing the runtime.",
|
||||
"default": true
|
||||
},
|
||||
"sourceMap": {
|
||||
"description": "Output sourcemaps. Use 'hidden' for use with error reporting tools without generating sourcemap comment.",
|
||||
"default": true,
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"progress": {
|
||||
"type": "boolean",
|
||||
"description": "Log progress to the console while building.",
|
||||
"default": false
|
||||
},
|
||||
"assets": {
|
||||
"type": "array",
|
||||
"description": "List of static application assets.",
|
||||
"default": [],
|
||||
"items": {
|
||||
"$ref": "#/definitions/assetPattern"
|
||||
}
|
||||
},
|
||||
"index": {
|
||||
"type": "string",
|
||||
"description": "HTML File which will be contain the application."
|
||||
},
|
||||
"scripts": {
|
||||
"type": "array",
|
||||
"description": "External Scripts which will be included before the main application entry.",
|
||||
"items": {
|
||||
"$ref": "#/definitions/extraEntryPoint"
|
||||
},
|
||||
"default": []
|
||||
},
|
||||
"styles": {
|
||||
"type": "array",
|
||||
"description": "External Styles which will be included with the application",
|
||||
"items": {
|
||||
"$ref": "#/definitions/extraEntryPoint"
|
||||
},
|
||||
"default": []
|
||||
},
|
||||
"budgets": {
|
||||
"description": "Budget thresholds to ensure parts of your application stay within boundaries which you set.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/budget"
|
||||
},
|
||||
"default": []
|
||||
},
|
||||
"namedChunks": {
|
||||
"type": "boolean",
|
||||
"description": "Names the produced bundles according to their entry file.",
|
||||
"default": true
|
||||
},
|
||||
"outputHashing": {
|
||||
"type": "string",
|
||||
"description": "Define the output filename cache-busting hashing mode.",
|
||||
"default": "none",
|
||||
"enum": ["none", "all", "media", "bundles"]
|
||||
},
|
||||
"stylePreprocessorOptions": {
|
||||
"description": "Options to pass to style preprocessors.",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"includePaths": {
|
||||
"description": "Paths to include. Paths will be resolved to project root.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"default": []
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"optimization": {
|
||||
"description": "Enables optimization of the build output.",
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"scripts": {
|
||||
"type": "boolean",
|
||||
"description": "Enables optimization of the scripts output.",
|
||||
"default": true
|
||||
},
|
||||
"styles": {
|
||||
"type": "boolean",
|
||||
"description": "Enables optimization of the styles output.",
|
||||
"default": true
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
{
|
||||
"type": "boolean"
|
||||
}
|
||||
]
|
||||
},
|
||||
"extractCss": {
|
||||
"type": "boolean",
|
||||
"description": "Extract CSS into a `.css` file.",
|
||||
"default": false
|
||||
},
|
||||
"es2015Polyfills": {
|
||||
"description": "Conditional polyfills loaded in browsers which do not support `ES2015`.",
|
||||
"type": "string"
|
||||
},
|
||||
"subresourceIntegrity": {
|
||||
"type": "boolean",
|
||||
"description": "Enables the use of subresource integrity validation.",
|
||||
"default": false
|
||||
},
|
||||
"polyfills": {
|
||||
"type": "string",
|
||||
"description": "Polyfills to load before application"
|
||||
},
|
||||
"verbose": {
|
||||
"type": "boolean",
|
||||
"description": "Emits verbose output",
|
||||
"default": false
|
||||
},
|
||||
"statsJson": {
|
||||
"type": "boolean",
|
||||
"description": "Generates a 'stats.json' file which can be analyzed using tools such as: 'webpack-bundle-analyzer' or `<https://webpack.github.io/analyse>`.",
|
||||
"default": false
|
||||
},
|
||||
"extractLicenses": {
|
||||
"type": "boolean",
|
||||
"description": "Extract all licenses in a separate file, in the case of production builds only.",
|
||||
"default": false
|
||||
},
|
||||
"memoryLimit": {
|
||||
"type": "number",
|
||||
"description": "Memory limit for type checking service process in `MB`.",
|
||||
"default": 2048
|
||||
},
|
||||
"maxWorkers": {
|
||||
"type": "number",
|
||||
"description": "Number of workers to use for type checking.",
|
||||
"default": 2
|
||||
},
|
||||
"fileReplacements": {
|
||||
"description": "Replace files with other files in the build.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"replace": {
|
||||
"type": "string",
|
||||
"description": "The file to be replaced."
|
||||
},
|
||||
"with": {
|
||||
"type": "string",
|
||||
"description": "The file to replace with."
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["replace", "with"]
|
||||
},
|
||||
"default": []
|
||||
},
|
||||
"buildLibsFromSource": {
|
||||
"type": "boolean",
|
||||
"description": "Read buildable libraries from source instead of building them separately.",
|
||||
"default": true
|
||||
},
|
||||
"generateIndexHtml": {
|
||||
"type": "boolean",
|
||||
"description": "Generates `index.html` file to the output path. This can be turned off if using a webpack plugin to generate HTML such as `html-webpack-plugin`.",
|
||||
"default": true
|
||||
},
|
||||
"postcssConfig": {
|
||||
"type": "string",
|
||||
"description": "Set a path to PostCSS config that applies to the app and all libs. Defaults to `undefined`, which auto-detects postcss.config.js files in each `app`/`lib` directory."
|
||||
},
|
||||
"webpackConfig": {
|
||||
"type": "string",
|
||||
"description": "Path to a function which takes a webpack config, some context and returns the resulting webpack config. See https://nx.dev/guides/customize-webpack"
|
||||
}
|
||||
},
|
||||
"required": ["tsConfig", "main", "index"],
|
||||
"definitions": {
|
||||
"assetPattern": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"glob": {
|
||||
"type": "string",
|
||||
"description": "The pattern to match."
|
||||
},
|
||||
"input": {
|
||||
"type": "string",
|
||||
"description": "The input directory path in which to apply 'glob'. Defaults to the project root."
|
||||
},
|
||||
"ignore": {
|
||||
"description": "An array of globs to ignore.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"output": {
|
||||
"type": "string",
|
||||
"description": "Absolute path within the output."
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["glob", "input", "output"]
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"budget": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"description": "The type of budget.",
|
||||
"enum": ["all", "allScript", "any", "anyScript", "bundle", "initial"]
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "The name of the bundle."
|
||||
},
|
||||
"baseline": {
|
||||
"type": "string",
|
||||
"description": "The baseline size for comparison."
|
||||
},
|
||||
"maximumWarning": {
|
||||
"type": "string",
|
||||
"description": "The maximum threshold for warning relative to the baseline."
|
||||
},
|
||||
"maximumError": {
|
||||
"type": "string",
|
||||
"description": "The maximum threshold for error relative to the baseline."
|
||||
},
|
||||
"minimumWarning": {
|
||||
"type": "string",
|
||||
"description": "The minimum threshold for warning relative to the baseline."
|
||||
},
|
||||
"minimumError": {
|
||||
"type": "string",
|
||||
"description": "The minimum threshold for error relative to the baseline."
|
||||
},
|
||||
"warning": {
|
||||
"type": "string",
|
||||
"description": "The threshold for warning relative to the baseline (min & max)."
|
||||
},
|
||||
"error": {
|
||||
"type": "string",
|
||||
"description": "The threshold for error relative to the baseline (min & max)."
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["type"]
|
||||
},
|
||||
"extraEntryPoint": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"input": {
|
||||
"type": "string",
|
||||
"description": "The file to include."
|
||||
},
|
||||
"bundleName": {
|
||||
"type": "string",
|
||||
"description": "The bundle name for this extra entry point."
|
||||
},
|
||||
"inject": {
|
||||
"type": "boolean",
|
||||
"description": "If the bundle will be referenced in the HTML file.",
|
||||
"default": true
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["input"]
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "The file to include."
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
14
tools/executors/webpack/executor.json
Normal file
14
tools/executors/webpack/executor.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"executors": {
|
||||
"serve": {
|
||||
"implementation": "./serve/impl",
|
||||
"schema": "./serve/schema.json",
|
||||
"description": "Starts a dev-server with an optional explicit environment."
|
||||
},
|
||||
"build": {
|
||||
"implementation": "./build/impl",
|
||||
"schema": "./build/schema.json",
|
||||
"description": "Starts a dev-server with an optional explicit environment."
|
||||
}
|
||||
}
|
||||
}
|
3
tools/executors/webpack/package.json
Normal file
3
tools/executors/webpack/package.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"executors": "./executor.json"
|
||||
}
|
19
tools/executors/webpack/serve/impl.ts
Normal file
19
tools/executors/webpack/serve/impl.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import type { ExecutorContext } from '@nrwl/devkit';
|
||||
import setup from '../../../utils/setup-environment';
|
||||
import devServerExecutor, {
|
||||
WebDevServerOptions,
|
||||
} from '@nrwl/web/src/executors/dev-server/dev-server.impl';
|
||||
|
||||
type Schema = WebDevServerOptions & {
|
||||
env?: string;
|
||||
};
|
||||
|
||||
export default async function* serve(
|
||||
options: Schema,
|
||||
context: ExecutorContext
|
||||
): ReturnType<typeof devServerExecutor> {
|
||||
const { env, ...serverOptions } = options;
|
||||
await setup(env, context, 'tools/executors/webpack/serve');
|
||||
|
||||
return yield* devServerExecutor(serverOptions, context);
|
||||
}
|
13
tools/executors/webpack/tsconfig.json
Normal file
13
tools/executors/webpack/tsconfig.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"types": ["node"],
|
||||
"importHelpers": false,
|
||||
"sourceMap": false,
|
||||
"inlineSourceMap": true
|
||||
},
|
||||
"include": ["build/impl.ts", "serve/impl.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
@ -1,28 +1,33 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as dotenv from 'dotenv';
|
||||
import { execSync } from 'child_process';
|
||||
import * as log from 'npmlog';
|
||||
import * as dotenv from 'dotenv';
|
||||
import type { ExecutorContext } from '@nrwl/devkit';
|
||||
import devServerExecutor, {
|
||||
WebDevServerOptions,
|
||||
} from '@nrwl/web/src/executors/dev-server/dev-server.impl';
|
||||
|
||||
type Schema = WebDevServerOptions & {
|
||||
env?: string;
|
||||
};
|
||||
|
||||
const LOGGER_SCOPE = 'tools/executors/serve';
|
||||
process.env['NX_GIT_COMMIT_HASH'] = execSync('git rev-parse HEAD')
|
||||
.toString()
|
||||
.replace(/[\r\n]/gm, '');
|
||||
process.env['NX_GIT_BRANCH'] = execSync('git rev-parse --abbrev-ref HEAD')
|
||||
.toString()
|
||||
.replace(/[\r\n]/gm, '');
|
||||
process.env['NX_GIT_ORIGIN_URL'] = execSync('git remote get-url origin')
|
||||
.toString()
|
||||
.replace('ssh://git@', 'https://')
|
||||
.replace('.git', '')
|
||||
.replace(/[\r\n]/gm, '');
|
||||
|
||||
const logEnvData = (
|
||||
envMap: Record<string, string>,
|
||||
envFiles: string[],
|
||||
env?: string,
|
||||
defaultEnvFile?: string
|
||||
defaultEnvFile?: string,
|
||||
loggerScope?: string
|
||||
) => {
|
||||
if (env && !envMap[env]) {
|
||||
log.warn(LOGGER_SCOPE, `No environment called "${env}" found.`);
|
||||
log.warn(loggerScope, `No environment called "${env}" found.`);
|
||||
log.info(
|
||||
LOGGER_SCOPE,
|
||||
loggerScope,
|
||||
envFiles.length > 0
|
||||
? `You can create a new environment by putting an ".env.${env}" file in your project root, or you can use the following available ones: ${envFiles.join(
|
||||
', '
|
||||
@ -33,14 +38,14 @@ const logEnvData = (
|
||||
|
||||
if (!envMap[env]) {
|
||||
log.info(
|
||||
LOGGER_SCOPE,
|
||||
loggerScope,
|
||||
defaultEnvFile
|
||||
? `Using "${defaultEnvFile}" as the default project environment.`
|
||||
: 'Serving the project only using the environment variables scoped to your CLI.'
|
||||
);
|
||||
} else {
|
||||
log.info(
|
||||
LOGGER_SCOPE,
|
||||
loggerScope,
|
||||
`Using "${envMap[env]}" as the default project environment.`
|
||||
);
|
||||
}
|
||||
@ -52,7 +57,7 @@ const getDefaultEnvFile = (envMap: Record<string, string>) => {
|
||||
return envMap['local'] || envMap['.env'];
|
||||
};
|
||||
|
||||
const getEnvFile = (env: string, envFiles: string[]) => {
|
||||
const getEnvFile = (env: string, envFiles: string[], loggerScope?: string) => {
|
||||
const envMap = envFiles.reduce(
|
||||
(acc, filename) => ({
|
||||
...acc,
|
||||
@ -62,28 +67,28 @@ const getEnvFile = (env: string, envFiles: string[]) => {
|
||||
);
|
||||
|
||||
const defaultEnvFile = getDefaultEnvFile(envMap);
|
||||
logEnvData(envMap, envFiles, env, defaultEnvFile);
|
||||
logEnvData(envMap, envFiles, env, defaultEnvFile, loggerScope);
|
||||
|
||||
return envMap[env] || defaultEnvFile;
|
||||
};
|
||||
|
||||
export default async function* serve(
|
||||
options: Schema,
|
||||
context: ExecutorContext
|
||||
): ReturnType<typeof devServerExecutor> {
|
||||
const { env, ...dsOptions } = options;
|
||||
export default async function setup(
|
||||
env: string,
|
||||
context: ExecutorContext,
|
||||
loggerScope?: string
|
||||
) {
|
||||
const { root } = context.workspace.projects[context.projectName];
|
||||
const workspacePath = path.join(context.cwd, root);
|
||||
|
||||
const files = await fs.promises.readdir(workspacePath);
|
||||
|
||||
const envFile = getEnvFile(
|
||||
env,
|
||||
files.filter((f) => f.startsWith('.env'))
|
||||
files.filter((f) => f.startsWith('.env')),
|
||||
loggerScope
|
||||
);
|
||||
|
||||
if (env && envFile) {
|
||||
dotenv.config({ path: path.join(workspacePath, envFile), override: true });
|
||||
}
|
||||
|
||||
return yield* devServerExecutor(dsOptions, context);
|
||||
}
|
@ -25,6 +25,7 @@
|
||||
"@vegaprotocol/fills": ["libs/fills/src/index.ts"],
|
||||
"@vegaprotocol/market-depth": ["libs/market-depth/src/index.ts"],
|
||||
"@vegaprotocol/market-list": ["libs/market-list/src/index.ts"],
|
||||
"@vegaprotocol/network-info": ["libs/network-info/src/index.ts"],
|
||||
"@vegaprotocol/network-stats": ["libs/network-stats/src/index.ts"],
|
||||
"@vegaprotocol/order-list": ["libs/order-list/src/index.ts"],
|
||||
"@vegaprotocol/positions": ["libs/positions/src/index.ts"],
|
||||
|
@ -12,6 +12,7 @@
|
||||
"fills": "libs/fills",
|
||||
"market-depth": "libs/market-depth",
|
||||
"market-list": "libs/market-list",
|
||||
"network-info": "libs/network-info",
|
||||
"network-stats": "libs/network-stats",
|
||||
"order-list": "libs/order-list",
|
||||
"positions": "libs/positions",
|
||||
|
Loading…
Reference in New Issue
Block a user