A web application to manage add-on source code
Перейти к файлу
Mathieu Pillard 38c56a8a98
Switch ubuntu image to 2004:current (ubuntu-2004:202201-02 is deprecated) (#2653)
2024-03-20 10:33:54 +01:00
.circleci Switch ubuntu image to 2004:current (ubuntu-2004:202201-02 is deprecated) (#2653) 2024-03-20 10:33:54 +01:00
.github Update dependabot.yml 2023-04-04 15:22:45 +02:00
public Fix session id auth: the data attribute in the HTML needs to match (#2159) 2022-02-23 18:16:33 +00:00
scripts Update dependency prettier to v2.3.0 (#1952) 2021-05-10 10:34:03 -04:00
src Remove code relating to canned responses (#2207) 2023-02-21 09:13:10 -05:00
stories/setup Upgrade Storybook to v6 (#1882) 2021-12-01 11:33:29 -05:00
.dockerignore Refactor Dockerfile to build static app during deployment (#475) 2019-03-27 15:19:27 +01:00
.env Fix session id auth: the data attribute in the HTML needs to match (#2159) 2022-02-23 18:16:33 +00:00
.env.common-local Remove Sentry integration (#2166) 2022-03-29 12:09:28 +02:00
.env.dev Add Google Analytics support to the app (#1426) 2020-02-11 10:53:10 -05:00
.env.olympia Add an env to use code-manager with a local olympia instance (#709) 2019-05-08 21:30:22 +02:00
.env.stage Add Google Analytics support to the app (#1426) 2020-02-11 10:53:10 -05:00
.eslintrc Update eslint-config-amo (#1887) 2021-03-15 14:03:59 +01:00
.gitignore Encourage devs to ignore .vscode globally (#1217) 2019-11-07 14:16:10 -06:00
.node-dev.json Implement server code in TS (#95) 2019-02-01 12:14:36 +01:00
.prettierignore Fully migrate to Circle CI (#1804) 2020-12-16 15:37:51 +01:00
.prettierrc Add prettier (#29) 2019-01-17 15:27:47 +01:00
.yarnrc Add SCSS support (#27) 2019-01-16 17:33:31 +01:00
Dockerfile Use specific non-root user to run the container (#2182) 2022-11-29 08:36:30 -08:00
LICENSE.txt Minor fixes for prettier (#57) 2019-01-23 19:15:30 +01:00
README.md Disable storybook-deployer (#2188) 2023-01-05 15:36:07 +01:00
codecov.yml Add codecov config (#2034) 2021-08-10 16:34:55 +02:00
package.json Bump react-ga from 3.3.0 to 3.3.1 (#2210) 2023-02-28 12:27:08 +01:00
tsconfig.json upgrade react-scripts to v4 (#1878) 2021-03-09 17:27:41 +01:00
version.json Add the circleci config (#397) 2019-03-18 12:10:47 +01:00
yarn.lock Bump react-ga from 3.3.0 to 3.3.1 (#2210) 2023-02-28 12:27:08 +01:00

README.md

addons-code-manager

CircleCI codecov

This is a web application to manage add-on source code, such as reviewing code for add-ons submitted to https://addons.mozilla.org. This project was bootstrapped with Create React App.

Requirements

  • You need Node 16 which is the current LTS (long term support) release.
  • You need yarn to manage dependencies and run commands.

Getting started

  • Clone this repository
  • Type yarn to install everything
  • Type yarn dev to launch the test suite, development servers, and all other development processes in stmux. Open http://localhost:3000 to view the development site. Press CTRL-a-? for help.

All available commands are documented below.

Read our contributing guidelines to get started on your first patch.

Prettier

We use Prettier to automatically format our JavaScript code and stop all the on-going debates over styles. As a developer, you have to run it (with yarn prettier-dev) before submitting a Pull Request.

TypeScript

All code is written in TypeScript. Currently, errors in test files won't be reported until you try to submit a pull request. Because of this, consider configuring your editor for error reporting.

CSS

All styles are written in the SASS pre-processor language as css modules.

Example: for a component like StarIcon/index.tsx, you'd create its module as StarIcon/styles.module.scss. You would import it at the top and reference it as a module. As an example, here is a simple stylesheet:

.container {
  padding: 12px;
}

You would reference this CSS class in your component like this:

import * as React from 'react';

import styles from './styles.module.scss';

const StarIcon = () => {
  return <div className={styles.container} />;
};

export default StarIcon;

Storybook

We use storybook to visualize the look and feel of our React components. Our Storybook is deployed on GitHub Pages: https://mozilla.github.io/addons-code-manager/.

Launch the development server like this:

yarn storybook

When developing a new component, always add a story for it. If you were creating a component like src/components/StarIcon/index.tsx then you'd put its story in stories/StarIcon.stories.tsx. The storybook server will automatically load files having the .stories.tsx suffix in this directory.

To update our Storybook, checkout gh-pages branch, run yarn storybook-build, commit and push the result to that branch.

Configuration

You can configure the app by defining environment variables in .env files, the standard way to configure Create React App, but read on below because there are some differences.

  • How to override an environment variable for local development
    • Define it in .env.common-local. This differs from how Create React App wants you to do it. If you put an environment variable in .env.local, it will get erased because we are generating this file when the app starts.
  • How to define a new environment variable
    • Add it to .env with the REACT_APP_ prefix.
  • How to override an environment variable for a hosted site
    • Define the variable in the corresponding puppet config file. To define a variable for code.addons-dev.allizom.org, for example, you'd update amo.code_manager.dev.yaml. Adding a variable to .env.dev will do nothing since that only affects the yarn dev command.

Profiling performance

Here are some tips for solving performance problems in addition to what's already in the official docs.

  • First, ask yourself if there is a real performance problem. If you need to simulate a slow CPU in the profiler just to see anything dramatic, it might be too early to start profiling!
  • Try to profile against a production build, if possible, with something like yarn start-local-dev. The overhead of a development build could be misleading.
  • If you want to see execution timing grouped by React component, you will need a development build.
  • Use Chrome so you can get React integration, if needed. This is a helpful guide for looking at the execution of React components in the User Timing section.
  • When a React component is taking a long time to render and you don't see any other components underneath it, it's time to switch away from the User Timing tab of the profiler to the Main tab so you can look at actual function executions. Clicking on a function will give you information about its source.
  • You can try using the React devtool extension for profiling but it doesn't provide a great timeline so it's hard to visualize overall slowness.

Setting up VSCode

If you want to use VSCode to develop Code Manager, some manual configuration is required. This is due to a security feature bug that prevents automatically applying a local config file.

  • Make sure you've installed all dependencies as documented.
  • Open the root folder in VSCode.
  • Open any TypeScript file and click the TypeScript version number from the bottom status bar. Choose the option Use Workspace Version to make sure you are developing with the correct version of TypeScript.

All Available Commands

In the project directory, you can run the following commands. There are a few commands not mentioned here (see package.json) but those are only used by internal processes.

yarn build

This builds the app for production to the build folder.

It correctly bundles React in production mode and optimizes the build for the best performance. The build is minified and the filenames include the hashes. Your app is ready to be deployed!

Note: for this project, we use a node server (see scripts/server.js).

yarn dev

This runs all development processes in a single column using stmux. Open http://localhost:3000 to view the development site. Press CTRL-a-? for help.

yarn dev-2col

This runs all development processes in two columns using stmux. Open http://localhost:3000 to view the development site. Press CTRL-a-? for help.

yarn dev-servers

This starts all development servers using stmux, connected to the -dev AMO API.

Open http://localhost:3000 to view it in the browser. Press CTRL-a-? for help.

yarn eject

This runs the eject command. Hopefully we won't ever need this 😭

yarn eslint

This runs ESLint to discover problems within our codebase without executing it. ESLint also enforces some patterns and practices.

yarn lint

This runs all the lint commands at once.

yarn olympia

A prerequisite to run this command is to install addons-server locally.

This runs all development processes in a single column using stmux. Open http://olympia.test:5000 to view the development site. Press CTRL-a-? for help. The application is configured to use a local AMO API.

Known issue: it is possible to login/logout but the login process will redirect you to the AMO frontend (http://olympia.test) instead of http://olympia.test:5000. You will have to manually go to code-manager, after that there should be no other authentication problem.

yarn prettier

This runs Prettier to automatically format the entire codebase.

yarn prettier-dev

This runs Prettier on only your changed files. This is intended for development.

yarn stage

This runs all development processes in a single column using stmux. Open http://localhost:3000 to view the development site. Press CTRL-a-? for help. The application is configured to use the stage AMO API.

yarn start-local-dev

This builds the app for production to the build folder (see yarn build command), configured with the -dev AMO API. It also starts a production server that serves the application (configured for local usage).

Open http://localhost:3000 to view it in the browser.

yarn start-local-prod

This builds the app for production to the build folder (see yarn build command), configured with the production AMO API. It also starts a production server that serves the application (configured for local usage).

Open http://localhost:3000 to view it in the browser.

⚠️ It is currently not possible to authenticate users.

yarn start-local-stage

This builds the app for production to the build folder (see yarn build command), configured with the stage AMO API. It also starts a production server that serves the application (configured for local usage).

Open http://localhost:3000 to view it in the browser.

yarn test

This launches Jest in the interactive watch mode.

See the section about running tests for more information.

yarn type-coverage

This will check how much of the codebase is protect by safe static types and fail if it's below the configured threshold.

yarn typecheck

This checks for TypeScript errors in all files, including test files.

You'd think that build does this but it does not check test files. See create-react-app issue 5626.

Learn More

You can learn more in the Create React App documentation.

To learn React, check out the React documentation.