Skip to content

Commit

Permalink
Improve CONTRIBUTING guide, fix bug in feature SDK instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
jdorn committed Mar 7, 2022
1 parent f7690db commit dbae7e1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 34 deletions.
48 changes: 25 additions & 23 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ If you just want to contribute a client library in a new language and not make c
- NodeJS 12.x or 14.x
- Yarn
- Python 3.6+ (for the stats engine)
- scipy
- numpy
- pandas
- Docker (for running MongoDB locally)

## Getting started

1. Fork the project
2. Clone your forked project by running `git clone git@github.com:{ YOUR_USERNAME }/growthbook.git`
3. Run `yarn` to install node modules
4. Start MongoDB in Docker
3. Run `yarn` to install dependencies
4. Run `yarn setup` to do the initial build
5. Start MongoDB in Docker

```sh
docker run -d -p 27017:27017 --name mongo \
Expand All @@ -26,8 +30,8 @@ docker run -d -p 27017:27017 --name mongo \
mongo
```

5. Run `yarn dev` to start the app in dev mode
6. Visit http://localhost:3000 in your browser and verify the app is working correctly
6. Run `yarn dev` to start the app in dev mode
7. Visit http://localhost:3000 in your browser and verify the app is working correctly

### Changing Configuration Settings

Expand All @@ -47,14 +51,15 @@ This repository is a monorepo with the following packages:
- **packages/docs** is another Next.js app of our documentation site (https://docs.growthbook.io).
- **packages/sdk-js** is our javascript SDK (`@growthbook/growthbook` on npm)
- **packages/sdk-react** is our React SDK (`@growthbook/growthbook-react` on npm)
- **packages/sdk-dev** is a Dev Mode variation switcher for our SDKs (`@growthbook/dev` on npm)
- **packages/stats** is our Python stats engine (`gbstats` on PyPi)

Depending on what you're changing, you may need to edit one or more of these packages.

### Working on the main app

The `yarn dev` command starts both the front-end and back-end in parallel
The `yarn dev` command starts both the front-end and back-end in parallel.

The back-end can take up to 30 seconds for the initial build, so be patient.

The packages are available at the following urls with hot-reloading:

Expand All @@ -67,33 +72,30 @@ To start the docs site, run `yarn workspace docs dev`. You can view the site at

### Working on the SDKs

Build the javascript SDK with `yarn workspace @growthbook/growthbook build`

Build the react SDK with `yarn workspace @growthbook/growthbook-react build`
To work on the SDKs, `cd` into the desired directory and the following commands are available:

The SDK dev mode has a playground for development. Make sure to build the javascript SDK and react SDK first before running. Start the playground with `yarn workspace @growthbook/dev dev` and view at http://localhost:3300
- `yarn test` - Run just
- `yarn build` - Run the rollup build process
- `yarn size` - Get the gzip size of the bundle (must run `yarn build` first)

### Working on the stats engine

We use `poetry` for managing dependencies. In the `packages/stats` directory, run `poetry install`.
To work on the Python stats engine, `cd` into the `packages/stats` directory and the following commands are available:

You may need to install some dependencies manually if you are using conda:

```sh
conda install scipy numpy pandas
```

Then you can run the test suite with `pytest`.
- `yarn test` - Run pytest
- `yarn lint` - Run flake8 and black
- `poetry build` - Run the build process

## Code Quality

Run repo-wide test suites with `yarn test`

There is a pre-commit hook that lints the code base and performs Typescript type checking. This can take 30 seconds or more so please be patient. You can run these same checks yourself with `yarn lint` and `yarn type-check`.
There are a few repo-wide code quality tools:

### Python
- `yarn test` - Run the full test suite on all packages
- `yarn type-check` - Typescript type checking
- `yarn lint` - Typescript code linting
- `yarn workspace stats lint` - Python code linting (need to `pip install flake8 black` first)

You can lint the python stats engine manually with `yarn workspace stats lint`. Note: you may need to install some global python dependencies with `pip install flake8 black`.
There is a pre-commit hook that runs `yarn lint` automatically, so you shouldn't need to run that yourself.

## Opening Pull Requests

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"dev": "wsrun -p '*-end' -m dev",
"build": "wsrun -p '*-end' -m build",
"start": "wsrun -p '*-end' -m start",
"setup": "wsrun -p '@growthbook/growthbook' -c build && wsrun -p '@growthbook/growthbook-react' -c build && wsrun -p 'stats' -c setup",
"prepare": "husky install"
},
"workspaces": [
Expand Down
30 changes: 20 additions & 10 deletions packages/front-end/components/Features/CodeSnippetModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,25 @@ export default function CodeSnippetModal({ close }: { close: () => void }) {
const { datasources } = useDefinitions();
const exampleAttributes = getExampleAttributes(attributeSchema);

// Record the fact that the SDK instructions have been seen
useEffect(() => {
if (!settings) return;
if (settings.sdkInstructionsViewed) return;
(async () => {
{
await apiCall(`/organization`, {
method: "PUT",
body: JSON.stringify({
settings: {
sdkInstructionsViewed: true,
},
}),
});
await update();
}
})();
}, [settings]);

// Create API key if one doesn't exist yet
const [devApiKey, setDevApiKey] = useState("");
const [prodApiKey, setProdApiKey] = useState("");
Expand Down Expand Up @@ -156,16 +175,7 @@ export default function CodeSnippetModal({ close }: { close: () => void }) {
size="lg"
header="Implementation Instructions"
submit={async () => {
if (settings?.sdkInstructionsViewed) return;
await apiCall(`/organization`, {
method: "PUT",
body: JSON.stringify({
settings: {
sdkInstructionsViewed: true,
},
}),
});
await update();
return;
}}
cta={"Finish"}
>
Expand Down
3 changes: 2 additions & 1 deletion packages/stats/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"scripts": {
"test": "pytest",
"lint": "black gbstats tests && flake8"
"lint": "black gbstats tests && flake8",
"setup": "poetry install"
}
}

0 comments on commit dbae7e1

Please sign in to comment.