methanol 0.0.8 → 0.0.10

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/README.md CHANGED
@@ -44,6 +44,9 @@ export default () => ({
44
44
  // optional: code highlighting (Starry Night)
45
45
  starryNight: false,
46
46
 
47
+ // optional: pwa support
48
+ pwa: true,
49
+
47
50
  // optional: site metadata
48
51
  site: {
49
52
  base: '/docs/'
package/index.js CHANGED
@@ -18,5 +18,10 @@
18
18
  * under the License.
19
19
  */
20
20
 
21
- export { env } from './src/rewind.js'
22
- export { HTMLRenderer } from './src/renderer.js'
21
+ import { HTMLRenderer } from './src/renderer.js'
22
+
23
+ export { env } from './src/reframe.js'
24
+
25
+ const DOCTYPE_HTML = HTMLRenderer.rawHTML`<!DOCTYPE html>`
26
+
27
+ export { HTMLRenderer, DOCTYPE_HTML }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "methanol",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "Static site generator powered by rEFui and MDX",
5
5
  "main": "./index.js",
6
6
  "type": "module",
@@ -35,12 +35,18 @@
35
35
  "gray-matter": "^4.0.3",
36
36
  "hast-util-is-element": "^3.0.0",
37
37
  "json5": "^2.2.3",
38
- "refui": "^0.16.2",
38
+ "null-prototype-object": "^1.2.5",
39
+ "refui": "^0.16.3",
39
40
  "refurbish": "^0.1.8",
40
41
  "rehype-slug": "^6.0.0",
41
42
  "rehype-starry-night": "^2.2.0",
43
+ "remark-gfm": "^4.0.1",
42
44
  "unist-util-visit": "^5.0.0",
43
- "vite": "^7.3.0",
45
+ "vite": "^7.3.1",
46
+ "vite-plugin-pwa": "^1.2.0",
47
+ "workbox-core": "^7.4.0",
48
+ "workbox-routing": "^7.4.0",
49
+ "workbox-strategies": "^7.4.0",
44
50
  "yargs": "^18.0.0"
45
51
  },
46
52
  "repository": {
@@ -20,7 +20,9 @@
20
20
 
21
21
  import { writeFile, mkdir, rm, readFile, readdir, stat } from 'fs/promises'
22
22
  import { resolve, dirname, join } from 'path'
23
+ import { fileURLToPath } from 'url'
23
24
  import { build as viteBuild, mergeConfig, normalizePath } from 'vite'
25
+ import { VitePWA } from 'vite-plugin-pwa'
24
26
  import { state, cli } from './state.js'
25
27
  import { resolveUserViteConfig } from './config.js'
26
28
  import { buildPagesContext } from './pages.js'
@@ -30,6 +32,9 @@ import { methanolVirtualHtmlPlugin, methanolResolverPlugin } from './vite-plugin
30
32
  import { createStageLogger } from './stage-logger.js'
31
33
  import { preparePublicAssets } from './public-assets.js'
32
34
 
35
+ const __filename = fileURLToPath(import.meta.url)
36
+ const __dirname = dirname(__filename)
37
+
33
38
  const ensureDir = async (dir) => {
34
39
  await mkdir(dir, { recursive: true })
35
40
  }
@@ -67,7 +72,7 @@ export const buildHtmlEntries = async () => {
67
72
  await ensureDir(state.INTERMEDIATE_DIR)
68
73
  }
69
74
 
70
- const logEnabled = state.CURRENT_MODE === 'production' && cli.command === 'build'
75
+ const logEnabled = state.CURRENT_MODE === 'production' && cli.command === 'build' && !cli.CLI_VERBOSE
71
76
  const stageLogger = createStageLogger(logEnabled)
72
77
  const themeComponentsDir = state.THEME_COMPONENTS_DIR
73
78
  const themeEnv = state.THEME_ENV
@@ -102,14 +107,11 @@ export const buildHtmlEntries = async () => {
102
107
  for (let i = 0; i < pagesContext.pages.length; i++) {
103
108
  const page = pagesContext.pages[i]
104
109
  if (logEnabled) {
105
- stageLogger.update(
106
- renderToken,
107
- `Rendering pages [${i + 1}/${totalPages}] ${page.filePath}`
108
- )
110
+ stageLogger.update(renderToken, `Rendering pages [${i + 1}/${totalPages}] ${page.path}`)
109
111
  }
110
112
  const html = await renderHtml({
111
113
  routePath: page.routePath,
112
- filePath: page.filePath,
114
+ path: page.path,
113
115
  components: mergedComponents,
114
116
  pagesContext,
115
117
  pageMeta: page
@@ -164,6 +166,10 @@ export const buildHtmlEntries = async () => {
164
166
  }
165
167
 
166
168
  export const runViteBuild = async (entry, htmlCache) => {
169
+ const logEnabled = state.CURRENT_MODE === 'production' && cli.command === 'build' && !cli.CLI_VERBOSE
170
+ const stageLogger = createStageLogger(logEnabled)
171
+ const token = stageLogger.start('Building bundle')
172
+
167
173
  if (state.STATIC_DIR !== false && state.MERGED_ASSETS_DIR) {
168
174
  await preparePublicAssets({
169
175
  themeDir: state.THEME_ASSETS_DIR,
@@ -172,11 +178,14 @@ export const runViteBuild = async (entry, htmlCache) => {
172
178
  })
173
179
  }
174
180
  const copyPublicDirEnabled = state.STATIC_DIR !== false
181
+ const manifestConfig = state.PWA_OPTIONS?.manifest || {}
182
+ const resolvedManifest = { name: state.SITE_NAME, short_name: state.SITE_NAME, ...manifestConfig }
175
183
  const baseConfig = {
176
184
  configFile: false,
177
185
  root: state.PAGES_DIR,
178
186
  appType: 'mpa',
179
187
  publicDir: state.STATIC_DIR === false ? false : state.STATIC_DIR,
188
+ logLevel: cli.CLI_VERBOSE ? 'info' : 'silent',
180
189
  build: {
181
190
  outDir: state.DIST_DIR,
182
191
  emptyOutDir: true,
@@ -193,9 +202,42 @@ export const runViteBuild = async (entry, htmlCache) => {
193
202
  resolve: {
194
203
  dedupe: ['refui', 'methanol']
195
204
  },
196
- plugins: [methanolVirtualHtmlPlugin(htmlCache), methanolResolverPlugin()]
205
+ plugins: [
206
+ methanolVirtualHtmlPlugin(htmlCache),
207
+ methanolResolverPlugin(),
208
+ state.PWA_ENABLED
209
+ ? VitePWA({
210
+ injectRegister: 'auto',
211
+ registerType: 'autoUpdate',
212
+ strategies: 'injectManifest',
213
+ srcDir: resolve(__dirname, 'client'),
214
+ filename: 'sw.js',
215
+ manifest: resolvedManifest,
216
+ injectManifest: {
217
+ globPatterns: ['**/*.{js,css,html,ico,png,svg}'],
218
+ ...(state.PWA_OPTIONS?.injectManifest || {})
219
+ }
220
+ })
221
+ : null
222
+ ]
197
223
  }
198
224
  const userConfig = await resolveUserViteConfig('build')
199
225
  const finalConfig = userConfig ? mergeConfig(baseConfig, userConfig) : baseConfig
200
- await viteBuild(finalConfig)
226
+
227
+ const originalLog = console.log
228
+ const originalWarn = console.warn
229
+ if (!cli.CLI_VERBOSE) {
230
+ console.log = () => {}
231
+ console.warn = () => {}
232
+ }
233
+
234
+ try {
235
+ await viteBuild(finalConfig)
236
+ } finally {
237
+ if (!cli.CLI_VERBOSE) {
238
+ console.log = originalLog
239
+ console.warn = originalWarn
240
+ }
241
+ }
242
+ stageLogger.end(token)
201
243
  }