pulse-js-framework 1.7.0 → 1.7.2

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/cli/dev.js CHANGED
@@ -25,9 +25,29 @@ const MIME_TYPES = {
25
25
  '.woff2': 'font/woff2'
26
26
  };
27
27
 
28
- // Connected clients for HMR
28
+ // Connected clients for LiveReload (Server-Sent Events)
29
29
  const clients = new Set();
30
30
 
31
+ // LiveReload client script injected into HTML
32
+ const LIVERELOAD_SCRIPT = `
33
+ <script>
34
+ (function() {
35
+ var es = new EventSource('/__pulse_livereload');
36
+ es.onmessage = function(e) {
37
+ if (e.data === 'reload') {
38
+ console.log('[Pulse] Reloading...');
39
+ location.reload();
40
+ }
41
+ };
42
+ es.onerror = function() {
43
+ console.log('[Pulse] Connection lost, reconnecting...');
44
+ es.close();
45
+ setTimeout(function() { location.reload(); }, 2000);
46
+ };
47
+ })();
48
+ </script>
49
+ </body>`;
50
+
31
51
  /**
32
52
  * Start the development server
33
53
  */
@@ -72,11 +92,18 @@ export async function startDevServer(args) {
72
92
  const url = new URL(req.url, `http://localhost:${port}`);
73
93
  let pathname = url.pathname;
74
94
 
75
- // Handle HMR WebSocket upgrade
76
- if (pathname === '/__pulse_hmr') {
77
- // This would need WebSocket support
78
- res.writeHead(200);
79
- res.end();
95
+ // Handle LiveReload SSE endpoint
96
+ if (pathname === '/__pulse_livereload') {
97
+ res.writeHead(200, {
98
+ 'Content-Type': 'text/event-stream',
99
+ 'Cache-Control': 'no-cache',
100
+ 'Connection': 'keep-alive',
101
+ 'Access-Control-Allow-Origin': '*'
102
+ });
103
+ res.write('data: connected\n\n');
104
+
105
+ clients.add(res);
106
+ req.on('close', () => clients.delete(res));
80
107
  return;
81
108
  }
82
109
 
@@ -188,8 +215,15 @@ export async function startDevServer(args) {
188
215
  const ext = extname(filePath);
189
216
  const mimeType = MIME_TYPES[ext] || 'application/octet-stream';
190
217
 
218
+ let content = readFileSync(filePath);
219
+
220
+ // Inject LiveReload script into HTML files
221
+ if (ext === '.html') {
222
+ content = content.toString().replace('</body>', LIVERELOAD_SCRIPT);
223
+ }
224
+
191
225
  res.writeHead(200, { 'Content-Type': mimeType });
192
- res.end(readFileSync(filePath));
226
+ res.end(content);
193
227
  return;
194
228
  }
195
229
 
@@ -213,57 +247,39 @@ export async function startDevServer(args) {
213
247
  }
214
248
 
215
249
  /**
216
- * Watch files for changes
250
+ * Watch files for changes and trigger LiveReload
217
251
  */
218
252
  function watchFiles(root) {
219
253
  const srcDir = join(root, 'src');
254
+ let debounceTimer = null;
220
255
 
221
256
  if (existsSync(srcDir)) {
222
257
  watch(srcDir, { recursive: true }, (eventType, filename) => {
223
- if (filename && filename.endsWith('.pulse')) {
224
- log.debug(`File changed: ${filename}`);
225
- // Notify HMR clients (simplified)
226
- notifyClients({ type: 'update', path: `/src/${filename}` });
258
+ if (filename && (filename.endsWith('.pulse') || filename.endsWith('.js') || filename.endsWith('.css'))) {
259
+ // Debounce to avoid multiple reloads
260
+ if (debounceTimer) clearTimeout(debounceTimer);
261
+ debounceTimer = setTimeout(() => {
262
+ log.info(`File changed: ${filename}`);
263
+ notifyClients('reload');
264
+ }, 100);
227
265
  }
228
266
  });
267
+ log.debug('Watching src/ for changes...');
229
268
  }
230
269
  }
231
270
 
232
271
  /**
233
- * Notify connected HMR clients
272
+ * Notify connected LiveReload clients
234
273
  */
235
- function notifyClients(message) {
274
+ function notifyClients(type = 'reload') {
275
+ log.info(`[LiveReload] Notifying ${clients.size} client(s)...`);
236
276
  for (const client of clients) {
237
277
  try {
238
- client.send(JSON.stringify(message));
278
+ client.write(`data: ${type}\n\n`);
239
279
  } catch (e) {
240
280
  clients.delete(client);
241
281
  }
242
282
  }
243
283
  }
244
284
 
245
- /**
246
- * Get HMR client code
247
- */
248
- function getHMRClient() {
249
- return `
250
- (function() {
251
- const ws = new WebSocket('ws://' + location.host + '/__pulse_hmr');
252
-
253
- ws.onmessage = function(event) {
254
- const data = JSON.parse(event.data);
255
- if (data.type === 'update') {
256
- console.log('[Pulse HMR] Update:', data.path);
257
- location.reload();
258
- }
259
- };
260
-
261
- ws.onclose = function() {
262
- console.log('[Pulse HMR] Connection lost, reconnecting...');
263
- setTimeout(() => location.reload(), 1000);
264
- };
265
- })();
266
- `;
267
- }
268
-
269
285
  export default { startDevServer };
package/cli/release.js CHANGED
@@ -819,8 +819,7 @@ export async function runRelease(args) {
819
819
  }
820
820
 
821
821
  if (!dryRun && !noPush) {
822
- log.info('Next steps:');
823
- log.info(` 1. Create GitHub release: https://github.com/vincenthirtz/pulse-js-framework/releases/new?tag=v${newVersion}`);
824
- log.info(' 2. Publish to npm: npm publish');
822
+ log.info('Next step:');
823
+ log.info(` Create GitHub release: https://github.com/vincenthirtz/pulse-js-framework/releases/new?tag=v${newVersion}`);
825
824
  }
826
825
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pulse-js-framework",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "description": "A declarative DOM framework with CSS selector-based structure and reactive pulsations",
5
5
  "type": "module",
6
6
  "main": "index.js",