onelaraveljs 1.1.4 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onelaraveljs",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "OneLaravel JS Framework Core & Compiler",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -9,7 +9,7 @@
9
9
  */
10
10
 
11
11
  import { spawn } from 'child_process';
12
- import { watch } from 'fs';
12
+ import { watch, existsSync } from 'fs';
13
13
  import { readFileSync, writeFileSync } from 'fs';
14
14
  import path from 'path';
15
15
  import { fileURLToPath } from 'url';
@@ -20,6 +20,7 @@ const __dirname = path.dirname(__filename);
20
20
 
21
21
  // Get context from command line argument
22
22
  const context = process.argv[2] || 'web'; // Default to 'web'
23
+ const projectRoot = process.env.ONEJS_PROJECT_ROOT || process.cwd();
23
24
 
24
25
  if (!['web', 'admin'].includes(context)) {
25
26
  console.error('❌ Invalid context. Use: web or admin');
@@ -27,7 +28,6 @@ if (!['web', 'admin'].includes(context)) {
27
28
  }
28
29
 
29
30
  // Load build config
30
- const projectRoot = process.env.ONEJS_PROJECT_ROOT || process.cwd();
31
31
  const buildConfigPath = path.resolve(projectRoot, 'build.config.json');
32
32
  const buildConfig = JSON.parse(readFileSync(buildConfigPath, 'utf-8'));
33
33
  const contextConfig = buildConfig.contexts[context];
@@ -42,9 +42,6 @@ const config = {
42
42
  watchPaths: {
43
43
  blade: contextConfig.sources, // Array of blade source paths from config
44
44
  jsCore: 'resources/js', // Watch entire js directory
45
- jsViewsExclude: 'resources/js/views', // Exclude views directory
46
- jsBuildExclude: 'resources/js/build',
47
- jsConfigExclude: 'resources/js/config',
48
45
  compiler: 'node_modules/onelaraveljs/scripts/compiler'
49
46
  },
50
47
  buildCommand: `npm run build:${context}`,
@@ -65,7 +62,8 @@ class ContextDevServer {
65
62
  }
66
63
 
67
64
  async start() {
68
- console.log(`🚀 Starting Development Server for [${config.context.toUpperCase()}] context...\n`);
65
+ console.log(`🚀 Starting Development Server for [${config.context.toUpperCase()}] context...`);
66
+ console.log(`📂 Project Root: ${projectRoot}\n`);
69
67
 
70
68
  // Initial build (templates + webpack)
71
69
  await this.runBuild();
@@ -86,7 +84,7 @@ class ContextDevServer {
86
84
  console.log(`📦 Context: ${config.context.toUpperCase()}`);
87
85
  console.log('📝 Watching:');
88
86
  console.log(` - Blade files: ${config.watchPaths.blade.join(', ')}`);
89
- console.log(` - JS Core: ${config.watchPaths.jsCore} (excluding views)`);
87
+ console.log(` - JS Core: ${config.watchPaths.jsCore} (excluding generated views)`);
90
88
  console.log(` - Compiler: ${config.watchPaths.compiler}`);
91
89
  console.log(`🌐 Laravel Server: http://localhost:${config.phpPort}`);
92
90
  console.log(`🔄 Auto-reload: Active (add script to your layout)`);
@@ -108,7 +106,7 @@ class ContextDevServer {
108
106
  return new Promise((resolve, reject) => {
109
107
  const build = spawn('sh', ['-c', config.buildCommand], {
110
108
  stdio: 'inherit',
111
- cwd: path.resolve(__dirname, '..')
109
+ cwd: projectRoot
112
110
  });
113
111
 
114
112
  build.on('close', (code) => {
@@ -182,7 +180,7 @@ class ContextDevServer {
182
180
  })();
183
181
  `;
184
182
 
185
- const publicPath = path.resolve(__dirname, '../public/reload-dev.js');
183
+ const publicPath = path.resolve(projectRoot, 'public/reload-dev.js');
186
184
  writeFileSync(publicPath, scriptContent, 'utf-8');
187
185
  console.log(`✅ Created reload script at public/reload-dev.js\n`);
188
186
  }
@@ -190,9 +188,9 @@ class ContextDevServer {
190
188
  startPhpServe() {
191
189
  console.log(`🐘 Starting PHP server on port ${config.phpPort}...`);
192
190
 
193
- this.processes.phpServe = spawn('php', ['artisan', 'serve', `--port=${config.phpPort}`], {
194
- stdio: 'inherit',
195
- cwd: path.resolve(__dirname, '..')
191
+ this.processes.phpServe = spawn('php', ['artisan', 'serve', `--port=${config.phpPort}`],
192
+ { stdio: 'inherit',
193
+ cwd: projectRoot
196
194
  });
197
195
 
198
196
  this.processes.phpServe.on('error', (err) => {
@@ -209,33 +207,63 @@ class ContextDevServer {
209
207
  startWatcher() {
210
208
  // Watch blade files (multiple source directories from config)
211
209
  config.watchPaths.blade.forEach(bladePath => {
212
- console.log(`👀 Watching blade files in: ${bladePath}`);
213
- watch(bladePath, { recursive: true }, (eventType, filename) => {
214
- if (filename && filename.endsWith('.blade.php')) {
215
- this.handleFileChange('blade', path.join(bladePath, filename));
216
- }
217
- });
210
+ const absoluteBladePath = path.resolve(projectRoot, bladePath);
211
+ if (existsSync(absoluteBladePath)) {
212
+ console.log(`👀 Watching blade files in: ${bladePath}`);
213
+ watch(absoluteBladePath, { recursive: true }, (eventType, filename) => {
214
+ if (filename && filename.endsWith('.blade.php')) {
215
+ this.handleFileChange('blade', path.join(bladePath, filename));
216
+ }
217
+ });
218
+ } else {
219
+ console.warn(`⚠️ Blade path not found: ${bladePath}`);
220
+ }
218
221
  });
219
222
 
220
- // Watch JS core files (entire onejs directory, excluding views)
221
- console.log(`👀 Watching JS core in: ${config.watchPaths.jsCore} (excluding views)`);
222
- watch(config.watchPaths.jsCore, { recursive: true }, (eventType, filename) => {
223
- if (filename && filename.endsWith('.js')) {
224
- const fullPath = path.join(config.watchPaths.jsCore, filename);
225
- // Skip if file is in views directory
226
- if (!fullPath.includes(path.sep + 'views' + path.sep) && !fullPath.endsWith(path.sep + 'views')) {
227
- this.handleFileChange('js-core', filename);
223
+ // Watch JS core files (resources/js)
224
+ const jsCorePath = path.resolve(projectRoot, config.watchPaths.jsCore);
225
+ if (existsSync(jsCorePath)) {
226
+ console.log(`👀 Watching JS core in: ${config.watchPaths.jsCore}`);
227
+ watch(jsCorePath, { recursive: true }, (eventType, filename) => {
228
+ if (filename && filename.endsWith('.js')) {
229
+ const fullPath = path.join(jsCorePath, filename);
230
+ // Skip if file is in excluded directories
231
+ const isInViews = fullPath.includes(path.sep + 'views' + path.sep) || fullPath.endsWith(path.sep + 'views');
232
+ const isInBuild = fullPath.includes(path.sep + 'build' + path.sep) || fullPath.endsWith(path.sep + 'build');
233
+ const isInConfig = fullPath.includes(path.sep + 'config' + path.sep) || fullPath.endsWith(path.sep + 'config');
234
+ const isGeneratedCore = fullPath.includes(path.sep + 'core' + path.sep + 'ViewTemplate.js');
235
+
236
+ if (!isInViews && !isInBuild && !isInConfig && !isGeneratedCore) {
237
+ this.handleFileChange('js-core', filename);
238
+ }
228
239
  }
229
- }
230
- });
240
+ });
241
+ }
231
242
 
232
- // Watch compiler files
233
- console.log(`👀 Watching compiler in: ${config.watchPaths.compiler}`);
234
- watch(config.watchPaths.compiler, { recursive: true }, (eventType, filename) => {
235
- if (filename && (filename.endsWith('.py') || filename.endsWith('.js'))) {
236
- this.handleFileChange('compiler', filename);
237
- }
238
- });
243
+ // Watch compiler files - Check if exists first to avoid crash
244
+ let compilerPath = config.watchPaths.compiler;
245
+ // fallback mainly for dev env if scripts/compiler exists
246
+ if (!compilerPath.includes('node_modules')) {
247
+ if (!require('fs').existsSync(path.resolve(projectRoot, 'scripts/compiler'))) {
248
+ // Try looking in node_modules
249
+ compilerPath = path.resolve(projectRoot, 'node_modules/onelaraveljs/scripts/compiler');
250
+ } else {
251
+ compilerPath = path.resolve(projectRoot, 'scripts/compiler');
252
+ }
253
+ } else {
254
+ compilerPath = path.resolve(projectRoot, compilerPath);
255
+ }
256
+
257
+ if (require('fs').existsSync(compilerPath)) {
258
+ console.log(`👀 Watching compiler in: ${compilerPath}`);
259
+ watch(compilerPath, { recursive: true }, (eventType, filename) => {
260
+ if (filename && (filename.endsWith('.py') || filename.endsWith('.js'))) {
261
+ this.handleFileChange('compiler', filename);
262
+ }
263
+ });
264
+ } else {
265
+ console.log(`⚠️ Compiler path not found for watching: ${compilerPath}`);
266
+ }
239
267
  }
240
268
 
241
269
  handleFileChange(type, filename) {