Skip to content

Commit 0409b4d

Browse files
author
Adam Butterworth
committed
Merge remote-tracking branch 'base/master'
2 parents 4a2b06f + 2638f76 commit 0409b4d

Some content is hidden

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

67 files changed

+23345
-0
lines changed

.env.development

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
EXAMPLE_VAR=Example Value
2+
ACCESS_TOKEN_COOKIE_NAME=edx-jwt-cookie-header-payload
3+
BASE_URL=localhost:1995
4+
CREDENTIALS_BASE_URL=http://localhost:18150
5+
CSRF_TOKEN_API_PATH=/csrf/api/v1/token
6+
ECOMMERCE_BASE_URL=http://localhost:18130
7+
LANGUAGE_PREFERENCE_COOKIE_NAME=openedx-language-preference
8+
LMS_BASE_URL=http://localhost:18000
9+
LOGIN_URL=http://localhost:18000/login
10+
LOGOUT_URL=http://localhost:18000/login
11+
MARKETING_SITE_BASE_URL=http://localhost:18000
12+
ORDER_HISTORY_URL=localhost:1996/orders
13+
REFRESH_ACCESS_TOKEN_ENDPOINT=http://localhost:18000/login_refresh
14+
SEGMENT_KEY=ul
15+
SITE_NAME=Open edX
16+
USER_INFO_COOKIE_NAME=edx-user-info

.eslintignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage
2+
dist
3+
node_modules

.eslintrc.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { createConfig } = require('@edx/frontend-build');
2+
3+
module.exports = createConfig('eslint');

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.idea
2+
coverage
3+
dist
4+
node_modules
5+
/.vscode
6+
/.DS_Store

.releaserc

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"branch": "master",
3+
"tagFormat": "v${version}",
4+
"verifyConditions": [
5+
"@semantic-release/npm",
6+
{
7+
"path": "@semantic-release/github",
8+
"assets": {
9+
"path": "dist/*"
10+
}
11+
}
12+
],
13+
"analyzeCommits": "@semantic-release/commit-analyzer",
14+
"generateNotes": "@semantic-release/release-notes-generator",
15+
"prepare": "@semantic-release/npm",
16+
"publish": [
17+
"@semantic-release/npm",
18+
{
19+
"path": "@semantic-release/github",
20+
"assets": {
21+
"path": "dist/*"
22+
}
23+
}
24+
],
25+
"success": [],
26+
"fail": []
27+
}

.travis.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
language: node_js
2+
node_js: 12
3+
before_install:
4+
- npm install -g npm@latest
5+
install:
6+
- npm install
7+
script:
8+
- npm run lint
9+
- npm run test
10+
- npm run build
11+
after_success:
12+
- npx semantic-release
13+
- codecov
14+
env:
15+
global:
16+
# NPM_TOKEN
17+
- secure: UOFOESGx8y+qGnNmLReNPcYAKYxwnkODisxCP5b7DgBJGbLN8h03Ik8n/LDEZlFpwfl3CbE3piWHDWyXW4IysULxaggglKXP1WQ2e2mwU1s33L8qf2X1tiW33zCiGDRExsEQwAWX5YCS6uqg1cLiZYS+gYqxRhXuGGLzSCYK/NvKnqaxsRY/DNTe9eH6xM4pLQt3/+1qOUgdhZlzc+E9JaMqFhtxxp+L1tadZ63KjCpsyWw4//Rb3z4khk0NcjJ0nW0B8VL4DKTNfqdkudThqDBOPMOGLZxE9sa9xiPattYoYxaDDPXiMzmUAK8KoHjhv6j6EuLewx0QSjsRf+fHYy5n/tHllVF0V6awnl1xuiDUXZI3LQV09//RkoQi/+vdUd7RbHDnNMaf3YQIkVNeCL1doiSS+uCjk1GxqUW2b+8g1RmugOj2F9XJClCB8d+75WlwxRGytuuN0VQUWi60LEiNFSU3f+AEuayy686iCZxvtahu37iWMbbaDt8vcUYTH7RYQq8OrDMRFErJpr0vEEVO2FqPrpVoR5fVXfpMox3L2jhylR0cwKevh/eiy/yGxRhnTcRJYn3D4pJMKDxu6ELOakKpNhDN+EhBfbwNcMZwbdNc0GCWSn6TavNArPFQaWocpSXPitBbTAHLZFxwcmBamHhHoIIZRWe1F3bZaLw=
18+
# GH_TOKEN - edx-semantic-release user PAT
19+
- secure: qRMdKu0P8JTHr8q3HjEFgZ2fZUtV3CuEgPJxpukSV5x/cJH5TURvES7InvY6AOfG3eiW4A3D65N/pNMc5MT9fIEmO0aqWqFwPVYA7Jhb0+CIAZHYj8zITgmBisLVH9jwP6lKWwSPUDrmEQpKw0fey7HBpzy0yvCW8ioEdKo3h38uhwnpbv/jiHApjbKUCgxX3EHcYWsh9ou2K2DTNP+/dv6KlTbaJnvszRM/dI1APzinZ4p7Kmy9GrGHYPry8+wEof6Id/QqJ9VWNyOQiWYo3HRpvxXuk6pOUd2RnvYGWqaYJHqJQmkhJUqfNpsvqsLw3mPhvqTOHSZmBhnbDoh83iQDtny/hG/uxO2vXoJolUkgJrnCkaXbcVh4L6mZVGsMqjp9P9979R3dNZVgjZX9AC/B3heL/DcL5beVOyqODZ0Lntcf7E97pp3DY+ov94k9EvU4XjskhrvkWsgTNhG0l9vwkQ/2RxBSuMfAOAWWxshvELFFHLpsCovc68gEUoq7iMaxLoRajDUf8x+E+vlsQ3BgjwEkXjTvEDTIycRUQTcvgT6sDL+p6rawD9QJ1uTfqYvlwckmBtEr/sViUvn45unS5uIOeUwPsvqi7SaJwa5RdA86D2e2CQN6vQPXoFW4ICVpw4W6xP4wTVJqVKXNWyJf1wRNylWXGbcAz702u2g=

LICENSE

+661
Large diffs are not rendered by default.

Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
build:
2+
rm -rf ./dist
3+
./node_modules/.bin/fedx-scripts babel src --out-dir dist --source-maps --ignore **/*.test.jsx,**/*.test.js,**/setupTest.js --copy-files
4+
@# --copy-files will bring in everything else that wasn't processed by babel. Remove what we don't want.
5+
@find dist -name '*.test.js*' -delete
6+
rm ./dist/setupTest.js

README.rst

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
frontend-base
2+
=============
3+
4+
|Build Status| |Codecov| |NPM Version| |npm_downloads| |license|
5+
|semantic release|
6+
7+
Overview
8+
--------
9+
10+
Foundational application management code for Open edX micro-frontend
11+
applications.
12+
13+
``frontend-base`` provides Open edX micro-frontends with:
14+
15+
- A standardized, yet customizable application initialization process.
16+
- Lifecycle event subscriptions for startup sequence extension.
17+
- Convenient access to environment configuration and application state
18+
data.
19+
- A React-based application data provider.
20+
- High-level logging of events and errors to promote observability.
21+
- Fallback error handling.
22+
23+
With respect to the initialization process, ``frontend-base`` helps
24+
manage the vast majority of what we expect all Open edX micro-frontends
25+
to have by default, namely:
26+
27+
- Environment configuration
28+
- Authentication / access to an authenticated API client
29+
- Analytics
30+
- Logging
31+
- Internationalization
32+
33+
Running the example app and test suite
34+
--------------------------------------
35+
36+
This repo has an example app that demonstrates basic usage of the
37+
library.
38+
39+
::
40+
41+
npm install # do this once
42+
npm start # starts the dev server
43+
44+
Visit `http://localhost:8080/ <http://localhost:8080/>`__ in your
45+
browser.
46+
47+
The jest test suite can be run with:
48+
49+
::
50+
51+
npm test
52+
53+
Getting Started
54+
---------------
55+
56+
Initialization is managed via the ``App`` singleton.
57+
58+
The simplest initialization sequence looks like this:
59+
60+
::
61+
62+
import { App, APP_READY } from '@edx/frontend-base';
63+
64+
import HelloWorld from './HelloWorld'; // Your application component
65+
66+
App.subscribe(APP_READY, () => {
67+
ReactDOM.render(
68+
<HelloWorld />
69+
)
70+
});
71+
72+
App.initialize();
73+
74+
This initialization sequence will do the following:
75+
76+
- Read in expected environment configuration variables and validate
77+
that they're not ``undefined``
78+
- Configure NewRelicLoggingService for @edx/frontend-logging.
79+
- Verify that the user is logged in and authenticated, with a current
80+
JWT token.
81+
- Redirect the user to login if they're not authenticated.
82+
- Initialize i18n without any messages.
83+
- Configure analytics with Segment.
84+
85+
Error handling
86+
~~~~~~~~~~~~~~
87+
88+
If an error occurs during the initialization sequence, the application
89+
will go into an error state and log the error to the logging service.
90+
91+
You can hook into this state by subscribing to the ``APP_ERROR`` event.
92+
For convenience, ``frontend-base`` provides a simple ``<ErrorPage>``
93+
component that can be used to display errors to the user of the app as a
94+
fallback error experience. This experience can be used as-is (shown
95+
below), or replaced with your own error page experience.
96+
97+
::
98+
99+
App.subscribe(APP_ERROR, (error) => {
100+
ReactDOM.render(<ErrorPage />, document.getElementById('root'));
101+
});
102+
103+
Error handling after initialization (in React)
104+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
105+
106+
It's recommended that in React applications you use `error
107+
boundaries <https://reactjs.org/docs/error-boundaries.html>`__ to catch
108+
run-time errors in your React components.
109+
110+
``frontend-base`` provides an error boundary component which displays
111+
``<ErrorPage>`` in the event of an uncaught error in React. If you use
112+
``<AppProvider>`` then you'll get this behavior for free.
113+
114+
If you need a custom error page, you can add your own error boundary
115+
inside ``<AppProvider>`` and the fallback handling will effectively be
116+
ignored (since errors won't bubble up to it anymore).
117+
118+
Foundational React Components
119+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
120+
121+
``frontend-base`` also provides several companion React components which
122+
pair with the App singleton to help bootstrap your React application.
123+
Please see the API documentation for ``<AppProvider>`` and
124+
``<AppContext>`` specifically; they're an important part of the
125+
frontend-base ecosystem.
126+
127+
Additional Resources
128+
--------------------
129+
130+
- `API
131+
Reference <https://github.com/edx/frontend-base/blob/master/docs/API.rst>`__
132+
133+
.. |Build Status| image:: https://api.travis-ci.org/edx/frontend-base.svg?branch=master
134+
:target: https://travis-ci.org/edx/frontend-base
135+
.. |Codecov| image:: https://img.shields.io/codecov/c/github/edx/frontend-base
136+
:target: https://codecov.io/gh/edx/frontend-base
137+
.. |NPM Version| image:: https://img.shields.io/npm/v/@edx/frontend-base.svg
138+
:target: https://www.npmjs.com/package/@edx/frontend-base
139+
.. |npm_downloads| image:: https://img.shields.io/npm/dt/@edx/frontend-base.svg
140+
:target: https://www.npmjs.com/package/@edx/frontend-base
141+
.. |license| image:: https://img.shields.io/npm/l/@edx/frontend-base.svg
142+
:target: https://github.com/edx/frontend-base/blob/master/LICENSE
143+
.. |semantic release| image:: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
144+
:target: https://github.com/semantic-release/semantic-release

babel.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { createConfig } = require('@edx/frontend-build');
2+
3+
module.exports = createConfig('babel-preserve-modules');

codecov.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
coverage:
2+
status:
3+
project:
4+
default:
5+
target: auto
6+
threshold: 0%
7+
patch:
8+
default:
9+
target: auto
10+
threshold: 0%

commitlint.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: ['@commitlint/config-angular'],
3+
};

0 commit comments

Comments
 (0)