frontend
frontend copied to clipboard
Frontend of Source Academy, an online experiential environment for computational thinking (React, Redux, Saga, Blueprint)
Source Academy Frontend
The Source Academy (https://sourceacademy.org/) is an immersive online experiential environment for learning programming. It is developed by a community of learners (also called "Source Academy") who use the book Structure and Interpretation of Computer Programs, JavaScript Adaptation (SICP JS). This repository houses the sources for the frontend of the Source Academy, written in ReactJS with Redux.
Features
- Playground to write and test programs
- Built-in stepper, data visualizer, and environment visualizer to debug your programs
- Assessments (Missions/Quests/Contests) to solve challenging problems while learning about programming fundamentals
- Sessions for collaborative programming
- Integration with Google Drive and Github
- Graphic-novel-style game to provide context for themed assessments
- Grading System to grade and comment on submitted assessments
Getting Started
Installation of Source Academy (latest version available in GitHub Pages)
-
Install the current LTS version of Node.js. The current version (usually the version one greater than the current LTS) may also work, but if you encounter issues, use the current LTS.
-
Clone this repository and navigate to it using "cd" in your command line or shell tool.
-
Run
yarn installto install dependencies.
If you encounter error message:No such file or directory: 'install'. These instruction may work for you.
sudo apt remove cmdtest
sudo apt remove yarn
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update
sudo apt-get install yarn -y -
Run
yarn run startto start the server atlocalhost:8000. It might take a couple of minutes for the server to start. -
Point your browser to
http://localhost:8000to see your local Source Academy.
In this edition, you will only see the Playground with all its tools, but no login options or homework submission features.
If you wish to set up the GitHub or Google Drive integrations, copy the .env.example file as .env and refer to Setting up your environment below for the relevant configuration options.
Installation of Source Academy @ NUS (access latest production version here)
- Install the current LTS version of Node.js. The current version (usually the version one greater than the current LTS) may also work, but if you encounter issues, use the current LTS.
- Clone this repository and navigate to it using "cd" in your command line or shell tool.
- Run
yarn installto install dependencies. - Copy the
.env.examplefile as.envand set the necessary variables (refer below for more information) - Run
yarn run startto start the server atlocalhost:8000. It might take a couple of minutes for the server to start.
Setting up your environment
The project requires some environment variables to be set to work properly. In the .env file a few things need to be set up:
Backend configuration
REACT_APP_BACKEND_URL: The base URL of the backend. If you are testing with a local backend, the value in.env.examplematches the default development configuration of the backend.REACT_APP_USE_BACKEND: Set to false if not running together with the backend.REACT_APP_MODULE_BACKEND_URL: The base URL from which Source modules are loaded. (This is a js-slang feature, but of course it has to be configured here.) You can just use the default value in development.REACT_APP_SHAREDB_BACKEND_URL: The base URL of the ShareDB collaborative editor backend. The protocol must be HTTP or HTTPS (it will automatically be set to WS/WSS as appropriate). Must end in a trailing/.REACT_APP_SICPJS_BACKEND_URL: The base URL from which SICP JS content is loaded.
URL shortener configuration
Unless you need to use the shortener locally, you can leave these values blank. Otherwise, ask your backend engineer.
REACT_APP_URL_SHORTENER_SIGNATURE: The API key for the YOURLS URL shortener.REACT_APP_URL_SHORTENER_DOMAIN: The base URL of the YOURLS URL shortener. Unless you need to use the shortener locally, you can leave this blank. Otherwise, ask your backend engineer.
Authentication provider configuration
If you are testing with a local backend, the values in .env.example match the default development configuration of the backend. Otherwise, your backend engineer should provide you with the configuration for the staging and/or production backend.
n is an integer starting from 1. The numbers must be consecutive i.e. if you have 5 authentication providers, the numbers must be 1, 2, 3, 4, and 5.
REACT_APP_OAUTH2_PROVIDERn: The provider ID of the nth authentication provider. This must match the backend configuration.REACT_APP_OAUTH2_PROVIDERn_NAME: The name of the nth authentication provider shown on the login screen.REACT_APP_OAUTH2_PROVIDERn_ENDPOINT: The authentication endpoint of the nth authentication provider.
Google API configuration
The following properties are used for the Playground Google Drive integration. You can leave them blank if you are not using or testing that feature locally.
REACT_APP_GOOGLE_CLIENT_ID: The OAuth2 client ID issued by Google.REACT_APP_GOOGLE_API_KEY: The Picker API key issued by Google.REACT_APP_GOOGLE_APP_ID: The project ID of the Google API project.
See here a guide on obtaining the above values from the Google API Console.
Disable periods
The frontend can be configured to disable itself (based on user's system time) during certain periods e.g. during e-exams. Note that this is not foolproof, but it can be combined with other strategies e.g. taking down the frontend entirely (but this is needed to counteract the service worker).
REACT_APP_DISABLEn_START: The time from which to disable the frontend.REACT_APP_DISABLEn_END: The time until which to disable the frontend.REACT_APP_DISABLEn_REASON: Optional. A reason shown for the disablement.
Other configuration
REACT_APP_DEPLOYMENT_NAME: The name of the Source Academy deployment. This will be shown in the/welcomeroute. Defaults to 'Source Academy'.REACT_APP_PLAYGROUND_ONLY: Whether to build the "playground-only" version, which disables the Academy components, so only the Playground is available. This is what we deploy onto GitHub Pages.REACT_APP_ENABLE_GITHUB_ASSESSMENTS: Whether to enable the GitHub Assessments feature. Off by default.REACT_APP_SHOW_RESEARCH_PROMPT: Whether to show the educational research consent prompt to users. This is mainly for instructors using their own deployment of Source Academy @ NUS to disable this prompt.
Development
Running the tests
Before pushing to Github, ensure that your code is formatted and your tests are passing. These two commands should help with that:
yarn run format: formats your codeyarn run test: runs the tests and prints the output
Running your own js-slang
See js-slang README for instructions how to run your own js-slang in the frontend.
Contribution Guidelines
Refer to our issue tracker and contribute to any open issues you are able to spot there. If you have any new issues, please do post there as well. We welcome any form of contribution and are open to any new ideas you may have for the project!
To start contributing, create a fork from our repo and send a PR. Refer to this article for more information.
Application Structure
assetscontains static assets.commonscontains components or other code common to more than one page.featurescontains action creators, reducers and type declarations for specific functions.pagescontains pages and components used only in one page; its layout should mirror the actual routes.stylescontains all SCSS styles.
TypeScript Coding Conventions
We reference this guide.
See also the this standard in the wiki.
Projects
For more info on specific frontend projects, please consult our wiki.
Build and deployment
There are a few additional environment variables that are used when building and deploying for production.
REACT_APP_VERSION: A version string shown in the console on app launch.REACT_APP_ENVIRONMENT: An environment string. Currently it is only used to differentiate different deploys in Sentry.REACT_APP_SENTRY_DSN: The Sentry DSN for error monitoring.REACT_APP_SW_EXCLUDE_REGEXES: A JSON array of regexes as strings. The service worker will ignore paths matching any of these regexes. This is used in our GitHub Pages deploy so that it does not conflict with the subsites we host on GitHub Pages.REACT_APP_CADET_LOGGER: Log server URL. To test with cadet-logger on localhost, set it tohttp://localhost:8001/assessment-logger.REACT_APP_CADET_LOGGER_INTERVAL: The interval (in ms) that the frontend should upload logs.
Testing
The frontend comes with an extensive test suite. To run the tests after you made your modifications, run
yarn test. Regression tests are run automatically when you want to push changes to this repository.
The regression tests are generated using jest and stored as snapshots in src/\_\_tests\_\_. After modifying the frontend, carefully inspect any failing regression tests reported in red in the command line. If you are convinced that the regression tests and not your changes are at fault, you can update the regression tests by running:
$ yarn test --updateSnapshot
and then typing a to update all snapshots.
License
All sources in this repository are licensed under the Apache License Version 2.