Skip to content

Commit e383874

Browse files
authored
fix npm cli; parameterize yjs port in trpc router (#571)
1 parent 19a7aa3 commit e383874

File tree

6 files changed

+244
-180
lines changed

6 files changed

+244
-180
lines changed

BUILD.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Building CodePod
2+
3+
First build the UI:
4+
5+
```
6+
cd ui
7+
pnpm bulid
8+
```
9+
10+
This will generate the frontend html/js files into `api/public` folder. Then build the app in `api/` folder:
11+
12+
```
13+
cd api
14+
pnpm build
15+
```
16+
17+
This will generate `api/build/cli.js`. This is the binary executable. You can
18+
install and test the app locally:
19+
20+
```
21+
cd api
22+
npm install -g .
23+
```
24+
25+
Now the `codepod` command is available. Test:
26+
27+
```
28+
> which codepod
29+
# /opt/homebrew/bin/codepod
30+
> npm list --global
31+
# /opt/homebrew/lib
32+
# ├── [email protected] -> ./../../../Users/xxx/git/codepod/api
33+
> codepod /path/to/repo
34+
# ... 🚀 Server ready at http://localhost:4001
35+
```
36+
37+
Remove the globally installed local package:
38+
39+
```
40+
npm remove -g codepod
41+
```
42+
43+
Now it's ready to publish. We will first publish to npm registry. First login to
44+
npm-cli, upgrade the version in `api/package.json` then:
45+
46+
```
47+
npm publish
48+
```
49+
50+
Now it is in npm at https://www.npmjs.com/package/codepod. Install it from npm:
51+
52+
```
53+
# option 1: install
54+
npm install -g codepod
55+
codepod /path/to/repo
56+
57+
# option 2: run with npx without install
58+
npx codepod /path/to/repo
59+
```

api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codepod",
3-
"version": "0.0.4",
3+
"version": "0.0.5",
44
"license": "MIT",
55
"scripts": {
66
"build": "tsc",
@@ -9,7 +9,7 @@
99
"test": "jest --config jest.config.js"
1010
},
1111
"bin": {
12-
"codepod": "./build/bin.js"
12+
"codepod": "./build/cli.js"
1313
},
1414
"dependencies": {
1515
"@trpc/server": "^10.43.0",

api/src/bin.ts renamed to api/src/cli.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { startServer } from "./server";
99
// CMD: codepod /path/to/repo
1010

1111
program
12-
.version("0.0.1")
12+
// get the version from package.json
13+
.version(require("../package.json").version)
1314
.arguments("<repoPath>")
1415
.action(function (repoPath) {
1516
console.log("repoPath", repoPath);

api/src/server.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { createSetupWSConnection } from "./yjs/yjs-setupWS";
88
import { bindState, writeState } from "./yjs/yjs-blob";
99

1010
import cors from "cors";
11-
import { appRouter } from "./spawner/trpc";
11+
import { createSpawnerRouter, router } from "./spawner/trpc";
1212

1313
export async function startServer({ port, blobDir }) {
1414
console.log("starting server ..");
@@ -21,10 +21,14 @@ export async function startServer({ port, blobDir }) {
2121
console.log("html path: ", path);
2222
app.use(express.static(path));
2323

24+
const yjsServerUrl = `ws://localhost:${port}/socket`;
25+
2426
app.use(
2527
"/trpc",
2628
trpcExpress.createExpressMiddleware({
27-
router: appRouter,
29+
router: router({
30+
spawner: createSpawnerRouter(yjsServerUrl),
31+
}),
2832
})
2933
);
3034

0 commit comments

Comments
 (0)