Skip to content

Commit ae5b53f

Browse files
committed
temp: add dist folder for testing purposes
1 parent 8f84e1c commit ae5b53f

File tree

121 files changed

+7074
-1
lines changed

Some content is hidden

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

121 files changed

+7074
-1
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
.idea
33
.vscode
44
coverage
5-
dist
65
src/i18n/transifex_input.json
76
node_modules
87
/docs/api

dist/LICENSE

+661
Large diffs are not rendered by default.

dist/README.md

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
[![Build Status](https://github.com/openedx/frontend-platform/actions/workflows/ci.yml/badge.svg)](https://github.com/openedx/frontend-platform/actions/workflows/ci.yml)
2+
[![Codecov](https://img.shields.io/codecov/c/github/edx/frontend-platform)](https://codecov.io/gh/edx/frontend-platform)
3+
[![NPM Version](https://img.shields.io/npm/v/@edx/frontend-platform.svg)](https://www.npmjs.com/package/@edx/frontend-platform)
4+
[![npm_downloads](https://img.shields.io/npm/dt/@edx/frontend-platform.svg)](https://www.npmjs.com/package/@edx/frontend-platform)
5+
[![license](https://img.shields.io/npm/l/@edx/frontend-platform.svg)](https://github.com/openedx/frontend-platform/blob/master/LICENSE)
6+
[![semantic release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
7+
8+
# Overview
9+
10+
See the [GitHub Pages site for the complete documentation](https://openedx.github.io/frontend-platform/).
11+
12+
frontend-platform is a modest application framework for Open edX micro-frontend applications and their supporting libraries. It provides several foundational services that all Open edX micro-frontends should have:
13+
14+
| Service | Module location |
15+
|------------------------------------|----------------------------------|
16+
| Analytics | @edx/frontend-platform/analytics |
17+
| Logging | @edx/frontend-platform/logging |
18+
| Authenticated API client (auth) | @edx/frontend-platform/auth |
19+
| Internationalization (i18n) | @edx/frontend-platform/i18n |
20+
| Misc (init, config, pubSub, utils) | @edx/frontend-platform |
21+
22+
-------------------------------------------------------------------------
23+
24+
In addition, frontend-platform provides an extensible application initialization lifecycle to help manage the configuration of the above services, freeing application developers to focus on feature development.
25+
26+
## Getting started
27+
28+
### One-time setup if you have not upgraded node/npm
29+
IMPORTANT: There is now a new node/npm version being used by frontend-platform as of
30+
https://github.com/openedx/frontend-platform/pull/259
31+
32+
#### Install nvm
33+
This is highly recommended to be able to leverage different node/npm versions.
34+
For a some time, different repositories may be using different versions of node/npm.
35+
36+
Alternatively, please install node16 and npm8 for use with this repository.
37+
38+
#### Switch to node/npm version for this repo
39+
```nvm use```
40+
if you don't have the right node/npm versions, nvm will instruct you to install those
41+
42+
#### Clean out old node modules and reinstall
43+
This step is needed because node now uses a different package lock format, and it's important to reinstall
44+
dependencies based on this new package file. Delete node_modules, and issue an `npm ci`
45+
46+
47+
### Standard getting started steps
48+
49+
1. `npm install`
50+
2. `npm start`
51+
3. Open http://localhost:8080 to view the example app.
52+
53+
## Architecture
54+
55+
The four foundational services listed above (analytics, auth, i18n, and logging) are provided as imports to applications via frontend-platform's API layer. The initialization sequence creates an instance of each service and exposes its methods as functional exports, creating a layer of abstraction between service implementations and their usage in application code.
56+
57+
Each type of service has a documented API contract which service implementations must fulfill. This allows different service implementations to be used as necessary without updates to consuming applications.
58+
59+
### Service architecture
60+
61+
Internally, service implementations are strictly isolated from the rest of the platform. They are classes that take their dependencies as arguments to their constructor. This means, for instance, if analytics depends on logging, it takes a reference to an instance fulfilling the `LoggingService` interface as an option when it's instantiated. It cannot import from the logging module directly. Put another way, the default service implementations may be co-located with the service interfaces for convenience, but they can theoretically live in their own repository and it wouldn't require any refactoring.
62+
63+
Likewise, platform code should not make use of service methods that are not part of the documented interface for the same reasons.
64+
65+
### Application initialization
66+
67+
frontend-platform provides an `initialize()` function which bootstraps and configures an application. The `initialize()` function uses a set of [sensible defaults](https://en.wikipedia.org/wiki/Convention_over_configuration) unless otherwise specified, bootstrapping the application with services reflecting Open edX's best practices around analytics, authentication, internationalization, and logging.
68+
69+
The initialization process proceeds in a series of phases, giving the initializing application code opportunities to hook into the process and do custom setup as desired:
70+
71+
- Before initialization
72+
- Pub/Sub initialized
73+
- Environment config document loaded
74+
- Logging service initialized
75+
- Authentication service initialized
76+
- Analytics service initialized
77+
- Internationalization service initialized
78+
- Application ready
79+
80+
Most applications won't need to do anything special at all.
81+
82+
### Application configuration
83+
84+
When the application loads, a list of known environment variables is loaded from `process.env` into an object which it exposes via `getConfig` - the point here is primarily to isolate our code from usages of `process.env` which may not always be the way we choose to configure our apps. The application initialization lifecycle supports runtime configuration as well via the `config` handler, documented in the [initialize function](https://edx.github.io/frontend-platform/module-Initialization.html#~initialize). If you want to get a variable into the config that it’s not expecting, you can use [`mergeConfig`](https://edx.github.io/frontend-platform/module-Config.html#~mergeConfig) during initialization to add it in from `process.env`.
85+
86+
Such an example might look like this:
87+
88+
```
89+
initialize({
90+
// ... other initialization options
91+
handlers: {
92+
config: () => {
93+
mergeConfig({
94+
CUSTOM_VARIABLE: process.env.CUSTOM_VARIABLE || null,
95+
}, 'Custom app config');
96+
},
97+
},
98+
});
99+
```
100+
101+
When using runtime configuration via `mergeConfig` noted above, `getConfig` must be called within a component's render lifecycle for the added keys and values to be returned in the configuration object. If `getConfig` is called outside of a component's render lifecycle, the custom configuration key/value pairs will not initially be part of the object returned by `getConfig`. For example:
102+
103+
```jsx
104+
import { getConfig } from '@edx/frontend-platform/config';
105+
106+
// The runtime configuration `CUSTOM_VARIABLE` added in the above code snippet will not appear here. This is
107+
// because `getConfig` is called before `mergeConfig` is executed to add the custom runtime configuration.
108+
console.log(getConfig().CUSTOM_VARIABLE); // returns undefined
109+
110+
const ExampleComponent = () => {
111+
// This returns the value as expected since it is called after `mergeConfig` has already been executed.
112+
console.log(getConfig().CUSTOM_VARIABLE)
113+
};
114+
```
115+
116+
### Service interfaces
117+
118+
Each service (analytics, auth, i18n, logging) provided by frontend-platform has an API contract which all implementations of that service are guaranteed to fulfill. Applications that use frontend-platform can use its configured services via a convenient set of exported functions. An application that wants to use the service interfaces need only initialize them via the initialize() function, optionally providing custom service interfaces as desired (you probably won't need to).
119+
120+
![Service interface](service-interface.png)
121+
122+
### Service implementations
123+
124+
This repository contains default service implementations for convenience. These implementations are co-located with their consuming service interfaces for ease of development, though the two should remain _strictly_ modular and separate.
125+
126+
The included service implementations are:
127+
128+
- New Relic (logging)
129+
- Segment (analytics)
130+
- Axios/JWT (auth)
131+
- React Intl (i18n)
132+
133+
NOTE: As of this writing, i18n is _not_ configurable. The `initialize()` function does not allow applications to supply an alternate i18n implementation; this is because the interface and implementation for i18n has not yet been separated and modularized.
134+
135+
# Local Development & Testing Locally
136+
137+
When making changes to frontend-platform, be sure to manually run the included example app located in `./example`. The example app includes 2 routes to test for both unauthenticated and authenticated users. To start the example app, run `npm start` from the root directory.
138+
139+
If you want to test changes to frontend-platform against a micro-frontend locally, follow the directions here: https://github.com/openedx/frontend-build#local-module-configuration-for-webpack
140+
141+
# Production Deployment Strategy
142+
143+
For any MFE built on top of the frontend-platform, the deployment strategy will be something like the following:
144+
145+
1. Run the build script with environment variables on the command line to pass in any relevant config. Example:
146+
147+
```bash
148+
NODE_ENV=development BASE_URL=open.edx.org ETC=etc npm run build
149+
```
150+
151+
This will create a dist/ directory that contains the deployable artifacts.
152+
153+
2. Copy the contents of dist/ to a web server.
154+
155+
3. Configure the platform to point at your MFE. (details on this coming soon)

dist/analytics/MockAnalyticsService.js

+75
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/analytics/MockAnalyticsService.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)