vite-wp 0.1.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.
Files changed (82) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +132 -0
  3. package/dist/astro.d.ts +5 -0
  4. package/dist/astro.js +27 -0
  5. package/dist/cli.d.ts +2 -0
  6. package/dist/cli.js +40 -0
  7. package/dist/commands/dev.d.ts +1 -0
  8. package/dist/commands/dev.js +62 -0
  9. package/dist/commands/doctor.d.ts +6 -0
  10. package/dist/commands/doctor.js +139 -0
  11. package/dist/commands/init.d.ts +1 -0
  12. package/dist/commands/init.js +55 -0
  13. package/dist/commands/smoke.d.ts +1 -0
  14. package/dist/commands/smoke.js +138 -0
  15. package/dist/commands/types.d.ts +1 -0
  16. package/dist/commands/types.js +67 -0
  17. package/dist/config.d.ts +71 -0
  18. package/dist/config.js +74 -0
  19. package/dist/content.d.ts +44 -0
  20. package/dist/content.js +190 -0
  21. package/dist/dev-toolbar/vitewp-toolbar.d.ts +23 -0
  22. package/dist/dev-toolbar/vitewp-toolbar.js +144 -0
  23. package/dist/index.d.ts +4 -0
  24. package/dist/index.js +2 -0
  25. package/dist/live.config.d.ts +64 -0
  26. package/dist/live.config.js +21 -0
  27. package/dist/runtime/astro.d.ts +4 -0
  28. package/dist/runtime/astro.js +69 -0
  29. package/dist/runtime/composer.d.ts +2 -0
  30. package/dist/runtime/composer.js +36 -0
  31. package/dist/runtime/php.d.ts +3 -0
  32. package/dist/runtime/php.js +79 -0
  33. package/dist/runtime/ports.d.ts +3 -0
  34. package/dist/runtime/ports.js +38 -0
  35. package/dist/runtime/process.d.ts +12 -0
  36. package/dist/runtime/process.js +51 -0
  37. package/dist/runtime/proxy.d.ts +6 -0
  38. package/dist/runtime/proxy.js +204 -0
  39. package/dist/runtime/wp-config.d.ts +3 -0
  40. package/dist/runtime/wp-config.js +82 -0
  41. package/dist/wordpress/client.d.ts +98 -0
  42. package/dist/wordpress/client.js +133 -0
  43. package/dist/wordpress/generated-types.d.ts +33 -0
  44. package/dist/wordpress/generated-types.js +2 -0
  45. package/dist/wordpress/menus.d.ts +24 -0
  46. package/dist/wordpress/menus.js +20 -0
  47. package/dist/wordpress/schemas.d.ts +58 -0
  48. package/dist/wordpress/schemas.js +39 -0
  49. package/dist/wordpress/templates.d.ts +19 -0
  50. package/dist/wordpress/templates.js +88 -0
  51. package/package.json +78 -0
  52. package/starter/.env.example +15 -0
  53. package/starter/astro.config.mjs +16 -0
  54. package/starter/composer.json +37 -0
  55. package/starter/src/env.d.ts +1 -0
  56. package/starter/src/live.config.ts +22 -0
  57. package/starter/src/pages/[...slug].astro +101 -0
  58. package/starter/src/templates/404.astro +11 -0
  59. package/starter/src/templates/pages/.gitkeep +0 -0
  60. package/starter/src/templates/pages/default.astro +12 -0
  61. package/starter/src/templates/pages/front-page.astro +13 -0
  62. package/starter/src/templates/partials/Header.astro +23 -0
  63. package/starter/src/templates/partials/Pagination.astro +21 -0
  64. package/starter/src/templates/post-types/.gitkeep +0 -0
  65. package/starter/src/templates/posts/.gitkeep +0 -0
  66. package/starter/src/templates/posts/archive.astro +25 -0
  67. package/starter/src/templates/posts/single.astro +12 -0
  68. package/starter/src/templates/search.astro +30 -0
  69. package/starter/src/templates/taxonomies/.gitkeep +0 -0
  70. package/starter/src/templates/taxonomies/taxonomy-[taxonomy].astro +28 -0
  71. package/starter/src/wordpress/client.ts +263 -0
  72. package/starter/src/wordpress/generated-types.ts +38 -0
  73. package/starter/src/wordpress/menus.ts +51 -0
  74. package/starter/src/wordpress/schemas.ts +44 -0
  75. package/starter/src/wordpress/templates.ts +113 -0
  76. package/starter/tsconfig.json +4 -0
  77. package/starter/vitewp.config.ts +29 -0
  78. package/starter/wordpress/content/mu-plugins/.gitkeep +0 -0
  79. package/starter/wordpress/content/mu-plugins/vitewp-bridge.php +560 -0
  80. package/starter/wordpress/content/themes/vitewp/functions.php +9 -0
  81. package/starter/wordpress/content/themes/vitewp/index.php +22 -0
  82. package/starter/wordpress/content/themes/vitewp/style.css +10 -0
@@ -0,0 +1,38 @@
1
+ // Generated by ViteWP. Do not edit by hand.
2
+
3
+ export type WpPostType = "post" | "page" | "attachment";
4
+ export type WpTaxonomy = "category" | "post_tag";
5
+
6
+ export type WpRestBaseByPostType = {
7
+ "post": "posts";
8
+ "page": "pages";
9
+ "attachment": "media";
10
+ };
11
+ export type WpArchiveSlugByPostType = {
12
+ "post": null;
13
+ "page": null;
14
+ "attachment": null;
15
+ };
16
+ export type WpRestBaseByTaxonomy = {
17
+ "category": "categories";
18
+ "post_tag": "tags";
19
+ };
20
+
21
+ export interface WpRenderedField {
22
+ rendered: string;
23
+ protected?: boolean;
24
+ }
25
+
26
+ export interface WpContentItem<PostType extends WpPostType = WpPostType> {
27
+ id: number;
28
+ slug: string;
29
+ type: PostType;
30
+ link: string;
31
+ title: WpRenderedField;
32
+ content: WpRenderedField;
33
+ excerpt?: WpRenderedField;
34
+ date?: string;
35
+ modified?: string;
36
+ }
37
+
38
+ export interface WpArchiveItem<PostType extends WpPostType = WpPostType> extends WpContentItem<PostType> {}
@@ -0,0 +1,51 @@
1
+ import { getWordPressBaseUrl } from './client.js';
2
+
3
+ export interface WpMenuItem {
4
+ id: number;
5
+ parent: number;
6
+ title: string;
7
+ url: string;
8
+ target: string;
9
+ classes: string[];
10
+ object: string;
11
+ objectId: number;
12
+ type: string;
13
+ }
14
+
15
+ export interface WpMenu {
16
+ id: number;
17
+ slug: string;
18
+ name: string;
19
+ items: WpMenuItem[];
20
+ }
21
+
22
+ export interface WpMenusPayload {
23
+ locations: Record<string, number>;
24
+ menus: WpMenu[];
25
+ }
26
+
27
+ export async function getMenus(): Promise<WpMenusPayload> {
28
+ const response = await fetch(`${getWordPressBaseUrl()}/wp-json/vitewp/v1/menus`);
29
+
30
+ if (!response.ok) {
31
+ throw new Error(`Could not fetch WordPress menus: ${response.status} ${response.statusText}`);
32
+ }
33
+
34
+ return response.json() as Promise<WpMenusPayload>;
35
+ }
36
+
37
+ export async function getMenuByLocation(location: string): Promise<WpMenu | null> {
38
+ const payload = await getMenus();
39
+ const menuId = payload.locations[location];
40
+
41
+ if (!menuId) {
42
+ return null;
43
+ }
44
+
45
+ return payload.menus.find((menu) => menu.id === menuId) ?? null;
46
+ }
47
+
48
+ export async function getMenuBySlug(slug: string): Promise<WpMenu | null> {
49
+ const payload = await getMenus();
50
+ return payload.menus.find((menu) => menu.slug === slug) ?? null;
51
+ }
@@ -0,0 +1,44 @@
1
+ import { z } from 'astro/zod';
2
+
3
+ export const wpRenderedFieldSchema = z.looseObject({
4
+ rendered: z.string(),
5
+ protected: z.boolean().optional(),
6
+ });
7
+
8
+ export const wpContentItemSchema = z.looseObject({
9
+ id: z.number(),
10
+ slug: z.string(),
11
+ type: z.string(),
12
+ link: z.string(),
13
+ title: wpRenderedFieldSchema,
14
+ content: wpRenderedFieldSchema,
15
+ excerpt: wpRenderedFieldSchema.optional(),
16
+ date: z.string().optional(),
17
+ modified: z.string().optional(),
18
+ });
19
+
20
+ export const wpResolvedRouteSchema = z.looseObject({
21
+ kind: z.string(),
22
+ postType: z.string(),
23
+ restBase: z.string(),
24
+ slug: z.string(),
25
+ });
26
+
27
+ export const wpMenuItemSchema = z.looseObject({
28
+ id: z.number(),
29
+ parent: z.number(),
30
+ title: z.string(),
31
+ url: z.string(),
32
+ target: z.string(),
33
+ classes: z.array(z.string()),
34
+ object: z.string(),
35
+ objectId: z.number(),
36
+ type: z.string(),
37
+ });
38
+
39
+ export const wpMenuSchema = z.looseObject({
40
+ id: z.number(),
41
+ slug: z.string(),
42
+ name: z.string(),
43
+ items: z.array(wpMenuItemSchema),
44
+ });
@@ -0,0 +1,113 @@
1
+ import type { WpContentItem, WpResolvedRoute } from './client.js';
2
+
3
+ export interface TemplateContext {
4
+ route: WpResolvedRoute;
5
+ title: string;
6
+ content: string;
7
+ excerpt: string;
8
+ slug: string;
9
+ postType: string;
10
+ items: WpContentItem[];
11
+ page: number;
12
+ perPage: number;
13
+ total: number;
14
+ totalPages: number;
15
+ search?: string;
16
+ taxonomy?: string;
17
+ termName?: string;
18
+ }
19
+
20
+ export function createTemplateContext(route: WpResolvedRoute): TemplateContext {
21
+ switch (route.kind) {
22
+ case 'postsArchive':
23
+ case 'postTypeArchive':
24
+ case 'search':
25
+ return {
26
+ route,
27
+ title: route.title,
28
+ content: '',
29
+ excerpt: '',
30
+ slug: route.slug,
31
+ postType: route.postType,
32
+ items: route.items,
33
+ page: route.page,
34
+ perPage: route.perPage,
35
+ total: route.total,
36
+ totalPages: route.totalPages,
37
+ search: route.search,
38
+ };
39
+ case 'taxonomyArchive':
40
+ return {
41
+ route,
42
+ title: route.title,
43
+ content: '',
44
+ excerpt: '',
45
+ slug: route.slug,
46
+ postType: route.postType,
47
+ items: route.items,
48
+ page: route.page,
49
+ perPage: route.perPage,
50
+ total: route.total,
51
+ totalPages: route.totalPages,
52
+ taxonomy: route.taxonomy,
53
+ termName: route.termName,
54
+ };
55
+ case 'page':
56
+ case 'single':
57
+ return {
58
+ route,
59
+ title: route.item.title.rendered,
60
+ content: route.item.content.rendered,
61
+ excerpt: route.item.excerpt?.rendered ?? '',
62
+ slug: route.slug,
63
+ postType: route.postType,
64
+ items: [],
65
+ page: 1,
66
+ perPage: 0,
67
+ total: 0,
68
+ totalPages: 0,
69
+ };
70
+ }
71
+ }
72
+
73
+ export function templateCandidates(route: WpResolvedRoute): string[] {
74
+ if (route.kind === 'search') {
75
+ return ['search.astro', 'posts/archive.astro'];
76
+ }
77
+
78
+ if (route.kind === 'taxonomyArchive') {
79
+ return [
80
+ `taxonomies/${route.taxonomy}-${route.slug}.astro`,
81
+ `taxonomies/${route.taxonomy}.astro`,
82
+ 'taxonomies/taxonomy-[taxonomy].astro',
83
+ 'posts/archive.astro',
84
+ ];
85
+ }
86
+
87
+ if (route.kind === 'postsArchive') {
88
+ return ['posts/archive.astro'];
89
+ }
90
+
91
+ if (route.kind === 'postTypeArchive') {
92
+ return [
93
+ `post-types/${route.postType}/archive.astro`,
94
+ 'posts/archive.astro',
95
+ ];
96
+ }
97
+
98
+ if (route.kind === 'page') {
99
+ return [
100
+ ...(route.isFrontPage ? ['pages/front-page.astro'] : []),
101
+ `pages/page-${route.slug}.astro`,
102
+ 'pages/default.astro',
103
+ ];
104
+ }
105
+
106
+ return [
107
+ `post-types/${route.postType}/single-${route.slug}.astro`,
108
+ `post-types/${route.postType}/single.astro`,
109
+ ...(route.postType === 'post' ? [] : ['posts/single.astro']),
110
+ `posts/single-${route.slug}.astro`,
111
+ 'posts/single.astro',
112
+ ];
113
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "astro/tsconfigs/strict",
3
+ "include": [".astro/types.d.ts", "src"]
4
+ }
@@ -0,0 +1,29 @@
1
+ import { defineConfig } from 'vitewp';
2
+
3
+ export default defineConfig({
4
+ database: {
5
+ driver: 'mysql',
6
+ host: process.env.WP_DB_HOST ?? '127.0.0.1',
7
+ port: Number(process.env.WP_DB_PORT ?? 3306),
8
+ name: process.env.WP_DB_NAME ?? 'vitewp',
9
+ user: process.env.WP_DB_USER ?? 'root',
10
+ password: process.env.WP_DB_PASSWORD ?? '',
11
+ tablePrefix: process.env.WP_DB_TABLE_PREFIX ?? 'wp_',
12
+ },
13
+ wordpress: {
14
+ mode: 'local',
15
+ url: 'http://localhost:3000',
16
+ docroot: 'wordpress/public',
17
+ contentDir: 'wordpress/content',
18
+ },
19
+ composer: {
20
+ install: true,
21
+ wordpressPackage: 'johnpbloch/wordpress',
22
+ },
23
+ templates: {
24
+ directory: 'src/templates',
25
+ },
26
+ types: {
27
+ output: 'src/wordpress/generated-types.ts',
28
+ },
29
+ });
File without changes