pulse-js-framework 1.7.1 → 1.7.3
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 +55 -39
- package/cli/release.js +2 -3
- package/package.json +8 -2
- package/runtime/async.js +619 -0
- package/runtime/devtools.js +619 -0
- package/runtime/dom.js +254 -40
- package/runtime/form.js +659 -0
- package/runtime/pulse.js +36 -3
- package/runtime/router.js +51 -5
- package/runtime/store.js +45 -0
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
|
|
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
|
|
76
|
-
if (pathname === '/
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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(
|
|
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
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
|
272
|
+
* Notify connected LiveReload clients
|
|
234
273
|
*/
|
|
235
|
-
function notifyClients(
|
|
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.
|
|
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
|
|
823
|
-
log.info(`
|
|
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.
|
|
3
|
+
"version": "1.7.3",
|
|
4
4
|
"description": "A declarative DOM framework with CSS selector-based structure and reactive pulsations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -52,6 +52,9 @@
|
|
|
52
52
|
},
|
|
53
53
|
"./runtime/lru-cache": "./runtime/lru-cache.js",
|
|
54
54
|
"./runtime/utils": "./runtime/utils.js",
|
|
55
|
+
"./runtime/async": "./runtime/async.js",
|
|
56
|
+
"./runtime/form": "./runtime/form.js",
|
|
57
|
+
"./runtime/devtools": "./runtime/devtools.js",
|
|
55
58
|
"./compiler": {
|
|
56
59
|
"types": "./types/index.d.ts",
|
|
57
60
|
"default": "./compiler/index.js"
|
|
@@ -80,7 +83,7 @@
|
|
|
80
83
|
"LICENSE"
|
|
81
84
|
],
|
|
82
85
|
"scripts": {
|
|
83
|
-
"test": "npm run test:compiler && npm run test:sourcemap && npm run test:pulse && npm run test:dom && npm run test:router && npm run test:store && npm run test:hmr && npm run test:lint && npm run test:format && npm run test:analyze && npm run test:lru-cache && npm run test:utils && npm run test:docs",
|
|
86
|
+
"test": "npm run test:compiler && npm run test:sourcemap && npm run test:pulse && npm run test:dom && npm run test:router && npm run test:store && npm run test:hmr && npm run test:lint && npm run test:format && npm run test:analyze && npm run test:lru-cache && npm run test:utils && npm run test:docs && npm run test:async && npm run test:form && npm run test:devtools",
|
|
84
87
|
"test:compiler": "node test/compiler.test.js",
|
|
85
88
|
"test:sourcemap": "node test/sourcemap.test.js",
|
|
86
89
|
"test:pulse": "node test/pulse.test.js",
|
|
@@ -94,6 +97,9 @@
|
|
|
94
97
|
"test:lru-cache": "node test/lru-cache.test.js",
|
|
95
98
|
"test:utils": "node test/utils.test.js",
|
|
96
99
|
"test:docs": "node test/docs.test.js",
|
|
100
|
+
"test:async": "node test/async.test.js",
|
|
101
|
+
"test:form": "node test/form.test.js",
|
|
102
|
+
"test:devtools": "node test/devtools.test.js",
|
|
97
103
|
"build:netlify": "node scripts/build-netlify.js",
|
|
98
104
|
"version": "node scripts/sync-version.js",
|
|
99
105
|
"docs": "node cli/index.js dev docs"
|