Skip to content

Commit 93f0ad8

Browse files
committed
fix(typesync): package client UI in dist and store data in .typesync.db
1 parent 3d0940d commit 93f0ad8

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

apps/typesync/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"coverage": "vitest run --coverage",
3434
"copy-package-json": "tsx scripts/copy-package-json.ts",
3535
"copy-db-migrations": "cp ./src/migrations/_schema.sql ./dist/migrations/_schema.sql",
36-
"copy-client-dist": "mkdir -p ./dist/client && cp -rp ./client/dist ./dist/client/dist",
36+
"copy-client-dist": "tsx scripts/copy-client-dist.ts",
3737
"copy-all": "pnpm run copy-package-json && pnpm run copy-db-migrations && pnpm run copy-client-dist",
3838
"typesync": "pnpx tsx ./src/bin.ts studio"
3939
},
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { cp, mkdir } from 'node:fs/promises';
2+
import { resolve } from 'node:path';
3+
4+
(async () => {
5+
try {
6+
const src = resolve(process.cwd(), 'client', 'dist');
7+
const dest = resolve(process.cwd(), 'dist', 'client', 'dist');
8+
9+
await mkdir(dest, { recursive: true });
10+
// Node >=16.7 has cp with recursive
11+
await cp(src, dest, { recursive: true });
12+
13+
console.info('[Build] Copied client/dist to dist/client/dist');
14+
} catch (err) {
15+
console.error('[Build] Failed to copy client/dist', err);
16+
process.exitCode = 1;
17+
}
18+
})();

apps/typesync/src/Database.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import * as TypesyncDomain from '../domain/Domain.js';
2020
import * as Domain from './Domain.js';
2121

2222
const SqlLive = SqliteClient.layer({
23-
filename: 'typesync.db',
23+
filename: '.typesync.db',
2424
});
2525
const MigratorLive = Migrator.layer({
2626
loader: Migrator.fromFileSystem(fileURLToPath(new URL('migrations', import.meta.url))),

apps/typesync/src/Server.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
/** Defines the static file routes for serving the client dist directory with the built vite/react app */
22

3+
import * as NodePath from 'node:path';
4+
import { fileURLToPath } from 'node:url';
35
import * as HttpMiddleware from '@effect/platform/HttpMiddleware';
46
import * as HttpRouter from '@effect/platform/HttpRouter';
57
import * as HttpServer from '@effect/platform/HttpServer';
68
import * as HttpServerResponse from '@effect/platform/HttpServerResponse';
7-
import * as Path from '@effect/platform/Path';
89
import * as Effect from 'effect/Effect';
910
import * as Layer from 'effect/Layer';
1011
import * as Option from 'effect/Option';
1112
import * as Struct from 'effect/Struct';
1213

1314
import * as Api from './Api.js';
1415

15-
const FilesRouter = Effect.gen(function* () {
16-
const path = yield* Path.Path;
16+
const __dirname = NodePath.dirname(fileURLToPath(import.meta.url));
17+
const CLIENT_DIST_DIR = NodePath.resolve(__dirname, 'client', 'dist');
1718

19+
const FilesRouter = Effect.gen(function* () {
1820
return HttpRouter.empty.pipe(
1921
HttpRouter.get(
2022
'/',
21-
HttpServerResponse.file(path.resolve('client', 'dist', 'index.html')).pipe(
23+
HttpServerResponse.file(NodePath.join(CLIENT_DIST_DIR, 'index.html')).pipe(
2224
Effect.orElse(() => HttpServerResponse.empty({ status: 404 })),
2325
),
2426
),
@@ -31,8 +33,8 @@ const FilesRouter = Effect.gen(function* () {
3133
return HttpServerResponse.empty({ status: 404 });
3234
}
3335

34-
const assets = path.resolve('client', 'dist', 'assets');
35-
const normalized = path.normalize(path.join(assets, ...file.value.split('/')));
36+
const assets = NodePath.join(CLIENT_DIST_DIR, 'assets');
37+
const normalized = NodePath.normalize(NodePath.join(assets, ...file.value.split('/')));
3638
if (!normalized.startsWith(assets)) {
3739
return HttpServerResponse.empty({ status: 404 });
3840
}

0 commit comments

Comments
 (0)