@xleddyl/nuxt-cms 0.1.44 → 0.1.46

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@xleddyl/nuxt-cms",
3
3
  "configKey": "cms",
4
- "version": "0.1.44",
4
+ "version": "0.1.46",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { spawn } from 'node:child_process';
2
- import { existsSync, readdirSync } from 'node:fs';
2
+ import { existsSync } from 'node:fs';
3
3
  import { createRequire } from 'node:module';
4
4
  import { join, isAbsolute, resolve, relative, dirname } from 'node:path';
5
5
  import { fileURLToPath } from 'node:url';
@@ -10,10 +10,11 @@ import { introspectionFromSchema, buildSchema } from 'graphql';
10
10
  import { minifyIntrospection, outputIntrospectionFile } from 'gql.tada/internal';
11
11
  import { createJiti } from 'jiti';
12
12
  import { typeName, blockTypeName, blocksFieldTypeName, renderGraphqlSdl } from '../dist/runtime/shared/graphql-sdl.js';
13
- import { isTranslatableField, isTranslatableMediaField, isMultiSelect, pageAllFields, PAGE_PATH_FIELD, pageRoutes, fieldConditions, isRequiredField, pageFields, isPrivateField, entryFieldsFor, pageLabelFromPath, pageKeyFromPath, mediaTypeFilter, DEFAULT_MEDIA_MAX_FILE_SIZE } from '../dist/runtime/shared/index.js';
13
+ import { isTranslatableField, isTranslatableMediaField, isMultiSelect, pageAllFields, PAGE_PATH_FIELD, pageRoutes, fieldConditions, isRequiredField, pageFields, isPrivateField, entryFieldsFor, mediaTypeFilter, DEFAULT_MEDIA_MAX_FILE_SIZE } from '../dist/runtime/shared/index.js';
14
14
  import { scanMediaDirectory, readMediaFileMeta } from '../dist/runtime/server/utils/media-sync.js';
15
15
  import { createHash } from 'node:crypto';
16
16
  import { readFile } from 'node:fs/promises';
17
+ import { routePathsFromDir, resolvePageRoutes } from '../dist/runtime/shared/page-routes.js';
17
18
 
18
19
  async function collectMediaManifest(root) {
19
20
  const files = await scanMediaDirectory(root);
@@ -598,45 +599,6 @@ function renderQueriesFile(config) {
598
599
  ].join("\n");
599
600
  }
600
601
 
601
- const DYNAMIC = /[[\]]/;
602
- function vueFiles(dir, prefix = "") {
603
- if (!existsSync(dir)) return [];
604
- const files = [];
605
- for (const item of readdirSync(dir, { withFileTypes: true })) {
606
- const name = `${prefix}${item.name}`;
607
- if (item.isDirectory()) files.push(...vueFiles(join(dir, item.name), `${name}/`));
608
- else if (item.name.endsWith(".vue")) files.push(name);
609
- }
610
- return files;
611
- }
612
- function routePathFromFile(file) {
613
- if (DYNAMIC.test(file)) return null;
614
- const segments = file.replace(/\.vue$/, "").split("/").filter((segment) => !/^\(.+\)$/.test(segment));
615
- if (segments.at(-1) === "index") segments.pop();
616
- const path = `/${segments.join("/")}`.replace(/\/$/, "");
617
- return path || "/";
618
- }
619
- function routePathsFromDir(pagesDir) {
620
- const paths = /* @__PURE__ */ new Set();
621
- for (const file of vueFiles(pagesDir)) {
622
- const path = routePathFromFile(file);
623
- if (path) paths.add(path);
624
- }
625
- return [...paths];
626
- }
627
- function resolvePageRoutes(entry, discovered) {
628
- const declared = Array.isArray(entry.routes) ? entry.routes : discovered;
629
- const paths = /* @__PURE__ */ new Set([...declared, ...entry.include ?? []]);
630
- for (const path of entry.exclude ?? []) paths.delete(path);
631
- const rank = new Map((entry.order ?? []).map((path, index) => [path, index]));
632
- const order = entry.order?.length ?? 0;
633
- return [...paths].sort((a, b) => (rank.get(a) ?? order) - (rank.get(b) ?? order) || a.localeCompare(b)).map((path) => ({
634
- path,
635
- key: pageKeyFromPath(path),
636
- label: entry.labels?.[path] ?? pageLabelFromPath(path)
637
- }));
638
- }
639
-
640
602
  function mediaTsType(field) {
641
603
  const types = mediaTypeFilter(field.mediaType);
642
604
  return types ? `CmsMedia<${types.map((type) => `'${type}'`).join(" | ")}>` : "CmsMedia";
@@ -1,5 +1,12 @@
1
+ import type { CmsConfig, CmsPageRoute } from './shared/index.js';
1
2
  import { customId, ID_LENGTH } from './server/utils/custom-id.js';
2
3
  export { customId, ID_LENGTH };
4
+ export type { CmsPageRoute };
5
+ export interface ResolveCmsPagesOptions {
6
+ root?: string;
7
+ pagesDir?: string;
8
+ }
9
+ export declare function resolveCmsPages<T extends CmsConfig>(config: T, options?: ResolveCmsPagesOptions): T;
3
10
  export type SeedDriver = 'sqlite' | 'libsql' | 'postgres';
4
11
  export interface CmsSeederOptions {
5
12
  driver?: SeedDriver;
@@ -1,7 +1,17 @@
1
1
  import { mkdirSync } from "node:fs";
2
2
  import { dirname, isAbsolute, resolve } from "node:path";
3
+ import { resolvePageRoutes, routePathsFromDir } from "./shared/page-routes.js";
3
4
  import { customId, ID_LENGTH } from "./server/utils/custom-id.js";
4
5
  export { customId, ID_LENGTH };
6
+ export function resolveCmsPages(config, options = {}) {
7
+ const root = options.root ?? process.cwd();
8
+ const pagesDir = options.pagesDir ? isAbsolute(options.pagesDir) ? options.pagesDir : resolve(root, options.pagesDir) : resolve(root, "app/pages");
9
+ const discovered = routePathsFromDir(pagesDir);
10
+ for (const entry of Object.values(config)) {
11
+ if (entry.kind === "page") entry.pages = resolvePageRoutes(entry, discovered);
12
+ }
13
+ return config;
14
+ }
5
15
  function inferDriver(url) {
6
16
  if (/^(libsql|wss?|https?):\/\//.test(url)) return "libsql";
7
17
  if (/^postgres(ql)?:\/\//.test(url)) return "postgres";
@@ -0,0 +1,4 @@
1
+ import type { CmsEntry, CmsPageRoute } from './index.js';
2
+ export declare function routePathFromFile(file: string): string | null;
3
+ export declare function routePathsFromDir(pagesDir: string): string[];
4
+ export declare function resolvePageRoutes(entry: CmsEntry, discovered: string[]): CmsPageRoute[];
@@ -0,0 +1,41 @@
1
+ import { existsSync, readdirSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { pageKeyFromPath, pageLabelFromPath } from "./index.js";
4
+ const DYNAMIC = /[[\]]/;
5
+ function vueFiles(dir, prefix = "") {
6
+ if (!existsSync(dir)) return [];
7
+ const files = [];
8
+ for (const item of readdirSync(dir, { withFileTypes: true })) {
9
+ const name = `${prefix}${item.name}`;
10
+ if (item.isDirectory()) files.push(...vueFiles(join(dir, item.name), `${name}/`));
11
+ else if (item.name.endsWith(".vue")) files.push(name);
12
+ }
13
+ return files;
14
+ }
15
+ export function routePathFromFile(file) {
16
+ if (DYNAMIC.test(file)) return null;
17
+ const segments = file.replace(/\.vue$/, "").split("/").filter((segment) => !/^\(.+\)$/.test(segment));
18
+ if (segments.at(-1) === "index") segments.pop();
19
+ const path = `/${segments.join("/")}`.replace(/\/$/, "");
20
+ return path || "/";
21
+ }
22
+ export function routePathsFromDir(pagesDir) {
23
+ const paths = /* @__PURE__ */ new Set();
24
+ for (const file of vueFiles(pagesDir)) {
25
+ const path = routePathFromFile(file);
26
+ if (path) paths.add(path);
27
+ }
28
+ return [...paths];
29
+ }
30
+ export function resolvePageRoutes(entry, discovered) {
31
+ const declared = Array.isArray(entry.routes) ? entry.routes : discovered;
32
+ const paths = /* @__PURE__ */ new Set([...declared, ...entry.include ?? []]);
33
+ for (const path of entry.exclude ?? []) paths.delete(path);
34
+ const rank = new Map((entry.order ?? []).map((path, index) => [path, index]));
35
+ const order = entry.order?.length ?? 0;
36
+ return [...paths].sort((a, b) => (rank.get(a) ?? order) - (rank.get(b) ?? order) || a.localeCompare(b)).map((path) => ({
37
+ path,
38
+ key: pageKeyFromPath(path),
39
+ label: entry.labels?.[path] ?? pageLabelFromPath(path)
40
+ }));
41
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xleddyl/nuxt-cms",
3
- "version": "0.1.44",
3
+ "version": "0.1.46",
4
4
  "description": "Lightweight CMS that ships with your Nuxt app: runs on the Nitro server, content types defined in code, /cms admin panel, GraphQL API, SQLite or Postgres. No external CMS needed!",
5
5
  "license": "MIT",
6
6
  "author": "Edoardo Alberti (https://github.com/xleddyl)",