clovie 0.2.9 → 0.2.10
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/lib/createClovie.js +1 -1
- package/lib/services/Run.js +2 -32
- package/lib/utils/transformConfig.js +18 -0
- package/package.json +2 -2
package/lib/createClovie.js
CHANGED
package/lib/services/Run.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { ServiceProvider } from '@jucie.io/engine';
|
|
2
|
-
import {
|
|
3
|
-
import { viewsToRoutes, pagesToRoutes, resolveRoutes } from '../utils/viewsToRoutes.js';
|
|
4
|
-
import { defineRoutes as defineServerRoutes, defineHooks as defineServerHooks, defineMiddleware as defineServerMiddleware } from '@jucie.io/engine-server';
|
|
2
|
+
import { resolveRoutes } from '../utils/viewsToRoutes.js';
|
|
5
3
|
import { extractScriptSources } from '../utils/extractScripts.js';
|
|
6
4
|
|
|
7
5
|
export class Run extends ServiceProvider {
|
|
@@ -24,7 +22,6 @@ export class Run extends ServiceProvider {
|
|
|
24
22
|
|
|
25
23
|
serve: async () => {
|
|
26
24
|
const opts = configurator.opts;
|
|
27
|
-
await this.#normalizeRoutes(opts);
|
|
28
25
|
const server = useContext('server');
|
|
29
26
|
if (!server) {
|
|
30
27
|
throw new Error('Server service not available. Use type: "server" in opts.');
|
|
@@ -32,7 +29,6 @@ export class Run extends ServiceProvider {
|
|
|
32
29
|
|
|
33
30
|
log.info('🌐 Starting production server...');
|
|
34
31
|
await this.#build(opts);
|
|
35
|
-
await this.#serve(opts);
|
|
36
32
|
|
|
37
33
|
if (typeof opts.beforeListen === 'function') {
|
|
38
34
|
await opts.beforeListen(useContext, opts);
|
|
@@ -49,16 +45,9 @@ export class Run extends ServiceProvider {
|
|
|
49
45
|
const [relay, liveReload, server] = useContext('relay', 'liveReload', 'server');
|
|
50
46
|
|
|
51
47
|
log.info('🚀 Starting development server...');
|
|
52
|
-
|
|
53
|
-
await this.#normalizeRoutes(configurator.opts);
|
|
54
48
|
|
|
55
|
-
// Build initial version
|
|
56
49
|
await this.#build(configurator.opts);
|
|
57
50
|
|
|
58
|
-
if (configurator.opts.type === 'server') {
|
|
59
|
-
await this.#serve(configurator.opts);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
51
|
if (typeof configurator.opts.beforeListen === 'function') {
|
|
63
52
|
await configurator.opts.beforeListen(useContext, configurator.opts);
|
|
64
53
|
}
|
|
@@ -157,25 +146,6 @@ export class Run extends ServiceProvider {
|
|
|
157
146
|
await compile.scripts(opts);
|
|
158
147
|
}
|
|
159
148
|
|
|
160
|
-
async #serve (opts) {
|
|
161
|
-
const [server, file, liveReload] = this.inject('server', 'file', 'liveReload');
|
|
162
|
-
const services = { file, liveReload };
|
|
163
|
-
|
|
164
|
-
const viewRoutes = viewsToRoutes(opts, services);
|
|
165
|
-
const pageRoutes = pagesToRoutes(opts.routes, opts, services);
|
|
166
|
-
|
|
167
|
-
const factories = [
|
|
168
|
-
...normalizeToFactories(opts.hooks, defineServerHooks),
|
|
169
|
-
...normalizeToFactories(opts.middleware, defineServerMiddleware),
|
|
170
|
-
...normalizeToFactories(opts.api, defineServerRoutes),
|
|
171
|
-
...normalizeToFactories([...viewRoutes, ...pageRoutes], defineServerRoutes),
|
|
172
|
-
];
|
|
173
|
-
|
|
174
|
-
if (factories.length) {
|
|
175
|
-
server.use(...factories);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
149
|
async #watch(opts) {
|
|
180
150
|
const [file, compile, log] = this.inject('file', 'compile', 'log');
|
|
181
151
|
log.info('Watching for changes...');
|
|
@@ -272,4 +242,4 @@ export class Run extends ServiceProvider {
|
|
|
272
242
|
closeWatchers.forEach(watcher => watcher());
|
|
273
243
|
}
|
|
274
244
|
}
|
|
275
|
-
}
|
|
245
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import { loadRenderEngine } from './loadRenderEngine.js';
|
|
4
|
+
import { defineRoutes } from '@jucie.io/engine-server';
|
|
5
|
+
import { viewsToRoutes, pagesToRoutes, resolveRoutes } from './viewsToRoutes.js';
|
|
4
6
|
|
|
5
7
|
// Add this near the top of the file, after the imports
|
|
6
8
|
const DATA_TYPES = {
|
|
@@ -195,6 +197,22 @@ export async function transformConfig(config, log = null) {
|
|
|
195
197
|
if (discovered.data) {
|
|
196
198
|
discovered.data = await resolveData(discovered.data);
|
|
197
199
|
}
|
|
200
|
+
|
|
201
|
+
// For server mode, create a factory that generates view routes at listen() time.
|
|
202
|
+
// Deferred to a factory so the file and liveReload services are available when it runs.
|
|
203
|
+
if (discovered.type === 'server') {
|
|
204
|
+
const opts = { ...discovered };
|
|
205
|
+
discovered._viewRoutesFactory = defineRoutes('_views', (inject) => {
|
|
206
|
+
const file = inject('file');
|
|
207
|
+
const liveReload = inject('liveReload');
|
|
208
|
+
const services = { file, liveReload };
|
|
209
|
+
const resolvedRoutes = resolveRoutes(opts.routes || [], inject);
|
|
210
|
+
return [
|
|
211
|
+
...viewsToRoutes(opts, services),
|
|
212
|
+
...pagesToRoutes(resolvedRoutes, opts, services),
|
|
213
|
+
];
|
|
214
|
+
});
|
|
215
|
+
}
|
|
198
216
|
|
|
199
217
|
return discovered;
|
|
200
218
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clovie",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
4
4
|
"description": "Vintage web dev tooling with modern quality of life",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"static-site-generator",
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"dependencies": {
|
|
88
88
|
"@jucie.io/engine": "^1.1.70",
|
|
89
89
|
"@jucie.io/engine-esbuild": "^1.0.10",
|
|
90
|
-
"@jucie.io/engine-server": "^1.0.
|
|
90
|
+
"@jucie.io/engine-server": "^1.0.27",
|
|
91
91
|
"@jucie.io/reactive": "^1.0.30",
|
|
92
92
|
"chalk": "^5.6.2",
|
|
93
93
|
"chokidar": "^3.5.3",
|