@sudajs/cli 0.7.1 → 0.8.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/index.d.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import { ThemeModule } from '@sudajs/theme-engine';
2
+ import { ThemeModule, ThemeStarterPage } from '@sudajs/theme-engine';
3
+ import { ThemeRender, extractLayoutChrome, resolveAssetPath } from '@sudajs/theme-engine/server';
3
4
  import { Command } from 'commander';
5
+ import { createElement } from 'react';
6
+ import { renderToString } from 'react-dom/server';
7
+ import { z } from 'zod';
4
8
 
5
9
  interface ValidatedTheme {
6
10
  root: string;
@@ -9,16 +13,118 @@ interface ValidatedTheme {
9
13
  clientEntryPath: string | null;
10
14
  stylesheetPath: string | null;
11
15
  }
16
+ interface CliAuthContext {
17
+ baseUrl: string;
18
+ token: string;
19
+ }
20
+ type FetchJsonFn = typeof fetchJson;
21
+ declare const destructivePageOperationOutputSchema: z.ZodDiscriminatedUnion<"status", [z.ZodObject<{
22
+ status: z.ZodLiteral<"needs_confirmation">;
23
+ projectId: z.ZodString;
24
+ slug: z.ZodString;
25
+ impact: z.ZodString;
26
+ }, "strip", z.ZodTypeAny, {
27
+ projectId: string;
28
+ slug: string;
29
+ status: "needs_confirmation";
30
+ impact: string;
31
+ }, {
32
+ projectId: string;
33
+ slug: string;
34
+ status: "needs_confirmation";
35
+ impact: string;
36
+ }>, z.ZodObject<{
37
+ status: z.ZodEnum<["deleted", "published"]>;
38
+ projectId: z.ZodString;
39
+ slug: z.ZodString;
40
+ pageId: z.ZodString;
41
+ }, "strip", z.ZodTypeAny, {
42
+ projectId: string;
43
+ slug: string;
44
+ status: "deleted" | "published";
45
+ pageId: string;
46
+ }, {
47
+ projectId: string;
48
+ slug: string;
49
+ status: "deleted" | "published";
50
+ pageId: string;
51
+ }>]>;
52
+ declare const activateThemeOutputSchema: z.ZodDiscriminatedUnion<"status", [z.ZodObject<{
53
+ status: z.ZodLiteral<"needs_confirmation">;
54
+ projectId: z.ZodString;
55
+ themeKey: z.ZodString;
56
+ themeVersion: z.ZodNullable<z.ZodString>;
57
+ impact: z.ZodString;
58
+ }, "strip", z.ZodTypeAny, {
59
+ projectId: string;
60
+ status: "needs_confirmation";
61
+ impact: string;
62
+ themeKey: string;
63
+ themeVersion: string | null;
64
+ }, {
65
+ projectId: string;
66
+ status: "needs_confirmation";
67
+ impact: string;
68
+ themeKey: string;
69
+ themeVersion: string | null;
70
+ }>, z.ZodObject<{
71
+ status: z.ZodLiteral<"activated">;
72
+ projectId: z.ZodString;
73
+ themeKey: z.ZodString;
74
+ themeVersion: z.ZodNullable<z.ZodString>;
75
+ }, "strip", z.ZodTypeAny, {
76
+ projectId: string;
77
+ status: "activated";
78
+ themeKey: string;
79
+ themeVersion: string | null;
80
+ }, {
81
+ projectId: string;
82
+ status: "activated";
83
+ themeKey: string;
84
+ themeVersion: string | null;
85
+ }>]>;
86
+ declare function fetchJson<T>(url: string, options?: RequestInit & {
87
+ token?: string;
88
+ }): Promise<T>;
12
89
  declare function validateTheme(root: string): Promise<ValidatedTheme>;
13
90
  declare function toViteModuleUrl(root: string, absolutePath: string): string;
14
91
  declare function buildTheme(root: string): Promise<ValidatedTheme>;
15
92
  declare function finalizeTheme(root: string): Promise<ValidatedTheme>;
16
93
  declare function findAnchorTagByHref(html: string, href: string): string | null;
17
94
  declare const __testUtils: {
95
+ createRemotePageDraft: typeof createRemotePageDraft;
18
96
  findAnchorTagByHref: typeof findAnchorTagByHref;
97
+ loadThemeScopedRenderer: typeof loadThemeScopedRenderer;
98
+ initThemeWithKey: typeof initThemeWithKey;
99
+ performActivateTheme: typeof performActivateTheme;
100
+ performConfirmedPageOperation: typeof performConfirmedPageOperation;
101
+ renderDevStarterPageHtml: typeof renderDevStarterPageHtml;
102
+ slugifyThemeName: typeof slugifyThemeName;
103
+ validateThemeKey: typeof validateThemeKey;
104
+ validateThemeName: typeof validateThemeName;
19
105
  toViteModuleUrl: typeof toViteModuleUrl;
106
+ updateRemotePageDraft: typeof updateRemotePageDraft;
20
107
  };
21
108
  declare function watchTheme(root: string, port: number): Promise<void>;
109
+ /**
110
+ * Theme-project-scoped renderer bundle. We deliberately resolve `react`,
111
+ * `react-dom/server` and `@sudajs/theme-engine/server` through the theme
112
+ * project's own `require` graph instead of the CLI's, because the theme
113
+ * `dist/index.js` was already loaded against that copy of React. Importing
114
+ * a different React instance from the CLI side would yield two React
115
+ * dispatchers; client components inside the theme would call hooks against
116
+ * the CLI's React (whose dispatcher is `null` outside a render), producing
117
+ * `Cannot read properties of null (reading 'useState')`.
118
+ */
119
+ interface ThemeRenderer {
120
+ ThemeRender: typeof ThemeRender;
121
+ extractLayoutChrome: typeof extractLayoutChrome;
122
+ resolveAssetPath: typeof resolveAssetPath;
123
+ createElement: typeof createElement;
124
+ renderToString: typeof renderToString;
125
+ }
126
+ declare function loadThemeScopedRenderer(themeRoot: string): Promise<ThemeRenderer>;
127
+ declare function renderDevStarterPageHtml(theme: ValidatedTheme, page: ThemeStarterPage, renderer: ThemeRenderer): string;
22
128
  /**
23
129
  * 解析人机交互的 `key@version` 格式。允许仅 `key`,也允许带 version。
24
130
  * 注意:theme key 现行约束不含 `@`,所以从右侧第一个 `@` 之后视为 version。
@@ -29,7 +135,42 @@ declare function parseThemeRef(value: string): {
29
135
  key: string;
30
136
  version?: string;
31
137
  };
138
+ declare function createRemotePageDraft(auth: CliAuthContext, input: {
139
+ projectId: string;
140
+ title: string;
141
+ slug: string;
142
+ themeKey: string;
143
+ themeVersion: string;
144
+ data: unknown;
145
+ }, fetcher?: FetchJsonFn): Promise<{
146
+ pageId: string;
147
+ }>;
148
+ declare function updateRemotePageDraft(auth: CliAuthContext, input: {
149
+ projectId: string;
150
+ slug: string;
151
+ themeKey: string;
152
+ themeVersion: string;
153
+ data: unknown;
154
+ }, fetcher?: FetchJsonFn): Promise<{
155
+ pageId: string;
156
+ }>;
157
+ declare function performConfirmedPageOperation(auth: CliAuthContext, input: {
158
+ operation: "delete" | "publish";
159
+ projectId: string;
160
+ slug: string;
161
+ confirm?: boolean | undefined;
162
+ }, fetcher?: FetchJsonFn): Promise<z.infer<typeof destructivePageOperationOutputSchema>>;
163
+ declare function performActivateTheme(auth: CliAuthContext, input: {
164
+ projectId: string;
165
+ themeKey: string;
166
+ themeVersion?: string | undefined;
167
+ confirm?: boolean | undefined;
168
+ }, fetcher?: FetchJsonFn): Promise<z.infer<typeof activateThemeOutputSchema>>;
169
+ declare function validateThemeName(name: string): string | null;
170
+ declare function validateThemeKey(key: string): string | null;
171
+ declare function slugifyThemeName(name: string): string;
32
172
  declare function initTheme(target: string): Promise<void>;
173
+ declare function initThemeWithKey(target: string, key: string): Promise<void>;
33
174
  declare function buildProgram(): Command;
34
175
  declare function main(): Promise<void>;
35
176