@equinor/echo-cli 1.0.0-beta-1 → 1.0.0-beta-3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/echo-dev-host/.env +29 -0
  2. package/echo-dev-host/.vscode/settings.json +5 -0
  3. package/{lib/echo-client → echo-dev-host}/README.md +7 -5
  4. package/echo-dev-host/env.sh +51 -0
  5. package/{lib/echo-client → echo-dev-host}/package-lock.json +2 -2
  6. package/{lib/echo-client → echo-dev-host}/src/app.tsx +1 -1
  7. package/{lib/echo-client → echo-dev-host}/src/index.tsx +1 -1
  8. package/{lib/echo-client → echo-dev-host}/webpack.config.js +4 -4
  9. package/lib/{echo-build-client.d.ts → echo-build-dev-host.d.ts} +1 -1
  10. package/lib/echo-build-dev-host.js +35 -0
  11. package/lib/echo-build-dev-host.js.map +1 -0
  12. package/lib/echo-dev-host/.env +29 -0
  13. package/lib/echo-dev-host/README.md +46 -0
  14. package/lib/echo-dev-host/babel.config.js +11 -0
  15. package/lib/echo-dev-host/env.sh +51 -0
  16. package/lib/echo-dev-host/jest.config.js +21 -0
  17. package/lib/echo-dev-host/package-lock.json +12457 -0
  18. package/lib/echo-dev-host/package.json +80 -0
  19. package/lib/echo-dev-host/public/env-config.js +17 -0
  20. package/{client → lib/echo-dev-host/public}/index.html +1 -1
  21. package/lib/echo-dev-host/src/api/api-plants.ts +22 -0
  22. package/lib/echo-dev-host/src/app.css +12 -0
  23. package/lib/echo-dev-host/src/app.tsx +43 -0
  24. package/lib/echo-dev-host/src/components/Home/Home.tsx +23 -0
  25. package/lib/echo-dev-host/src/components/Home/home.module.css +38 -0
  26. package/lib/echo-dev-host/src/components/legend.tsx +3 -0
  27. package/lib/echo-dev-host/src/index.tsx +90 -0
  28. package/lib/echo-dev-host/src/setupTests.ts +25 -0
  29. package/lib/echo-dev-host/src/utils/plants.test.ts +33 -0
  30. package/lib/echo-dev-host/src/utils/plants.ts +12 -0
  31. package/lib/echo-dev-host/src/utils/setupSkipAuth.ts +43 -0
  32. package/lib/echo-dev-host/tsconfig.json +21 -0
  33. package/lib/echo-dev-host/webpack.config.js +138 -0
  34. package/package.json +4 -4
  35. package/client/env-config.js +0 -1
  36. package/client/main.echo.bundle.js +0 -3
  37. package/client/main.echo.bundle.js.LICENSE.txt +0 -133
  38. package/client/main.echo.bundle.js.map +0 -1
  39. package/client/vendors-node_modules_babel_polyfill_lib_index_js-node_modules_react-dom_client_js-node_module-5b8715.echo.bundle.js +0 -3
  40. package/client/vendors-node_modules_babel_polyfill_lib_index_js-node_modules_react-dom_client_js-node_module-5b8715.echo.bundle.js.LICENSE.txt +0 -8453
  41. package/client/vendors-node_modules_babel_polyfill_lib_index_js-node_modules_react-dom_client_js-node_module-5b8715.echo.bundle.js.map +0 -1
  42. package/lib/echo-build-client.js +0 -37
  43. package/lib/echo-build-client.js.map +0 -1
  44. package/lib/echo-client/.links.json +0 -3
  45. package/lib/echo-client/build/env-config.js +0 -1
  46. package/lib/echo-client/public/echoModuleManifest.json +0 -30
  47. package/lib/echo-client/public/index.css +0 -60
  48. package/lib/echo-client/public/module-bundle-demo1.js +0 -250
  49. package/lib/echo-client/public/module-bundle-demo2.js +0 -251
  50. package/lib/echo-client/public/module-bundle-demo3.js +0 -251
  51. /package/{lib/echo-client → echo-dev-host}/babel.config.js +0 -0
  52. /package/{lib/echo-client → echo-dev-host}/jest.config.js +0 -0
  53. /package/{lib/echo-client → echo-dev-host}/package.json +0 -0
  54. /package/{lib/echo-client → echo-dev-host}/public/env-config.js +0 -0
  55. /package/{client → echo-dev-host/public}/index.css +0 -0
  56. /package/{lib/echo-client → echo-dev-host}/public/index.html +0 -0
  57. /package/{lib/echo-client → echo-dev-host}/src/api/api-plants.ts +0 -0
  58. /package/{lib/echo-client → echo-dev-host}/src/app.css +0 -0
  59. /package/{lib/echo-client → echo-dev-host}/src/components/Home/Home.tsx +0 -0
  60. /package/{lib/echo-client → echo-dev-host}/src/components/Home/home.module.css +0 -0
  61. /package/{lib/echo-client → echo-dev-host}/src/components/legend.tsx +0 -0
  62. /package/{lib/echo-client → echo-dev-host}/src/images/frontpage-brand-placeholder.jpg +0 -0
  63. /package/{lib/echo-client → echo-dev-host}/src/setupTests.ts +0 -0
  64. /package/{lib/echo-client → echo-dev-host}/src/utils/plants.test.ts +0 -0
  65. /package/{lib/echo-client → echo-dev-host}/src/utils/plants.ts +0 -0
  66. /package/{lib/echo-client → echo-dev-host}/src/utils/setupSkipAuth.ts +0 -0
  67. /package/{lib/echo-client → echo-dev-host}/tsconfig.json +0 -0
  68. /package/lib/{echo-client/build → echo-dev-host/public}/index.css +0 -0
  69. /package/{client/d2d97a9feca22f12a8c8c7413d7867ac.jpg → lib/echo-dev-host/src/images/frontpage-brand-placeholder.jpg} +0 -0
@@ -0,0 +1,29 @@
1
+ /* eslint-disable */
2
+
3
+ Never use PROCESS.ENV/process.env use env() instead. (Except for process.env.NODE_ENV)
4
+ ---------------------------------
5
+
6
+ Based on: https://www.freecodecamp.org/news/how-to-implement-runtime-environment-variables-with-create-react-app-docker-and-nginx-7f9d42a91d70/
7
+
8
+ All variables in this files are converted to env() during build, and values here are replaced
9
+ by environment variables if they exists. This is done by running the env.sh bash script before the
10
+ build.
11
+
12
+ env.sh generates env-config.js containing all the variables, which is included in index.html,
13
+ and appended to Window._env_. env() is a shortcut for Window._env_ and should be used in code.
14
+
15
+ NOTE: Seems like window._env_ is not available in a worker
16
+
17
+ */
18
+ WEBSITE_HOSTNAME=localhost:3000;
19
+ REACT_APP_DEFAULT_CACHE_LOCATION=localstorage
20
+ REACT_APP_API_URL=https://dt-echopedia-api-dev.azurewebsites.net
21
+ REACT_APP_WEB_URL=https://dt-echopedia-web-dev.azurewebsites.net
22
+ REACT_APP_WEB_PROD_URL=https://echo.equinor.com
23
+ REACT_APP_AZURE_AD_TENNANT=StatoilSRM.onmicrosoft.com
24
+ REACT_APP_AZURE_AD_TENNANT_ID=3aa4a235-b6e2-48d5-9195-7fcf05b459b0
25
+ REACT_APP_AZURE_AD_CLIENT_ID=751d2504-0b66-4b78-9807-4b60525a14c6
26
+ REACT_APP_API_CLIENT_ID=aef35d97-53d4-4fd0-adaf-c5a514b38436
27
+ REACT_APP_APPINSIGHTS_CONNECTION_STRING=InstrumentationKey=e5299075-a00d-4012-96f9-42861e8d8a9e;IngestionEndpoint=https://northeurope-3.in.applicationinsights.azure.com/;LiveEndpoint=https://northeurope.livediagnostics.monitor.azure.com/;ApplicationId=a9b64222-d4a9-42e6-a615-7428fe1a26af
28
+ REACT_APP_AZURE_BUILD_NUMBER=0.8.dev.9
29
+ REACT_APP_LOGGER_ACTIVE=false
@@ -0,0 +1,5 @@
1
+ {
2
+ "cSpell.words": [
3
+ "equinor"
4
+ ]
5
+ }
@@ -1,6 +1,8 @@
1
- # echo-client
1
+ # echo-dev-host
2
2
 
3
- Lightweight client for Echo Module development, shipped with `echo-cli`
3
+ TODO: update this readme
4
+
5
+ Lightweight host application for Echo Module development, shipped with `echo-cli`
4
6
 
5
7
  ## Why it's needed
6
8
 
@@ -24,9 +26,9 @@ of EchopediaWeb.
24
26
 
25
27
  Development goes as usual:
26
28
 
27
- - change code
28
- - save changes
29
- - hot reload will take care of applying the changes
29
+ - change code
30
+ - save changes
31
+ - hot reload will take care of applying the changes
30
32
 
31
33
  ## Maintaining dependencies
32
34
 
@@ -0,0 +1,51 @@
1
+ #!/bin/bash
2
+
3
+ #https://www.freecodecamp.org/news/how-to-implement-runtime-environment-variables-with-create-react-app-docker-and-nginx-7f9d42a91d70/
4
+ #
5
+
6
+ # Recreate config file
7
+ rm -rf ./env-config.js
8
+ touch ./env-config.js
9
+
10
+ echo "creating env-config.js"
11
+
12
+ # Add assignment
13
+ echo "window._env_ = {" >> ./env-config.js
14
+
15
+ # Read each line in .env file
16
+ # Each line represents key=value pairs
17
+ while read -r line || [[ -n "$line" ]];
18
+ do
19
+ #only process lines containting =
20
+ if [[ $line == *"="* ]]; then
21
+
22
+ # Split env variables by character `=`
23
+ if printf '%s\n' "$line" | grep -q -e '='; then
24
+ varname=$(printf '%s\n' "$line" | sed -e 's/=.*//')
25
+ varvalue=$(printf '%s\n' "$line" | sed -e 's/^[^=]*=//')
26
+ fi
27
+
28
+ # Read value of current variable if exists as Environment variable
29
+ value=$(printf '%s\n' "${!varname}")
30
+ # Otherwise use value from .env file
31
+ [[ -z $value ]] && value=${varvalue}
32
+
33
+ # Append configuration property to JS file
34
+ echo " $varname: \"$value\"," >> ./env-config.js
35
+
36
+ #print variables
37
+ valueObfuscated=$(printf '%s' "$value" | cut -c 1-3)
38
+ #echo " $varname: \"$value\"," #print the environment variables
39
+ echo " $varname=\"$valueObfuscated***\"," #print the environment variables obfuscated
40
+ fi
41
+ done < .env
42
+
43
+ echo "}" >> ./env-config.js
44
+
45
+ #if directory exists, copy to public folder. Needed for dev enironment (npm start)
46
+ if [ -d "public" ]; then
47
+ rm -rf ./public/env-config.js
48
+ cp ./env-config.js ./public/env-config.js
49
+ fi
50
+
51
+ echo "done creating env-config.js"
@@ -1,11 +1,11 @@
1
1
  {
2
- "name": "@equinor/echo-client",
2
+ "name": "@equinor/echo-dev-host",
3
3
  "version": "0.0.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
- "name": "@equinor/echo-client",
8
+ "name": "@equinor/echo-dev-host",
9
9
  "version": "0.0.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
@@ -12,7 +12,7 @@ export const EchoApp: React.FC = () => {
12
12
  useInitial(async () => {
13
13
  await Syncer.configuration.setApiBaseUrl(EchoEnv.env().REACT_APP_API_URL);
14
14
  fireAndForget(getCorePlants, {
15
- userFriendlyErrorMessage: '[echo-client] Failed to load plants data',
15
+ userFriendlyErrorMessage: '[echo-dev-host][app.tsx] Failed to load plants data',
16
16
  displayToast: true
17
17
  });
18
18
  });
@@ -69,7 +69,7 @@ const Echo: React.FC = (): JSX.Element => {
69
69
  Property '#private' in type 'QueryClient' refers to a different member that cannot be accessed from within type 'QueryClient'.
70
70
  Based on my research we used the same version of react-query in echopediaWeb and echo-client.
71
71
  */}
72
- <QueryClientProvider client={queryClient as unknown as QueryClient}>
72
+ <QueryClientProvider client={queryClient}>
73
73
  <EventHubProvider>
74
74
  <Mediator options={moduleOptions} />
75
75
  <BrowserRouter>
@@ -5,14 +5,14 @@ import path from 'path';
5
5
  import WebpackBar from 'webpackbar';
6
6
 
7
7
  const webpackConfig = (env) => {
8
- console.log('Building the client for EchoCli.');
8
+ console.log('Building the dev host application for EchoCli.');
9
9
  return {
10
10
  entry: ['@babel/polyfill', './src/index.tsx'],
11
11
  mode: 'production',
12
12
  devtool: 'source-map',
13
13
  output: {
14
14
  clean: true,
15
- path: path.resolve(process.cwd(), 'client'),
15
+ path: path.resolve(process.cwd(), 'echo-dev-host'),
16
16
  filename: '[name].echo.bundle.js',
17
17
  chunkFilename: 'assets/[name].[contenthash].chunk.js',
18
18
  publicPath: '/'
@@ -117,11 +117,11 @@ const webpackConfig = (env) => {
117
117
  patterns: [
118
118
  {
119
119
  from: path.resolve(import.meta.dirname, './public/index.css'),
120
- to: path.resolve(process.cwd(), 'client', 'index.css')
120
+ to: path.resolve(process.cwd(), 'echo-dev-host', 'index.css')
121
121
  },
122
122
  {
123
123
  from: path.resolve(import.meta.dirname, './public/env-config.js'),
124
- to: path.resolve(process.cwd(), 'client', 'env-config.js')
124
+ to: path.resolve(process.cwd(), 'echo-dev-host', 'env-config.js')
125
125
  }
126
126
  ]
127
127
  })
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command } from '@oclif/command';
3
- export default class BuildClient extends Command {
3
+ export default class BuildDevHost extends Command {
4
4
  static description: string;
5
5
  run(): Promise<void>;
6
6
  }
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from '@oclif/command';
3
+ import { execSync } from 'child_process';
4
+ import fs from 'fs-extra';
5
+ import path from 'path';
6
+ export default class BuildDevHost extends Command {
7
+ static description = 'Build echo-dev-host locally with current echo lib versions';
8
+ async run() {
9
+ // Paths
10
+ const cliNodeModules = path.resolve(process.cwd(), 'node_modules', '@equinor', 'echo-cli');
11
+ const devHostSrc = path.join(cliNodeModules, './lib/echo-dev-host');
12
+ const tmpDevHost = path.resolve(process.cwd(), 'echo-dev-host-tmp');
13
+ const buildOutput = path.join(tmpDevHost, 'echo-dev-host');
14
+ const finalOutput = path.join(cliNodeModules, 'echo-dev-host');
15
+ // 1. Prepare echo-dev-host-tmp
16
+ if (!fs.existsSync(tmpDevHost)) {
17
+ this.log(`echo-dev-host-tmp does not exist. Copying echo-dev-host to ${tmpDevHost}...`);
18
+ fs.copySync(devHostSrc, tmpDevHost);
19
+ }
20
+ else {
21
+ this.log(`echo-dev-host-tmp exists. Reusing it.`);
22
+ }
23
+ // 2. Run npm install and build in temp folder
24
+ this.log('Installing dependencies and building echo-dev-host...');
25
+ execSync('npm install', { cwd: tmpDevHost, stdio: 'inherit' });
26
+ execSync('npm run build', { cwd: tmpDevHost, stdio: 'inherit' });
27
+ // 3. Copy build output back to echo-cli's client folder
28
+ this.log(`Copying build output to ${finalOutput}...`);
29
+ fs.removeSync(finalOutput);
30
+ fs.copySync(buildOutput, finalOutput);
31
+ this.log('echo-dev-host build complete.');
32
+ }
33
+ }
34
+ BuildDevHost.run();
35
+ //# sourceMappingURL=echo-build-dev-host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"echo-build-dev-host.js","sourceRoot":"","sources":["../src/echo-build-dev-host.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,OAAO;IAC7C,MAAM,CAAC,WAAW,GAAG,4DAA4D,CAAC;IAElF,KAAK,CAAC,GAAG;QACL,QAAQ;QACR,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;QAC3F,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,qBAAqB,CAAC,CAAC;QACpE,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,mBAAmB,CAAC,CAAC;QACpE,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;QAC3D,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;QAE/D,+BAA+B;QAC/B,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAC7B,IAAI,CAAC,GAAG,CAAC,8DAA8D,UAAU,KAAK,CAAC,CAAC;YACxF,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;QACxC,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;QACtD,CAAC;QAED,8CAA8C;QAC9C,IAAI,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAC;QAClE,QAAQ,CAAC,aAAa,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;QAC/D,QAAQ,CAAC,eAAe,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;QAEjE,wDAAwD;QACxD,IAAI,CAAC,GAAG,CAAC,2BAA2B,WAAW,KAAK,CAAC,CAAC;QACtD,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QAC3B,EAAE,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;QAEtC,IAAI,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;IAC9C,CAAC;;AAGL,YAAY,CAAC,GAAG,EAAE,CAAC"}
@@ -0,0 +1,29 @@
1
+ /* eslint-disable */
2
+
3
+ Never use PROCESS.ENV/process.env use env() instead. (Except for process.env.NODE_ENV)
4
+ ---------------------------------
5
+
6
+ Based on: https://www.freecodecamp.org/news/how-to-implement-runtime-environment-variables-with-create-react-app-docker-and-nginx-7f9d42a91d70/
7
+
8
+ All variables in this files are converted to env() during build, and values here are replaced
9
+ by environment variables if they exists. This is done by running the env.sh bash script before the
10
+ build.
11
+
12
+ env.sh generates env-config.js containing all the variables, which is included in index.html,
13
+ and appended to Window._env_. env() is a shortcut for Window._env_ and should be used in code.
14
+
15
+ NOTE: Seems like window._env_ is not available in a worker
16
+
17
+ */
18
+ WEBSITE_HOSTNAME=localhost:3000;
19
+ REACT_APP_DEFAULT_CACHE_LOCATION=localstorage
20
+ REACT_APP_API_URL=https://dt-echopedia-api-dev.azurewebsites.net
21
+ REACT_APP_WEB_URL=https://dt-echopedia-web-dev.azurewebsites.net
22
+ REACT_APP_WEB_PROD_URL=https://echo.equinor.com
23
+ REACT_APP_AZURE_AD_TENNANT=StatoilSRM.onmicrosoft.com
24
+ REACT_APP_AZURE_AD_TENNANT_ID=3aa4a235-b6e2-48d5-9195-7fcf05b459b0
25
+ REACT_APP_AZURE_AD_CLIENT_ID=751d2504-0b66-4b78-9807-4b60525a14c6
26
+ REACT_APP_API_CLIENT_ID=aef35d97-53d4-4fd0-adaf-c5a514b38436
27
+ REACT_APP_APPINSIGHTS_CONNECTION_STRING=InstrumentationKey=e5299075-a00d-4012-96f9-42861e8d8a9e;IngestionEndpoint=https://northeurope-3.in.applicationinsights.azure.com/;LiveEndpoint=https://northeurope.livediagnostics.monitor.azure.com/;ApplicationId=a9b64222-d4a9-42e6-a615-7428fe1a26af
28
+ REACT_APP_AZURE_BUILD_NUMBER=0.8.dev.9
29
+ REACT_APP_LOGGER_ACTIVE=false
@@ -0,0 +1,46 @@
1
+ # echo-dev-host
2
+
3
+ TODO: update this readme
4
+
5
+ Lightweight host application for Echo Module development, shipped with `echo-cli`
6
+
7
+ ## Why it's needed
8
+
9
+ Each Echo Module needs EchopediaWeb as a host to run.
10
+
11
+ This makes development of Echo Modules difficult, since every time a
12
+ new change is introduced, one would need to release and deploy new version of the given Echo Module to see the newly developed features, changes.
13
+
14
+ Echo Client (with the help of `echo-cli`) solves this issue: it provides an "empty shell" of EchopediaWeb's framework, providing the same dependencies.
15
+
16
+ Echo Module devs can run their module via `npm start`, and develop their module "as normal": their module will show up in echo client, so they can see their changes right away with hot module reload.
17
+
18
+ To make sure that Echo Client mimics the same environment as the original echopediaWeb app, their dependencies are linked, and they need to be kept in sync.
19
+
20
+ ## How it works
21
+
22
+ `echo-client` ships together with `echo-cli`, so each Echo Module should have `echo-cli` as a dev dependency.
23
+
24
+ When you run the script `npm start` in your Echo Module, `echo-client` will start up providing the dev environment and the empty shell
25
+ of EchopediaWeb.
26
+
27
+ Development goes as usual:
28
+
29
+ - change code
30
+ - save changes
31
+ - hot reload will take care of applying the changes
32
+
33
+ ## Maintaining dependencies
34
+
35
+ ### Echo packages
36
+
37
+ With new echo packages released (for example: `echo-framework`, `echo-components`) the `echo-client` needs to be updated with these new versions as well,
38
+ and a new `echo-cli` release needs to be done.
39
+
40
+ When that's done, your Echo Module needs to be bumped to this new version of `echo-cli`.
41
+
42
+ See [here](../echo-cli/README.md) how to release new version of `echo-cli` (which ships `echo-client`)
43
+
44
+ ### Non-Echo packages
45
+
46
+ Non echo package dependencies are linked to echopediaWeb dependencies, so they are aligned and don't require maintenance.
@@ -0,0 +1,11 @@
1
+ module.exports = {
2
+ presets: ['@babel/preset-env', ['@babel/preset-react', {'runtime': 'automatic'}]],
3
+ plugins: [
4
+ '@babel/plugin-syntax-dynamic-import'
5
+ ],
6
+ env: {
7
+ test: {
8
+ plugins: ['@babel/plugin-transform-runtime'],
9
+ },
10
+ },
11
+ };
@@ -0,0 +1,51 @@
1
+ #!/bin/bash
2
+
3
+ #https://www.freecodecamp.org/news/how-to-implement-runtime-environment-variables-with-create-react-app-docker-and-nginx-7f9d42a91d70/
4
+ #
5
+
6
+ # Recreate config file
7
+ rm -rf ./env-config.js
8
+ touch ./env-config.js
9
+
10
+ echo "creating env-config.js"
11
+
12
+ # Add assignment
13
+ echo "window._env_ = {" >> ./env-config.js
14
+
15
+ # Read each line in .env file
16
+ # Each line represents key=value pairs
17
+ while read -r line || [[ -n "$line" ]];
18
+ do
19
+ #only process lines containting =
20
+ if [[ $line == *"="* ]]; then
21
+
22
+ # Split env variables by character `=`
23
+ if printf '%s\n' "$line" | grep -q -e '='; then
24
+ varname=$(printf '%s\n' "$line" | sed -e 's/=.*//')
25
+ varvalue=$(printf '%s\n' "$line" | sed -e 's/^[^=]*=//')
26
+ fi
27
+
28
+ # Read value of current variable if exists as Environment variable
29
+ value=$(printf '%s\n' "${!varname}")
30
+ # Otherwise use value from .env file
31
+ [[ -z $value ]] && value=${varvalue}
32
+
33
+ # Append configuration property to JS file
34
+ echo " $varname: \"$value\"," >> ./env-config.js
35
+
36
+ #print variables
37
+ valueObfuscated=$(printf '%s' "$value" | cut -c 1-3)
38
+ #echo " $varname: \"$value\"," #print the environment variables
39
+ echo " $varname=\"$valueObfuscated***\"," #print the environment variables obfuscated
40
+ fi
41
+ done < .env
42
+
43
+ echo "}" >> ./env-config.js
44
+
45
+ #if directory exists, copy to public folder. Needed for dev enironment (npm start)
46
+ if [ -d "public" ]; then
47
+ rm -rf ./public/env-config.js
48
+ cp ./env-config.js ./public/env-config.js
49
+ fi
50
+
51
+ echo "done creating env-config.js"
@@ -0,0 +1,21 @@
1
+ module.exports = {
2
+ testEnvironment: 'jsdom',
3
+ moduleNameMapper: {
4
+ '\\.css$': 'identity-obj-proxy',
5
+ '\\.svg$': '<rootDir>/src/__mocks__/svgrMock.ts'
6
+ },
7
+ preset: 'ts-jest',
8
+ coveragePathIgnorePatterns: ['src/types/*', 'src/index.ts', 'src/typings/*'],
9
+ collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!<rootDir>/node_modules/'],
10
+ coverageThreshold: {
11
+ global: {
12
+ lines: 90,
13
+ statements: 90
14
+ }
15
+ },
16
+ transform: {
17
+ '^.+\\.(j|t)sx?$': 'ts-jest'
18
+ },
19
+ testMatch: ['**/__tests__/**/*.test.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)'],
20
+ setupFilesAfterEnv: ['<rootDir>/src/setupTests.ts']
21
+ };