clovie 0.2.1 → 0.2.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/lib/services/Compile.js
CHANGED
|
@@ -6,6 +6,7 @@ import { createProgressTracker } from '../utils/progress.js';
|
|
|
6
6
|
|
|
7
7
|
import { replaceRouteParams } from '../utils/routeMatch.js';
|
|
8
8
|
import { formatOutputPath } from '../utils/outputPath.js';
|
|
9
|
+
import { isFactory } from '../utils/normalizeToFactories.js';
|
|
9
10
|
|
|
10
11
|
export class Compile extends ServiceProvider {
|
|
11
12
|
|
|
@@ -183,13 +184,19 @@ export class Compile extends ServiceProvider {
|
|
|
183
184
|
log.debug('No routes to compile');
|
|
184
185
|
return [];
|
|
185
186
|
}
|
|
187
|
+
|
|
188
|
+
const routeConfigs = opts.routes.filter(r => !isFactory(r));
|
|
189
|
+
if (!routeConfigs.length) {
|
|
190
|
+
log.debug('No routes to compile');
|
|
191
|
+
return [];
|
|
192
|
+
}
|
|
186
193
|
|
|
187
|
-
const progressId = this.#progressTracker.createProgressBar('Compiling Routes',
|
|
194
|
+
const progressId = this.#progressTracker.createProgressBar('Compiling Routes', routeConfigs.length, 'routes');
|
|
188
195
|
const promises = [];
|
|
189
|
-
const routesLength =
|
|
196
|
+
const routesLength = routeConfigs.length;
|
|
190
197
|
|
|
191
198
|
for (let i = 0; i < routesLength; i++) {
|
|
192
|
-
const route =
|
|
199
|
+
const route = routeConfigs[i];
|
|
193
200
|
if (route.repeat) {
|
|
194
201
|
const data = route.repeat(opts.data);
|
|
195
202
|
const entries = Array.isArray(data) ? data.entries() : Object.entries(data);
|
|
@@ -216,7 +223,7 @@ export class Compile extends ServiceProvider {
|
|
|
216
223
|
}
|
|
217
224
|
|
|
218
225
|
const results = await Promise.all(promises);
|
|
219
|
-
this.#progressTracker.completeProgress(progressId, `✅ Compiled ${
|
|
226
|
+
this.#progressTracker.completeProgress(progressId, `✅ Compiled ${routeConfigs.length} routes`);
|
|
220
227
|
|
|
221
228
|
return results.filter(Boolean);
|
|
222
229
|
},
|
package/lib/services/Run.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ServiceProvider } from '@jucie.io/engine';
|
|
2
|
-
import { normalizeToFactories } from '../utils/normalizeToFactories.js';
|
|
3
|
-
import { viewsToRoutes
|
|
2
|
+
import { normalizeToFactories, normalizeRoutesToFactories } from '../utils/normalizeToFactories.js';
|
|
3
|
+
import { viewsToRoutes } from '../utils/viewsToRoutes.js';
|
|
4
4
|
import { defineRoutes } from '../factories/routes.js';
|
|
5
5
|
import { defineHooks } from '../factories/hooks.js';
|
|
6
6
|
import { defineMiddleware } from '../factories/middleware.js';
|
|
@@ -153,13 +153,13 @@ export class Run extends ServiceProvider {
|
|
|
153
153
|
const services = { file, liveReload };
|
|
154
154
|
|
|
155
155
|
const viewRoutes = viewsToRoutes(opts, services);
|
|
156
|
-
const pageRoutes = pagesToRoutes(opts.routes, opts, services);
|
|
157
156
|
|
|
158
157
|
const factories = [
|
|
159
158
|
...normalizeToFactories(opts.hooks, defineHooks),
|
|
160
159
|
...normalizeToFactories(opts.middleware, defineMiddleware),
|
|
161
160
|
...normalizeToFactories(opts.api, defineRoutes),
|
|
162
|
-
...
|
|
161
|
+
...normalizeRoutesToFactories(opts.routes, defineRoutes, opts, services),
|
|
162
|
+
...normalizeToFactories(viewRoutes, defineRoutes),
|
|
163
163
|
];
|
|
164
164
|
|
|
165
165
|
if (factories.length) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { definitionType } from '@jucie.io/engine';
|
|
2
|
+
import { pagesToRoutes } from './viewsToRoutes.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Normalizes a config value into an array of engine-server factory definitions.
|
|
@@ -43,10 +44,48 @@ export function normalizeToFactories(value, factoryFn) {
|
|
|
43
44
|
return factories;
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
function isFactory(value) {
|
|
47
|
+
export function isFactory(value) {
|
|
47
48
|
return typeof value === 'function' && definitionType(value) !== undefined;
|
|
48
49
|
}
|
|
49
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Like normalizeToFactories, but raw route config objects are converted
|
|
53
|
+
* to engine-server route objects via pagesToRoutes before wrapping.
|
|
54
|
+
* Factory definitions pass through as-is.
|
|
55
|
+
*
|
|
56
|
+
* @param {*} value - The routes config value (raw configs, factories, or intermixed)
|
|
57
|
+
* @param {Function} factoryFn - The define* factory to wrap converted routes with
|
|
58
|
+
* @param {object} opts - Clovie config opts (passed to pagesToRoutes)
|
|
59
|
+
* @param {object} services - Injected services { file, liveReload }
|
|
60
|
+
* @returns {Array} Array of factory definitions ready for server.use()
|
|
61
|
+
*/
|
|
62
|
+
export function normalizeRoutesToFactories(value, factoryFn, opts, services) {
|
|
63
|
+
if (!value) return [];
|
|
64
|
+
if (isFactory(value)) return [value];
|
|
65
|
+
if (!Array.isArray(value)) return [wrapRaw(factoryFn, pagesToRoutes([value], opts, services))];
|
|
66
|
+
|
|
67
|
+
const raw = [];
|
|
68
|
+
const factories = [];
|
|
69
|
+
|
|
70
|
+
for (const item of value) {
|
|
71
|
+
if (isFactory(item)) {
|
|
72
|
+
if (raw.length) {
|
|
73
|
+
factories.push(wrapRaw(factoryFn, pagesToRoutes([...raw], opts, services)));
|
|
74
|
+
raw.length = 0;
|
|
75
|
+
}
|
|
76
|
+
factories.push(item);
|
|
77
|
+
} else {
|
|
78
|
+
raw.push(item);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (raw.length) {
|
|
83
|
+
factories.push(wrapRaw(factoryFn, pagesToRoutes(raw, opts, services)));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return factories;
|
|
87
|
+
}
|
|
88
|
+
|
|
50
89
|
function wrapRaw(factoryFn, data) {
|
|
51
90
|
return factoryFn(() => data);
|
|
52
91
|
}
|