@hywax/cms 2.0.1 → 2.0.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/dist/module.json +1 -1
- package/dist/module.mjs +88 -83
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { defu } from 'defu';
|
|
|
7
7
|
import { globSync } from 'tinyglobby';
|
|
8
8
|
|
|
9
9
|
const name = "@hywax/cms";
|
|
10
|
-
const version = "2.0.
|
|
10
|
+
const version = "2.0.2";
|
|
11
11
|
|
|
12
12
|
function createContext(options, nuxt) {
|
|
13
13
|
const { resolve } = createResolver(import.meta.url);
|
|
@@ -149,7 +149,86 @@ const icons = {
|
|
|
149
149
|
editLine: "i-lucide-pen-line"
|
|
150
150
|
};
|
|
151
151
|
|
|
152
|
-
function
|
|
152
|
+
async function buildComponentDependencyGraph(componentDir, componentPattern) {
|
|
153
|
+
const dependencyGraph = /* @__PURE__ */ new Map();
|
|
154
|
+
const componentFiles = globSync(["**/*.vue"], {
|
|
155
|
+
cwd: componentDir,
|
|
156
|
+
absolute: true
|
|
157
|
+
});
|
|
158
|
+
for (const componentFile of componentFiles) {
|
|
159
|
+
try {
|
|
160
|
+
const content = await readFile(componentFile, "utf-8");
|
|
161
|
+
const componentName = pascalCase(componentFile.split("/").pop().replace(".vue", ""));
|
|
162
|
+
const dependencies = /* @__PURE__ */ new Set();
|
|
163
|
+
const matches = content.matchAll(componentPattern);
|
|
164
|
+
for (const match of matches) {
|
|
165
|
+
const depName = match[1] || match[2];
|
|
166
|
+
if (depName && depName !== componentName) {
|
|
167
|
+
dependencies.add(depName);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
dependencyGraph.set(componentName, dependencies);
|
|
171
|
+
} catch {
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return dependencyGraph;
|
|
175
|
+
}
|
|
176
|
+
function resolveComponentDependencies(component, dependencyGraph, resolved = /* @__PURE__ */ new Set()) {
|
|
177
|
+
if (resolved.has(component)) {
|
|
178
|
+
return resolved;
|
|
179
|
+
}
|
|
180
|
+
resolved.add(component);
|
|
181
|
+
const dependencies = dependencyGraph.get(component);
|
|
182
|
+
if (dependencies) {
|
|
183
|
+
for (const dep of dependencies) {
|
|
184
|
+
resolveComponentDependencies(dep, dependencyGraph, resolved);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return resolved;
|
|
188
|
+
}
|
|
189
|
+
async function detectUsedComponents(dirs, prefix, componentDir, includeComponents) {
|
|
190
|
+
const detectedComponents = /* @__PURE__ */ new Set();
|
|
191
|
+
if (includeComponents && includeComponents.length > 0) {
|
|
192
|
+
for (const component of includeComponents) {
|
|
193
|
+
detectedComponents.add(component);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const componentPattern = new RegExp(`<(?:Lazy)?${prefix}([A-Z][a-zA-Z]+)|\\b(?:Lazy)?${prefix}([A-Z][a-zA-Z]+)\\b`, "g");
|
|
197
|
+
for (const dir of dirs) {
|
|
198
|
+
const appFiles = globSync(["**/*.{vue,ts,js,tsx,jsx}"], {
|
|
199
|
+
cwd: dir,
|
|
200
|
+
ignore: ["node_modules/**", ".nuxt/**", "dist/**"]
|
|
201
|
+
});
|
|
202
|
+
for (const file of appFiles) {
|
|
203
|
+
try {
|
|
204
|
+
const filePath = join(dir, file);
|
|
205
|
+
const content = await readFile(filePath, "utf-8");
|
|
206
|
+
const matches = content.matchAll(componentPattern);
|
|
207
|
+
for (const match of matches) {
|
|
208
|
+
const componentName = match[1] || match[2];
|
|
209
|
+
if (componentName) {
|
|
210
|
+
detectedComponents.add(componentName);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
} catch {
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (detectedComponents.size === 0) {
|
|
218
|
+
return void 0;
|
|
219
|
+
}
|
|
220
|
+
const dependencyGraph = await buildComponentDependencyGraph(componentDir, componentPattern);
|
|
221
|
+
const allComponents = /* @__PURE__ */ new Set();
|
|
222
|
+
for (const component of detectedComponents) {
|
|
223
|
+
const resolved = resolveComponentDependencies(component, dependencyGraph);
|
|
224
|
+
for (const resolvedComponent of resolved) {
|
|
225
|
+
allComponents.add(resolvedComponent);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return allComponents;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
async function prepareMergeConfigs({ nuxt, options, resolve }) {
|
|
153
232
|
nuxt.options.experimental = defu(nuxt.options.experimental || {}, {
|
|
154
233
|
typedPages: true
|
|
155
234
|
});
|
|
@@ -219,12 +298,17 @@ function prepareMergeConfigs({ nuxt, options }) {
|
|
|
219
298
|
}
|
|
220
299
|
}
|
|
221
300
|
});
|
|
301
|
+
const detectedComponents = await detectUsedComponents(
|
|
302
|
+
[resolve("./runtime/components"), resolve("./runtime/composables")],
|
|
303
|
+
"U",
|
|
304
|
+
resolve("./runtime/components")
|
|
305
|
+
);
|
|
222
306
|
nuxt.options.ui = defu(nuxt.options.ui || {}, {
|
|
223
307
|
colorMode: true,
|
|
224
308
|
fonts: true,
|
|
225
309
|
mdc: true,
|
|
226
310
|
experimental: {
|
|
227
|
-
componentDetection:
|
|
311
|
+
componentDetection: [...detectedComponents || []]
|
|
228
312
|
}
|
|
229
313
|
});
|
|
230
314
|
nuxt.options.colorMode = defu(nuxt.options.colorMode || {}, {
|
|
@@ -455,85 +539,6 @@ const themeProse = {
|
|
|
455
539
|
uploraImage: uploraImage
|
|
456
540
|
};
|
|
457
541
|
|
|
458
|
-
async function buildComponentDependencyGraph(componentDir, componentPattern) {
|
|
459
|
-
const dependencyGraph = /* @__PURE__ */ new Map();
|
|
460
|
-
const componentFiles = globSync(["**/*.vue"], {
|
|
461
|
-
cwd: componentDir,
|
|
462
|
-
absolute: true
|
|
463
|
-
});
|
|
464
|
-
for (const componentFile of componentFiles) {
|
|
465
|
-
try {
|
|
466
|
-
const content = await readFile(componentFile, "utf-8");
|
|
467
|
-
const componentName = pascalCase(componentFile.split("/").pop().replace(".vue", ""));
|
|
468
|
-
const dependencies = /* @__PURE__ */ new Set();
|
|
469
|
-
const matches = content.matchAll(componentPattern);
|
|
470
|
-
for (const match of matches) {
|
|
471
|
-
const depName = match[1] || match[2];
|
|
472
|
-
if (depName && depName !== componentName) {
|
|
473
|
-
dependencies.add(depName);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
dependencyGraph.set(componentName, dependencies);
|
|
477
|
-
} catch {
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
return dependencyGraph;
|
|
481
|
-
}
|
|
482
|
-
function resolveComponentDependencies(component, dependencyGraph, resolved = /* @__PURE__ */ new Set()) {
|
|
483
|
-
if (resolved.has(component)) {
|
|
484
|
-
return resolved;
|
|
485
|
-
}
|
|
486
|
-
resolved.add(component);
|
|
487
|
-
const dependencies = dependencyGraph.get(component);
|
|
488
|
-
if (dependencies) {
|
|
489
|
-
for (const dep of dependencies) {
|
|
490
|
-
resolveComponentDependencies(dep, dependencyGraph, resolved);
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
return resolved;
|
|
494
|
-
}
|
|
495
|
-
async function detectUsedComponents(dirs, prefix, componentDir, includeComponents) {
|
|
496
|
-
const detectedComponents = /* @__PURE__ */ new Set();
|
|
497
|
-
if (includeComponents && includeComponents.length > 0) {
|
|
498
|
-
for (const component of includeComponents) {
|
|
499
|
-
detectedComponents.add(component);
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
const componentPattern = new RegExp(`<(?:Lazy)?${prefix}([A-Z][a-zA-Z]+)|\\b(?:Lazy)?${prefix}([A-Z][a-zA-Z]+)\\b`, "g");
|
|
503
|
-
for (const dir of dirs) {
|
|
504
|
-
const appFiles = globSync(["**/*.{vue,ts,js,tsx,jsx}"], {
|
|
505
|
-
cwd: dir,
|
|
506
|
-
ignore: ["node_modules/**", ".nuxt/**", "dist/**"]
|
|
507
|
-
});
|
|
508
|
-
for (const file of appFiles) {
|
|
509
|
-
try {
|
|
510
|
-
const filePath = join(dir, file);
|
|
511
|
-
const content = await readFile(filePath, "utf-8");
|
|
512
|
-
const matches = content.matchAll(componentPattern);
|
|
513
|
-
for (const match of matches) {
|
|
514
|
-
const componentName = match[1] || match[2];
|
|
515
|
-
if (componentName) {
|
|
516
|
-
detectedComponents.add(componentName);
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
} catch {
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
if (detectedComponents.size === 0) {
|
|
524
|
-
return void 0;
|
|
525
|
-
}
|
|
526
|
-
const dependencyGraph = await buildComponentDependencyGraph(componentDir, componentPattern);
|
|
527
|
-
const allComponents = /* @__PURE__ */ new Set();
|
|
528
|
-
for (const component of detectedComponents) {
|
|
529
|
-
const resolved = resolveComponentDependencies(component, dependencyGraph);
|
|
530
|
-
for (const resolvedComponent of resolved) {
|
|
531
|
-
allComponents.add(resolvedComponent);
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
return allComponents;
|
|
535
|
-
}
|
|
536
|
-
|
|
537
542
|
function getAppTemplates({ options, resolve, nuxt }) {
|
|
538
543
|
const templates = [];
|
|
539
544
|
let previousDetectedComponents;
|
|
@@ -759,7 +764,7 @@ const module$1 = defineNuxtModule({
|
|
|
759
764
|
defaults: defaultModuleOptions,
|
|
760
765
|
async setup(options, nuxt) {
|
|
761
766
|
const context = createContext(options, nuxt);
|
|
762
|
-
prepareMergeConfigs(context);
|
|
767
|
+
await prepareMergeConfigs(context);
|
|
763
768
|
prepareTemplates(context);
|
|
764
769
|
prepareAutoImports(context);
|
|
765
770
|
prepareServerRoutes(context);
|