@hywax/cms 3.3.0 → 3.4.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hywax/cms",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "configKey": "cms",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
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.3.0";
10
+ const version = "3.4.0";
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, type], prefix, componentDir, includeComponents) {
222
223
  const detectedComponents = /* @__PURE__ */ new Set();
223
224
  if (includeComponents && includeComponents.length > 0) {
224
225
  for (const component of includeComponents) {
@@ -226,15 +227,10 @@ 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");
229
- for (const dir of dirs) {
230
- const appFiles = globSync(["**/*.{vue,ts,js,tsx,jsx}"], {
231
- cwd: dir,
232
- ignore: ["node_modules/**", ".nuxt/**", "dist/**"]
233
- });
234
- for (const file of appFiles) {
230
+ if (type === "files") {
231
+ for (const file of dirs) {
235
232
  try {
236
- const filePath = join(dir, file);
237
- const content = await readFile(filePath, "utf-8");
233
+ const content = await readFile(file, "utf-8");
238
234
  const matches = content.matchAll(componentPattern);
239
235
  for (const match of matches) {
240
236
  const componentName = match[1] || match[2];
@@ -245,6 +241,27 @@ async function detectUsedComponents(dirs, prefix, componentDir, includeComponent
245
241
  } catch {
246
242
  }
247
243
  }
244
+ } else if (type === "dirs") {
245
+ for (const dir of dirs) {
246
+ const appFiles = globSync(["**/*.{vue,ts,js,tsx,jsx}"], {
247
+ cwd: dir,
248
+ ignore: ["node_modules/**", ".nuxt/**", "dist/**"]
249
+ });
250
+ for (const file of appFiles) {
251
+ try {
252
+ const filePath = join(dir, file);
253
+ const content = await readFile(filePath, "utf-8");
254
+ const matches = content.matchAll(componentPattern);
255
+ for (const match of matches) {
256
+ const componentName = match[1] || match[2];
257
+ if (componentName) {
258
+ detectedComponents.add(componentName);
259
+ }
260
+ }
261
+ } catch {
262
+ }
263
+ }
264
+ }
248
265
  }
249
266
  if (detectedComponents.size === 0) {
250
267
  return void 0;
@@ -260,7 +277,7 @@ async function detectUsedComponents(dirs, prefix, componentDir, includeComponent
260
277
  return allComponents;
261
278
  }
262
279
 
263
- async function prepareMergeConfigs({ nuxt, options, resolve }) {
280
+ async function prepareMergeConfigs({ nuxt, options, resolve, detectedComponents: contextDetectedComponents }) {
264
281
  nuxt.options.experimental = defu(nuxt.options.experimental || {}, {
265
282
  typedPages: true
266
283
  });
@@ -331,7 +348,7 @@ async function prepareMergeConfigs({ nuxt, options, resolve }) {
331
348
  }
332
349
  });
333
350
  const detectedComponents = await detectUsedComponents(
334
- [resolve("./runtime/components"), resolve("./runtime/composables")],
351
+ [[...contextDetectedComponents].map((component) => resolve(`./runtime/components/${component}.vue`)), "files"],
335
352
  "U",
336
353
  resolve("./runtime/components")
337
354
  );
@@ -363,7 +380,7 @@ async function prepareMergeConfigs({ nuxt, options, resolve }) {
363
380
  nuxt.options.vite = defu(nuxt.options.vite || {}, {
364
381
  optimizeDeps: {
365
382
  include: [
366
- "@unovis/vue",
383
+ ...options.unovis ? ["@unovis/vue"] : [],
367
384
  "@tanstack/vue-table",
368
385
  "@uplora/formats",
369
386
  "@nuxt/ui/utils/editor",
@@ -395,7 +412,7 @@ async function prepareMergeConfigs({ nuxt, options, resolve }) {
395
412
  });
396
413
  }
397
414
 
398
- function prepareServerRoutes({ resolve }) {
415
+ async function prepareServerRoutes({ resolve }) {
399
416
  addServerHandler({
400
417
  route: "/api/_uplora",
401
418
  method: "post",
@@ -566,7 +583,7 @@ const themeProse = {
566
583
  uploraImage: uploraImage
567
584
  };
568
585
 
569
- function getAppTemplates({ options, resolve, nuxt }) {
586
+ async function getAppTemplates({ options, resolve, nuxt, detectedComponents: contextDetectedComponents }) {
570
587
  const templates = [];
571
588
  let previousDetectedComponents;
572
589
  function writeThemeTemplate(theme2, path) {
@@ -604,11 +621,11 @@ function getAppTemplates({ options, resolve, nuxt }) {
604
621
  }
605
622
  }
606
623
  async function generateSources() {
607
- const sources = [];
624
+ const sources2 = [];
608
625
  const layers = getLayerDirectories(nuxt).map((layer) => layer.app);
609
626
  if (options.componentDetection) {
610
627
  const detectedComponents = await detectUsedComponents(
611
- layers,
628
+ [layers, "dirs"],
612
629
  options.componentsPrefix,
613
630
  resolve("./runtime/components"),
614
631
  Array.isArray(options.componentDetection) ? options.componentDetection : void 0
@@ -626,13 +643,14 @@ function getAppTemplates({ options, resolve, nuxt }) {
626
643
  }
627
644
  previousDetectedComponents = detectedComponents;
628
645
  if (options.prose?.enabled) {
629
- sources.push('@source "./cms/prose";');
646
+ sources2.push('@source "./cms/prose";');
630
647
  }
631
648
  for (const component of detectedComponents) {
632
649
  const kebabComponent = kebabCase(component);
633
650
  const camelComponent = camelCase(component);
634
651
  if (theme[camelComponent]) {
635
- sources.push(`@source "./cms/${kebabComponent}.ts";`);
652
+ sources2.push(`@source "./cms/${kebabComponent}.ts";`);
653
+ contextDetectedComponents.add(component);
636
654
  }
637
655
  }
638
656
  } else {
@@ -640,12 +658,12 @@ function getAppTemplates({ options, resolve, nuxt }) {
640
658
  logger.info("CMS detected no components in use, including all components");
641
659
  }
642
660
  previousDetectedComponents = /* @__PURE__ */ new Set();
643
- sources.push('@source "./cms";');
661
+ sources2.push('@source "./cms";');
644
662
  }
645
663
  } else {
646
- sources.push('@source "./cms";');
664
+ sources2.push('@source "./cms";');
647
665
  }
648
- return sources.join("\n");
666
+ return sources2.join("\n");
649
667
  }
650
668
  if (options.prose?.enabled) {
651
669
  templates.push({
@@ -656,11 +674,11 @@ function getAppTemplates({ options, resolve, nuxt }) {
656
674
  writeThemeTemplate(themeProse, "prose");
657
675
  }
658
676
  writeThemeTemplate(theme);
677
+ const sources = await generateSources();
659
678
  templates.push({
660
679
  filename: "cms.css",
661
680
  write: true,
662
681
  getContents: async () => {
663
- const sources = await generateSources();
664
682
  return `${sources}
665
683
  ${options.unovis ? `
666
684
  @layer components {
@@ -753,8 +771,8 @@ function getServerTemplates(_context) {
753
771
  const templates = [];
754
772
  return templates;
755
773
  }
756
- function prepareTemplates(context) {
757
- const appTemplates = getAppTemplates(context);
774
+ async function prepareTemplates(context) {
775
+ const appTemplates = await getAppTemplates(context);
758
776
  const serverTemplates = getServerTemplates();
759
777
  for (const template of appTemplates) {
760
778
  if (template.filename.endsWith(".d.ts")) {
@@ -794,11 +812,16 @@ const module$1 = defineNuxtModule({
794
812
  defaults: defaultModuleOptions,
795
813
  async setup(options, nuxt) {
796
814
  const context = createContext(options, nuxt);
797
- await prepareMergeConfigs(context);
798
- prepareTemplates(context);
799
- prepareAutoImports(context);
800
- prepareServerRoutes(context);
801
- await prepareGenerateEnv(context);
815
+ const prepareHandlers = [
816
+ prepareTemplates,
817
+ prepareMergeConfigs,
818
+ prepareAutoImports,
819
+ prepareServerRoutes,
820
+ prepareGenerateEnv
821
+ ];
822
+ for (const handler of prepareHandlers) {
823
+ await handler(context);
824
+ }
802
825
  }
803
826
  });
804
827
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hywax/cms",
3
3
  "type": "module",
4
- "version": "3.3.0",
4
+ "version": "3.4.0",
5
5
  "description": "Hywax CMS. ⚠️ This package is intended for internal use only.",
6
6
  "imports": {
7
7
  "#build/cms/*": "./.nuxt/cms/*.ts",