11import { createServer } from 'vite' ;
22import react from '@vitejs/plugin-react' ;
3- import { existsSync , readFileSync , writeFileSync , mkdirSync , realpathSync } from 'fs' ;
4- import { join , resolve , dirname } from 'path' ;
3+ import { existsSync , readFileSync , writeFileSync , mkdirSync } from 'fs' ;
4+ import { join , resolve } from 'path' ;
55import chalk from 'chalk' ;
6- import { fileURLToPath } from 'url' ;
7-
8- const __filename = fileURLToPath ( import . meta. url ) ;
9- const __dirname = dirname ( __filename ) ;
106
117interface ServeOptions {
128 port : string ;
139 host : string ;
1410}
1511
16- // Check if we're running from the monorepo
17- function isInMonorepo ( ) : boolean {
18- try {
19- const cliRoot = resolve ( __dirname , '../..' ) ;
20- const monorepoRoot = resolve ( cliRoot , '../..' ) ;
21- return existsSync ( join ( monorepoRoot , 'pnpm-workspace.yaml' ) ) ;
22- } catch {
23- return false ;
24- }
25- }
26-
2712export async function serve ( schemaPath : string , options : ServeOptions ) {
2813 const cwd = process . cwd ( ) ;
2914 const fullSchemaPath = resolve ( cwd , schemaPath ) ;
@@ -48,26 +33,21 @@ export async function serve(schemaPath: string, options: ServeOptions) {
4833 const tmpDir = join ( cwd , '.objectui-tmp' ) ;
4934 mkdirSync ( tmpDir , { recursive : true } ) ;
5035
51- // Determine if we should use workspace or npm packages
52- const useWorkspace = isInMonorepo ( ) ;
53-
5436 // Create temporary app files
55- createTempApp ( tmpDir , schema , useWorkspace ) ;
56-
57- if ( ! useWorkspace ) {
58- // Install dependencies only when not in workspace
59- console . log ( chalk . blue ( '📦 Installing dependencies...' ) ) ;
60- console . log ( chalk . dim ( ' This may take a moment on first run...' ) ) ;
61- const { execSync } = await import ( 'child_process' ) ;
62- try {
63- execSync ( 'npm install --silent --prefer-offline' , {
64- cwd : tmpDir ,
65- stdio : 'inherit' ,
66- } ) ;
67- console . log ( chalk . green ( '✓ Dependencies installed' ) ) ;
68- } catch ( error ) {
69- throw new Error ( 'Failed to install dependencies. Please check your internet connection and try again.' ) ;
70- }
37+ createTempApp ( tmpDir , schema ) ;
38+
39+ // Install dependencies
40+ console . log ( chalk . blue ( '📦 Installing dependencies...' ) ) ;
41+ console . log ( chalk . dim ( ' This may take a moment on first run...' ) ) ;
42+ const { execSync } = await import ( 'child_process' ) ;
43+ try {
44+ execSync ( 'npm install --silent --prefer-offline' , {
45+ cwd : tmpDir ,
46+ stdio : 'inherit' ,
47+ } ) ;
48+ console . log ( chalk . green ( '✓ Dependencies installed' ) ) ;
49+ } catch ( error ) {
50+ throw new Error ( 'Failed to install dependencies. Please check your internet connection and try again.' ) ;
7151 }
7252
7353 console . log ( chalk . green ( '✓ Schema loaded successfully' ) ) ;
@@ -84,19 +64,6 @@ export async function serve(schemaPath: string, options: ServeOptions) {
8464 plugins : [ react ( ) ] ,
8565 } ;
8666
87- // If in workspace, add resolve aliases
88- if ( useWorkspace ) {
89- const monorepoRoot = resolve ( __dirname , '../../../..' ) ;
90- viteConfig . resolve = {
91- alias : {
92- '@object-ui/react' : resolve ( monorepoRoot , 'packages/react/src' ) ,
93- '@object-ui/components' : resolve ( monorepoRoot , 'packages/components/src' ) ,
94- '@object-ui/core' : resolve ( monorepoRoot , 'packages/core/src' ) ,
95- '@object-ui/types' : resolve ( monorepoRoot , 'packages/types/src' ) ,
96- } ,
97- } ;
98- }
99-
10067 // Create Vite server
10168 const server = await createServer ( viteConfig ) ;
10269
@@ -115,7 +82,7 @@ export async function serve(schemaPath: string, options: ServeOptions) {
11582 console . log ( ) ;
11683}
11784
118- function createTempApp ( tmpDir : string , schema : any , useWorkspace : boolean ) {
85+ function createTempApp ( tmpDir : string , schema : any ) {
11986 // Create index.html
12087 const html = `<!DOCTYPE html>
12188<html lang="en">
@@ -164,10 +131,12 @@ export default App;`;
164131
165132 writeFileSync ( join ( srcDir , 'App.tsx' ) , appTsx ) ;
166133
167- // Create index.css with Tailwind
134+ // Create index.css
168135 const indexCss = `@tailwind base;
169136@tailwind components;
170137@tailwind utilities;
138+ @tailwind components;
139+ @tailwind utilities;
171140
172141@layer base {
173142 :root {
@@ -305,27 +274,19 @@ export default {
305274 autoprefixer: {},
306275 },
307276};` ;
308-
277+
309278 writeFileSync ( join ( tmpDir , 'postcss.config.js' ) , postcssConfig ) ;
310279
311- // Create package.json with published packages or workspace
280+ // Create package.json
312281 const packageJson = {
313282 name : 'objectui-temp-app' ,
314283 private : true ,
315284 type : 'module' ,
316285 dependencies : {
317286 react : '^18.3.1' ,
318287 'react-dom' : '^18.3.1' ,
319- ...( useWorkspace
320- ? {
321- '@object-ui/react' : 'workspace:*' ,
322- '@object-ui/components' : 'workspace:*' ,
323- }
324- : {
325- '@object-ui/react' : '^0.1.0' ,
326- '@object-ui/components' : '^0.1.0' ,
327- }
328- ) ,
288+ '@object-ui/react' : '^0.1.0' ,
289+ '@object-ui/components' : '^0.1.0' ,
329290 } ,
330291 devDependencies : {
331292 '@types/react' : '^18.3.12' ,
0 commit comments