Skip to content

Commit 45f72e8

Browse files
MagdalenaJadachsra405
MagdalenaJadach
andauthored
Redundant editor code tidy up (#1103)
closes #1088 --------- Co-authored-by: Scott <[email protected]>
1 parent 6cf5e5a commit 45f72e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+52
-2409
lines changed

.env.example

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
REACT_APP_AUTHENTICATION_CLIENT_ID='editor-dev'
22
REACT_APP_AUTHENTICATION_URL='http://localhost:9001'
3+
REACT_APP_SENTRY_DSN=''
4+
REACT_APP_SENTRY_ENV='local'
5+
PUBLIC_URL='http://localhost:3011'
6+
ASSETS_URL='http://localhost:3011'
37
REACT_APP_API_ENDPOINT='http://localhost:3009'
48
REACT_APP_GOOGLE_TAG_MANAGER_ID=''
59
REACT_APP_PLAUSIBLE_DATA_DOMAIN=''
610
REACT_APP_PLAUSIBLE_SOURCE=''
7-
REACT_APP_SENTRY_DSN=''
8-
REACT_APP_SENTRY_ENV='local'
9-
PUBLIC_URL='http://localhost:3011'
10-
ASSETS_URL='http://localhost:3010'

.env.webcomponent.example

-7
This file was deleted.

.github/workflows/ci-cd.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ jobs:
9292
with:
9393
install: false
9494
start: |
95-
yarn start:wc
95+
yarn start
9696
wait-on: "http://localhost:3011"
9797
quiet: true
9898
env:

.github/workflows/deploy.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ jobs:
128128
if [[ "${{ inputs.environment }}" != "production" ]]; then
129129
yarn build:dev
130130
fi
131-
yarn build:wc
131+
yarn build
132132
env:
133133
PUBLIC_URL: ${{ needs.setup-environment.outputs.public_url }}
134134
ASSETS_URL: ${{ needs.setup-environment.outputs.assets_url }}

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5757

5858
- Enabling web component to find the `turtle` canvas (#1082)
5959
- Ability to stop code in the web component (#1083)
60+
- Remove redundant code (#1103)
6061

6162
## [0.27.0] - 2024-09-26
6263

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ RUN corepack enable \
1818

1919
RUN yarn
2020

21-
EXPOSE 3010
21+
EXPOSE 3011
2222

2323
CMD ["yarn", "start"]

README.md

+5-13
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ Copy the example files into the correct place:
99

1010
```
1111
cp .env.example .env
12-
13-
cp .env.webcomponent.example .env.webcomponent
1412
```
1513

16-
Variables for the web application need to go into the `.env` file.
17-
Variables for the web component can be placed in `.env.webcomponent`.
14+
Variables for the web component can be placed in `.env`.
1815

1916
## Private repo setup (.npmrc)
2017

@@ -32,7 +29,7 @@ In the project directory, you can run:
3229
### `yarn start`
3330

3431
Runs the app in the development mode.\
35-
Open [http://localhost:3010](http://localhost:3010) to view it in the browser.
32+
Open [http://localhost:3011](http://localhost:3011) to view it in the browser.
3633

3734
The page will reload if you make edits.\
3835
You will also see any lint errors in the console.
@@ -57,8 +54,9 @@ See the section about [deployment](https://facebook.github.io/create-react-app/d
5754
Automated unit tests can be run via the `yarn test` command. These unit tests are written using the JavaScript testing framework `Jest` and make use of the tools provided by the [React Testing Library](https://testing-library.com/docs/). Automated accessibility testing for components is available via the `jest-axe` library. This can be achieved using the `haveNoViolations` matcher provided by `jest-axe`, although this does not guarantee that the tested components have no accessibility issues.
5855

5956
Integration testing is carried out via `cypress` and can be run using:
60-
* `yarn exec cypress run` to run in the CLI
61-
* `yarn exec cypress open` to run in the GUI
57+
58+
- `yarn exec cypress run` to run in the CLI
59+
- `yarn exec cypress open` to run in the GUI
6260

6361
Currently, there are basic `cypress` tests for the standalone editor site, the web component and Mission Zero-related functionality. These can be found in the `cypress/e2e` directory. Screenshots and videos related to the most recent `cypress` test run can be found in `cypress/screenshots` and `cypress/videos` respectively.
6462

@@ -80,12 +78,6 @@ The web component can be included in a page by using the `<editor-wc>` HTML elem
8078
- `embedded`: Enable embedded mode which hides some functionality (defaults to `false`)
8179
- `output_split_view`: Start with split view in output panel (defaults to `false`, i.e. tabbed view)
8280

83-
### `yarn start:wc`
84-
85-
Runs the web component in development mode. Open [http://localhost:3011](http://localhost:3011) to view it in the browser.
86-
87-
**NB** You need to have the main `yarn start` process running too.
88-
8981
It is possible to add query strings to control how the web component is configured. Any HTML attribute can be set on the query string, including `class`, `style` etc.
9082

9183
For example, to load the page with the Sense Hat always showing, add [`?sense_hat_always_enabled` to the URL](http://localhost:3011?sense_hat_always_enabled)

config/env.js

+18-20
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
'use strict';
2-
3-
const fs = require('fs');
4-
const path = require('path');
5-
const paths = require('./paths');
1+
const fs = require("fs");
2+
const path = require("path");
3+
const paths = require("./paths");
64

75
// Make sure that including paths.js after env.js will read .env variables.
8-
delete require.cache[require.resolve('./paths')];
6+
delete require.cache[require.resolve("./paths")];
97

108
const NODE_ENV = process.env.NODE_ENV;
119
if (!NODE_ENV) {
1210
throw new Error(
13-
'The NODE_ENV environment variable is required but was not specified.'
11+
"The NODE_ENV environment variable is required but was not specified.",
1412
);
1513
}
1614

@@ -20,7 +18,7 @@ const dotenvFiles = [
2018
// Don't include `.env.local` for `test` environment
2119
// since normally you expect tests to produce the same
2220
// results for everyone
23-
NODE_ENV !== 'test' && `${paths.dotenv}.local`,
21+
NODE_ENV !== "test" && `${paths.dotenv}.local`,
2422
`${paths.dotenv}.${NODE_ENV}`,
2523
paths.dotenv,
2624
].filter(Boolean);
@@ -30,12 +28,12 @@ const dotenvFiles = [
3028
// that have already been set. Variable expansion is supported in .env files.
3129
// https://github.com/motdotla/dotenv
3230
// https://github.com/motdotla/dotenv-expand
33-
dotenvFiles.forEach(dotenvFile => {
31+
dotenvFiles.forEach((dotenvFile) => {
3432
if (fs.existsSync(dotenvFile)) {
35-
require('dotenv-expand')(
36-
require('dotenv').config({
33+
require("dotenv-expand")(
34+
require("dotenv").config({
3735
path: dotenvFile,
38-
})
36+
}),
3937
);
4038
}
4139
});
@@ -50,10 +48,10 @@ dotenvFiles.forEach(dotenvFile => {
5048
// https://github.com/facebook/create-react-app/issues/1023#issuecomment-265344421
5149
// We also resolve them to make sure all tools using them work consistently.
5250
const appDirectory = fs.realpathSync(process.cwd());
53-
process.env.NODE_PATH = (process.env.NODE_PATH || '')
51+
process.env.NODE_PATH = (process.env.NODE_PATH || "")
5452
.split(path.delimiter)
55-
.filter(folder => folder && !path.isAbsolute(folder))
56-
.map(folder => path.resolve(appDirectory, folder))
53+
.filter((folder) => folder && !path.isAbsolute(folder))
54+
.map((folder) => path.resolve(appDirectory, folder))
5755
.join(path.delimiter);
5856

5957
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
@@ -62,7 +60,7 @@ const REACT_APP = /^REACT_APP_/i;
6260

6361
function getClientEnvironment(publicUrl) {
6462
const raw = Object.keys(process.env)
65-
.filter(key => REACT_APP.test(key))
63+
.filter((key) => REACT_APP.test(key))
6664
.reduce(
6765
(env, key) => {
6866
env[key] = process.env[key];
@@ -71,7 +69,7 @@ function getClientEnvironment(publicUrl) {
7169
{
7270
// Useful for determining whether we’re running in production mode.
7371
// Most importantly, it switches React into the correct mode.
74-
NODE_ENV: process.env.NODE_ENV || 'development',
72+
NODE_ENV: process.env.NODE_ENV || "development",
7573
// Useful for resolving the correct path to static assets in `public`.
7674
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
7775
// This should only be used as an escape hatch. Normally you would put
@@ -90,12 +88,12 @@ function getClientEnvironment(publicUrl) {
9088
// react-refresh is not 100% stable at this time,
9189
// which is why it's disabled by default.
9290
// It is defined here so it is available in the webpackHotDevClient.
93-
FAST_REFRESH: process.env.FAST_REFRESH !== 'false',
94-
}
91+
FAST_REFRESH: process.env.FAST_REFRESH !== "false",
92+
},
9593
);
9694
// Stringify all values so we can feed into webpack DefinePlugin
9795
const stringified = {
98-
'process.env': Object.keys(raw).reduce((env, key) => {
96+
"process.env": Object.keys(raw).reduce((env, key) => {
9997
env[key] = JSON.stringify(raw[key]);
10098
return env;
10199
}, {}),

config/paths.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ module.exports = {
5454
appPath: resolveApp("."),
5555
appBuild: resolveApp(buildPath),
5656
appPublic: resolveApp("public"),
57-
appHtml: resolveApp("src/index.html"),
58-
appIndexJs: resolveModule(resolveApp, "src/index"),
57+
appHtml: resolveApp("src/web-component.html"),
58+
appIndexJs: resolveModule(resolveApp, "src/web-component"),
5959
appPackageJson: resolveApp("package.json"),
6060
appSrc: resolveApp("src"),
6161
appTsConfig: resolveApp("tsconfig.json"),

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ x-app: &x-app
1414
services:
1515
react-ui-wc:
1616
<<: *x-app
17-
command: yarn start:wc
17+
command: yarn start
1818
ports:
1919
- "3011:3011"
2020
container_name: react-ui-wc

docs/WebComponent.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
To have the web component be able to use the same React components as the site application there needed to be a separate start script for the component. This required being able to customise how build was done and meant the `create-react-app` needed to be ejected. This copies configuration files into the project instead of running it all in create-react-app scripts.
44

5-
There is a custom webpack config file for the component `webpack.component.config.js` and a script in the `package.json`: `start:wc` which will start serving the web component.
5+
There is a custom webpack config file for the component `webpack.config.js` and a script in the `package.json`: `start` which will start serving the web component.
66

77
In `public/web-component/index.html` the JavaScript output is added and the web-component mounted. Then viewing `http://localhost:3011` will load the page with the web component mounted.
88

package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@
8080
"web-vitals": "^1.0.1"
8181
},
8282
"scripts": {
83-
"start": "node scripts/start.js",
83+
"start": "NODE_ENV=development BABEL_ENV=development webpack serve -c ./webpack.config.js",
84+
"build": "NODE_ENV=production BABEL_ENV=production webpack build -c ./webpack.config.js",
8485
"build:dev": "yarn install --check-cache && yarn run build-storybook",
8586
"build-storybook": "cd ./storybook && yarn install && yarn run build-storybook -- -o ../public/storybook --loglevel warn",
8687
"lint": "eslint \"src/**/*.{js,jsx,json}\"",
@@ -89,9 +90,7 @@
8990
"test": "node scripts/test.js --transformIgnorePatterns 'node_modules/(?!three)/'",
9091
"storybook": "cd storybook && rm -rf ./node_modules/.cache/storybook && yarn run storybook",
9192
"watch-css": "sass --load-path=./ -q --watch src:src",
92-
"start:wc": "NODE_ENV=development BABEL_ENV=development webpack serve -c ./webpack.component.config.js",
93-
"build:wc": "NODE_ENV=production BABEL_ENV=production webpack build -c ./webpack.component.config.js",
94-
"heroku-postbuild": "export PUBLIC_URL='' && yarn build && yarn build:wc"
93+
"heroku-postbuild": "export PUBLIC_URL='' && yarn build"
9594
},
9695
"browserslist": {
9796
"production": [

0 commit comments

Comments
 (0)