Skip to content

Commit

Permalink
Introduce monorepo to manage packages using pnpm (#880)
Browse files Browse the repository at this point in the history
Workspace:

```
examples/           
- nextjs-scheduler
- profile-stack
- react-tldraw
- react-todomvc
- simultaneous-cursors
- vanilla-codemirror6
- vanilla-quill
- vuejs-kanban

packages/
- create-yorkie-app
- devtools
- sdk                  <-- previous yorkie-js-sdk package
```

Command:

```
`sdk`
- [x] pnpm sdk build
- [x] pnpm sdk build:proto
- [x] pnpm sdk build:docs
- [x] pnpm sdk build:ghpages
- [x] pnpm sdk dev
- [x] pnpm sdk test
- [x] pnpm sdk test:watch
- [x] pnpm sdk test:bench
- [x] pnpm sdk test:ci
- [x] pnpm sdk test:yorkie.dev
- [x] pnpm sdk lint
- [x] pnpm sdk prepare

`devtools`
- [x] pnpm devtools dev
- [x] pnpm devtools build
- [x] pnpm devtools test

`create-yorkie-app`
- [x] pnpm create-yorkie-app start
- [x] pnpm create-yorkie-app build
- [x] pnpm create-yorkie-app build:copy-assets
```

---------

Co-authored-by: Youngteac Hong <susukang98@gmail.com>
  • Loading branch information
gwbaik9717 and hackerwins authored Aug 16, 2024
1 parent 267878f commit e84ba27
Show file tree
Hide file tree
Showing 211 changed files with 14,664 additions and 22,507 deletions.
27 changes: 15 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,34 @@ jobs:
node-version: [18.x]
steps:
- uses: actions/checkout@v2

- uses: pnpm/action-setup@v2
with:
version: 8
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache: 'pnpm'

- name: Cache Node Moudles
- name: Cache pnpm store
id: cache
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-node-
${{ runner.os }}-pnpm-
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm install
run: pnpm install

- run: npm run lint
- run: npm run build
- run: npm run build:examples
- run: pnpm sdk lint
- run: pnpm sdk build
- run: pnpm build:examples
- run: docker compose -f docker/docker-compose-ci.yml up --build -d
- run: npm run test:ci
- run: pnpm sdk test:ci

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
Expand All @@ -51,4 +54,4 @@ jobs:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: Run benchmark
run: npm run test:bench
run: pnpm sdk test:bench
13 changes: 7 additions & 6 deletions .github/workflows/create-yorkie-app-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ on:
branches:
- main
paths:
- tools/create-yorkie-app/**
- packages/create-yorkie-app/**
- examples/**

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -21,17 +22,17 @@ jobs:
uses: actions/setup-node@v2
with:
node-version: '18'
cache: 'npm'
cache: 'pnpm'
registry-url: 'https://registry.npmjs.org'

- name: Install and Build 🔧
run: |
cd tools/create-yorkie-app
npm install
npm run build
cd packages/create-yorkie-app
pnpm install
pnpm build
- name: Publish 🚀
run: cd tools/create-yorkie-app && npm publish --provenance
run: cd packages/create-yorkie-app && pnpm publish --provenance
continue-on-error: true
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
12 changes: 6 additions & 6 deletions .github/workflows/devtools-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- 'main'
paths:
- tools/devtools/**
- packages/devtools/**
jobs:
build-and-deploy:
runs-on: ubuntu-latest
Expand All @@ -17,16 +17,16 @@ jobs:
uses: actions/setup-node@v2
with:
node-version: '18'
cache: 'npm'
cache: 'pnpm'

- name: Install and Build 🔧
run: |
cd tools/devtools
npm install
npm run build
cd packages/devtools
pnpm install
pnpm build
- name: Deploy 🚀
uses: PlasmoHQ/bpp@v3
with:
keys: ${{ secrets.BPP_KEYS }}
chrome-file: 'tools/devtools/dist/chrome-mv3-prod.zip'
chrome-file: 'packages/devtools/dist/chrome-mv3-prod.zip'
22 changes: 11 additions & 11 deletions .github/workflows/github-page-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@ jobs:
uses: actions/setup-node@v2
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: package-lock.json
cache: 'pnpm'
cache-dependency-path: pnpm-lock.yaml

- name: Cache Node Moudles
- name: Cache pnpm store
id: cache
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-node-
${{ runner.os }}-pnpm-
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm install
run: pnpm install

- name: Build 🔧
run: |
npm run build
npm run build:docs
npm run build:examples
npm run build:ghpages
pnpm sdk build
pnpm sdk build:docs
pnpm build:examples
pnpm sdk build:ghpages
- name: Deploy 🚀
uses: peaceiris/actions-gh-pages@v3
Expand Down
21 changes: 12 additions & 9 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,31 @@ jobs:
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Setup Node 🔧
uses: actions/setup-node@v2
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: package-lock.json
cache: 'pnpm'
cache-dependency-path: pnpm-lock.yaml
registry-url: 'https://registry.npmjs.org'

- name: Cache Node Moudles
- name: Cache pnpm store
id: cache
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-node-
${{ runner.os }}-pnpm-
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm install
run: pnpm install

- run: npm run build
- run: npm publish --provenance
- run: pnpm sdk build
- run: pnpm publish --provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,6 @@ lib/

# profile output
*.cpuprofile

# npm
**/package-lock.json
3 changes: 2 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
engine-strict=true
engine-strict=true
@buf:registry=https://buf.build/gen/npm/v1
25 changes: 17 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,21 @@ Thanks for contributing!

### Building yorkie-js-sdk

For building yorkie-js-sdk, You'll first need Node.js installed(Node.js version 18+ and npm version 7.10+ are required).
For building yorkie-js-sdk, You'll first need Node.js installed(Node.js version 18+ and pnpm version 9.6+ are required).

- [Node.js](https://nodejs.org/en) (version 18+)
- [npm](https://www.npmjs.com/) (version 7.10+)
- [pnpm](https://pnpm.io/) (version 9.6+)

```bash
# install packages
$ npm install

# In the root directory of the repository.
$ pnpm sdk install

# build
$ npm run build

# In the root directory of the repository.
$ pnpm sdk build
```

To generate proto messages, we use protoc-gen-connect-es, which is a code generator plugin for Protocol Buffer compilers, like buf and protoc. It generates both clients and server definitions from Protocol Buffer schema.
Expand All @@ -55,7 +59,9 @@ For more details, see [@connectrpc/protoc-gen-connect-es](https://github.com/con

```bash
# generate proto messages and the service client stub classes
$ npm run build:proto

# In the root directory of the repository.
$ pnpm sdk build:proto
```

> Primary "source of truth" location of protobuf message is
Expand All @@ -72,7 +78,8 @@ $ docker compose -f docker/docker-compose.yml up --build -d
Start the test in another terminal session.

```bash
$ npm run test
# In the root directory of the repository.
$ pnpm sdk test
```

To get the latest server locally, run the command below then restart containers again:
Expand Down Expand Up @@ -108,7 +115,8 @@ To run only specific suites or tests, use `.only` and execute the following comm
Refer to [Test Filtering](https://vitest.dev/guide/filtering#selecting-suites-and-tests-to-run) in `vitest` for more details:

```bash
$ npm run test {test file path} # e.g. npm run test integration/tree_test.ts
# In the root directory of the repository.
$ pnpm sdk test {test file path} # e.g. pnpm sdk test integration/tree_test.ts
```

### Starting co-editing example with CodeMirror
Expand All @@ -122,7 +130,8 @@ $ docker compose -f docker/docker-compose.yml up --build -d
Start the webpack-dev-server in another terminal session.

```bash
$ npm run dev
# In the root directory of the repository.
$ pnpm sdk dev
```

Open the co-editing example page served by webpack-dev-server in your browser.
Expand Down
14 changes: 9 additions & 5 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@ $ docker compose -f docker/docker-compose.yml up --build -d
The examples have own local dependencies. So you should install dependencies before running examples.

```bash
# In the directory of the example.
$ npm install
# In the root directory of the repository.
$ pnpm install
```

Then you can run the examples.

```bash
# In the directory of the example.
$ npm run dev
# In the root directory of the repository.
$ pnpm <EXAMPLE-NAME> dev

# Or in the directory of the example.
$ pnpm dev
```

Open the browser and go to the URL that is printed in the terminal.

## Releasing an example to https://yorkie.dev

To release an example, the example should export static files to `./dist` directory when running `npm run build`.
To release an example, the example should export static files to `./dist` directory when running `pnpm <EXAMPLE-NAME> build` in the root directory of the repository or `pnpm build` in the directory of the example.

After the example is merged to the `main` branch, it is automatically deployed to https://yorkie.dev/yorkie-js-sdk/examples/{EXAMPLE-NAME}.
1 change: 1 addition & 0 deletions examples/nextjs-scheduler/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
extends: ['next', 'plugin:prettier/recommended'],
rules: {
'prettier/prettier': [
'error',
Expand Down
9 changes: 7 additions & 2 deletions examples/nextjs-scheduler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ $ docker compose -f docker/docker-compose.yml up --build -d
Then install dependencies and run the demo.

```bash
$ npm install
# In the root directory of the repository.
$ pnpm install
```

Now you can run the demo.

```bash
$ npm run dev
# In the root directory of the repository.
$ pnpm nextjs-scheduler dev

# Or in the directory of the example.
$ pnpm dev
```
Loading

0 comments on commit e84ba27

Please sign in to comment.