Skip to content

Commit 30f4904

Browse files
jollyjerraliza614
andauthored
♻️ Local dev environment improvements (#463)
* Adding a before you begin section * added install instructions to before you start still need version check * Completed changes to before you get started section * Completed changes to before you get started section * adding console format to some of them * playing with formatting * formatted code in block format * adding cd to server * add local redis image * server: clean up unused css selectors * clean up mongo deprecations * add start:local script * move vscode settings to vscode workspace * clean up server env file * reduce logging and add docker check * move db container away from default mogo port * update readmes * fix some readme typos * switch to correct cypress bin but find child process spawn bug * test to make sure this still works on travis * add testing docs and update redis port so we never see a redis v. redis showdown * clean * ⬆️ bump postcss version * add ability to reset local env * add extra help text in readmes Co-authored-by: aliza614 <47804976+aliza614@users.noreply.github.com>
1 parent 3a2e58e commit 30f4904

25 files changed

+250
-229
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ config.ts
3131
.redispid
3232
.redisuri
3333
packages/server/cypress/screenshots/**/*(failed).png
34+
cypress/
35+
cypress.json
3436

3537
# web integration test
3638
packages/web/cypress/screenshots/**/*(failed).png

.vscode/extensions.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

.vscode/launch.json

Lines changed: 0 additions & 23 deletions
This file was deleted.

.vscode/settings.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

README.md

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,23 @@ UpSwyng is a mobile-ready, digital directory of resources to assist the unhoused
66

77
If you have any issues getting started using these directions, please see the [Troubleshooting section](#Troubleshooting).
88

9-
1. Install the Yarn package manager by following the instructions at
10-
[https://yarnpkg.com/lang/en/docs/install](https://yarnpkg.com/lang/en/docs/install)
9+
### Requirements
1110

12-
2. While in the root of this repo, install all project dependencies by running
11+
Make sure you have these tools installed before you begin.
1312

14-
```console
15-
yarn
16-
```
13+
- Node.js version 14.3
1714

18-
3. Next, try starting try running the web client by entering `yarn workspace @upswyng/web start`. This command will start in on port 3000. For specific setup instructions on the two main projects, see their corresponding READMEs.
15+
- [Docker](https://docs.docker.com/get-docker/) version 20.10 or above
16+
17+
- [Yarn](https://classic.yarnpkg.com/en/docs/install/#mac-stable)
18+
19+
### Building your local dev environment
20+
21+
1. Clone (or fork and clone) this repository and `cd` into it
22+
23+
2. Make sure docker is running on your machine. You can check by running `docker ps` in your terminal
24+
25+
3. Run `yarn start:local`
1926

2027
## Project Organization
2128

@@ -44,7 +51,7 @@ yarn workspace @upswyng/web start
4451
To run the same command in _all_ workspaces, use `yarn workspaces`. For instance, to run `test` in all packages use:
4552

4653
```console
47-
yarn workspaces test
54+
yarn workspaces run test
4855
```
4956

5057
Typing out the full workspace name can get tedious. You can place aliases in your `.bashrc` or `.profile` to save time:
@@ -55,6 +62,15 @@ alias @uw="yarn workspace @upswyng/web "
5562

5663
Now you only need `@uw start` to start the web dev server.
5764

65+
### Running tests
66+
67+
When you push a branch up to GitHub, [travis](https://docs.travis-ci.com/) will attempt to build the app with your changes and will run our entire test suite to ensure that nothing is broken.
68+
It's a good idea to run tests locally before pushing, although it is not required.
69+
70+
If you wish to run tests locally, you will need to ensure that `redis-server` is available in your `path`. You can check by running `redis-server`, and you can install it [here](https://redis.io/topics/quickstart) or via `brew install redis` on mac.
71+
72+
Once Redis is installed, run our entire test suite with `yarn test`.
73+
5874
### Troubleshooting
5975

6076
#### The engine "node" is incompatible with this module.
@@ -65,7 +81,7 @@ When running `yarn` to install project dependencies, you may see a message that
6581
The engine "node" is incompatible with this module. Expected version "^14.3.x". Got "11.15.0".
6682
```
6783

68-
This just means that your machine's current version of node does not match the version required to run the UpSwyng server, 12.14.x. To fix this you'll need to install and which your current version of Node. [nvm](https://itnext.io/nvm-the-easiest-way-to-switch-node-js-environments-on-your-machine-in-a-flash-17babb7d5f1b#d594) is a helpful tool, among others, you could use to easily switch between node versions.
84+
This just means that your machine's current version of node does not match the version required to run the UpSwyng server, 14.3.x. To fix this you'll need to install and which your current version of Node. [nvm](https://itnext.io/nvm-the-easiest-way-to-switch-node-js-environments-on-your-machine-in-a-flash-17babb7d5f1b#d594) is a helpful tool, among others, you could use to easily switch between node versions.
6985

7086
#### Type Errors
7187

@@ -86,6 +102,10 @@ To fix this, run the script:
86102
yarn build:local-packages
87103
```
88104

105+
## Reset
106+
107+
If nothing you try is fixing your issue, you can totally reset your local environment with `yarn reset`. After performing a reset, try `yarn start:local` and see if things work out.
108+
89109
## Contributing
90110

91111
Pull requests are welcome and encouraged! Please review and follow our [guidelines](CONTRIBUTING.md).

clean.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,38 @@
1+
/**
2+
* Script to clean local environment. Usage:
3+
* `yarn clean` to clean build artifacts
4+
* `yarn clean --reset` to totally reset local environment by removing build artifacts, node modules, and .env files.
5+
*/
6+
17
const fs = require("fs");
28
const glob = require("glob");
39

10+
const args = process.argv.slice(2);
11+
412
const foldersToDelete = [
513
"./packages/types/dist",
614
"./packages/common/dist",
715
"./packages/server/__build__",
816
"./packages/web/build",
917
];
1018

11-
const globsToDelete = ["./packages/**/tsconfig*.tsbuildinfo"];
19+
const globsToDelete = [
20+
"./packages/**/tsconfig*.tsbuildinfo",
21+
"./packages/web/.env",
22+
];
23+
24+
const foldersToDeleteForFullReset = [
25+
"./node_modules",
26+
"./packages/types/node_modules",
27+
"./packages/web/node_modules",
28+
"./packages/server/node_modules",
29+
"./packages/common/node_modules",
30+
];
31+
32+
const globsToDeleteForFullReset = [
33+
"./packages/web/.env",
34+
"./packages/server/.env",
35+
];
1236

1337
function deleteFolderRecursive(path) {
1438
if (fs.existsSync(path) && fs.lstatSync(path).isDirectory()) {
@@ -24,7 +48,7 @@ function deleteFolderRecursive(path) {
2448
}
2549
});
2650

27-
console.log(` 🗑 Deleting directory "${path}"...`);
51+
console.log(` 🗑 Deleting "${path}"...`);
2852
fs.rmdirSync(path);
2953
}
3054
}
@@ -36,9 +60,14 @@ function deleteGlob(globString) {
3660
});
3761
}
3862

39-
console.log("🧹 Cleaning build artifacts...");
63+
console.log("🧹 Cleaning...");
4064

4165
foldersToDelete.forEach(deleteFolderRecursive);
4266
globsToDelete.forEach(deleteGlob);
4367

44-
console.log("🧼 Successfully cleaned build artifacts.");
68+
if (args[0] === "--reset") {
69+
foldersToDeleteForFullReset.forEach(deleteFolderRecursive);
70+
globsToDeleteForFullReset.forEach(deleteGlob);
71+
}
72+
73+
console.log("🧼 Successfully cleaned.");

docker-compose.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services:
55
image: mongo:3.6.20
66
restart: always
77
ports:
8-
- 27017:27017
8+
- 27018:27017
99
environment:
1010
MONGO_INITDB_ROOT_USERNAME: root
1111
MONGO_INITDB_ROOT_PASSWORD: local
@@ -20,3 +20,9 @@ services:
2020
environment:
2121
ME_CONFIG_MONGODB_ADMINUSERNAME: root
2222
ME_CONFIG_MONGODB_ADMINPASSWORD: local
23+
redis:
24+
image: "redis:alpine"
25+
ports:
26+
- "6380:6379"
27+
environment:
28+
- REDIS_REPLICATION_MODE=master

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,15 @@
8383
"build:local-packages": "yarn workspace @upswyng/types build && yarn workspace @upswyng/common build",
8484
"build:server": "yarn build:local-packages && yarn workspace @upswyng/server build",
8585
"build:web": "yarn build:local-packages && yarn workspace @upswyng/web build",
86-
"build:local-db": "docker-compose up --build -d && mongorestore --username upswyng-dev-user --password upswyng123 -d upswyng-dev ./packages/server/localdb/mongodump",
86+
"build:local-db": "docker compose up --build -d && mongorestore --port 27018 --username upswyng-dev-user --password upswyng123 -d upswyng-dev ./packages/server/localdb/mongodump",
8787
"clean": "node clean.js",
88+
"reset": "node clean.js --reset && docker compose down -v",
8889
"heroku-postbuild": "yarn build:web && yarn build:server",
8990
"lint": "tsc --noEmit && eslint \"packages/**/src/**/*.{js,jsx,ts,tsx}\" --fix",
9091
"lint:ci": "tsc --noEmit && eslint \"packages/**/src/**/*.{js,jsx,ts,tsx}\" --quiet",
91-
"test": "concurrently -n common,server -c yellow,blue \"yarn workspace @upswyng/common test\" \"yarn workspace @upswyng/server test\" && yarn workspace @upswyng/web test",
92-
"test:ci": "concurrently -n common,server -c yellow,blue \"yarn workspace @upswyng/common test\" \"yarn workspace @upswyng/server test\" --kill-others-on-fail && yarn workspace @upswyng/web test"
92+
"test": "concurrently -n common,server -c yellow,blue \"yarn workspace @upswyng/common test:unit\" \"yarn workspace @upswyng/server test\" && yarn workspace @upswyng/web test",
93+
"test:ci": "concurrently -n common,server -c yellow,blue \"yarn workspace @upswyng/common test:unit\" \"yarn workspace @upswyng/server test\" --kill-others-on-fail && yarn workspace @upswyng/web test",
94+
"start:local": "./start_local.sh"
9395
},
9496
"version": "0.1.0",
9597
"workspaces": [

packages/common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"name": "@upswyng/common",
2525
"scripts": {
2626
"build": "rollup --config",
27-
"test": "jest"
27+
"test:unit": "jest"
2828
},
2929
"types": "dist/index.d.ts",
3030
"version": "0.1.0"

packages/common/rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module.exports = {
2525
// All the other modules besides 'rrule' should be resolved with the default entrypoint priority. (Defaults
2626
// to ['module', 'main'].) See: https://github.com/rollup/rollup-plugin-node-resolve#usage
2727
resolve({
28+
preferBuiltins: true,
2829
only: [/^(?!.*rrule).*$/],
2930
browser: true,
3031
preferBuiltins: false,

0 commit comments

Comments
 (0)