clovie 0.1.1 → 0.1.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/README.md +4 -4
- package/bin/cli.js +1 -1
- package/lib/core/render.js +41 -2
- package/lib/core/watcher.js +11 -1
- package/lib/main.js +5 -1
- package/package.json +4 -3
- package/templates/default/package.json +1 -1
- /package/templates/default/{app.config.js → clovie.config.js} +0 -0
package/README.md
CHANGED
|
@@ -135,7 +135,7 @@ export default {
|
|
|
135
135
|
Clovie supports asynchronous data loading for dynamic content:
|
|
136
136
|
|
|
137
137
|
```javascript
|
|
138
|
-
//
|
|
138
|
+
// clovie.config.js
|
|
139
139
|
export default {
|
|
140
140
|
// ... other config
|
|
141
141
|
data: async () => {
|
|
@@ -157,7 +157,7 @@ export default {
|
|
|
157
157
|
Create multiple pages from data arrays using the models system:
|
|
158
158
|
|
|
159
159
|
```javascript
|
|
160
|
-
//
|
|
160
|
+
// clovie.config.js
|
|
161
161
|
export default {
|
|
162
162
|
// ... other config
|
|
163
163
|
data: {
|
|
@@ -369,7 +369,7 @@ When you create a new project with `clovie create`, you get this structure:
|
|
|
369
369
|
|
|
370
370
|
```
|
|
371
371
|
my-site/
|
|
372
|
-
├──
|
|
372
|
+
├── clovie.config.js # Configuration
|
|
373
373
|
├── package.json # Dependencies and scripts
|
|
374
374
|
├── README.md # Project documentation
|
|
375
375
|
├── views/ # HTML templates
|
|
@@ -386,7 +386,7 @@ You can also create your own structure:
|
|
|
386
386
|
|
|
387
387
|
```
|
|
388
388
|
my-site/
|
|
389
|
-
├──
|
|
389
|
+
├── clovie.config.js # Configuration
|
|
390
390
|
├── views/ # Templates
|
|
391
391
|
│ ├── _base.html # Base template (partial)
|
|
392
392
|
│ ├── _header.html # Header partial
|
package/bin/cli.js
CHANGED
|
@@ -77,7 +77,7 @@ const argv = mainOptions._unknown || [];
|
|
|
77
77
|
|
|
78
78
|
// Command-specific options
|
|
79
79
|
const optionDefinitions = [
|
|
80
|
-
{ name: 'config', alias: 'c', type: String, defaultValue: '
|
|
80
|
+
{ name: 'config', alias: 'c', type: String, defaultValue: 'clovie.config.js' },
|
|
81
81
|
{ name: 'watch', alias: 'w', type: Boolean },
|
|
82
82
|
{ name: 'template', alias: 't', type: String, defaultValue: 'default' }
|
|
83
83
|
];
|
package/lib/core/render.js
CHANGED
|
@@ -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
|
-
|
|
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;
|
package/lib/core/watcher.js
CHANGED
|
@@ -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.
|
|
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.
|
|
3
|
+
"version": "0.1.3",
|
|
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
|
-
"
|
|
51
|
-
"docs:
|
|
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": {
|
|
File without changes
|