@sudajs/cli 0.8.2 → 0.9.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.
package/dist/index.d.ts CHANGED
@@ -13,6 +13,9 @@ interface ValidatedTheme {
13
13
  clientEntryPath: string | null;
14
14
  stylesheetPath: string | null;
15
15
  }
16
+ interface ThemeRootOptions {
17
+ themeRoot?: string | undefined;
18
+ }
16
19
  interface CliAuthContext {
17
20
  baseUrl: string;
18
21
  token: string;
@@ -92,13 +95,18 @@ declare function buildTheme(root: string): Promise<ValidatedTheme>;
92
95
  declare function finalizeTheme(root: string): Promise<ValidatedTheme>;
93
96
  declare function findAnchorTagByHref(html: string, href: string): string | null;
94
97
  declare const __testUtils: {
98
+ createThemeProjectRequire: typeof createThemeProjectRequire;
95
99
  createRemotePageDraft: typeof createRemotePageDraft;
96
100
  findAnchorTagByHref: typeof findAnchorTagByHref;
101
+ formatMissingSharpWarning: typeof formatMissingSharpWarning;
97
102
  loadThemeScopedRenderer: typeof loadThemeScopedRenderer;
103
+ normalizePlaywrightModule: typeof normalizePlaywrightModule;
104
+ normalizeSharpModule: typeof normalizeSharpModule;
98
105
  initThemeWithKey: typeof initThemeWithKey;
99
106
  performActivateTheme: typeof performActivateTheme;
100
107
  performConfirmedPageOperation: typeof performConfirmedPageOperation;
101
108
  renderDevStarterPageHtml: typeof renderDevStarterPageHtml;
109
+ resolveScreenshotOptions: typeof resolveScreenshotOptions;
102
110
  slugifyThemeName: typeof slugifyThemeName;
103
111
  validateThemeKey: typeof validateThemeKey;
104
112
  validateThemeName: typeof validateThemeName;
@@ -109,8 +117,8 @@ declare function watchTheme(root: string, port: number): Promise<void>;
109
117
  /**
110
118
  * Theme-project-scoped renderer bundle. We deliberately resolve `react`,
111
119
  * `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
120
+ * project's own `require` graph instead of the CLI's, because the theme's
121
+ * local `dist/index.js` was already loaded against that copy of React. Importing
114
122
  * a different React instance from the CLI side would yield two React
115
123
  * dispatchers; client components inside the theme would call hooks against
116
124
  * the CLI's React (whose dispatcher is `null` outside a render), producing
@@ -125,6 +133,70 @@ interface ThemeRenderer {
125
133
  }
126
134
  declare function loadThemeScopedRenderer(themeRoot: string): Promise<ThemeRenderer>;
127
135
  declare function renderDevStarterPageHtml(theme: ValidatedTheme, page: ThemeStarterPage, renderer: ThemeRenderer): string;
136
+ interface ScreenshotOptions extends ThemeRootOptions {
137
+ device?: string[] | string;
138
+ output?: string;
139
+ width?: string;
140
+ height?: string;
141
+ port?: string;
142
+ fullPage?: boolean;
143
+ }
144
+ interface ResolvedScreenshotOptions {
145
+ targets: ScreenshotTarget[];
146
+ port: number;
147
+ fullPage: boolean;
148
+ }
149
+ declare const SCREENSHOT_DEVICES: readonly ["desktop", "tablet", "mobile"];
150
+ type ScreenshotDevice = (typeof SCREENSHOT_DEVICES)[number];
151
+ interface ScreenshotTarget {
152
+ device: ScreenshotDevice;
153
+ outputPath: string;
154
+ viewport: {
155
+ width: number;
156
+ height: number;
157
+ };
158
+ }
159
+ declare function resolveScreenshotOptions(root: string, options: ScreenshotOptions): ResolvedScreenshotOptions;
160
+ interface PlaywrightModule {
161
+ chromium: {
162
+ launch: (options?: {
163
+ headless?: boolean;
164
+ }) => Promise<{
165
+ newContext: (options: {
166
+ viewport: {
167
+ width: number;
168
+ height: number;
169
+ };
170
+ deviceScaleFactor?: number;
171
+ }) => Promise<{
172
+ newPage: () => Promise<{
173
+ goto: (url: string, options?: {
174
+ waitUntil?: string;
175
+ }) => Promise<unknown>;
176
+ screenshot: (options: {
177
+ path: string;
178
+ fullPage?: boolean;
179
+ }) => Promise<unknown>;
180
+ close: () => Promise<void>;
181
+ }>;
182
+ close: () => Promise<void>;
183
+ }>;
184
+ close: () => Promise<void>;
185
+ }>;
186
+ };
187
+ }
188
+ type SharpOptimizer = (input: string) => {
189
+ png: (options?: {
190
+ compressionLevel?: number;
191
+ palette?: boolean;
192
+ }) => {
193
+ toBuffer: () => Promise<Buffer>;
194
+ };
195
+ };
196
+ declare function createThemeProjectRequire(themeRoot: string): NodeJS.Require;
197
+ declare function normalizePlaywrightModule(moduleValue: unknown): PlaywrightModule | null;
198
+ declare function normalizeSharpModule(moduleValue: unknown): SharpOptimizer | null;
199
+ declare function formatMissingSharpWarning(): string;
128
200
  /**
129
201
  * 解析人机交互的 `key@version` 格式。允许仅 `key`,也允许带 version。
130
202
  * 注意:theme key 现行约束不含 `@`,所以从右侧第一个 `@` 之后视为 version。