Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul monorepo tooling #201

Merged
merged 18 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests.
# For now we only run against node 22.x, but can easily add more node versions should we decide to support them.
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js + pnpm CI
name: CI

on:
push:
branches: ['main']
pull_request:
branches: ['main']
types: [opened, synchronize]

jobs:
app:
build:
name: Build and Test
timeout-minutes: 10
runs-on: ubuntu-latest

strategy:
matrix:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
node-version: [22.x]
# To use enable remote caching just set these env vars up
# env:
# TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
# TURBO_TEAM: ${{ vars.TURBO_TEAM }}
# TURBO_REMOTE_ONLY: true

steps:
- name: Checkout
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 2

- uses: pnpm/action-setup@v4
name: Install pnpm
- uses: pnpm/action-setup@v3
with:
run_install: true
version: 9

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
node-version: 22
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Lint
run: pnpm run check-prettier
run: pnpm check-format

- name: Check that the application can successfully build
run: pnpm run build
- name: Build
run: pnpm build

- name: Test
run: pnpm --filter api test
run: pnpm test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ srcbook/public/**/*

srcbook/lib/**/*
!srcbook/lib/.gitkeep

# turbo
**/.turbo
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22.7.0
12 changes: 3 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ To run the app for local development, you'll need to start both:
Run the API:

```shell
pnpm run dev-api
```

Run the Web server:

```shell
pnpm run dev-web
turbo dev
```

Then visit http://localhost:5173
Expand All @@ -30,13 +24,13 @@ _Note: make sure to run the database migrations with `pnpm run migrate` prior to
Similar to NPM, check top-level package.json for scripts.

```shell
pnpm check-types
turbo check-types
```

To run a script defined in one of the packages:

```shell
pnpm --filter api check-types
turbo check-types --filter=@srcbook/api
```

## Adding a dependency
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ Srcbook runs locally on your machine as a CLI application with a web interface.

### Requirements

- Node.js v20+
- We recommend using [nvm](https://github.com/nvm-sh/nvm) to manage local node versions
- Node 20+, we recommend using [nvm](https://github.com/nvm-sh/nvm) to manage local node versions
- [corepack](https://nodejs.org/api/corepack.html) to manage package manager versions

### Installing

Expand Down
23 changes: 14 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@
"version": "0.0.1",
"type": "module",
"scripts": {
"dev-api": "pnpm --filter api dev",
"dev-web": "pnpm --filter web dev",
"build": "./scripts/build",
"lint-web": "pnpm --filter web lint",
"check-types": "pnpm --recursive check-types",
"check-prettier": "pnpm prettier --check .",
"format": "pnpm prettier --write .",
"dev": "turbo dev",
"build": "turbo build",
versecafe marked this conversation as resolved.
Show resolved Hide resolved
"test": "turbo test",
"lint": "turbo lint",
"check-format": "prettier --check .",
"format": "prettier --write .",
"generate": "pnpm --filter api generate",
"migrate": "pnpm --filter api migrate",
versecafe marked this conversation as resolved.
Show resolved Hide resolved
"start": "pnpm --filter srcbook start"
"start": "turbo start"
},
"devDependencies": {
"@types/node": "catalog:",
"prettier": "catalog:",
"typescript": "catalog:"
},
"packageManager": "[email protected]+sha512.38dc6fba8dba35b39340b9700112c2fe1e12f10b17134715a4aa98ccf7bb035e76fd981cf0bb384dfa98f8d6af5481c2bef2f4266a24bfa20c34eb7147ce0b5e"
"dependencies": {
"turbo": "^2.0.14"
},
"packageManager": "[email protected]",
"engines": {
"node": ">=20"
}
}
6 changes: 4 additions & 2 deletions packages/api/db/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Make sure we've created the .srcbook directory on disk
* before creating the DB
*/
import '../initialization.mjs';
import path from 'node:path';
import { drizzle } from 'drizzle-orm/better-sqlite3';
import Database from 'better-sqlite3';
Expand All @@ -18,4 +17,7 @@ const DB_PATH = `${process.env.HOME}/.srcbook/srcbook.db`;

const sqlite = new Database(DB_PATH);
export const db = drizzle(sqlite, { schema });
migrate(db, { migrationsFolder: drizzleFolder });

export function configureDB(): void {
migrate(db, { migrationsFolder: drizzleFolder });
}
3 changes: 2 additions & 1 deletion packages/api/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import app from './server/http.mjs';
import wss from './server/ws.mjs';
import { SRCBOOKS_DIR } from './constants.mjs';
import { posthog } from './posthog-client.mjs';
import { configureDB } from './db/index.mjs';

export { app, wss, SRCBOOKS_DIR, posthog };
export { app, wss, SRCBOOKS_DIR, posthog, configureDB };
4 changes: 4 additions & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"version": "0.0.1-alpha.1",
"type": "module",
"main": "./dist/index.mjs",
"types": "./dist/index.d.mts",
"files": [
"dist/**"
],
"scripts": {
"init": "vite-node ./initialization.mts",
"predev": "pnpm run init",
Expand Down
2 changes: 1 addition & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"dev": "vite",
"prebuild": "rm -rf ./dist",
"build": "tsc && vite build",
"build": "tsc && vite build && cp -R ./dist ../../srcbook/public",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This copies dist into public such that it's public/dist/{files} but the express server is expecting public/{files}.

I think changing it to cp -R ./dist/. ../../srcbook/public will work

"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"format": "prettier --write .",
"preview": "vite preview",
Expand Down
122 changes: 95 additions & 27 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 0 additions & 25 deletions scripts/build

This file was deleted.

Empty file removed srcbook/lib/.gitkeep
Empty file.
Loading