@hywax/cms 3.3.0 → 3.4.1
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 +44 -35
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { pascalCase, kebabCase, camelCase } from 'scule';
|
|
|
7
7
|
import { globSync } from 'tinyglobby';
|
|
8
8
|
|
|
9
9
|
const name = "@hywax/cms";
|
|
10
|
-
const version = "3.
|
|
10
|
+
const version = "3.4.1";
|
|
11
11
|
|
|
12
12
|
function createContext(options, nuxt) {
|
|
13
13
|
const { resolve } = createResolver(import.meta.url);
|
|
@@ -18,7 +18,8 @@ function createContext(options, nuxt) {
|
|
|
18
18
|
resolve,
|
|
19
19
|
distDir,
|
|
20
20
|
runtimeDir,
|
|
21
|
-
nuxt
|
|
21
|
+
nuxt,
|
|
22
|
+
detectedComponents: /* @__PURE__ */ new Set()
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
25
|
|
|
@@ -92,7 +93,7 @@ const defaultModuleOptions = {
|
|
|
92
93
|
}
|
|
93
94
|
};
|
|
94
95
|
|
|
95
|
-
function prepareAutoImports({ resolve, options, nuxt }) {
|
|
96
|
+
async function prepareAutoImports({ resolve, options, nuxt }) {
|
|
96
97
|
const cmsConfigPath = resolve(nuxt.options.buildDir, "cms/config");
|
|
97
98
|
const httpStatusesPath = resolve(nuxt.options.buildDir, "cms/http-statuses");
|
|
98
99
|
addComponentsDir({
|
|
@@ -218,7 +219,7 @@ function resolveComponentDependencies(component, dependencyGraph, resolved = /*
|
|
|
218
219
|
}
|
|
219
220
|
return resolved;
|
|
220
221
|
}
|
|
221
|
-
async function detectUsedComponents(dirs, prefix, componentDir, includeComponents) {
|
|
222
|
+
async function detectUsedComponents({ dirs, prefix, componentDir, includeComponents = [], allowComponents = [] }) {
|
|
222
223
|
const detectedComponents = /* @__PURE__ */ new Set();
|
|
223
224
|
if (includeComponents && includeComponents.length > 0) {
|
|
224
225
|
for (const component of includeComponents) {
|
|
@@ -226,8 +227,9 @@ async function detectUsedComponents(dirs, prefix, componentDir, includeComponent
|
|
|
226
227
|
}
|
|
227
228
|
}
|
|
228
229
|
const componentPattern = new RegExp(`<(?:Lazy)?${prefix}([A-Z][a-zA-Z]+)|\\b(?:Lazy)?${prefix}([A-Z][a-zA-Z]+)\\b`, "g");
|
|
230
|
+
const filesPattern = allowComponents.length ? `**/(${allowComponents.join("|")}).{vue,ts,js,tsx,jsx}` : "**/*.{vue,ts,js,tsx,jsx}";
|
|
229
231
|
for (const dir of dirs) {
|
|
230
|
-
const appFiles = globSync([
|
|
232
|
+
const appFiles = globSync([filesPattern], {
|
|
231
233
|
cwd: dir,
|
|
232
234
|
ignore: ["node_modules/**", ".nuxt/**", "dist/**"]
|
|
233
235
|
});
|
|
@@ -252,7 +254,7 @@ async function detectUsedComponents(dirs, prefix, componentDir, includeComponent
|
|
|
252
254
|
const dependencyGraph = await buildComponentDependencyGraph(componentDir, componentPattern);
|
|
253
255
|
const allComponents = /* @__PURE__ */ new Set();
|
|
254
256
|
for (const component of detectedComponents) {
|
|
255
|
-
const resolved = resolveComponentDependencies(component, dependencyGraph);
|
|
257
|
+
const resolved = resolveComponentDependencies(component, dependencyGraph, /* @__PURE__ */ new Set());
|
|
256
258
|
for (const resolvedComponent of resolved) {
|
|
257
259
|
allComponents.add(resolvedComponent);
|
|
258
260
|
}
|
|
@@ -260,7 +262,7 @@ async function detectUsedComponents(dirs, prefix, componentDir, includeComponent
|
|
|
260
262
|
return allComponents;
|
|
261
263
|
}
|
|
262
264
|
|
|
263
|
-
async function prepareMergeConfigs({ nuxt, options, resolve }) {
|
|
265
|
+
async function prepareMergeConfigs({ nuxt, options, resolve, detectedComponents: contextDetectedComponents }) {
|
|
264
266
|
nuxt.options.experimental = defu(nuxt.options.experimental || {}, {
|
|
265
267
|
typedPages: true
|
|
266
268
|
});
|
|
@@ -330,11 +332,12 @@ async function prepareMergeConfigs({ nuxt, options, resolve }) {
|
|
|
330
332
|
}
|
|
331
333
|
}
|
|
332
334
|
});
|
|
333
|
-
const detectedComponents = await detectUsedComponents(
|
|
334
|
-
[resolve("./runtime/components"), resolve("./runtime/composables")],
|
|
335
|
-
"U",
|
|
336
|
-
resolve("./runtime/components")
|
|
337
|
-
|
|
335
|
+
const detectedComponents = await detectUsedComponents({
|
|
336
|
+
dirs: [resolve("./runtime/components"), resolve("./runtime/composables")],
|
|
337
|
+
prefix: "U",
|
|
338
|
+
componentDir: resolve("./runtime/components"),
|
|
339
|
+
allowComponents: [...contextDetectedComponents]
|
|
340
|
+
});
|
|
338
341
|
nuxt.options.ui = defu(nuxt.options.ui || {}, {
|
|
339
342
|
colorMode: true,
|
|
340
343
|
fonts: true,
|
|
@@ -363,7 +366,7 @@ async function prepareMergeConfigs({ nuxt, options, resolve }) {
|
|
|
363
366
|
nuxt.options.vite = defu(nuxt.options.vite || {}, {
|
|
364
367
|
optimizeDeps: {
|
|
365
368
|
include: [
|
|
366
|
-
"@unovis/vue",
|
|
369
|
+
...options.unovis ? ["@unovis/vue"] : [],
|
|
367
370
|
"@tanstack/vue-table",
|
|
368
371
|
"@uplora/formats",
|
|
369
372
|
"@nuxt/ui/utils/editor",
|
|
@@ -395,7 +398,7 @@ async function prepareMergeConfigs({ nuxt, options, resolve }) {
|
|
|
395
398
|
});
|
|
396
399
|
}
|
|
397
400
|
|
|
398
|
-
function prepareServerRoutes({ resolve }) {
|
|
401
|
+
async function prepareServerRoutes({ resolve }) {
|
|
399
402
|
addServerHandler({
|
|
400
403
|
route: "/api/_uplora",
|
|
401
404
|
method: "post",
|
|
@@ -566,7 +569,7 @@ const themeProse = {
|
|
|
566
569
|
uploraImage: uploraImage
|
|
567
570
|
};
|
|
568
571
|
|
|
569
|
-
function getAppTemplates({ options, resolve, nuxt }) {
|
|
572
|
+
async function getAppTemplates({ options, resolve, nuxt, detectedComponents: contextDetectedComponents }) {
|
|
570
573
|
const templates = [];
|
|
571
574
|
let previousDetectedComponents;
|
|
572
575
|
function writeThemeTemplate(theme2, path) {
|
|
@@ -604,15 +607,15 @@ function getAppTemplates({ options, resolve, nuxt }) {
|
|
|
604
607
|
}
|
|
605
608
|
}
|
|
606
609
|
async function generateSources() {
|
|
607
|
-
const
|
|
610
|
+
const sources2 = [];
|
|
608
611
|
const layers = getLayerDirectories(nuxt).map((layer) => layer.app);
|
|
609
612
|
if (options.componentDetection) {
|
|
610
|
-
const detectedComponents = await detectUsedComponents(
|
|
611
|
-
layers,
|
|
612
|
-
options.componentsPrefix,
|
|
613
|
-
resolve("./runtime/components"),
|
|
614
|
-
Array.isArray(options.componentDetection) ? options.componentDetection : void 0
|
|
615
|
-
);
|
|
613
|
+
const detectedComponents = await detectUsedComponents({
|
|
614
|
+
dirs: layers,
|
|
615
|
+
prefix: options.componentsPrefix,
|
|
616
|
+
componentDir: resolve("./runtime/components"),
|
|
617
|
+
includeComponents: Array.isArray(options.componentDetection) ? options.componentDetection : void 0
|
|
618
|
+
});
|
|
616
619
|
if (detectedComponents && detectedComponents.size > 0) {
|
|
617
620
|
if (previousDetectedComponents) {
|
|
618
621
|
const newComponents = Array.from(detectedComponents).filter(
|
|
@@ -626,26 +629,27 @@ function getAppTemplates({ options, resolve, nuxt }) {
|
|
|
626
629
|
}
|
|
627
630
|
previousDetectedComponents = detectedComponents;
|
|
628
631
|
if (options.prose?.enabled) {
|
|
629
|
-
|
|
632
|
+
sources2.push('@source "./cms/prose";');
|
|
630
633
|
}
|
|
631
634
|
for (const component of detectedComponents) {
|
|
632
635
|
const kebabComponent = kebabCase(component);
|
|
633
636
|
const camelComponent = camelCase(component);
|
|
634
637
|
if (theme[camelComponent]) {
|
|
635
|
-
|
|
638
|
+
sources2.push(`@source "./cms/${kebabComponent}.ts";`);
|
|
636
639
|
}
|
|
640
|
+
contextDetectedComponents.add(component);
|
|
637
641
|
}
|
|
638
642
|
} else {
|
|
639
643
|
if (!previousDetectedComponents || previousDetectedComponents.size > 0) {
|
|
640
644
|
logger.info("CMS detected no components in use, including all components");
|
|
641
645
|
}
|
|
642
646
|
previousDetectedComponents = /* @__PURE__ */ new Set();
|
|
643
|
-
|
|
647
|
+
sources2.push('@source "./cms";');
|
|
644
648
|
}
|
|
645
649
|
} else {
|
|
646
|
-
|
|
650
|
+
sources2.push('@source "./cms";');
|
|
647
651
|
}
|
|
648
|
-
return
|
|
652
|
+
return sources2.join("\n");
|
|
649
653
|
}
|
|
650
654
|
if (options.prose?.enabled) {
|
|
651
655
|
templates.push({
|
|
@@ -656,11 +660,11 @@ function getAppTemplates({ options, resolve, nuxt }) {
|
|
|
656
660
|
writeThemeTemplate(themeProse, "prose");
|
|
657
661
|
}
|
|
658
662
|
writeThemeTemplate(theme);
|
|
663
|
+
const sources = await generateSources();
|
|
659
664
|
templates.push({
|
|
660
665
|
filename: "cms.css",
|
|
661
666
|
write: true,
|
|
662
667
|
getContents: async () => {
|
|
663
|
-
const sources = await generateSources();
|
|
664
668
|
return `${sources}
|
|
665
669
|
${options.unovis ? `
|
|
666
670
|
@layer components {
|
|
@@ -753,8 +757,8 @@ function getServerTemplates(_context) {
|
|
|
753
757
|
const templates = [];
|
|
754
758
|
return templates;
|
|
755
759
|
}
|
|
756
|
-
function prepareTemplates(context) {
|
|
757
|
-
const appTemplates = getAppTemplates(context);
|
|
760
|
+
async function prepareTemplates(context) {
|
|
761
|
+
const appTemplates = await getAppTemplates(context);
|
|
758
762
|
const serverTemplates = getServerTemplates();
|
|
759
763
|
for (const template of appTemplates) {
|
|
760
764
|
if (template.filename.endsWith(".d.ts")) {
|
|
@@ -794,11 +798,16 @@ const module$1 = defineNuxtModule({
|
|
|
794
798
|
defaults: defaultModuleOptions,
|
|
795
799
|
async setup(options, nuxt) {
|
|
796
800
|
const context = createContext(options, nuxt);
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
801
|
+
const prepareHandlers = [
|
|
802
|
+
prepareTemplates,
|
|
803
|
+
prepareMergeConfigs,
|
|
804
|
+
prepareAutoImports,
|
|
805
|
+
prepareServerRoutes,
|
|
806
|
+
prepareGenerateEnv
|
|
807
|
+
];
|
|
808
|
+
for (const handler of prepareHandlers) {
|
|
809
|
+
await handler(context);
|
|
810
|
+
}
|
|
802
811
|
}
|
|
803
812
|
});
|
|
804
813
|
|