qarpeo 0.1.4 → 0.1.6

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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { existsSync, readFileSync, writeFileSync, appendFileSync, readdirSync, statSync } from 'node:fs';
1
+ import { existsSync, readFileSync, writeFileSync, appendFileSync, readdirSync, statSync, rmSync } from 'node:fs';
2
2
  import { createRequire } from 'node:module';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  import { defineNuxtModule, useLogger, createResolver, addVitePlugin, addTemplate, hasNuxtModule, installModule, addNitroPlugin, addImports, addServerImports, addTypeTemplate, updateTemplates, addServerImportsDir, addServerHandler, addRouteMiddleware, addComponent, extendPages, addPlugin } from '@nuxt/kit';
@@ -19,7 +19,7 @@ import 'drizzle-orm/node-sqlite';
19
19
  import 'node:process';
20
20
  import 'node:readline/promises';
21
21
 
22
- const version = "0.1.4";
22
+ const version = "0.1.6";
23
23
 
24
24
  function ensureDevEnv(rootDir) {
25
25
  const envPath = join(rootDir, ".env");
@@ -261,7 +261,7 @@ async function discoverSources(contentDir) {
261
261
  return results;
262
262
  }
263
263
  async function resolveAllCmsSources(options) {
264
- const { contentDir, rootDir, cacheDir, configSources = [] } = options;
264
+ const { contentDir, rootDir, cacheDir, configSources = [], cacheOnly = false } = options;
265
265
  const discovered = await discoverSources(contentDir);
266
266
  const resolvedList = [];
267
267
  for (const item of discovered) {
@@ -275,21 +275,27 @@ async function resolveAllCmsSources(options) {
275
275
  if (isRemoteSource(src.from)) {
276
276
  const hash = createHash("sha256").update(src.from).digest("hex").slice(0, 12);
277
277
  const targetDir = resolve(cacheDir, `qarpeo/cms-sources/source-${hash}`);
278
+ const _auth = src.token || process.env.GITHUB_TOKEN || process.env.GH_TOKEN;
278
279
  try {
279
- await downloadTemplate(src.from, {
280
- dir: targetDir,
281
- preferOffline: true,
282
- auth: src.token || process.env.GITHUB_TOKEN || process.env.GH_TOKEN
283
- });
284
- resolvedDir = targetDir;
285
- } catch (err) {
286
- console.warn(
287
- `[qarpeo:cms] Failed to download remote source "${src.from}":`,
288
- err?.message || err
289
- );
290
280
  if (existsSync(targetDir)) {
281
+ const cached = await readdir(targetDir);
282
+ if (cached.length > 0) {
283
+ resolvedDir = targetDir;
284
+ } else {
285
+ if (!cacheOnly) rmSync(targetDir, { recursive: true, force: true });
286
+ }
287
+ }
288
+ if (!resolvedDir && !cacheOnly) {
289
+ await downloadTemplate(src.from, { dir: targetDir, auth: _auth });
291
290
  resolvedDir = targetDir;
292
291
  }
292
+ } catch (err) {
293
+ if (!cacheOnly) {
294
+ console.warn(
295
+ `[qarpeo:cms] Failed to download remote source "${src.from}": ${err?.message ?? String(err)}`
296
+ );
297
+ }
298
+ if (existsSync(targetDir)) resolvedDir = targetDir;
293
299
  }
294
300
  } else {
295
301
  resolvedDir = resolve(sourceFileDir, src.from);
@@ -319,21 +325,27 @@ async function resolveAllCmsSources(options) {
319
325
  if (isRemoteSource(src.from)) {
320
326
  const hash = createHash("sha256").update(src.from).digest("hex").slice(0, 12);
321
327
  const targetDir = resolve(cacheDir, `qarpeo/cms-sources/source-${hash}`);
328
+ const _auth2 = src.token || process.env.GITHUB_TOKEN || process.env.GH_TOKEN;
322
329
  try {
323
- await downloadTemplate(src.from, {
324
- dir: targetDir,
325
- preferOffline: true,
326
- auth: src.token || process.env.GITHUB_TOKEN || process.env.GH_TOKEN
327
- });
328
- resolvedDir = targetDir;
329
- } catch (err) {
330
- console.warn(
331
- `[qarpeo:cms] Failed to download remote source "${src.from}":`,
332
- err?.message || err
333
- );
334
330
  if (existsSync(targetDir)) {
331
+ const cached = await readdir(targetDir);
332
+ if (cached.length > 0) {
333
+ resolvedDir = targetDir;
334
+ } else {
335
+ if (!cacheOnly) rmSync(targetDir, { recursive: true, force: true });
336
+ }
337
+ }
338
+ if (!resolvedDir && !cacheOnly) {
339
+ await downloadTemplate(src.from, { dir: targetDir, auth: _auth2 });
335
340
  resolvedDir = targetDir;
336
341
  }
342
+ } catch (err) {
343
+ if (!cacheOnly) {
344
+ console.warn(
345
+ `[qarpeo:cms] Failed to download remote source "${src.from}": ${err?.message ?? String(err)}`
346
+ );
347
+ }
348
+ if (existsSync(targetDir)) resolvedDir = targetDir;
337
349
  }
338
350
  } else {
339
351
  resolvedDir = resolve(contentDir, src.from);
@@ -419,9 +431,19 @@ async function readNavJson(dir) {
419
431
  return {};
420
432
  }
421
433
  async function scanContentEntries(options) {
422
- const { contentDir, collectionsConfig = {}, sources = [], exclude } = options;
434
+ const { contentDir, collectionsConfig = {}, sources = [], exclude, shiki } = options;
423
435
  const entries = [];
424
436
  const now = Date.now();
437
+ let shikiPluginInstance = null;
438
+ if (shiki !== false) {
439
+ try {
440
+ const shikiMod = await import('comark/plugins/shiki');
441
+ const shikiPlugin = shikiMod.default || shikiMod;
442
+ const shikiOptions = typeof shiki === "object" ? shiki : {};
443
+ shikiPluginInstance = shikiPlugin(shikiOptions);
444
+ } catch {
445
+ }
446
+ }
425
447
  async function syncSource(source) {
426
448
  if (!source?.resolvedDir || !existsSync(source.resolvedDir)) return;
427
449
  let orderCounter = 0;
@@ -507,7 +529,8 @@ async function scanContentEntries(options) {
507
529
  let ast = { nodes: [], frontmatter: {}, meta: {} };
508
530
  let contentHtml = "";
509
531
  try {
510
- ast = await parseMarkdown(body);
532
+ const plugins = shikiPluginInstance ? [shikiPluginInstance] : [];
533
+ ast = await parseMarkdown(body, { plugins });
511
534
  contentHtml = (await render(ast, { format: "text/html" })).trim();
512
535
  } catch {
513
536
  contentHtml = body;
@@ -3275,14 +3298,31 @@ export default queueHandler;
3275
3298
  const cmsPath = cmsConfig.path || "/cms";
3276
3299
  const contentDirName = cmsConfig.contentDir || "content";
3277
3300
  const resolvedContentDir = existsSync(resolve(nuxt.options.rootDir, contentDirName)) ? resolve(nuxt.options.rootDir, contentDirName) : resolve(nuxt.options.srcDir || nuxt.options.rootDir, contentDirName);
3278
- const cacheDir = nuxt.options.buildDir || resolve(nuxt.options.rootDir, ".nuxt");
3301
+ const cacheDir = resolve(nuxt.options.rootDir, ".nuxt");
3302
+ try {
3303
+ const dotenvPath = resolve(nuxt.options.rootDir, ".env");
3304
+ if (existsSync(dotenvPath)) {
3305
+ const raw = readFileSync(dotenvPath, "utf8");
3306
+ for (const line of raw.split(/\r?\n/)) {
3307
+ const trimmed = line.trim();
3308
+ if (!trimmed || trimmed.startsWith("#")) continue;
3309
+ const eqIdx = trimmed.indexOf("=");
3310
+ if (eqIdx < 1) continue;
3311
+ const key = trimmed.slice(0, eqIdx).trim();
3312
+ const val = trimmed.slice(eqIdx + 1).trim().replace(/^["']|["']$/g, "");
3313
+ if (key && !(key in process.env)) process.env[key] = val;
3314
+ }
3315
+ }
3316
+ } catch {
3317
+ }
3279
3318
  let resolvedSources = [];
3280
3319
  try {
3281
3320
  resolvedSources = await resolveAllCmsSources({
3282
3321
  contentDir: resolvedContentDir,
3283
3322
  rootDir: nuxt.options.rootDir,
3284
3323
  cacheDir,
3285
- configSources: cmsConfig.sources
3324
+ configSources: cmsConfig.sources,
3325
+ cacheOnly: true
3286
3326
  });
3287
3327
  } catch (err) {
3288
3328
  console.warn("[qarpeo:cms] Error resolving CMS sources:", err);
@@ -3346,16 +3386,36 @@ export default queueHandler;
3346
3386
  ])
3347
3387
  )
3348
3388
  };
3389
+ nuxt.hook("build:before", async () => {
3390
+ try {
3391
+ const freshSources = await resolveAllCmsSources({
3392
+ contentDir: resolvedContentDir,
3393
+ rootDir: nuxt.options.rootDir,
3394
+ cacheDir,
3395
+ configSources: cmsConfig.sources
3396
+ });
3397
+ resolvedSources.length = 0;
3398
+ resolvedSources.push(...freshSources);
3399
+ if (nuxt.options.runtimeConfig.qarpeo?.cms) {
3400
+ ;
3401
+ nuxt.options.runtimeConfig.qarpeo.cms.sources = freshSources;
3402
+ }
3403
+ } catch (err) {
3404
+ console.warn("[qarpeo:cms] Error resolving CMS sources in build:before:", err);
3405
+ }
3406
+ });
3349
3407
  const cmsManifestTemplate = addTemplate({
3350
3408
  filename: "qarpeo/cms-manifest.mjs",
3351
3409
  write: true,
3352
3410
  async getContents() {
3353
3411
  try {
3412
+ const shikiOpt = cmsConfig.shiki !== void 0 ? cmsConfig.shiki : cmsConfig.plugins?.shiki;
3354
3413
  const entries = await scanContentEntries({
3355
3414
  contentDir: resolvedContentDir,
3356
3415
  collectionsConfig: cmsConfig.collections,
3357
3416
  sources: resolvedSources,
3358
- exclude: cmsConfig.exclude
3417
+ exclude: cmsConfig.exclude,
3418
+ shiki: shikiOpt !== false ? typeof shikiOpt === "object" ? shikiOpt : true : false
3359
3419
  });
3360
3420
  const payload = JSON.stringify({
3361
3421
  entries,
@@ -3383,11 +3443,13 @@ export const manifestCollections = ${JSON.stringify(cmsConfig.collections || {})
3383
3443
  const prerenderPatterns = Object.entries(routeRules).filter(([_, rule]) => rule?.prerender === true).map(([pattern]) => pattern);
3384
3444
  if (prerenderPatterns.length > 0) {
3385
3445
  try {
3446
+ const shikiOpt = cmsConfig.shiki !== void 0 ? cmsConfig.shiki : cmsConfig.plugins?.shiki;
3386
3447
  const entries = await scanContentEntries({
3387
3448
  contentDir: resolvedContentDir,
3388
3449
  collectionsConfig: cmsConfig.collections,
3389
3450
  sources: resolvedSources,
3390
- exclude: cmsConfig.exclude
3451
+ exclude: cmsConfig.exclude,
3452
+ shiki: shikiOpt !== false ? typeof shikiOpt === "object" ? shikiOpt : true : false
3391
3453
  });
3392
3454
  const matchingRoutes = entries.map((e) => e.path).filter((p) => Boolean(p) && matchPathPatterns(p, prerenderPatterns));
3393
3455
  if (matchingRoutes.length > 0) {
@@ -12,12 +12,14 @@ const props = withDefaults(
12
12
  size?: "xs" | "sm" | "md"
13
13
  color?: "primary" | "neutral" | "secondary"
14
14
  class?: string
15
+ repo?: string
15
16
  }>(),
16
17
  {
17
18
  variant: "dropdown",
18
19
  size: "xs",
19
20
  color: "primary",
20
21
  class: "",
22
+ repo: "qarpeo/qarpeo",
21
23
  },
22
24
  )
23
25
 
@@ -29,6 +31,15 @@ const currentLabel = computed(() => {
29
31
  return currentVersion.value === "latest" ? "latest" : currentVersion.value
30
32
  })
31
33
 
34
+ const releaseNotesUrl = computed(() => {
35
+ const raw = currentVersion.value === "latest" ? currentLabel.value : currentVersion.value
36
+ const clean = (raw || "").replace(/^v/, "").trim()
37
+ if (clean && /^\d+\.\d+/.test(clean)) {
38
+ return `https://github.com/${props.repo}/releases/tag/v${clean}`
39
+ }
40
+ return `https://github.com/${props.repo}/releases`
41
+ })
42
+
32
43
  const dropdownItems = computed(() => [
33
44
  (versions.value || []).map((v) => ({
34
45
  label: v.label,
@@ -113,14 +124,17 @@ const selectItems = computed(() =>
113
124
  </UDropdownMenu>
114
125
  </template>
115
126
 
116
- <!-- Single version or loading fallback: static Nuxt UI UBadge -->
117
- <UBadge
127
+ <!-- Single version or loading fallback: interactive Nuxt UI UButton linking to release notes -->
128
+ <UButton
118
129
  v-else
119
- :color="color"
130
+ :label="currentLabel"
131
+ :aria-label="`Open ${currentLabel} release notes on GitHub`"
120
132
  variant="subtle"
121
133
  :size="size"
122
- class="font-mono"
134
+ :color="color"
135
+ :to="releaseNotesUrl"
136
+ target="_blank"
137
+ class="font-semibold text-xs cursor-pointer hover:bg-primary/10 active:bg-primary/10 transition-colors"
123
138
  :class="props.class"
124
- :label="currentLabel"
125
139
  />
126
140
  </template>
@@ -3118,27 +3118,54 @@ export async function getCMSNavigationTree(event, collectionId, options) {
3118
3118
  section.title = sectionMeta.title;
3119
3119
  if (sectionMeta.icon) section.icon = sectionMeta.icon;
3120
3120
  }
3121
- const isSubFeature = segments.length >= 4 && !meta._isIndex && segments[0] === "docs" && segments[1] === "features";
3121
+ const isFeatureSection = segments[0] === "docs" && segments[1] === "features";
3122
+ const subFeatureKey = isFeatureSection && segments.length >= 3 ? segments[2] : null;
3123
+ const isSubFeature = Boolean(
3124
+ subFeatureKey && (segments.length >= 4 || segments.length === 3 && meta._isIndex && meta._nav?.title && meta._nav.title !== "Features")
3125
+ );
3122
3126
  let targetParent = section;
3123
- if (isSubFeature) {
3124
- const subFeaturePath = `/${segments[0]}/${segments[1]}/${segments[2]}`;
3125
- let subFeatureNode = section.children?.find((c) => c.path === subFeaturePath);
3127
+ if (isSubFeature && subFeatureKey) {
3128
+ const subFeaturePath = `/${segments[0]}/${segments[1]}/${subFeatureKey}`;
3129
+ let subFeatureNode = section.children?.find(
3130
+ (c) => c._subFeatureKey === subFeatureKey || c.path === subFeaturePath
3131
+ );
3126
3132
  if (!subFeatureNode) {
3127
- const subFeatureTitle = segments[2].charAt(0).toUpperCase() + segments[2].slice(1).replace(/-/g, " ");
3133
+ const subFeatureTitle = meta._nav?.title || subFeatureKey.charAt(0).toUpperCase() + subFeatureKey.slice(1).replace(/-/g, " ");
3134
+ const subFeatureOrder = typeof meta._nav?.order === "number" ? meta._nav.order : meta._sectionOrder ?? 500;
3128
3135
  const newNode = {
3129
3136
  title: subFeatureTitle,
3130
3137
  path: subFeaturePath,
3138
+ icon: meta._nav?.icon || "i-lucide-layers",
3131
3139
  children: []
3132
3140
  };
3133
- newNode._groupOrder = 500;
3141
+ newNode._subFeatureKey = subFeatureKey;
3142
+ newNode._groupOrder = subFeatureOrder;
3134
3143
  section.children = section.children || [];
3135
3144
  section.children.push(newNode);
3136
3145
  subFeatureNode = newNode;
3146
+ } else {
3147
+ if (meta._nav?.title && subFeatureNode.title !== meta._nav.title) {
3148
+ subFeatureNode.title = meta._nav.title;
3149
+ }
3150
+ if (meta._nav?.icon) {
3151
+ subFeatureNode.icon = meta._nav.icon;
3152
+ }
3153
+ if (typeof meta._nav?.order === "number") {
3154
+ ;
3155
+ subFeatureNode._groupOrder = meta._nav.order;
3156
+ }
3137
3157
  }
3138
3158
  if (!subFeatureNode.children) {
3139
3159
  subFeatureNode.children = [];
3140
3160
  }
3141
3161
  targetParent = subFeatureNode;
3162
+ targetParent.children.push({
3163
+ title: itemTitle,
3164
+ path: entryPath,
3165
+ icon: meta.navigation?.icon || meta._nav?.icon,
3166
+ _groupOrder: meta._isIndex ? 0 : 500
3167
+ });
3168
+ continue;
3142
3169
  }
3143
3170
  if (meta._group) {
3144
3171
  const groupKey = meta._group.key;
@@ -3235,6 +3262,7 @@ export async function getCMSNavigationTree(event, collectionId, options) {
3235
3262
  delete c._groupKey;
3236
3263
  delete c._groupOrder;
3237
3264
  delete c._subGroupKey;
3265
+ delete c._subFeatureKey;
3238
3266
  cleanAndSortNode(c);
3239
3267
  }
3240
3268
  }
@@ -25,6 +25,7 @@ export interface ScanContentOptions {
25
25
  collectionsConfig?: Record<string, CMSCollectionConfig>;
26
26
  sources?: any[];
27
27
  exclude?: string | string[];
28
+ shiki?: boolean | any;
28
29
  }
29
30
  export declare function extractTOC(md: string): any[];
30
31
  export declare function parseFrontmatter(raw: string): {
@@ -52,11 +52,16 @@ export declare function discoverSources(contentDir: string): Promise<Array<{
52
52
  /**
53
53
  * Resolves all discovered and config-declared sources into absolute disk paths and normalized
54
54
  * prefixes. Downloads remote sources via giget tarball into the cache directory.
55
+ *
56
+ * @param options.cacheOnly When true, skips remote downloads and only uses already-cached dirs.
57
+ * Use this in Nuxt module `setup()` to avoid blocking startup — then call again (without
58
+ * cacheOnly) in a `build:before` hook to fetch any missing remote sources.
55
59
  */
56
60
  export declare function resolveAllCmsSources(options: {
57
61
  contentDir: string;
58
62
  rootDir: string;
59
63
  cacheDir: string;
60
64
  configSources?: CMSSourceConfig[];
65
+ cacheOnly?: boolean;
61
66
  }): Promise<CMSResolvedSource[]>;
62
67
  export { matchesSourceFilters, matchesGlobFilter } from "../runtime/server/utils/cms-filter";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qarpeo",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Zero-config Cloudflare Edge Platform for Nuxt",
5
5
  "keywords": [
6
6
  "analytics-engine",
@@ -56,7 +56,7 @@
56
56
  "@comark/nuxt": "^0.8.1",
57
57
  "@comark/vue": "^0.8.1",
58
58
  "@nuxt/devtools-kit": "^4.1.0",
59
- "@nuxt/kit": "npm:@nuxt/kit-nightly@^5.0.0-2611051431-8a89118",
59
+ "@nuxt/kit": "npm:@nuxt/kit-nightly@^5.0.0-2611052317-a04317f",
60
60
  "@simplewebauthn/browser": "14.0.0",
61
61
  "@simplewebauthn/server": "14.0.3",
62
62
  "citty": "^0.2.2",
@@ -81,7 +81,7 @@
81
81
  "@typescript/typescript6": "^6.0.2",
82
82
  "h3": "^2.0.8",
83
83
  "nitro": "3.0.261103-rc",
84
- "nuxt": "npm:nuxt-nightly@^5.0.0-2611051431-8a89118",
84
+ "nuxt": "npm:nuxt-nightly@^5.0.0-2611052317-a04317f",
85
85
  "typescript": "^7.0.2",
86
86
  "unbuild": "^3.6.1",
87
87
  "vite-plus": "1.5.0",