|
1 | 1 | import { Application, TSConfigReader, LogLevel, DefaultTheme, type TypeDocOptions } from 'typedoc';
|
2 |
| -import { existsSync, mkdirSync, writeFileSync, readdirSync } from 'node:fs'; |
| 2 | +import { existsSync, mkdirSync, writeFileSync, readdirSync, readFileSync, cpSync } from 'node:fs'; |
3 | 3 | import { resolve, join, dirname } from 'node:path';
|
4 | 4 | import { fileURLToPath } from 'node:url';
|
5 | 5 |
|
@@ -108,7 +108,7 @@ async function generator() {
|
108 | 108 | }
|
109 | 109 |
|
110 | 110 | async function generateDocs(options: Partial<TypeDocOptions>) {
|
111 |
| - console.log(`Generating docs for ${options.name || 'unknown'}`); |
| 111 | + // console.log(`Generating docs for ${options.name}`); |
112 | 112 |
|
113 | 113 | const outDir = options.out as string;
|
114 | 114 | if (!existsSync(outDir)) {
|
@@ -149,110 +149,31 @@ async function generateIndexPage() {
|
149 | 149 | .join('');
|
150 | 150 | }
|
151 | 151 |
|
152 |
| - // TODO: move this to a file and improve layout |
153 |
| - // TODO: copy assets to the output directory |
| 152 | + // TODO: improve layout |
154 | 153 | // TODO: improve theme switcher
|
155 | 154 | // TODO: link to docs
|
156 | 155 | // TODO: make docs link to here
|
157 |
| - const indexContent = ` |
158 |
| -<!DOCTYPE html> |
159 |
| -<html lang="en"> |
160 |
| -<head> |
161 |
| - <meta charset="UTF-8"> |
162 |
| - <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
163 |
| - <meta name="color-scheme" content="light dark"> |
164 |
| - <title>Tauri JS API Reference</title> |
165 |
| - <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.slate.min.css"> |
166 |
| - <style> |
167 |
| - .grid { |
168 |
| - --grid-min-value: 16rem; |
169 |
| - grid-template-columns: repeat(auto-fit, minmax(var(--grid-min-value), 1fr)); |
170 |
| - } |
171 |
| - .tauri-logo { |
172 |
| - height: 2rem; |
173 |
| - vertical-align: middle; |
174 |
| - margin-right: 0.5rem; |
175 |
| - } |
176 |
| - .logo-light { display: none; } |
177 |
| - .logo-dark { display: none; } |
178 |
| - @media (prefers-color-scheme: dark) { |
179 |
| - .logo-dark { display: inline; } |
180 |
| - .logo-light { display: none; } |
181 |
| - } |
182 |
| - @media (prefers-color-scheme: light), (prefers-color-scheme: no-preference) { |
183 |
| - .logo-light { display: inline; } |
184 |
| - .logo-dark { display: none; } |
185 |
| - } |
186 |
| - [data-theme="dark"] .logo-dark { display: inline; } |
187 |
| - [data-theme="dark"] .logo-light { display: none; } |
188 |
| - [data-theme="light"] .logo-light { display: inline; } |
189 |
| - [data-theme="light"] .logo-dark { display: none; } |
190 |
| - </style> |
191 |
| -</head> |
192 |
| -<body> |
193 |
| - <header class="container"> |
194 |
| - <nav> |
195 |
| - <ul> |
196 |
| - <li> |
197 |
| - <img src="./assets/logo_light.svg" alt="Tauri Logo" class="tauri-logo logo-light" loading="lazy"> |
198 |
| - <img src="./assets/logo.svg" alt="Tauri Logo" class="tauri-logo logo-dark" loading="lazy"> |
199 |
| - </li> |
200 |
| - </ul> |
201 |
| - <ul> |
202 |
| - <li> |
203 |
| - <select id="theme-switcher" aria-label="Theme"> |
204 |
| - <option value="light">Light</option> |
205 |
| - <option value="dark">Dark</option> |
206 |
| - <option value="auto" selected>Auto</option> |
207 |
| - </select> |
208 |
| - </li> |
209 |
| - </ul> |
210 |
| - </nav> |
211 |
| - </header> |
212 |
| - <main class="container"> |
213 |
| - <hgroup> |
214 |
| - <h1>Javascript Reference</h1> |
215 |
| - <p>API reference for Tauri core and plugins</p> |
216 |
| - </hgroup> |
217 |
| - <section> |
218 |
| - <div>${cardTemplate('Tauri Core API', './core/index.html')}</div> |
219 |
| - <h3>Plugins</h3> |
220 |
| - <div class="grid"> |
221 |
| - ${pluginsGridHtml} |
222 |
| - </div> |
223 |
| - </section> |
224 |
| - </main> |
225 |
| - <footer class="container"> |
226 |
| - <small>© 2025 Tauri Apps. All rights reserved.</small> |
227 |
| - </footer> |
228 |
| - <script> |
229 |
| - const themeSwitcher = document.getElementById('theme-switcher'); |
230 |
| - function setTheme(theme) { |
231 |
| - if (theme === 'auto') { |
232 |
| - document.documentElement.removeAttribute('data-theme'); |
233 |
| - localStorage.removeItem('theme'); |
234 |
| - } else { |
235 |
| - document.documentElement.setAttribute('data-theme', theme); |
236 |
| - localStorage.setItem('theme', theme); |
237 |
| - } |
238 |
| - } |
239 |
| - themeSwitcher.value = localStorage.getItem('theme') || 'auto'; |
240 |
| - setTheme(themeSwitcher.value); |
241 |
| - themeSwitcher.addEventListener('change', (e) => { |
242 |
| - setTheme(e.target.value); |
243 |
| - }); |
244 |
| - </script> |
245 |
| -</body> |
246 |
| -</html> |
247 |
| - `; |
248 |
| - |
249 |
| - const cssDir = join(BASE_OUTPUT_DIR, 'assets'); |
250 |
| - if (!existsSync(cssDir)) { |
251 |
| - mkdirSync(cssDir, { recursive: true }); |
| 156 | + const indexTemplatePath = join(__dirname, 'indexTemplate.html'); |
| 157 | + const indexContent = readFileSync(indexTemplatePath, 'utf-8') |
| 158 | + .replace('{{ pluginsGridHtml }}', pluginsGridHtml || '') |
| 159 | + .replace('{{ tauriCard }}', cardTemplate('Tauri Core API', './core/index.html')); |
| 160 | + |
| 161 | + const assetsDir = join(BASE_OUTPUT_DIR, 'assets'); |
| 162 | + if (!existsSync(assetsDir)) { |
| 163 | + mkdirSync(assetsDir, { recursive: true }); |
| 164 | + } |
| 165 | + const distAssetsDir = join(__dirname, 'assets'); |
| 166 | + if (existsSync(distAssetsDir)) { |
| 167 | + try { |
| 168 | + cpSync(distAssetsDir, assetsDir, { recursive: true, force: true }); |
| 169 | + } catch (err) { |
| 170 | + console.error('Failed to copy assets:', err); |
| 171 | + } |
| 172 | + } else { |
| 173 | + console.warn(`Assets directory not found at ${distAssetsDir}`); |
252 | 174 | }
|
253 | 175 | try {
|
254 | 176 | writeFileSync(indexPath, indexContent);
|
255 |
| - console.log(`Generated index page at ${indexPath}`); |
256 | 177 | } catch (error) {
|
257 | 178 | console.error('Failed to write index files:', error);
|
258 | 179 | }
|
|
0 commit comments