@@ -4,6 +4,8 @@ import * as FileSystem from '@effect/platform/FileSystem';
44import * as Path from '@effect/platform/Path' ;
55import * as Data from 'effect/Data' ;
66import * as Effect from 'effect/Effect' ;
7+ import * as fsSync from 'node:fs' ;
8+ import * as nodePath from 'node:path' ;
79
810import * as Domain from '../domain/Domain.js' ;
911import * as Utils from './Utils.js' ;
@@ -25,11 +27,27 @@ export class SchemaGenerator extends Effect.Service<SchemaGenerator>()('/typesyn
2527 codegen ( app : Domain . InsertAppSchema ) {
2628 return Effect . gen ( function * ( ) {
2729 // check directory
28- /** @todo solve directory pathing */
29- let directory = app . directory ;
30- if ( ! directory ) {
31- directory = `./${ app . name } ` ;
32- }
30+ /**
31+ * Decide where to place the new application.
32+ * If the caller explicitly provides `app.directory` we respect it.
33+ * Otherwise, we always create the application inside the repository-root
34+ * `apps` folder so it shows up next to `connect`, `events`, etc.
35+ */
36+
37+ // 1. Locate the repo root by walking up until we find `pnpm-workspace.yaml`
38+ const findRepoRoot = ( start : string ) : string => {
39+ let dir = start ;
40+ while ( true ) {
41+ if ( fsSync . existsSync ( nodePath . join ( dir , 'pnpm-workspace.yaml' ) ) ) return dir ;
42+ const parent = nodePath . dirname ( dir ) ;
43+ if ( parent === dir ) return start ; // Fallback if we can't find it
44+ dir = parent ;
45+ }
46+ } ;
47+
48+ const repoRoot = findRepoRoot ( process . cwd ( ) ) ;
49+
50+ let directory = app . directory ?. length ? app . directory : nodePath . join ( repoRoot , 'apps' , app . name ) ;
3351 const directoryExists = yield * fs . exists ( directory ) ;
3452 if ( directoryExists ) {
3553 // directory already exists, fail
@@ -72,13 +90,14 @@ export class SchemaGenerator extends Effect.Service<SchemaGenerator>()('/typesyn
7290 // 3. Run `pnpm install` at repo root to update lockfile/hoist
7391 // -----------------------------
7492
75- const workspaceFile = 'pnpm-workspace.yaml' ;
93+ const workspaceFile = nodePath . join ( repoRoot , 'pnpm-workspace.yaml' ) ;
7694 const workspaceExists = yield * fs . exists ( workspaceFile ) ;
7795 if ( workspaceExists ) {
7896 const current = yield * fs . readFileString ( workspaceFile ) ;
7997 const lines = current . split ( '\n' ) ;
8098
81- const newPackageLine = ` - ${ directory } ` ;
99+ const relPackagePath = nodePath . relative ( repoRoot , directory ) ;
100+ const newPackageLine = ` - ${ relPackagePath } ` ;
82101 const alreadyExists = lines . some ( ( line ) => line . trim ( ) === newPackageLine . trim ( ) ) ;
83102
84103 if ( ! alreadyExists ) {
0 commit comments