From a7d1a2121d4fa3220ca2b7e89918476943a75949 Mon Sep 17 00:00:00 2001 From: Tobias Schmidt Date: Tue, 25 Feb 2020 11:16:35 +0100 Subject: [PATCH 01/10] update run target for production deploy --- package.json | 5 +++-- packages/frontend/package.json | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 4c01a52..f96660e 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,9 @@ "lint": "eslint './packages/*/src/**/*.{ts,d.ts}' --max-warnings 0", "lint:fix": "eslint './packages/*/src/**/*.{ts,d.ts}' --fix", "build": "tsc -b && lerna run webpack:build --stream", - "start": "lerna run production:start --stream", - "frontend:watch": "lerna run frontend:watch --stream" + "frontend:start": "lerna run frontend:start --stream", + "frontend:watch": "lerna run frontend:watch --stream", + "watch": "tsc -b -w" }, "devDependencies": { "@hot-loader/react-dom": "^16.11.0", diff --git a/packages/frontend/package.json b/packages/frontend/package.json index 1eff0d9..1662d4c 100644 --- a/packages/frontend/package.json +++ b/packages/frontend/package.json @@ -7,8 +7,9 @@ }, "scripts": { "frontend:watch": "webpack-dev-server --mode development --color --hot --progress", + "frontend:start": "webpack-dev-server --mode production --color --progress", "webpack:build": "webpack --mode production", - "clean": "rm -rf dist/" + "clean": "rm -rf dist/ node_modules/ tsconfig.tsbuildinfo" }, "devDependencies": { "@types/react": "^16.9.11", From b5f62e4f7ff7214b04e0967058fc16a330994bca Mon Sep 17 00:00:00 2001 From: Tobias Schmidt Date: Tue, 25 Feb 2020 11:17:07 +0100 Subject: [PATCH 02/10] remove unused dependency from frontend --- packages/frontend/package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/frontend/package.json b/packages/frontend/package.json index 1662d4c..6ea7649 100644 --- a/packages/frontend/package.json +++ b/packages/frontend/package.json @@ -16,8 +16,7 @@ "@types/react-dom": "^16.9.4", "@types/react-router": "^5.1.3", "@types/react-router-dom": "^5.1.3", - "elite-types": "^1.0.0", - "replace": "^1.1.3" + "elite-types": "^1.0.0" }, "dependencies": { "@material-ui/core": "^4.9.3", From e797fa23bb52b5544482e8b54ec871dd2e13d18c Mon Sep 17 00:00:00 2001 From: Tobias Schmidt Date: Tue, 25 Feb 2020 11:17:45 +0100 Subject: [PATCH 03/10] add initial configuration type --- packages/types/src/config/configuration.type.ts | 5 +++++ packages/types/src/config/featureMap.type.ts | 1 + packages/types/src/config/index.ts | 2 ++ packages/types/src/index.ts | 1 + 4 files changed, 9 insertions(+) create mode 100644 packages/types/src/config/configuration.type.ts create mode 100644 packages/types/src/config/featureMap.type.ts create mode 100644 packages/types/src/config/index.ts diff --git a/packages/types/src/config/configuration.type.ts b/packages/types/src/config/configuration.type.ts new file mode 100644 index 0000000..115743e --- /dev/null +++ b/packages/types/src/config/configuration.type.ts @@ -0,0 +1,5 @@ +import { FeatureMap } from './featureMap.type'; + +export type Configuration = { + featureMap: FeatureMap; +}; diff --git a/packages/types/src/config/featureMap.type.ts b/packages/types/src/config/featureMap.type.ts new file mode 100644 index 0000000..2715c8c --- /dev/null +++ b/packages/types/src/config/featureMap.type.ts @@ -0,0 +1 @@ +export type FeatureMap = { [key: string]: boolean }; diff --git a/packages/types/src/config/index.ts b/packages/types/src/config/index.ts new file mode 100644 index 0000000..0cd8795 --- /dev/null +++ b/packages/types/src/config/index.ts @@ -0,0 +1,2 @@ +export * from './configuration.type'; +export * from './featureMap.type'; diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index e69de29..f03c228 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -0,0 +1 @@ +export * from './config'; From f40047b87b0d59a92279c99f92be61458ba34ccd Mon Sep 17 00:00:00 2001 From: Tobias Schmidt Date: Tue, 25 Feb 2020 11:19:18 +0100 Subject: [PATCH 04/10] add package for configuration management --- packages/configuration/package.json | 16 ++++++++++++++++ packages/configuration/tsconfig.json | 14 ++++++++++++++ tsconfig.json | 3 +++ 3 files changed, 33 insertions(+) create mode 100644 packages/configuration/package.json create mode 100644 packages/configuration/tsconfig.json diff --git a/packages/configuration/package.json b/packages/configuration/package.json new file mode 100644 index 0000000..dafe845 --- /dev/null +++ b/packages/configuration/package.json @@ -0,0 +1,16 @@ +{ + "name": "elite-configuration", + "version": "1.0.0", + "private": true, + "publishConfig": { + "access": "public" + }, + "types": "dist/index.d.ts", + "main": "dist/index.js", + "scripts": { + "clean": "rm -rf dist/ node_modules/ tsconfig.tsbuildinfo" + }, + "devDependencies": { + "elite-types": "^1.0.0" + } +} diff --git a/packages/configuration/tsconfig.json b/packages/configuration/tsconfig.json new file mode 100644 index 0000000..ccfc6c0 --- /dev/null +++ b/packages/configuration/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "dist", + "baseUrl": "src" + }, + "include": ["src/**/*"], + "references": [ + { + "path": "../types" + } + ] +} diff --git a/tsconfig.json b/tsconfig.json index 7aef651..5540f20 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,6 +4,9 @@ { "path": "./packages/types" }, + { + "path": "./packages/configuration" + }, { "path": "./packages/frontend" } From 6c8c77de37c7c6f4237b1379514019b6b7487cec Mon Sep 17 00:00:00 2001 From: Tobias Schmidt Date: Tue, 25 Feb 2020 11:21:04 +0100 Subject: [PATCH 05/10] add logic for loading configuration files and add example production and development configuration using symlinks --- development.configuration.ts | 9 +++++++++ packages/configuration/src/development.configuration.ts | 1 + packages/configuration/src/index.ts | 7 +++++++ packages/configuration/src/production.configuration.ts | 1 + production.configuration.ts | 9 +++++++++ 5 files changed, 27 insertions(+) create mode 100644 development.configuration.ts create mode 120000 packages/configuration/src/development.configuration.ts create mode 100644 packages/configuration/src/index.ts create mode 120000 packages/configuration/src/production.configuration.ts create mode 100644 production.configuration.ts diff --git a/development.configuration.ts b/development.configuration.ts new file mode 100644 index 0000000..eeeb40b --- /dev/null +++ b/development.configuration.ts @@ -0,0 +1,9 @@ +import { Configuration } from 'elite-types'; + +const configuration: Configuration = { + featureMap: { + 'under-construction-message': true, + }, +}; + +export default configuration; diff --git a/packages/configuration/src/development.configuration.ts b/packages/configuration/src/development.configuration.ts new file mode 120000 index 0000000..5d97350 --- /dev/null +++ b/packages/configuration/src/development.configuration.ts @@ -0,0 +1 @@ +../../../development.configuration.ts \ No newline at end of file diff --git a/packages/configuration/src/index.ts b/packages/configuration/src/index.ts new file mode 100644 index 0000000..5a361e8 --- /dev/null +++ b/packages/configuration/src/index.ts @@ -0,0 +1,7 @@ +import devConfig from './development.configuration'; +import prodConfig from './production.configuration'; +import { Configuration } from 'elite-types'; + +export function getConfiguration(): Configuration { + return process.env.NODE_ENV === 'development' ? devConfig : prodConfig; +} diff --git a/packages/configuration/src/production.configuration.ts b/packages/configuration/src/production.configuration.ts new file mode 120000 index 0000000..d31b870 --- /dev/null +++ b/packages/configuration/src/production.configuration.ts @@ -0,0 +1 @@ +../../../production.configuration.ts \ No newline at end of file diff --git a/production.configuration.ts b/production.configuration.ts new file mode 100644 index 0000000..a21f371 --- /dev/null +++ b/production.configuration.ts @@ -0,0 +1,9 @@ +import { Configuration } from 'elite-types'; + +const configuration: Configuration = { + featureMap: { + 'under-construction-message': false, + }, +}; + +export default configuration; From 840e8f0d25b1b342b883df675fafeabc3977f4fc Mon Sep 17 00:00:00 2001 From: Tobias Schmidt Date: Tue, 25 Feb 2020 11:22:39 +0100 Subject: [PATCH 06/10] add package for a react feature flag component --- packages/feature-flags/package.json | 20 ++++++++++++++++++++ packages/feature-flags/tsconfig.json | 14 ++++++++++++++ tsconfig.json | 3 +++ 3 files changed, 37 insertions(+) create mode 100644 packages/feature-flags/package.json create mode 100644 packages/feature-flags/tsconfig.json diff --git a/packages/feature-flags/package.json b/packages/feature-flags/package.json new file mode 100644 index 0000000..209bd94 --- /dev/null +++ b/packages/feature-flags/package.json @@ -0,0 +1,20 @@ +{ + "name": "elite-feature-flags", + "version": "1.0.0", + "private": true, + "publishConfig": { + "access": "public" + }, + "types": "dist/index.d.ts", + "main": "dist/index.js", + "scripts": { + "clean": "rm -rf dist/ node_modules/ tsconfig.tsbuildinfo" + }, + "devDependencies": { + "@types/react": "^16.9.11", + "elite-types": "^1.0.0" + }, + "dependencies": { + "react": "^16.12.0" + } +} diff --git a/packages/feature-flags/tsconfig.json b/packages/feature-flags/tsconfig.json new file mode 100644 index 0000000..ccfc6c0 --- /dev/null +++ b/packages/feature-flags/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "dist", + "baseUrl": "src" + }, + "include": ["src/**/*"], + "references": [ + { + "path": "../types" + } + ] +} diff --git a/tsconfig.json b/tsconfig.json index 5540f20..740cc9b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,9 @@ { "path": "./packages/configuration" }, + { + "path": "./packages/feature-flags" + }, { "path": "./packages/frontend" } From edb07dbe39e0a5b2e1fbb3f61d4fe8888016a992 Mon Sep 17 00:00:00 2001 From: Tobias Schmidt Date: Tue, 25 Feb 2020 11:23:15 +0100 Subject: [PATCH 07/10] implement the feature flag component --- .../src/components/featureFlag.component.tsx | 29 +++++++++++++++++++ packages/feature-flags/src/index.ts | 1 + 2 files changed, 30 insertions(+) create mode 100644 packages/feature-flags/src/components/featureFlag.component.tsx create mode 100644 packages/feature-flags/src/index.ts diff --git a/packages/feature-flags/src/components/featureFlag.component.tsx b/packages/feature-flags/src/components/featureFlag.component.tsx new file mode 100644 index 0000000..d382a45 --- /dev/null +++ b/packages/feature-flags/src/components/featureFlag.component.tsx @@ -0,0 +1,29 @@ +import React, { PureComponent, createContext, Context } from 'react'; +import { FeatureMap } from 'elite-types'; + +const FeatureFlags: Context = createContext({}); + +export interface FeatureToggleProperties { + readonly inverted?: boolean; + readonly featureName: string; +} + +export class FeatureFlag extends PureComponent { + render() { + const { children, inverted, featureName } = this.props; + + return ( + + {(featureMap: FeatureMap) => { + if ((featureMap[featureName] && !inverted) || (!featureMap[featureName] && inverted)) { + return children; + } else { + return null; + } + }} + + ); + } +} + +export const FeatureFlagsProvider = FeatureFlags.Provider; diff --git a/packages/feature-flags/src/index.ts b/packages/feature-flags/src/index.ts new file mode 100644 index 0000000..8f6db98 --- /dev/null +++ b/packages/feature-flags/src/index.ts @@ -0,0 +1 @@ +export * from './components/featureFlag.component'; From 8aa477a79440f7b6d2b72c11d4903d48628fb7f0 Mon Sep 17 00:00:00 2001 From: Tobias Schmidt Date: Tue, 25 Feb 2020 11:24:34 +0100 Subject: [PATCH 08/10] use the configuration and feature flag package in frontend --- packages/frontend/package.json | 4 +++- packages/frontend/src/components/App.tsx | 23 ++++++++++++++++------- packages/frontend/tsconfig.json | 6 ++++++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/packages/frontend/package.json b/packages/frontend/package.json index 6ea7649..5468a6f 100644 --- a/packages/frontend/package.json +++ b/packages/frontend/package.json @@ -24,6 +24,8 @@ "react": "^16.12.0", "react-dom": "^16.12.0", "react-router": "^5.1.2", - "react-router-dom": "^5.1.2" + "react-router-dom": "^5.1.2", + "elite-feature-flags": "^1.0.0", + "elite-configuration": "^1.0.0" } } diff --git a/packages/frontend/src/components/App.tsx b/packages/frontend/src/components/App.tsx index 7d6ff6f..67f2538 100644 --- a/packages/frontend/src/components/App.tsx +++ b/packages/frontend/src/components/App.tsx @@ -4,14 +4,23 @@ import { Route, Switch } from 'react-router'; import { Router } from 'react-router-dom'; import { APP_ROUTES, ERROR_404_PAGE } from '../util/approutes'; import history from '../util/history'; +import { FeatureFlagsProvider } from 'elite-feature-flags'; +import { Configuration } from 'elite-types'; +import { getConfiguration } from 'elite-configuration'; + +const configuration: Configuration = getConfiguration(); export const AppComponent = () => ( - - - {APP_ROUTES.map((routeProps, index) => )} - - - + + + + {APP_ROUTES.map((routeProps, index) => ( + + ))} + + + + ); -export const App = hot(module)(AppComponent); \ No newline at end of file +export const App = hot(module)(AppComponent); diff --git a/packages/frontend/tsconfig.json b/packages/frontend/tsconfig.json index ccfc6c0..c4af582 100644 --- a/packages/frontend/tsconfig.json +++ b/packages/frontend/tsconfig.json @@ -7,6 +7,12 @@ }, "include": ["src/**/*"], "references": [ + { + "path": "../configuration" + }, + { + "path": "../feature-flags" + }, { "path": "../types" } From 45706a81b258053bd3167a2f9f1ab30934f77769 Mon Sep 17 00:00:00 2001 From: Tobias Schmidt Date: Tue, 25 Feb 2020 11:52:27 +0100 Subject: [PATCH 09/10] use feature flag component for under construction text --- packages/frontend/src/components/pages/HomePage.tsx | 5 ++++- packages/frontend/src/index.tsx | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/frontend/src/components/pages/HomePage.tsx b/packages/frontend/src/components/pages/HomePage.tsx index aecebc9..f3e3656 100644 --- a/packages/frontend/src/components/pages/HomePage.tsx +++ b/packages/frontend/src/components/pages/HomePage.tsx @@ -2,13 +2,16 @@ import * as React from 'react'; import { RouteComponentProps } from 'react-router'; import { LinkDirectory } from './support/LinkDirectory'; import { Divider } from '@material-ui/core'; +import { FeatureFlag } from 'elite-feature-flags'; export interface HomePageProps extends RouteComponentProps {} export const HomePage = (props: HomePageProps) => ( <>

Main Page

- Elite Sexyz is currently under construction. See discord main channel for more information + + Elite Sexyz is currently under construction. See discord main channel for more information + diff --git a/packages/frontend/src/index.tsx b/packages/frontend/src/index.tsx index 3be5b1a..ad3bc8b 100644 --- a/packages/frontend/src/index.tsx +++ b/packages/frontend/src/index.tsx @@ -2,4 +2,4 @@ import * as React from 'react'; import * as ReactDOM from 'react-dom'; import { App } from './components/App'; -ReactDOM.render(, document.getElementById('root')); \ No newline at end of file +ReactDOM.render(, document.getElementById('root')); From 868230f45ad19c4684a1ee95327e7cb22830028b Mon Sep 17 00:00:00 2001 From: Tobias Schmidt Date: Tue, 25 Feb 2020 11:53:36 +0100 Subject: [PATCH 10/10] update yarn lock --- yarn.lock | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/yarn.lock b/yarn.lock index 3d0dd5c..5ce0359 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5546,7 +5546,7 @@ minimalistic-crypto-utils@^1.0.0, minimalistic-crypto-utils@^1.0.1: resolved "https://registry.yarnpkg.com/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz#f6c00c1c0b082246e5c4d99dfb8c7c083b2b582a" integrity sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo= -minimatch@3.0.4, minimatch@^3.0.4: +minimatch@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA== @@ -7094,15 +7094,6 @@ repeating@^2.0.0: dependencies: is-finite "^1.0.0" -replace@^1.1.3: - version "1.1.5" - resolved "https://registry.yarnpkg.com/replace/-/replace-1.1.5.tgz#adac4e0cd111b57da568393cba03f3ef8fac7f96" - integrity sha512-Mww6GyTix4GqN1GSbJDkUzftkjQE0xfzzlGkFF26ukm8DBzgwGPFntvmVsvAKJogwSSMjvAoZei7fJ2tfiKMcA== - dependencies: - chalk "2.4.2" - minimatch "3.0.4" - yargs "^12.0.5" - request@^2.88.0: version "2.88.2" resolved "https://registry.yarnpkg.com/request/-/request-2.88.2.tgz#d73c918731cb5a87da047e207234146f664d12b3" @@ -8851,7 +8842,7 @@ yargs-parser@^15.0.0: camelcase "^5.0.0" decamelize "^1.2.0" -yargs@12.0.5, yargs@^12.0.5: +yargs@12.0.5: version "12.0.5" resolved "https://registry.yarnpkg.com/yargs/-/yargs-12.0.5.tgz#05f5997b609647b64f66b81e3b4b10a368e7ad13" integrity sha512-Lhz8TLaYnxq/2ObqHDql8dX8CJi97oHxrjUcYtzKbbykPtVW9WB+poxI+NM2UIzsMgNCZTIf0AQwsjK5yMAqZw==