Skip to content

Commit 424dea3

Browse files
authored
Integrate wireit services and misc improvements (#1386)
- Used (new!) Wireit services feature to streamline config of all scripts where relevant - The top-level `npm run watch:dev` and `npm run watch:prod` scripts are now `npm start --watch` and `npm start:prod --watch` - The `start` scripts now automatically restart servers whenever needed based on which files changed - The `start` scripts now also launch the catalog server and firestore emulator Also: - Added some dependencies that were missing - Fixed `tsc` errors by adding some new `build:types` scripts. - Fixed some format/lint errors - Added CI jobs for `build` and `check` - Switched the firestore emulator port to something more in line with the scheme we're using for the rest of the services - Fixed a bug with `undefined` vs `null` that broke firestore calls - Documented how to bootstrap firestore for local dev
1 parent 5964285 commit 424dea3

File tree

29 files changed

+299
-118
lines changed

29 files changed

+299
-118
lines changed

.github/workflows/build.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Build
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v3
11+
12+
- uses: actions/setup-node@v3
13+
with:
14+
node-version: 18
15+
cache: 'npm'
16+
cache-dependency-path: package-lock.json
17+
18+
- uses: google/wireit@setup-github-actions-caching/v1
19+
20+
- name: NPM install
21+
run: npm ci
22+
23+
- name: Build
24+
run: npm run build

.github/workflows/check.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Check
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
check:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v3
11+
12+
- uses: actions/setup-node@v3
13+
with:
14+
node-version: 18
15+
cache: 'npm'
16+
cache-dependency-path: package-lock.json
17+
18+
- uses: google/wireit@setup-github-actions-caching/v1
19+
20+
- name: NPM install
21+
run: npm ci
22+
23+
- name: Check
24+
run: npm run check

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,27 @@ This monorepo contains several npm packages:
2020
## Quick Start
2121

2222
1. Install dependencies:
23+
2324
```bash
2425
npm ci
2526
```
27+
2628
2. Run tests:
29+
2730
```bash
2831
npm test
2932
```
33+
3034
3. Start everything in development mode and watch for changes:
35+
3136
```bash
32-
npm watch:dev
37+
npm start --watch
3338
```
3439

40+
4. Visit [`http://localhost:6451/bootstrap-packages`](http://localhost:6451/bootstrap-packages) to bootstrap the database with a default set of elements.
41+
42+
5. Visit [`http://localhost:5450/catalog`](http://localhost:5450/catalog) and search for "button" to see example elements.
43+
3544
## Docker
3645

3746
Using Docker locally gives you the most realistic simulation of a production
@@ -50,3 +59,4 @@ We use the following port scheme for consistency and to prevent collisions:
5059
- [`localhost:5452`](http://localhost:5452): site-server in docker
5160
- [`localhost:6451`](http://localhost:6451): catalog-server
5261
- [`localhost:6452`](http://localhost:6452): catalog-server in docker
62+
- [`localhost:7450`](http://localhost:7450): firestore-emulator

docker/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
context: ../
1010
dockerfile: docker/firestore-emulator/Dockerfile
1111
ports:
12-
- 8088:8088
12+
- 7450:7450
1313

1414
catalog:
1515
depends_on:
@@ -19,7 +19,7 @@ services:
1919
dockerfile: docker/catalog/Dockerfile
2020
environment:
2121
- PORT=6452
22-
- FIRESTORE_EMULATOR_HOST=firestore-emulator:8088
22+
- FIRESTORE_EMULATOR_HOST=firestore-emulator:7450
2323
ports:
2424
- 6452:6452
2525

package-lock.json

Lines changed: 7 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
"test": "wireit",
1212
"build:dev": "wireit",
1313
"build:prod": "wireit",
14+
"start": "wireit",
15+
"start:prod": "wireit",
1416
"start:docker": "docker-compose -f docker/docker-compose.yml up --build --remove-orphans",
15-
"watch:dev": "npm run build:dev && (npm run start:dev > /dev/null 2>&1 & WIREIT_FAILURES=continue npm run build-and-check:dev --watch)",
16-
"watch:prod": "npm run build:prod && (npm run start:prod & WIREIT_FAILURES=continue npm run build-and-check:prod --watch)",
1717
"check": "wireit",
1818
"check:lint": "wireit",
1919
"build-and-check:dev": "wireit",
@@ -31,14 +31,30 @@
3131
"eslint-plugin-no-only-tests": "^3.0.0",
3232
"prettier": "^2.7.1",
3333
"typescript": "~4.8.2",
34-
"wireit": "^0.7.2"
34+
"wireit": "^0.7.3-pre.3"
3535
},
3636
"wireit": {
37+
"start": {
38+
"dependencies": [
39+
"./packages/site-server:start:dev",
40+
"./packages/catalog-server:start:dev",
41+
"check"
42+
]
43+
},
44+
"start:prod": {
45+
"dependencies": [
46+
"./packages/site-server:start:prod",
47+
"./packages/catalog-server:start:dev",
48+
"check"
49+
]
50+
},
3751
"build": {
3852
"dependencies": [
3953
"./packages/custom-elements-manifest-tools:build",
4054
"./packages/catalog-api:build",
41-
"./packages/catalog-server:build"
55+
"./packages/catalog-server:build",
56+
"./packages/site-content:build",
57+
"./packages/site-client:build"
4258
]
4359
},
4460
"test": {

packages/catalog-server/firebase.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"port": 9099
55
},
66
"firestore": {
7-
"port": 8088,
7+
"port": 7450,
88
"host": "0.0.0.0"
99
},
1010
"ui": {

packages/catalog-server/package.json

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"start:dev": "wireit",
1919
"test": "wireit",
2020
"test:manual": "wireit",
21-
"emulators:start": "firebase emulators:start --project wc-catalog",
21+
"emulators:start": "wireit",
2222
"firebase": "firebase"
2323
},
2424
"wireit": {
@@ -41,34 +41,43 @@
4141
},
4242
"start": {
4343
"command": "node --enable-source-maps index.js",
44+
"service": true,
4445
"dependencies": [
4546
"build"
4647
]
4748
},
4849
"start:dev": {
49-
"command": "FIRESTORE_EMULATOR_HOST=localhost:8088 npm start",
50+
"command": "FIRESTORE_EMULATOR_HOST=localhost:7450 npm start",
51+
"service": true,
5052
"dependencies": [
51-
"build"
53+
"build",
54+
"emulators:start"
5255
]
5356
},
5457
"test": {
55-
"command": "firebase emulators:exec --project wc-catalog ./test.sh",
58+
"command": "NODE_OPTIONS=--enable-source-maps FIRESTORE_EMULATOR_HOST=localhost:7450 uvu test \"_test\\.js$\"",
5659
"dependencies": [
57-
"build"
58-
],
59-
"files": [
60-
"test.sh"
60+
"build",
61+
"emulators:start"
6162
],
63+
"files": [],
6264
"output": []
6365
},
66+
"emulators:start": {
67+
"command": "firebase emulators:start --project wc-catalog",
68+
"service": true,
69+
"files": [
70+
"firebase.json",
71+
"firestore.indexes.json",
72+
"firestore.rules"
73+
]
74+
},
6475
"test:manual": {
65-
"command": "NODE_OPTIONS='--enable-source-maps' FIRESTORE_EMULATOR_HOST=localhost:8088 uvu test \"_test\\.js$\"",
76+
"command": "NODE_OPTIONS='--enable-source-maps' FIRESTORE_EMULATOR_HOST=localhost:7450 uvu test \"_test\\.js$\"",
6677
"dependencies": [
6778
"build"
6879
],
69-
"files": [
70-
"test.sh"
71-
],
80+
"files": [],
7281
"output": []
7382
}
7483
},

packages/catalog-server/src/lib/firestore/firestore-repository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ export class FirestoreRepository implements Repository {
5252
* A namespace suffix to apply to the 'packages' collection to support
5353
* multi-tenant-like separation of the database. Used for testing.
5454
*/
55-
private readonly namespace?: string;
55+
private readonly namespace: string | null;
5656

5757
constructor(namespace?: string) {
58-
this.namespace = namespace;
58+
this.namespace = namespace ?? null;
5959
}
6060

6161
async startPackageImport(packageName: string): Promise<void> {

packages/catalog-server/src/lib/firestore/validation-problem-converter.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import {
99
FirestoreDataConverter,
1010
QueryDocumentSnapshot,
1111
} from '@google-cloud/firestore';
12-
import type {
13-
ValidationProblem
14-
} from '@webcomponents/catalog-api/lib/schema.js';
12+
import type {ValidationProblem} from '@webcomponents/catalog-api/lib/schema.js';
1513

1614
export const validationProblemConverter: FirestoreDataConverter<ValidationProblem> =
1715
{

0 commit comments

Comments
 (0)