@foundrykit/guides-plugin 0.0.0-stage → 0.1.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.
Files changed (41) hide show
  1. package/README.md +92 -2
  2. package/dist/collections/guides.d.ts +8 -0
  3. package/dist/collections/guides.js +129 -0
  4. package/dist/collections/guides.js.map +1 -0
  5. package/dist/collections/siteGuides.d.ts +7 -0
  6. package/dist/collections/siteGuides.js +139 -0
  7. package/dist/collections/siteGuides.js.map +1 -0
  8. package/dist/components/GuideArticle.d.ts +24 -0
  9. package/dist/components/GuideArticle.js +79 -0
  10. package/dist/components/GuideArticle.js.map +1 -0
  11. package/dist/components/GuideSearch.d.ts +5 -0
  12. package/dist/components/GuideSearch.js +83 -0
  13. package/dist/components/GuideSearch.js.map +1 -0
  14. package/dist/components/GuidesNavLink.d.ts +2 -0
  15. package/dist/components/GuidesNavLink.js +16 -0
  16. package/dist/components/GuidesNavLink.js.map +1 -0
  17. package/dist/components/GuidesView.d.ts +6 -0
  18. package/dist/components/GuidesView.js +212 -0
  19. package/dist/components/GuidesView.js.map +1 -0
  20. package/dist/components/Help.d.ts +12 -0
  21. package/dist/components/Help.js +112 -0
  22. package/dist/components/Help.js.map +1 -0
  23. package/dist/exports/client.d.ts +2 -0
  24. package/dist/exports/client.js +4 -0
  25. package/dist/exports/client.js.map +1 -0
  26. package/dist/exports/rsc.d.ts +1 -0
  27. package/dist/exports/rsc.js +3 -0
  28. package/dist/exports/rsc.js.map +1 -0
  29. package/dist/hub.d.ts +33 -0
  30. package/dist/hub.js +40 -0
  31. package/dist/hub.js.map +1 -0
  32. package/dist/index.d.ts +12 -0
  33. package/dist/index.js +111 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/searchGuides.d.ts +12 -0
  36. package/dist/searchGuides.js +63 -0
  37. package/dist/searchGuides.js.map +1 -0
  38. package/dist/sync.d.ts +29 -0
  39. package/dist/sync.js +71 -0
  40. package/dist/sync.js.map +1 -0
  41. package/package.json +106 -3
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n CollectionConfig,\n Config,\n GlobalConfig,\n Payload,\n TaskConfig,\n} from 'payload';\n\nimport { guidesCollection } from './collections/guides.js';\nimport { siteGuidesCollection } from './collections/siteGuides.js';\nimport {\n GUIDES_SLUG,\n type GuidesPluginConfig,\n type ResolvedConfig,\n resolveConfig,\n SITE_GUIDES_SLUG,\n} from './hub.js';\nimport { syncGuides } from './sync.js';\n\nexport type {\n GuidesPluginConfig,\n GuidesPluginConfig as PluginConfig,\n} from './hub.js';\nexport { syncGuides } from './sync.js';\n\nconst HELP_BUTTON = '@foundrykit/guides-plugin/client#HelpButton';\n\nconst skipHelp = (slug: string) =>\n slug === GUIDES_SLUG ||\n slug === SITE_GUIDES_SLUG ||\n slug === 'users' ||\n slug.startsWith('payload-');\n\n// Payload reads beforeDocumentControls from `edit` on collections but from `elements` on globals\n// (@payloadcms/next views/Document/renderDocumentSlots), so the slot depends on the kind.\nconst withHelp =\n <T extends CollectionConfig | GlobalConfig>(slot: 'edit' | 'elements') =>\n (entry: T): T => {\n if (skipHelp(entry.slug)) return entry;\n const components = (entry.admin?.components ?? {}) as Record<\n string,\n { beforeDocumentControls?: unknown[] }\n >;\n const current = components[slot] ?? {};\n return {\n ...entry,\n admin: {\n ...entry.admin,\n components: {\n ...components,\n [slot]: {\n ...current,\n beforeDocumentControls: [\n ...(current.beforeDocumentControls ?? []),\n HELP_BUTTON,\n ],\n },\n },\n },\n } as T;\n };\n\nconst syncTask = (config: ResolvedConfig): TaskConfig => ({\n slug: 'guidesSync',\n label: 'Sync guides from the hub',\n handler: async ({ req }) => ({\n output: await syncGuides(req.payload, config),\n }),\n ...(config.schedule\n ? { schedule: [{ cron: config.schedule, queue: 'default' }] }\n : {}),\n});\n\n/** Fills an empty local copy on first boot, without holding startup up or failing it. */\nconst syncIfEmpty = async (payload: Payload, config: ResolvedConfig) => {\n try {\n const { totalDocs } = await payload.count({\n collection: GUIDES_SLUG as never,\n });\n if (totalDocs === 0) await syncGuides(payload, config);\n } catch (err) {\n payload.logger.warn(\n { err },\n 'Guides: first sync from the hub failed; the next webhook or scheduled pull will retry.'\n );\n }\n};\n\n/**\n * CMS guides from the Umi guides hub: a Guides page in the sidebar, a Help button on every edit\n * page, and local search, all read from a local copy the hub keeps in sync. Umi staff\n * (`canAuthor`) write site-specific guides in the Site guides collection; publishing saves\n * them to the hub.\n */\nexport const guidesPlugin =\n (options: GuidesPluginConfig = {}) =>\n (config: Config): Config => {\n if (options.disabled) return config;\n const resolved = resolveConfig(options);\n const components = config.admin?.components ?? {};\n const onInit = config.onInit;\n\n return {\n ...config,\n collections: [\n ...(config.collections ?? []).map(withHelp<CollectionConfig>('edit')),\n guidesCollection(resolved),\n siteGuidesCollection(resolved),\n ],\n globals: (config.globals ?? []).map(withHelp<GlobalConfig>('elements')),\n admin: {\n ...config.admin,\n components: {\n ...components,\n afterNavLinks: [\n ...(components.afterNavLinks ?? []),\n '@foundrykit/guides-plugin/client#GuidesNavLink',\n ],\n views: {\n ...components.views,\n guides: {\n Component: '@foundrykit/guides-plugin/rsc#GuidesView',\n path: '/guides',\n meta: { title: 'Guides' },\n },\n },\n },\n },\n jobs: {\n ...config.jobs,\n tasks: [...(config.jobs?.tasks ?? []), syncTask(resolved)],\n },\n onInit: async payload => {\n await onInit?.(payload);\n void syncIfEmpty(payload, resolved);\n },\n };\n };\n\nexport default guidesPlugin;\n"],"names":["guidesCollection","siteGuidesCollection","GUIDES_SLUG","resolveConfig","SITE_GUIDES_SLUG","syncGuides","HELP_BUTTON","skipHelp","slug","startsWith","withHelp","slot","entry","components","admin","current","beforeDocumentControls","syncTask","config","label","handler","req","output","payload","schedule","cron","queue","syncIfEmpty","totalDocs","count","collection","err","logger","warn","guidesPlugin","options","disabled","resolved","onInit","collections","map","globals","afterNavLinks","views","guides","Component","path","meta","title","jobs","tasks"],"mappings":"AAQA,SAASA,gBAAgB,QAAQ,0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};
7
+ /**
8
+ * Plain-question search over the guides (threshold 0.2, 3-char minimum, as tuned on Turquoise).
9
+ * Each remaining word is matched on its own and the scores summed, so "how do I take an offer
10
+ * down" ranks by "take", "offer", "down" rather than needing the whole phrase to appear.
11
+ */
12
+ export declare const searchGuides: <T extends GuideHit>(guides: T[], query: string) => T[];
@@ -0,0 +1,63 @@
1
+ import Fuse from 'fuse.js';
2
+ const STOP_WORDS = new Set([
3
+ 'how',
4
+ 'do',
5
+ 'i',
6
+ 'the',
7
+ 'a',
8
+ 'an',
9
+ 'to',
10
+ 'in',
11
+ 'on',
12
+ 'my',
13
+ 'of',
14
+ 'for',
15
+ 'is',
16
+ 'can'
17
+ ]);
18
+ const LIMIT = 8;
19
+ /**
20
+ * Plain-question search over the guides (threshold 0.2, 3-char minimum, as tuned on Turquoise).
21
+ * Each remaining word is matched on its own and the scores summed, so "how do I take an offer
22
+ * down" ranks by "take", "offer", "down" rather than needing the whole phrase to appear.
23
+ */ export const searchGuides = (guides, query)=>{
24
+ const words = query.toLowerCase().split(/[^a-z0-9']+/).filter((w)=>w.length >= 3 && !STOP_WORDS.has(w));
25
+ if (words.length === 0) return [];
26
+ const fuse = new Fuse(guides, {
27
+ threshold: 0.2,
28
+ minMatchCharLength: 3,
29
+ ignoreLocation: true,
30
+ includeScore: true,
31
+ keys: [
32
+ {
33
+ name: 'title',
34
+ weight: 3
35
+ },
36
+ {
37
+ name: 'summary',
38
+ weight: 2
39
+ },
40
+ {
41
+ name: 'bodyText',
42
+ weight: 1
43
+ }
44
+ ]
45
+ });
46
+ // Lower Fuse score is better; a word that matches nothing contributes nothing.
47
+ const totals = new Map();
48
+ for (const word of words){
49
+ for (const { item, score = 1 } of fuse.search(word)){
50
+ const entry = totals.get(item.slug) ?? {
51
+ guide: item,
52
+ score: 0
53
+ };
54
+ entry.score += 1 - score;
55
+ totals.set(item.slug, entry);
56
+ }
57
+ }
58
+ return [
59
+ ...totals.values()
60
+ ].sort((a, b)=>b.score - a.score).slice(0, LIMIT).map((e)=>e.guide);
61
+ };
62
+
63
+ //# sourceMappingURL=searchGuides.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/searchGuides.ts"],"sourcesContent":["import Fuse from 'fuse.js';\n\nexport type GuideHit = {\n slug: string;\n title: string;\n summary: string;\n bodyText: string;\n};\n\nconst STOP_WORDS = new Set([\n 'how',\n 'do',\n 'i',\n 'the',\n 'a',\n 'an',\n 'to',\n 'in',\n 'on',\n 'my',\n 'of',\n 'for',\n 'is',\n 'can',\n]);\nconst LIMIT = 8;\n\n/**\n * Plain-question search over the guides (threshold 0.2, 3-char minimum, as tuned on Turquoise).\n * Each remaining word is matched on its own and the scores summed, so \"how do I take an offer\n * down\" ranks by \"take\", \"offer\", \"down\" rather than needing the whole phrase to appear.\n */\nexport const searchGuides = <T extends GuideHit>(\n guides: T[],\n query: string\n): T[] => {\n const words = query\n .toLowerCase()\n .split(/[^a-z0-9']+/)\n .filter(w => w.length >= 3 && !STOP_WORDS.has(w));\n if (words.length === 0) return [];\n\n const fuse = new Fuse(guides, {\n threshold: 0.2,\n minMatchCharLength: 3,\n ignoreLocation: true,\n includeScore: true,\n keys: [\n { name: 'title', weight: 3 },\n { name: 'summary', weight: 2 },\n { name: 'bodyText', weight: 1 },\n ],\n });\n\n // Lower Fuse score is better; a word that matches nothing contributes nothing.\n const totals = new Map<string, { guide: T; score: number }>();\n for (const word of words) {\n for (const { item, score = 1 } of fuse.search(word)) {\n const entry = totals.get(item.slug) ?? { guide: item, score: 0 };\n entry.score += 1 - score;\n totals.set(item.slug, entry);\n }\n }\n\n return [...totals.values()]\n .sort((a, b) => b.score - a.score)\n .slice(0, LIMIT)\n .map(e => e.guide);\n};\n"],"names":["Fuse","STOP_WORDS","Set","LIMIT","searchGuides","guides","query","words","toLowerCase","split","filter","w","length","has","fuse","threshold","minMatchCharLength","ignoreLocation","includeScore","keys","name","weight","totals","Map","word","item","score","search","entry","get","slug","guide","set","values","sort","a","b","slice","map","e"],"mapp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 @@
1
+ import type { Payload } from 'payload';
2
+ import { type ResolvedConfig } from './hub.js';
3
+ /** One guide as the hub's feed sends it. */
4
+ export type FeedGuide = {
5
+ id: number | string;
6
+ title: string;
7
+ slug: string;
8
+ summary: string;
9
+ scope: 'general' | 'site';
10
+ topic: {
11
+ title?: string;
12
+ order?: number | null;
13
+ } | null;
14
+ helpContexts: string[];
15
+ order: number | null;
16
+ body: unknown;
17
+ bodyText: string;
18
+ updatedAt: string;
19
+ };
20
+ /**
21
+ * Makes the local guides collection match this site's feed from the hub: adds new guides,
22
+ * updates changed ones and removes any the site is no longer entitled to. Reports the plugin
23
+ * version and features on the way, so the hub's Sites record stays current.
24
+ */
25
+ export declare const syncGuides: (payload: Payload, config: ResolvedConfig) => Promise<{
26
+ changed: number;
27
+ removed: number;
28
+ total: number;
29
+ }>;
package/dist/sync.js ADDED
@@ -0,0 +1,71 @@
1
+ import { GUIDES_SLUG, hubFetch, PLUGIN_VERSION } from './hub.js';
2
+ const toLocal = (g)=>({
3
+ hubId: String(g.id),
4
+ title: g.title,
5
+ slug: g.slug,
6
+ summary: g.summary,
7
+ scope: g.scope,
8
+ topic: {
9
+ title: g.topic?.title ?? null,
10
+ order: g.topic?.order ?? null
11
+ },
12
+ helpContexts: g.helpContexts,
13
+ order: g.order,
14
+ body: g.body,
15
+ bodyText: g.bodyText,
16
+ hubUpdatedAt: g.updatedAt
17
+ });
18
+ /**
19
+ * Makes the local guides collection match this site's feed from the hub: adds new guides,
20
+ * updates changed ones and removes any the site is no longer entitled to. Reports the plugin
21
+ * version and features on the way, so the hub's Sites record stays current.
22
+ */ export const syncGuides = async (payload, config)=>{
23
+ const params = new URLSearchParams({
24
+ pluginVersion: PLUGIN_VERSION,
25
+ features: config.features.join(',')
26
+ });
27
+ const res = await hubFetch(config, `/api/sites/feed?${params}`);
28
+ if (!res.ok) throw new Error(`The guides hub answered ${res.status} to the feed request.`);
29
+ const { guides } = await res.json();
30
+ const { docs } = await payload.find({
31
+ collection: GUIDES_SLUG,
32
+ pagination: false,
33
+ depth: 0,
34
+ select: {
35
+ hubId: true,
36
+ hubUpdatedAt: true
37
+ }
38
+ });
39
+ const local = new Map(docs.map((d)=>[
40
+ d.hubId,
41
+ d
42
+ ]));
43
+ let changed = 0;
44
+ for (const guide of guides){
45
+ const existing = local.get(String(guide.id));
46
+ local.delete(String(guide.id));
47
+ if (existing?.hubUpdatedAt === guide.updatedAt) continue;
48
+ const data = toLocal(guide);
49
+ if (existing) await payload.update({
50
+ collection: GUIDES_SLUG,
51
+ id: existing.id,
52
+ data
53
+ });
54
+ else await payload.create({
55
+ collection: GUIDES_SLUG,
56
+ data
57
+ });
58
+ changed++;
59
+ }
60
+ for (const stale of local.values())await payload.delete({
61
+ collection: GUIDES_SLUG,
62
+ id: stale.id
63
+ });
64
+ return {
65
+ changed,
66
+ removed: local.size,
67
+ total: guides.length
68
+ };
69
+ };
70
+
71
+ //# sourceMappingURL=sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/sync.ts"],"sourcesContent":["import type { Payload } from 'payload';\n\nimport {\n GUIDES_SLUG,\n hubFetch,\n PLUGIN_VERSION,\n type ResolvedConfig,\n} from './hub.js';\n\n/** One guide as the hub's feed sends it. */\nexport type FeedGuide = {\n id: number | string;\n title: string;\n slug: string;\n summary: string;\n scope: 'general' | 'site';\n topic: { title?: string; order?: number | null } | null;\n helpContexts: string[];\n order: number | null;\n body: unknown;\n bodyText: string;\n updatedAt: string;\n};\n\nconst toLocal = (g: FeedGuide) => ({\n hubId: String(g.id),\n title: g.title,\n slug: g.slug,\n summary: g.summary,\n scope: g.scope,\n topic: { title: g.topic?.title ?? null, order: g.topic?.order ?? null },\n helpContexts: g.helpContexts,\n order: g.order,\n body: g.body,\n bodyText: g.bodyText,\n hubUpdatedAt: g.updatedAt,\n});\n\n/**\n * Makes the local guides collection match this site's feed from the hub: adds new guides,\n * updates changed ones and removes any the site is no longer entitled to. Reports the plugin\n * version and features on the way, so the hub's Sites record stays current.\n */\nexport const syncGuides = async (payload: Payload, config: ResolvedConfig) => {\n const params = new URLSearchParams({\n pluginVersion: PLUGIN_VERSION,\n features: config.features.join(','),\n });\n const res = await hubFetch(config, `/api/sites/feed?${params}`);\n if (!res.ok)\n throw new Error(\n `The guides hub answered ${res.status} to the feed request.`\n );\n const { guides } = (await res.json()) as { guides: FeedGuide[] };\n\n const { docs } = await payload.find({\n collection: GUIDES_SLUG as never,\n pagination: false,\n depth: 0,\n select: { hubId: true, hubUpdatedAt: true } as never,\n });\n const local = new Map(\n (docs as { id: number; hubId: string; hubUpdatedAt?: string }[]).map(d => [\n d.hubId,\n d,\n ])\n );\n\n let changed = 0;\n for (const guide of guides) {\n const existing = local.get(String(guide.id));\n local.delete(String(guide.id));\n if (existing?.hubUpdatedAt === guide.updatedAt) continue;\n const data = toLocal(guide) as never;\n if (existing)\n await payload.update({\n collection: GUIDES_SLUG as never,\n id: existing.id,\n data,\n });\n else await payload.create({ collection: GUIDES_SLUG as never, data });\n changed++;\n }\n for (const stale of local.values())\n await payload.delete({ collection: GUIDES_SLUG as never, id: stale.id });\n\n return { changed, removed: local.size, total: guides.length };\n};\n"],"names":["GUIDES_SLUG","hubFetch","PLUGIN_VERSION","toLocal","g","hubId","String","id","title","slug","summary","scope","topic","order","helpContexts","body","bodyText","hubUpdatedAt","updatedAt","syncGuides","payload","config","params","URLSearchParams","pluginVersion","features","join","res","ok","Error","status","guides","json","docs","find","collection","pagination","depth","select","local","Map","map","d","changed","guide","existing","get","delete","data","update","create","stale","values","removed","size","total","length"],"mappings":"AAEA,SACEA,WAAW,EACXC,QAAQ,EACRC,cAAc,QAET,WAAW;AAiBlB,MAAMC,UAAU,CAACC,IAAkB,CAAA;QACjCC,OAAOC,OAAOF,EAAEG,EAAE;QAClBC,OAAOJ,EAAEI,KAAK;QACdC,MAAML,EAAEK,IAAI;QACZC,SAASN,EAAEM,OAAO;QAClBC,OAAOP,EAAEO,KAAK;QACdC,OAAO;YAAEJ,OAAOJ,E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C,EAAE;YACfyC;QACF;aACG,MAAM5B,QAAQ8B,MAAM,CAAC;YAAEf,YAAYnC;YAAsBgD;QAAK;QACnEL;IACF;IACA,KAAK,MAAMQ,SAASZ,MAAMa,MAAM,GAC9B,MAAMhC,QAAQ2B,MAAM,CAAC;QAAEZ,YAAYnC;QAAsBO,IAAI4C,MAAM5C,EAAE;IAAC;IAExE,OAAO;QAAEoC;QAASU,SAASd,MAAMe,IAAI;QAAEC,OAAOxB,OAAOyB,MAAM;IAAC;AAC9D,EAAE"}
package/package.json CHANGED
@@ -1,6 +1,109 @@
1
1
  {
2
2
  "name": "@foundrykit/guides-plugin",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "CMS guides for Payload 3 client sites: a Guides page, Help buttons on edit pages and local search, synced read-only from the Umi guides hub, with site-specific guides written in place by Umi staff.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "author": {
8
+ "name": "Isaac SJ",
9
+ "email": "isaac@umidigital.co.uk"
10
+ },
11
+ "keywords": [
12
+ "payload",
13
+ "payloadcms",
14
+ "plugin",
15
+ "guides",
16
+ "help",
17
+ "documentation"
18
+ ],
19
+ "exports": {
20
+ ".": {
21
+ "import": "./dist/index.js",
22
+ "types": "./dist/index.d.ts",
23
+ "default": "./dist/index.js"
24
+ },
25
+ "./client": {
26
+ "import": "./dist/exports/client.js",
27
+ "types": "./dist/exports/client.d.ts",
28
+ "default": "./dist/exports/client.js"
29
+ },
30
+ "./rsc": {
31
+ "import": "./dist/exports/rsc.js",
32
+ "types": "./dist/exports/rsc.d.ts",
33
+ "default": "./dist/exports/rsc.js"
34
+ }
35
+ },
36
+ "main": "./dist/index.js",
37
+ "types": "./dist/index.d.ts",
38
+ "files": [
39
+ "dist"
40
+ ],
41
+ "dependencies": {
42
+ "fuse.js": "7.5.0"
43
+ },
44
+ "devDependencies": {
45
+ "@payloadcms/db-sqlite": "3.84.1",
46
+ "@payloadcms/next": "3.84.1",
47
+ "@payloadcms/richtext-lexical": "3.84.1",
48
+ "@payloadcms/ui": "3.84.1",
49
+ "@swc-node/register": "1.10.9",
50
+ "@swc/cli": "0.6.0",
51
+ "@testing-library/react": "16.3.0",
52
+ "@types/node": "22.19.9",
53
+ "@types/react": "19.2.14",
54
+ "@types/react-dom": "19.2.3",
55
+ "copyfiles": "2.4.1",
56
+ "cross-env": "^7.0.3",
57
+ "graphql": "^16.8.1",
58
+ "jsdom": "26.1.0",
59
+ "next": "16.2.6",
60
+ "payload": "3.84.1",
61
+ "react": "19.2.6",
62
+ "react-dom": "19.2.6",
63
+ "rimraf": "3.0.2",
64
+ "sharp": "0.34.2",
65
+ "typescript": "5.9.2",
66
+ "vite-tsconfig-paths": "6.0.5",
67
+ "vitest": "4.1.10"
68
+ },
69
+ "peerDependencies": {
70
+ "@payloadcms/next": "^3.37.0",
71
+ "@payloadcms/richtext-lexical": "^3.37.0",
72
+ "@payloadcms/ui": "^3.37.0",
73
+ "next": ">=15",
74
+ "payload": "^3.37.0",
75
+ "react": "^19"
76
+ },
77
+ "engines": {
78
+ "node": ">=20.9.0"
79
+ },
80
+ "publishConfig": {
81
+ "access": "public"
82
+ },
83
+ "repository": {
84
+ "type": "git",
85
+ "url": "git+https://github.com/umi-labs/foundry.git",
86
+ "directory": "packages/payload/guides-plugin"
87
+ },
88
+ "homepage": "https://github.com/umi-labs/foundry/tree/prod/packages/payload/guides-plugin#readme",
89
+ "bugs": {
90
+ "url": "https://github.com/umi-labs/foundry/issues"
91
+ },
92
+ "scripts": {
93
+ "build": "pnpm copyfiles && pnpm build:types && pnpm build:swc",
94
+ "build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths --ignore \"**/*.test.ts\" --ignore \"**/*.test.tsx\" --ignore \"**/*.d.ts\"",
95
+ "build:types": "tsc --outDir dist --rootDir ./src",
96
+ "clean": "rimraf {dist,*.tsbuildinfo}",
97
+ "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
98
+ "dev": "next dev dev",
99
+ "dev:generate-importmap": "pnpm dev:payload generate:importmap",
100
+ "dev:generate-types": "pnpm dev:payload generate:types",
101
+ "dev:payload": "cross-env PAYLOAD_CONFIG_PATH=./dev/payload.config.ts payload",
102
+ "generate:importmap": "pnpm dev:generate-importmap",
103
+ "generate:types": "pnpm dev:generate-types",
104
+ "verify:pack": "node scripts/verify-pack.mjs",
105
+ "test": "pnpm test:unit && pnpm test:int",
106
+ "test:unit": "vitest run src",
107
+ "test:int": "vitest run dev/int.spec.ts"
108
+ }
6
109
  }