clovie 0.1.1 → 0.1.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.
@@ -1,14 +1,53 @@
1
1
  import type from 'type-detect';
2
2
 
3
- const render = async (views, compiler, fileNames = Object.keys(views), accumulator = {}) => {
3
+ const render = async (views, compiler, fileNames = Object.keys(views), isDevMode = false, accumulator = {}) => {
4
4
  if (!fileNames || fileNames.length === 0) return accumulator;
5
5
 
6
+ // Live reload script to inject in development mode
7
+ const liveReloadScript = `
8
+ <!-- Live Reload Script (Development Mode Only) -->
9
+ <script src="https://cdn.socket.io/4.7.4/socket.io.min.js"></script>
10
+ <script>
11
+ (function() {
12
+ const socket = io();
13
+
14
+ socket.on('reload', () => {
15
+ console.log('🔄 Live reload triggered');
16
+ window.location.reload();
17
+ });
18
+
19
+ socket.on('connect', () => {
20
+ console.log('🔌 Connected to live reload server');
21
+ });
22
+
23
+ socket.on('disconnect', () => {
24
+ console.log('🔌 Disconnected from live reload server');
25
+ });
26
+
27
+ socket.on('connect_error', (error) => {
28
+ console.error('🔌 Connection error:', error);
29
+ });
30
+ })();
31
+ </script>`;
32
+
6
33
  for (const fileName of fileNames) {
7
34
  const view = views[fileName];
8
35
  if (!view || !view.template) continue;
9
36
 
10
37
  const res = compiler(view.template, {...view.data, fileName, fileNames});
11
- accumulator[fileName] = type(res) === 'Promise' ? await res : res;
38
+ let renderedContent = type(res) === 'Promise' ? await res : res;
39
+
40
+ // Inject live reload script before the last </body> tag if in development mode
41
+ if (isDevMode && renderedContent.includes('</body>')) {
42
+ const lastBodyIndex = renderedContent.lastIndexOf('</body>');
43
+ if (lastBodyIndex !== -1) {
44
+ renderedContent = renderedContent.substring(0, lastBodyIndex) +
45
+ liveReloadScript + '\n' +
46
+ renderedContent.substring(lastBodyIndex);
47
+ }
48
+ }
49
+
50
+ accumulator[fileName] = renderedContent;
12
51
  }
13
52
 
14
53
  return accumulator;
@@ -131,9 +131,19 @@ export class SmartWatcher {
131
131
  const getViews = await import('./getViews.js');
132
132
  this.clovie.views = getViews.default(this.clovie.config.views, this.clovie.config.models, this.clovie.data);
133
133
 
134
+ // Convert to the format expected by render (same as main build process)
135
+ this.clovie.processedViews = {};
136
+ for (const [key, value] of Object.entries(this.clovie.views)) {
137
+ if (value && value.template) {
138
+ // Use filename from model processing, or generate default
139
+ const fileName = value.filename || key.replace(/\.[^/.]+$/, '.html');
140
+ this.clovie.processedViews[fileName] = value;
141
+ }
142
+ }
143
+
134
144
  // Re-render all views using the render function
135
145
  const render = await import('./render.js');
136
- this.clovie.rendered = await render.default(this.clovie.views, this.clovie.config.compiler, Object.keys(this.clovie.views));
146
+ this.clovie.rendered = await render.default(this.clovie.processedViews, this.clovie.config.compiler, Object.keys(this.clovie.processedViews), this.clovie.isDevMode);
137
147
 
138
148
  // Write the updated views
139
149
  const write = await import('./write.js');
package/lib/main.js CHANGED
@@ -33,6 +33,7 @@ export default class Clovie {
33
33
  }
34
34
 
35
35
  this.errorCb = null;
36
+ this.isDevMode = false; // Track development mode
36
37
 
37
38
  // Initialize smart watcher
38
39
  this.watcher = new SmartWatcher(this);
@@ -50,6 +51,9 @@ export default class Clovie {
50
51
  try {
51
52
  console.log('🚀 Starting development server with smart watching...');
52
53
 
54
+ // Set development mode
55
+ this.isDevMode = true;
56
+
53
57
  // Do initial build
54
58
  console.log('📦 Building initial site...');
55
59
  await this.build();
@@ -119,7 +123,7 @@ export default class Clovie {
119
123
 
120
124
  // Render templates
121
125
  console.log('🎨 Rendering templates...');
122
- this.rendered = await render(this.processedViews, this.config.compiler, Object.keys(this.processedViews));
126
+ this.rendered = await render(this.processedViews, this.config.compiler, Object.keys(this.processedViews), this.isDevMode);
123
127
  console.log(` Rendered ${Object.keys(this.rendered).length} templates`);
124
128
 
125
129
  // Process assets in parallel for speed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clovie",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Vintage web dev tooling with modern quality of life",
5
5
  "keywords": [
6
6
  "static-site-generator",
@@ -47,8 +47,9 @@
47
47
  "test": "vitest run",
48
48
  "test:watch": "vitest",
49
49
  "test:run": "vitest run",
50
- "docs:build": "cd docs && node ../bin/cli.js build",
51
- "docs:dev": "cd docs && node ../bin/cli.js watch",
50
+ "build": "node build.config.js",
51
+ "docs:build": "cd docs && node ../dist/clovie.js build",
52
+ "docs:dev": "cd docs && node ../dist/clovie.js watch",
52
53
  "prepublishOnly": "npm test"
53
54
  },
54
55
  "dependencies": {